13#include "../../system/system_utils.h"
41 m_Future = std::async(std::launch::async,
61 std::future_status status =
62 m_Future.wait_for(std::chrono::seconds(0));
64 if (status == std::future_status::ready)
73 catch (
const std::exception&
e)
75 self->m_LastError =
e.what();
77 SYSTEM_LOG <<
"[AsyncJSONLoader] Load failed: " <<
e.what() << std::endl;
81 self->m_LastError =
"Unknown error during JSON load.";
83 SYSTEM_LOG <<
"[AsyncJSONLoader] Load failed with unknown error." << std::endl;
145 std::ifstream
file(path);
147 throw std::runtime_error(
"Cannot open file: " + path);
Asynchronous JSON file loader (Phase 7).
ComponentTypeID GetComponentTypeID_Static()
Loads and parses a JSON file on a background thread.
AsyncLoadState GetState() const
Returns the current state of the loader.
const std::string & GetLastError() const
Returns the last error message (non-empty when state == Failed).
std::future< nlohmann::json > m_Future
bool HasFailed() const
Returns true if the load failed (state == Failed).
nlohmann::json GetResult()
Returns the parsed JSON if ready; returns an empty object otherwise.
void Reset()
Resets state to Idle and clears the result / error.
void LoadAsync(const std::string &path)
Starts loading path on a background thread.
static nlohmann::json LoadFile(const std::string &path)
Opens, reads, and parses the JSON file; called on the background thread.
bool IsReady() const
Returns true if the result is available (state == Ready).
< Provides AssetID and INVALID_ASSET_ID
AsyncLoadState
Lifecycle state of an AsyncJSONLoader.
@ Loading
Background thread is running.
@ Failed
Load or parse failed — call GetLastError()
@ Idle
No load has been requested.
@ Ready
Result is available — call GetResult()