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
+24 -28
View File
@@ -2,24 +2,19 @@
#include <Core/Common/CoreUtils.h>
#include <Core/Common/EnumUtils.h>
#include <Core/Math/Vector.h>
#include <Core/Memory/Allocator.h>
#include <Core/Memory/MemoryArena.h>
#include <Engine/Class.h>
#define DECLARE_ENTITY() \
Entity* Base; \
static Class* Kind;
Entity* base; \
static Class* kind;
// Will register the class globally at launch
#define DEFINE_ENTITY(entity) \
Class entityKind##entity = \
MakeClass(ConstString(#entity), (uint8)Entity_Type::entity, sizeof(entity), alignof(entity), nullptr); \
Class* entity::Kind = &entityKind##entity;
#define DEFINE_ENTITY_SERIALIZED(entity, serialize_fct) \
Class entityKind##entity = \
MakeClass(ConstString(#entity), (uint8)Entity_Type::entity, sizeof(entity), alignof(entity), serialize_fct); \
Class* entity::Kind = &entityKind##entity;
#define DEFINE_ENTITY_VERSIONED(entity, version, serialize_fct) \
constexpr Class entityKind##entity = MakeClass(ConstString(#entity), (uint8)Entity_Type::entity, (version), \
&classKindEntity, sizeof(entity), alignof(entity), (serialize_fct)); \
Class* entity::kind = const_cast<Class*>(&entityKind##entity);
struct EntityManager;
using DerivedType = void*;
@@ -27,12 +22,12 @@ using EntityID = uint64_t;
struct Entity final
{
EntityID ID = 0;
Class* Kind = nullptr;
DerivedType Derived = nullptr;
float X = 0.0f;
float Y = 0.0f;
float Z = 0.0f;
static Class* kind;
EntityID ID = 0;
Class* derived_kind = nullptr;
DerivedType derived = nullptr;
Vector4 position = {};
};
struct Inert
@@ -60,7 +55,7 @@ inline const char* kEntity_type_names[] = {
};
#undef AS_STR
#define AS_CLASS(name) name::Kind
#define AS_CLASS(name) name::kind
inline Class* kEntity_type_class_ptr[]
{
ENTITY_TYPE_LIST(AS_CLASS)
@@ -80,8 +75,8 @@ struct entity_template
//
template <typename EntityType>
concept EntityConcept = requires(EntityType entity) {
{ EntityType::Kind } -> std::convertible_to<const Class*>;
requires std::same_as<decltype(entity.Base), Entity*>;
{ EntityType::kind } -> std::convertible_to<const Class*>;
requires std::same_as<decltype(entity.base), Entity*>;
};
template <typename EntityType>
@@ -89,7 +84,7 @@ template <typename EntityType>
[[nodiscard]] bool IsA(const Entity* entity)
{
Assert(entity != nullptr);
return entity->Kind == EntityType::Kind;
return entity->derived_kind == EntityType::kind;
}
template <typename EntityType>
@@ -98,10 +93,11 @@ template <typename EntityType>
{
EntityType result;
Entity base;
base.X = x;
base.Y = y;
base.Z = z;
base.Kind = EntityType::Kind;
base.position.x = x;
base.position.y = y;
base.position.z = z;
base.position.w = 1.0f;
base.derived_kind = EntityType::kind;
return (EntityType*)RegisterEntity(manager, &base, &result);
}
@@ -112,7 +108,7 @@ template <typename EntityType>
{
Assert(entity != nullptr);
Assert(IsA<EntityType>(entity));
return static_cast<EntityType*>(entity->Derived);
return static_cast<EntityType*>(entity->derived);
}
void serialize(archive& ar, NonNullPtr<Entity> entity);
void serialize(Archive& ar, NonNullPtr<Entity> entity);