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
fix: input touch ID tracking and spine cache key collision
esengineea2b707090e4
diff --git a/src/esengine/platform/input/Input.cpp b/src/esengine/platform/input/Input.cppindex 44bf970ce..a79293446 100644--- a/src/esengine/platform/input/Input.cpp+++ b/src/esengine/platform/input/Input.cpp@@ -35,11 +35,14 @@ void Input::shutdown() {}void Input::update() {- // Store previous frame's stateprevTouchStates_ = touchStates_;- prevKeyStates_ = keyStates_;-- // Clear per-frame values+ std::swap(prevKeyStates_, keyStates_);+ keyStates_.clear();+ for (const auto& [key, pressed] : prevKeyStates_) {+ if (pressed) {+ keyStates_[key] = true;+ }+ }scrollDelta_ = glm::vec2(0.0f);}@@ -122,7 +125,7 @@ void Input::onTouchEvent(TouchType type, const TouchPoint& point) {// Find existing touch with this IDfor (u32 i = 0; i < MAX_TOUCH_POINTS; ++i) {- if (touchStates_[i].active && static_cast<i32>(i) == point.id) {+ if (touchStates_[i].active && touchStates_[i].touchId == point.id) {index = i;break;}@@ -145,6 +148,7 @@ void Input::onTouchEvent(TouchType type, const TouchPoint& point) {switch (type) {case TouchType::Begin:state.active = true;+ state.touchId = point.id;state.x = point.x;state.y = point.y;state.startX = point.x;@@ -159,6 +163,7 @@ void Input::onTouchEvent(TouchType type, const TouchPoint& point) {case TouchType::End:case TouchType::Cancel:state.active = false;+ state.touchId = -1;break;}diff --git a/src/esengine/platform/input/Input.hpp b/src/esengine/platform/input/Input.hppindex 7fd403bde..34c117dc7 100644--- a/src/esengine/platform/input/Input.hpp+++ b/src/esengine/platform/input/Input.hpp@@ -48,6 +48,8 @@ constexpr u32 MAX_TOUCH_POINTS = 10;struct TouchState {/** @brief Whether this touch point is currently active */bool active = false;+ /** @brief Platform-assigned touch identifier */+ i32 touchId = -1;/** @brief Current X position */f32 x = 0.0f;/** @brief Current Y position */diff --git a/src/esengine/spine/SpineRenderer.cpp b/src/esengine/spine/SpineRenderer.cppindex 4ed0c5713..f8d05293f 100644--- a/src/esengine/spine/SpineRenderer.cpp+++ b/src/esengine/spine/SpineRenderer.cpp@@ -118,16 +118,12 @@ void SpineRenderer::submit(ecs::Registry& registry) {glm::quat rotation{1.0f, 0.0f, 0.0f, 0.0f};glm::vec3 scale{1.0f};- if (registry.has<ecs::WorldTransform>(entity)) {- const auto& world = registry.get<ecs::WorldTransform>(entity);- position = world.position;- rotation = world.rotation;- scale = world.scale;- } else if (registry.has<ecs::LocalTransform>(entity)) {- const auto& local = registry.get<ecs::LocalTransform>(entity);- position = local.position;- rotation = local.rotation;- scale = local.scale;+ if (registry.has<ecs::Transform>(entity)) {+ auto& t = registry.get<ecs::Transform>(entity);+ t.ensureDecomposed();+ position = t.worldPosition;+ rotation = t.worldRotation;+ scale = t.worldScale;}renderSkeleton(instance->skeleton.get(), position, rotation, scale,diff --git a/src/esengine/spine/SpineResourceManager.cpp b/src/esengine/spine/SpineResourceManager.cppindex 7b6d7bd10..791f63f57 100644--- a/src/esengine/spine/SpineResourceManager.cpp+++ b/src/esengine/spine/SpineResourceManager.cpp@@ -95,7 +95,8 @@ resource::SpineDataHandle SpineResourceManager::load(const std::string& skeletonreturn resource::SpineDataHandle();}- auto cacheIt = cache_.find(skeletonPath);+ std::string cacheKey = skeletonPath + ":" + atlasPath + ":" + std::to_string(scale);+ auto cacheIt = cache_.find(cacheKey);if (cacheIt != cache_.end()) {return cacheIt->second;}@@ -120,7 +121,7 @@ resource::SpineDataHandle SpineResourceManager::load(const std::string& skeletonif (data) {data->atlas = std::move(atlas);}- cache_[skeletonPath] = handle;+ cache_[cacheKey] = handle;ES_LOG_INFO("Loaded Spine skeleton: {}", skeletonPath);}@@ -190,8 +191,12 @@ void SpineResourceManager::release(resource::SpineDataHandle handle) {}resource::SpineDataHandle SpineResourceManager::getByPath(const std::string& skeletonPath) const {- auto it = cache_.find(skeletonPath);- return it != cache_.end() ? it->second : resource::SpineDataHandle();+ for (const auto& [key, handle] : cache_) {+ if (key == skeletonPath || key.starts_with(skeletonPath + ":")) {+ return handle;+ }+ }+ return resource::SpineDataHandle();}usize SpineResourceManager::getLoadedCount() const {diff --git a/src/esengine/spine/SpineSystem.cpp b/src/esengine/spine/SpineSystem.cppindex 9de54308b..73b881109 100644--- a/src/esengine/spine/SpineSystem.cpp+++ b/src/esengine/spine/SpineSystem.cpp@@ -43,13 +43,13 @@ void SpineSystem::update(ecs::Registry& registry, f32 deltaTime) {}}- std::vector<Entity> toRemove;+ pending_remove_.clear();for (auto& [entity, instance] : instances_) {if (!registry.valid(entity) || !registry.has<ecs::SpineAnimation>(entity)) {- toRemove.push_back(entity);+ pending_remove_.push_back(entity);}}- for (Entity e : toRemove) {+ for (Entity e : pending_remove_) {instances_.erase(e);}}@@ -134,6 +134,10 @@ void SpineSystem::reloadAssets(ecs::Registry& registry) {auto view = registry.view<ecs::SpineAnimation>();for (auto entity : view) {auto& comp = registry.get<ecs::SpineAnimation>(entity);+ if (comp.skeletonData.isValid()) {+ resource_manager_.release(comp.skeletonData);+ comp.skeletonData = {};+ }comp.needsReload = true;}}diff --git a/src/esengine/spine/SpineSystem.hpp b/src/esengine/spine/SpineSystem.hppindex 1c32b0c0f..d74afb2b8 100644--- a/src/esengine/spine/SpineSystem.hpp+++ b/src/esengine/spine/SpineSystem.hpp@@ -173,6 +173,7 @@ private:SpineResourceManager& resource_manager_;std::unordered_map<Entity, SpineInstance> instances_;+ std::vector<Entity> pending_remove_;};} // namespace esengine::spine