Unify the library on an akgl_ namespace
This commit is contained in:
92
src/heap.c
92
src/heap.c
@@ -9,39 +9,39 @@
|
||||
#include <sdl3game/iterator.h>
|
||||
#include <sdl3game/error.h>
|
||||
|
||||
actor HEAP_ACTOR[MAX_HEAP_ACTOR];
|
||||
sprite HEAP_SPRITE[MAX_HEAP_SPRITE];
|
||||
spritesheet HEAP_SPRITESHEET[MAX_HEAP_SPRITESHEET];
|
||||
character HEAP_CHARACTER[MAX_HEAP_CHARACTER];
|
||||
string HEAP_STRING[MAX_HEAP_STRING];
|
||||
akgl_Actor HEAP_ACTOR[AKGL_MAX_HEAP_ACTOR];
|
||||
akgl_Sprite HEAP_SPRITE[AKGL_MAX_HEAP_SPRITE];
|
||||
akgl_SpriteSheet HEAP_SPRITESHEET[AKGL_MAX_HEAP_SPRITESHEET];
|
||||
akgl_Character HEAP_CHARACTER[AKGL_MAX_HEAP_CHARACTER];
|
||||
akgl_String HEAP_STRING[AKGL_MAX_HEAP_STRING];
|
||||
|
||||
akerr_ErrorContext *heap_init()
|
||||
akerr_ErrorContext *akgl_heap_init()
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
int i = 0;
|
||||
akerr_name_for_status(AKERR_SDL, "SDL Error");
|
||||
for ( i = 0; i < MAX_HEAP_ACTOR; i++) {
|
||||
memset(&HEAP_ACTOR[i], 0x00, sizeof(actor));
|
||||
akerr_name_for_status(AKGL_ERR_SDL, "SDL Error");
|
||||
for ( i = 0; i < AKGL_MAX_HEAP_ACTOR; i++) {
|
||||
memset(&HEAP_ACTOR[i], 0x00, sizeof(akgl_Actor));
|
||||
}
|
||||
for ( i = 0; i < MAX_HEAP_SPRITE; i++) {
|
||||
memset(&HEAP_SPRITE[i], 0x00, sizeof(sprite));
|
||||
for ( i = 0; i < AKGL_MAX_HEAP_SPRITE; i++) {
|
||||
memset(&HEAP_SPRITE[i], 0x00, sizeof(akgl_Sprite));
|
||||
}
|
||||
for ( i = 0; i < MAX_HEAP_SPRITESHEET; i++) {
|
||||
memset(&HEAP_SPRITESHEET[i], 0x00, sizeof(spritesheet));
|
||||
for ( i = 0; i < AKGL_MAX_HEAP_SPRITESHEET; i++) {
|
||||
memset(&HEAP_SPRITESHEET[i], 0x00, sizeof(akgl_SpriteSheet));
|
||||
}
|
||||
for ( i = 0; i < MAX_HEAP_CHARACTER; i++) {
|
||||
memset(&HEAP_CHARACTER[i], 0x00, sizeof(character));
|
||||
for ( i = 0; i < AKGL_MAX_HEAP_CHARACTER; i++) {
|
||||
memset(&HEAP_CHARACTER[i], 0x00, sizeof(akgl_Character));
|
||||
}
|
||||
for ( i = 0; i < MAX_HEAP_STRING; i++) {
|
||||
memset(&HEAP_STRING[i], 0x00, sizeof(string));
|
||||
for ( i = 0; i < AKGL_MAX_HEAP_STRING; i++) {
|
||||
memset(&HEAP_STRING[i], 0x00, sizeof(akgl_String));
|
||||
}
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
akerr_ErrorContext *heap_next_actor(actor **dest)
|
||||
akerr_ErrorContext *akgl_heap_next_actor(akgl_Actor **dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
for (int i = 0; i < MAX_HEAP_ACTOR; i++ ) {
|
||||
for (int i = 0; i < AKGL_MAX_HEAP_ACTOR; i++ ) {
|
||||
if ( HEAP_ACTOR[i].refcount != 0 ) {
|
||||
continue;
|
||||
}
|
||||
@@ -51,10 +51,10 @@ akerr_ErrorContext *heap_next_actor(actor **dest)
|
||||
FAIL_RETURN(errctx, AKERR_HEAP, "Unable to find unused actor on the heap");
|
||||
}
|
||||
|
||||
akerr_ErrorContext *heap_next_sprite(sprite **dest)
|
||||
akerr_ErrorContext *akgl_heap_next_sprite(akgl_Sprite **dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
for (int i = 0; i < MAX_HEAP_SPRITE; i++ ) {
|
||||
for (int i = 0; i < AKGL_MAX_HEAP_SPRITE; i++ ) {
|
||||
if ( HEAP_SPRITE[i].refcount != 0 ) {
|
||||
continue;
|
||||
}
|
||||
@@ -64,10 +64,10 @@ akerr_ErrorContext *heap_next_sprite(sprite **dest)
|
||||
FAIL_RETURN(errctx, AKERR_HEAP, "Unable to find unused sprite on the heap");
|
||||
}
|
||||
|
||||
akerr_ErrorContext *heap_next_spritesheet(spritesheet **dest)
|
||||
akerr_ErrorContext *akgl_heap_next_spritesheet(akgl_SpriteSheet **dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
for (int i = 0; i < MAX_HEAP_SPRITESHEET; i++ ) {
|
||||
for (int i = 0; i < AKGL_MAX_HEAP_SPRITESHEET; i++ ) {
|
||||
if ( HEAP_SPRITESHEET[i].refcount != 0 ) {
|
||||
continue;
|
||||
}
|
||||
@@ -77,10 +77,10 @@ akerr_ErrorContext *heap_next_spritesheet(spritesheet **dest)
|
||||
FAIL_RETURN(errctx, AKERR_HEAP, "Unable to find unused spritesheet on the heap");
|
||||
}
|
||||
|
||||
akerr_ErrorContext *heap_next_character(character **dest)
|
||||
akerr_ErrorContext *akgl_heap_next_character(akgl_Character **dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
for (int i = 0; i < MAX_HEAP_CHARACTER; i++ ) {
|
||||
for (int i = 0; i < AKGL_MAX_HEAP_CHARACTER; i++ ) {
|
||||
if ( HEAP_CHARACTER[i].refcount != 0 ) {
|
||||
continue;
|
||||
}
|
||||
@@ -90,10 +90,10 @@ akerr_ErrorContext *heap_next_character(character **dest)
|
||||
FAIL_RETURN(errctx, AKERR_HEAP, "Unable to find unused character on the heap");
|
||||
}
|
||||
|
||||
akerr_ErrorContext *heap_next_string(string **dest)
|
||||
akerr_ErrorContext *akgl_heap_next_string(akgl_String **dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
for (int i = 0; i < MAX_HEAP_STRING; i++ ) {
|
||||
for (int i = 0; i < AKGL_MAX_HEAP_STRING; i++ ) {
|
||||
if ( HEAP_STRING[i].refcount != 0 ) {
|
||||
continue;
|
||||
}
|
||||
@@ -103,7 +103,7 @@ akerr_ErrorContext *heap_next_string(string **dest)
|
||||
FAIL_RETURN(errctx, AKERR_HEAP, "Unable to find unused string on the heap");
|
||||
}
|
||||
|
||||
akerr_ErrorContext *heap_release_actor(actor *ptr)
|
||||
akerr_ErrorContext *akgl_heap_release_actor(akgl_Actor *ptr)
|
||||
{
|
||||
int i = 0;
|
||||
PREPARE_ERROR(errctx);
|
||||
@@ -112,39 +112,39 @@ akerr_ErrorContext *heap_release_actor(actor *ptr)
|
||||
ptr->refcount -= 1;
|
||||
}
|
||||
if ( ptr->refcount == 0 ) {
|
||||
for ( i = 0; i < ACTOR_MAX_CHILDREN; i++ ) {
|
||||
for ( i = 0; i < AKGL_ACTOR_MAX_CHILDREN; i++ ) {
|
||||
if ( ptr->children[i] != NULL ) {
|
||||
CATCH_AND_RETURN(errctx, heap_release_actor(ptr->children[i]));
|
||||
CATCH_AND_RETURN(errctx, akgl_heap_release_actor(ptr->children[i]));
|
||||
}
|
||||
}
|
||||
if ( ptr->basechar != NULL ) {
|
||||
CATCH_AND_RETURN(errctx, heap_release_character(ptr->basechar));
|
||||
CATCH_AND_RETURN(errctx, akgl_heap_release_character(ptr->basechar));
|
||||
}
|
||||
memset(ptr, 0x00, sizeof(actor));
|
||||
SDL_ClearProperty(REGISTRY_ACTOR, (char *)&ptr->name);
|
||||
memset(ptr, 0x00, sizeof(akgl_Actor));
|
||||
SDL_ClearProperty(AKGL_REGISTRY_ACTOR, (char *)&ptr->name);
|
||||
}
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
akerr_ErrorContext *heap_release_character(character *basechar)
|
||||
akerr_ErrorContext *akgl_heap_release_character(akgl_Character *basechar)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
iterator opflags;
|
||||
akgl_Iterator opflags;
|
||||
FAIL_ZERO_RETURN(errctx, basechar, AKERR_NULLPOINTER, "NULL character reference");
|
||||
BITMASK_CLEAR(opflags.flags);
|
||||
BITMASK_ADD(opflags.flags, ITERATOR_OP_RELEASE);
|
||||
AKGL_BITMASK_CLEAR(opflags.flags);
|
||||
AKGL_BITMASK_ADD(opflags.flags, AKGL_ITERATOR_OP_RELEASE);
|
||||
|
||||
if ( basechar->refcount > 0 ) {
|
||||
basechar->refcount -= 1;
|
||||
}
|
||||
if ( basechar->refcount == 0 ) {
|
||||
SDL_EnumerateProperties(basechar->state_sprites, &character_state_sprites_iterate, (void *)&opflags);
|
||||
SDL_ClearProperty(REGISTRY_CHARACTER, (char *)&basechar->name);
|
||||
SDL_EnumerateProperties(basechar->state_sprites, &akgl_character_state_sprites_iterate, (void *)&opflags);
|
||||
SDL_ClearProperty(AKGL_REGISTRY_CHARACTER, (char *)&basechar->name);
|
||||
}
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
akerr_ErrorContext *heap_release_sprite(sprite *ptr)
|
||||
akerr_ErrorContext *akgl_heap_release_sprite(akgl_Sprite *ptr)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, ptr, AKERR_NULLPOINTER, "Received NULL sprite reference");
|
||||
@@ -153,16 +153,16 @@ akerr_ErrorContext *heap_release_sprite(sprite *ptr)
|
||||
}
|
||||
if ( ptr->refcount == 0 ) {
|
||||
ATTEMPT {
|
||||
CATCH(errctx, heap_release_spritesheet(ptr->sheet));
|
||||
CATCH(errctx, akgl_heap_release_spritesheet(ptr->sheet));
|
||||
} CLEANUP {
|
||||
SDL_ClearProperty(REGISTRY_SPRITE, (char *)&ptr->name);
|
||||
SDL_ClearProperty(AKGL_REGISTRY_SPRITE, (char *)&ptr->name);
|
||||
} PROCESS(errctx) {
|
||||
} FINISH(errctx, true);
|
||||
}
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
akerr_ErrorContext *heap_release_spritesheet(spritesheet *ptr)
|
||||
akerr_ErrorContext *akgl_heap_release_spritesheet(akgl_SpriteSheet *ptr)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, ptr, AKERR_NULLPOINTER, "Received NULL spritesheet reference");
|
||||
@@ -171,7 +171,7 @@ akerr_ErrorContext *heap_release_spritesheet(spritesheet *ptr)
|
||||
}
|
||||
if ( ptr->refcount == 0 ) {
|
||||
// TODO : If we go threaded, make sure this is only happening on the main thread
|
||||
SDL_ClearProperty(REGISTRY_SPRITESHEET, (char *)&ptr->name);
|
||||
SDL_ClearProperty(AKGL_AKGL_REGISTRY_SPRITESHEET, (char *)&ptr->name);
|
||||
if ( ptr-> texture != NULL )
|
||||
SDL_DestroyTexture(ptr->texture);
|
||||
ptr->texture = NULL;
|
||||
@@ -179,7 +179,7 @@ akerr_ErrorContext *heap_release_spritesheet(spritesheet *ptr)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
akerr_ErrorContext *heap_release_string(string *ptr)
|
||||
akerr_ErrorContext *akgl_heap_release_string(akgl_String *ptr)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, ptr, AKERR_NULLPOINTER, "Received NULL string reference");
|
||||
@@ -187,7 +187,7 @@ akerr_ErrorContext *heap_release_string(string *ptr)
|
||||
ptr->refcount -= 1;
|
||||
}
|
||||
if ( ptr->refcount == 0 ) {
|
||||
memset(&ptr->data, 0x00, MAX_STRING_LENGTH);
|
||||
memset(&ptr->data, 0x00, AKGL_MAX_STRING_LENGTH);
|
||||
}
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user