feat: Nav mesh generation
This commit is contained in:
@@ -61,6 +61,16 @@ void RenderWorld(World *world, D_Context *draw) {
|
||||
);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < world->navMesh->nodeCount; i++) {
|
||||
NavNode n = world->navMesh->nodes[i];
|
||||
D_Rect(
|
||||
draw,
|
||||
n.pos.x,
|
||||
n.pos.y,
|
||||
.texture = 0,
|
||||
.scale = 0.2f,
|
||||
);
|
||||
}
|
||||
for(U32 i = 0; i < world->npcCount; i++) {
|
||||
NPC npc = world->npcs[i];
|
||||
if(npc.currentArea == world->player.currentArea) {
|
||||
@@ -165,3 +175,36 @@ void LoadWorld(M_Arena *arena, World *world) {
|
||||
FS_FileClose(file);
|
||||
printf("loaded world\n");
|
||||
}
|
||||
|
||||
void GenerateNavMesh(M_Arena *arena, World *world) {
|
||||
world->navMesh = M_ArenaPush(arena, NavMesh);
|
||||
world->navMesh->nodeCount = 0;
|
||||
for(int i = 0; i < WORLD_MAP_MAX; i++) {
|
||||
U32 x = (i % 96);
|
||||
U32 y = (i / 96);
|
||||
world->navMesh->nodes[world->navMesh->nodeCount].pos.x = x;
|
||||
world->navMesh->nodes[world->navMesh->nodeCount].pos.y = y;
|
||||
U32 cost = 20;
|
||||
if(Str8_Equal(world->tileTypes[world->map[i]].tag, S("path_middle"), STR8_EQUAL_IGNORE_CASE)) {
|
||||
cost = 10;
|
||||
}
|
||||
world->navMesh->nodes[world->navMesh->nodeCount].connectionCount = 0;
|
||||
for(int nx = -1; nx < 2; nx++){
|
||||
for(int ny = -1; ny < 2; ny++){
|
||||
if((nx==ny) && nx==0) {continue;}
|
||||
if(x+nx < 0 || x+nx > 95) {
|
||||
continue;
|
||||
}
|
||||
if(y+ny < 0 || y+ny > 49) {
|
||||
continue;
|
||||
}
|
||||
U32 index = x+nx + (y+ny)*96;
|
||||
U32 nCount = world->navMesh->nodeCount;
|
||||
world->navMesh->nodes[nCount].connections[world->navMesh->nodes[nCount].connectionCount].NodeIndex = index;
|
||||
world->navMesh->nodes[nCount].connections[world->navMesh->nodes[nCount].connectionCount].Cost = cost;
|
||||
world->navMesh->nodes[nCount].connectionCount++;
|
||||
}
|
||||
}
|
||||
world->navMesh->nodeCount++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#define NAV_MAX_PATH 1024
|
||||
#define NAV_MAX_CONNECTIONS 8
|
||||
#define NAV_MAX_NODES 4096
|
||||
#define NAV_MAX_NODES 4800
|
||||
|
||||
typedef struct NavNode NavNode;
|
||||
|
||||
|
||||
35012
code/game/testnavmesh.h
35012
code/game/testnavmesh.h
File diff suppressed because it is too large
Load Diff
@@ -83,5 +83,6 @@ function void UpdateBandit(F32 delta, Bandit *bandit, World *world);
|
||||
|
||||
function void LoadWorld(M_Arena *arena, World *world);
|
||||
function void SaveWorld(M_Arena *arena, World *world);
|
||||
function void GenerateNavMesh(M_Arena *arena, World *world);
|
||||
|
||||
#endif // LD_GAME_WORLD_H_
|
||||
|
||||
Reference in New Issue
Block a user