51 lines
1.2 KiB
C++
51 lines
1.2 KiB
C++
#include <Entity/Entity.h>
|
|
|
|
#include <Core/Common/serialization.h>
|
|
|
|
void serialize(Archive& ar, NonNullPtr<Entity> entity)
|
|
{
|
|
// Entity fields
|
|
serialize(ar, Entity::kind, entity.Get());
|
|
|
|
// Derived fields
|
|
if (entity->derived_kind != nullptr && entity->derived != nullptr)
|
|
{
|
|
serialize(ar, entity->derived_kind, entity->derived);
|
|
}
|
|
}
|
|
|
|
DEFINE_CLASS_VERSIONED(Entity, 1, nullptr)
|
|
internal void serialize(Archive& ar, uint16 /*version*/, Entity& entity)
|
|
{
|
|
SERIALIZE(ar, id, entity.ID);
|
|
SERIALIZE(ar, position, entity.position);
|
|
}
|
|
|
|
const Class* resolve_entity_class(uint8 kind, uint32 crc)
|
|
{
|
|
Assert(kind <= ENTITY(Count));
|
|
|
|
NonNullPtr<const Class> class_ptr = kEntity_type_class_ptr[kind];
|
|
Assert(class_ptr->CRC == crc);
|
|
|
|
return class_ptr.Get();
|
|
}
|
|
|
|
const Class* find_class_by_name(String name)
|
|
{
|
|
Assert(IsValid(name));
|
|
|
|
const Class* result = nullptr;
|
|
const uint32 name_crc = crc32(name.Str, name.Size);
|
|
for (uint8 kind = 0; kind < ENTITY(Count); ++kind)
|
|
{
|
|
const Class* class_ptr = resolve_entity_class(kind, name_crc);
|
|
if (class_ptr != nullptr)
|
|
{
|
|
result = class_ptr;
|
|
break;
|
|
}
|
|
}
|
|
return result;
|
|
}
|