Fixed terrain cleanup

This commit is contained in:
2026-06-27 02:44:55 +03:00
parent 31864e3da5
commit e047f7bea1
2 changed files with 13 additions and 0 deletions
@@ -1219,6 +1219,13 @@ draw off by default with toggle; removing and re-adding terrain is leak-free.
### Milestone 3 — Serialization + heightmap editing + splat painting
- Scene serialization for `TerrainComponent` (save/load JSON round-trip).
**Terrain cleanup on entity/component removal** (added post-M2):
`TerrainSystem::update()` now tracks whether any matching terrain entity exists.
If `m_active` is true but the query returns no entity (because the terrain
entity was deleted or its TerrainComponent was removed), `deactivate()` is
called automatically. Without this, removing the component or deleting the
entity would leave the terrain and colliders orphaned in the scene.
- Binary heightmap file save/load alongside scene JSON.
- Brush tools (raise/lower/smooth/flatten) with curve-based brush profile.
- Splat paint brush (select layer, set opacity, paint blend values via
@@ -411,9 +411,11 @@ void TerrainSystem::deactivate()
void TerrainSystem::update(float /*deltaTime*/)
{
bool found = false;
m_terrainQuery.each([&](flecs::entity e, TerrainComponent &tc,
TransformComponent &xform) {
(void)e;
found = true;
if (!tc.enabled && m_active) {
deactivate();
return;
@@ -422,6 +424,10 @@ void TerrainSystem::update(float /*deltaTime*/)
activate(tc, xform);
});
/* If the terrain entity or its component was removed, tear down. */
if (m_active && !found)
deactivate();
if (m_active && mTerrainGroup)
mTerrainGroup->update(false);