From 2fa120c0249642b470ef97a071889fe1311019f1 Mon Sep 17 00:00:00 2001 From: Eric-Paul Ickhorn Date: Tue, 30 Jan 2024 22:47:43 +0100 Subject: [PATCH] Made pointers to structs visible more clearly, not hidden in the typedefs --- core/inc-c/entity.h | 46 +++++++++++++------------- core/inc-c/state.h | 12 +++---- core/src-c/entity_lookup.c | 14 ++++---- core/src-c/entity_registry.c | 14 ++++---- core/src-c/entity_tagging.c | 62 ++++++++++++++++++------------------ core/src-c/state.c | 12 +++---- 6 files changed, 80 insertions(+), 80 deletions(-) diff --git a/core/inc-c/entity.h b/core/inc-c/entity.h index dca572d..71717ad 100644 --- a/core/inc-c/entity.h +++ b/core/inc-c/entity.h @@ -11,8 +11,8 @@ typedef struct MtEntityListL2 MtEntityListL2; typedef struct MtEntityListL3 MtEntityListL3; typedef struct MtEntityPool MtEntityPool; typedef struct MtEntityRegistry MtEntityRegistry; -typedef struct MtEntity * MtEntity; -typedef struct MtTag * MtTag; +typedef struct MtEntity MtEntity; +typedef struct MtTag MtTag; struct MtEntityPool { @@ -52,7 +52,7 @@ struct MtEntityRegistry struct MtEntity { void *parent_state; - MtEntity pool_next_free; + MtEntity *pool_next_free; u32_t identifier; u16_t tags_capacity; @@ -78,35 +78,35 @@ struct MtTag 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); +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_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); +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); +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); +void mt_delete_entity_data(MtEntity *entity); MtEntityPool mt_create_entity_pool(usz_t capacity); void mt_delete_entity_pool(MtEntityPool *pool); -MtEntity mt_get_entity_pool_slot(MtEntityPool *pool); -void mt_give_back_entity_pool_slot(MtEntityPool *pool, MtEntity entity); +MtEntity * mt_allocate_entity_pool_slot(MtEntityPool *pool); +void mt_give_back_entity_pool_slot(MtEntityPool *pool, MtEntity *entity); #endif // MT_ENTITY_POOL_H diff --git a/core/inc-c/state.h b/core/inc-c/state.h index 5864149..f929dfc 100644 --- a/core/inc-c/state.h +++ b/core/inc-c/state.h @@ -8,7 +8,7 @@ #include #include -typedef struct MtState * MtState; +typedef struct MtState MtState; struct MtState { @@ -18,11 +18,11 @@ struct MtState MtEntityRegistry entity_registry; }; -MtState mt_initialize(char *app_name); -void mt_cleanup(MtState state); -void mt_start(MtState state); +MtState * mt_initialize(char *app_name); +void mt_cleanup(MtState *state); +void mt_start(MtState *state); -MtEntity mt_summon(MtState state); -void mt_delete(MtEntity entity); +MtEntity * mt_summon(MtState *state); +void mt_delete(MtEntity *entity); #endif // MT_STATE_H diff --git a/core/src-c/entity_lookup.c b/core/src-c/entity_lookup.c index d93350f..4dd78c2 100644 --- a/core/src-c/entity_lookup.c +++ b/core/src-c/entity_lookup.c @@ -2,9 +2,9 @@ #include #include -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]; if(level1 == NULL) { @@ -26,19 +26,19 @@ MtEntity mt_create_entity(void *state_voidptr, u32_t identifier) level3 = level2->sublists[(identifier >> 8) & 0xff]; } - MtEntity entity = level3->entities[identifier & 0xff]; + MtEntity *entity = level3->entities[identifier & 0xff]; 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; level3->entities[identifier & 0xff] = 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]; if(level1 == NULL) return NULL; @@ -51,7 +51,7 @@ MtEntity mt_get_entity(void *state_voidptr, u32_t identifier) if(level3 == NULL) return NULL; - MtEntity entity = level3->entities[identifier & 0xff]; + MtEntity *entity = level3->entities[identifier & 0xff]; if(entity == NULL) return NULL; diff --git a/core/src-c/entity_registry.c b/core/src-c/entity_registry.c index 54d7570..c64236b 100644 --- a/core/src-c/entity_registry.c +++ b/core/src-c/entity_registry.c @@ -63,7 +63,7 @@ void mt_delete_entity_lookup_tree(MtEntityLookupTree lookup_tree) usz_t entity_index = 0; while(entity_index < 256) { - MtEntity entity = level3_list->entities[entity_index]; + MtEntity *entity = level3_list->entities[entity_index]; if(entity == NULL) { ++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) free(entity->tags); @@ -108,7 +108,7 @@ MtEntityPool mt_create_entity_pool(usz_t capacity) { MtEntityPool pool; pool.capacity = capacity; - pool.entities = calloc(sizeof(struct MtEntity), pool.capacity); + pool.entities = calloc(sizeof(MtEntity), pool.capacity); mt_reset_entity_pool_allocation(&pool); pool.first_free = &pool.entities[0]; 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) { @@ -136,14 +136,14 @@ MtEntity mt_get_entity_pool_slot(MtEntityPool *pool) pool->continuation = malloc(sizeof(MtEntityPool)); *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; 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; pool->first_free = entity; diff --git a/core/src-c/entity_tagging.c b/core/src-c/entity_tagging.c index 74bee05..7b69f44 100644 --- a/core/src-c/entity_tagging.c +++ b/core/src-c/entity_tagging.c @@ -2,9 +2,9 @@ #include #include -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 @@ -31,89 +31,89 @@ MtTag mt_get_entity_tag_slot(MtEntity entity, char *name) 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; } -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; } -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; } -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; } -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; } -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; } -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; } -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; } -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; } -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; } -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; } -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; } -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; } -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; } diff --git a/core/src-c/state.c b/core/src-c/state.c index 9e714af..507bd5f 100644 --- a/core/src-c/state.c +++ b/core/src-c/state.c @@ -3,10 +3,10 @@ #include #include -MtState mt_initialize(char *app_name) +MtState * mt_initialize(char *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); rr_memcopy(state->app_name, app_name, len_app_name + 1); @@ -16,7 +16,7 @@ MtState mt_initialize(char *app_name) return state; } -void mt_cleanup(MtState state) +void mt_cleanup(MtState *state) { mt_delete_entity_registry(&state->entity_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++); } -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_give_back_entity_pool_slot(&state->entity_registry.pool, state->entity_registry.pool.first_free);