Shkyera Engine
Easy to use, game engine for Python
Loading...
Searching...
No Matches
shkyera::utils::assets Namespace Reference

Classes

class  CubeMapLoader
 
class  FactoryAssetLoader
 
class  MaterialLoader
 
class  PathAssetLoader
 
class  ShaderLoader
 

Functions

std::optional< AssetHandleregisterSingle (std::filesystem::path path, Registry *registry)
 
std::optional< AssetHandleregisterAll (std::filesystem::path path, Registry *registry)
 
std::vector< AssetHandlegetSubdirectories (AssetHandle directory, Registry const *registry)
 
template<typename AssetType >
AssetRef< AssetTyperead (AssetComponent< AssetType > &assetComponent)
 
template<typename AssetType >
AssetRef< AssetTyperead (Registry *registry, HandleAndAsset< AssetType > &handleAndAsset)
 
template<typename AssetType , typename... Args>
AssetRef< AssetTyperead (const std::filesystem::path &path, Args &&... args)
 
template<typename AssetType >
AssetRef< AssetTyperead (typename AssetType::Factory::Type type)
 
template<typename AssetType >
HandleAndAsset< AssetTypeadd (Registry *registry, std::unique_ptr< AssetLoader< AssetType > > loader)
 
template<typename AssetType >
HandleAndAsset< AssetTypeadd (Registry *registry, std::filesystem::path &&path)
 
template<typename AssetType >
HandleAndAsset< AssetTypeadd (Registry *registry, typename AssetType::Factory::Type type)
 
template<typename AssetType , typename... Args>
AssetRef< AssetTypereadPermanent (const std::filesystem::path &path, Args &&... args)
 
template<typename AssetType >
AssetRef< AssetTypereadPermanent (typename AssetType::Factory::Type type)
 

Function Documentation

◆ add() [1/3]

template<typename AssetType >
HandleAndAsset< AssetType > shkyera::utils::assets::add ( Registry registry,
std::filesystem::path &&  path 
)

Adds a new asset to the ECS registry, reads it, and returns a shared pointer to the asset. This is a combination of adding the asset and reading it from the AssetComponent in one step.

Template Parameters
AssetTypeThe type of the asset to add and read
ArgsThe argument types required for constructing the asset
Parameters
registryPointer to the ECS registry
argsArguments to be forwarded to the constructor of AssetComponent
Returns
A shared pointer to the asset of type AssetType

◆ add() [2/3]

template<typename AssetType >
HandleAndAsset< AssetType > shkyera::utils::assets::add ( Registry registry,
std::unique_ptr< AssetLoader< AssetType > >  loader 
)

Adds a new asset of the specified type to the registry and returns the asset handle along with a reference to the associated AssetComponent.

Template Parameters
AssetTypeThe type of the asset to add
ArgsThe argument types required for constructing the asset
Parameters
registryPointer to the ECS registry
argsArguments to be forwarded to the constructor of AssetComponent
Returns
A pair containing the handle of the new asset and a reference to its AssetComponent

◆ add() [3/3]

template<typename AssetType >
HandleAndAsset< AssetType > shkyera::utils::assets::add ( Registry registry,
typename AssetType::Factory::Type  type 
)

At first call, construct an Asset using the provided factory method. At later calls, return the oprevously constructed Asset.

Parameters
registryPointer to the ECS registry
Returns
A shared pointer to the asset of type AssetType

◆ getSubdirectories()

std::vector< AssetHandle > shkyera::utils::assets::getSubdirectories ( AssetHandle  directory,
Registry const registry 
)

Retrieves all subdirectories from the specified directory asset.

Parameters
directoryHandle to the directory asset whose subdirectories are to be retrieved
registryPointer to the ECS registry to access entity components
Returns
A vector of AssetHandles representing the subdirectories of the provided directory asset

◆ read() [1/4]

template<typename AssetType >
AssetRef< AssetType > shkyera::utils::assets::read ( AssetComponent< AssetType > &  assetComponent)

Reads the asset from the provided AssetComponent by either retrieving the cached asset or constructing a new asset and storing it in the component.

Template Parameters
AssetTypeThe type of the asset to read
Parameters
assetComponentReference to the AssetComponent holding the asset data
Returns
A shared pointer to the asset of type AssetType

◆ read() [2/4]

template<typename AssetType , typename... Args>
AssetRef< AssetType > shkyera::utils::assets::read ( const std::filesystem::path &  path,
Args &&...  args 
)

Constructs an asset of the specified type from a specified path with given constructor arguments.

Template Parameters
AssetTypeThe type of the asset to read
ArgsConstructor argument pack
Parameters
assetComponentReference to the AssetComponent holding the asset data
argsConstructor parameters
Returns
A shared pointer to the asset of type AssetType

◆ read() [3/4]

template<typename AssetType >
AssetRef< AssetType > shkyera::utils::assets::read ( Registry registry,
HandleAndAsset< AssetType > &  handleAndAsset 
)

◆ read() [4/4]

template<typename AssetType >
AssetRef< AssetType > shkyera::utils::assets::read ( typename AssetType::Factory::Type  type)

◆ readPermanent() [1/2]

template<typename AssetType , typename... Args>
AssetRef< AssetType > shkyera::utils::assets::readPermanent ( const std::filesystem::path &  path,
Args &&...  args 
)

At first call, adds a new asset to the ECS registry, reads it and returns a shared pointer to the asset. At later calls, it returns an already loaded asset. This function GUARANTEES that a once loaded asset will never be unloaded. It should not be used for loading large assets. The permanent assets DO NOT have a handle and DO NOT exist in any registry;

Template Parameters
AssetTypePathConstructible AssetType defining the type of the asset to add and read
ArgsThe argument types required for constructing the asset
Parameters
pathPath to the asset
argsArguments to be forwarded to the constructor of AssetComponent
Returns
A shared pointer to the asset of type AssetType

◆ readPermanent() [2/2]

template<typename AssetType >
AssetRef< AssetType > shkyera::utils::assets::readPermanent ( typename AssetType::Factory::Type  type)

◆ registerAll()

std::optional< AssetHandle > shkyera::utils::assets::registerAll ( std::filesystem::path  path,
Registry registry 
)

If path points to a directory, it recursively traverses the root directory and registers all assets, including both files and directories. If path poitns to a file, it registers a single file.

Parameters
rootPath to the initial asset
registryNon-owning pointer to the ECS registry
Returns
If successful, the handle of the asset at the provided path

◆ registerSingle()

std::optional< AssetHandle > shkyera::utils::assets::registerSingle ( std::filesystem::path  path,
Registry registry 
)

Registers the asset at the specified path in the registry. Asset type will be deduced. It can be either a file or a directory. This function does NOT traverse the filesystem if the asset is a directory.

Parameters
rootPath to the asset (directory or file) to register
registryNon-owning pointer to the ECS registry
Returns
If successful, the handle of the registerd asset