载入中...
搜索中...
未找到
AssetReloader.h
浏览该文件的文档.
1#pragma once
2
3// Asset ownership interface, shared by two consumers:
4//
5// 1. Hot reload: let each module react to its own asset files. The filesystem
6// watcher knows a path changed but nothing about what lives at that path,
7// so every module that owns an asset kind registers a reloader and the
8// watcher just dispatches. Modules the build does not contain simply are
9// not registered.
10// 2. Unified resource cache (common/Resource.h): on a cache miss the
11// ResourceManager asks the same registered providers to `load()` the CPU
12// resource for a key, so the engine-common layer still knows nothing about
13// graphics / particles / map / font / model / sound.
14//
15// Ordering matters when several reloaders react to one file: the cached CPU
16// resource must refresh before the GPU texture is re-uploaded, and the GPU
17// texture before the emitters / tile layers that sample it re-bind. Register
18// with a priority to express that.
19
20#include "common/Export.h"
21#include "common/Result.h"
22
23#include <string>
24
25namespace eve {
26class Resource;
27}
28
29namespace eve::caps {
30
33public:
36 enum Priority {
37 kCache = 0, // refresh cached CPU resources (ResourceManager)
38 kTexture = 10, // refresh GPU resources before their consumers re-bind
39 kConsumer = 20, // things that reference a reloaded resource
40 };
41
42 static constexpr const char* capabilityName = "IAssetReloader";
43 virtual ~IAssetReloader() = default;
44
55 virtual const char* reloadKind() const = 0;
56
62 virtual bool handlesPath(const std::string& normPath) const = 0;
63
83 [[nodiscard("loaded resource ownership must be retained or explicitly handled")]] virtual Resource* load(
84 const std::string& key) {
85 return nullptr;
86 }
87
94 [[nodiscard("asset reload outcome must be checked")]] virtual eve::Result<bool> reload(
95 const std::string& normPath) = 0;
96};
97
98} // namespace eve::caps
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
std::uint32_t key
Move-only, checked operation results for the common layer.
Resource is a game object that is managed by the ResourceManager. It can be loaded from a file or gen...
Definition Resource.h:51
Move-only operation result carrying either a value or Status.
Definition Result.h:155
EVENGINE_API_FOUNDATION public API.
virtual const char * reloadKind() const =0
Stable name for this reloader ("texture" / "particle" / "tilemap"). A path bound to this kind is offe...
virtual bool handlesPath(const std::string &normPath) const =0
virtual ~IAssetReloader()=default
Priority
Priority public API.
virtual Resource * load(const std::string &key)
Create the CPU-side resource identified by key (a normalized VFS path, optionally followed by ?...
virtual eve::Result< bool > reload(const std::string &normPath)=0
Reload everything referencing normPath.
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16