Loader
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.
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.
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.
LoaderResult<Resource> Loader<Resource>::Load(const fs::path& path) const;| Parameter | Description |
|---|---|
| path | File 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.
auto Loader<Resource>::LoadAsync(const fs::path& path, LoaderCallback<Resource> callback) const;| Parameter | Description |
|---|---|
| path | File system path to the resource. |
| callback | Callback 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.
virtual LoaderResult<Resource> Loader<Resource>::LoadImpl(const fs::path& path) const=0;| Parameter | Description |
|---|---|
| path | File system path to the resource. |