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(tilemap): animation clock uses a double accumulator
esengine9ccbbce3e282
diff --git a/src/esengine/tilemap/TilemapSystem.cpp b/src/esengine/tilemap/TilemapSystem.cppindex 04f3461c6..a7afcb850 100644--- a/src/esengine/tilemap/TilemapSystem.cpp+++ b/src/esengine/tilemap/TilemapSystem.cpp@@ -257,8 +257,8 @@ void TilemapSystem::clearTileAnimations(Entity entity) {namespace {/// Index of the frame an animation shows at `elapsedMs` (looped).-u32 frameIndexAt(const TileAnimation& anim, f32 elapsedMs) {- u32 t = static_cast<u32>(std::fmod(elapsedMs, static_cast<f32>(anim.total_duration_ms)));+u32 frameIndexAt(const TileAnimation& anim, f64 elapsedMs) {+ u32 t = static_cast<u32>(std::fmod(elapsedMs, static_cast<f64>(anim.total_duration_ms)));u32 acc = 0;for (u32 i = 0; i < anim.frames.size(); ++i) {acc += anim.frames[i].duration_ms;@@ -271,8 +271,8 @@ u32 frameIndexAt(const TileAnimation& anim, f32 elapsedMs) {void TilemapSystem::advanceAnimations(Entity entity, f32 dtMs) {auto* layer = getLayerDataMut(entity);if (!layer || layer->tile_animations.empty()) return;- const f32 prev = layer->elapsed_ms;- layer->elapsed_ms += dtMs;+ const f64 prev = layer->elapsed_ms;+ layer->elapsed_ms += static_cast<f64>(dtMs);// Bump the revision only when some animation's visible frame actually// flipped — the renderer rebuilds animated chunks on this stamp instead of// every frame, so slow animations cost re-meshing only at their frame rate.diff --git a/src/esengine/tilemap/TilemapSystem.hpp b/src/esengine/tilemap/TilemapSystem.hppindex d6a115902..188b55dd1 100644--- a/src/esengine/tilemap/TilemapSystem.hpp+++ b/src/esengine/tilemap/TilemapSystem.hpp@@ -147,7 +147,7 @@ public:u32 edit_revision = 0;std::unordered_map<u16, TileAnimation> tile_animations;- f32 elapsed_ms = 0;+ f64 elapsed_ms = 0; // f64: an f32 accumulator stalls (dt < ULP) after ~day-scale uptime// Bumped only when some animation's CURRENT frame flips — ANIMATED chunk// meshes rebuild on this, not every frame.u32 anim_revision = 0;