Parses raw file data into IResource objects using registered ResourceFactory instances.
More...
#include <ResourceLoader.h>
|
| void | RegisterGlobalResourceFactories () |
| | Registers the built-in factories (Blob, JSON, Shader). Called during construction.
|
| |
| std::shared_ptr< ResourceFactory > | GetFactory (uint32_t format, uint32_t type, uint32_t version) |
| | Returns the factory registered for the given (format, type, version) triple.
|
| |
| std::shared_ptr< ResourceFactory > | GetFactory (uint32_t format, std::string typeName, uint32_t version) |
| | Returns the factory registered for the given (format, typeName, version) triple.
|
| |
| std::shared_ptr< ResourceInitData > | ReadResourceInitData (const std::string &filePath, std::shared_ptr< File > metaFileToLoad) |
| | Reads and parses the resource header from the meta-file to produce ResourceInitData.
|
| |
| std::shared_ptr< ResourceInitData > | ReadResourceInitDataLegacy (const std::string &filePath, std::shared_ptr< File > fileToLoad) |
| | Reads a legacy (pre-versioned) binary resource header.
|
| |
| std::shared_ptr< ResourceInitData > | ReadResourceInitDataXml (const std::string &filePath, std::shared_ptr< tinyxml2::XMLDocument > document) |
| | Reads an XML resource header from an XMLDocument.
|
| |
| std::shared_ptr< BinaryReader > | CreateBinaryReader (std::shared_ptr< File > fileToLoad, std::shared_ptr< ResourceInitData > initData) |
| | Creates a BinaryReader wrapping the buffer of a loaded File.
|
| |
| std::shared_ptr< tinyxml2::XMLDocument > | CreateXMLReader (std::shared_ptr< File > fileToLoad, std::shared_ptr< ResourceInitData > initData) |
| | Parses the buffer of a loaded File as XML and returns the resulting document.
|
| |
Parses raw file data into IResource objects using registered ResourceFactory instances.
ResourceLoader sits between the archive layer and the ResourceManager. Given a File and its associated ResourceInitData, it selects the appropriate ResourceFactory (matched by format, type, and version) and delegates deserialization to that factory.
New resource types are registered at startup via RegisterResourceFactory(). Built-in factories (Blob, JSON, Shader) are registered automatically in RegisterGlobalResourceFactories().
◆ ResourceLoader()
| Ship::ResourceLoader::ResourceLoader |
( |
std::shared_ptr< ResourceManager > |
resourceManager = nullptr | ) |
|
|
explicit |
◆ ~ResourceLoader()
| virtual Ship::ResourceLoader::~ResourceLoader |
( |
| ) |
|
|
virtual |
◆ CreateBinaryReader()
| std::shared_ptr< BinaryReader > Ship::ResourceLoader::CreateBinaryReader |
( |
std::shared_ptr< File > |
fileToLoad, |
|
|
std::shared_ptr< ResourceInitData > |
initData |
|
) |
| |
|
protected |
Creates a BinaryReader wrapping the buffer of a loaded File.
- Parameters
-
| fileToLoad | File whose buffer should be wrapped. |
| initData | Init data used to configure byte-order. |
- Returns
- Configured BinaryReader.
◆ CreateDefaultResourceInitData()
| static std::shared_ptr< ResourceInitData > Ship::ResourceLoader::CreateDefaultResourceInitData |
( |
| ) |
|
|
staticprotected |
◆ CreateXMLReader()
| std::shared_ptr< tinyxml2::XMLDocument > Ship::ResourceLoader::CreateXMLReader |
( |
std::shared_ptr< File > |
fileToLoad, |
|
|
std::shared_ptr< ResourceInitData > |
initData |
|
) |
| |
|
protected |
Parses the buffer of a loaded File as XML and returns the resulting document.
- Parameters
-
| fileToLoad | File whose buffer should be parsed. |
| initData | Init data (unused currently, reserved for future use). |
- Returns
- Parsed XMLDocument, or nullptr if parsing failed.
◆ GetFactory() [1/2]
| std::shared_ptr< ResourceFactory > Ship::ResourceLoader::GetFactory |
( |
uint32_t |
format, |
|
|
std::string |
typeName, |
|
|
uint32_t |
version |
|
) |
| |
|
protected |
Returns the factory registered for the given (format, typeName, version) triple.
- Returns
- Matching factory, or nullptr if none is registered.
◆ GetFactory() [2/2]
| std::shared_ptr< ResourceFactory > Ship::ResourceLoader::GetFactory |
( |
uint32_t |
format, |
|
|
uint32_t |
type, |
|
|
uint32_t |
version |
|
) |
| |
|
protected |
Returns the factory registered for the given (format, type, version) triple.
- Returns
- Matching factory, or nullptr if none is registered.
◆ GetResourceType()
| uint32_t Ship::ResourceLoader::GetResourceType |
( |
const std::string & |
type | ) |
|
Looks up the numeric type ID for a given type name string.
- Parameters
-
| type | Human-readable type name (e.g. "Texture"). |
- Returns
- Numeric type ID, or 0 if the type name is not registered.
◆ LoadResource() [1/2]
Deserializes a File into a fully constructed IResource.
Reads the resource header from fileToLoad, selects the matching factory, and calls ResourceFactory::ReadResource().
- Parameters
-
| identifier | Resource identifier (path/hash + owner + archive context). |
| fileToLoad | Raw file buffer as returned by the archive layer. |
| initData | Optional metadata overrides; pass nullptr to infer from the header. |
- Returns
- Deserialized IResource, or nullptr if no matching factory was found or parsing failed.
◆ LoadResource() [2/2]
| std::shared_ptr< IResource > Ship::ResourceLoader::LoadResource |
( |
std::string |
filePath, |
|
|
std::shared_ptr< File > |
fileToLoad, |
|
|
std::shared_ptr< ResourceInitData > |
initData = nullptr |
|
) |
| |
Compatibility overload that loads a resource by virtual path.
◆ ReadResourceInitData()
| std::shared_ptr< ResourceInitData > Ship::ResourceLoader::ReadResourceInitData |
( |
const std::string & |
filePath, |
|
|
std::shared_ptr< File > |
metaFileToLoad |
|
) |
| |
|
protected |
Reads and parses the resource header from the meta-file to produce ResourceInitData.
- Parameters
-
| filePath | Virtual path (for error messages). |
| metaFileToLoad | File containing the header (may be a separate ".meta" sidecar). |
- Returns
- Populated ResourceInitData, or nullptr if the header is invalid.
◆ ReadResourceInitDataBinary()
| static std::shared_ptr< ResourceInitData > Ship::ResourceLoader::ReadResourceInitDataBinary |
( |
const std::string & |
filePath, |
|
|
std::shared_ptr< BinaryReader > |
headerReader |
|
) |
| |
|
staticprotected |
Reads a standard binary resource header from a BinaryReader.
- Parameters
-
| filePath | Virtual path (for error messages). |
| headerReader | Reader positioned at the start of the binary header. |
- Returns
- Populated ResourceInitData, or nullptr on failure.
◆ ReadResourceInitDataLegacy()
| std::shared_ptr< ResourceInitData > Ship::ResourceLoader::ReadResourceInitDataLegacy |
( |
const std::string & |
filePath, |
|
|
std::shared_ptr< File > |
fileToLoad |
|
) |
| |
|
protected |
Reads a legacy (pre-versioned) binary resource header.
- Parameters
-
| filePath | Virtual path (for error messages). |
| fileToLoad | File containing the legacy header. |
- Returns
- Populated ResourceInitData, or nullptr on failure.
◆ ReadResourceInitDataPng()
| static std::shared_ptr< ResourceInitData > Ship::ResourceLoader::ReadResourceInitDataPng |
( |
const std::string & |
filePath, |
|
|
std::shared_ptr< BinaryReader > |
headerReader |
|
) |
| |
|
staticprotected |
Reads a PNG image header to produce ResourceInitData.
- Parameters
-
| filePath | Virtual path (for error messages). |
| headerReader | Reader positioned at the start of the PNG file. |
- Returns
- Populated ResourceInitData, or nullptr on failure.
◆ ReadResourceInitDataXml()
| std::shared_ptr< ResourceInitData > Ship::ResourceLoader::ReadResourceInitDataXml |
( |
const std::string & |
filePath, |
|
|
std::shared_ptr< tinyxml2::XMLDocument > |
document |
|
) |
| |
|
protected |
Reads an XML resource header from an XMLDocument.
- Parameters
-
| filePath | Virtual path (for error messages). |
| document | Parsed XML document containing the header. |
- Returns
- Populated ResourceInitData, or nullptr on failure.
◆ RegisterGlobalResourceFactories()
| void Ship::ResourceLoader::RegisterGlobalResourceFactories |
( |
| ) |
|
|
protected |
Registers the built-in factories (Blob, JSON, Shader). Called during construction.
◆ RegisterResourceFactory()
| bool Ship::ResourceLoader::RegisterResourceFactory |
( |
std::shared_ptr< ResourceFactory > |
factory, |
|
|
uint32_t |
format, |
|
|
std::string |
typeName, |
|
|
uint32_t |
type, |
|
|
uint32_t |
version |
|
) |
| |
Registers a factory so that ResourceLoader can handle a new resource type.
- Parameters
-
| factory | The factory implementation to register. |
| format | Format tag (RESOURCE_FORMAT_BINARY / RESOURCE_FORMAT_XML). |
| typeName | Human-readable type name string (e.g. "Texture"). |
| type | Numeric type identifier. |
| version | Resource format version this factory handles. |
- Returns
- true if registration succeeded; false if a factory with the same key already exists.
The documentation for this class was generated from the following file: