ResourceManager is a singleton that manages all resources in the game. It provides a way to load, reload, and unload resources. 更多...
#include <Resource.h>
Public 成员函数 | |
| Resource * | get (std::string key) |
Get the cached resource for key; on a miss, load it through the registered IAssetReloader providers and cache the result. | |
| void | unload (std::string key) |
Drop the exact cache entry key (parameters included). The resource stays alive while other holders still reference it. | |
| void | unloadPath (const std::string &path) |
| Drop every cache entry whose path matches, whatever its parameters. | |
| size_t | count () const |
| Number of cached entries. | |
| void | clear () |
| Drop every entry and re-arm lazy registration (tests / teardown). | |
| const char * | reloadKind () const override |
| bool | handlesPath (const std::string &normPath) const override |
| bool | reload (const std::string &normPath) override |
| Resource * | load (const std::string &key) override |
Public 成员函数 继承自 eve::caps::IAssetReloader | |
| virtual | ~IAssetReloader ()=default |
静态 Public 成员函数 | |
| static ResourceManager & | getInstance () |
| static std::string | normalizePath (std::string path) |
| Normalize a VFS path: backslashes to '/', strip leading "./" and trailing '/'. | |
| static std::string | makeKey (const std::string &path, const std::string &query="") |
Build a cache key from a path and optional ?query parameters. | |
| static std::string | pathOfKey (const std::string &key) |
| The path part of a cache key (everything before the first '?'). | |
Protected 成员函数 | |
| ResourceManager ()=default | |
| void | ensureRegistered () |
| bool | refreshEntry (const std::string &key, std::set< std::string > &visited) |
| void | refreshDependents (Resource *updated, std::set< std::string > &visited) |
Protected 属性 | |
| std::map< std::string, ref< Resource > > | resources |
| std::mutex | mu_ |
| bool | registered_ = false |
额外继承的成员函数 | |
Public 类型 继承自 eve::caps::IAssetReloader | |
| enum | Priority { kCache = 0 , kTexture = 10 , kConsumer = 20 } |
静态 Public 属性 继承自 eve::caps::IAssetReloader | |
| static constexpr const char * | capabilityName = "IAssetReloader" |
详细描述
ResourceManager is a singleton that manages all resources in the game. It provides a way to load, reload, and unload resources.
The manager is a unified cache for CPU-side assets (ImageData, FontData, ModelData, SoundData, ...). Keys are normalized VFS paths, optionally with ?param=value entries ("fonts/a.ttf?size=16"). On a miss it asks the registered eve::caps::IAssetReloader providers which one claims the key and can load() it; the first hit is cached and returned. On a file change the manager itself participates in hot reload as the first IAssetReloader listener (kCache priority): every cached entry for that path is re-loaded and refreshed in place through Resource::adopt, so holders keep a valid pointer. Entries that list the refreshed resource as a dependency are refreshed too (transitively, cycle-safe).
The cache itself is thread-safe: map access is mutex-guarded and the heavy provider load() runs outside the lock, so sceneloader's background decode threads can insert entries while the main thread reads them. Reloads (adopt) are expected on the main thread during hot-reload dispatch.
在文件 Resource.h 第 87 行定义.
构造及析构函数说明
◆ ResourceManager()
|
protecteddefault |
被这些函数引用 getInstance().
成员函数说明
◆ clear()
| void eve::ResourceManager::clear | ( | ) |
Drop every entry and re-arm lazy registration (tests / teardown).
在文件 Resource.cpp 第 105 行定义.
引用了 mu_, eve::cap::query(), registered_ , 以及 resources.
◆ count()
| size_t eve::ResourceManager::count | ( | ) | const |
◆ ensureRegistered()
|
protected |
在文件 Resource.cpp 第 44 行定义.
引用了 eve::caps::IAssetReloader::kCache, mu_, eve::cap::query() , 以及 registered_.
被这些函数引用 getInstance().
◆ get()
| Resource * eve::ResourceManager::get | ( | std::string | key | ) |
Get the cached resource for key; on a miss, load it through the registered IAssetReloader providers and cache the result.
- 参数
-
key A normalized VFS path, optionally with ?params.
- 返回
- The shared resource, or nullptr when no provider claims the key. Loader errors propagate to the caller. The returned pointer is owned by the cache (kept alive while the entry exists); callers must not delete it, and it stays valid until unload() or process exit.
在文件 Resource.cpp 第 56 行定义.
引用了 eve::caps::IAssetReloader::handlesPath(), eve::caps::IAssetReloader::load(), makeKey(), mu_, eve::cap::query(), resources , 以及 eve::Resource::setUri().
被这些函数引用 eve::font::Font::newFontDataFromFile(), eve::image::Image::newImageDataFromFile(), eve::model3d::Model3D::newModelDataFromFile() , 以及 eve::sound::Sound::newSoundDataFromFile().
◆ getInstance()
|
static |
◆ handlesPath()
|
overridevirtual |
Whether this reloader claims normPath during automatic dispatch. For providers of cached CPU resources the key may carry parameters ("fonts/a.ttf?size=16"); use ResourceManager::pathOfKey() to strip them.
实现了 eve::caps::IAssetReloader.
在文件 Resource.cpp 第 116 行定义.
引用了 mu_, normalizePath(), pathOfKey() , 以及 resources.
◆ load()
|
inlineoverridevirtual |
Create the CPU-side resource identified by key (a normalized VFS path, optionally followed by ?param=value entries that change the decoded asset, e.g. "fonts/a.ttf?size=16").
- 返回
- nullptr when this provider does not claim the key. The caller (ResourceManager) caches the result and keeps it alive; later reloads drain the freshly loaded instance into the cached one via Resource::adopt, so the cached identity stays stable.
重载 eve::caps::IAssetReloader .
在文件 Resource.h 第 132 行定义.
◆ makeKey()
|
static |
Build a cache key from a path and optional ?query parameters.
在文件 Resource.cpp 第 30 行定义.
引用了 normalizePath().
被这些函数引用 get(), eve::model3d::modelCacheKey(), eve::font::Font::newFontDataFromFile() , 以及 unload().
◆ normalizePath()
|
static |
Normalize a VFS path: backslashes to '/', strip leading "./" and trailing '/'.
在文件 Resource.cpp 第 21 行定义.
引用了 c.
被这些函数引用 handlesPath(), makeKey(), pathOfKey(), reload() , 以及 unloadPath().
◆ pathOfKey()
|
static |
The path part of a cache key (everything before the first '?').
在文件 Resource.cpp 第 39 行定义.
引用了 normalizePath().
被这些函数引用 handlesPath(), reload() , 以及 unloadPath().
◆ refreshDependents()
|
protected |
在文件 Resource.cpp 第 185 行定义.
引用了 dependents, mu_, refreshEntry() , 以及 resources.
被这些函数引用 refreshEntry().
◆ refreshEntry()
|
protected |
在文件 Resource.cpp 第 146 行定义.
引用了 eve::Resource::adopt(), eve::caps::IAssetReloader::handlesPath(), eve::caps::IAssetReloader::load(), mu_, eve::cap::query(), refreshDependents() , 以及 resources.
被这些函数引用 refreshDependents() , 以及 reload().
◆ reload()
|
overridevirtual |
Reload everything referencing normPath. Returns true if anything changed.
重载 eve::caps::IAssetReloader .
在文件 Resource.cpp 第 126 行定义.
引用了 mu_, normalizePath(), pathOfKey(), refreshEntry() , 以及 resources.
◆ reloadKind()
|
inlineoverridevirtual |
Stable name for this reloader ("texture" / "particle" / "tilemap"). A path bound to this kind is offered here regardless of its extension.
实现了 eve::caps::IAssetReloader.
在文件 Resource.h 第 129 行定义.
◆ unload()
| void eve::ResourceManager::unload | ( | std::string | key | ) |
Drop the exact cache entry key (parameters included). The resource stays alive while other holders still reference it.
在文件 Resource.cpp 第 89 行定义.
◆ unloadPath()
| void eve::ResourceManager::unloadPath | ( | const std::string & | path | ) |
Drop every cache entry whose path matches, whatever its parameters.
在文件 Resource.cpp 第 94 行定义.
引用了 mu_, normalizePath(), pathOfKey() , 以及 resources.
类成员变量说明
◆ mu_
|
mutableprotected |
在文件 Resource.h 第 142 行定义.
被这些函数引用 clear(), count(), ensureRegistered(), get(), handlesPath(), refreshDependents(), refreshEntry(), reload(), unload() , 以及 unloadPath().
◆ registered_
|
protected |
在文件 Resource.h 第 143 行定义.
被这些函数引用 clear() , 以及 ensureRegistered().
◆ resources
在文件 Resource.h 第 141 行定义.
被这些函数引用 clear(), count(), get(), handlesPath(), refreshDependents(), refreshEntry(), reload(), unload() , 以及 unloadPath().
该类的文档由以下文件生成:
- src/engine/common/Resource.h
- src/engine/common/Resource.cpp
Public 成员函数 继承自