Fix missing sdl3game.pc for pkg-config, change sprite speed and character movement values to long int expressed in nanoseconds for better compatibility with SDL_Time and locking against game clock, still expressed as milliseconds in json

This commit is contained in:
2026-05-05 20:39:58 -04:00
parent 90cbf41d75
commit 284ffd7b4a
9 changed files with 24 additions and 16 deletions

View File

@@ -19,6 +19,11 @@ find_package(box2d REQUIRED)
#pkg_check_modules(akerror REQUIRED akerror) #pkg_check_modules(akerror REQUIRED akerror)
set(GAMECONTROLLERDB_H "include/sdl3game/SDL_GameControllerDB.h") set(GAMECONTROLLERDB_H "include/sdl3game/SDL_GameControllerDB.h")
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix "\${prefix}")
set(libdir "\${exec_prefix}/lib")
set(includedir "\${prefix}/include")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/sdl3game.pc.in ${CMAKE_CURRENT_BINARY_DIR}/sdl3game.pc @ONLY)
add_custom_command( add_custom_command(
OUTPUT ${GAMECONTROLLERDB_H} OUTPUT ${GAMECONTROLLERDB_H}
@@ -90,10 +95,12 @@ target_link_libraries(test_util PRIVATE akerror::akerror sdl3game SDL3::SDL3 SDL
target_link_libraries(charviewer PRIVATE akerror::akerror sdl3game SDL3::SDL3 SDL3_image::SDL3_image SDL3_mixer::SDL3_mixer box2d::box2d jansson::jansson -lm) target_link_libraries(charviewer PRIVATE akerror::akerror sdl3game SDL3::SDL3 SDL3_image::SDL3_image SDL3_mixer::SDL3_mixer box2d::box2d jansson::jansson -lm)
set(main_lib_dest "lib/sdl3game-${MY_LIBRARY_VERSION}") set(main_lib_dest "lib/sdl3game-${MY_LIBRARY_VERSION}")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/sdl3game.pc DESTINATION "lib/pkgconfig/")
install(TARGETS sdl3game DESTINATION "lib/") install(TARGETS sdl3game DESTINATION "lib/")
install(FILES "include/sdl3game/actor.h" DESTINATION "include/sdl3game/") install(FILES "include/sdl3game/actor.h" DESTINATION "include/sdl3game/")
install(FILES "include/sdl3game/assets.h" DESTINATION "include/sdl3game/") install(FILES "include/sdl3game/assets.h" DESTINATION "include/sdl3game/")
install(FILES "include/sdl3game/character.h" DESTINATION "include/sdl3game/") install(FILES "include/sdl3game/character.h" DESTINATION "include/sdl3game/")
install(FILES "include/sdl3game/error.h" DESTINATION "include/sdl3game/")
install(FILES "include/sdl3game/draw.h" DESTINATION "include/sdl3game/") install(FILES "include/sdl3game/draw.h" DESTINATION "include/sdl3game/")
install(FILES "include/sdl3game/game.h" DESTINATION "include/sdl3game/") install(FILES "include/sdl3game/game.h" DESTINATION "include/sdl3game/")
install(FILES "include/sdl3game/controller.h" DESTINATION "include/sdl3game/") install(FILES "include/sdl3game/controller.h" DESTINATION "include/sdl3game/")

View File

@@ -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 Sun May 3 11:38:30 PM EDT 2026 // Taken from https://raw.githubusercontent.com/mdqinc/SDL_GameControllerDB/refs/heads/master/gamecontrollerdb.txt on Tue May 5 08:39:19 PM EDT 2026
#define SDL_GAMECONTROLLER_DB_LEN 2225 #define SDL_GAMECONTROLLER_DB_LEN 2225

View File

@@ -68,7 +68,7 @@ typedef struct actor {
bool movement_controls_face; bool movement_controls_face;
void *actorData; void *actorData;
bool visible; bool visible;
int logictimer; SDL_Time logictimer;
float x; float x;
float y; float y;
struct actor *children[ACTOR_MAX_CHILDREN]; struct actor *children[ACTOR_MAX_CHILDREN];

View File

@@ -13,7 +13,7 @@ typedef struct character {
SDL_PropertiesID state_sprites; SDL_PropertiesID state_sprites;
akerr_ErrorContext AKERR_NOIGNORE *(*sprite_add)(struct character *, sprite *, int); akerr_ErrorContext AKERR_NOIGNORE *(*sprite_add)(struct character *, sprite *, int);
akerr_ErrorContext AKERR_NOIGNORE *(*sprite_get)(struct character *, int, sprite **); akerr_ErrorContext AKERR_NOIGNORE *(*sprite_get)(struct character *, int, sprite **);
int movementspeed; long int movementspeed;
float vx; float vx;
float vy; float vy;
} character; } character;

View File

@@ -29,7 +29,7 @@ typedef struct {
int frames; // how many frames are in this animation int frames; // how many frames are in this animation
int width; int width;
int height; int height;
int speed; // how many milliseconds a given sprite frame should be visible before cycling long int speed; // how many milliseconds a given sprite frame should be visible before cycling
bool loop; // when this sprite is done playing, it should immediately start again bool loop; // when this sprite is done playing, it should immediately start again
bool loopReverse; // when this sprite is done playing, it should go in reverse order through its frames bool loopReverse; // when this sprite is done playing, it should go in reverse order through its frames
char name[SPRITE_MAX_NAME_LENGTH]; char name[SPRITE_MAX_NAME_LENGTH];

View File

@@ -76,7 +76,7 @@ akerr_ErrorContext *actor_automatic_face(actor *obj)
SUCCEED_RETURN(errctx); SUCCEED_RETURN(errctx);
} }
akerr_ErrorContext *actor_logic_changeframe(actor *obj, sprite *curSprite, SDL_Time curtimems) akerr_ErrorContext *actor_logic_changeframe(actor *obj, sprite *curSprite, SDL_Time curtime)
{ {
PREPARE_ERROR(errctx); PREPARE_ERROR(errctx);
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "Null actor reference"); FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "Null actor reference");
@@ -111,7 +111,7 @@ akerr_ErrorContext *actor_logic_changeframe(actor *obj, sprite *curSprite, SDL_T
SUCCEED_RETURN(errctx); SUCCEED_RETURN(errctx);
} }
akerr_ErrorContext *actor_logic_movement(actor *obj, SDL_Time curtimems) akerr_ErrorContext *actor_logic_movement(actor *obj, SDL_Time curtime)
{ {
PREPARE_ERROR(errctx); PREPARE_ERROR(errctx);
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "Null actor reference"); FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "Null actor reference");
@@ -139,7 +139,6 @@ akerr_ErrorContext *actor_update(actor *obj)
{ {
PREPARE_ERROR(errctx); PREPARE_ERROR(errctx);
SDL_Time curtime = 0; SDL_Time curtime = 0;
SDL_Time curtimems = 0;
sprite *curSprite = NULL; sprite *curSprite = NULL;
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor reference"); FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor reference");
@@ -147,12 +146,11 @@ akerr_ErrorContext *actor_update(actor *obj)
ATTEMPT { ATTEMPT {
SDL_GetCurrentTime(&curtime); SDL_GetCurrentTime(&curtime);
curtimems = curtime / 1000000;
CATCH(errctx, obj->facefunc(obj)); CATCH(errctx, obj->facefunc(obj));
// is it time to apply movement logic? // is it time to apply movement logic?
if ( (curtimems - obj->logictimer) >= obj->basechar->movementspeed ) { if ( (curtime - obj->logictimer) >= obj->basechar->movementspeed ) {
CATCH(errctx, obj->movementlogicfunc(obj, curtimems)); CATCH(errctx, obj->movementlogicfunc(obj, curtime));
obj->logictimer = curtimems; obj->logictimer = curtime;
} }
} CLEANUP { } CLEANUP {
} PROCESS(errctx) { } PROCESS(errctx) {
@@ -161,9 +159,9 @@ akerr_ErrorContext *actor_update(actor *obj)
ATTEMPT { ATTEMPT {
CATCH(errctx, character_sprite_get(obj->basechar, obj->state, &curSprite)); CATCH(errctx, character_sprite_get(obj->basechar, obj->state, &curSprite));
// is it time to change frames? // is it time to change frames?
if ( (curtimems - obj->curSpriteFrameTimer) >= curSprite->speed ) { if ( ((curtime) - obj->curSpriteFrameTimer) >= curSprite->speed) {
CATCH(errctx, obj->changeframefunc(obj, curSprite, curtimems)); CATCH(errctx, obj->changeframefunc(obj, curSprite, curtime));
obj->curSpriteFrameTimer = curtimems; obj->curSpriteFrameTimer = curtime;
} }
} CLEANUP { } CLEANUP {
} PROCESS(errctx) { } PROCESS(errctx) {

View File

@@ -185,6 +185,8 @@ akerr_ErrorContext *character_load_json(char *filename)
"Error while loading character from %s on line %d: %s", filename, error.line, error.text "Error while loading character from %s on line %d: %s", filename, error.line, error.text
); );
CATCH(errctx, character_load_json_inner(json, obj)); CATCH(errctx, character_load_json_inner(json, obj));
CATCH(errctx, get_json_integer_value(json, "movementspeed", (int *)&obj->movementspeed));
obj->movementspeed = obj->movementspeed * 1000000;
CATCH(errctx, get_json_number_value(json, "velocity_x", &obj->vx)); CATCH(errctx, get_json_number_value(json, "velocity_x", &obj->vx));
CATCH(errctx, get_json_number_value(json, "velocity_y", &obj->vy)); CATCH(errctx, get_json_number_value(json, "velocity_y", &obj->vy));
} CLEANUP { } CLEANUP {

View File

@@ -98,7 +98,8 @@ akerr_ErrorContext *sprite_load_json(char *filename)
CATCH(errctx, get_json_integer_value((json_t *)json, "width", &obj->width)); CATCH(errctx, get_json_integer_value((json_t *)json, "width", &obj->width));
CATCH(errctx, get_json_integer_value((json_t *)json, "height", &obj->height)); CATCH(errctx, get_json_integer_value((json_t *)json, "height", &obj->height));
CATCH(errctx, get_json_integer_value((json_t *)json, "speed", &obj->speed)); CATCH(errctx, get_json_integer_value((json_t *)json, "speed", (int *)&obj->speed));
obj->speed = obj->speed * 1000000;
CATCH(errctx, get_json_boolean_value((json_t *)json, "loop", &obj->loop)); CATCH(errctx, get_json_boolean_value((json_t *)json, "loop", &obj->loop));
CATCH(errctx, get_json_boolean_value((json_t *)json, "loopReverse", &obj->loopReverse)); CATCH(errctx, get_json_boolean_value((json_t *)json, "loopReverse", &obj->loopReverse));

View File

@@ -126,7 +126,7 @@ akerr_ErrorContext *test_sprite_load_json(void)
FAIL_ZERO_BREAK(errctx, (testsprite->width == 48), AKERR_VALUE, "width incorrect (48 : %d)", testsprite->width); FAIL_ZERO_BREAK(errctx, (testsprite->width == 48), AKERR_VALUE, "width incorrect (48 : %d)", testsprite->width);
FAIL_ZERO_BREAK(errctx, (testsprite->height == 48), AKERR_VALUE, "height incorrect (48 : %d)", testsprite->height); FAIL_ZERO_BREAK(errctx, (testsprite->height == 48), AKERR_VALUE, "height incorrect (48 : %d)", testsprite->height);
FAIL_ZERO_BREAK(errctx, (testsprite->speed == 100), AKERR_VALUE, "speed incorrect (100 : %d)", testsprite->speed); FAIL_ZERO_BREAK(errctx, (testsprite->speed == 100000000), AKERR_VALUE, "speed incorrect (100 : %ld)", testsprite->speed);
FAIL_ZERO_BREAK(errctx, (testsprite->loop == true), AKERR_VALUE, "loop incorrect (1 : %d)", testsprite->loop); FAIL_ZERO_BREAK(errctx, (testsprite->loop == true), AKERR_VALUE, "loop incorrect (1 : %d)", testsprite->loop);
FAIL_ZERO_BREAK(errctx, (testsprite->loopReverse == true), AKERR_VALUE, "loopReverse incorrect (1 : %d)", testsprite->loopReverse); FAIL_ZERO_BREAK(errctx, (testsprite->loopReverse == true), AKERR_VALUE, "loopReverse incorrect (1 : %d)", testsprite->loopReverse);
FAIL_ZERO_BREAK(errctx, (testsprite->frames == 3), AKERR_VALUE, "frame count incorrect (3 : %d)", testsprite->frames); FAIL_ZERO_BREAK(errctx, (testsprite->frames == 3), AKERR_VALUE, "frame count incorrect (3 : %d)", testsprite->frames);