Fixing some performance
This commit is contained in:
@@ -8,11 +8,13 @@
|
|||||||
#include "npc.h"
|
#include "npc.h"
|
||||||
#include "rpg/entity/entity.h"
|
#include "rpg/entity/entity.h"
|
||||||
#include "rpg/overworld/worldpos.h"
|
#include "rpg/overworld/worldpos.h"
|
||||||
|
#include "time/time.h"
|
||||||
|
|
||||||
void npcPathInit(npc_t *npc) {
|
void npcPathInit(npc_t *npc) {
|
||||||
npcpath_t *path = &npc->moveData.path;
|
npcpath_t *path = &npc->moveData.path;
|
||||||
path->count = 0;
|
path->count = 0;
|
||||||
path->index = 0;
|
path->index = 0;
|
||||||
|
path->blockedTimer = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void npcPathMovement(entity_t *entity) {
|
void npcPathMovement(entity_t *entity) {
|
||||||
@@ -43,9 +45,14 @@ void npcPathMovement(entity_t *entity) {
|
|||||||
worldpos_t prevPos = entity->position;
|
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)) {
|
if(worldPosIsEqual(entity->position, prevPos)) {
|
||||||
|
// Blocked - wait before skipping so temporary blockers can move away.
|
||||||
|
path->blockedTimer += TIME.delta;
|
||||||
|
if(path->blockedTimer >= NPC_PATH_BLOCKED_TIMEOUT) {
|
||||||
path->index = (path->index + 1) % path->count;
|
path->index = (path->index + 1) % path->count;
|
||||||
|
path->blockedTimer = 0.0f;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
path->blockedTimer = 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,14 +10,14 @@
|
|||||||
|
|
||||||
#define TILE_SIZE_PIXELS 24
|
#define TILE_SIZE_PIXELS 24
|
||||||
|
|
||||||
#define CHUNK_WIDTH 32
|
#define CHUNK_WIDTH 16
|
||||||
#define CHUNK_HEIGHT 32
|
#define CHUNK_HEIGHT 14
|
||||||
#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 2
|
#define MAP_CHUNK_WIDTH 5
|
||||||
#define MAP_CHUNK_HEIGHT 2
|
#define MAP_CHUNK_HEIGHT 3
|
||||||
#define MAP_CHUNK_DEPTH 2
|
#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)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user