From d054cf9e3656f038e6c76cf172281bb461c40b8a Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Sun, 9 Nov 2025 18:50:02 -0600 Subject: [PATCH] Fixed animation --- src/rpg/entity/entity.c | 11 +++++++---- src/rpg/entity/entity.h | 2 +- src/rpg/entity/entityanim.h | 4 ++-- src/scene/scene/scenemap.c | 4 +--- src/time/CMakeLists.txt | 1 + src/time/time.h | 14 +------------- 6 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/rpg/entity/entity.c b/src/rpg/entity/entity.c index e74dc17..d808321 100644 --- a/src/rpg/entity/entity.c +++ b/src/rpg/entity/entity.c @@ -39,8 +39,11 @@ void entityUpdate(entity_t *entity) { // What state is the entity in? if(entity->animation != ENTITY_ANIM_IDLE) { // Entity is mid animation, tick it (down). - entity->animFrame--; - if(entity->animFrame == 0) entity->animation = ENTITY_ANIM_IDLE; + entity->animTime -= TIME.delta; + if(entity->animTime <= 0) { + entity->animation = ENTITY_ANIM_IDLE; + entity->animTime = 0; + } return; } @@ -56,7 +59,7 @@ void entityUpdate(entity_t *entity) { void entityTurn(entity_t *entity, const entitydir_t direction) { entity->direction = direction; entity->animation = ENTITY_ANIM_TURN; - entity->animFrame = ENTITY_ANIM_TURN_DURATION; + entity->animTime = ENTITY_ANIM_TURN_DURATION; } void entityWalk(entity_t *entity, const entitydir_t direction) { @@ -99,7 +102,7 @@ void entityWalk(entity_t *entity, const entitydir_t direction) { entity->position.y = newY; entity->animation = ENTITY_ANIM_WALK; - entity->animFrame = ENTITY_ANIM_WALK_DURATION;// TODO: Running vs walking + entity->animTime = ENTITY_ANIM_WALK_DURATION;// TODO: Running vs walking } entity_t * entityGetAt(const worldpos_t position) { diff --git a/src/rpg/entity/entity.h b/src/rpg/entity/entity.h index 9a89860..8290422 100644 --- a/src/rpg/entity/entity.h +++ b/src/rpg/entity/entity.h @@ -25,7 +25,7 @@ typedef struct entity_s { worldpos_t position; entityanim_t animation; - uint8_t animFrame; + float_t animTime; } entity_t; extern entity_t ENTITIES[ENTITY_COUNT]; diff --git a/src/rpg/entity/entityanim.h b/src/rpg/entity/entityanim.h index 58bb47d..42f7d40 100644 --- a/src/rpg/entity/entityanim.h +++ b/src/rpg/entity/entityanim.h @@ -8,8 +8,8 @@ #pragma once #include "dusk.h" -#define ENTITY_ANIM_TURN_DURATION 6 -#define ENTITY_ANIM_WALK_DURATION 10 +#define ENTITY_ANIM_TURN_DURATION 0.06f +#define ENTITY_ANIM_WALK_DURATION 0.1f typedef enum { ENTITY_ANIM_IDLE, diff --git a/src/scene/scene/scenemap.c b/src/scene/scene/scenemap.c index 29a7677..ce3698b 100644 --- a/src/scene/scene/scenemap.c +++ b/src/scene/scene/scenemap.c @@ -58,9 +58,7 @@ void sceneMapEntityGetPosition(const entity_t *entity, vec3 outPosition) { // Add animation offset(s) switch(entity->animation) { case ENTITY_ANIM_WALK: - float_t animPercentage = ( - (float_t)entity->animFrame / (float_t)ENTITY_ANIM_WALK_DURATION - ); + float_t animPercentage = entity->animTime / ENTITY_ANIM_WALK_DURATION; // Get facing rel, we know we moved from the inverse direction. int8_t x, y; diff --git a/src/time/CMakeLists.txt b/src/time/CMakeLists.txt index 80797bd..2f93036 100644 --- a/src/time/CMakeLists.txt +++ b/src/time/CMakeLists.txt @@ -14,6 +14,7 @@ if(DUSK_TARGET_SYSTEM STREQUAL "linux") target_compile_definitions(${DUSK_TARGET_NAME} PRIVATE TIME_SDL2=1 + TIME_FIXED=0 ) elseif(DUSK_TARGET_SYSTEM STREQUAL "psp") target_compile_definitions(${DUSK_TARGET_NAME} diff --git a/src/time/time.h b/src/time/time.h index 2547a45..a27de2e 100644 --- a/src/time/time.h +++ b/src/time/time.h @@ -8,22 +8,10 @@ #pragma once #include "dusk.h" -#define TIME_STEP (1.0f / 60.0f) // 60 Ticks per second. +#define TIME_STEP (1.0f / 144.0f) // 60 Ticks per second. #ifndef TIME_FIXED #define TIME_FIXED 0 -#else - #ifndef TIME_PLATFORM_STEP - #error "TIME_PLATFORM_STEP must be defined when TIME_FIXED is enabled" - #endif - - #if TIME_PLATFORM_STEP <= 0.0f - #error "TIME_PLATFORM_STEP must be greater than zero" - #endif - - #if TIME_PLATFORM_STEP != TIME_STEP - #define TIME_FIXED 0 - #endif #endif typedef struct {