Namespace every exported symbol, and bump to 0.5.0
Closes internal-consistency items 1 through 6, 12 and 13. Every include guard is _AKGL_<FILE>_H_, every in-project header include is angled, and every exported function, type and global carries the akgl_ prefix. This is an ABI break; the soname goes to libakgl.so.0.5. TODO.md carries the full rename table. The renames were driven by renaming each declaration and letting the compiler find the uses, not by pattern substitution: renderer, physics and camera are also parameter and struct-member names, and a sed would have rewritten map->physics and every akgl_RenderBackend *renderer parameter without a word. Item 4 turned out not to be cosmetic. The library exported a global called renderer and tests/character.c defined an SDL_Renderer *renderer of its own; the executable's definition preempted the library's, akgl_sprite_load_json read a SDL_Renderer * through an akgl_RenderBackend *, and every texture load in that suite failed. The suite reported success anyway, because libakerror's unhandled-error handler ends in exit(errctx->status), exit keeps only the low byte, and AKGL_ERR_SDL is exactly 256. So character had been green while running one of its four tests, and every suite in the tree was unable to fail on the most common status in a library built on SDL. Both are fixed. tests/testutil.h gains TEST_TRAP_UNHANDLED_ERRORS(), which collapses any status a byte cannot carry onto 1, and every suite installs it. character binds a real backend with akgl_render_2d_bind. Its fourth test then runs for the first time and fails on a defect it has asserted all along, so akgl_heap_release_character now walks state_sprites with AKGL_ITERATOR_OP_RELEASE and destroys the property set before zeroing the slot -- TODO.md Defects item 21 and half of Carried over item 1. AKGL_TIME_ONESEC_MS said "one second in milliseconds" and held 1000000, so akgl_game_state_lock waited roughly sixteen minutes rather than one second. It is AKGL_TIME_ONEMS_NS now, the budget is its own named constant, and tests/game.c holds the mutex from a second thread to assert the wait -- the contended path had no coverage at all. Headers are self-contained and it is enforced: AKGL_PUBLIC_HEADERS drives both install() and a generated translation unit per header, so a header that ships is a header that is checked. Writing that found registry.h, which used SDL_PropertiesID in eight declarations and included no SDL header. 23/23 suites pass, memcheck is clean, reindent --check is clean. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-Authored-By: Andrew Kesterson <andrew@aklabs.net>
This commit is contained in:
72
src/heap.c
72
src/heap.c
@@ -14,11 +14,11 @@
|
||||
#include <akgl/iterator.h>
|
||||
#include <akgl/error.h>
|
||||
|
||||
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];
|
||||
akgl_Actor akgl_heap_actors[AKGL_MAX_HEAP_ACTOR];
|
||||
akgl_Sprite akgl_heap_sprites[AKGL_MAX_HEAP_SPRITE];
|
||||
akgl_SpriteSheet akgl_heap_spritesheets[AKGL_MAX_HEAP_SPRITESHEET];
|
||||
akgl_Character akgl_heap_characters[AKGL_MAX_HEAP_CHARACTER];
|
||||
akgl_String akgl_heap_strings[AKGL_MAX_HEAP_STRING];
|
||||
|
||||
akerr_ErrorContext *akgl_heap_init()
|
||||
{
|
||||
@@ -26,16 +26,16 @@ akerr_ErrorContext *akgl_heap_init()
|
||||
int i = 0;
|
||||
PASS(errctx, akgl_heap_init_actor());
|
||||
for ( i = 0; i < AKGL_MAX_HEAP_SPRITE; i++) {
|
||||
memset(&HEAP_SPRITE[i], 0x00, sizeof(akgl_Sprite));
|
||||
memset(&akgl_heap_sprites[i], 0x00, sizeof(akgl_Sprite));
|
||||
}
|
||||
for ( i = 0; i < AKGL_MAX_HEAP_SPRITESHEET; i++) {
|
||||
memset(&HEAP_SPRITESHEET[i], 0x00, sizeof(akgl_SpriteSheet));
|
||||
memset(&akgl_heap_spritesheets[i], 0x00, sizeof(akgl_SpriteSheet));
|
||||
}
|
||||
for ( i = 0; i < AKGL_MAX_HEAP_CHARACTER; i++) {
|
||||
memset(&HEAP_CHARACTER[i], 0x00, sizeof(akgl_Character));
|
||||
memset(&akgl_heap_characters[i], 0x00, sizeof(akgl_Character));
|
||||
}
|
||||
for ( i = 0; i < AKGL_MAX_HEAP_STRING; i++) {
|
||||
memset(&HEAP_STRING[i], 0x00, sizeof(akgl_String));
|
||||
memset(&akgl_heap_strings[i], 0x00, sizeof(akgl_String));
|
||||
}
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
@@ -44,7 +44,7 @@ akerr_ErrorContext *akgl_heap_init_actor(void)
|
||||
{
|
||||
PREPARE_ERROR(e);
|
||||
for ( int i = 0; i < AKGL_MAX_HEAP_ACTOR; i++) {
|
||||
memset(&HEAP_ACTOR[i], 0x00, sizeof(akgl_Actor));
|
||||
memset(&akgl_heap_actors[i], 0x00, sizeof(akgl_Actor));
|
||||
}
|
||||
SUCCEED_RETURN(e);
|
||||
}
|
||||
@@ -53,10 +53,10 @@ akerr_ErrorContext *akgl_heap_next_actor(akgl_Actor **dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
for (int i = 0; i < AKGL_MAX_HEAP_ACTOR; i++ ) {
|
||||
if ( HEAP_ACTOR[i].refcount != 0 ) {
|
||||
if ( akgl_heap_actors[i].refcount != 0 ) {
|
||||
continue;
|
||||
}
|
||||
*dest = &HEAP_ACTOR[i];
|
||||
*dest = &akgl_heap_actors[i];
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
FAIL_RETURN(errctx, AKGL_ERR_HEAP, "Unable to find unused actor on the heap");
|
||||
@@ -66,10 +66,10 @@ akerr_ErrorContext *akgl_heap_next_sprite(akgl_Sprite **dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
for (int i = 0; i < AKGL_MAX_HEAP_SPRITE; i++ ) {
|
||||
if ( HEAP_SPRITE[i].refcount != 0 ) {
|
||||
if ( akgl_heap_sprites[i].refcount != 0 ) {
|
||||
continue;
|
||||
}
|
||||
*dest = &HEAP_SPRITE[i];
|
||||
*dest = &akgl_heap_sprites[i];
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
FAIL_RETURN(errctx, AKGL_ERR_HEAP, "Unable to find unused sprite on the heap");
|
||||
@@ -79,10 +79,10 @@ akerr_ErrorContext *akgl_heap_next_spritesheet(akgl_SpriteSheet **dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
for (int i = 0; i < AKGL_MAX_HEAP_SPRITESHEET; i++ ) {
|
||||
if ( HEAP_SPRITESHEET[i].refcount != 0 ) {
|
||||
if ( akgl_heap_spritesheets[i].refcount != 0 ) {
|
||||
continue;
|
||||
}
|
||||
*dest = &HEAP_SPRITESHEET[i];
|
||||
*dest = &akgl_heap_spritesheets[i];
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
FAIL_RETURN(errctx, AKGL_ERR_HEAP, "Unable to find unused spritesheet on the heap");
|
||||
@@ -92,10 +92,10 @@ akerr_ErrorContext *akgl_heap_next_character(akgl_Character **dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
for (int i = 0; i < AKGL_MAX_HEAP_CHARACTER; i++ ) {
|
||||
if ( HEAP_CHARACTER[i].refcount != 0 ) {
|
||||
if ( akgl_heap_characters[i].refcount != 0 ) {
|
||||
continue;
|
||||
}
|
||||
*dest = &HEAP_CHARACTER[i];
|
||||
*dest = &akgl_heap_characters[i];
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
FAIL_RETURN(errctx, AKGL_ERR_HEAP, "Unable to find unused character on the heap");
|
||||
@@ -105,11 +105,11 @@ akerr_ErrorContext *akgl_heap_next_string(akgl_String **dest)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
for (int i = 0; i < AKGL_MAX_HEAP_STRING; i++ ) {
|
||||
if ( HEAP_STRING[i].refcount != 0 ) {
|
||||
if ( akgl_heap_strings[i].refcount != 0 ) {
|
||||
continue;
|
||||
}
|
||||
*dest = &HEAP_STRING[i];
|
||||
HEAP_STRING[i].refcount += 1;
|
||||
*dest = &akgl_heap_strings[i];
|
||||
akgl_heap_strings[i].refcount += 1;
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
FAIL_RETURN(errctx, AKGL_ERR_HEAP, "Unable to find unused string on the heap");
|
||||
@@ -135,19 +135,35 @@ akerr_ErrorContext *akgl_heap_release_actor(akgl_Actor *ptr)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
akerr_ErrorContext *akgl_heap_release_character(akgl_Character *basechar)
|
||||
akerr_ErrorContext *akgl_heap_release_character(akgl_Character *ptr)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
akgl_Iterator opflags;
|
||||
FAIL_ZERO_RETURN(errctx, basechar, AKERR_NULLPOINTER, "NULL character reference");
|
||||
FAIL_ZERO_RETURN(errctx, ptr, AKERR_NULLPOINTER, "NULL character reference");
|
||||
AKGL_BITMASK_CLEAR(opflags.flags);
|
||||
|
||||
if ( basechar->refcount > 0 ) {
|
||||
basechar->refcount -= 1;
|
||||
if ( ptr->refcount > 0 ) {
|
||||
ptr->refcount -= 1;
|
||||
}
|
||||
if ( basechar->refcount == 0 ) {
|
||||
SDL_ClearProperty(AKGL_REGISTRY_CHARACTER, (char *)&basechar->name);
|
||||
memset(basechar, 0x00, sizeof(akgl_Character));
|
||||
if ( ptr->refcount == 0 ) {
|
||||
// Give back every sprite reference akgl_character_sprite_add took, and
|
||||
// the property set holding the map, before the slot is zeroed. Without
|
||||
// this a game that loads and releases characters level by level
|
||||
// exhausts the sprite pool and leaks one SDL_PropertiesID per
|
||||
// character. akgl_character_state_sprites_iterate exists for exactly
|
||||
// this walk and simply was never called from here.
|
||||
if ( ptr->state_sprites != 0 ) {
|
||||
AKGL_BITMASK_ADD(opflags.flags, AKGL_ITERATOR_OP_RELEASE);
|
||||
SDL_EnumerateProperties(
|
||||
ptr->state_sprites,
|
||||
&akgl_character_state_sprites_iterate,
|
||||
(void *)&opflags
|
||||
);
|
||||
SDL_DestroyProperties(ptr->state_sprites);
|
||||
ptr->state_sprites = 0;
|
||||
}
|
||||
SDL_ClearProperty(AKGL_REGISTRY_CHARACTER, (char *)&ptr->name);
|
||||
memset(ptr, 0x00, sizeof(akgl_Character));
|
||||
}
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user