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.

fix(renderer): skip collapsed flat hierarchies without epsilon culling

yhhf95a28586d29
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c692ac36b..7a292908d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,8 @@ published separately; it ships inside the editor.
### Fixed
+- **Collapsed 2D hierarchies skip geometry and recover reliably.** Transform composition propagates authored zero-area state through planar rotations and transformless groups, preventing floating-point residue from reviving degenerate boxes. Sprite, UI, native bitmap text, picking and empty scissor/stencil subtrees share the guard. Valid tiny spans and children that regain area through a 3D tilt remain available; hidden bitmap runs skip font layout and submission.
+
- **Advertising requests preserve a single active break.** Rewarded and interstitial requests reject immediately while another ad is showing, before creating a competing unit. The active break retains its showing flag, clock pause and audio suspension until it closes; errors release the guard so a later request can proceed. Rejected requests are not queued for playback.
- **UI geometry, picking and scissors retain parent-induced shear.** Solid, image, nine-slice, tiled and filled visuals use the complete parent basis for vertices and camera bounds. UI, editor and world-sprite picking test the same local boxes, and scissor bounds project their actual corners. Mirrored radial fills retain their wedges and UVs; axis-aligned positive UI keeps its existing geometry path.
diff --git a/src/esengine/ecs/FlatGeometry.hpp b/src/esengine/ecs/FlatGeometry.hpp
new file mode 100644
index 000000000..b69ed4317
--- /dev/null
+++ b/src/esengine/ecs/FlatGeometry.hpp
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+#pragma once
+
+#include "components/Transform.hpp"
+#include "components/Hierarchy.hpp"
+#include "Registry.hpp"
+
+#include <cmath>
+
+namespace esengine::ecs {
+
+// Derived by TransformSystem; never serialized or exposed as an authored component.
+struct FlatGeometryCollapsed {};
+
+// A flat local box has area only when its two transformed axes span a plane.
+// Double products preserve tiny finite spans without an arbitrary epsilon cutoff.
+inline bool hasFlatGeometryArea(Transform& transform, bool parented) {
+ transform.ensureDecomposed();
+ if (!parented) {
+ return transform.worldScale.x != 0 && transform.worldScale.y != 0
+ && std::isfinite(transform.worldScale.x) && std::isfinite(transform.worldScale.y);
+ }
+ const glm::dvec3 x(transform.cachedMatrix_[0]), y(transform.cachedMatrix_[1]);
+ const auto cross = glm::cross(x, y);
+ return (cross.x != 0 || cross.y != 0 || cross.z != 0)
+ && std::isfinite(cross.x) && std::isfinite(cross.y) && std::isfinite(cross.z);
+}
+
+inline bool hasFlatGeometryArea(Registry& registry, Entity entity, Transform& transform) {
+ return !registry.has<FlatGeometryCollapsed>(entity)
+ && hasFlatGeometryArea(transform, registry.has<Parent>(entity));
+}
+
+} // namespace esengine::ecs
diff --git a/src/esengine/ecs/TransformSystem.hpp b/src/esengine/ecs/TransformSystem.hpp
index e961162b9..4156e8a79 100644
--- a/src/esengine/ecs/TransformSystem.hpp
+++ b/src/esengine/ecs/TransformSystem.hpp
@@ -18,6 +18,7 @@
#include "Registry.hpp"
#include "components/Transform.hpp"
#include "components/Hierarchy.hpp"
+#include "FlatGeometry.hpp"
#include "../math/Math.hpp"
#include <algorithm>
@@ -139,6 +140,7 @@ private:
Entity entity;
const glm::mat4* parentMatrix;
bool parentDirty;
+ bool parentFlatCollapsed;
};
std::vector<TraversalTask> pending_;
std::vector<u32> traversal_stamps_;
@@ -146,6 +148,18 @@ private:
bool have_dirty_ = false;
bool have_static_ = false;
bool have_children_ = false;
+ bool have_collapsed_ = false;
+
+ void setFlatCollapsed(Registry& registry, Entity entity, bool collapsed) {
+ if (!collapsed && !have_collapsed_) return;
+ const bool present = have_collapsed_ && registry.has<FlatGeometryCollapsed>(entity);
+ if (collapsed && !present) {
+ registry.emplace<FlatGeometryCollapsed>(entity);
+ have_collapsed_ = true;
+ } else if (!collapsed && present) {
+ registry.remove<FlatGeometryCollapsed>(entity);
+ }
+ }
bool visitOnce(Entity entity) {
const auto index = entity.index();
@@ -185,11 +199,12 @@ private:
have_dirty_ = !registry.entitiesWith<TransformDirty>().empty();
have_static_ = !registry.entitiesWith<TransformStatic>().empty();
have_children_ = !registry.entitiesWith<Children>().empty();
+ have_collapsed_ = !registry.entitiesWith<FlatGeometryCollapsed>().empty();
const bool haveParents = !registry.entitiesWith<Parent>().empty();
// eachLive (no per-frame snapshot copy of the entity list): the callback
- // only reads/writes Transform fields and defers TransformDirty removal to
- // dirty_to_clear_, so it never structurally mutates the Transform pool.
+ // writes Transform fields and derived collapse tags, while deferring
+ // TransformDirty removal; the Transform pool itself stays stable.
registry.eachLive<Transform>([&registry, this, haveParents](Entity entity, Transform& transform) {
if (!haveParents || !registry.has<Parent>(entity)) {
bool isStatic = have_static_ && registry.has<TransformStatic>(entity);
@@ -200,7 +215,8 @@ private:
if (children) {
visitOnce(entity);
for (Entity child : children->entities) {
- updateEntityTransform(registry, child, transform.cachedMatrix_, false);
+ updateEntityTransform(registry, child, transform.cachedMatrix_, false,
+ registry.has<FlatGeometryCollapsed>(entity));
}
}
return;
@@ -215,7 +231,8 @@ private:
registry.eachLive<Children>([&registry, this, &identity](Entity entity, Children& children) {
if (registry.has<Transform>(entity) || registry.has<Parent>(entity) || !visitOnce(entity)) return;
if (have_dirty_ && registry.has<TransformDirty>(entity)) dirty_to_clear_.push_back(entity);
- for (Entity child : children.entities) updateEntityTransform(registry, child, identity, true);
+ setFlatCollapsed(registry, entity, false);
+ for (Entity child : children.entities) updateEntityTransform(registry, child, identity, true, false);
});
}
@@ -240,6 +257,8 @@ private:
transform.worldRotation = transform.rotation;
transform.worldScale = transform.scale;
transform.decomposed_ = true;
+ const bool collapsed = transform.scale.x == 0 || transform.scale.y == 0;
+ setFlatCollapsed(registry, entity, collapsed);
if (localDirty) {
dirty_to_clear_.push_back(entity);
@@ -257,14 +276,14 @@ private:
transform.cachedMatrix_ = math::compose(transform.worldPosition, transform.worldRotation, transform.worldScale);
visitOnce(entity);
for (Entity child : children->entities) {
- updateEntityTransform(registry, child, transform.cachedMatrix_, true);
+ updateEntityTransform(registry, child, transform.cachedMatrix_, true, collapsed);
}
}
void updateEntityTransform(Registry& registry, Entity entity,
- const glm::mat4& parentWorldMatrix, bool parentDirty) {
+ const glm::mat4& parentWorldMatrix, bool parentDirty, bool parentFlatCollapsed) {
pending_.clear();
- TraversalTask task{entity, &parentWorldMatrix, parentDirty};
+ TraversalTask task{entity, &parentWorldMatrix, parentDirty, parentFlatCollapsed};
// Explicit DFS preserves child order without a depth limit or call-stack
// growth. Per-composition stamps bound corrupt duplicate/cyclic links.
for (;;) {
@@ -274,7 +293,10 @@ private:
const bool dirty = task.parentDirty || localDirty;
const bool keepStatic = transform && have_static_ && registry.has<TransformStatic>(task.entity) && !dirty;
const glm::mat4* childMatrix = task.parentMatrix;
+ bool flatCollapsed = task.parentFlatCollapsed;
if (transform && !keepStatic) {
+ 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);
if (changedOut_) {
++visited_;
@@ -282,7 +304,10 @@ private:
}
transform->cachedMatrix_ = matrix;
transform->decomposed_ = false;
+ } else if (keepStatic) {
+ flatCollapsed = registry.has<FlatGeometryCollapsed>(task.entity);
}
+ setFlatCollapsed(registry, task.entity, flatCollapsed);
if (localDirty) dirty_to_clear_.push_back(task.entity);
if (transform) childMatrix = &transform->cachedMatrix_;
if (auto* children = registry.tryGet<Children>(task.entity)) {
@@ -292,10 +317,10 @@ private:
for (usize i = list.size(); i > 1; --i) {
// Transform storage is stable throughout composition; borrow
// its cache rather than copying a matrix into every task.
- pending_.push_back({list[i - 1], childMatrix, keepStatic ? false : dirty});
+ pending_.push_back({list[i - 1], childMatrix, keepStatic ? false : dirty, flatCollapsed});
}
if (!list.empty()) {
- task = {list[0], childMatrix, keepStatic ? false : dirty};
+ task = {list[0], childMatrix, keepStatic ? false : dirty, flatCollapsed};
continue;
}
}
diff --git a/src/esengine/renderer/frame/RenderFrameMask.cpp b/src/esengine/renderer/frame/RenderFrameMask.cpp
index 9118ba81c..3b6785714 100644
--- a/src/esengine/renderer/frame/RenderFrameMask.cpp
+++ b/src/esengine/renderer/frame/RenderFrameMask.cpp
@@ -6,6 +6,7 @@
#include "../../ecs/components/UINode.hpp"
#include "../../ecs/components/UIMask.hpp"
#include "../../ecs/components/Hierarchy.hpp"
+#include "../../ecs/FlatGeometry.hpp"
#include <glm/glm.hpp>
@@ -53,7 +54,8 @@ ScreenRect computeMaskScreenRect(
// other pass has read this frame would be clipped to where it used to be.
transform.ensureDecomposed();
- if (transform.worldScale.x == 0.0f || transform.worldScale.y == 0.0f) return {0, 0, 0, 0};
+ if (transform.worldScale.x == 0 || transform.worldScale.y == 0
+ || !ecs::hasFlatGeometryArea(registry, entity, transform)) return {0, 0, 0, 0};
glm::vec3 axisX, axisY;
if (registry.has<ecs::Parent>(entity)) {
axisX = glm::vec3(transform.cachedMatrix_[0]);
@@ -160,7 +162,8 @@ bool hasEmptyMaskBox(ecs::Registry& registry, Entity entity) {
if (!node || !transform) return false;
if (node->computed_size_.x <= 0.0f || node->computed_size_.y <= 0.0f) return true;
transform->ensureDecomposed();
- return transform->worldScale.x == 0.0f || transform->worldScale.y == 0.0f;
+ return transform->worldScale.x == 0 || transform->worldScale.y == 0
+ || !ecs::hasFlatGeometryArea(registry, entity, *transform);
}
void applyStencilHierarchy(ecs::Registry& registry, RenderFrame& frame,
diff --git a/src/esengine/renderer/plugins/SpritePlugin.cpp b/src/esengine/renderer/plugins/SpritePlugin.cpp
index e99a9da92..b09e141e0 100644
--- a/src/esengine/renderer/plugins/SpritePlugin.cpp
+++ b/src/esengine/renderer/plugins/SpritePlugin.cpp
@@ -7,6 +7,7 @@
#include "../rhi/Texture.hpp"
#include "../../ecs/components/Transform.hpp"
#include "../../ecs/components/Hierarchy.hpp"
+#include "../../ecs/FlatGeometry.hpp"
#include "../../ecs/components/Sprite.hpp"
#include "../../ecs/components/SpriteMask.hpp"
#include "../../ecs/components/UINode.hpp"
@@ -37,14 +38,15 @@ void SpritePlugin::collect(RenderCollectContext& collect_ctx) {
const auto& rotation = transform.worldRotation;
const auto& scale = transform.worldScale;
- if (scale.x == 0.0f || scale.y == 0.0f || sprite.size.x == 0.0f || sprite.size.y == 0.0f) continue;
+ const bool parented = registry.has<ecs::Parent>(entity);
+ if (scale.x == 0 || scale.y == 0 || !ecs::hasFlatGeometryArea(registry, entity, transform)
+ || sprite.size.x == 0.0f || sprite.size.y == 0.0f) continue;
glm::vec2 finalSize = sprite.size * glm::vec2(scale);
// The quad turns about `position`, so its pivot offset turns with it and its
// extents grow. Bounding the unturned box instead loses a turned sprite while
// part of it is still on screen — at 45 degrees the box is 41% short.
const glm::vec2 turn = flatTurnZ(rotation);
- const bool parented = registry.has<ecs::Parent>(entity);
const glm::vec3 axisX = parented ? glm::vec3(transform.cachedMatrix_[0])
: glm::vec3(turn.x, turn.y, 0.0f) * scale.x;
const glm::vec3 axisY = parented ? glm::vec3(transform.cachedMatrix_[1])
diff --git a/src/esengine/renderer/plugins/TextPlugin.cpp b/src/esengine/renderer/plugins/TextPlugin.cpp
index 6f7a52a00..3a28899e7 100644
--- a/src/esengine/renderer/plugins/TextPlugin.cpp
+++ b/src/esengine/renderer/plugins/TextPlugin.cpp
@@ -7,6 +7,7 @@
#include "../rhi/Texture.hpp"
#include "../../ecs/components/Transform.hpp"
#include "../../ecs/components/Hierarchy.hpp"
+#include "../../ecs/FlatGeometry.hpp"
#include "../../ecs/components/BitmapText.hpp"
#include "../../text/BitmapFont.hpp"
@@ -151,6 +152,9 @@ void TextPlugin::collect(RenderCollectContext& collect_ctx) {
if (!bt.enabled) continue;
if (bt.text.empty() || !bt.font.isValid()) continue;
if (!batchEntityVisible(draw_list, clips, entity, bt.layer, 0)) continue;
+ auto& transform = textView.get<ecs::Transform>(entity);
+ const bool parented = registry.has<ecs::Parent>(entity);
+ if (!ecs::hasFlatGeometryArea(registry, entity, transform)) continue;
auto* font = ctx.resources.getBitmapFont(bt.font);
if (!font) continue;
@@ -175,10 +179,9 @@ void TextPlugin::collect(RenderCollectContext& collect_ctx) {
}
if (cache.indices.empty()) continue;
- auto& transform = textView.get<ecs::Transform>(entity);
glm::vec3 position = parallaxedWorldPosition(transform, bt.parallax, collect_ctx.camera);
glm::vec3 axisX, axisY;
- if (registry.has<ecs::Parent>(entity)) {
+ if (parented) {
axisX = glm::vec3(transform.cachedMatrix_[0]);
axisY = glm::vec3(transform.cachedMatrix_[1]);
} else {
diff --git a/src/esengine/renderer/plugins/UIElementPlugin.cpp b/src/esengine/renderer/plugins/UIElementPlugin.cpp
index cc307016b..6ee578a79 100644
--- a/src/esengine/renderer/plugins/UIElementPlugin.cpp
+++ b/src/esengine/renderer/plugins/UIElementPlugin.cpp
@@ -7,6 +7,7 @@
#include "../rhi/Texture.hpp"
#include "../../ecs/components/Transform.hpp"
#include "../../ecs/components/Hierarchy.hpp"
+#include "../../ecs/FlatGeometry.hpp"
#include "../../ecs/components/UIVisual.hpp"
#include "../../ecs/components/UINode.hpp"
#include "../../ecs/components/UIMask.hpp"
@@ -79,8 +80,8 @@ void UIElementPlugin::collect(RenderCollectContext& collect_ctx) {
glm::vec3 position = transform.worldPosition;
const auto& rotation = transform.worldRotation;
const auto& scale = transform.worldScale;
- if (scale.x == 0.0f || scale.y == 0.0f) continue;
const bool parented = registry.has<ecs::Parent>(entity);
+ if (scale.x == 0 || scale.y == 0 || !ecs::hasFlatGeometryArea(registry, entity, transform)) continue;
const glm::vec3 basisOrigin = position;
const auto& matrix = transform.cachedMatrix_;
const bool mapBasis = parented && (matrix[0].y != 0 || matrix[1].x != 0
diff --git a/src/esengine/ui/UIHitTestSystem.hpp b/src/esengine/ui/UIHitTestSystem.hpp
index f3c0b9dc1..0523e00fd 100644
--- a/src/esengine/ui/UIHitTestSystem.hpp
+++ b/src/esengine/ui/UIHitTestSystem.hpp
@@ -13,6 +13,7 @@
#include "../ecs/components/Hierarchy.hpp"
#include "../ecs/components/UINode.hpp"
#include "../ecs/components/UIMask.hpp"
+#include "../ecs/FlatGeometry.hpp"
#include <algorithm>
#include <cmath>
@@ -121,7 +122,7 @@ inline bool rayHitsOBB(const PickRay& ray,
inline bool pointInTransformedBox(Registry& registry, Entity entity, Transform& transform,
f32 px, f32 py, f32 width, f32 height,
f32 pivotX, f32 pivotY) {
- transform.ensureDecomposed();
+ if (!hasFlatGeometryArea(registry, entity, transform)) return false;
if (!registry.has<Parent>(entity)) {
return pointInOBB(px, py, transform.worldPosition.x, transform.worldPosition.y,
width * transform.worldScale.x, height * transform.worldScale.y,
diff --git a/tests/renderer/test_batch_builder.cpp b/tests/renderer/test_batch_builder.cpp
index 551bcf139..2424ca59b 100644
--- a/tests/renderer/test_batch_builder.cpp
+++ b/tests/renderer/test_batch_builder.cpp
@@ -27,6 +27,8 @@
#include "esengine/ecs/components/UIMask.hpp"
#include "esengine/ecs/components/Interactable.hpp"
#include "esengine/ui/UISystem.hpp"
+#include "esengine/ecs/FlatGeometry.hpp"
+#include "esengine/ecs/TransformSystem.hpp"
#include "esengine/ecs/components/Hierarchy.hpp"
#include <functional>
@@ -533,6 +535,208 @@ TEST_CASE("UI scissor: affine corners determine the projected clip rectangle") {
frame.endFrame();
}
+TEST_CASE("flat geometry: collapsed parent bases skip uploads and recover") {
+ for (bool ui : {false, true}) {
+ for (u32 mode = 0; mode < (ui ? 5u : 3u); ++mode) {
+ Harness h;
+ RenderContext context(h.device);
+ resource::ResourceManager resources;
+ resources.init(h.device);
+ const u8 pixels[16 * 16 * 4] = {};
+ const auto texture = resources.createTexture(resource::ResourceContent::Retained,
+ 16, 16, pixels, TextureFormat::RGBA8);
+ resource::TextureMetadata metadata;
+ metadata.sliceBorder = {2, 2, 2, 2};
+ resources.setTextureMetadata(texture, metadata);
+ ecs::Registry registry;
+ const auto parent = registry.create(), entity = registry.create();
+ registry.emplace<ecs::Parent>(entity).entity = parent;
+ auto& transform = registry.emplace<ecs::Transform>(entity);
+ transform.cachedMatrix_[0] = {1, 1, 0, 0};
+ transform.cachedMatrix_[1] = {.5f, .5f, 0, 0};
+ if (ui) {
+ registry.emplace<ecs::UINode>(entity).computed_size_ = {20, 30};
+ auto& visual = registry.emplace<ecs::UIVisual>(entity);
+ visual.texture = texture;
+ visual.visualType = static_cast<ecs::UIVisualType>(mode + 1);
+ visual.fillMethod = ecs::UIFillMethod::Radial360;
+ } else {
+ auto& sprite = registry.emplace<ecs::Sprite>(entity);
+ sprite.size = {20, 30};
+ sprite.tileSize = {10, 10};
+ sprite.texture = texture;
+ const ecs::SpriteDrawMode modes[] = {ecs::SpriteDrawMode::Simple,
+ ecs::SpriteDrawMode::NineSlice, ecs::SpriteDrawMode::Tiled};
+ sprite.drawMode = modes[mode];
+ }
+ Frustum frustum;
+ frustum.extractFromMatrix(glm::ortho(-500.0f, 500.0f, -500.0f, 500.0f));
+ RenderFrameContext frameContext{context, resources};
+ RenderCollectContext collect{registry, frustum, h.clips, h.pool, h.list, frameContext, {}};
+ UIElementPlugin uiPlugin;
+ SpritePlugin spritePlugin;
+ uiPlugin.init(frameContext);
+ spritePlugin.init(frameContext);
+ for (bool collapsed : {true, false, true}) {
+ transform.cachedMatrix_[1] = collapsed ? glm::vec4(.5f, .5f, 0, 0) : glm::vec4(.5f, -.5f, 0, 0);
+ transform.decomposed_ = false;
+ h.pool.beginFrame();
+ h.list.clear();
+ if (ui) uiPlugin.collect(collect);
+ else spritePlugin.collect(collect);
+ CHECK((h.pool.vertexBytesUsed(LayoutId::Batch) == 0) == collapsed);
+ CHECK((h.pool.indicesUsed(LayoutId::Batch) == 0) == collapsed);
+ }
+ resources.shutdown();
+ }
+ }
+}
+
+TEST_CASE("UI masks: collapsed parent bases clip the complete subtree") {
+ for (auto mode : {ecs::MaskMode::Scissor, ecs::MaskMode::Stencil}) {
+ MockGfxDevice device;
+ RenderContext context(device);
+ resource::ResourceManager resources;
+ ecs::Registry registry;
+ RenderFrame frame(device, context, resources);
+ frame.init(64, 64);
+ const auto parent = registry.create(), mask = registry.create(), child = registry.create();
+ registry.emplace<ecs::Parent>(mask).entity = parent;
+ registry.emplace<ecs::Children>(mask).entities.push_back(child);
+ registry.emplace<ecs::Parent>(child).entity = mask;
+ auto& transform = registry.emplace<ecs::Transform>(mask);
+ transform.cachedMatrix_[0] = {1, 1, 0, 0};
+ registry.emplace<ecs::UINode>(mask).computed_size_ = {20, 20};
+ registry.emplace<ecs::UIMask>(mask).mode = mode;
+ const f32 vertices[36] = {};
+ const u16 indices[] = {0, 1, 2, 2, 3, 0};
+ const glm::mat4 identity(1);
+ for (bool collapsed : {true, false, true}) {
+ transform.cachedMatrix_[1] = collapsed ? glm::vec4(.5f, .5f, 0, 0) : glm::vec4(.5f, -.5f, 0, 0);
+ transform.decomposed_ = false;
+ frame.beginFrame();
+ frame.begin(glm::ortho(-32.0f, 32.0f, -32.0f, 32.0f));
+ frame.processMasks(registry, 0, 0, 64, 64);
+ frame.collectAll(registry);
+ const auto uploads = device.updateBufferCalls;
+ frame.submitTextBatch(vertices, 4, indices, 6, 1, &identity[0][0], child, 0, 0, false);
+ frame.flush();
+ frame.end();
+ CHECK(frame.stats().text == (collapsed ? 0 : 1));
+ if (collapsed) CHECK(device.updateBufferCalls == uploads);
+ frame.endFrame();
+ }
+ }
+}
+
+TEST_CASE("flat geometry: tiny finite and tilted spans retain their area") {
+ ecs::Transform transform;
+ transform.cachedMatrix_[0] = {1, 1, 0, 0};
+ transform.cachedMatrix_[1] = {.5f, .5f, 0, 0};
+ CHECK_FALSE(ecs::hasFlatGeometryArea(transform, true));
+ CHECK(ecs::hasFlatGeometryArea(transform, false));
+ transform.cachedMatrix_[1].z = 1;
+ CHECK(ecs::hasFlatGeometryArea(transform, true));
+ transform.cachedMatrix_[0] = {1e-30f, 0, 0, 0};
+ transform.cachedMatrix_[1] = {0, 1e-30f, 0, 0};
+ CHECK(ecs::hasFlatGeometryArea(transform, true));
+ transform.cachedMatrix_[1].y = std::numeric_limits<f32>::infinity();
+ CHECK_FALSE(ecs::hasFlatGeometryArea(transform, true));
+}
+
+TEST_CASE("flat geometry: authored planar zero scales remain collapsed through rotation") {
+ for (f32 angle : {0.0f, .4f, .7f}) {
+ ecs::Registry registry;
+ ecs::TransformSystem system;
+ const auto parent = registry.create(), group = registry.create(), child = registry.create();
+ auto& root = registry.emplace<ecs::Transform>(parent);
+ root.scale.x = 0;
+ root.rotation = glm::angleAxis(.7f, glm::vec3(0, 0, 1));
+ auto& transform = registry.emplace<ecs::Transform>(child);
+ transform.rotation = glm::angleAxis(angle, glm::vec3(0, 0, 1));
+ ecs::setParent(registry, group, parent);
+ ecs::setParent(registry, child, group);
+ system.ensureComposed(registry);
+ CHECK_FALSE(ecs::hasFlatGeometryArea(registry, child, transform));
+ CHECK_FALSE(ecs::pointInTransformedBox(registry, child, transform, 0, 0, 20, 30, .5f, .5f));
+ registry.get<ecs::Transform>(parent).scale.x = 1;
+ ecs::invalidateTransformComposition();
+ system.ensureComposed(registry);
+ CHECK(ecs::hasFlatGeometryArea(registry, child, transform));
+ CHECK(ecs::pointInTransformedBox(registry, child, transform, 0, 0, 20, 30, .5f, .5f));
+ registry.get<ecs::Transform>(parent).scale.x = 0;
+ transform.rotation = glm::angleAxis(.5f, glm::vec3(0, 1, 0));
+ ecs::invalidateTransformComposition();
+ system.ensureComposed(registry);
+ CHECK(ecs::hasFlatGeometryArea(registry, child, transform));
+ ecs::setParent(registry, child, INVALID_ENTITY);
+ system.ensureComposed(registry);
+ CHECK(ecs::hasFlatGeometryArea(registry, child, transform));
+ }
+}
+
+TEST_CASE("flat geometry: deep collapsed groups propagate and recover in one traversal") {
+ ecs::Registry registry;
+ ecs::TransformSystem system;
+ const auto root = registry.create();
+ registry.emplace<ecs::Transform>(root).scale.x = 0;
+ auto parent = root;
+ for (u32 i = 0; i < 50000; ++i) {
+ const auto child = registry.create();
+ registry.emplace<ecs::Parent>(child).entity = parent;
+ registry.emplace<ecs::Children>(parent).entities.push_back(child);
+ parent = child;
+ }
+ auto& transform = registry.emplace<ecs::Transform>(parent);
+ transform.rotation = glm::angleAxis(.4f, glm::vec3(0, 0, 1));
+ system.ensureComposed(registry);
+ CHECK_FALSE(ecs::hasFlatGeometryArea(registry, parent, transform));
+ registry.get<ecs::Transform>(root).scale.x = 1;
+ ecs::invalidateTransformComposition();
+ system.ensureComposed(registry);
+ CHECK(ecs::hasFlatGeometryArea(registry, parent, transform));
+ CHECK(registry.entitiesWith<ecs::FlatGeometryCollapsed>().empty());
+}
+
+TEST_CASE("bitmap text: collapsed parent bases skip long glyph runs and recover") {
+ Harness h;
+ RenderContext context(h.device);
+ resource::ResourceManager resources;
+ resources.init(h.device);
+ const u8 pixels[16 * 16 * 4] = {};
+ const auto texture = resources.createTexture(resource::ResourceContent::Retained,
+ 16, 16, pixels, TextureFormat::RGBA8);
+ const auto font = resources.createBitmapFont(
+ "common lineHeight=16 base=12 scaleW=16 scaleH=16 pages=1\n"
+ "char id=65 x=0 y=0 width=8 height=16 xoffset=0 yoffset=0 xadvance=10 page=0 chnl=15\n",
+ texture, 16, 16);
+ REQUIRE(font.isValid());
+ ecs::Registry registry;
+ const auto parent = registry.create(), entity = registry.create();
+ registry.emplace<ecs::Parent>(entity).entity = parent;
+ auto& transform = registry.emplace<ecs::Transform>(entity);
+ transform.cachedMatrix_[0] = {1, 1, 0, 0};
+ auto& text = registry.emplace<ecs::BitmapText>(entity);
+ text.font = font;
+ text.text = std::string(65536, 'A');
+ Frustum frustum;
+ frustum.extractFromMatrix(glm::ortho(-1e7f, 1e7f, -1e7f, 1e7f));
+ RenderFrameContext frameContext{context, resources};
+ RenderCollectContext collect{registry, frustum, h.clips, h.pool, h.list, frameContext, {}};
+ TextPlugin plugin;
+ plugin.init(frameContext);
+ for (bool collapsed : {true, false, true}) {
+ transform.cachedMatrix_[1] = collapsed ? glm::vec4(.5f, .5f, 0, 0) : glm::vec4(.5f, -.5f, 0, 0);
+ transform.decomposed_ = false;
+ h.pool.beginFrame();
+ h.list.clear();
+ plugin.collect(collect);
+ CHECK(h.pool.vertexBytesUsed(LayoutId::Batch) == (collapsed ? 0 : 65536 * 4 * sizeof(BatchVertex)));
+ CHECK(h.pool.indicesUsed(LayoutId::Batch) == (collapsed ? 0 : 65536 * 6));
+ }
+ resources.shutdown();
+}
+
TEST_CASE("sprites: tile budget applies before integer conversion") {
struct Case { glm::vec2 tile, spacing; u32 quads; };
const Case cases[] = {
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index ba886efae..83fdecba5 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -32,6 +32,8 @@ export const NOTED = {
{ note: 'Web exports can select the Poki channel.' },
'feat(editor): expose Poki Web distribution channel':
{ note: 'Web exports can select the Poki channel.' },
+ 'fix(renderer): skip collapsed flat hierarchies without epsilon culling':
+ { note: 'Collapsed 2D hierarchies skip geometry and recover reliably.' },
'fix(ads): reject overlapping advertising requests':
{ note: 'Advertising requests preserve a single active break.' },