Skip to content

Loader

Abstract base class for resource loader types.

Loader provides a common interface for loading engine assets from the filesystem, typically in engine-optimized formats. It supports both synchronous and asynchronous loading through Load and LoadAsync.

Concrete loaders such as TextureLoader and MeshLoader implement this interface to handle engine-optimized asset formats. Additional runtime loaders can be implemented by deriving from this class and providing a resource-specific LoadImpl method.

Types

LoaderCallback typedef

Callback type used by asynchronous loaders.

Invoked with the result of a loading operation once it completes.

cpp
using LoaderCallback =  std::function<void(LoaderResult<T>)>

LoaderResult typedef

Result type returned by resource loaders.

Contains either a shared pointer to the loaded resource or an error message describing why loading failed.

cpp
using LoaderResult =  std::expected<std::shared_ptr<T>, std::string>

Functions

Load() LoaderResult<Resource>

Loads a resource synchronously from the specified file path.

Verifies that the file exists before attempting to load. If the file is missing or an error occurs during loading, an error message is returned via std::unexpected.

cpp
LoaderResult<Resource> Loader<Resource>::Load(const fs::path& path) const;
ParameterDescription
pathFile system path to the resource.

LoadAsync() auto

Loads a resource asynchronously from the specified file path.

Verifies that the file exists, then performs the loading operation on a background thread. Once loading completes, the result is delivered to the provided callback.

The current implementation spawns a detached thread for each call and is intended as a simple baseline. In production scenarios it is recommended to integrate this with a thread pool or task system for better control and efficiency.

cpp
auto Loader<Resource>::LoadAsync(const fs::path& path, LoaderCallback<Resource> callback) const;
ParameterDescription
pathFile system path to the resource.
callbackCallback that receives the result of the loading operation.

LoadImpl() LoaderResult<Resource> pure virtual

Implements the resource-specific loading logic.

Called by Load and LoadAsync after the file has been verified to exist. Derived classes must override this method to decode the file and construct the resource instance.

cpp
virtual LoaderResult<Resource> Loader<Resource>::LoadImpl(const fs::path& path) const=0;
ParameterDescription
pathFile system path to the resource.

Released under the MIT License.