Resource::cResourceManager class

The implementation of IResourceManager; this should only be used for extending and detouring.

Base classes

class IResourceManager
IResourceManager is a singleton class used to access resources in Spore's file system.

Public types

using DatabaseList = eastl::list<Database*, CoreAllocatorAdapter<ICoreAllocator>>

Public functions

auto Initialize() -> bool override
auto Dispose() -> bool override
auto GetResource(const ResourceKey& name, ResourceObjectPtr* ppDst = nullptr, void* factoryData = 0, Database* pDatabase = nullptr, IResourceFactory* pFactory = nullptr, const ResourceKey* pCacheName = nullptr) -> bool override
Gets the resource that has the given ResourceKey name.
auto GetResourceAsync(const ResourceKey& name, ResourceObjectPtr* ppDst = nullptr, IAsyncRequestPtr* ppDstAsync = nullptr, void* arg_C = nullptr, void* factoryData = nullptr, Database* pDatabase = nullptr, IResourceFactory* pFactory = nullptr, const ResourceKey* pCacheName = nullptr) -> bool override
Similar usage to ResourceManager::GetResource(), but this method returns inmediately and loads the resource asynchronously.
auto GetLoadedResource(const ResourceKey& name, ResourceObjectPtr* pDst) -> bool override
Gets a resource from the resource cache in this manager.
auto ReloadResource(const ResourceKey& name, ResourceObject* pResource, void* pFactoryData = nullptr, Database* pDatabase = nullptr, IResourceFactory* pFactory = nullptr) -> bool override
auto GetPrivateResource(const ResourceKey& name, ResourceObjectPtr* ppDst = nullptr, void* pFactoryData = 0, Database* pDatabase = nullptr, IResourceFactory* pFactory = nullptr, const ResourceKey* pCacheName = nullptr) -> bool override
Similar usage to ResourceManager::GetResource .
auto WriteResource(const ResourceObject* pResource, void* pFactoryData = 0, Database* pDatabase = nullptr, IResourceFactory* pFactory = nullptr, const ResourceKey* pNameKey = nullptr) -> bool override
Writes the given resource to a package file.
auto SetTypeMapping(uint32_t resourceType, uint32_t* recordTypes, size_t count) -> void override
Maps all the record types to the given resource type.
auto GetRecordTypesFromResourceType(eastl::vector<uint32_t>& dst, uint32_t resourceType) -> size_t override
Gets all the record type IDs mapped to the given.
auto GetTypeMapping(uint32_t recordType) -> uint32_t override
Gets the general resource type ID that the given record type is assigned to.
auto FindRecord(const ResourceKey& nameKey, ResourceKey* pDst = nullptr, Database* pDatabase = nullptr) -> Database* override
Finds the real record key of a given resource, as well as the database that contaiend it.
auto GetResourceKeyList(eastl::vector<ResourceKey>& pDst, IKeyFilter* filter) -> size_t override
Gets a list of the keys of all the loaded resources in this manager.
auto GetRecordKeyList(eastl::vector<ResourceKey>& dst, IKeyFilter* filter, eastl::vector<Database*>* pDstDatabases = nullptr) -> size_t override
Gets all the file keys in this manager that match the criteria specified by the given request.
auto GetRecordKeyList2(eastl::vector<ResourceKey>& dst, IKeyFilter* filter, bool cached) -> size_t override
auto RegisterChangeNotification(bool, ChangeNotificationCallback_t callback, void* data, IKeyFilter* filter, int) -> bool override
auto RegisterFactory(bool add, IResourceFactory* pFactory, uint32_t arg_8) -> bool override
Adds or removes the given IResourceFactory to this manager.
auto FindFactory(uint32_t resourceTypeID, uint32_t recordTypeID = ResourceKey::kWildcardID) -> IResourceFactory* override
Returns the IResourceFactory that belongs to the specified typeID.
auto GetFactoryList(eastl::list<IResourceFactory*>& dst, uint32_t resourceTypeID = ResourceKey::kWildcardID) -> size_t override
Puts all the IResourceFactory instances that are assigned to the specified resourceTypeID into the given list.
auto RegisterDatabase(bool add, Database* pDatabase, int priority) -> bool override
Adds/removes the given DatabasePackedFile to this manager, using the priority specified.
auto IsDatabaseRegistered(Database* pDatabase, int* dstPriority = nullptr) -> bool override
Checks if a database is already registered in this manager, and optionally gets its priority.
auto FindDatabase(const ResourceKey& name) -> Database* override
Returns the first database that contains the given file.
auto GetDatabaseList(DatabaseList& dst, const ResourceKey* pFileKey = nullptr) -> size_t override
auto DoDatabaseChanged(Database* pDatabase, eastl::vector<ResourceKey>& keys) -> void override
Calls the registered database change listeners that were added with RegisterChangeNotification()
auto RegisterCache(bool add, ICache* pCache, int) -> bool override
auto FindCache(const ResourceKey& name) -> ICache* override
Returns the cache that contains a resource with this name (if any).
auto CacheResource(ResourceObject* pResource, bool) -> bool override
auto FlushCache(ICache* pCache, IKeyFilter* pFilter) -> void override
Removes certain (or all) elements from a cache.
auto GetCacheList(eastl::list<ICache*>& dst) -> size_t override
Puts all the resource caches used in this manager into the given list.
auto GetKeyFromName(const char16_t* fileName, uint32_t defaultTypeID = 0, uint32_t defaultGroupID = 0) -> ResourceKey override
Adds this file name to the list, so that it can be accessed using the corresponding ResourceKey.
auto GetNameFromKey(const ResourceKey& key, eastl::string16& dst) -> void override
Gets the file name that corresponds to the specified ResourceKey.
auto SetKeyName(const ResourceKey& key, const char16_t* fileName) -> bool override
Maps the given ResourceKey to the file name specified, which is in the format "groupID!instanceID.typeID".
auto ForgetKeyName(const ResourceKey& key) -> bool override
Removes the file name mapped for the given ResourceKey.
auto GetTypeFromTypename(const char16_t* typeName) -> uint32_t override
Returns the typeID that has the given extension mapped to it, or 0xFFFFFFFF if no typeID has this extension mapped.
auto GetTypenameFromType(uint32_t typeID) -> const char16_t* override
Returns the extension that is mapped to the given type ID, or nullptr if there's no mapping.
auto SetTypename(uint32_t typeID, const char16_t* pExtension) -> bool override
Maps the given typeID to the specified extension string.
auto ResetTypename(uint32_t typeID) -> bool override
Removes the extension the given typeID it is mapped to.

Protected types

template<typename Key, typename T, typename Allocator>
using adapter_hash_map = eastl::hash_map<Key, T, eastl::hash<Key>, eastl::equal_to<Key>, Allocator>
using FactoriesMap_t = adapter_hash_map<uint32_t, eastl::vector<eastl::pair<IResourceFactoryPtr, uint32_t>>, ICoreAllocatorAdapter>
using ResourceTypeToRecordTypeMap_t = adapter_hash_map<uint32_t, eastl::vector<uint32_t>, ICoreAllocatorAdapter>
using RecordTypeToResourceTypeMap_t = adapter_hash_map<uint32_t, uint32_t, ICoreAllocatorAdapter>
using ExtensionsMap_t = adapter_hash_map<uint32_t, eastl::string16, ICoreAllocatorAdapter>
using FilenamesMap_t = adapter_hash_map<ResourceKey, eastl::string16, FixedPoolAllocatorAdapter>
using CacheVector_t = eastl::vector<eastl::pair<ICache*, int>>

Protected variables

bool mbNeedsToRelease
ICoreAllocator* mpAllocator
eastl::map<int, int, eastl::less<ResourceKey>, ICoreAllocatorAdapter> mChangeNotifications
void* field_2C
FactoriesMap_t mResourceFactories
ResourceTypeToRecordTypeMap_t mResourceTypeToRecordType
RecordTypeToResourceTypeMap_t mRecordTypeToResourceType
CacheVector_t mCacheVector
ExtensionsMap_t mExtensionMappings
FixedPoolAllocator field_D4
FilenamesMap_t mFilenameMapping
Mutex field_118
Mutex field_148

Function documentation

bool Resource::cResourceManager::GetResource(const ResourceKey& name, ResourceObjectPtr* ppDst = nullptr, void* factoryData = 0, Database* pDatabase = nullptr, IResourceFactory* pFactory = nullptr, const ResourceKey* pCacheName = nullptr) override

Gets the resource that has the given ResourceKey name.

Parameters
name in The ResourceKey name to find. If the typeID is mapped in the manager to other alternative typeIDs, all them will be tested.
ppDst out [Optional] A pointer to a ResourceObject*. It will be assigned with the generated resource.
factoryData in [Optional] Additional data that is passed to the resource factory, usually null.
pDatabase in [Optional] The Database where the file will be searched. Use nullptr to search in all available databases.
pFactory in [Optional] The IResourceFactory used to generate the resource. Use nullptr to use the appropiate factory according to the typeID mapping in this manager.
pCacheName in [Optional] The ResourceKey name used to search the resource in the cache.
Returns True if the resource was found or generated, false otherwise.

If the resource is contained in the cache, that will be used. The name will be modified to use the correct types, according to the mappings in this manager. The resource will be seached in all the databases in this manager, unless a specific one is specified. Once the file is found, the correct factory will be used to generate the appropiate resource, unless a specific IResourceFactory is specified.

bool Resource::cResourceManager::GetResourceAsync(const ResourceKey& name, ResourceObjectPtr* ppDst = nullptr, IAsyncRequestPtr* ppDstAsync = nullptr, void* arg_C = nullptr, void* factoryData = nullptr, Database* pDatabase = nullptr, IResourceFactory* pFactory = nullptr, const ResourceKey* pCacheName = nullptr) override

Similar usage to ResourceManager::GetResource(), but this method returns inmediately and loads the resource asynchronously.

Parameters
name in
ppDst out
ppDstAsync out
arg_C in
factoryData in
pDatabase in
pFactory in
pCacheName in

bool Resource::cResourceManager::GetLoadedResource(const ResourceKey& name, ResourceObjectPtr* pDst) override

Gets a resource from the resource cache in this manager.

Parameters
name
pDst
Returns True if the file was present in the cache, false otherwise.

If it isn't present in the cache, nothing will happen.

bool Resource::cResourceManager::GetPrivateResource(const ResourceKey& name, ResourceObjectPtr* ppDst = nullptr, void* pFactoryData = 0, Database* pDatabase = nullptr, IResourceFactory* pFactory = nullptr, const ResourceKey* pCacheName = nullptr) override

Similar usage to ResourceManager::GetResource .

Parameters
name in The ResourceKey name to find. If the typeID is mapped in the manager to other alternative typeIDs, all them will be tested.
ppDst out [Optional] A pointer to a ResourceObject*. It will be assigned with the generated resource.
pFactoryData
pDatabase in [Optional] The Database where the file will be searched. Use nullptr to search in all available databases.
pFactory in [Optional] The IResourceFactory used to generate the resource. Use nullptr to use the appropiate factory according to the typeID mapping in this manager.
pCacheName in [Optional] The ResourceKey name used to search the resource in the cache.
Returns True if the resource was successfully generated and read, false otherwise.

This method does not check the cache, however, therefore always generating a new resource.

bool Resource::cResourceManager::WriteResource(const ResourceObject* pResource, void* pFactoryData = 0, Database* pDatabase = nullptr, IResourceFactory* pFactory = nullptr, const ResourceKey* pNameKey = nullptr) override

Writes the given resource to a package file.

Returns True if the resource was successfuly written, false otherwise.

If the database is specified in this method, a new file will always be created on it even if it does not exist yet; however, if no database is specified, the resource will be written in the first database that contains a file with the given name. If there is a problem while writing the resource, the file on the database will be deleted.

void Resource::cResourceManager::SetTypeMapping(uint32_t resourceType, uint32_t* recordTypes, size_t count) override

Maps all the record types to the given resource type.

Parameters
resourceType
recordTypes
count Number of entries in recordTypes

size_t Resource::cResourceManager::GetRecordTypesFromResourceType(eastl::vector<uint32_t>& dst, uint32_t resourceType) override

Gets all the record type IDs mapped to the given.

Parameters
dst out
resourceType
Returns The number of record types mapped.

uint32_t Resource::cResourceManager::GetTypeMapping(uint32_t recordType) override

Gets the general resource type ID that the given record type is assigned to.

Parameters
recordType
Returns

Record types are the ones found in files, whereas resource types are for ResourceObject (for example, .raster and .rw4 are different record types but they all map to the same resource type).

Database* Resource::cResourceManager::FindRecord(const ResourceKey& nameKey, ResourceKey* pDst = nullptr, Database* pDatabase = nullptr) override

Finds the real record key of a given resource, as well as the database that contaiend it.

Parameters
nameKey in The original ResourceKey of the file.
pDst out [Optional] The ResourceKey where the real key of the file will be put, with the correct typeID.
pDatabase in [Optional] The database where the file will be searched. If not specified, it will be searched in all available databases.
Returns The database that contains this file, or null if it is not in any database.

size_t Resource::cResourceManager::GetResourceKeyList(eastl::vector<ResourceKey>& pDst, IKeyFilter* filter) override

Gets a list of the keys of all the loaded resources in this manager.

Parameters
pDst out
filter

size_t Resource::cResourceManager::GetRecordKeyList(eastl::vector<ResourceKey>& dst, IKeyFilter* filter, eastl::vector<Database*>* pDstDatabases = nullptr) override

Gets all the file keys in this manager that match the criteria specified by the given request.

Parameters
dst out The vector where all the files ResourceKey names will be added.
filter in The criteria that the files must match in order to be added to the vector.
pDstDatabases out [Optional] A vector where all the Database objects that contained the files will be added.
Returns The number of file keys that matched the criteria.

If request is nullptr, all the files in the manager will be given.

bool Resource::cResourceManager::RegisterFactory(bool add, IResourceFactory* pFactory, uint32_t arg_8) override

Adds or removes the given IResourceFactory to this manager.

Parameters
add If true, pFactory will be added to the manager; if false, it will be removed from the manager.
pFactory The IResourceFactory to add to/remove from this manager.
arg_8 Unknown usage, usually 0.
Returns True if the factory was successfully added/removed, false otherwise.

Resource factories are used to generate resource objects depending on their type. The factory will be assigned to the types returned by IResourceFactory::GetSupportedTypes.

IResourceFactory* Resource::cResourceManager::FindFactory(uint32_t resourceTypeID, uint32_t recordTypeID = ResourceKey::kWildcardID) override

Returns the IResourceFactory that belongs to the specified typeID.

Parameters
resourceTypeID
recordTypeID
Returns

If recordTypeID is ResourceKey::kWildcardID, the first factory assigned to the resourceTypeID will be returned; Otherwise, IResourceFactory::CanConvert() will be called on every factory using the types provided here, and the first one that returns true will be returned.

size_t Resource::cResourceManager::GetFactoryList(eastl::list<IResourceFactory*>& dst, uint32_t resourceTypeID = ResourceKey::kWildcardID) override

Puts all the IResourceFactory instances that are assigned to the specified resourceTypeID into the given list.

Parameters
dst out
resourceTypeID in
Returns The number of factories found.

If resourceTypeID is ResourceKey::kWildcardID, all the factories in this manager will be added.

bool Resource::cResourceManager::RegisterDatabase(bool add, Database* pDatabase, int priority) override

Adds/removes the given DatabasePackedFile to this manager, using the priority specified.

Parameters
add If true, the database is added to the manager; if false, the database is removed from the manager
pDatabase The database to add/remove
priority The priority of this database, this determines in which order files are searched in databases
Returns Whether the database was registered or not.

The priority of a database is used when getting files from the resource manager; since a certain file name can be contained in multiple packages, the one with the most priority will be chosen. The usage of the first argument is unknown, but it is usually 'true'.

bool Resource::cResourceManager::IsDatabaseRegistered(Database* pDatabase, int* dstPriority = nullptr) override

Checks if a database is already registered in this manager, and optionally gets its priority.

Parameters
pDatabase in The database
dstPriority out [Optional] A pointer to an integer that will contain the priority. This parameter can be nullptr.
Returns True if the manager contained the database, false otherwise.

Database* Resource::cResourceManager::FindDatabase(const ResourceKey& name) override

Returns the first database that contains the given file.

Parameters
name
Returns name

Databases are searched in descending order of priority.

void Resource::cResourceManager::DoDatabaseChanged(Database* pDatabase, eastl::vector<ResourceKey>& keys) override

Calls the registered database change listeners that were added with RegisterChangeNotification()

Parameters
pDatabase
keys

ICache* Resource::cResourceManager::FindCache(const ResourceKey& name) override

Returns the cache that contains a resource with this name (if any).

Parameters
name

void Resource::cResourceManager::FlushCache(ICache* pCache, IKeyFilter* pFilter) override

Removes certain (or all) elements from a cache.

Parameters
pCache
pFilter

size_t Resource::cResourceManager::GetCacheList(eastl::list<ICache*>& dst) override

Puts all the resource caches used in this manager into the given list.

Returns The number of caches.

ResourceKey Resource::cResourceManager::GetKeyFromName(const char16_t* fileName, uint32_t defaultTypeID = 0, uint32_t defaultGroupID = 0) override

Adds this file name to the list, so that it can be accessed using the corresponding ResourceKey.

Parameters
fileName
defaultTypeID [Optional] Type ID used if the file name does not have an extension
defaultGroupID [Optional] Group ID used if the file name does not have a folder
Returns True if the file name was mapped successfully, false otherwise. Returns the resource key that maps to the given file name.

The file name is in the format "groupID!instanceID.typeID", and it will be mapped to the key generated using the ResourceKey::Parse function.

void Resource::cResourceManager::GetNameFromKey(const ResourceKey& key, eastl::string16& dst) override

Gets the file name that corresponds to the specified ResourceKey.

Parameters
key in The ResourceKey that will be represented as a eastl::string.
dst out A string16 that will contain the resulting text.

The file name will be in the format "groupID!instanceID.typeID". The file name can be parsed to a key again using the ResourceKey::Parse() method. A file name wil be generated even if it's not mapped; when that happens, the ResourceKey members are displayed in hexadecimal format.

bool Resource::cResourceManager::SetKeyName(const ResourceKey& key, const char16_t* fileName) override

Maps the given ResourceKey to the file name specified, which is in the format "groupID!instanceID.typeID".

Parameters
key
fileName
Returns True if it was successfully mapped.

The file name can be parsed to a key again using the ResourceKey::Parse method.

bool Resource::cResourceManager::ForgetKeyName(const ResourceKey& key) override

Removes the file name mapped for the given ResourceKey.

Parameters
key
Returns True if the file name mapping was removed, false if it did not exist.

The file name can be parsed to a key again using the ResourceKey::Parse method.

uint32_t Resource::cResourceManager::GetTypeFromTypename(const char16_t* typeName) override

Returns the typeID that has the given extension mapped to it, or 0xFFFFFFFF if no typeID has this extension mapped.

Parameters
typeName

const char16_t* Resource::cResourceManager::GetTypenameFromType(uint32_t typeID) override

Returns the extension that is mapped to the given type ID, or nullptr if there's no mapping.

Parameters
typeID

bool Resource::cResourceManager::SetTypename(uint32_t typeID, const char16_t* pExtension) override

Maps the given typeID to the specified extension string.

Parameters
typeID
pExtension
Returns True if the extension was successfully mapped or already existed, false if the typeID was mapped to a different extension.

bool Resource::cResourceManager::ResetTypename(uint32_t typeID) override

Removes the extension the given typeID it is mapped to.

Parameters
typeID
Returns True if the extension existed and was removed, false otherwise.