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(resource): RM texture-budget + acquire-by-path API (E3 foundation)
yhhe6b2e7cd96bb
diff --git a/sdk/src/wasm.ts b/sdk/src/wasm.tsindex 6c6e0958f..e25acebd4 100644--- a/sdk/src/wasm.ts+++ b/sdk/src/wasm.ts@@ -51,6 +51,8 @@ export interface CppResourceManager {setTextureMetadata(handle: number, left: number, right: number, top: number, bottom: number): void;updateTextureSubregion(handle: number, x: number, y: number, width: number, height: number, pixels: number, pixelsLen: number): void;registerTextureWithPath(handle: number, path: string): void;+ setTextureBudget(bytes: number): void;+ acquireTextureByPath(path: string): number;loadBitmapFont(fntContent: string, textureHandle: number, texWidth: number, texHeight: number): number;createLabelAtlasFont(textureHandle: number, texWidth: number, texHeight: number, chars: string, charWidth: number, charHeight: number): number;releaseBitmapFont(handle: number): void;diff --git a/src/esengine/bindings/ResourceManagerBindings.cpp b/src/esengine/bindings/ResourceManagerBindings.cppindex 888cb9cdd..9d04c90fb 100644--- a/src/esengine/bindings/ResourceManagerBindings.cpp+++ b/src/esengine/bindings/ResourceManagerBindings.cpp@@ -86,6 +86,14 @@ void rm_registerTextureWithPath(resource::ResourceManager& rm, u32 handleId, conrm.registerTextureWithPath(resource::TextureHandle(handleId), path);}+void rm_setTextureBudget(resource::ResourceManager& rm, u32 bytes) {+ rm.setTextureBudget(static_cast<usize>(bytes));+}++u32 rm_acquireTextureByPath(resource::ResourceManager& rm, const std::string& path) {+ return rm.acquireTextureByPath(path).id();+}+void rm_releaseShader(resource::ResourceManager& rm, u32 handleId) {rm.releaseShader(resource::ShaderHandle(handleId));}diff --git a/src/esengine/bindings/ResourceManagerBindings.hpp b/src/esengine/bindings/ResourceManagerBindings.hppindex e9b5b39ac..6349ff939 100644--- a/src/esengine/bindings/ResourceManagerBindings.hpp+++ b/src/esengine/bindings/ResourceManagerBindings.hpp@@ -25,6 +25,8 @@ u32 rm_registerExternalTexture(resource::ResourceManager& rm, u32 glTextureId,void rm_releaseTexture(resource::ResourceManager& rm, u32 handleId);u32 rm_getTextureRefCount(resource::ResourceManager& rm, u32 handleId);void rm_registerTextureWithPath(resource::ResourceManager& rm, u32 handleId, const std::string& path);+void rm_setTextureBudget(resource::ResourceManager& rm, u32 bytes);+u32 rm_acquireTextureByPath(resource::ResourceManager& rm, const std::string& path);void rm_releaseShader(resource::ResourceManager& rm, u32 handleId);u32 rm_getShaderRefCount(resource::ResourceManager& rm, u32 handleId);u32 rm_getTextureGLId(resource::ResourceManager& rm, u32 handleId);diff --git a/src/esengine/bindings/WebSDKEntry.cpp b/src/esengine/bindings/WebSDKEntry.cppindex 2c4f29f52..28bb0d890 100644--- a/src/esengine/bindings/WebSDKEntry.cpp+++ b/src/esengine/bindings/WebSDKEntry.cpp@@ -396,6 +396,8 @@ EMSCRIPTEN_BINDINGS(esengine_renderer) {.function("setTextureMetadata", &esengine::rm_setTextureMetadata).function("updateTextureSubregion", &esengine::rm_updateTextureSubregion).function("registerTextureWithPath", &esengine::rm_registerTextureWithPath)+ .function("setTextureBudget", &esengine::rm_setTextureBudget)+ .function("acquireTextureByPath", &esengine::rm_acquireTextureByPath)#ifdef ES_ENABLE_BITMAP_TEXT.function("loadBitmapFont", &esengine::rm_loadBitmapFont).function("createLabelAtlasFont", &esengine::rm_createLabelAtlasFont)diff --git a/src/esengine/resource/ResourceManager.cpp b/src/esengine/resource/ResourceManager.cppindex d611a1856..9a5a57310 100644--- a/src/esengine/resource/ResourceManager.cpp+++ b/src/esengine/resource/ResourceManager.cpp@@ -219,6 +219,16 @@ const std::string& ResourceManager::getTexturePath(TextureHandle handle) const {return textures_.getPath(handle);}+void ResourceManager::setTextureBudget(usize bytes) {+ textures_.setBudget(bytes);+}++TextureHandle ResourceManager::acquireTextureByPath(const std::string& path) {+ auto handle = textures_.findByPath(path);+ if (handle.isValid()) textures_.addRef(handle);+ return handle;+}+TextureHandle ResourceManager::loadTextureByGUID(const std::string& guid, const std::string& path) {auto it = guidToTexture_.find(guid);if (it != guidToTexture_.end() && it->second.isValid()) {diff --git a/src/esengine/resource/ResourceManager.hpp b/src/esengine/resource/ResourceManager.hppindex bed8de6ac..33ec40e6d 100644--- a/src/esengine/resource/ResourceManager.hpp+++ b/src/esengine/resource/ResourceManager.hpp@@ -270,6 +270,19 @@ public:*/void releaseTextureByGUID(const std::string& guid);+ /**+ * @brief Sets the texture pool's resident-byte budget (0 = no eviction).+ * Over budget, refCount==0 textures are evicted oldest-first.+ */+ void setTextureBudget(usize bytes);++ /**+ * @brief Reuses a cached texture by its build path: returns its handle with an+ * added reference (reviving an evictable one), or an invalid handle if+ * none is cached. Lets the runtime dedupe + reuse textures across loads.+ */+ TextureHandle acquireTextureByPath(const std::string& path);+// =========================================================================// Texture Metadata// =========================================================================