|
VisuTwin Canvas
C++ 3D Engine — Metal Backend
|
Async resource loader with background I/O thread, pixel decoding, and main-thread callbacks. More...
#include <framework/handlers/resourceLoader.h>
Public Member Functions | |
| void | addHandler (const std::string &type, std::unique_ptr< ResourceHandler > handler) |
| bool | hasPending () const |
| void | load (const std::string &url, const std::string &type, LoadSuccessCallback onSuccess, LoadErrorCallback onError=nullptr) |
| ResourceLoader & | operator= (const ResourceLoader &)=delete |
| void | processCompletions (int maxCompletions=0) |
| void | removeHandler (const std::string &type) |
| ResourceLoader (const ResourceLoader &)=delete | |
| ResourceLoader (const std::shared_ptr< Engine > &engine) | |
| void | shutdown () |
| ~ResourceLoader () | |
Async resource loader with background I/O thread, pixel decoding, and main-thread callbacks.
Asynchronous resource loader with a single background I/O thread.
Thread model
┌──────────────┐ load() ┌────────────────┐ │ Main thread │ ────────▶ │ Worker thread │ │ │ │ (I/O + decode) │ │ process │ ◀──────── │ │ │ Completions()│ callback └────────────────┘ └──────────────┘
Usage:
Definition at line 132 of file resourceLoader.h.
|
explicit |
Definition at line 24 of file resourceLoader.cpp.
Referenced by operator=(), and ResourceLoader().
| visutwin::canvas::ResourceLoader::~ResourceLoader | ( | ) |
Definition at line 32 of file resourceLoader.cpp.
References shutdown().
|
delete |
References ResourceLoader().
| void visutwin::canvas::ResourceLoader::addHandler | ( | const std::string & | type, |
| std::unique_ptr< ResourceHandler > | handler ) |
Register a handler for a given asset type (e.g. "texture", "container").
Definition at line 37 of file resourceLoader.cpp.
| bool visutwin::canvas::ResourceLoader::hasPending | ( | ) | const |
Returns true if there are pending or in-flight requests.
Definition at line 106 of file resourceLoader.cpp.
| void visutwin::canvas::ResourceLoader::load | ( | const std::string & | url, |
| const std::string & | type, | ||
| LoadSuccessCallback | onSuccess, | ||
| LoadErrorCallback | onError = nullptr ) |
Queue an asynchronous load request.
The background thread calls the appropriate ResourceHandler::load(). On the next processCompletions() call the onSuccess or onError callback is invoked on the main thread.
| url | Local file-system path. |
| type | Asset type string used to look up the handler. |
| onSuccess | Called on the main thread with loaded data. |
| onError | Called on the main thread with an error message. |
Definition at line 47 of file resourceLoader.cpp.
Referenced by visutwin::canvas::Asset::loadAsync().
|
delete |
References ResourceLoader().
| void visutwin::canvas::ResourceLoader::processCompletions | ( | int | maxCompletions = 0 | ) |
Must be called from the main thread each frame (from Engine::update). Dispatches completed load callbacks.
| maxCompletions | Maximum number of callbacks to dispatch per call. 0 means unlimited (drain all). Use 1 to spread heavy main-thread work (e.g. GLB parsing) across frames and avoid stalling the event loop. |
Definition at line 58 of file resourceLoader.cpp.
| void visutwin::canvas::ResourceLoader::removeHandler | ( | const std::string & | type | ) |
Remove a handler for a given asset type.
Definition at line 42 of file resourceLoader.cpp.
| void visutwin::canvas::ResourceLoader::shutdown | ( | ) |
Shut down the worker thread. Safe to call multiple times.
Definition at line 93 of file resourceLoader.cpp.
Referenced by ~ResourceLoader().