A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat: Add async loading, hot reload, and editor/runtime separation
esengine05315b731480
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 844c49bda..09e0f6953 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -40,6 +40,8 @@ set(ESENGINE_SOURCESsrc/esengine/core/Log.cppsrc/esengine/resource/ResourceManager.cppsrc/esengine/resource/ShaderParser.cpp+ src/esengine/resource/LoaderJobQueue.cpp+ src/esengine/resource/HotReloadManager.cppsrc/esengine/resource/loaders/ShaderLoader.cppsrc/esengine/renderer/RenderContext.cppsrc/esengine/renderer/Renderer.cppdiff --git a/src/esengine/core/RuntimeConfig.hpp b/src/esengine/core/RuntimeConfig.hppnew file mode 100644index 000000000..95dede74a--- /dev/null+++ b/src/esengine/core/RuntimeConfig.hpp@@ -0,0 +1,64 @@+/**+ * @file RuntimeConfig.hpp+ * @brief Runtime configuration for engine mode detection+ * @details Provides runtime flags for distinguishing editor vs game mode.+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */+#pragma once++namespace esengine {++// =============================================================================+// RuntimeConfig+// =============================================================================++/**+ * @brief Runtime configuration singleton+ *+ * @details Provides runtime flags for feature detection. Set by the+ * application at startup based on build type.+ *+ * @code+ * // In editor main.cpp+ * RuntimeConfig::get().setEditorMode(true);+ *+ * // Anywhere in engine code+ * if (RuntimeConfig::get().isEditorMode()) {+ * // Editor-only code+ * }+ * @endcode+ */+class RuntimeConfig {+public:+ static RuntimeConfig& get() {+ static RuntimeConfig instance;+ return instance;+ }++ /** @brief Sets editor mode flag */+ void setEditorMode(bool enabled) { editorMode_ = enabled; }++ /** @brief Checks if running in editor mode */+ bool isEditorMode() const { return editorMode_; }++ /** @brief Sets hot reload enabled flag */+ void setHotReloadEnabled(bool enabled) { hotReloadEnabled_ = enabled; }++ /** @brief Checks if hot reload is enabled */+ bool isHotReloadEnabled() const { return hotReloadEnabled_ && editorMode_; }++private:+ RuntimeConfig() = default;+ RuntimeConfig(const RuntimeConfig&) = delete;+ RuntimeConfig& operator=(const RuntimeConfig&) = delete;++ bool editorMode_ = false;+ bool hotReloadEnabled_ = true;+};++} // namespace esenginediff --git a/src/esengine/editor/CMakeLists.txt b/src/esengine/editor/CMakeLists.txtindex 480fb2eb9..8d5131be2 100644--- a/src/esengine/editor/CMakeLists.txt+++ b/src/esengine/editor/CMakeLists.txt@@ -115,6 +115,9 @@ add_executable(esengine_editor ${EDITOR_SOURCES} ${EDITOR_HEADERS})# Link against the engine librarytarget_link_libraries(esengine_editor PRIVATE esengine)+# Define ES_EDITOR macro for editor-specific code+target_compile_definitions(esengine_editor PRIVATE ES_EDITOR)+# Include directoriestarget_include_directories(esengine_editor PRIVATE${CMAKE_SOURCE_DIR}/srcdiff --git a/src/esengine/editor/main.cpp b/src/esengine/editor/main.cppindex 08ff98983..84c4ab15f 100644--- a/src/esengine/editor/main.cpp+++ b/src/esengine/editor/main.cpp@@ -11,10 +11,14 @@#include "EditorApplication.hpp"#include "../core/Log.hpp"+#include "../core/RuntimeConfig.hpp"int main() {esengine::Log::init();+ esengine::RuntimeConfig::get().setEditorMode(true);+ esengine::RuntimeConfig::get().setHotReloadEnabled(true);+ES_LOG_INFO("Starting ESEngine Editor...");esengine::editor::EditorApplication editor;diff --git a/src/esengine/resource/AsyncHandle.hpp b/src/esengine/resource/AsyncHandle.hppnew file mode 100644index 000000000..4713d7011--- /dev/null+++ b/src/esengine/resource/AsyncHandle.hpp@@ -0,0 +1,163 @@+/**+ * @file AsyncHandle.hpp+ * @brief Asynchronous resource handle+ * @details Tracks the loading state of an async resource request and provides+ * access to the loaded resource once complete.+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */+#pragma once++// =============================================================================+// Includes+// =============================================================================++#include "../core/Types.hpp"+#include "Handle.hpp"++#include <functional>+#include <atomic>+#include <mutex>+#include <vector>++namespace esengine::resource {++// =============================================================================+// Load State+// =============================================================================++enum class LoadState : u8 {+ NotStarted, ///< Loading has not begun+ Loading, ///< Resource is being loaded+ Ready, ///< Resource loaded successfully+ Failed ///< Loading failed+};++// =============================================================================+// AsyncHandle Class+// =============================================================================++/**+ * @brief Handle for tracking async resource loading+ *+ * @details Wraps a Handle<T> with loading state tracking and completion+ * callbacks. Use with ResourceManager::loadAsync<T>().+ *+ * @tparam T The resource type being loaded+ *+ * @code+ * auto asyncTex = rm.loadAsync<Texture>("large_texture.png");+ *+ * asyncTex.onComplete([](TextureHandle h, bool success) {+ * if (success) {+ * // Use the texture+ * }+ * });+ *+ * // Later in update loop+ * if (asyncTex.isReady()) {+ * TextureHandle handle = asyncTex.handle();+ * }+ * @endcode+ */+template<typename T>+class AsyncHandle {+public:+ AsyncHandle() = default;++ /**+ * @brief Constructs an AsyncHandle with a job ID+ * @param jobId The job ID from LoaderJobQueue+ */+ explicit AsyncHandle(u64 jobId) : jobId_(jobId), state_(LoadState::Loading) {}++ /** @brief Gets the underlying resource handle (valid only when ready) */+ Handle<T> handle() const {+ std::lock_guard<std::mutex> lock(mutex_);+ return handle_;+ }++ /** @brief Gets the current loading state */+ LoadState state() const { return state_.load(); }++ /** @brief Checks if the resource is ready to use */+ bool isReady() const { return state_.load() == LoadState::Ready; }++ /** @brief Checks if the resource is currently loading */+ bool isLoading() const { return state_.load() == LoadState::Loading; }++ /** @brief Checks if loading failed */+ bool isFailed() const { return state_.load() == LoadState::Failed; }++ /** @brief Gets the job ID for this async operation */+ u64 jobId() const { return jobId_; }++ /** @brief Gets the error message if loading failed */+ const std::string& errorMessage() const {+ std::lock_guard<std::mutex> lock(mutex_);+ return errorMessage_;+ }++ /**+ * @brief Registers a completion callback+ * @param callback Function called when loading completes (handle, success)+ */+ void onComplete(std::function<void(Handle<T>, bool)> callback) {+ std::lock_guard<std::mutex> lock(mutex_);+ if (state_.load() == LoadState::Ready || state_.load() == LoadState::Failed) {+ callback(handle_, state_.load() == LoadState::Ready);+ } else {+ callbacks_.push_back(std::move(callback));+ }+ }++ /**+ * @brief Sets the result (called internally by ResourceManager)+ * @param h The loaded handle+ * @param success Whether loading succeeded+ * @param error Error message if failed+ */+ void setResult(Handle<T> h, bool success, const std::string& error = "") {+ std::vector<std::function<void(Handle<T>, bool)>> callbacksCopy;+ {+ std::lock_guard<std::mutex> lock(mutex_);+ handle_ = h;+ errorMessage_ = error;+ state_.store(success ? LoadState::Ready : LoadState::Failed);+ callbacksCopy = std::move(callbacks_);+ }++ for (auto& cb : callbacksCopy) {+ cb(h, success);+ }+ }++ /** @brief Explicit bool conversion (true if ready with valid handle) */+ explicit operator bool() const {+ return isReady() && handle().isValid();+ }++private:+ u64 jobId_ = 0;+ std::atomic<LoadState> state_{LoadState::NotStarted};+ mutable std::mutex mutex_;+ Handle<T> handle_;+ std::string errorMessage_;+ std::vector<std::function<void(Handle<T>, bool)>> callbacks_;+};++// =============================================================================+// Type Aliases+// =============================================================================++class Shader;+class Texture;++using AsyncShaderHandle = AsyncHandle<Shader>;+using AsyncTextureHandle = AsyncHandle<Texture>;++} // namespace esengine::resourcediff --git a/src/esengine/resource/HotReloadManager.cpp b/src/esengine/resource/HotReloadManager.cppnew file mode 100644index 000000000..58a2e3a45--- /dev/null+++ b/src/esengine/resource/HotReloadManager.cpp@@ -0,0 +1,138 @@+/**+ * @file HotReloadManager.cpp+ * @brief Hot reload manager implementation+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */++#include "HotReloadManager.hpp"+#include "../core/Log.hpp"+#include "../core/RuntimeConfig.hpp"++namespace esengine::resource {++// =============================================================================+// Lifecycle+// =============================================================================++HotReloadManager::~HotReloadManager() {+ if (initialized_) {+ shutdown();+ }+}++void HotReloadManager::init(bool enabled) {+ if (initialized_) {+ ES_LOG_WARN("HotReloadManager already initialized");+ return;+ }++ enabled_ = enabled && RuntimeConfig::get().isEditorMode();+ initialized_ = true;++ if (enabled_) {+ ES_LOG_INFO("HotReloadManager initialized (hot reload enabled)");+ } else {+ ES_LOG_INFO("HotReloadManager initialized (hot reload disabled)");+ }+}++void HotReloadManager::shutdown() {+ if (!initialized_) {+ return;+ }++ std::lock_guard<std::mutex> lock(mutex_);++ for (const auto& [path, entry] : watchedFiles_) {+ FileSystem::unwatchFile(path);+ }+ watchedFiles_.clear();+ pendingReloads_.clear();++ initialized_ = false;+ ES_LOG_INFO("HotReloadManager shutdown complete");+}++void HotReloadManager::update() {+ if (!enabled_ || !initialized_) {+ return;+ }++ std::unordered_set<std::string> reloadsToProcess;+ {+ std::lock_guard<std::mutex> lock(mutex_);+ reloadsToProcess = std::move(pendingReloads_);+ pendingReloads_.clear();+ }++ for (const auto& path : reloadsToProcess) {+ WatchEntry entry;+ {+ std::lock_guard<std::mutex> lock(mutex_);+ auto it = watchedFiles_.find(path);+ if (it == watchedFiles_.end()) {+ continue;+ }+ entry = it->second;+ }++ ES_LOG_INFO("HotReloadManager: Reloading '{}'", path);++ onAnyFileChanged.publish(path);++ if (entry.reloadFn) {+ try {+ entry.reloadFn(path);+ } catch (const std::exception& e) {+ ES_LOG_ERROR("HotReloadManager: Reload failed for '{}': {}", path, e.what());+ }+ }+ }+}++void HotReloadManager::setEnabled(bool enabled) {+ if (enabled_ == enabled) {+ return;+ }++ enabled_ = enabled;++ if (!enabled) {+ std::lock_guard<std::mutex> lock(mutex_);+ for (const auto& [path, entry] : watchedFiles_) {+ FileSystem::unwatchFile(path);+ }+ watchedFiles_.clear();+ }++ ES_LOG_INFO("HotReloadManager: Hot reload {}", enabled ? "enabled" : "disabled");+}++void HotReloadManager::unwatch(const std::string& path) {+ std::lock_guard<std::mutex> lock(mutex_);++ auto it = watchedFiles_.find(path);+ if (it == watchedFiles_.end()) {+ return;+ }++ FileSystem::unwatchFile(path);+ watchedFiles_.erase(it);+}++bool HotReloadManager::isWatching(const std::string& path) const {+ std::lock_guard<std::mutex> lock(mutex_);+ return watchedFiles_.find(path) != watchedFiles_.end();+}++void HotReloadManager::onFileChanged(const std::string& path) {+ std::lock_guard<std::mutex> lock(mutex_);+ pendingReloads_.insert(path);+}++} // namespace esengine::resourcediff --git a/src/esengine/resource/HotReloadManager.hpp b/src/esengine/resource/HotReloadManager.hppnew file mode 100644index 000000000..944c1ca54--- /dev/null+++ b/src/esengine/resource/HotReloadManager.hpp@@ -0,0 +1,204 @@+/**+ * @file HotReloadManager.hpp+ * @brief Hot reload manager for resources+ * @details Watches files for changes and triggers reloading of resources.+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */+#pragma once++// =============================================================================+// Includes+// =============================================================================++#include "../core/Types.hpp"+#include "../events/Signal.hpp"+#include "../platform/FileSystem.hpp"+#include "Handle.hpp"++#include <string>+#include <mutex>+#include <unordered_map>+#include <unordered_set>+#include <functional>+#include <typeindex>++namespace esengine::resource {++// Forward declarations+class ResourceManager;++// =============================================================================+// Reload Event+// =============================================================================++/**+ * @brief Event data for resource reload+ */+template<typename T>+struct ReloadEvent {+ Handle<T> handle; ///< Handle to the reloaded resource+ std::string path; ///< File path that changed+ bool success = false; ///< Whether reload succeeded+ std::string errorMessage; ///< Error message if reload failed+};++// =============================================================================+// WatchEntry+// =============================================================================++struct WatchEntry {+ std::string path; ///< File path being watched+ std::type_index type = std::type_index(typeid(void)); ///< Resource type+ std::function<void(const std::string&)> reloadFn; ///< Reload function+};++// =============================================================================+// HotReloadManager Class+// =============================================================================++/**+ * @brief Manages hot reloading of resources+ *+ * @details Integrates with FileSystem::watchFile to detect file changes+ * and trigger resource reloading. Connect to signals to handle+ * reload events.+ *+ * @code+ * HotReloadManager hrm;+ * hrm.init(true); // Enable hot reload+ *+ * // Watch a shader+ * hrm.watch<Shader>(shaderHandle, "shaders/my.esshader", [&](auto& path) {+ * // Reload logic+ * });+ *+ * // Handle reload events+ * hrm.onShaderReloaded.connect([](const ReloadEvent<Shader>& e) {+ * if (e.success) {+ * ES_LOG_INFO("Shader reloaded: {}", e.path);+ * }+ * });+ *+ * // In main loop+ * hrm.update(); // Must be called each frame+ * @endcode+ */+class HotReloadManager {+public:+ HotReloadManager() = default;+ ~HotReloadManager();++ HotReloadManager(const HotReloadManager&) = delete;+ HotReloadManager& operator=(const HotReloadManager&) = delete;++ /**+ * @brief Initializes the hot reload manager+ * @param enabled Whether hot reload is enabled+ */+ void init(bool enabled = true);++ /**+ * @brief Shuts down and stops all file watching+ */+ void shutdown();++ /**+ * @brief Updates file watchers (call once per frame)+ */+ void update();++ /**+ * @brief Checks if hot reload is enabled+ * @return True if enabled+ */+ bool isEnabled() const { return enabled_; }++ /**+ * @brief Enables or disables hot reload+ * @param enabled Whether to enable+ */+ void setEnabled(bool enabled);++ /**+ * @brief Watches a resource for file changes+ * @tparam T Resource type+ * @param handle Resource handle+ * @param path File path to watch+ * @param reloadFn Function to call when file changes+ */+ template<typename T>+ void watch(Handle<T> handle, const std::string& path,+ std::function<void(const std::string&)> reloadFn);++ /**+ * @brief Stops watching a file+ * @param path File path to unwatch+ */+ void unwatch(const std::string& path);++ /**+ * @brief Checks if a file is being watched+ * @param path File path+ * @return True if being watched+ */+ bool isWatching(const std::string& path) const;++ /**+ * @brief Gets the number of watched files+ * @return Number of watched files+ */+ usize getWatchCount() const { return watchedFiles_.size(); }++ // =========================================================================+ // Reload Signals+ // =========================================================================++ Signal<void(const ReloadEvent<class Shader>&)> onShaderReloaded;+ Signal<void(const ReloadEvent<class Texture>&)> onTextureReloaded;+ Signal<void(const std::string&)> onAnyFileChanged;++private:+ void onFileChanged(const std::string& path);++ bool enabled_ = false;+ bool initialized_ = false;+ std::unordered_map<std::string, WatchEntry> watchedFiles_;+ std::unordered_set<std::string> pendingReloads_;+ mutable std::mutex mutex_;+};++// =============================================================================+// Template Implementation+// =============================================================================++template<typename T>+void HotReloadManager::watch(Handle<T> handle, const std::string& path,+ std::function<void(const std::string&)> reloadFn) {+ if (!enabled_ || !initialized_) {+ return;+ }++ std::lock_guard<std::mutex> lock(mutex_);++ if (watchedFiles_.find(path) != watchedFiles_.end()) {+ return;+ }++ WatchEntry entry;+ entry.path = path;+ entry.type = std::type_index(typeid(T));+ entry.reloadFn = std::move(reloadFn);++ watchedFiles_[path] = std::move(entry);++ FileSystem::watchFile(path, [this](const std::string& changedPath) {+ onFileChanged(changedPath);+ });+}++} // namespace esengine::resourcediff --git a/src/esengine/resource/LoaderJobQueue.cpp b/src/esengine/resource/LoaderJobQueue.cppnew file mode 100644index 000000000..7ed9f5ea1--- /dev/null+++ b/src/esengine/resource/LoaderJobQueue.cpp@@ -0,0 +1,229 @@+/**+ * @file LoaderJobQueue.cpp+ * @brief Async resource loading job queue implementation+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */++#include "LoaderJobQueue.hpp"+#include "../core/Log.hpp"++namespace esengine::resource {++// =============================================================================+// Lifecycle+// =============================================================================++LoaderJobQueue::~LoaderJobQueue() {+ if (initialized_) {+ shutdown();+ }+}++void LoaderJobQueue::init(u32 numWorkers) {+ if (initialized_) {+ ES_LOG_WARN("LoaderJobQueue already initialized");+ return;+ }++ if (numWorkers == 0) {+ numWorkers = std::max(1u, std::thread::hardware_concurrency() - 1);+ }++ shutdownRequested_ = false;++ for (u32 i = 0; i < numWorkers; ++i) {+ workers_.emplace_back(&LoaderJobQueue::workerThread, this);+ }++ initialized_ = true;+ ES_LOG_INFO("LoaderJobQueue initialized with {} worker threads", numWorkers);+}++void LoaderJobQueue::shutdown() {+ if (!initialized_) {+ return;+ }++ ES_LOG_INFO("LoaderJobQueue shutting down...");++ {+ std::lock_guard<std::mutex> lock(pendingMutex_);+ shutdownRequested_ = true;+ }+ pendingCondition_.notify_all();++ for (auto& worker : workers_) {+ if (worker.joinable()) {+ worker.join();+ }+ }+ workers_.clear();++ {+ std::lock_guard<std::mutex> lock(pendingMutex_);+ while (!pendingJobs_.empty()) {+ pendingJobs_.pop();+ }+ }++ {+ std::lock_guard<std::mutex> lock(completionMutex_);+ while (!completions_.empty()) {+ completions_.pop();+ }+ }++ {+ std::lock_guard<std::mutex> lock(activeJobsMutex_);+ activeJobIds_.clear();+ }++ initialized_ = false;+ ES_LOG_INFO("LoaderJobQueue shutdown complete");+}++// =============================================================================+// Job Management+// =============================================================================++u64 LoaderJobQueue::submit(LoadJob job) {+ if (!initialized_) {+ ES_LOG_ERROR("LoaderJobQueue::submit called before init()");+ return 0;+ }++ u64 jobId = nextJobId_++;+ job.jobId = jobId;++ {+ std::lock_guard<std::mutex> lock(activeJobsMutex_);+ activeJobIds_.insert(jobId);+ }++ {+ std::lock_guard<std::mutex> lock(pendingMutex_);+ pendingJobs_.push(std::move(job));+ }+ pendingCondition_.notify_one();++ ES_LOG_DEBUG("LoaderJobQueue: Submitted job {} for '{}'", jobId, job.path);+ return jobId;+}++bool LoaderJobQueue::cancel(u64 jobId) {+ std::lock_guard<std::mutex> lock(activeJobsMutex_);+ auto it = activeJobIds_.find(jobId);+ if (it != activeJobIds_.end()) {+ activeJobIds_.erase(it);+ return true;+ }+ return false;+}++u32 LoaderJobQueue::processCompletions(u32 maxJobs) {+ u32 processed = 0;++ while (maxJobs == 0 || processed < maxJobs) {+ std::function<void()> completeFn;++ {+ std::lock_guard<std::mutex> lock(completionMutex_);+ if (completions_.empty()) {+ break;+ }+ completeFn = std::move(completions_.front());+ completions_.pop();+ }++ if (completeFn) {+ completeFn();+ }+ ++processed;+ }++ return processed;+}++u32 LoaderJobQueue::getPendingCount() const {+ std::lock_guard<std::mutex> lock(pendingMutex_);+ return static_cast<u32>(pendingJobs_.size());+}++u32 LoaderJobQueue::getCompletionCount() const {+ std::lock_guard<std::mutex> lock(completionMutex_);+ return static_cast<u32>(completions_.size());+}++bool LoaderJobQueue::isJobActive(u64 jobId) const {+ std::lock_guard<std::mutex> lock(activeJobsMutex_);+ return activeJobIds_.find(jobId) != activeJobIds_.end();+}++// =============================================================================+// Worker Thread+// =============================================================================++void LoaderJobQueue::workerThread() {+ while (true) {+ LoadJob job;++ {+ std::unique_lock<std::mutex> lock(pendingMutex_);+ pendingCondition_.wait(lock, [this] {+ return shutdownRequested_ || !pendingJobs_.empty();+ });++ if (shutdownRequested_ && pendingJobs_.empty()) {+ break;+ }++ if (pendingJobs_.empty()) {+ continue;+ }++ job = std::move(const_cast<LoadJob&>(pendingJobs_.top()));+ pendingJobs_.pop();+ }++ bool cancelled = false;+ {+ std::lock_guard<std::mutex> lock(activeJobsMutex_);+ if (activeJobIds_.find(job.jobId) == activeJobIds_.end()) {+ cancelled = true;+ }+ }++ if (cancelled) {+ continue;+ }++ ++activeJobs_;++ if (job.workFn) {+ try {+ job.workFn();+ } catch (const std::exception& e) {+ ES_LOG_ERROR("LoaderJobQueue: Job {} threw exception: {}", job.jobId, e.what());+ }+ }++ {+ std::lock_guard<std::mutex> lock(activeJobsMutex_);+ activeJobIds_.erase(job.jobId);+ }++ if (job.completeFn) {+ std::lock_guard<std::mutex> lock(completionMutex_);+ completions_.push(std::move(job.completeFn));+ }++ --activeJobs_;+ }+}++} // namespace esengine::resourcediff --git a/src/esengine/resource/LoaderJobQueue.hpp b/src/esengine/resource/LoaderJobQueue.hppnew file mode 100644index 000000000..19c492906--- /dev/null+++ b/src/esengine/resource/LoaderJobQueue.hpp@@ -0,0 +1,179 @@+/**+ * @file LoaderJobQueue.hpp+ * @brief Async resource loading job queue+ * @details Provides a thread pool for background resource loading with+ * main-thread completion callbacks.+ *+ * @author ESEngine Team+ * @date 2026+ *+ * @copyright Copyright (c) 2026 ESEngine Team+ * Licensed under the MIT License.+ */+#pragma once++// =============================================================================+// Includes+// =============================================================================++#include "../core/Types.hpp"++#include <string>+#include <functional>+#include <queue>+#include <mutex>+#include <condition_variable>+#include <thread>+#include <atomic>+#include <vector>+#include <unordered_set>++namespace esengine::resource {++// =============================================================================+// Load Priority+// =============================================================================++enum class LoadPriority : u8 {+ Low = 0,+ Normal = 1,+ High = 2,+ Immediate = 3+};++// =============================================================================+// Load Job+// =============================================================================++/**+ * @brief A single loading job for the queue+ */+struct LoadJob {+ u64 jobId = 0; ///< Unique job identifier+ std::string path; ///< Resource path for logging+ LoadPriority priority = LoadPriority::Normal;+ std::function<void()> workFn; ///< Function to execute on worker thread+ std::function<void()> completeFn; ///< Function to execute on main thread++ bool operator<(const LoadJob& other) const {+ return static_cast<u8>(priority) < static_cast<u8>(other.priority);+ }+};++// =============================================================================+// LoaderJobQueue Class+// =============================================================================++/**+ * @brief Thread pool for async resource loading+ *+ * @details Manages a pool of worker threads for background loading.+ * Completion callbacks are queued and must be processed on the+ * main thread via processCompletions().+ *+ * @code+ * LoaderJobQueue queue;+ * queue.init(4); // 4 worker threads+ *+ * // Submit a job+ * queue.submit({+ * .jobId = 1,+ * .path = "texture.png",+ * .priority = LoadPriority::Normal,+ * .workFn = [&]() { loadedData = loadFromDisk(); },+ * .completeFn = [&]() { createGPUResource(loadedData); }+ * });+ *+ * // In main loop+ * queue.processCompletions();+ *+ * queue.shutdown();+ * @endcode+ */+class LoaderJobQueue {+public:+ LoaderJobQueue() = default;+ ~LoaderJobQueue();++ LoaderJobQueue(const LoaderJobQueue&) = delete;+ LoaderJobQueue& operator=(const LoaderJobQueue&) = delete;++ /**+ * @brief Initializes the job queue with worker threads+ * @param numWorkers Number of worker threads (0 = hardware concurrency)+ */+ void init(u32 numWorkers = 0);++ /**+ * @brief Shuts down all worker threads+ * @details Waits for all pending jobs to complete+ */+ void shutdown();++ /**+ * @brief Checks if the queue is initialized+ * @return True if init() has been called+ */+ bool isInitialized() const { return initialized_; }++ /**+ * @brief Submits a job for async loading+ * @param job The job to submit+ * @return Job ID for tracking+ */+ u64 submit(LoadJob job);++ /**+ * @brief Cancels a pending job+ * @param jobId Job to cancel+ * @return True if job was cancelled (false if already running/completed)+ */+ bool cancel(u64 jobId);++ /**+ * @brief Processes completed job callbacks on the main thread+ * @param maxJobs Maximum jobs to process (0 = unlimited)+ * @return Number of completions processed+ */+ u32 processCompletions(u32 maxJobs = 0);++ /**+ * @brief Gets the number of pending jobs+ * @return Number of jobs waiting to be processed+ */+ u32 getPendingCount() const;++ /**+ * @brief Gets the number of completed jobs waiting for callbacks+ * @return Number of completions waiting+ */+ u32 getCompletionCount() const;++ /**+ * @brief Checks if a job is still pending or running+ * @param jobId Job to check+ * @return True if job is still in queue or running+ */+ bool isJobActive(u64 jobId) const;++private:+ void workerThread();++ std::vector<std::thread> workers_;+ std::priority_queue<LoadJob> pendingJobs_;+ std::queue<std::function<void()>> completions_;++ mutable std::mutex pendingMutex_;+ mutable std::mutex completionMutex_;+ std::condition_variable pendingCondition_;++ std::atomic<u64> nextJobId_{1};+ std::atomic<bool> shutdownRequested_{false};+ std::atomic<u32> activeJobs_{0};+ bool initialized_ = false;++ std::unordered_set<u64> activeJobIds_;+ mutable std::mutex activeJobsMutex_;+};++} // namespace esengine::resourcediff --git a/src/esengine/resource/ResourceManager.cpp b/src/esengine/resource/ResourceManager.cppindex 519b4a526..34467ce18 100644--- a/src/esengine/resource/ResourceManager.cpp+++ b/src/esengine/resource/ResourceManager.cpp@@ -83,7 +83,7 @@ ShaderHandle ResourceManager::loadShader(const std::string& vertPath, const std:return shaders_.add(std::move(shader), cacheKey);}-ShaderHandle ResourceManager::loadUnifiedShader(const std::string& path, const std::string& platform) {+ShaderHandle ResourceManager::loadShaderFile(const std::string& path, const std::string& platform) {auto cached = shaders_.findByPath(path);if (cached.isValid()) {shaders_.addRef(cached);diff --git a/src/esengine/resource/ResourceManager.hpp b/src/esengine/resource/ResourceManager.hppindex cdfc5d950..40fb7cea5 100644--- a/src/esengine/resource/ResourceManager.hpp+++ b/src/esengine/resource/ResourceManager.hpp@@ -126,12 +126,12 @@ public:ShaderHandle loadShader(const std::string& vertPath, const std::string& fragPath);/**- * @brief Loads a unified shader from .esshader file (with caching)+ * @brief Loads a shader from .esshader file (with caching)* @param path Path to the .esshader file* @param platform Platform variant (empty for auto-detect)* @return Handle to the shader, or invalid handle on failure*/- ShaderHandle loadUnifiedShader(const std::string& path, const std::string& platform = "");+ ShaderHandle loadShaderFile(const std::string& path, const std::string& platform = "");/*** @brief Gets a shader by handle