serialization fixing world unit test and missing serialize for inert.

This commit is contained in:
2026-09-13 11:59:10 -04:00
parent 58b79fb499
commit 2bd0cf39f1
4 changed files with 35 additions and 20 deletions
+2
View File
@@ -140,4 +140,6 @@ Entity* deserialize_entity(Archive& ar, EntityManager& manager)
} }
entity_base->is_dirty = false; entity_base->is_dirty = false;
return entity_base;
} }
+6 -1
View File
@@ -1,4 +1,9 @@
#include <Entity/entity_types.h> #include <Entity/entity_types.h>
#include <Core/Common/serialization.h>
DEFINE_ENTITY_VERSIONED(Inert, 1) 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);
}
+20 -1
View File
@@ -11,6 +11,7 @@
#include <Core/Thread/ThreadContext.h> #include <Core/Thread/ThreadContext.h>
#include <Data/World.h> #include <Data/World.h>
#include <Entity/entity_types.h> #include <Entity/entity_types.h>
#include <game.h>
namespace UnitTest namespace UnitTest
{ {
@@ -20,7 +21,9 @@ namespace UnitTest
TempArena tempArena = scratch_begin(nullptr, 0); TempArena tempArena = scratch_begin(nullptr, 0);
GameState* gameState = GetGameState();
World testWorld{}; World testWorld{};
gameState->World = &testWorld;
InitWorld(&testWorld, tempArena.Arena); InitWorld(&testWorld, tempArena.Arena);
InitEntityManager(&testWorld); InitEntityManager(&testWorld);
@@ -53,7 +56,10 @@ namespace UnitTest
ShutdownEntityManager(); ShutdownEntityManager();
ShutdownWorld(&testWorld); ShutdownWorld(&testWorld);
gameState->World = nullptr;
scratch_end(tempArena); scratch_end(tempArena);
Log(LogLevel::Message, LogCategory::Game, "[UnitTest] PASSED: TestEntityAllocationAndWiring"); Log(LogLevel::Message, LogCategory::Game, "[UnitTest] PASSED: TestEntityAllocationAndWiring");
} }
@@ -61,12 +67,16 @@ namespace UnitTest
{ {
Log(LogLevel::Message, LogCategory::Game, "[UnitTest] Running TestInPlaceDeserialization..."); Log(LogLevel::Message, LogCategory::Game, "[UnitTest] Running TestInPlaceDeserialization...");
TempArena tempArena = scratch_begin(nullptr, 0); TempArena tempArena = scratch_begin(nullptr, 0);
GameState* gameState = GetGameState();
World testWorld{}; World testWorld{};
gameState->World = &testWorld;
InitWorld(&testWorld, tempArena.Arena); InitWorld(&testWorld, tempArena.Arena);
InitEntityManager(&testWorld); InitEntityManager(&testWorld);
EntityManager& manager = *testWorld.EntityManager; EntityManager& manager = *testWorld.EntityManager;
// 1. In-memory .jasset text fixture (no streams or files needed) // 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" "Inert\n"
"; version\n" "; version\n"
"1\n" "1\n"
@@ -100,6 +110,9 @@ namespace UnitTest
Assert(loaded_inert->MeshInstance == 42); Assert(loaded_inert->MeshInstance == 42);
ShutdownEntityManager(); ShutdownEntityManager();
ShutdownWorld(&testWorld); ShutdownWorld(&testWorld);
gameState->World = nullptr;
scratch_end(tempArena); scratch_end(tempArena);
Log(LogLevel::Message, LogCategory::Game, "[UnitTest] PASSED: TestInPlaceDeserialization"); Log(LogLevel::Message, LogCategory::Game, "[UnitTest] PASSED: TestInPlaceDeserialization");
} }
@@ -110,14 +123,18 @@ namespace UnitTest
TempArena tempArena = scratch_begin(nullptr, 0); TempArena tempArena = scratch_begin(nullptr, 0);
GameState* gameState = GetGameState();
World testWorld{}; World testWorld{};
gameState->World = &testWorld;
InitWorld(&testWorld, tempArena.Arena); InitWorld(&testWorld, tempArena.Arena);
InitEntityManager(&testWorld); InitEntityManager(&testWorld);
EntityManager& manager = *testWorld.EntityManager; EntityManager& manager = *testWorld.EntityManager;
Entity* entity = allocate_entity(manager, Inert::kind); Entity* entity = allocate_entity(manager, Inert::kind);
Assert(entity->is_dirty == true); Assert(entity->is_dirty == true);
// TODO : proper save and mutation
// Simulate save // Simulate save
entity->is_dirty = false; entity->is_dirty = false;
Assert(entity->is_dirty == false); Assert(entity->is_dirty == false);
@@ -130,6 +147,8 @@ namespace UnitTest
ShutdownEntityManager(); ShutdownEntityManager();
ShutdownWorld(&testWorld); ShutdownWorld(&testWorld);
gameState->World = nullptr;
scratch_end(tempArena); scratch_end(tempArena);
Log(LogLevel::Message, LogCategory::Game, "[UnitTest] PASSED: TestDirtyTrackingLifecycle"); Log(LogLevel::Message, LogCategory::Game, "[UnitTest] PASSED: TestDirtyTrackingLifecycle");
} }
+4 -15
View File
@@ -20,17 +20,6 @@
#include <UnitTest/WorldUnitTest.h> #include <UnitTest/WorldUnitTest.h>
#endif #endif
// namespace
// {
// void serialize_test(Archive* ar, void* payload)
// {
// SerializedEntityTest* test = reinterpret_cast<SerializedEntityTest*>(payload);
// serialize_elem(ar, test->A);
// }
// } // namespace
//
// DEFINE_ENTITY_SERIALIZED(SerializedEntityTest, serialize_test)
namespace namespace
{ {
GameState* gGameState = nullptr; 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 // Reserve cameras. Lets go with 4 for now
ReserveCamera(4); ReserveCamera(4);
#if JULIET_DEBUG
UnitTest::WorldUnitTest();
#endif
// Bootstrap world // Bootstrap world
auto* worldArena = ArenaAllocate({ .ReserveSize = Megabytes(1), .Name = "World Arena" }); auto* worldArena = ArenaAllocate({ .ReserveSize = Megabytes(1), .Name = "World Arena" });
World* world = ArenaPushStruct<World>(worldArena JULIET_DEBUG_PARAM("World")); World* world = ArenaPushStruct<World>(worldArena JULIET_DEBUG_PARAM("World"));
gameState->World = world; gameState->World = world;
InitWorld(gameState->World, worldArena); InitWorld(gameState->World, worldArena);
#if JULIET_DEBUG
UnitTest::WorldUnitTest();
#endif
// Entity Use case // Entity Use case
InitEntityManager(gameState->World); InitEntityManager(gameState->World);
auto& manager = GetEntityManager(); auto& manager = GetEntityManager();