libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
Ship::ResourceManager Class Reference

Central manager for loading, caching, and unloading game resources. More...

#include <ResourceManager.h>

Inheritance diagram for Ship::ResourceManager:
[legend]
Collaboration diagram for Ship::ResourceManager:
[legend]

Public Member Functions

 ResourceManager (std::shared_ptr< ThreadPool > threadPool=nullptr, std::shared_ptr< Keystore > keystore=nullptr)
 
 ~ResourceManager ()
 
std::shared_ptr< ArchiveManagerGetArchiveManager ()
 Returns the ArchiveManager that manages the mounted archives.
 
std::shared_ptr< ResourceLoaderGetResourceLoader ()
 Returns the ResourceLoader responsible for deserializing file data.
 
std::shared_ptr< IResourceGetCachedResource (const std::string &filePath, bool loadExact=false)
 Returns a resource from the cache if present, without loading from disk.
 
std::shared_ptr< IResourceGetCachedResource (const ResourceIdentifier &identifier, bool loadExact=false)
 Returns a resource from the cache using a ResourceIdentifier.
 
std::shared_ptr< IResourceLoadResource (const std::string &filePath, bool loadExact=false, std::shared_ptr< ResourceInitData > initData=nullptr)
 Loads a resource synchronously, returning it from the cache if already loaded.
 
template<typename T >
std::shared_ptr< T > LoadResource (const std::string &filePath, bool loadExact=false, std::shared_ptr< ResourceInitData > initData=nullptr)
 Loads a resource synchronously, cast to the concrete type T.
 
std::shared_ptr< IResourceLoadResource (const ResourceIdentifier &identifier, bool loadExact=false, std::shared_ptr< ResourceInitData > initData=nullptr)
 Loads a resource synchronously by ResourceIdentifier.
 
template<typename T >
std::shared_ptr< T > LoadResource (const ResourceIdentifier &identifier, bool loadExact=false, std::shared_ptr< ResourceInitData > initData=nullptr)
 Loads a resource synchronously by ResourceIdentifier, cast to the concrete type T.
 
std::shared_ptr< IResourceLoadResource (uint64_t crc, bool loadExact=false, std::shared_ptr< ResourceInitData > initData=nullptr)
 Loads a resource synchronously by content-hash CRC.
 
std::shared_ptr< IResourceLoadResourceProcess (const std::string &filePath, bool loadExact=false, std::shared_ptr< ResourceInitData > initData=nullptr)
 Loads a resource synchronously, bypassing the cache.
 
std::shared_ptr< IResourceLoadResourceProcess (const ResourceIdentifier &identifier, bool loadExact=false, std::shared_ptr< ResourceInitData > initData=nullptr)
 Loads a resource synchronously by ResourceIdentifier, bypassing the cache.
 
std::shared_future< std::shared_ptr< IResource > > LoadResourceAsync (const std::string &filePath, bool loadExact=false, BS::priority_t priority=BS::pr::normal, std::shared_ptr< ResourceInitData > initData=nullptr)
 Schedules an asynchronous resource load and returns a future.
 
std::shared_future< std::shared_ptr< IResource > > LoadResourceAsync (const ResourceIdentifier &identifier, bool loadExact=false, BS::priority_t priority=BS::pr::normal, std::shared_ptr< ResourceInitData > initData=nullptr)
 Schedules an asynchronous resource load by ResourceIdentifier.
 
size_t UnloadResource (const ResourceIdentifier &identifier)
 Removes a resource from the cache by ResourceIdentifier.
 
size_t UnloadResource (const std::string &filePath)
 Removes a resource from the cache by path.
 
bool WriteResource (const ResourceIdentifier &identifier, const std::vector< uint8_t > &data, bool unloadFile)
 Writes raw data into an archive and optionally evicts the stale cache entry.
 
bool WriteResource (uint64_t hash, const std::vector< uint8_t > &data, bool unloadFile)
 Writes raw data into an archive by hash and optionally evicts the stale cache entry.
 
std::shared_ptr< std::vector< std::shared_ptr< IResource > > > LoadResources (const std::string &searchMask)
 Loads all resources whose paths match the given glob mask.
 
std::shared_ptr< std::vector< std::shared_ptr< IResource > > > LoadResources (const ResourceFilter &filter)
 Loads all resources matching the given filter.
 
std::shared_future< std::shared_ptr< std::vector< std::shared_ptr< IResource > > > > LoadResourcesAsync (const std::string &searchMask, BS::priority_t priority=BS::pr::normal)
 Asynchronously loads all resources matching a glob mask.
 
std::shared_future< std::shared_ptr< std::vector< std::shared_ptr< IResource > > > > LoadResourcesAsync (const ResourceFilter &filter, BS::priority_t priority=BS::pr::normal)
 Asynchronously loads all resources matching a filter.
 
void DirtyResources (const std::string &searchMask)
 Marks as dirty all cached resources whose paths match a glob mask.
 
void DirtyResources (const ResourceFilter &filter)
 Marks as dirty all cached resources matching a filter.
 
void UnloadResources (const std::string &searchMask)
 Synchronously unloads all resources matching a glob mask.
 
void UnloadResources (const ResourceFilter &filter)
 Synchronously unloads all resources matching a filter.
 
void UnloadResourcesAsync (const std::string &searchMask, BS::priority_t priority=BS::pr::normal)
 Asynchronously unloads all resources matching a glob mask.
 
void UnloadResourcesAsync (const ResourceFilter &filter, BS::priority_t priority=BS::pr::normal)
 Asynchronously unloads all resources matching a filter.
 
bool OtrSignatureCheck (const char *fileName)
 Checks whether a file is a valid OTR archive by reading its header signature.
 
bool IsAltAssetsEnabled ()
 Returns whether alt-asset (mod) loading is currently enabled.
 
void SetAltAssetsEnabled (bool isEnabled)
 Enables or disables alt-asset (mod) loading.
 
std::shared_ptr< FileLoadFileProcess (const ResourceIdentifier &identifier)
 Loads raw file bytes from the archive, bypassing resource deserialization.
 
std::shared_ptr< FileLoadFileProcess (const std::string &filePath)
 Loads raw file bytes from the archive by path.
 
std::shared_ptr< FileLoadFileProcess (uint64_t hash)
 Loads raw file bytes from the archive by hash.
 
size_t GetResourceSize (std::shared_ptr< IResource > resource)
 Returns the byte size of the payload of a loaded resource.
 
size_t GetResourceSize (const char *name)
 Returns the byte size of the payload of a resource identified by path.
 
size_t GetResourceSize (uint64_t crc)
 Returns the byte size of the payload of a resource identified by CRC.
 
bool GetResourceIsCustom (std::shared_ptr< IResource > resource)
 Returns true if the given resource originated from an alt-assets override.
 
bool GetResourceIsCustom (const char *name)
 Returns true if the resource at the given path is an alt-asset override.
 
bool GetResourceIsCustom (uint64_t crc)
 Returns true if the resource identified by CRC is an alt-asset override.
 
void * GetResourceRawPointer (std::shared_ptr< IResource > resource)
 Returns a type-erased raw pointer to the resource payload.
 
void * GetResourceRawPointer (const char *name)
 Returns a type-erased raw pointer to the payload of a resource by path.
 
void * GetResourceRawPointer (uint64_t crc)
 Returns a type-erased raw pointer to the payload of a resource by CRC.
 
- Public Member Functions inherited from Ship::Component
 Component (const std::string &name, std::shared_ptr< Context > context=nullptr)
 Constructs a Component with the given name.
 
virtual ~Component ()
 
void Init (const nlohmann::json &initArgs=nlohmann::json::object())
 Performs one-time initialization of this component.
 
bool IsInitialized () const
 Returns true once Init() (or MarkInitialized()) has completed successfully.
 
const std::string & GetName () const
 Returns the name of this Component.
 
std::string ToString () const
 Returns a human-readable string representation (e.g. "Name (id)").
 
std::string ToTreeString (int depth=0) const
 Returns a human-readable tree representation of this component and its children.
 
 operator std::string () const
 Conversion operator to std::string; equivalent to ToString().
 
ParentComponentListGetParents ()
 Returns a mutable reference to the parent list.
 
const ParentComponentListGetParents () const
 Returns a const reference to the parent list.
 
ComponentListGetChildren ()
 Returns a mutable reference to the child list.
 
const ComponentListGetChildren () const
 Returns a const reference to the child list.
 
virtual std::shared_ptr< ComponentTryGetSharedComponent () noexcept
 Returns a shared_ptr to this Component when available, otherwise nullptr.
 
virtual std::shared_ptr< ComponentGetSharedComponent ()
 Returns a shared_ptr to this Component via the correct enable_shared_from_this base.
 
template<typename T >
bool HasInChildren () const
 Checks whether any descendant Component matches type T via BFS.
 
template<typename T >
std::shared_ptr< T > GetFirstInChildren () const
 Returns the first descendant that matches type T via BFS.
 
template<typename T >
std::shared_ptr< std::vector< std::shared_ptr< T > > > GetInChildren () const
 Returns all descendants that match type T via BFS.
 
template<typename T >
bool HasInParents () const
 Checks whether any ancestor Component matches type T via BFS.
 
template<typename T >
std::shared_ptr< T > GetFirstInParents () const
 Returns the first ancestor that matches type T via BFS.
 
template<typename T >
std::shared_ptr< std::vector< std::shared_ptr< T > > > GetInParents () const
 Returns all ancestors that match type T via BFS.
 
- Public Member Functions inherited from Ship::Part
 Part ()
 Constructs a Part and assigns it a unique ID.
 
 Part (std::shared_ptr< Context > context)
 Constructs a Part with an explicit Context reference and unique ID.
 
virtual ~Part ()=default
 
uint64_t GetId () const
 Returns the unique identifier for this Part.
 
bool operator== (const Part &other) const
 Compares two Parts for equality by their unique IDs.
 
std::shared_ptr< ContextGetContext () const
 Returns the Context this Part belongs to, or nullptr if unset.
 
void SetContext (std::shared_ptr< Context > ctx)
 Sets the Context this Part belongs to.
 

Protected Member Functions

void OnInit (const nlohmann::json &initArgs=nlohmann::json::object()) override
 Component initialization hook. Mounts archives and starts the thread pool.
 
std::shared_ptr< std::vector< std::shared_ptr< IResource > > > LoadResourcesProcess (const ResourceFilter &filter)
 
void UnloadResourcesProcess (const ResourceFilter &filter)
 
std::variant< ResourceLoadError, std::shared_ptr< IResource > > CheckCache (const ResourceIdentifier &identifier, bool loadExact=false)
 
std::variant< ResourceLoadError, std::shared_ptr< IResource > > CheckCache (const std::string &filePath, bool loadExact=false)
 
std::shared_ptr< IResourceGetCachedResource (std::variant< ResourceLoadError, std::shared_ptr< IResource > > cacheLine)
 
- Protected Member Functions inherited from Ship::Component
void MarkInitialized ()
 Marks this component as initialized without going through Init().
 
template<typename T >
std::shared_ptr< T > RequireDependency (const std::shared_ptr< T > &dependency, const std::string &dependencyName) const
 Returns a cached dependency after validating it exists and is initialized.
 
- Protected Member Functions inherited from Ship::Part
virtual void OnAdded (bool forced)
 Called after this Part has been added to a PartList.
 
virtual void OnRemoved (bool forced)
 Called after this Part has been removed from a PartList.
 

Friends

class ResourceLoader
 

Detailed Description

Central manager for loading, caching, and unloading game resources.

ResourceManager sits between the game code and the archive/file system. It maintains an in-memory cache of loaded IResource objects, dispatches asynchronous load requests to a thread pool, and delegates actual deserialization to ResourceLoader.

Required dependencies (constructor-injected):

  • ThreadPool — used for all asynchronous resource load/unload operations.
  • Keystore — optional; passed through to ArchiveManager/Archive for signature validation.

Obtain the instance from Context::GetChildren().GetFirst<ResourceManager>().

Constructor & Destructor Documentation

◆ ResourceManager()

Ship::ResourceManager::ResourceManager ( std::shared_ptr< ThreadPool threadPool = nullptr,
std::shared_ptr< Keystore keystore = nullptr 
)
explicit

◆ ~ResourceManager()

Ship::ResourceManager::~ResourceManager ( )

Member Function Documentation

◆ CheckCache() [1/2]

std::variant< ResourceLoadError, std::shared_ptr< IResource > > Ship::ResourceManager::CheckCache ( const ResourceIdentifier identifier,
bool  loadExact = false 
)
protected

◆ CheckCache() [2/2]

std::variant< ResourceLoadError, std::shared_ptr< IResource > > Ship::ResourceManager::CheckCache ( const std::string &  filePath,
bool  loadExact = false 
)
protected

◆ DirtyResources() [1/2]

void Ship::ResourceManager::DirtyResources ( const ResourceFilter filter)

Marks as dirty all cached resources matching a filter.

Parameters
filterResourceFilter.

◆ DirtyResources() [2/2]

void Ship::ResourceManager::DirtyResources ( const std::string &  searchMask)

Marks as dirty all cached resources whose paths match a glob mask.

Dirty resources remain in the cache but are flagged for reload on next access.

Parameters
searchMaskGlob pattern.

◆ GetArchiveManager()

std::shared_ptr< ArchiveManager > Ship::ResourceManager::GetArchiveManager ( )

Returns the ArchiveManager that manages the mounted archives.

◆ GetCachedResource() [1/3]

std::shared_ptr< IResource > Ship::ResourceManager::GetCachedResource ( const ResourceIdentifier identifier,
bool  loadExact = false 
)

Returns a resource from the cache using a ResourceIdentifier.

Parameters
identifierExact resource identifier including owner and parent archive.
loadExactIf true, skips alt-asset path resolution.
Returns
Cached IResource, or nullptr if not found.

◆ GetCachedResource() [2/3]

std::shared_ptr< IResource > Ship::ResourceManager::GetCachedResource ( const std::string &  filePath,
bool  loadExact = false 
)

Returns a resource from the cache if present, without loading from disk.

Parameters
filePathVirtual path of the resource.
loadExactIf true, skips alt-asset path resolution and uses the exact path.
Returns
Cached IResource, or nullptr if not found in the cache.

◆ GetCachedResource() [3/3]

std::shared_ptr< IResource > Ship::ResourceManager::GetCachedResource ( std::variant< ResourceLoadError, std::shared_ptr< IResource > >  cacheLine)
protected

◆ GetResourceIsCustom() [1/3]

bool Ship::ResourceManager::GetResourceIsCustom ( const char *  name)

Returns true if the resource at the given path is an alt-asset override.

Parameters
nameVirtual path of the resource.

◆ GetResourceIsCustom() [2/3]

bool Ship::ResourceManager::GetResourceIsCustom ( std::shared_ptr< IResource resource)

Returns true if the given resource originated from an alt-assets override.

Parameters
resourceShared pointer to the resource.

◆ GetResourceIsCustom() [3/3]

bool Ship::ResourceManager::GetResourceIsCustom ( uint64_t  crc)

Returns true if the resource identified by CRC is an alt-asset override.

Parameters
crc64-bit content hash.

◆ GetResourceLoader()

std::shared_ptr< ResourceLoader > Ship::ResourceManager::GetResourceLoader ( )

Returns the ResourceLoader responsible for deserializing file data.

◆ GetResourceRawPointer() [1/3]

void * Ship::ResourceManager::GetResourceRawPointer ( const char *  name)

Returns a type-erased raw pointer to the payload of a resource by path.

Parameters
nameVirtual path of the resource.
Returns
Void pointer to the payload, or nullptr if not found.

◆ GetResourceRawPointer() [2/3]

void * Ship::ResourceManager::GetResourceRawPointer ( std::shared_ptr< IResource resource)

Returns a type-erased raw pointer to the resource payload.

Parameters
resourceShared pointer to the resource.
Returns
Void pointer to the payload, or nullptr if the resource is null.

◆ GetResourceRawPointer() [3/3]

void * Ship::ResourceManager::GetResourceRawPointer ( uint64_t  crc)

Returns a type-erased raw pointer to the payload of a resource by CRC.

Parameters
crc64-bit content hash.
Returns
Void pointer to the payload, or nullptr if not found.

◆ GetResourceSize() [1/3]

size_t Ship::ResourceManager::GetResourceSize ( const char *  name)

Returns the byte size of the payload of a resource identified by path.

Parameters
nameVirtual path of the resource.
Returns
Size in bytes, or 0 if not found.

◆ GetResourceSize() [2/3]

size_t Ship::ResourceManager::GetResourceSize ( std::shared_ptr< IResource resource)

Returns the byte size of the payload of a loaded resource.

Parameters
resourceShared pointer to the resource.
Returns
Size in bytes, or 0 if the resource is null.

◆ GetResourceSize() [3/3]

size_t Ship::ResourceManager::GetResourceSize ( uint64_t  crc)

Returns the byte size of the payload of a resource identified by CRC.

Parameters
crc64-bit content hash.
Returns
Size in bytes, or 0 if not found.

◆ IsAltAssetsEnabled()

bool Ship::ResourceManager::IsAltAssetsEnabled ( )

Returns whether alt-asset (mod) loading is currently enabled.

Returns
true if alternate assets are active.

◆ LoadFileProcess() [1/3]

std::shared_ptr< File > Ship::ResourceManager::LoadFileProcess ( const ResourceIdentifier identifier)

Loads raw file bytes from the archive, bypassing resource deserialization.

Parameters
identifierExact resource identifier.
Returns
Loaded File with raw buffer, or nullptr on failure.

◆ LoadFileProcess() [2/3]

std::shared_ptr< File > Ship::ResourceManager::LoadFileProcess ( const std::string &  filePath)

Loads raw file bytes from the archive by path.

Parameters
filePathVirtual path of the file.
Returns
Loaded File with raw buffer, or nullptr on failure.

◆ LoadFileProcess() [3/3]

std::shared_ptr< File > Ship::ResourceManager::LoadFileProcess ( uint64_t  hash)

Loads raw file bytes from the archive by hash.

Parameters
hashVirtual-file hash of the file.
Returns
Loaded File with raw buffer, or nullptr on failure.

◆ LoadResource() [1/5]

std::shared_ptr< IResource > Ship::ResourceManager::LoadResource ( const ResourceIdentifier identifier,
bool  loadExact = false,
std::shared_ptr< ResourceInitData initData = nullptr 
)

Loads a resource synchronously by ResourceIdentifier.

Parameters
identifierExact identifier (path/hash + owner + parent archive).
loadExactIf true, skips alt-asset path resolution.
initDataOptional metadata overrides.
Returns
Loaded (or cached) IResource, or nullptr on failure.

◆ LoadResource() [2/5]

template<typename T >
std::shared_ptr< T > Ship::ResourceManager::LoadResource ( const ResourceIdentifier identifier,
bool  loadExact = false,
std::shared_ptr< ResourceInitData initData = nullptr 
)
inline

Loads a resource synchronously by ResourceIdentifier, cast to the concrete type T.

Template Parameters
TConcrete resource type (must derive from IResource).
Parameters
identifierExact identifier (path/hash + owner + parent archive).
loadExactIf true, skips alt-asset path resolution.
initDataOptional metadata overrides.
Returns
Loaded (or cached) resource cast to T, or nullptr on failure.

◆ LoadResource() [3/5]

std::shared_ptr< IResource > Ship::ResourceManager::LoadResource ( const std::string &  filePath,
bool  loadExact = false,
std::shared_ptr< ResourceInitData initData = nullptr 
)

Loads a resource synchronously, returning it from the cache if already loaded.

Parameters
filePathVirtual path of the resource.
loadExactIf true, skips alt-asset path resolution.
initDataOptional metadata overrides; pass nullptr to use defaults from the file header.
Returns
Loaded (or cached) IResource, or nullptr on failure.

◆ LoadResource() [4/5]

template<typename T >
std::shared_ptr< T > Ship::ResourceManager::LoadResource ( const std::string &  filePath,
bool  loadExact = false,
std::shared_ptr< ResourceInitData initData = nullptr 
)
inline

Loads a resource synchronously, cast to the concrete type T.

Template Parameters
TConcrete resource type (must derive from IResource).
Parameters
filePathVirtual path of the resource.
loadExactIf true, skips alt-asset path resolution.
initDataOptional metadata overrides.
Returns
Loaded (or cached) resource cast to T, or nullptr on failure.

◆ LoadResource() [5/5]

std::shared_ptr< IResource > Ship::ResourceManager::LoadResource ( uint64_t  crc,
bool  loadExact = false,
std::shared_ptr< ResourceInitData initData = nullptr 
)

Loads a resource synchronously by content-hash CRC.

Parameters
crc64-bit content hash identifying the resource.
loadExactIf true, skips alt-asset path resolution.
initDataOptional metadata overrides.
Returns
Loaded IResource, or nullptr if the CRC is not found in any mounted archive.

◆ LoadResourceAsync() [1/2]

std::shared_future< std::shared_ptr< IResource > > Ship::ResourceManager::LoadResourceAsync ( const ResourceIdentifier identifier,
bool  loadExact = false,
BS::priority_t  priority = BS::pr::normal,
std::shared_ptr< ResourceInitData initData = nullptr 
)

Schedules an asynchronous resource load by ResourceIdentifier.

Parameters
identifierExact identifier.
loadExactIf true, skips alt-asset path resolution.
priorityThread-pool scheduling priority.
initDataOptional metadata overrides.
Returns
Shared future that will resolve to the loaded IResource (or nullptr on failure).

◆ LoadResourceAsync() [2/2]

std::shared_future< std::shared_ptr< IResource > > Ship::ResourceManager::LoadResourceAsync ( const std::string &  filePath,
bool  loadExact = false,
BS::priority_t  priority = BS::pr::normal,
std::shared_ptr< ResourceInitData initData = nullptr 
)

Schedules an asynchronous resource load and returns a future.

Parameters
filePathVirtual path of the resource.
loadExactIf true, skips alt-asset path resolution.
priorityThread-pool scheduling priority.
initDataOptional metadata overrides.
Returns
Shared future that will resolve to the loaded IResource (or nullptr on failure).

◆ LoadResourceProcess() [1/2]

std::shared_ptr< IResource > Ship::ResourceManager::LoadResourceProcess ( const ResourceIdentifier identifier,
bool  loadExact = false,
std::shared_ptr< ResourceInitData initData = nullptr 
)

Loads a resource synchronously by ResourceIdentifier, bypassing the cache.

Parameters
identifierExact identifier.
loadExactIf true, skips alt-asset path resolution.
initDataOptional metadata overrides.
Returns
Freshly loaded IResource, or nullptr on failure.

◆ LoadResourceProcess() [2/2]

std::shared_ptr< IResource > Ship::ResourceManager::LoadResourceProcess ( const std::string &  filePath,
bool  loadExact = false,
std::shared_ptr< ResourceInitData initData = nullptr 
)

Loads a resource synchronously, bypassing the cache.

Unlike LoadResource(), this always reads from the archive even if a cached copy exists.

Parameters
filePathVirtual path of the resource.
loadExactIf true, skips alt-asset path resolution.
initDataOptional metadata overrides.
Returns
Freshly loaded IResource, or nullptr on failure.

◆ LoadResources() [1/2]

std::shared_ptr< std::vector< std::shared_ptr< IResource > > > Ship::ResourceManager::LoadResources ( const ResourceFilter filter)

Loads all resources matching the given filter.

Parameters
filterResourceFilter specifying include/exclude masks, owner, and parent archive.
Returns
Pointer to a vector of loaded IResource objects.

◆ LoadResources() [2/2]

std::shared_ptr< std::vector< std::shared_ptr< IResource > > > Ship::ResourceManager::LoadResources ( const std::string &  searchMask)

Loads all resources whose paths match the given glob mask.

Parameters
searchMaskGlob pattern (e.g. "textures/ui/*" ).
Returns
Pointer to a vector of loaded IResource objects.

◆ LoadResourcesAsync() [1/2]

std::shared_future< std::shared_ptr< std::vector< std::shared_ptr< IResource > > > > Ship::ResourceManager::LoadResourcesAsync ( const ResourceFilter filter,
BS::priority_t  priority = BS::pr::normal 
)

Asynchronously loads all resources matching a filter.

Parameters
filterResourceFilter.
priorityThread-pool scheduling priority.
Returns
Shared future resolving to a vector of loaded IResource objects.

◆ LoadResourcesAsync() [2/2]

std::shared_future< std::shared_ptr< std::vector< std::shared_ptr< IResource > > > > Ship::ResourceManager::LoadResourcesAsync ( const std::string &  searchMask,
BS::priority_t  priority = BS::pr::normal 
)

Asynchronously loads all resources matching a glob mask.

Parameters
searchMaskGlob pattern.
priorityThread-pool scheduling priority.
Returns
Shared future resolving to a vector of loaded IResource objects.

◆ LoadResourcesProcess()

std::shared_ptr< std::vector< std::shared_ptr< IResource > > > Ship::ResourceManager::LoadResourcesProcess ( const ResourceFilter filter)
protected

◆ OnInit()

void Ship::ResourceManager::OnInit ( const nlohmann::json &  initArgs = nlohmann::json::object())
overrideprotectedvirtual

Component initialization hook. Mounts archives and starts the thread pool.

Expected initArgs keys:

  • "archivePaths" (array of strings): paths to OTR/O2R archive files or directories.
  • "validHashes" (array of uint32): acceptable game-version hashes; empty = all accepted.

Reimplemented from Ship::Component.

◆ OtrSignatureCheck()

bool Ship::ResourceManager::OtrSignatureCheck ( const char *  fileName)

Checks whether a file is a valid OTR archive by reading its header signature.

Parameters
fileNamePath to the file to inspect.
Returns
true if the file starts with a valid OTR signature.

◆ SetAltAssetsEnabled()

void Ship::ResourceManager::SetAltAssetsEnabled ( bool  isEnabled)

Enables or disables alt-asset (mod) loading.

Parameters
isEnabledtrue to enable, false to disable.

◆ UnloadResource() [1/2]

size_t Ship::ResourceManager::UnloadResource ( const ResourceIdentifier identifier)

Removes a resource from the cache by ResourceIdentifier.

Parameters
identifierIdentifier of the resource to evict.
Returns
Number of cache entries removed (0 or 1).

◆ UnloadResource() [2/2]

size_t Ship::ResourceManager::UnloadResource ( const std::string &  filePath)

Removes a resource from the cache by path.

Parameters
filePathVirtual path of the resource to evict.
Returns
Number of cache entries removed (0 or 1).

◆ UnloadResources() [1/2]

void Ship::ResourceManager::UnloadResources ( const ResourceFilter filter)

Synchronously unloads all resources matching a filter.

Parameters
filterResourceFilter.

◆ UnloadResources() [2/2]

void Ship::ResourceManager::UnloadResources ( const std::string &  searchMask)

Synchronously unloads all resources matching a glob mask.

Parameters
searchMaskGlob pattern.

◆ UnloadResourcesAsync() [1/2]

void Ship::ResourceManager::UnloadResourcesAsync ( const ResourceFilter filter,
BS::priority_t  priority = BS::pr::normal 
)

Asynchronously unloads all resources matching a filter.

Parameters
filterResourceFilter.
priorityThread-pool scheduling priority.

◆ UnloadResourcesAsync() [2/2]

void Ship::ResourceManager::UnloadResourcesAsync ( const std::string &  searchMask,
BS::priority_t  priority = BS::pr::normal 
)

Asynchronously unloads all resources matching a glob mask.

Parameters
searchMaskGlob pattern.
priorityThread-pool scheduling priority.

◆ UnloadResourcesProcess()

void Ship::ResourceManager::UnloadResourcesProcess ( const ResourceFilter filter)
protected

◆ WriteResource() [1/2]

bool Ship::ResourceManager::WriteResource ( const ResourceIdentifier identifier,
const std::vector< uint8_t > &  data,
bool  unloadFile 
)

Writes raw data into an archive and optionally evicts the stale cache entry.

Parameters
identifierIdentifier of the resource to write.
dataRaw bytes to write.
unloadFileIf true, removes the old cache entry after writing.
Returns
true on success.

◆ WriteResource() [2/2]

bool Ship::ResourceManager::WriteResource ( uint64_t  hash,
const std::vector< uint8_t > &  data,
bool  unloadFile 
)

Writes raw data into an archive by hash and optionally evicts the stale cache entry.

Parameters
hashVirtual-file hash of the resource to write.
dataRaw bytes to write.
unloadFileIf true, removes the old cache entry after writing.
Returns
true on success.

Friends And Related Symbol Documentation

◆ ResourceLoader

friend class ResourceLoader
friend

The documentation for this class was generated from the following file: