Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
Infinity::Assets::AssetPluginStore Class Reference

Central registry and management system for source-specific AssetPlugin instances. More...

#include <AssetPluginStore.hpp>

Static Public Member Functions

static void setDefaultLoader (const std::string &name)
 Sets the default asset loader by plugin name.
 
template<typename T >
static void setDefaultLoader ()
 Sets the default asset loader by plugin type.
 
static void setSecondaryLoader (const std::string &name)
 Sets the secondary asset loader by plugin name.
 
template<typename T >
static void setSecondaryLoader ()
 Sets the secondary asset loader by plugin type.
 
static void resetDefaults ()
 Resets all loader preferences to their default state.
 
static void addPlugin (const std::filesystem::path &path)
 Loads and registers a plugin from a shared library file.
 
static void addPlugin (CreateAssetPluginFunction *factory)
 Registers a plugin using a factory function.
 
static AssetPlugingetDefaultLoader ()
 Gets the currently configured default loader.
 
static AssetPlugingetSecondaryLoader ()
 Gets the currently configured secondary loader.
 
static AssetPlugingetFallbackLoader ()
 Gets the fallback loader.
 
template<typename T >
static AssetPlugingetLoader ()
 Gets a loader by its C++ type.
 
static AssetPlugingetLoader (const std::string &name)
 Gets a loader by its plugin name.
 

Detailed Description

Central registry and management system for source-specific AssetPlugin instances.

AssetPluginStore provides a singleton-style interface for managing multiple asset loading plugins within the Infinity engine. Each plugin represents a different asset source (filesystem, remote server, database, etc.) and provides loading implementations for the asset types it supports.

The store implements a fallback chain mechanism: when loading an asset, the default loader is tried first. If it cannot provide a valid asset (because the asset doesn't exist in that source or the loader doesn't support that type), the secondary loader is automatically attempted. This allows for flexible asset sourcing with graceful fallback behavior.

Plugins can be loaded dynamically from shared libraries or registered via factory functions, and can be selected either by name or by C++ type.

Note
All methods are static; this class maintains global plugin state.

Member Function Documentation

◆ addPlugin() [1/2]

static void Infinity::Assets::AssetPluginStore::addPlugin ( const std::filesystem::path &  path)
static

Loads and registers a plugin from a shared library file.

Dynamically loads an AssetPlugin from the specified shared library (e.g., .dll, .so, .dylib) and adds it to the plugin store. The library must export the CreateAssetPlugin and DestroyAssetPlugin functions.

Parameters
pathFilesystem path to the plugin shared library
Exceptions
std::runtime_errorif the plugin cannot be loaded or is invalid

◆ addPlugin() [2/2]

static void Infinity::Assets::AssetPluginStore::addPlugin ( CreateAssetPluginFunction factory)
static

Registers a plugin using a factory function.

Adds a plugin to the store by providing a factory function that creates plugin instances. This is useful for statically-linked plugins or when programmatic plugin registration is preferred.

Parameters
factoryPointer to a function that creates AssetPlugin instances

◆ getDefaultLoader()

static AssetPlugin & Infinity::Assets::AssetPluginStore::getDefaultLoader ( )
static

Gets the currently configured default loader.

Returns the primary asset source that will be tried first when loading assets.

Returns
Reference to the default AssetPlugin instance
Exceptions
std::runtime_errorif no default loader is configured

◆ getFallbackLoader()

static AssetPlugin & Infinity::Assets::AssetPluginStore::getFallbackLoader ( )
static

Gets the fallback loader.

Returns the system's ultimate fallback loader, which is used when both default and secondary loaders are unavailable or fail to provide a valid asset.

Returns
Reference to the fallback AssetPlugin instance

◆ getLoader() [1/2]

template<typename T >
static AssetPlugin & Infinity::Assets::AssetPluginStore::getLoader ( )
inlinestatic

Gets a loader by its C++ type.

Template method for retrieving a specific plugin instance by its compile-time type.

Template Parameters
TThe plugin class type to retrieve
Returns
Reference to the requested AssetPlugin instance
Exceptions
std::runtime_errorif the requested plugin type is not registered
auto& fsLoader = AssetPluginStore::getLoader<FilesystemAssetPlugin>();

◆ getLoader() [2/2]

static AssetPlugin & Infinity::Assets::AssetPluginStore::getLoader ( const std::string &  name)
static

Gets a loader by its plugin name.

Retrieves a specific plugin instance by the name it reports via getPluginName().

Parameters
nameThe name of the plugin to retrieve
Returns
Reference to the requested AssetPlugin instance
Exceptions
std::runtime_errorif no plugin with the specified name exists

◆ getSecondaryLoader()

static AssetPlugin & Infinity::Assets::AssetPluginStore::getSecondaryLoader ( )
static

Gets the currently configured secondary loader.

Returns the fallback asset source that will be tried when the default loader cannot provide a valid asset.

Returns
Reference to the secondary AssetPlugin instance
Exceptions
std::runtime_errorif no secondary loader is configured

◆ resetDefaults()

static void Infinity::Assets::AssetPluginStore::resetDefaults ( )
static

Resets all loader preferences to their default state.

Clears any configured default and secondary loaders, reverting to the system's initial loader configuration.

◆ setDefaultLoader() [1/2]

template<typename T >
static void Infinity::Assets::AssetPluginStore::setDefaultLoader ( )
inlinestatic

Sets the default asset loader by plugin type.

Template convenience method that sets the default loader using the plugin's C++ type rather than its name string.

Template Parameters
TThe plugin class type to set as default
AssetPluginStore::setDefaultLoader<FilesystemAssetPlugin>();

◆ setDefaultLoader() [2/2]

static void Infinity::Assets::AssetPluginStore::setDefaultLoader ( const std::string &  name)
static

Sets the default asset loader by plugin name.

Configures which plugin should be used as the primary asset source. The default loader is attempted first when loading assets. If it cannot provide a valid asset, the system falls back to the secondary loader.

Parameters
nameThe name of the plugin to set as default

◆ setSecondaryLoader() [1/2]

template<typename T >
static void Infinity::Assets::AssetPluginStore::setSecondaryLoader ( )
inlinestatic

Sets the secondary asset loader by plugin type.

Template convenience method that sets the secondary loader using the plugin's C++ type rather than its name string.

Template Parameters
TThe plugin class type to set as secondary
AssetPluginStore::setSecondaryLoader<RemoteAssetPlugin>();

◆ setSecondaryLoader() [2/2]

static void Infinity::Assets::AssetPluginStore::setSecondaryLoader ( const std::string &  name)
static

Sets the secondary asset loader by plugin name.

Configures which plugin should be used as a fallback source when the default loader cannot provide a valid asset. This enables multi-source asset loading strategies, such as checking local filesystem first, then falling back to a remote source.

Parameters
nameThe name of the plugin to set as secondary