testing some performance stuff
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
#include "time/time.h"
|
||||
|
||||
#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)
|
||||
|
||||
typedef struct entity_s entity_t;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "npc.h"
|
||||
#include "rpg/entity/entity.h"
|
||||
#include "rpg/overworld/worldpos.h"
|
||||
|
||||
void npcPathInit(npc_t *npc) {
|
||||
npcpath_t *path = &npc->moveData.path;
|
||||
@@ -19,23 +20,32 @@ void npcPathMovement(entity_t *entity) {
|
||||
if(path->count == 0) return;
|
||||
if(!entityCanWalk(entity)) return;
|
||||
|
||||
// Advance past any waypoints already reached (including the current one).
|
||||
worldpos_t *target = &path->positions[path->index];
|
||||
|
||||
// At this waypoint - advance to the next
|
||||
if(
|
||||
entity->position.x == target->x &&
|
||||
entity->position.y == target->y
|
||||
) {
|
||||
if(worldPosIsEqual(entity->position, *target)) {
|
||||
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;
|
||||
if(entity->position.x != target->x) {
|
||||
dir = entity->position.x < target->x ? ENTITY_DIR_EAST : ENTITY_DIR_WEST;
|
||||
worldpos_t pos = entity->position;
|
||||
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 {
|
||||
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);
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,15 +10,15 @@
|
||||
|
||||
#define TILE_SIZE_PIXELS 24
|
||||
|
||||
#define CHUNK_WIDTH 16
|
||||
#define CHUNK_HEIGHT 16
|
||||
#define CHUNK_WIDTH 32
|
||||
#define CHUNK_HEIGHT 32
|
||||
#define CHUNK_DEPTH 8
|
||||
|
||||
#define CHUNK_TILE_COUNT (CHUNK_WIDTH * CHUNK_HEIGHT * CHUNK_DEPTH)
|
||||
|
||||
#define MAP_CHUNK_WIDTH 4
|
||||
#define MAP_CHUNK_HEIGHT 4
|
||||
#define MAP_CHUNK_DEPTH 3
|
||||
#define MAP_CHUNK_WIDTH 2
|
||||
#define MAP_CHUNK_HEIGHT 2
|
||||
#define MAP_CHUNK_DEPTH 2
|
||||
#define MAP_CHUNK_COUNT (MAP_CHUNK_WIDTH * MAP_CHUNK_HEIGHT * MAP_CHUNK_DEPTH)
|
||||
|
||||
#define ENTITY_COUNT 32
|
||||
|
||||
+3
-3
@@ -48,9 +48,9 @@ errorret_t rpgInit(void) {
|
||||
|
||||
npcpath_t *path = &npc->data.npc.moveData.path;
|
||||
path->positions[0] = (worldpos_t){ 3, 3, 0 };
|
||||
path->positions[1] = (worldpos_t){ 5, 3, 0 };
|
||||
path->positions[2] = (worldpos_t){ 5, 5, 0 };
|
||||
path->positions[3] = (worldpos_t){ 3, 5, 0 };
|
||||
path->positions[1] = (worldpos_t){ 10, 3, 0 };
|
||||
path->positions[2] = (worldpos_t){ 10, 10, 0 };
|
||||
path->positions[3] = (worldpos_t){ 3, 10, 0 };
|
||||
path->count = 4;
|
||||
|
||||
// All Good!
|
||||
|
||||
Reference in New Issue
Block a user