载入中...
搜索中...
未找到

ResourceManager is a singleton that manages all resources in the game. It provides a way to load, reload, and unload resources. 更多...

#include <Resource.h>

类 eve::ResourceManager 继承关系图:
eve::caps::IAssetReloader

Public 成员函数

Resourceget (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
 
Resourceload (const std::string &key) override
 
- Public 成员函数 继承自 eve::caps::IAssetReloader
virtual ~IAssetReloader ()=default
 

静态 Public 成员函数

static ResourceManagergetInstance ()
 
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.h87 行定义.

构造及析构函数说明

◆ ResourceManager()

eve::ResourceManager::ResourceManager ( )
protecteddefault

被这些函数引用 getInstance().

成员函数说明

◆ clear()

void eve::ResourceManager::clear ( )

Drop every entry and re-arm lazy registration (tests / teardown).

在文件 Resource.cpp105 行定义.

引用了 mu_, eve::cap::query(), registered_ , 以及 resources.

◆ count()

size_t eve::ResourceManager::count ( ) const

Number of cached entries.

在文件 Resource.cpp51 行定义.

引用了 mu_ , 以及 resources.

◆ ensureRegistered()

void eve::ResourceManager::ensureRegistered ( )
protected

在文件 Resource.cpp44 行定义.

引用了 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.

参数
keyA 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.cpp56 行定义.

引用了 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()

◆ handlesPath()

bool eve::ResourceManager::handlesPath ( const std::string &  normPath) const
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.cpp116 行定义.

引用了 mu_, normalizePath(), pathOfKey() , 以及 resources.

◆ load()

Resource * eve::ResourceManager::load ( const std::string &  key)
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.h132 行定义.

◆ makeKey()

std::string eve::ResourceManager::makeKey ( const std::string &  path,
const std::string &  query = "" 
)
static

Build a cache key from a path and optional ?query parameters.

在文件 Resource.cpp30 行定义.

引用了 normalizePath().

被这些函数引用 get(), eve::model3d::modelCacheKey(), eve::font::Font::newFontDataFromFile() , 以及 unload().

◆ normalizePath()

std::string eve::ResourceManager::normalizePath ( std::string  path)
static

Normalize a VFS path: backslashes to '/', strip leading "./" and trailing '/'.

在文件 Resource.cpp21 行定义.

引用了 c.

被这些函数引用 handlesPath(), makeKey(), pathOfKey(), reload() , 以及 unloadPath().

◆ pathOfKey()

std::string eve::ResourceManager::pathOfKey ( const std::string &  key)
static

The path part of a cache key (everything before the first '?').

在文件 Resource.cpp39 行定义.

引用了 normalizePath().

被这些函数引用 handlesPath(), reload() , 以及 unloadPath().

◆ refreshDependents()

void eve::ResourceManager::refreshDependents ( Resource updated,
std::set< std::string > &  visited 
)
protected

在文件 Resource.cpp185 行定义.

引用了 dependents, mu_, refreshEntry() , 以及 resources.

被这些函数引用 refreshEntry().

◆ refreshEntry()

bool eve::ResourceManager::refreshEntry ( const std::string &  key,
std::set< std::string > &  visited 
)
protected

◆ reload()

bool eve::ResourceManager::reload ( const std::string &  normPath)
overridevirtual

Reload everything referencing normPath. Returns true if anything changed.

重载 eve::caps::IAssetReloader .

在文件 Resource.cpp126 行定义.

引用了 mu_, normalizePath(), pathOfKey(), refreshEntry() , 以及 resources.

被这些函数引用 eve::sceneloader::SceneLoader::diff().

◆ reloadKind()

const char * eve::ResourceManager::reloadKind ( ) const
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.h129 行定义.

◆ 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.cpp89 行定义.

引用了 makeKey(), mu_ , 以及 resources.

◆ unloadPath()

void eve::ResourceManager::unloadPath ( const std::string &  path)

Drop every cache entry whose path matches, whatever its parameters.

在文件 Resource.cpp94 行定义.

引用了 mu_, normalizePath(), pathOfKey() , 以及 resources.

类成员变量说明

◆ mu_

std::mutex eve::ResourceManager::mu_
mutableprotected

◆ registered_

bool eve::ResourceManager::registered_ = false
protected

在文件 Resource.h143 行定义.

被这些函数引用 clear() , 以及 ensureRegistered().

◆ resources

std::map<std::string, ref<Resource> > eve::ResourceManager::resources
protected

在文件 Resource.h141 行定义.

被这些函数引用 clear(), count(), get(), handlesPath(), refreshDependents(), refreshEntry(), reload(), unload() , 以及 unloadPath().


该类的文档由以下文件生成: