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:
18
src/actor.c
18
src/actor.c
@@ -76,7 +76,7 @@ akerr_ErrorContext *actor_automatic_face(actor *obj)
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
akerr_ErrorContext *actor_logic_movement(actor *obj, SDL_Time curtimems)
|
||||
akerr_ErrorContext *actor_logic_movement(actor *obj, SDL_Time curtime)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "Null actor reference");
|
||||
@@ -139,7 +139,6 @@ akerr_ErrorContext *actor_update(actor *obj)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
SDL_Time curtime = 0;
|
||||
SDL_Time curtimems = 0;
|
||||
sprite *curSprite = NULL;
|
||||
|
||||
FAIL_ZERO_RETURN(errctx, obj, AKERR_NULLPOINTER, "NULL actor reference");
|
||||
@@ -147,12 +146,11 @@ akerr_ErrorContext *actor_update(actor *obj)
|
||||
|
||||
ATTEMPT {
|
||||
SDL_GetCurrentTime(&curtime);
|
||||
curtimems = curtime / 1000000;
|
||||
CATCH(errctx, obj->facefunc(obj));
|
||||
// is it time to apply movement logic?
|
||||
if ( (curtimems - obj->logictimer) >= obj->basechar->movementspeed ) {
|
||||
CATCH(errctx, obj->movementlogicfunc(obj, curtimems));
|
||||
obj->logictimer = curtimems;
|
||||
if ( (curtime - obj->logictimer) >= obj->basechar->movementspeed ) {
|
||||
CATCH(errctx, obj->movementlogicfunc(obj, curtime));
|
||||
obj->logictimer = curtime;
|
||||
}
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
@@ -161,9 +159,9 @@ akerr_ErrorContext *actor_update(actor *obj)
|
||||
ATTEMPT {
|
||||
CATCH(errctx, character_sprite_get(obj->basechar, obj->state, &curSprite));
|
||||
// is it time to change frames?
|
||||
if ( (curtimems - obj->curSpriteFrameTimer) >= curSprite->speed ) {
|
||||
CATCH(errctx, obj->changeframefunc(obj, curSprite, curtimems));
|
||||
obj->curSpriteFrameTimer = curtimems;
|
||||
if ( ((curtime) - obj->curSpriteFrameTimer) >= curSprite->speed) {
|
||||
CATCH(errctx, obj->changeframefunc(obj, curSprite, curtime));
|
||||
obj->curSpriteFrameTimer = curtime;
|
||||
}
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
|
||||
@@ -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
|
||||
);
|
||||
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_y", &obj->vy));
|
||||
} CLEANUP {
|
||||
|
||||
@@ -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, "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, "loopReverse", &obj->loopReverse));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user