Serialization : started to unify how to allocate entity whether its from MakeEntity or during deserialization.
This commit is contained in:
+13
-61
@@ -1,24 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#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; \
|
||||
DECLARE_CLASS()
|
||||
|
||||
#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*;
|
||||
using EntityID = uint64_t;
|
||||
#include <Entity/entity_common.h>
|
||||
#include <Entity/EntityManager.h>
|
||||
|
||||
struct Entity final
|
||||
{
|
||||
@@ -30,44 +16,8 @@ struct Entity final
|
||||
Vector4 position = {};
|
||||
};
|
||||
|
||||
struct Inert
|
||||
{
|
||||
DECLARE_ENTITY()
|
||||
|
||||
index_t MeshInstance = indexMax;
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
#define ENTITY_TYPE_LIST(X) X(Inert),
|
||||
|
||||
#define AS_ENUM(name) name
|
||||
enum class Entity_Type : uint8
|
||||
{
|
||||
ENTITY_TYPE_LIST(AS_ENUM)
|
||||
Count
|
||||
};
|
||||
#undef AS_ENUM
|
||||
|
||||
#define AS_STR(name) #name
|
||||
inline const char* kEntity_type_names[] = {
|
||||
ENTITY_TYPE_LIST(AS_STR)
|
||||
"Count"
|
||||
};
|
||||
#undef AS_STR
|
||||
|
||||
#define AS_CLASS(name) name::kind
|
||||
inline Class* kEntity_type_class_ptr[]
|
||||
{
|
||||
ENTITY_TYPE_LIST(AS_CLASS)
|
||||
nullptr
|
||||
};
|
||||
#undef AS_CLASS
|
||||
|
||||
#define ENTITY(kind) ToUnderlying(Entity_Type::kind)
|
||||
// clang-format on
|
||||
|
||||
// Can reinterpret cast to this to have the offset of Base and Kind for any entity
|
||||
struct entity_template
|
||||
struct EntityTemplate
|
||||
{
|
||||
DECLARE_ENTITY();
|
||||
};
|
||||
@@ -91,15 +41,17 @@ template <typename EntityType>
|
||||
requires EntityConcept<EntityType>
|
||||
[[nodiscard]] EntityType* MakeEntity(EntityManager& manager, float x, float y, float z)
|
||||
{
|
||||
EntityType result;
|
||||
Entity base;
|
||||
base.position.x = x;
|
||||
base.position.y = y;
|
||||
base.position.z = z;
|
||||
base.position.w = 1.0f;
|
||||
base.derived_kind = EntityType::kind;
|
||||
Entity* base_ptr = allocate_entity(manager, EntityType::kind);
|
||||
Assert(base_ptr);
|
||||
|
||||
return (EntityType*)RegisterEntity(manager, &base, &result);
|
||||
base_ptr->ID = EntityManager::ID++;
|
||||
|
||||
base_ptr->position.x = x;
|
||||
base_ptr->position.y = y;
|
||||
base_ptr->position.z = z;
|
||||
base_ptr->position.w = 1.0f;
|
||||
|
||||
return (EntityType*)base_ptr->derived;
|
||||
}
|
||||
|
||||
template <typename EntityType>
|
||||
|
||||
Reference in New Issue
Block a user