From dc2e88b72f1757fb98036413bea53f3b5d7b1963 Mon Sep 17 00:00:00 2001 From: Andrew Kesterson Date: Wed, 13 May 2026 16:56:24 -0400 Subject: [PATCH] Fix a scale bug (default should be 1.0), add tilemap release function --- include/akgl/SDL_GameControllerDB.h | 2 +- include/akgl/tilemap.h | 1 + src/actor.c | 1 + src/character.c | 1 + src/tilemap.c | 30 ++++++++++++++++++++++------- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/include/akgl/SDL_GameControllerDB.h b/include/akgl/SDL_GameControllerDB.h index 52136c5..d786c0e 100644 --- a/include/akgl/SDL_GameControllerDB.h +++ b/include/akgl/SDL_GameControllerDB.h @@ -1,7 +1,7 @@ #ifndef _SDL_GAMECONTROLLERDB_H_ #define _SDL_GAMECONTROLLERDB_H_ -// Taken from https://raw.githubusercontent.com/mdqinc/SDL_GameControllerDB/refs/heads/master/gamecontrollerdb.txt on Wed May 13 09:55:53 AM EDT 2026 +// Taken from https://raw.githubusercontent.com/mdqinc/SDL_GameControllerDB/refs/heads/master/gamecontrollerdb.txt on Wed May 13 04:55:09 PM EDT 2026 #define AKGL_SDL_GAMECONTROLLER_DB_LEN 2228 diff --git a/include/akgl/tilemap.h b/include/akgl/tilemap.h index 041c2cb..abf6dd8 100644 --- a/include/akgl/tilemap.h +++ b/include/akgl/tilemap.h @@ -115,6 +115,7 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_tilemap_load_layer_tile(akgl_Tilemap *de akerr_ErrorContext AKERR_NOIGNORE *akgl_tilemap_load_layers(akgl_Tilemap *dest, json_t *root); akerr_ErrorContext AKERR_NOIGNORE *akgl_tilemap_load_tilesets_each(json_t *tileset, akgl_Tilemap *dest, int tsidx); akerr_ErrorContext AKERR_NOIGNORE *akgl_tilemap_load_tilesets(akgl_Tilemap *dest, json_t *root); +akerr_ErrorContext AKERR_NOIGNORE *akgl_tilemap_release(akgl_Tilemap *dest); akerr_ErrorContext AKERR_NOIGNORE *akgl_tilemap_scale_actor(akgl_Tilemap *map, akgl_Actor *actor); #endif //_TILEMAP_H_ diff --git a/src/actor.c b/src/actor.c index b0d5965..530615c 100644 --- a/src/actor.c +++ b/src/actor.c @@ -20,6 +20,7 @@ akerr_ErrorContext *akgl_actor_initialize(akgl_Actor *obj, char *name) memset(obj, 0x00, sizeof(akgl_Actor)); strncpy((char *)obj->name, name, AKGL_ACTOR_MAX_NAME_LENGTH); obj->curSpriteReversing = false; + obj->scale = 1.0; obj->movement_controls_face = true; obj->updatefunc = &akgl_actor_update; diff --git a/src/character.c b/src/character.c index aa85238..016ddf1 100644 --- a/src/character.c +++ b/src/character.c @@ -198,5 +198,6 @@ akerr_ErrorContext *akgl_character_load_json(char *filename) } } PROCESS(errctx) { } FINISH(errctx, true); + SDL_Log("Character %s loaded from %s", obj->name, filename); SUCCEED_RETURN(errctx); } diff --git a/src/tilemap.c b/src/tilemap.c index 4712ee4..8f33958 100644 --- a/src/tilemap.c +++ b/src/tilemap.c @@ -451,7 +451,7 @@ akerr_ErrorContext *akgl_tilemap_load(char *fname, akgl_Tilemap *dest) // How much bigger is the foreground vs the vanishing point? // if vanishing is height 16, and foreground is height 32, that is a 2x scale difference dest->p_scale = (dest->p_foreground_h / dest->p_vanishing_h); - SDL_Log("Map perspective scale is (%f/%f) = %f", dest->p_foreground_h, dest->p_vanishing_h, dest->p_scale); + SDL_Log("Map perspective scale is (%d/%d) = %f", dest->p_foreground_h, dest->p_vanishing_h, dest->p_scale); // Sprites are always size 1.0 at the foreground, so how much do we need to // scale them for every pixel above foreground_y before they reach vanishing_y? // If vanishing is at 320 and foreground is at 640, that is a 320 line difference @@ -646,11 +646,6 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_tilemap_scale_actor(akgl_Tilemap *map, a FAIL_ZERO_RETURN(e, map, AKERR_NULLPOINTER, "NULL map"); FAIL_ZERO_RETURN(e, actor, AKERR_NULLPOINTER, "NULL actor"); - SDL_Log("Map foreground is at %d, vanishes at %d, actor %p is at %f", - map->p_foreground_y, - map->p_vanishing_y, - actor, - actor->y); if ( actor->y <= map->p_vanishing_y ) { actor->scale = 1.0 / map->p_scale; } else if ( actor->y >= map->p_foreground_y ) { @@ -658,5 +653,26 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_tilemap_scale_actor(akgl_Tilemap *map, a } else { actor->scale = 1.0 - (map->p_rate * (map->p_foreground_y - actor->y)); } - SDL_Log("Actor %p scaled to %f", actor, actor->scale); + SUCCEED_RETURN(e); +} + +akerr_ErrorContext AKERR_NOIGNORE *akgl_tilemap_release(akgl_Tilemap *dest) +{ + // Release all tileset textures + // Release all image layer textures + // Memset to zero + PREPARE_ERROR(e); + FAIL_ZERO_RETURN(e, dest, AKERR_NULLPOINTER, "NULL map"); + int i = 0; + for ( i = 0; i < AKGL_TILEMAP_MAX_TILESETS; i++ ) { + if ( dest->tilesets[i].texture != NULL ) { + SDL_DestroyTexture(dest->tilesets[i].texture); + } + } + for ( i = 0; i < AKGL_TILEMAP_MAX_LAYERS; i++ ) { + if ( dest->layers[i].texture != NULL ) { + SDL_DestroyTexture(dest->tilesets[i].texture); + } + } + SUCCEED_RETURN(e); }