Made pointers to structs visible more clearly, not hidden in the typedefs
This commit is contained in:
parent
b4846569bb
commit
2fa120c024
|
@ -11,8 +11,8 @@ typedef struct MtEntityListL2 MtEntityListL2;
|
||||||
typedef struct MtEntityListL3 MtEntityListL3;
|
typedef struct MtEntityListL3 MtEntityListL3;
|
||||||
typedef struct MtEntityPool MtEntityPool;
|
typedef struct MtEntityPool MtEntityPool;
|
||||||
typedef struct MtEntityRegistry MtEntityRegistry;
|
typedef struct MtEntityRegistry MtEntityRegistry;
|
||||||
typedef struct MtEntity * MtEntity;
|
typedef struct MtEntity MtEntity;
|
||||||
typedef struct MtTag * MtTag;
|
typedef struct MtTag MtTag;
|
||||||
|
|
||||||
struct MtEntityPool
|
struct MtEntityPool
|
||||||
{
|
{
|
||||||
|
@ -52,7 +52,7 @@ struct MtEntityRegistry
|
||||||
struct MtEntity
|
struct MtEntity
|
||||||
{
|
{
|
||||||
void *parent_state;
|
void *parent_state;
|
||||||
MtEntity pool_next_free;
|
MtEntity *pool_next_free;
|
||||||
|
|
||||||
u32_t identifier;
|
u32_t identifier;
|
||||||
u16_t tags_capacity;
|
u16_t tags_capacity;
|
||||||
|
@ -78,35 +78,35 @@ struct MtTag
|
||||||
MtEntityRegistry mt_create_entity_registry();
|
MtEntityRegistry mt_create_entity_registry();
|
||||||
void mt_delete_entity_registry(MtEntityRegistry *entity_list);
|
void mt_delete_entity_registry(MtEntityRegistry *entity_list);
|
||||||
|
|
||||||
MtEntity mt_create_entity(void *state_voidptr, u32_t identifier);
|
MtEntity * mt_create_entity(void *state_voidptr, u32_t identifier);
|
||||||
MtEntity mt_get_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_i64(MtEntity *entity, char *name, i64_t integer);
|
||||||
void mt_tag_f64(MtEntity entity, char *name, f64_t real);
|
void mt_tag_f64(MtEntity *entity, char *name, f64_t real);
|
||||||
void mt_tag_str(MtEntity entity, char *name, char *string);
|
void mt_tag_str(MtEntity *entity, char *name, char *string);
|
||||||
void mt_tag_ptr(MtEntity entity, char *name, void *pointer);
|
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_vec2(MtEntity *entity, char *name, rr_vec2f_s vector);
|
||||||
void mt_tag_vec3(MtEntity entity, char *name, rr_vec3f_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_tag_vec4(MtEntity *entity, char *name, rr_vec4f_s vector);
|
||||||
|
|
||||||
void mt_untag(MtEntity entity, char *name);
|
void mt_untag(MtEntity *entity, char *name);
|
||||||
|
|
||||||
i64_t mt_get_i64_tag(MtEntity entity, char *name);
|
i64_t mt_get_i64_tag(MtEntity *entity, char *name);
|
||||||
f64_t mt_get_f64_tag(MtEntity entity, char *name);
|
f64_t mt_get_f64_tag(MtEntity *entity, char *name);
|
||||||
char * mt_get_str_tag(MtEntity entity, char *name);
|
char * mt_get_str_tag(MtEntity *entity, char *name);
|
||||||
void * mt_get_ptr_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_vec2f_s mt_get_vec2_tag(MtEntity *entity, char *name);
|
||||||
rr_vec3f_s mt_get_vec3_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);
|
rr_vec4f_s mt_get_vec4_tag(MtEntity *entity, char *name);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void mt_delete_entity_data(MtEntity entity);
|
void mt_delete_entity_data(MtEntity *entity);
|
||||||
|
|
||||||
MtEntityPool mt_create_entity_pool(usz_t capacity);
|
MtEntityPool mt_create_entity_pool(usz_t capacity);
|
||||||
void mt_delete_entity_pool(MtEntityPool *pool);
|
void mt_delete_entity_pool(MtEntityPool *pool);
|
||||||
|
|
||||||
MtEntity mt_get_entity_pool_slot(MtEntityPool *pool);
|
MtEntity * mt_allocate_entity_pool_slot(MtEntityPool *pool);
|
||||||
void mt_give_back_entity_pool_slot(MtEntityPool *pool, MtEntity entity);
|
void mt_give_back_entity_pool_slot(MtEntityPool *pool, MtEntity *entity);
|
||||||
|
|
||||||
#endif // MT_ENTITY_POOL_H
|
#endif // MT_ENTITY_POOL_H
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#include <librr/types.h>
|
#include <librr/types.h>
|
||||||
#include <librr/alloc/generic.h>
|
#include <librr/alloc/generic.h>
|
||||||
|
|
||||||
typedef struct MtState * MtState;
|
typedef struct MtState MtState;
|
||||||
|
|
||||||
struct MtState
|
struct MtState
|
||||||
{
|
{
|
||||||
|
@ -18,11 +18,11 @@ struct MtState
|
||||||
MtEntityRegistry entity_registry;
|
MtEntityRegistry entity_registry;
|
||||||
};
|
};
|
||||||
|
|
||||||
MtState mt_initialize(char *app_name);
|
MtState * mt_initialize(char *app_name);
|
||||||
void mt_cleanup(MtState state);
|
void mt_cleanup(MtState *state);
|
||||||
void mt_start(MtState state);
|
void mt_start(MtState *state);
|
||||||
|
|
||||||
MtEntity mt_summon(MtState state);
|
MtEntity * mt_summon(MtState *state);
|
||||||
void mt_delete(MtEntity entity);
|
void mt_delete(MtEntity *entity);
|
||||||
|
|
||||||
#endif // MT_STATE_H
|
#endif // MT_STATE_H
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
#include <state.h>
|
#include <state.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
MtEntity mt_create_entity(void *state_voidptr, u32_t identifier)
|
MtEntity * mt_create_entity(void *state_voidptr, u32_t identifier)
|
||||||
{
|
{
|
||||||
MtState state = state_voidptr;
|
MtState *state = state_voidptr;
|
||||||
MtEntityListL1 *level1 = state->entity_registry.lookup.sublists[identifier >> 24];
|
MtEntityListL1 *level1 = state->entity_registry.lookup.sublists[identifier >> 24];
|
||||||
if(level1 == NULL)
|
if(level1 == NULL)
|
||||||
{
|
{
|
||||||
|
@ -26,19 +26,19 @@ MtEntity mt_create_entity(void *state_voidptr, u32_t identifier)
|
||||||
level3 = level2->sublists[(identifier >> 8) & 0xff];
|
level3 = level2->sublists[(identifier >> 8) & 0xff];
|
||||||
}
|
}
|
||||||
|
|
||||||
MtEntity entity = level3->entities[identifier & 0xff];
|
MtEntity *entity = level3->entities[identifier & 0xff];
|
||||||
if(entity == NULL)
|
if(entity == NULL)
|
||||||
{
|
{
|
||||||
entity = mt_get_entity_pool_slot(&state->entity_registry.pool);
|
entity = mt_allocate_entity_pool_slot(&state->entity_registry.pool);
|
||||||
entity->parent_state = state;
|
entity->parent_state = state;
|
||||||
level3->entities[identifier & 0xff] = entity;
|
level3->entities[identifier & 0xff] = entity;
|
||||||
}
|
}
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
MtEntity mt_get_entity(void *state_voidptr, u32_t identifier)
|
MtEntity * mt_get_entity(void *state_voidptr, u32_t identifier)
|
||||||
{
|
{
|
||||||
MtState state = state_voidptr;
|
MtState *state = state_voidptr;
|
||||||
MtEntityListL1 *level1 = state->entity_registry.lookup.sublists[identifier >> 24];
|
MtEntityListL1 *level1 = state->entity_registry.lookup.sublists[identifier >> 24];
|
||||||
if(level1 == NULL)
|
if(level1 == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -51,7 +51,7 @@ MtEntity mt_get_entity(void *state_voidptr, u32_t identifier)
|
||||||
if(level3 == NULL)
|
if(level3 == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
MtEntity entity = level3->entities[identifier & 0xff];
|
MtEntity *entity = level3->entities[identifier & 0xff];
|
||||||
if(entity == NULL)
|
if(entity == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ void mt_delete_entity_lookup_tree(MtEntityLookupTree lookup_tree)
|
||||||
usz_t entity_index = 0;
|
usz_t entity_index = 0;
|
||||||
while(entity_index < 256)
|
while(entity_index < 256)
|
||||||
{
|
{
|
||||||
MtEntity entity = level3_list->entities[entity_index];
|
MtEntity *entity = level3_list->entities[entity_index];
|
||||||
if(entity == NULL)
|
if(entity == NULL)
|
||||||
{
|
{
|
||||||
++entity_index;
|
++entity_index;
|
||||||
|
@ -85,7 +85,7 @@ void mt_delete_entity_lookup_tree(MtEntityLookupTree lookup_tree)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void mt_delete_entity_data(MtEntity entity)
|
void mt_delete_entity_data(MtEntity *entity)
|
||||||
{
|
{
|
||||||
if(entity->tags != NULL)
|
if(entity->tags != NULL)
|
||||||
free(entity->tags);
|
free(entity->tags);
|
||||||
|
@ -108,7 +108,7 @@ MtEntityPool mt_create_entity_pool(usz_t capacity)
|
||||||
{
|
{
|
||||||
MtEntityPool pool;
|
MtEntityPool pool;
|
||||||
pool.capacity = capacity;
|
pool.capacity = capacity;
|
||||||
pool.entities = calloc(sizeof(struct MtEntity), pool.capacity);
|
pool.entities = calloc(sizeof(MtEntity), pool.capacity);
|
||||||
mt_reset_entity_pool_allocation(&pool);
|
mt_reset_entity_pool_allocation(&pool);
|
||||||
pool.first_free = &pool.entities[0];
|
pool.first_free = &pool.entities[0];
|
||||||
pool.continuation = NULL;
|
pool.continuation = NULL;
|
||||||
|
@ -127,7 +127,7 @@ void mt_delete_entity_pool(MtEntityPool *pool)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MtEntity mt_get_entity_pool_slot(MtEntityPool *pool)
|
MtEntity * mt_allocate_entity_pool_slot(MtEntityPool *pool)
|
||||||
{
|
{
|
||||||
if(pool->first_free == NULL)
|
if(pool->first_free == NULL)
|
||||||
{
|
{
|
||||||
|
@ -136,14 +136,14 @@ MtEntity mt_get_entity_pool_slot(MtEntityPool *pool)
|
||||||
pool->continuation = malloc(sizeof(MtEntityPool));
|
pool->continuation = malloc(sizeof(MtEntityPool));
|
||||||
*pool->continuation = mt_create_entity_pool(pool->capacity * 2);
|
*pool->continuation = mt_create_entity_pool(pool->capacity * 2);
|
||||||
}
|
}
|
||||||
return mt_get_entity_pool_slot(pool->continuation);
|
return mt_allocate_entity_pool_slot(pool->continuation);
|
||||||
}
|
}
|
||||||
MtEntity allocated = pool->first_free;
|
MtEntity *allocated = pool->first_free;
|
||||||
pool->first_free = allocated->pool_next_free;
|
pool->first_free = allocated->pool_next_free;
|
||||||
return allocated;
|
return allocated;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mt_give_back_entity_pool_slot(MtEntityPool *pool, MtEntity entity)
|
void mt_give_back_entity_pool_slot(MtEntityPool *pool, MtEntity *entity)
|
||||||
{
|
{
|
||||||
entity->pool_next_free = pool->first_free;
|
entity->pool_next_free = pool->first_free;
|
||||||
pool->first_free = entity;
|
pool->first_free = entity;
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
#include <state.h>
|
#include <state.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
MtTag mt_get_entity_tag_slot(MtEntity entity, char *name)
|
MtTag * mt_get_entity_tag_slot(MtEntity *entity, char *name)
|
||||||
{
|
{
|
||||||
MtState state = entity->parent_state;
|
MtState *state = entity->parent_state;
|
||||||
|
|
||||||
// Find the correct slot if it already exist
|
// Find the correct slot if it already exist
|
||||||
|
|
||||||
|
@ -31,89 +31,89 @@ MtTag mt_get_entity_tag_slot(MtEntity entity, char *name)
|
||||||
return &entity->tags[entity->num_tags++];
|
return &entity->tags[entity->num_tags++];
|
||||||
}
|
}
|
||||||
|
|
||||||
void mt_tag_i64(MtEntity entity, char *name, i64_t integer)
|
void mt_tag_i64(MtEntity *entity, char *name, i64_t integer)
|
||||||
{
|
{
|
||||||
MtTag tag = mt_get_entity_tag_slot(entity, name);
|
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||||
tag->data.integer = integer;
|
tag->data.integer = integer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mt_tag_f64(MtEntity entity, char *name, f64_t real)
|
void mt_tag_f64(MtEntity *entity, char *name, f64_t real)
|
||||||
{
|
{
|
||||||
MtTag tag = mt_get_entity_tag_slot(entity, name);
|
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||||
tag->data.real = real;
|
tag->data.real = real;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mt_tag_str(MtEntity entity, char *name, char *string)
|
void mt_tag_str(MtEntity *entity, char *name, char *string)
|
||||||
{
|
{
|
||||||
MtTag tag = mt_get_entity_tag_slot(entity, name);
|
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||||
tag->data.string = string;
|
tag->data.string = string;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mt_tag_ptr(MtEntity entity, char *name, void *pointer)
|
void mt_tag_ptr(MtEntity *entity, char *name, void *pointer)
|
||||||
{
|
{
|
||||||
MtTag tag = mt_get_entity_tag_slot(entity, name);
|
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||||
tag->data.pointer = pointer;
|
tag->data.pointer = pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mt_tag_vec2(MtEntity entity, char *name, rr_vec2f_s vector)
|
void mt_tag_vec2(MtEntity *entity, char *name, rr_vec2f_s vector)
|
||||||
{
|
{
|
||||||
MtTag tag = mt_get_entity_tag_slot(entity, name);
|
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||||
tag->data.vec2f = vector;
|
tag->data.vec2f = vector;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mt_tag_vec3(MtEntity entity, char *name, rr_vec3f_s vector)
|
void mt_tag_vec3(MtEntity *entity, char *name, rr_vec3f_s vector)
|
||||||
{
|
{
|
||||||
MtTag tag = mt_get_entity_tag_slot(entity, name);
|
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||||
tag->data.vec3f = vector;
|
tag->data.vec3f = vector;
|
||||||
}
|
}
|
||||||
void mt_tag_vec4(MtEntity entity, char *name, rr_vec4f_s vector)
|
void mt_tag_vec4(MtEntity *entity, char *name, rr_vec4f_s vector)
|
||||||
{
|
{
|
||||||
MtTag tag = mt_get_entity_tag_slot(entity, name);
|
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||||
tag->data.vec4f = vector;
|
tag->data.vec4f = vector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void mt_untag(MtEntity entity, char *name);
|
void mt_untag(MtEntity *entity, char *name);
|
||||||
|
|
||||||
i64_t mt_get_i64_tag(MtEntity entity, char *name)
|
i64_t mt_get_i64_tag(MtEntity *entity, char *name)
|
||||||
{
|
{
|
||||||
MtTag tag = mt_get_entity_tag_slot(entity, name);
|
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||||
return tag->data.integer;
|
return tag->data.integer;
|
||||||
}
|
}
|
||||||
|
|
||||||
f64_t mt_get_f64_tag(MtEntity entity, char *name)
|
f64_t mt_get_f64_tag(MtEntity *entity, char *name)
|
||||||
{
|
{
|
||||||
MtTag tag = mt_get_entity_tag_slot(entity, name);
|
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||||
return tag->data.real;
|
return tag->data.real;
|
||||||
}
|
}
|
||||||
|
|
||||||
char * mt_get_str_tag(MtEntity entity, char *name)
|
char * mt_get_str_tag(MtEntity *entity, char *name)
|
||||||
{
|
{
|
||||||
MtTag tag = mt_get_entity_tag_slot(entity, name);
|
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||||
return tag->data.string;
|
return tag->data.string;
|
||||||
}
|
}
|
||||||
|
|
||||||
void * mt_get_ptr_tag(MtEntity entity, char *name)
|
void * mt_get_ptr_tag(MtEntity *entity, char *name)
|
||||||
{
|
{
|
||||||
MtTag tag = mt_get_entity_tag_slot(entity, name);
|
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||||
return tag->data.pointer;
|
return tag->data.pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
rr_vec2f_s mt_get_vec2_tag(MtEntity entity, char *name)
|
rr_vec2f_s mt_get_vec2_tag(MtEntity *entity, char *name)
|
||||||
{
|
{
|
||||||
MtTag tag = mt_get_entity_tag_slot(entity, name);
|
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||||
return tag->data.vec2f;
|
return tag->data.vec2f;
|
||||||
}
|
}
|
||||||
|
|
||||||
rr_vec3f_s mt_get_vec3_tag(MtEntity entity, char *name)
|
rr_vec3f_s mt_get_vec3_tag(MtEntity *entity, char *name)
|
||||||
{
|
{
|
||||||
MtTag tag = mt_get_entity_tag_slot(entity, name);
|
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||||
return tag->data.vec3f;
|
return tag->data.vec3f;
|
||||||
}
|
}
|
||||||
|
|
||||||
rr_vec4f_s mt_get_vec4_tag(MtEntity entity, char *name)
|
rr_vec4f_s mt_get_vec4_tag(MtEntity *entity, char *name)
|
||||||
{
|
{
|
||||||
MtTag tag = mt_get_entity_tag_slot(entity, name);
|
MtTag *tag = mt_get_entity_tag_slot(entity, name);
|
||||||
return tag->data.vec4f;
|
return tag->data.vec4f;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
#include <librr/memory.h>
|
#include <librr/memory.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
MtState mt_initialize(char *app_name)
|
MtState * mt_initialize(char *app_name)
|
||||||
{
|
{
|
||||||
usz_t len_app_name = rr_measure_string(app_name);
|
usz_t len_app_name = rr_measure_string(app_name);
|
||||||
MtState state = malloc(sizeof(struct MtState));
|
MtState *state = malloc(sizeof(struct MtState));
|
||||||
|
|
||||||
state->app_name = malloc(len_app_name + 1);
|
state->app_name = malloc(len_app_name + 1);
|
||||||
rr_memcopy(state->app_name, app_name, len_app_name + 1);
|
rr_memcopy(state->app_name, app_name, len_app_name + 1);
|
||||||
|
@ -16,7 +16,7 @@ MtState mt_initialize(char *app_name)
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mt_cleanup(MtState state)
|
void mt_cleanup(MtState *state)
|
||||||
{
|
{
|
||||||
mt_delete_entity_registry(&state->entity_registry);
|
mt_delete_entity_registry(&state->entity_registry);
|
||||||
mt_delete_tag_registry(state->tag_registry);
|
mt_delete_tag_registry(state->tag_registry);
|
||||||
|
@ -32,14 +32,14 @@ void mt_start(MtState state)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
MtEntity mt_summon(MtState state)
|
MtEntity * mt_summon(MtState *state)
|
||||||
{
|
{
|
||||||
return mt_create_entity(state, state->entity_registry.entity_id_counter++);
|
return mt_create_entity(state, state->entity_registry.entity_id_counter++);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mt_drop(MtEntity entity)
|
void mt_drop(MtEntity *entity)
|
||||||
{
|
{
|
||||||
MtState state = entity->parent_state;
|
MtState *state = entity->parent_state;
|
||||||
|
|
||||||
mt_delete_entity_data(entity);
|
mt_delete_entity_data(entity);
|
||||||
mt_give_back_entity_pool_slot(&state->entity_registry.pool, state->entity_registry.pool.first_free);
|
mt_give_back_entity_pool_slot(&state->entity_registry.pool, state->entity_registry.pool.first_free);
|
||||||
|
|
Reference in New Issue