This repository has been archived on 2024-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
MainTree/core/inc-c/entity.h

113 lines
3.2 KiB
C
Raw Normal View History

#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;
typedef struct MtEntity MtEntity;
typedef struct MtTag MtTag;
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;
u32_t entity_id_counter;
};
struct MtEntity
{
void *parent_state;
MtEntity *pool_next_free;
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);
MtEntity * mt_create_entity(void *state_voidptr, u32_t identifier);
MtEntity * mt_get_entity(void *state_voidptr, u32_t identifier);
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);
void mt_untag(MtEntity *entity, char *name);
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);
void mt_delete_entity_data(MtEntity *entity);
MtEntityPool mt_create_entity_pool(usz_t capacity);
void mt_delete_entity_pool(MtEntityPool *pool);
MtEntity * mt_allocate_entity_pool_slot(MtEntityPool *pool);
void mt_give_back_entity_pool_slot(MtEntityPool *pool, MtEntity *entity);
#endif // MT_ENTITY_POOL_H