载入中...
搜索中...
未找到
TextureReloader.cpp
浏览该文件的文档.
1// Refreshes path-cached GPU textures when their image file changes on disk.
2//
3// Registered at kTexture priority so the texture is re-uploaded before the
4// modules that sample it (particle emitters, tile layers) re-bind.
5
7#include "common/Capability.h"
8#include "common/Module.h"
9#include "graphics/Graphics.h"
10
11#include <cctype>
12#include <string>
13
14namespace eve::graphics {
15namespace {
16
17std::string extensionOf(const std::string &path) {
18 const auto pos = path.find_last_of('.');
19 if (pos == std::string::npos) return {};
20 std::string ext = path.substr(pos);
21 for (char &c : ext) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
22 return ext;
23}
24
25bool isImagePath(const std::string &path) {
26 const std::string ext = extensionOf(path);
27 return ext == ".png" || ext == ".jpg" || ext == ".jpeg" || ext == ".bmp" || ext == ".tga" ||
28 ext == ".gif" || ext == ".webp" || ext == ".exr" || ext == ".hdr";
29}
30
31class TextureReloader : public eve::caps::IAssetReloader {
32public:
33 const char *reloadKind() const override { return "texture"; }
34
35 bool handlesPath(const std::string &normPath) const override { return isImagePath(normPath); }
36
37 eve::Result<bool> reload(const std::string &normPath) override {
38 auto *gfx = eve::ModuleManager::getInstance<Graphics>("Graphics");
39 if (!gfx) return eve::Result<bool>::success(false);
40 return eve::Result<bool>::success(gfx->reloadTextureFromFile(normPath));
41 }
42};
43
44struct Register {
45 Register() {
46 static TextureReloader reloader;
47 eve::cap::addListener<eve::caps::IAssetReloader>(&reloader,
49 }
50} g_register;
51
52} // namespace
53} // namespace eve::graphics
std::int32_t c
std::string path
Definition PlayHost.cpp:110
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
EVENGINE_API_FOUNDATION public API.
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25