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
Revert "perf(transform): reuse authored matrix decomposition across frames"
yhh69c555a7627e
diff --git a/src/esengine/ecs/TransformSystem.hpp b/src/esengine/ecs/TransformSystem.hppindex 463a35ea7..4935d0f59 100644--- a/src/esengine/ecs/TransformSystem.hpp+++ b/src/esengine/ecs/TransformSystem.hpp@@ -80,10 +80,6 @@ public:/*** @brief Collect which entities' composed OUTPUT changed, from now on- * @details Off by default: only a consumer maintaining an incremental- * structure needs the change mailbox. Matrix equality also protects- * lazy world-TRS caches independently of tracking. Turning tracking- * on does not compose.* @note One consumer. The pending set is a mailbox, not a per-reader journal:* whoever acknowledges empties it for everyone.*/@@ -129,7 +125,8 @@ private:std::vector<Entity> dirty_to_clear_;- // Only a caller building an incremental structure pays to collect changes.+ // Off on the shipped path: composition answers "are they stale", and only a+ // caller building an incremental structure pays for "which ones moved".bool tracking_ = false;std::vector<Entity>* changedOut_ = nullptr;std::vector<Entity> changed_;@@ -298,18 +295,12 @@ private:flatCollapsed = transform->scale.x == 0 || transform->scale.y == 0|| (task.parentFlatCollapsed && transform->rotation.x == 0 && transform->rotation.y == 0);const auto matrix = *task.parentMatrix * math::compose(transform->position, transform->rotation, transform->scale);- const bool changed = matrix != transform->cachedMatrix_;if (changedOut_) {++visited_;- if (changed) changedOut_->push_back(task.entity);- }- // A moving sibling can require a hierarchy pass without- // changing this entity. Keep its derived TRS warm: a few- // physics bodies must not force every static mesh to decompose.- if (changed) {- transform->cachedMatrix_ = matrix;- transform->decomposed_ = false;+ if (matrix != transform->cachedMatrix_) changedOut_->push_back(task.entity);}+ transform->cachedMatrix_ = matrix;+ transform->decomposed_ = false;} else if (keepStatic) {flatCollapsed = registry.has<FlatGeometryCollapsed>(task.entity);}diff --git a/tests/ecs/test_transform_traversal.cpp b/tests/ecs/test_transform_traversal.cppindex e31fe1662..0794e5008 100644--- a/tests/ecs/test_transform_traversal.cpp+++ b/tests/ecs/test_transform_traversal.cpp@@ -189,23 +189,3 @@ TEST_CASE("siblings retain their own parent matrices during iterative traversal"const std::vector<Entity> expected{root, siblings[0], left, siblings[1], right};CHECK(system.pendingChanges() == expected);}--TEST_CASE("moving siblings preserve unchanged descendant decomposition caches") {- Registry r; TransformSystem system;- const auto root=r.create(), fixed=r.create(), moving=r.create(), leaf=r.create();- r.emplace<Transform>(root).scale={100,100,100};- r.emplace<Transform>(fixed).position={2,3,4};- r.emplace<Transform>(moving).position={5,6,7};- r.emplace<Transform>(leaf).position={1,0,0};- setParent(r,fixed,root);setParent(r,moving,root);setParent(r,leaf,moving);- system.ensureComposed(r);- for(auto e:{fixed,moving,leaf})r.get<Transform>(e).ensureDecomposed();- r.get<Transform>(moving).position.x+=2;- invalidateTransformComposition(); system.ensureComposed(r);- CHECK(r.get<Transform>(fixed).decomposed_);- CHECK_FALSE(r.get<Transform>(moving).decomposed_);- CHECK_FALSE(r.get<Transform>(leaf).decomposed_);- CHECK(r.get<Transform>(fixed).worldPosition==glm::vec3(200,300,400));- r.get<Transform>(leaf).ensureDecomposed();- CHECK(r.get<Transform>(leaf).worldPosition.x==doctest::Approx(800));-}