From 2bd0cf39f1ea7641dbd336d800fbe92f9c613505 Mon Sep 17 00:00:00 2001 From: Patedam Date: Sun, 13 Sep 2026 11:59:10 -0400 Subject: [PATCH] serialization fixing world unit test and missing serialize for inert. --- Game/Entity/EntityManager.cpp | 2 ++ Game/Entity/entity_types.cpp | 7 ++++++- Game/UnitTest/WorldUnitTest.cpp | 27 +++++++++++++++++++++++---- Game/game.cpp | 19 ++++--------------- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/Game/Entity/EntityManager.cpp b/Game/Entity/EntityManager.cpp index 92e4314..30811f1 100644 --- a/Game/Entity/EntityManager.cpp +++ b/Game/Entity/EntityManager.cpp @@ -140,4 +140,6 @@ Entity* deserialize_entity(Archive& ar, EntityManager& manager) } entity_base->is_dirty = false; + + return entity_base; } diff --git a/Game/Entity/entity_types.cpp b/Game/Entity/entity_types.cpp index fa11c72..bbf99e8 100644 --- a/Game/Entity/entity_types.cpp +++ b/Game/Entity/entity_types.cpp @@ -1,4 +1,9 @@ #include +#include + DEFINE_ENTITY_VERSIONED(Inert, 1) -internal void serialize(Archive& /*ar*/, uint16 /*version*/, Inert& /*inert*/) {} +internal void serialize(Archive& ar, uint16 /*version*/, Inert& inert) +{ + SERIALIZE(ar, MeshInstance, inert.MeshInstance); +} diff --git a/Game/UnitTest/WorldUnitTest.cpp b/Game/UnitTest/WorldUnitTest.cpp index 446c1e1..21d1cdc 100644 --- a/Game/UnitTest/WorldUnitTest.cpp +++ b/Game/UnitTest/WorldUnitTest.cpp @@ -11,6 +11,7 @@ #include #include #include +#include namespace UnitTest { @@ -20,7 +21,9 @@ namespace UnitTest TempArena tempArena = scratch_begin(nullptr, 0); - World testWorld{}; + GameState* gameState = GetGameState(); + World testWorld{}; + gameState->World = &testWorld; InitWorld(&testWorld, tempArena.Arena); InitEntityManager(&testWorld); @@ -53,7 +56,10 @@ namespace UnitTest ShutdownEntityManager(); ShutdownWorld(&testWorld); + gameState->World = nullptr; + scratch_end(tempArena); + Log(LogLevel::Message, LogCategory::Game, "[UnitTest] PASSED: TestEntityAllocationAndWiring"); } @@ -61,12 +67,16 @@ namespace UnitTest { Log(LogLevel::Message, LogCategory::Game, "[UnitTest] Running TestInPlaceDeserialization..."); TempArena tempArena = scratch_begin(nullptr, 0); - World testWorld{}; + + GameState* gameState = GetGameState(); + World testWorld{}; + gameState->World = &testWorld; InitWorld(&testWorld, tempArena.Arena); + InitEntityManager(&testWorld); EntityManager& manager = *testWorld.EntityManager; // 1. In-memory .jasset text fixture (no streams or files needed) - String asset_content = ConstString("; class\n" + String asset_content = ConstString("; Class\n" "Inert\n" "; version\n" "1\n" @@ -100,6 +110,9 @@ namespace UnitTest Assert(loaded_inert->MeshInstance == 42); ShutdownEntityManager(); ShutdownWorld(&testWorld); + + gameState->World = nullptr; + scratch_end(tempArena); Log(LogLevel::Message, LogCategory::Game, "[UnitTest] PASSED: TestInPlaceDeserialization"); } @@ -110,14 +123,18 @@ namespace UnitTest TempArena tempArena = scratch_begin(nullptr, 0); - World testWorld{}; + GameState* gameState = GetGameState(); + World testWorld{}; + gameState->World = &testWorld; InitWorld(&testWorld, tempArena.Arena); + InitEntityManager(&testWorld); EntityManager& manager = *testWorld.EntityManager; Entity* entity = allocate_entity(manager, Inert::kind); Assert(entity->is_dirty == true); + // TODO : proper save and mutation // Simulate save entity->is_dirty = false; Assert(entity->is_dirty == false); @@ -130,6 +147,8 @@ namespace UnitTest ShutdownEntityManager(); ShutdownWorld(&testWorld); + gameState->World = nullptr; + scratch_end(tempArena); Log(LogLevel::Message, LogCategory::Game, "[UnitTest] PASSED: TestDirtyTrackingLifecycle"); } diff --git a/Game/game.cpp b/Game/game.cpp index 31fb875..f265a56 100644 --- a/Game/game.cpp +++ b/Game/game.cpp @@ -20,17 +20,6 @@ #include #endif -// namespace -// { -// void serialize_test(Archive* ar, void* payload) -// { -// SerializedEntityTest* test = reinterpret_cast(payload); -// serialize_elem(ar, test->A); -// } -// } // namespace -// -// DEFINE_ENTITY_SERIALIZED(SerializedEntityTest, serialize_test) - namespace { GameState* gGameState = nullptr; @@ -71,16 +60,16 @@ extern "C" JULIET_API void __cdecl GameUpdate(GameData* params, [[maybe_unused]] // Reserve cameras. Lets go with 4 for now ReserveCamera(4); +#if JULIET_DEBUG + UnitTest::WorldUnitTest(); +#endif + // Bootstrap world auto* worldArena = ArenaAllocate({ .ReserveSize = Megabytes(1), .Name = "World Arena" }); World* world = ArenaPushStruct(worldArena JULIET_DEBUG_PARAM("World")); gameState->World = world; InitWorld(gameState->World, worldArena); -#if JULIET_DEBUG - UnitTest::WorldUnitTest(); -#endif - // Entity Use case InitEntityManager(gameState->World); auto& manager = GetEntityManager();