Fix a scale bug (default should be 1.0), add tilemap release function

This commit is contained in:
2026-05-13 16:56:24 -04:00
parent 53e4f5c14f
commit dc2e88b72f
5 changed files with 27 additions and 8 deletions

View File

@@ -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);
}