Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
Olympe::AssetManager Class Reference

Singleton cache for engine assets. More...

#include <AssetManager.h>

Public Member Functions

AssetID LoadTaskGraph (const std::string &path, std::vector< std::string > &outErrors)
 Loads a TaskGraphTemplate from path and caches it.
 
const TaskGraphTemplateGetTaskGraph (AssetID id) const
 Returns a non-owning pointer to the cached TaskGraphTemplate.
 
const TaskGraphTemplateLoadTaskGraphFromFile (const std::string &path, std::vector< std::string > &outErrors)
 Loads a TaskGraphTemplate from path and returns a direct pointer.
 
void UnloadTaskGraph (AssetID id)
 Releases the cached TaskGraphTemplate for id.
 

Static Public Member Functions

static AssetManagerGet ()
 Returns the singleton AssetManager instance.
 
static AssetID ComputeAssetID (const std::string &path)
 Computes the 32-bit FNV-1a hash of a file path string.
 

Private Member Functions

 AssetManager ()=default
 
 ~AssetManager ()=default
 
 AssetManager (const AssetManager &)=delete
 
AssetManageroperator= (const AssetManager &)=delete
 

Private Attributes

std::unordered_map< AssetID, std::unique_ptr< TaskGraphTemplate > > m_taskGraphs
 Cached task graph templates: AssetID -> owned template.
 

Detailed Description

Singleton cache for engine assets.

Call Get() to obtain the singleton instance. All TaskGraphTemplate assets loaded through LoadTaskGraph() are owned by AssetManager; callers must not delete the pointers returned by GetTaskGraph().

Definition at line 61 of file AssetManager.h.

Constructor & Destructor Documentation

◆ AssetManager() [1/2]

Olympe::AssetManager::AssetManager ( )
privatedefault

◆ ~AssetManager()

Olympe::AssetManager::~AssetManager ( )
privatedefault

◆ AssetManager() [2/2]

Olympe::AssetManager::AssetManager ( const AssetManager )
privatedelete

Member Function Documentation

◆ ComputeAssetID()

AssetID Olympe::AssetManager::ComputeAssetID ( const std::string &  path)
static

Computes the 32-bit FNV-1a hash of a file path string.

The hash is used as the AssetID so that the same path always maps to the same identifier. Exposed publicly so callers can pre-compute IDs.

Parameters
pathAny non-empty string.
Returns
32-bit FNV-1a hash. Returns INVALID_ASSET_ID (0) only if the input is empty.

Definition at line 29 of file AssetManager.cpp.

References GetComponentTypeID_Static(), and Olympe::INVALID_ASSET_ID.

Referenced by LoadTaskGraph().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Get()

AssetManager & Olympe::AssetManager::Get ( )
static

Returns the singleton AssetManager instance.

Definition at line 19 of file AssetManager.cpp.

Referenced by Olympe::VSGraphExecutor::HandleSubGraph(), Olympe::BlueprintEditor::PreloadATSGraphs(), and Olympe::TaskSystem::Process().

+ Here is the caller graph for this function:

◆ GetTaskGraph()

const TaskGraphTemplate * Olympe::AssetManager::GetTaskGraph ( AssetID  id) const

Returns a non-owning pointer to the cached TaskGraphTemplate.

Parameters
idAssetID previously returned by LoadTaskGraph().
Returns
Pointer to the template, or nullptr if id is unknown.
Note
The returned pointer is valid until UnloadTaskGraph() or the AssetManager is destroyed. Do NOT delete it.

Definition at line 97 of file AssetManager.cpp.

References GetComponentTypeID_Static(), and m_taskGraphs.

Referenced by LoadTaskGraphFromFile(), and Olympe::TaskSystem::Process().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ LoadTaskGraph()

AssetID Olympe::AssetManager::LoadTaskGraph ( const std::string &  path,
std::vector< std::string > &  outErrors 
)

Loads a TaskGraphTemplate from path and caches it.

If the asset has already been loaded (same path hash), the cached AssetID is returned immediately without re-reading the file.

Parameters
pathAbsolute or relative path to the JSON task graph file.
outErrorsReceives human-readable error messages on failure.
Returns
A non-zero AssetID on success, or INVALID_ASSET_ID on failure.
Note
AssetManager owns the loaded template. Do NOT delete the pointer returned by GetTaskGraph().

Definition at line 60 of file AssetManager.cpp.

References ComputeAssetID(), GetComponentTypeID_Static(), Olympe::INVALID_ASSET_ID, Olympe::TaskGraphLoader::LoadFromFile(), m_taskGraphs, and SYSTEM_LOG.

Referenced by LoadTaskGraphFromFile(), and Olympe::BlueprintEditor::PreloadATSGraphs().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ LoadTaskGraphFromFile()

const TaskGraphTemplate * Olympe::AssetManager::LoadTaskGraphFromFile ( const std::string &  path,
std::vector< std::string > &  outErrors 
)

Loads a TaskGraphTemplate from path and returns a direct pointer.

Convenience wrapper around LoadTaskGraph() + GetTaskGraph() for use in code that needs a template pointer without managing AssetIDs (e.g., SubGraph execution in VSGraphExecutor).

Parameters
pathAbsolute or relative path to the JSON task graph file.
outErrorsReceives human-readable error messages on failure.
Returns
Non-owning pointer to the template, or nullptr on failure.
Note
AssetManager retains ownership. Do NOT delete the returned pointer.

Definition at line 107 of file AssetManager.cpp.

References GetComponentTypeID_Static(), GetTaskGraph(), Olympe::INVALID_ASSET_ID, and LoadTaskGraph().

Referenced by Olympe::VSGraphExecutor::HandleSubGraph().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=()

AssetManager & Olympe::AssetManager::operator= ( const AssetManager )
privatedelete

◆ UnloadTaskGraph()

void Olympe::AssetManager::UnloadTaskGraph ( AssetID  id)

Releases the cached TaskGraphTemplate for id.

After this call, any raw pointers previously obtained from GetTaskGraph() for the same id are dangling and must not be used.

Parameters
idAssetID returned by LoadTaskGraph().

Definition at line 118 of file AssetManager.cpp.

References GetComponentTypeID_Static(), m_taskGraphs, and SYSTEM_LOG.

+ Here is the call graph for this function:

Member Data Documentation

◆ m_taskGraphs

std::unordered_map<AssetID, std::unique_ptr<TaskGraphTemplate> > Olympe::AssetManager::m_taskGraphs
private

Cached task graph templates: AssetID -> owned template.

Definition at line 159 of file AssetManager.h.

Referenced by GetTaskGraph(), LoadTaskGraph(), and UnloadTaskGraph().


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