testing some performance stuff

This commit is contained in:
2026-06-26 14:29:55 -05:00
parent e53775b97f
commit dd22d6424a
4 changed files with 29 additions and 19 deletions
+1 -1
View File
@@ -9,7 +9,7 @@
#include "time/time.h" #include "time/time.h"
#define ENTITY_ANIM_TURN_DURATION TIME_TICKS_TO_TIME(2) #define ENTITY_ANIM_TURN_DURATION TIME_TICKS_TO_TIME(2)
#define ENTITY_ANIM_WALK_DURATION TIME_TICKS_TO_TIME(10) #define ENTITY_ANIM_WALK_DURATION TIME_TICKS_TO_TIME(12)
#define ENTITY_ANIM_RUN_DURATION TIME_TICKS_TO_TIME(6) #define ENTITY_ANIM_RUN_DURATION TIME_TICKS_TO_TIME(6)
typedef struct entity_s entity_t; typedef struct entity_s entity_t;
+20 -10
View File
@@ -7,6 +7,7 @@
#include "npc.h" #include "npc.h"
#include "rpg/entity/entity.h" #include "rpg/entity/entity.h"
#include "rpg/overworld/worldpos.h"
void npcPathInit(npc_t *npc) { void npcPathInit(npc_t *npc) {
npcpath_t *path = &npc->moveData.path; npcpath_t *path = &npc->moveData.path;
@@ -19,23 +20,32 @@ void npcPathMovement(entity_t *entity) {
if(path->count == 0) return; if(path->count == 0) return;
if(!entityCanWalk(entity)) return; if(!entityCanWalk(entity)) return;
// Advance past any waypoints already reached (including the current one).
worldpos_t *target = &path->positions[path->index]; worldpos_t *target = &path->positions[path->index];
if(worldPosIsEqual(entity->position, *target)) {
// At this waypoint - advance to the next
if(
entity->position.x == target->x &&
entity->position.y == target->y
) {
path->index = (path->index + 1) % path->count; path->index = (path->index + 1) % path->count;
return; target = &path->positions[path->index];
// New target is the same tile - nothing to do this tick
if(worldPosIsEqual(entity->position, *target)) return;
} }
entitydir_t dir; entitydir_t dir;
if(entity->position.x != target->x) { worldpos_t pos = entity->position;
dir = entity->position.x < target->x ? ENTITY_DIR_EAST : ENTITY_DIR_WEST; if(pos.x != target->x) {
dir = pos.x < target->x ? ENTITY_DIR_EAST : ENTITY_DIR_WEST;
} else if(pos.y != target->y) {
dir = pos.y < target->y ? ENTITY_DIR_NORTH : ENTITY_DIR_SOUTH;
} else { } else {
dir = entity->position.y < target->y ? ENTITY_DIR_SOUTH : ENTITY_DIR_NORTH; // x and y match but z differs - step to correct z via ramp logic
dir = pos.z < target->z ? ENTITY_DIR_NORTH : ENTITY_DIR_SOUTH;
} }
worldpos_t prevPos = entity->position;
entityWalk(entity, dir); entityWalk(entity, dir);
// If entityWalk didn't move us (blocked), skip this waypoint to avoid
// getting stuck.
if(worldPosIsEqual(entity->position, prevPos)) {
path->index = (path->index + 1) % path->count;
}
} }
+5 -5
View File
@@ -10,15 +10,15 @@
#define TILE_SIZE_PIXELS 24 #define TILE_SIZE_PIXELS 24
#define CHUNK_WIDTH 16 #define CHUNK_WIDTH 32
#define CHUNK_HEIGHT 16 #define CHUNK_HEIGHT 32
#define CHUNK_DEPTH 8 #define CHUNK_DEPTH 8
#define CHUNK_TILE_COUNT (CHUNK_WIDTH * CHUNK_HEIGHT * CHUNK_DEPTH) #define CHUNK_TILE_COUNT (CHUNK_WIDTH * CHUNK_HEIGHT * CHUNK_DEPTH)
#define MAP_CHUNK_WIDTH 4 #define MAP_CHUNK_WIDTH 2
#define MAP_CHUNK_HEIGHT 4 #define MAP_CHUNK_HEIGHT 2
#define MAP_CHUNK_DEPTH 3 #define MAP_CHUNK_DEPTH 2
#define MAP_CHUNK_COUNT (MAP_CHUNK_WIDTH * MAP_CHUNK_HEIGHT * MAP_CHUNK_DEPTH) #define MAP_CHUNK_COUNT (MAP_CHUNK_WIDTH * MAP_CHUNK_HEIGHT * MAP_CHUNK_DEPTH)
#define ENTITY_COUNT 32 #define ENTITY_COUNT 32
+3 -3
View File
@@ -48,9 +48,9 @@ errorret_t rpgInit(void) {
npcpath_t *path = &npc->data.npc.moveData.path; npcpath_t *path = &npc->data.npc.moveData.path;
path->positions[0] = (worldpos_t){ 3, 3, 0 }; path->positions[0] = (worldpos_t){ 3, 3, 0 };
path->positions[1] = (worldpos_t){ 5, 3, 0 }; path->positions[1] = (worldpos_t){ 10, 3, 0 };
path->positions[2] = (worldpos_t){ 5, 5, 0 }; path->positions[2] = (worldpos_t){ 10, 10, 0 };
path->positions[3] = (worldpos_t){ 3, 5, 0 }; path->positions[3] = (worldpos_t){ 3, 10, 0 };
path->count = 4; path->count = 4;
// All Good! // All Good!