Resource is a game object that is managed by the ResourceManager. It can be loaded from a file or generated at runtime. If the resource is loaded from file, a monitor will be created to watch the file changes. When the file is modified, the resource will be reloaded. If the resource is generated at runtime, it can depend on a few other resources and the ResourceManager will update the resource when the dependencies are changed. 更多...
#include <Resource.h>
Public 成员函数 | |
| virtual | ~Resource () |
| Releases Resource resources. | |
| Resource (const Resource &)=delete | |
| Resources own keep-alive pins, so they are not copyable. | |
| Resource & | operator= (const Resource &)=delete |
| std::string | getUri () const |
| Returns the uri. | |
| EVENGINE_API_FOUNDATION std::vector< Resource * > | getDependencies () const |
| Borrowed views of the resources this instance keeps alive. | |
| EVENGINE_API_FOUNDATION eve::Result< void > | addDependency (Resource &dependency) |
Keeps dependency alive for as long as this instance lives. | |
| virtual void | adopt (eve::Resource &replacement)=0 |
Replace this instance's contents with replacement's. The ResourceManager keeps instance identity stable across reloads, so existing holders (raw pointers, refs, script instances) keep a valid object. Subclasses move the payload out of replacement, which is drained and destroyed by the caller afterwards. replacement must be the same concrete type as this. Implementations must use a reversible swap and either complete without throwing or leave both objects unchanged; ResourceManager uses the drained candidate to roll back a later failure in the same dependency transaction. | |
Protected 成员函数 | |
| Resource (std::string uri) | |
| Constructs a Resource. | |
| void | setUri (std::string value) |
| Set the resource URI (the cache key). Used by ResourceManager. | |
Protected 属性 | |
| std::string | uri |
| std::vector< ResourcePin > | dependencies |
| Keep-alive pins; see getDependencies()/addDependency(). | |
友元 | |
| class | ResourceManager |
详细描述
Resource is a game object that is managed by the ResourceManager. It can be loaded from a file or generated at runtime. If the resource is loaded from file, a monitor will be created to watch the file changes. When the file is modified, the resource will be reloaded. If the resource is generated at runtime, it can depend on a few other resources and the ResourceManager will update the resource when the dependencies are changed.
Resource ID format:
- File: file://path/to/file
- Generated: res://category/name
- Online: http://example.com/path/to/resource
- Save: save://path/name
- Config: config://name
The ResourceManager cache keys file-backed resources by their normalized VFS path, optionally with ?param=value suffixes for parameters that change the decoded asset (e.g. a font's pixel size). See ResourceManager::makeKey.
在文件 Resource.h 第 51 行定义.
构造及析构函数说明
◆ ~Resource()
|
inlinevirtual |
Releases Resource resources.
在文件 Resource.h 第 54 行定义.
◆ Resource() [1/2]
|
delete |
Resources own keep-alive pins, so they are not copyable.
The pins in dependencies are move-only, which already deletes both special members implicitly; declaring that intent is not cosmetic. Under the SHARED linkage the resource subclasses are dllexport, and MSVC then tries to emit every special member it would export – including the implicitly deleted copy assignment – which turns a silent deletion into a hard C2280 in every translation unit that merely includes the subclass (image/sound/font/graphics resource loaders). A user-declared = delete is not emitted, so the exported subclass stays well-formed, exactly like the in-module out-of-line special members the OBJECT route already needs.
◆ Resource() [2/2]
|
inlineprotected |
Constructs a Resource.
在文件 Resource.h 第 114 行定义.
成员函数说明
◆ addDependency()
| eve::Result< void > eve::Resource::addDependency | ( | Resource & | dependency | ) |
Keeps dependency alive for as long as this instance lives.
- 参数
-
dependency A resource the cache currently owns (see ResourceManager::pin).
- 返回
- Applied, or NotFound/Failed when
dependencyis not cached. @ownership The cache keeps owningdependency; this instance only postpones its destruction across unload()/clear()/reload. @lifetime The pin is released when this instance is destroyed. @thread Same thread as the owning ResourceManager. @reentrancy Registers a pin only; it never invokes callbacks.
在文件 Resource.cpp 第 511 行定义.
引用了 eve::Applied, dependencies, eve::Result< T >::failure(), eve::ResourceManager::getInstance(), eve::ResourceManager::pin(), pinned, eve::Status::success() , 以及 eve::Result< T >::success().
◆ adopt()
|
pure virtual |
Replace this instance's contents with replacement's. The ResourceManager keeps instance identity stable across reloads, so existing holders (raw pointers, refs, script instances) keep a valid object. Subclasses move the payload out of replacement, which is drained and destroyed by the caller afterwards. replacement must be the same concrete type as this. Implementations must use a reversible swap and either complete without throwing or leave both objects unchanged; ResourceManager uses the drained candidate to roll back a later failure in the same dependency transaction.
在 eve::font::FontData, eve::image::ImageData, eve::model3d::ModelData , 以及 eve::sound::SoundData 内被实现.
◆ getDependencies()
| std::vector< Resource * > eve::Resource::getDependencies | ( | ) | const |
Borrowed views of the resources this instance keeps alive.
- 返回
- One borrowed entry per registered dependency, in registration order. @ownership Borrowed; the dependency stays owned by the resource cache. @nullable No entry is null while this instance holds its keep-alive pins. @lifetime Valid until this instance is destroyed or a pin is released; callers must not retain the pointers across either. @thread Same thread as the owning ResourceManager. @reentrancy Side-effect free.
在文件 Resource.cpp 第 504 行定义.
引用了 borrowed , 以及 dependencies.
被这些函数引用 eve::ResourceManager::reload().
◆ getUri()
|
inline |
◆ operator=()
◆ setUri()
|
inlineprotected |
Set the resource URI (the cache key). Used by ResourceManager.
在文件 Resource.h 第 117 行定义.
被这些函数引用 eve::ResourceManager::loadUncached().
友元及相关函数文档
◆ ResourceManager
|
friend |
在文件 Resource.h 第 119 行定义.
类成员变量说明
◆ dependencies
|
protected |
Keep-alive pins; see getDependencies()/addDependency().
在文件 Resource.h 第 123 行定义.
被这些函数引用 addDependency() , 以及 getDependencies().
◆ uri
|
protected |
在文件 Resource.h 第 121 行定义.
该类的文档由以下文件生成:
- src/engine/common/Resource.h
- src/engine/common/Resource.cpp