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;
return entity_base;
}
+6 -1
View File
@@ -1,4 +1,9 @@
#include <Entity/entity_types.h>
#include <Core/Common/serialization.h>
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);
}
+23 -4
View File
@@ -11,6 +11,7 @@
#include <Core/Thread/ThreadContext.h>
#include <Data/World.h>
#include <Entity/entity_types.h>
#include <game.h>
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");
}
+4 -15
View File
@@ -20,17 +20,6 @@
#include <UnitTest/WorldUnitTest.h>
#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
{
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<World>(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();