2024-01-29 18:48:56 +00:00
|
|
|
|
|
|
|
#ifndef MT_ENTITY_POOL_H
|
|
|
|
#define MT_ENTITY_POOL_H
|
|
|
|
|
|
|
|
#include <librr/types.h>
|
|
|
|
#include <librr/linear_algebra.h>
|
|
|
|
|
|
|
|
typedef struct MtEntityLookupTree MtEntityLookupTree;
|
|
|
|
typedef struct MtEntityListL1 MtEntityListL1;
|
|
|
|
typedef struct MtEntityListL2 MtEntityListL2;
|
|
|
|
typedef struct MtEntityListL3 MtEntityListL3;
|
|
|
|
typedef struct MtEntityPool MtEntityPool;
|
|
|
|
typedef struct MtEntityRegistry MtEntityRegistry;
|
2024-01-30 21:47:43 +00:00
|
|
|
typedef struct MtEntity MtEntity;
|
|
|
|
typedef struct MtTag MtTag;
|
2024-01-29 18:48:56 +00:00
|
|
|
|
|
|
|
struct MtEntityPool
|
|
|
|
{
|
|
|
|
usz_t capacity;
|
|
|
|
struct MtEntity *entities;
|
|
|
|
struct MtEntity *first_free;
|
|
|
|
MtEntityPool *continuation;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MtEntityLookupTree
|
|
|
|
{
|
|
|
|
MtEntityListL1 *sublists[256];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MtEntityListL1
|
|
|
|
{
|
|
|
|
MtEntityListL2 *sublists[256];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MtEntityListL2
|
|
|
|
{
|
|
|
|
MtEntityListL3 *sublists[256];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MtEntityListL3
|
|
|
|
{
|
|
|
|
struct MtEntity *entities[256];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MtEntityRegistry
|
|
|
|
{
|
|
|
|
MtEntityPool pool;
|
|
|
|
MtEntityLookupTree lookup;
|
2024-01-30 21:31:31 +00:00
|
|
|
u32_t entity_id_counter;
|
2024-01-29 18:48:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct MtEntity
|
|
|
|
{
|
|
|
|
void *parent_state;
|
2024-01-30 21:47:43 +00:00
|
|
|
MtEntity *pool_next_free;
|
2024-01-29 18:48:56 +00:00
|
|
|
|
|
|
|
u32_t identifier;
|
|
|
|
u16_t tags_capacity;
|
|
|
|
u16_t num_tags;
|
|
|
|
struct MtTag *tags;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MtTag
|
|
|
|
{
|
|
|
|
u32_t identifier;
|
|
|
|
union MtTagData
|
|
|
|
{
|
|
|
|
i64_t integer;
|
|
|
|
f64_t real;
|
|
|
|
char *string;
|
|
|
|
void *pointer;
|
|
|
|
rr_vec2f_s vec2f;
|
|
|
|
rr_vec3f_s vec3f;
|
|
|
|
rr_vec4f_s vec4f;
|
|
|
|
} data;
|
|
|
|
};
|
|
|
|
|
|
|
|
MtEntityRegistry mt_create_entity_registry();
|
|
|
|
void mt_delete_entity_registry(MtEntityRegistry *entity_list);
|
|
|
|
|
2024-01-30 21:47:43 +00:00
|
|
|
MtEntity * mt_create_entity(void *state_voidptr, u32_t identifier);
|
|
|
|
MtEntity * mt_get_entity(void *state_voidptr, u32_t identifier);
|
2024-01-29 18:48:56 +00:00
|
|
|
|
2024-01-30 21:47:43 +00:00
|
|
|
void mt_tag_i64(MtEntity *entity, char *name, i64_t integer);
|
|
|
|
void mt_tag_f64(MtEntity *entity, char *name, f64_t real);
|
|
|
|
void mt_tag_str(MtEntity *entity, char *name, char *string);
|
|
|
|
void mt_tag_ptr(MtEntity *entity, char *name, void *pointer);
|
|
|
|
void mt_tag_vec2(MtEntity *entity, char *name, rr_vec2f_s vector);
|
|
|
|
void mt_tag_vec3(MtEntity *entity, char *name, rr_vec3f_s vector);
|
|
|
|
void mt_tag_vec4(MtEntity *entity, char *name, rr_vec4f_s vector);
|
2024-01-29 18:48:56 +00:00
|
|
|
|
2024-01-30 21:47:43 +00:00
|
|
|
void mt_untag(MtEntity *entity, char *name);
|
2024-01-29 18:48:56 +00:00
|
|
|
|
2024-01-30 21:47:43 +00:00
|
|
|
i64_t mt_get_i64_tag(MtEntity *entity, char *name);
|
|
|
|
f64_t mt_get_f64_tag(MtEntity *entity, char *name);
|
|
|
|
char * mt_get_str_tag(MtEntity *entity, char *name);
|
|
|
|
void * mt_get_ptr_tag(MtEntity *entity, char *name);
|
|
|
|
rr_vec2f_s mt_get_vec2_tag(MtEntity *entity, char *name);
|
|
|
|
rr_vec3f_s mt_get_vec3_tag(MtEntity *entity, char *name);
|
|
|
|
rr_vec4f_s mt_get_vec4_tag(MtEntity *entity, char *name);
|
2024-01-29 18:48:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2024-01-30 21:47:43 +00:00
|
|
|
void mt_delete_entity_data(MtEntity *entity);
|
2024-01-30 21:31:31 +00:00
|
|
|
|
2024-01-29 18:48:56 +00:00
|
|
|
MtEntityPool mt_create_entity_pool(usz_t capacity);
|
|
|
|
void mt_delete_entity_pool(MtEntityPool *pool);
|
|
|
|
|
2024-01-30 21:47:43 +00:00
|
|
|
MtEntity * mt_allocate_entity_pool_slot(MtEntityPool *pool);
|
|
|
|
void mt_give_back_entity_pool_slot(MtEntityPool *pool, MtEntity *entity);
|
2024-01-29 18:48:56 +00:00
|
|
|
|
|
|
|
#endif // MT_ENTITY_POOL_H
|