Merge branch 'debug/world_change' of yibble.dev:bulmanator/ld58 into debug

This commit is contained in:
2025-10-06 19:38:14 +01:00
5 changed files with 52 additions and 35022 deletions

View File

@@ -24,7 +24,6 @@
#include "game/impl/world.c"
#include "game/impl/npc.c"
#include "game/impl/bandit.c"
#include "game/testnavmesh.h"
int main(int argc, char **argv)
{
@@ -99,18 +98,18 @@ int main(int argc, char **argv)
//LoadWorld(arena, world);
game->world = world;
world->arena = arena;
world->navMesh = &TestNavMesh;
//world->navMesh = &TestNavMesh;
world->random = Random_Seed(29237489723847);
world->npcCount = 2;
world->npcCount = 127;
for(U32 i = 0; i < world->npcCount; i++) {
NPC *npc1 = &world->npcs[i];
npc1->collision.pos.x = 15;
npc1->collision.pos.y = 15;
NPC *npc1 = &world->npcs[i];
npc1->collision.pos.x = 0;
npc1->collision.pos.y = 0;
npc1->collision.size.x = 1;
npc1->collision.size.y = 2;
npc1->name = S("Matt");
npc1->mode = NPC_ACTION_WAITING;
npc1->currentArea = i;
npc1->currentArea = WORLD_AREA_OUTSIDE;
npc1->waitTime = 0;
npc1->maxWaitTime = 5;
npc1->currentNavNode = 0;
@@ -218,6 +217,7 @@ int main(int argc, char **argv)
world->propCount = 0;
world->props = M_ArenaPush(arena, World_Prop, .count=WORLD_PROP_MAX);
world->hitboxes = M_ArenaPush(arena, AABB, .count=WORLD_HITBOX_MAX);
GenerateNavMesh(arena, world);
}
game->editor.enabled = false;
game->editor.mode = G_EDITOR_MODE_TILE;
@@ -232,8 +232,6 @@ int main(int argc, char **argv)
bool running = true;
printf("%zu size in bytes\n", sizeof(TestNavMesh));
const int width = 1280;
const int height = 720;

View File

@@ -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) {
@@ -214,3 +224,36 @@ void LoadWorld(M_Arena *arena, World *world) {
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++;
}
}

View File

@@ -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;

File diff suppressed because it is too large Load Diff

View File

@@ -83,5 +83,6 @@ function void UpdateBandit(F32 delta, Bandit *bandit, World *world);
function void LoadWorld(M_Arena *arena, World *world);
function void SaveWorld(World *world);
function void GenerateNavMesh(M_Arena *arena, World *world);
#endif // LD_GAME_WORLD_H_