16#include <unordered_map>
17#include "aeongames/ResourceCache.hpp"
18#include "aeongames/ResourceFactory.hpp"
19#include "aeongames/ResourceId.hpp"
23 static std::unordered_map<uint32_t, UniqueAnyPtr> gResourceStore{};
27 gResourceStore.clear();
32 for (
auto& i : gResourceStore )
34 if ( !aEnumerator ( i.first, i.second ) )
45 if ( pointer.GetRaw() )
47 gResourceStore.emplace ( std::make_pair<> ( aKey, std::move ( pointer ) ) );
48 return gResourceStore[aKey];
50 return unique_nullptr;
56 auto i = gResourceStore.find ( aKey );
57 if ( i != gResourceStore.end() )
59 result.
Swap ( ( *i ).second );
60 gResourceStore.erase ( i );
68 auto i = gResourceStore.find ( aKey );
69 if ( i != gResourceStore.end() )
73 return unique_nullptr;
78 auto i = gResourceStore.find ( aResourceId.
GetPath() );
79 if ( i != gResourceStore.end() )
Identifies a resource by its type and path CRC32 hashes.
uint32_t GetType() const
Get the CRC32 hash of the resource type.
uint32_t GetPath() const
Get the CRC32 hash of the resource path.
A type-erased owning smart pointer with unique ownership semantics.
void Swap(UniqueAnyPtr &aUniqueAnyPtr) noexcept
Swaps the contents of this pointer with another.
<- This is here just for the literals
DLL const UniqueAnyPtr & GetDefaultResource(uint32_t aType)
Get the default resource for a given type.
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.
DLL void EnumerateResources(const std::function< bool(uint32_t, const UniqueAnyPtr &) > &aEnumerator)
Enumerate all cached resources.
DLL void ClearAllResources()
Remove all resources from the cache.