16#ifndef AEONGAMES_RESOURCEID_H
17#define AEONGAMES_RESOURCEID_H
21#include "aeongames/AeonEngine.hpp"
22#include "aeongames/CRC.hpp"
23#include "aeongames/ResourceFactory.hpp"
24#include "aeongames/ResourceCache.hpp"
40 mType{aType}, mPath{aPath} {}
44 ResourceId (
const std::string& aType,
const std::string& aPath ) :
45 mType{
crc32i ( aType.data(), aType.length() ) }, mPath{
crc32i ( aPath.data(), aPath.length() ) } {}
49 ResourceId (
const std::string& aType, uint32_t aPath ) :
50 mType{
crc32i ( aType.data(), aType.length() ) }, mPath{aPath} {}
54 ResourceId ( uint32_t aType,
const std::string& aPath ) :
55 mType{aType}, mPath{
crc32i ( aPath.data(), aPath.length() ) } {}
Identifies a resource by its type and path CRC32 hashes.
uint32_t GetType() const
Get the CRC32 hash of the resource type.
ResourceId()=default
Default constructor.
T * Get() const
Get the resource, loading and caching it if necessary.
ResourceId(uint32_t aType, const std::string &aPath)
Construct from a pre-computed type hash and a path string.
void Dispose() const
Remove the resource from the cache if present.
T * Cast() const
Cast the cached resource to the specified type without loading.
void Store() const
Construct and store the resource in the cache if not already present.
ResourceId(const std::string &aType, uint32_t aPath)
Construct from a type string and a pre-computed path hash.
ResourceId(const ResourceId &)=default
Copy constructor.
ResourceId(const std::string &aType, const std::string &aPath)
Construct from type and path strings (hashed internally).
std::string GetPathString() const
Get the original resource path string from the hash.
uint32_t GetPath() const
Get the CRC32 hash of the resource path.
ResourceId(uint32_t aType, uint32_t aPath)
Construct from pre-computed CRC32 hashes.
const void * GetRaw() const
Returns a const void pointer to the owned object.
T * Get() const
Returns a typed pointer to the owned object (const overload).
<- This is here just for the literals
DLL std::vector< std::string > GetResourcePath()
Get the list of resource search paths.
uint32_t crc32i(const char *message, size_t size, uint32_t previous_crc)
Compute the CRC32 of a given message, continuing from a previous CRC value.
DLL UniqueAnyPtr ConstructResource(const ResourceId &aResourceId)
Construct a resource identified by a ResourceId.
DLL const UniqueAnyPtr & StoreResource(uint32_t aKey, UniqueAnyPtr &&pointer)
Store a resource in the cache.
DLL UniqueAnyPtr DisposeResource(uint32_t aKey)
Remove and return a resource from the cache.
DLL const UniqueAnyPtr & GetResource(uint32_t aKey)
Retrieve a cached resource by key.