conversion to c by gemini 4 argon
This commit is contained in:
1 parent
b70e2d21d2
commit
f9356f9ba7
369 files changed
+18074
-107634
No files matched your search
+48
-51
@@ -6,98 +6,95 @@
|
||||
#include <Entity/entity_common.h>
|
||||
#include <Entity/EntityManager.h>
|
||||
|
||||
struct Entity final
|
||||
typedef struct Entity Entity;
|
||||
struct Entity
|
||||
{
|
||||
DECLARE_CLASS()
|
||||
|
||||
EntityID ID = 0;
|
||||
const Class* derived_kind = nullptr;
|
||||
DerivedType derived = nullptr;
|
||||
Vector4 position = {};
|
||||
bool is_dirty = false;
|
||||
EntityID ID;
|
||||
const Class* derived_kind;
|
||||
DerivedType derived;
|
||||
Vector4 position;
|
||||
bool8 is_dirty;
|
||||
};
|
||||
DECLARE_CLASS(Entity)
|
||||
|
||||
// Can reinterpret cast to this to have the offset of Base and Kind for any entity
|
||||
// Can cast to this to have the offset of base for any entity
|
||||
typedef struct EntityTemplate EntityTemplate;
|
||||
struct EntityTemplate
|
||||
{
|
||||
DECLARE_ENTITY();
|
||||
DECLARE_ENTITY()
|
||||
};
|
||||
|
||||
//
|
||||
template <typename EntityType>
|
||||
concept EntityConcept = requires(EntityType entity) {
|
||||
{ EntityType::kind } -> std::convertible_to<const Class*>;
|
||||
requires std::same_as<decltype(entity.base), Entity*>;
|
||||
};
|
||||
|
||||
inline constexpr EntityID make_entity_id(uint8 user_id, uint64 local_counter)
|
||||
static inline EntityID make_entity_id(uint8 user_id, uint64 local_counter)
|
||||
{
|
||||
Assert(user_id != kInvalid_user_id);
|
||||
Assert((local_counter & kEntityID_user_id_mask) == kInvalid_entity_id);
|
||||
|
||||
EntityID result = kInvalid_user_id;
|
||||
result = ((EntityID)user_id << kEntityID_user_id_shift) | (local_counter & kEntityID_user_id_mask);
|
||||
EntityID result = ((EntityID)user_id << kEntityID_user_id_shift) | (local_counter & kEntityID_user_id_mask);
|
||||
return result;
|
||||
}
|
||||
|
||||
inline constexpr uint8 get_user_id(EntityID entity_id)
|
||||
static inline uint8 get_user_id(EntityID entity_id)
|
||||
{
|
||||
return (((uint8)entity_id & kEntityID_user_id_mask) << kEntityID_user_id_shift);
|
||||
return (uint8)((entity_id & kEntityID_user_id_mask) >> kEntityID_user_id_shift);
|
||||
}
|
||||
|
||||
inline constexpr uint64 get_local_counter(EntityID entity_id)
|
||||
static inline uint64 get_local_counter(EntityID entity_id)
|
||||
{
|
||||
return (uint64)entity_id & kEntityID_user_id_mask;
|
||||
return (uint64)entity_id & ~kEntityID_user_id_mask;
|
||||
}
|
||||
|
||||
inline constexpr bool is_entity_id_valid(EntityID entity_id)
|
||||
static inline bool8 is_entity_id_valid(EntityID entity_id)
|
||||
{
|
||||
bool result = entity_id != kInvalid_entity_id;
|
||||
bool8 result = (entity_id != kInvalid_entity_id);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename EntityType>
|
||||
requires EntityConcept<EntityType>
|
||||
[[nodiscard]] bool IsA(const Entity* entity)
|
||||
static inline bool8 IsEntityA(const Entity* entity, const Class* kind)
|
||||
{
|
||||
Assert(entity != nullptr);
|
||||
return entity->derived_kind == EntityType::kind;
|
||||
Assert(entity != NULL);
|
||||
return entity->derived_kind == kind;
|
||||
}
|
||||
|
||||
template <typename EntityType>
|
||||
requires EntityConcept<EntityType>
|
||||
[[nodiscard]] EntityType* MakeEntity(EntityManager& manager, float x, float y, float z)
|
||||
{
|
||||
Entity* base_ptr = allocate_entity(manager, EntityType::kind);
|
||||
Assert(base_ptr);
|
||||
#define IsEntityOfType(entity_ptr, EntityType) IsEntityA((entity_ptr), ClassKind(EntityType))
|
||||
|
||||
base_ptr->ID = EntityManager::ID++;
|
||||
static inline void* make_entity_by_class(EntityManager* manager, const Class* kind, float x, float y, float z)
|
||||
{
|
||||
Assert(manager != NULL);
|
||||
Assert(kind != NULL);
|
||||
|
||||
Entity* base_ptr = allocate_entity(manager, kind);
|
||||
Assert(base_ptr != NULL);
|
||||
|
||||
base_ptr->ID = g_entity_manager_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;
|
||||
return base_ptr->derived;
|
||||
}
|
||||
|
||||
template <typename EntityType>
|
||||
requires EntityConcept<EntityType>
|
||||
[[nodiscard]] EntityType* DownCast(Entity* entity)
|
||||
#define MakeEntity(EntityType, manager_ptr, x, y, z) \
|
||||
((EntityType*)make_entity_by_class((manager_ptr), ClassKind(EntityType), (x), (y), (z)))
|
||||
|
||||
static inline void* down_cast_entity(Entity* entity, const Class* kind)
|
||||
{
|
||||
Assert(entity != nullptr);
|
||||
Assert(IsA<EntityType>(entity));
|
||||
return static_cast<EntityType*>(entity->derived);
|
||||
Assert(entity != NULL);
|
||||
Assert(IsEntityA(entity, kind));
|
||||
return entity->derived;
|
||||
}
|
||||
|
||||
void serialize(Archive& ar, NonNullPtr<Entity> entity);
|
||||
#define DownCastEntity(EntityType, entity_ptr) ((EntityType*)down_cast_entity((entity_ptr), ClassKind(EntityType)))
|
||||
|
||||
JULIET_API uint8 get_local_user_id();
|
||||
void serialize_entity(Archive* ar, Entity* entity);
|
||||
|
||||
JULIET_API String format_entity_id(NonNullPtr<Arena> arena, EntityID id);
|
||||
JULIET_API uint8 get_local_user_id(void);
|
||||
|
||||
JULIET_API bool parse_entity_id(String str, EntityID& outId);
|
||||
JULIET_API String format_entity_id(Arena* arena, EntityID id);
|
||||
|
||||
[[nodiscard]] const Class* find_class_by_name(String name);
|
||||
JULIET_API bool8 parse_entity_id(String str, EntityID* outId);
|
||||
|
||||
[[nodiscard]] const Class* resolve_entity_class(uint8 kind, uint32 crc);
|
||||
const Class* find_class_by_name(String name);
|
||||
|
||||
const Class* resolve_entity_class(uint8 kind, uint32 crc);
|
||||
Reference in new issue
Block a user