Skip to content

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.

refactor(f1): collapse ResourceManager + Texture to web-only

esengine36480b5c8f69
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f595e4371..c2790eec8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -223,21 +223,10 @@ set(GENERATED_WEB_BINDINGS "${CMAKE_CURRENT_SOURCE_DIR}/src/esengine/bindings/We
set(GENERATED_EDITOR_API "${CMAKE_CURRENT_SOURCE_DIR}/src/esengine/bindings/EditorAPI.generated.cpp")
set(GENERATED_TS_DEFINITIONS "${CMAKE_CURRENT_SOURCE_DIR}/sdk/src/wasm.generated.ts")
-if(ES_BUILD_WEB OR ES_BUILD_WXGAME)
- list(APPEND ESENGINE_SOURCES
- src/esengine/platform/web/WebPlatform.cpp
- src/esengine/platform/web/WebFileSystem.cpp
- )
-else()
- # Web-only repo: the native platform layer (NativePlatform/NativeFileSystem/
- # FileDialog) was removed in d9a08d87. Keep only the platform-agnostic
- # sources a native tooling/test build still needs.
- list(APPEND ESENGINE_SOURCES
- src/esengine/renderer/stb_image_impl.cpp
- src/esengine/resource/HotReloadManager.cpp
- src/esengine/resource/loaders/ShaderLoader.cpp
- )
-endif()
+list(APPEND ESENGINE_SOURCES
+ src/esengine/platform/web/WebPlatform.cpp
+ src/esengine/platform/web/WebFileSystem.cpp
+)
# =============================================================================
# EHT - ESEngine Header Tool
diff --git a/src/esengine/renderer/RenderFrame.cpp b/src/esengine/renderer/RenderFrame.cpp
index 704d2ab2f..210974be1 100644
--- a/src/esengine/renderer/RenderFrame.cpp
+++ b/src/esengine/renderer/RenderFrame.cpp
@@ -394,11 +394,9 @@ void RenderFrame::collectAll(ecs::Registry& registry, u32 skipFlags) {
}
u32 RenderFrame::initBatchShader() {
-#ifndef ES_PLATFORM_WEB
- auto handle = resource_manager_.loadEngineShader("batch");
-#else
+ // The batch shader ships embedded as source (ShaderSources::BATCH_*); there is
+ // no file-load path on web.
resource::ShaderHandle handle;
-#endif
if (!handle.isValid()) {
handle = resource_manager_.createShaderWithBindings(
ShaderSources::BATCH_VERTEX,
diff --git a/src/esengine/renderer/Texture.cpp b/src/esengine/renderer/Texture.cpp
index 5e195fb1f..bcb3c770c 100644
--- a/src/esengine/renderer/Texture.cpp
+++ b/src/esengine/renderer/Texture.cpp
@@ -16,10 +16,6 @@
#include "GfxDevice.hpp"
#include "../core/Log.hpp"
-#ifndef ES_PLATFORM_WEB
-#include <stb_image.h>
-#endif
-
#include <span>
namespace esengine {
@@ -121,44 +117,6 @@ Unique<Texture> Texture::createRaw(GfxDevice& device, u32 width, u32 height, con
return texture;
}
-#ifndef ES_PLATFORM_WEB
-Unique<Texture> Texture::createFromFile(GfxDevice& device, const std::string& path) {
- int width, height, channels;
- unsigned char* data = stbi_load(path.c_str(), &width, &height, &channels, 0);
-
- if (!data) {
- ES_LOG_ERROR("Failed to load texture: {} ({})", path, stbi_failure_reason());
- return nullptr;
- }
-
- TextureFormat format = TextureFormat::RGBA8;
- if (channels == 3) {
- format = TextureFormat::RGB8;
- } else if (channels == 4) {
- format = TextureFormat::RGBA8;
- } else {
- ES_LOG_WARN("Unsupported texture format ({} channels), converting to RGBA", channels);
- stbi_image_free(data);
-
- data = stbi_load(path.c_str(), &width, &height, &channels, 4);
- if (!data) {
- ES_LOG_ERROR("Failed to convert texture to RGBA: {}", path);
- return nullptr;
- }
- format = TextureFormat::RGBA8;
- }
-
- auto texture = createRaw(device, static_cast<u32>(width), static_cast<u32>(height), data, format);
- stbi_image_free(data);
-
- if (texture) {
- ES_LOG_DEBUG("Loaded texture: {} ({}x{}, {} channels)", path, width, height, channels);
- }
-
- return texture;
-}
-#endif
-
Unique<Texture> Texture::createFromExternalId(GfxDevice& device, u32 glTextureId, u32 width, u32 height,
TextureFormat format) {
auto texture = makeUnique<Texture>();
diff --git a/src/esengine/renderer/Texture.hpp b/src/esengine/renderer/Texture.hpp
index 9848fe051..1cf9061d7 100644
--- a/src/esengine/renderer/Texture.hpp
+++ b/src/esengine/renderer/Texture.hpp
@@ -113,9 +113,6 @@ struct TextureSpecification {
* creation from pixel data, files, or empty specifications.
*
* @code
- * // Create from file
- * auto texture = Texture::createFromFile("assets/player.png");
- *
* // Create from pixel data
* std::vector<u8> pixels = {...}; // RGBA data
* auto texture = Texture::create(64, 64, std::span(pixels));
@@ -174,17 +171,6 @@ public:
TextureFormat format = TextureFormat::RGBA8,
bool flipY = false);
- /**
- * @brief Creates a texture from an image file
- * @param path Path to the image file
- * @return Unique pointer to the texture, or nullptr on failure
- *
- * @note Supported formats depend on the image loading implementation.
- */
-#ifndef ES_PLATFORM_WEB
- static Unique<Texture> createFromFile(GfxDevice& device, const std::string& path);
-#endif
-
// =========================================================================
// Operations
// =========================================================================
diff --git a/src/esengine/renderer/stb_image_impl.cpp b/src/esengine/renderer/stb_image_impl.cpp
deleted file mode 100644
index b21469897..000000000
--- a/src/esengine/renderer/stb_image_impl.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-// STB Image implementation file
-// PNG, JPEG, BMP support via stb_image
-// WebP uses browser's native decoding API
-
-#define STB_IMAGE_IMPLEMENTATION
-#define STBI_ONLY_PNG
-#define STBI_ONLY_JPEG
-#define STBI_ONLY_BMP
-#define STBI_NO_STDIO
-#define STBI_NO_LINEAR
-#define STBI_NO_HDR
-
-#include <stb_image.h>
diff --git a/src/esengine/resource/HotReloadManager.cpp b/src/esengine/resource/HotReloadManager.cpp
deleted file mode 100644
index 6b123aa7c..000000000
--- a/src/esengine/resource/HotReloadManager.cpp
+++ /dev/null
@@ -1,148 +0,0 @@
-/**
- * @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"
-
-#include <vector>
-
-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::vector<std::string> reloadsToProcess;
- {
- std::lock_guard<std::mutex> lock(mutex_);
- const auto now = std::chrono::steady_clock::now();
- const auto quietFor = std::chrono::milliseconds(debounce_ms_);
- for (auto it = pendingReloads_.begin(); it != pendingReloads_.end(); ) {
- if (now - it->second >= quietFor) {
- reloadsToProcess.push_back(it->first);
- it = pendingReloads_.erase(it);
- } else {
- ++it;
- }
- }
- }
-
- 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_[path] = std::chrono::steady_clock::now();
-}
-
-} // namespace esengine::resource
diff --git a/src/esengine/resource/HotReloadManager.hpp b/src/esengine/resource/HotReloadManager.hpp
deleted file mode 100644
index 60ee2effe..000000000
--- a/src/esengine/resource/HotReloadManager.hpp
+++ /dev/null
@@ -1,214 +0,0 @@
-/**
- * @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 <chrono>
-#include <string>
-#include <mutex>
-#include <unordered_map>
-#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(); }
-
- /** Time window (ms) a file must be quiet for before reload fires. */
- void setDebounceMs(u32 ms) { debounce_ms_ = ms; }
- u32 getDebounceMs() const { return debounce_ms_; }
-
- // =========================================================================
- // 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;
- u32 debounce_ms_ = 150;
- std::unordered_map<std::string, WatchEntry> watchedFiles_;
- std::unordered_map<std::string, std::chrono::steady_clock::time_point> 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);
- }
-
- // Register outside the lock: if a backend delivers its first notify
- // synchronously during registration, onFileChanged would otherwise
- // deadlock trying to re-acquire mutex_.
- FileSystem::watchFile(path, [this](const std::string& changedPath) {
- onFileChanged(changedPath);
- });
-}
-
-} // namespace esengine::resource
diff --git a/src/esengine/resource/LoaderRegistry.hpp b/src/esengine/resource/LoaderRegistry.hpp
index d5e11be55..e5bcfd7f7 100644
--- a/src/esengine/resource/LoaderRegistry.hpp
+++ b/src/esengine/resource/LoaderRegistry.hpp
@@ -34,12 +34,11 @@ namespace esengine::resource {
*
* @code
* LoaderRegistry registry;
- * registry.registerLoader<Shader>(makeUnique<ShaderFileLoader>());
- * registry.registerLoader<Texture>(makeUnique<TextureFileLoader>());
+ * registry.registerLoader<Texture>(makeUnique<MyTextureLoader>());
*
- * auto* loader = registry.getLoader<Shader>();
- * if (loader && loader->canLoad("my.esshader")) {
- * auto result = loader->load({"my.esshader"});
+ * auto* loader = registry.getLoader<Texture>();
+ * if (loader && loader->canLoad("my.png")) {
+ * auto result = loader->load({"my.png"});
* }
* @endcode
*/
diff --git a/src/esengine/resource/ResourceManager.cpp b/src/esengine/resource/ResourceManager.cpp
index b1a938f5c..63e55ac58 100644
--- a/src/esengine/resource/ResourceManager.cpp
+++ b/src/esengine/resource/ResourceManager.cpp
@@ -11,14 +11,7 @@
#include "ResourceManager.hpp"
#include "../text/BitmapFont.hpp"
-#ifndef ES_PLATFORM_WEB
-#include "loaders/ShaderLoader.hpp"
-#include <json.hpp>
-#include <fstream>
-#include <stb_image.h>
-#endif
#include "../core/Log.hpp"
-#include "../platform/PathResolver.hpp"
#include "../renderer/GfxDevice.hpp"
#include "../renderer/Shader.hpp"
#include "../renderer/Texture.hpp"
@@ -34,11 +27,6 @@ void ResourceManager::init(GfxDevice& device) {
device_ = &device;
-#ifndef ES_PLATFORM_WEB
- stbi_set_flip_vertically_on_load(true);
- hotReloadManager_.init(true);
-#endif
-
stats_ = {};
initialized_ = true;
}
@@ -51,11 +39,6 @@ void ResourceManager::shutdown() {
ES_LOG_INFO("ResourceManager shutting down (shaders: {}, textures: {}, vbos: {}, ibos: {}, fonts: {})",
shaders_.size(), textures_.size(), vertexBuffers_.size(), indexBuffers_.size(), fonts_.size());
-#ifndef ES_PLATFORM_WEB
- hotReloadManager_.shutdown();
- shaderPaths_.clear();
-#endif
-
guidToTexture_.clear();
textureMetadata_.clear();
fonts_.clear();
@@ -69,11 +52,7 @@ void ResourceManager::shutdown() {
}
void ResourceManager::update() {
-#ifndef ES_PLATFORM_WEB
- if (initialized_) {
- hotReloadManager_.update();
- }
-#endif
+ // Hot reload is editor/native-only; no-op on web.
}
// =============================================================================
@@ -122,67 +101,6 @@ ShaderHandle ResourceManager::loadShader(const std::string& vertPath, const std:
return shaders_.add(std::move(shader), cacheKey);
}
-#ifndef ES_PLATFORM_WEB
-ShaderHandle ResourceManager::loadShaderFile(const std::string& path, const std::string& platform) {
- auto cached = shaders_.findByPath(path);
- if (cached.isValid()) {
- shaders_.addRef(cached);
- stats_.cacheHits++;
- return cached;
- }
-
- ShaderFileLoader loader(*device_);
- LoadRequest request;
- request.path = path;
- request.platform = platform;
- auto result = loader.load(request);
- if (!result.isOk()) {
- stats_.cacheMisses++;
- return ShaderHandle();
- }
-
- stats_.cacheMisses++;
- auto handle = shaders_.add(std::move(result.resource), path);
-
-#ifndef ES_PLATFORM_WEB
- if (handle.isValid()) {
- shaderPaths_[handle.id()] = path;
- hotReloadManager_.watch<Shader>(handle, path, [this, handle](const std::string& p) {
- reloadShader(handle, p);
- });
- }
-#endif
-
- return handle;
-}
-
-ShaderHandle ResourceManager::loadEngineShader(const std::string& name, const std::string& platform) {
- std::string cacheKey = "engine:" + name;
- auto cached = shaders_.findByPath(cacheKey);
- if (cached.isValid()) {
- shaders_.addRef(cached);
- stats_.cacheHits++;
- return cached;
- }
-
- std::string path = PathResolver::editorPath("src/esengine/data/shaders/" + name + ".esshader");
-
- ShaderFileLoader loader(*device_);
- LoadRequest request;
- request.path = path;
- request.platform = platform;
- auto result = loader.load(request);
- if (!result.isOk()) {
- ES_LOG_ERROR("Failed to load engine shader '{}': {}", name, result.errorMessage);
- stats_.cacheMisses++;
- return ShaderHandle();
- }
-
- stats_.cacheMisses++;
- return shaders_.add(std::move(result.resource), cacheKey);
-}
-#endif
-
Shader* ResourceManager::getShader(ShaderHandle handle) {
return shaders_.get(handle);
}
@@ -233,40 +151,11 @@ TextureHandle ResourceManager::loadTexture(const std::string& path) {
return cached;
}
-#ifdef ES_PLATFORM_WEB
+ // Web decodes images JS-side and uploads via createTexture/registerExternalTexture;
+ // there is no C++ file-decode path.
ES_LOG_ERROR("loadTexture from file not supported on Web, use createTexture with pixel data");
stats_.cacheMisses++;
return TextureHandle();
-#else
- auto texture = Texture::createFromFile(*device_, path);
- if (!texture) {
- stats_.cacheMisses++;
- return TextureHandle();
- }
-
- stats_.cacheMisses++;
- auto handle = textures_.add(std::move(texture), path);
-
- // Load .meta file if exists
- std::string metaPath = path + ".meta";
- std::ifstream metaFile(metaPath);
- if (metaFile.is_open()) {
- std::string content((std::istreambuf_iterator<char>(metaFile)),
- std::istreambuf_iterator<char>());
- auto j = nlohmann::json::parse(content, nullptr, false);
- if (!j.is_discarded() && j.contains("sliceBorder")) {
- TextureMetadata metadata;
- auto& sb = j["sliceBorder"];
- metadata.sliceBorder.left = sb.value("left", 0.0f);
- metadata.sliceBorder.right = sb.value("right", 0.0f);
- metadata.sliceBorder.top = sb.value("top", 0.0f);
- metadata.sliceBorder.bottom = sb.value("bottom", 0.0f);
- setTextureMetadata(handle, metadata);
- }
- }
-
- return handle;
-#endif
}
Texture* ResourceManager::getTexture(TextureHandle handle) {
@@ -452,36 +341,11 @@ BitmapFontHandle ResourceManager::loadBitmapFont(const std::string& fntPath) {
return cached;
}
-#ifdef ES_PLATFORM_WEB
+ // Web has no filesystem font-decode path; fonts come via createBitmapFont
+ // with content + texture already supplied from JS.
ES_LOG_ERROR("loadBitmapFont from file not supported on Web");
stats_.cacheMisses++;
return BitmapFontHandle();
-#else
- std::ifstream fntFile(fntPath);
- if (!fntFile.is_open()) {
- ES_LOG_ERROR("Failed to open BMFont file: {}", fntPath);
- stats_.cacheMisses++;
- return BitmapFontHandle();
- }
-
- std::string content((std::istreambuf_iterator<char>(fntFile)),
- std::istreambuf_iterator<char>());
-
- auto font = makeUnique<text::BitmapFont>();
- std::string basePath;
- auto lastSlash = fntPath.find_last_of("/\\");
- if (lastSlash != std::string::npos) {
- basePath = fntPath.substr(0, lastSlash);
- }
-
- if (!font->loadFromFntText(content, basePath, *this)) {
- stats_.cacheMisses++;
- return BitmapFontHandle();
- }
-
- stats_.cacheMisses++;
- return fonts_.add(std::move(font), fntPath);
-#endif
}
BitmapFontHandle ResourceManager::createBitmapFont(const std::string& fntContent,
@@ -538,52 +402,4 @@ void ResourceManager::resetCacheStats() {
stats_.cacheMisses = 0;
}
-#ifndef ES_PLATFORM_WEB
-void ResourceManager::reloadShader(ShaderHandle handle, const std::string& path) {
- if (!handle.isValid()) {
- return;
- }
-
- auto it = shaderPaths_.find(handle.id());
- if (it == shaderPaths_.end()) {
- ES_LOG_ERROR("HotReload: Shader path not found for handle {}", handle.id());
- return;
- }
-
- ES_LOG_INFO("HotReload: Reloading shader '{}'", path);
-
- ShaderFileLoader loader(*device_);
- LoadRequest request;
- request.path = path;
- auto result = loader.load(request);
-
- ReloadEvent<Shader> event;
- event.handle = handle;
- event.path = path;
-
- if (!result.isOk()) {
- ES_LOG_ERROR("HotReload: Failed to reload shader '{}': {}", path, result.errorMessage);
- event.success = false;
- event.errorMessage = result.errorMessage;
- hotReloadManager_.onShaderReloaded.publish(event);
- return;
- }
-
- Shader* oldShader = shaders_.get(handle);
- if (!oldShader) {
- ES_LOG_ERROR("HotReload: Shader handle {} is no longer valid", handle.id());
- event.success = false;
- event.errorMessage = "Shader handle no longer valid";
- hotReloadManager_.onShaderReloaded.publish(event);
- return;
- }
-
- *oldShader = std::move(*result.resource);
-
- ES_LOG_INFO("HotReload: Successfully reloaded shader '{}'", path);
- event.success = true;
- hotReloadManager_.onShaderReloaded.publish(event);
-}
-#endif
-
} // namespace esengine::resource
diff --git a/src/esengine/resource/ResourceManager.hpp b/src/esengine/resource/ResourceManager.hpp
index 95a112d75..d3272ea1d 100644
--- a/src/esengine/resource/ResourceManager.hpp
+++ b/src/esengine/resource/ResourceManager.hpp
@@ -22,9 +22,6 @@
#include "ResourcePool.hpp"
#include "LoaderRegistry.hpp"
#include "TextureMetadata.hpp"
-#ifndef ES_PLATFORM_WEB
-#include "HotReloadManager.hpp"
-#endif
#include "../renderer/Shader.hpp"
#include "../renderer/Texture.hpp"
#include "../renderer/Buffer.hpp"
@@ -121,20 +118,6 @@ public:
*/
void update();
-#ifndef ES_PLATFORM_WEB
- /**
- * @brief Gets the hot reload manager
- * @return Reference to the hot reload manager
- */
- HotReloadManager& getHotReloadManager() { return hotReloadManager_; }
-
- /**
- * @brief Gets the hot reload manager (const)
- * @return Const reference to the hot reload manager
- */
- const HotReloadManager& getHotReloadManager() const { return hotReloadManager_; }
-#endif
-
// =========================================================================
// Shader Resources
// =========================================================================
@@ -157,24 +140,6 @@ public:
*/
ShaderHandle loadShader(const std::string& vertPath, const std::string& fragPath);
-#ifndef ES_PLATFORM_WEB
- /**
- * @brief Loads a shader from .esshader file (with caching)
- * @param path Path to the .esshader file (relative to project)
- * @param platform Platform variant (empty for auto-detect)
- * @return Handle to the shader, or invalid handle on failure
- */
- ShaderHandle loadShaderFile(const std::string& path, const std::string& platform = "");
-
- /**
- * @brief Loads an engine shader from src/esengine/data/shaders/ (with caching)
- * @param name Shader name without path or extension (e.g., "grid", "ui")
- * @param platform Platform variant (empty for auto-detect)
- * @return Handle to the shader, or invalid handle on failure
- */
- ShaderHandle loadEngineShader(const std::string& name, const std::string& platform = "");
-#endif
-
/**
* @brief Gets a shader by handle
* @param handle The shader handle
@@ -487,10 +452,6 @@ public:
LoaderRegistry& getLoaderRegistry() { return loaderRegistry_; }
private:
-#ifndef ES_PLATFORM_WEB
- void reloadShader(ShaderHandle handle, const std::string& path);
-#endif
-
ResourcePool<Shader> shaders_;
ResourcePool<Texture> textures_;
ResourcePool<VertexBuffer> vertexBuffers_;
@@ -498,10 +459,6 @@ private:
ResourcePool<text::BitmapFont> fonts_;
std::unordered_map<std::string, TextureHandle> guidToTexture_;
std::unordered_map<TextureHandle::IdType, TextureMetadata> textureMetadata_;
-#ifndef ES_PLATFORM_WEB
- std::unordered_map<ShaderHandle::IdType, std::string> shaderPaths_;
- HotReloadManager hotReloadManager_;
-#endif
LoaderRegistry loaderRegistry_;
mutable ResourceStats stats_;
GfxDevice* device_ = nullptr; ///< GPU device for resource creation (set in init)
diff --git a/src/esengine/resource/loaders/ShaderLoader.cpp b/src/esengine/resource/loaders/ShaderLoader.cpp
deleted file mode 100644
index 4a06bd263..000000000
--- a/src/esengine/resource/loaders/ShaderLoader.cpp
+++ /dev/null
@@ -1,153 +0,0 @@
-/**
- * @file ShaderLoader.cpp
- * @brief Shader resource loader implementation
- *
- * @author ESEngine Team
- * @date 2026
- *
- * @copyright Copyright (c) 2026 ESEngine Team
- * Licensed under the MIT License.
- */
-
-#include "ShaderLoader.hpp"
-#include "../../platform/FileSystem.hpp"
-#include "../../core/Log.hpp"
-
-#include <algorithm>
-
-namespace esengine::resource {
-
-// =============================================================================
-// ShaderFileLoader Implementation
-// =============================================================================
-
-bool ShaderFileLoader::canLoad(const std::string& path) const {
- auto extensions = getSupportedExtensions();
- for (const auto& ext : extensions) {
- if (path.size() >= ext.size() &&
- path.compare(path.size() - ext.size(), ext.size(), ext) == 0) {
- return true;
- }
- }
- return false;
-}
-
-std::vector<std::string> ShaderFileLoader::getSupportedExtensions() const {
- return {".esshader"};
-}
-
-LoadResult<Shader> ShaderFileLoader::load(const LoadRequest& request) {
- if (!FileSystem::fileExists(request.path)) {
- return LoadResult<Shader>::err("Shader file not found: " + request.path);
- }
-
- std::string source = FileSystem::readTextFile(request.path);
- if (source.empty()) {
- return LoadResult<Shader>::err("Failed to read shader file: " + request.path);
- }
-
- std::string shaderDir;
- const usize slash = request.path.find_last_of("/\\");
- if (slash != std::string::npos) {
- shaderDir = request.path.substr(0, slash);
- }
-
- std::vector<std::string> includedPaths;
- ShaderIncludeResolver resolver = [&shaderDir, &includedPaths](const std::string& include)
- -> std::optional<std::string> {
- std::string full = shaderDir.empty() ? include : shaderDir + "/" + include;
- if (!FileSystem::fileExists(full)) return std::nullopt;
- std::string contents = FileSystem::readTextFile(full);
- if (contents.empty()) return std::nullopt;
- includedPaths.push_back(std::move(full));
- return contents;
- };
-
- auto result = loadFromSource(source, request.platform, resolver);
- result.dependencies.push_back(request.path);
- for (auto& dep : includedPaths) {
- result.dependencies.push_back(std::move(dep));
- }
-
- if (result.isOk()) {
- ES_LOG_DEBUG("ShaderFileLoader: Loaded shader from {}", request.path);
- }
-
- return result;
-}
-
-LoadResult<Shader> ShaderFileLoader::loadFromSource(const std::string& source,
- const std::string& platform) {
- return loadFromSource(source, platform, ShaderIncludeResolver{});
-}
-
-LoadResult<Shader> ShaderFileLoader::loadFromSource(const std::string& source,
- const std::string& platform,
- const ShaderIncludeResolver& resolver) {
- ParsedShader parsed = ShaderParser::parse(source, resolver);
- if (!parsed.valid) {
- ES_LOG_ERROR("ShaderFileLoader: {}", parsed.errorMessage);
- return LoadResult<Shader>::err("Shader parse error: " + parsed.errorMessage);
- }
-
- std::string effectivePlatform = platform.empty() ? getDefaultPlatform() : platform;
-
- auto vertexAssembled = ShaderParser::assembleStageEx(parsed, ShaderStage::Vertex, effectivePlatform);
- auto fragmentAssembled = ShaderParser::assembleStageEx(parsed, ShaderStage::Fragment, effectivePlatform);
-
- if (vertexAssembled.source.empty()) {
- return LoadResult<Shader>::err("Failed to assemble vertex shader");
- }
-
- if (fragmentAssembled.source.empty()) {
- return LoadResult<Shader>::err("Failed to assemble fragment shader");
- }
-
- auto outcome = Shader::createEx(device_, vertexAssembled.source, fragmentAssembled.source);
- if (!outcome.shader || !outcome.shader->isValid()) {
- std::string remapped = outcome.log;
- const char* stageLabel = "unknown";
- switch (outcome.failedStage) {
- case ShaderStageFailure::Vertex: {
- stageLabel = "vertex";
- auto it = parsed.stageLineMaps.find(ShaderStage::Vertex);
- if (it != parsed.stageLineMaps.end()) {
- remapped = ShaderParser::remapCompilerLog(
- outcome.log, it->second, vertexAssembled.headerLineCount);
- }
- break;
- }
- case ShaderStageFailure::Fragment: {
- stageLabel = "fragment";
- auto it = parsed.stageLineMaps.find(ShaderStage::Fragment);
- if (it != parsed.stageLineMaps.end()) {
- remapped = ShaderParser::remapCompilerLog(
- outcome.log, it->second, fragmentAssembled.headerLineCount);
- }
- break;
- }
- case ShaderStageFailure::Link:
- stageLabel = "link";
- break;
- case ShaderStageFailure::None:
- break;
- }
- ES_LOG_ERROR("ShaderFileLoader: {} stage failed — {}", stageLabel, remapped);
- return LoadResult<Shader>::err(
- std::string{"Shader "} + stageLabel + " stage failed:\n" + remapped);
- }
-
- ES_LOG_DEBUG("ShaderFileLoader: Successfully compiled shader '{}'", parsed.name);
- return LoadResult<Shader>::ok(std::move(outcome.shader));
-}
-
-std::string ShaderFileLoader::getDefaultPlatform() {
-#ifdef ES_PLATFORM_WEB
- return "WEBGL";
-#else
- return "DESKTOP";
-#endif
-}
-
-
-} // namespace esengine::resource
diff --git a/src/esengine/resource/loaders/ShaderLoader.hpp b/src/esengine/resource/loaders/ShaderLoader.hpp
deleted file mode 100644
index 81fb65b1a..000000000
--- a/src/esengine/resource/loaders/ShaderLoader.hpp
+++ /dev/null
@@ -1,97 +0,0 @@
-/**
- * @file ShaderLoader.hpp
- * @brief Shader resource loader for .esshader files
- * @details Loads unified shader files and creates Shader 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 "../ResourceLoader.hpp"
-#include "../ShaderParser.hpp"
-#include "../../renderer/Shader.hpp"
-
-#include <string>
-
-namespace esengine { class GfxDevice; }
-
-namespace esengine::resource {
-
-// =============================================================================
-// ShaderLoadResult (legacy compatibility)
-// =============================================================================
-
-using ShaderLoadResult = LoadResult<Shader>;
-
-// =============================================================================
-// ShaderFileLoader Class
-// =============================================================================
-
-/**
- * @brief Loader for unified .esshader files
- *
- * @details Implements ResourceLoader<Shader> interface for loading shaders
- * from the unified .esshader format. Supports platform variants.
- *
- * @code
- * ShaderFileLoader loader;
- * auto result = loader.load({"shaders/sprite.esshader"});
- * if (result.isOk()) {
- * Shader* shader = result.resource.get();
- * }
- * @endcode
- */
-class ShaderFileLoader : public ResourceLoader<Shader> {
-public:
- /**
- * @brief Constructs the loader bound to a graphics device.
- * @param device Device used to compile/link the shader program.
- */
- explicit ShaderFileLoader(GfxDevice& device) : device_(device) {}
-
- bool canLoad(const std::string& path) const override;
- std::vector<std::string> getSupportedExtensions() const override;
- LoadResult<Shader> load(const LoadRequest& request) override;
- const char* getTypeName() const override { return "Shader"; }
-
- /**
- * @brief Loads a shader from source string (no include support)
- * @param source Complete .esshader content
- * @param platform Platform variant to use (empty for auto-detect)
- * @return Load result with shader or error message
- */
- LoadResult<Shader> loadFromSource(const std::string& source,
- const std::string& platform = "");
-
- /**
- * @brief Loads a shader from source string, expanding #include via resolver
- * @param source Complete .esshader content
- * @param platform Platform variant to use (empty for auto-detect)
- * @param resolver Callback invoked to fetch included files
- * @return Load result with shader or error message
- */
- LoadResult<Shader> loadFromSource(const std::string& source,
- const std::string& platform,
- const ShaderIncludeResolver& resolver);
-
- /**
- * @brief Gets the default platform identifier for current build
- * @return Platform string (e.g., "WEBGL", "DESKTOP")
- */
- static std::string getDefaultPlatform();
-
-private:
- GfxDevice& device_;
-};
-
-
-} // namespace esengine::resource