ongoing refactor of serialization and various cleanup

This commit is contained in:
2026-09-07 16:58:57 -04:00
parent 1a045c3578
commit a462575af4
43 changed files with 952 additions and 483 deletions
+35 -31
View File
@@ -24,14 +24,14 @@ void ShutdownWorld(NonNullPtr<World> world)
world->WorldArena = nullptr;
}
void AddToWorld(NonNullPtr<World> world, NonNullPtr<Entity> entity)
void AddToWorld(NonNullPtr<World> /*world*/, NonNullPtr<Entity> /*entity*/)
{
// RegisterEntity(*world->EntityManager, entity.Get());
}
void RemoveWorldEntity(World& world, size_t index) {}
void RemoveWorldEntity(World& /*world*/, size_t /*index*/) {}
void Serialize(archive& ar, World& world, String filename)
void Serialize(Archive& ar, World& /*world*/, String filename)
{
Assert(IsValid(filename));
@@ -41,28 +41,33 @@ void Serialize(archive& ar, World& world, String filename)
{
// Load
ByteBuffer fileBuffer = LoadFile(ar.arena, filename);
if (fileBuffer.Size >= sizeof(WorldFileHeader))
{
ar.base_ptr = fileBuffer.Data;
WorldFileHeader header;
serialize_elem(ar, header);
Assert(header.Magic == kWorldMagic);
Assert(header.Version == kWorldVersion);
// TEST SERIALIZATION
ParsedArchive archive = tokenize_archive(ar.arena, fileBuffer);
// ArchivePropertyNode* property = find_property(&archive, "Position"_crc32);
audit_unconsumed_properties(&archive, ConstString("World"));
for (typed_entity_array& type : entityManager.by_type)
{
serialize_elem(ar, type.count);
if (type.count > 0)
{
// Unserialize the base entity to get informations
Entity entity;
serialize(ar, &entity);
}
}
}
// if (fileBuffer.Size >= sizeof(WorldFileHeader))
// {
// ar.base_ptr = fileBuffer.Data;
//
// WorldFileHeader header;
// serialize_elem(ar, header);
// Assert(header.Magic == kWorldMagic);
//
// for (typed_entity_array& type : entityManager.by_type)
// {
// serialize_elem(ar, type.count);
//
// if (type.count > 0)
// {
//
// // Unserialize the base entity to get informations
// Entity entity;
// // serialize(ar, &entity);
// }
// }
// }
}
else
{
@@ -72,9 +77,8 @@ void Serialize(archive& ar, World& world, String filename)
index_t beginPos = ArenaPos(ar.arena);
// Headers
auto* header = ArenaPushStruct<WorldFileHeader>(ar.arena);
header->Magic = kWorldMagic;
header->Version = kWorldVersion;
auto* header = ArenaPushStruct<WorldFileHeader>(ar.arena);
header->Magic = kWorldMagic;
ar.base_ptr = header;
@@ -84,12 +88,12 @@ void Serialize(archive& ar, World& world, String filename)
serialize_elem(ar, type.count);
auto* element = type.array;
uint8* rawElement = reinterpret_cast<uint8*>(element);
size_t stride = element->Base->Kind->size_of;
size_t stride = element->base->derived_kind->size_of;
for (index_t idx = 0; idx < type.count; ++idx)
{
// Todo : utils
// Get base entity from type
Entity* entity = reinterpret_cast<entity_template*>(rawElement + (idx * stride))->Base;
Entity* entity = reinterpret_cast<entity_template*>(rawElement + (idx * stride))->base;
serialize(ar, entity);
}
}
@@ -164,7 +168,7 @@ void Serialize(archive& ar, World& world, String filename)
// return true;
}
[[nodiscard]] bool LoadWorld(World& world, String filename)
[[nodiscard]] bool LoadWorld(World& /*world*/, String filename)
{
Assert(IsValid(filename));
// Assert(world.WorldArena != nullptr);
@@ -236,13 +240,13 @@ void RenderWorldEditorUI(World& world)
if (ImGui::Button("Save World"))
{
archive data{ .arena = temp.Arena, .loading = false };
Archive data = { .arena = temp.Arena, .loading = false };
Serialize(data, world, path);
}
ImGui::SameLine();
if (ImGui::Button("Load World"))
{
archive data{ .arena = temp.Arena, .loading = true };
Archive data{ .arena = temp.Arena, .loading = true };
Serialize(data, world, path);
}