4#include <unordered_map>
53 explicit ResourceLoader(std::shared_ptr<ResourceManager> resourceManager =
nullptr);
68 std::shared_ptr<ResourceInitData> initData =
nullptr);
73 std::shared_ptr<IResource>
LoadResource(std::string filePath, std::shared_ptr<File> fileToLoad,
74 std::shared_ptr<ResourceInitData> initData =
nullptr);
87 uint32_t type, uint32_t version);
104 std::shared_ptr<ResourceFactory>
GetFactory(uint32_t format, uint32_t type, uint32_t version);
110 std::shared_ptr<ResourceFactory>
GetFactory(uint32_t format, std::string typeName, uint32_t version);
119 std::shared_ptr<File> metaFileToLoad);
131 std::shared_ptr<File> fileToLoad);
140 std::shared_ptr<BinaryReader> headerReader);
149 std::shared_ptr<tinyxml2::XMLDocument> document);
158 std::shared_ptr<BinaryReader> headerReader);
167 std::shared_ptr<ResourceInitData> initData);
175 std::shared_ptr<tinyxml2::XMLDocument>
CreateXMLReader(std::shared_ptr<File> fileToLoad,
176 std::shared_ptr<ResourceInitData> initData);
179 std::string DecodeASCII(uint32_t value);
180 std::unordered_map<std::string, uint32_t> mResourceTypes;
181 std::unordered_map<ResourceFactoryKey, std::shared_ptr<ResourceFactory>,
ResourceFactoryKeyHash> mFactories;
182 std::shared_ptr<ResourceManager> mResourceManager;
Uniquely identifies a cached resource by path/hash, owner, and source archive.
Definition ResourceIdentifier.h:15
Parses raw file data into IResource objects using registered ResourceFactory instances.
Definition ResourceLoader.h:51
std::shared_ptr< IResource > LoadResource(std::string filePath, std::shared_ptr< File > fileToLoad, std::shared_ptr< ResourceInitData > initData=nullptr)
Compatibility overload that loads a resource by virtual path.
bool 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.
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.
static std::shared_ptr< ResourceInitData > ReadResourceInitDataBinary(const std::string &filePath, std::shared_ptr< BinaryReader > headerReader)
Reads a standard binary resource header from a BinaryReader.
uint32_t GetResourceType(const std::string &type)
Looks up the numeric type ID for a given type name string.
static std::shared_ptr< ResourceInitData > CreateDefaultResourceInitData()
Creates a ResourceInitData with default/zeroed fields.
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< IResource > LoadResource(const ResourceIdentifier &identifier, std::shared_ptr< File > fileToLoad, std::shared_ptr< ResourceInitData > initData=nullptr)
Deserializes a File into a fully constructed IResource.
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.
void RegisterGlobalResourceFactories()
Registers the built-in factories (Blob, JSON, Shader). Called during construction.
std::shared_ptr< ResourceInitData > ReadResourceInitDataLegacy(const std::string &filePath, std::shared_ptr< File > fileToLoad)
Reads a legacy (pre-versioned) binary resource header.
virtual ~ResourceLoader()
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< ResourceFactory > GetFactory(uint32_t format, uint32_t type, uint32_t version)
Returns the factory registered for the given (format, type, version) triple.
static std::shared_ptr< ResourceInitData > ReadResourceInitDataPng(const std::string &filePath, std::shared_ptr< BinaryReader > headerReader)
Reads a PNG image header to produce ResourceInitData.
ResourceLoader(std::shared_ptr< ResourceManager > resourceManager=nullptr)
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14
std::hash specialization for ResourceFactoryKey, used by the factory map.
Definition ResourceLoader.h:34
std::size_t operator()(const ResourceFactoryKey &key) const
Definition ResourceLoader.h:35
Cache key that uniquely identifies a ResourceFactory by format, type, and version.
Definition ResourceLoader.h:19
uint32_t resourceType
Numeric resource type identifier (see ResourceType).
Definition ResourceLoader.h:23
uint32_t resourceVersion
Version of the resource format this factory handles.
Definition ResourceLoader.h:25
uint32_t resourceFormat
Format tag (RESOURCE_FORMAT_BINARY or RESOURCE_FORMAT_XML).
Definition ResourceLoader.h:21
bool operator==(const ResourceFactoryKey &o) const
Definition ResourceLoader.h:27