Fix a scale bug (default should be 1.0), add tilemap release function
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#ifndef _SDL_GAMECONTROLLERDB_H_
|
#ifndef _SDL_GAMECONTROLLERDB_H_
|
||||||
#define _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
|
#define AKGL_SDL_GAMECONTROLLER_DB_LEN 2228
|
||||||
|
|
||||||
|
|||||||
@@ -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_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_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_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);
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_tilemap_scale_actor(akgl_Tilemap *map, akgl_Actor *actor);
|
||||||
|
|
||||||
#endif //_TILEMAP_H_
|
#endif //_TILEMAP_H_
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ akerr_ErrorContext *akgl_actor_initialize(akgl_Actor *obj, char *name)
|
|||||||
memset(obj, 0x00, sizeof(akgl_Actor));
|
memset(obj, 0x00, sizeof(akgl_Actor));
|
||||||
strncpy((char *)obj->name, name, AKGL_ACTOR_MAX_NAME_LENGTH);
|
strncpy((char *)obj->name, name, AKGL_ACTOR_MAX_NAME_LENGTH);
|
||||||
obj->curSpriteReversing = false;
|
obj->curSpriteReversing = false;
|
||||||
|
obj->scale = 1.0;
|
||||||
obj->movement_controls_face = true;
|
obj->movement_controls_face = true;
|
||||||
|
|
||||||
obj->updatefunc = &akgl_actor_update;
|
obj->updatefunc = &akgl_actor_update;
|
||||||
|
|||||||
@@ -198,5 +198,6 @@ akerr_ErrorContext *akgl_character_load_json(char *filename)
|
|||||||
}
|
}
|
||||||
} PROCESS(errctx) {
|
} PROCESS(errctx) {
|
||||||
} FINISH(errctx, true);
|
} FINISH(errctx, true);
|
||||||
|
SDL_Log("Character %s loaded from %s", obj->name, filename);
|
||||||
SUCCEED_RETURN(errctx);
|
SUCCEED_RETURN(errctx);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -451,7 +451,7 @@ akerr_ErrorContext *akgl_tilemap_load(char *fname, akgl_Tilemap *dest)
|
|||||||
// How much bigger is the foreground vs the vanishing point?
|
// 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
|
// 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);
|
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
|
// 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?
|
// 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
|
// 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, map, AKERR_NULLPOINTER, "NULL map");
|
||||||
FAIL_ZERO_RETURN(e, actor, AKERR_NULLPOINTER, "NULL actor");
|
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 ) {
|
if ( actor->y <= map->p_vanishing_y ) {
|
||||||
actor->scale = 1.0 / map->p_scale;
|
actor->scale = 1.0 / map->p_scale;
|
||||||
} else if ( actor->y >= map->p_foreground_y ) {
|
} 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 {
|
} else {
|
||||||
actor->scale = 1.0 - (map->p_rate * (map->p_foreground_y - actor->y));
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user