Merge branch 'main' of yibble.dev:bulmanator/ld58
This commit is contained in:
@@ -64,16 +64,6 @@ void RenderWorld(World *world, D_Context *draw) {
|
||||
);
|
||||
}
|
||||
}
|
||||
for (U32 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) {
|
||||
@@ -124,6 +114,8 @@ void SaveWorld(World *world) {
|
||||
|
||||
WRITEN(world->map, WORLD_MAP_MAX);
|
||||
|
||||
WRITE(world->portalCount);
|
||||
WRITEN(world->portals, WORLD_PORTAL_MAX);
|
||||
FS_FileClose(file);
|
||||
|
||||
printf("--- World Saved ---\n");
|
||||
@@ -197,14 +189,14 @@ void LoadWorld(M_Arena *arena, World *world) {
|
||||
//
|
||||
{
|
||||
U32 n_hitbox = *(U32 *) base; base += 4;
|
||||
AABB *boxes = (AABB *) base;
|
||||
World_Hitbox *boxes = (World_Hitbox *) base;
|
||||
|
||||
world->hitboxCount = n_hitbox;
|
||||
world->hitboxes = M_ArenaPush(arena, AABB, .count = WORLD_HITBOX_MAX);
|
||||
world->hitboxes = M_ArenaPush(arena, World_Hitbox, .count = WORLD_HITBOX_MAX);
|
||||
|
||||
M_CopySize(world->hitboxes, boxes, n_hitbox * sizeof(AABB));
|
||||
M_CopySize(world->hitboxes, boxes, n_hitbox * sizeof(World_Hitbox));
|
||||
|
||||
base += (WORLD_HITBOX_MAX * sizeof(AABB));
|
||||
base += (WORLD_HITBOX_MAX * sizeof(World_Hitbox));
|
||||
}
|
||||
|
||||
// Map
|
||||
@@ -217,11 +209,24 @@ void LoadWorld(M_Arena *arena, World *world) {
|
||||
|
||||
base += (WORLD_MAP_MAX * sizeof(U32));
|
||||
}
|
||||
{
|
||||
U32 n_portals = *(U32 *) base; base += 4;
|
||||
World_Portal *portals = (World_Portal *) base;
|
||||
|
||||
world->portalCount = n_portals;
|
||||
world->portals = M_ArenaPush(arena, World_Portal, .count = WORLD_PORTAL_MAX);
|
||||
|
||||
M_CopySize(world->portals, portals, n_portals * sizeof(World_Portal));
|
||||
|
||||
base += (WORLD_PORTAL_MAX * sizeof(World_Portal));
|
||||
}
|
||||
|
||||
if (base != (data.data + data.count)) {
|
||||
printf("--- OFFSET MISMATCH ---\n");
|
||||
}
|
||||
|
||||
printf("loaded world\n");
|
||||
|
||||
printf(" - %d props\n", world->propCount);
|
||||
printf(" - %d hitboxes\n", world->hitboxCount);
|
||||
|
||||
@@ -237,7 +242,7 @@ void GenerateNavMesh(M_Arena *arena, World *world) {
|
||||
U32 y = (i / 96);
|
||||
bool skip = false;
|
||||
for(U32 hi = 0; hi < world->hitboxCount; hi++) {
|
||||
if(AABB_Point(world->hitboxes[hi], V2F((F32) x, (F32) y))) {
|
||||
if(AABB_Point(world->hitboxes[hi].box, V2F((F32) x, (F32) y))) {
|
||||
skip = true;
|
||||
break;
|
||||
}
|
||||
@@ -245,14 +250,10 @@ void GenerateNavMesh(M_Arena *arena, World *world) {
|
||||
if(skip) {continue;}
|
||||
world->navMesh->nodes[world->navMesh->nodeCount].pos.x = cast(F32) x;
|
||||
world->navMesh->nodes[world->navMesh->nodeCount].pos.y = cast(F32) 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(nx==0 && ny==0) {continue;}
|
||||
if(x+nx < 0 || x+nx > 95) {
|
||||
continue;
|
||||
}
|
||||
@@ -261,19 +262,47 @@ void GenerateNavMesh(M_Arena *arena, World *world) {
|
||||
}
|
||||
// It's quad for loop time :D
|
||||
for(U32 hi = 0; hi < world->hitboxCount; hi++) {
|
||||
if(AABB_Point(world->hitboxes[hi], V2F((F32) (x + nx), (F32) (y + ny)))) {
|
||||
if(AABB_Point(world->hitboxes[hi].box, V2F((F32) (x + nx), (F32) (y + ny)))) {
|
||||
skip = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(skip) {continue;}
|
||||
U32 index = x+nx + (y+ny)*96;
|
||||
U32 nCount = world->navMesh->nodeCount;
|
||||
S32 index = -1;
|
||||
for (U32 ohgod = 0; ohgod < nCount; ohgod++) {
|
||||
if(world->navMesh->nodes[ohgod].pos.x == nx+x&& world->navMesh->nodes[ohgod].pos.y == y+ny) {
|
||||
index=ohgod;
|
||||
break;
|
||||
}
|
||||
}
|
||||
F32 cost = 20;
|
||||
if(ny+nx == 2) {
|
||||
cost = 40;
|
||||
};
|
||||
if(Str8_Equal(world->tileTypes[world->map[i]].tag, S("path_middle"), STR8_EQUAL_IGNORE_CASE)) {
|
||||
cost = 1;
|
||||
if(Abs(ny+nx) == 2) {
|
||||
cost = 4;
|
||||
};
|
||||
}
|
||||
if(index < 0) {continue;}
|
||||
skip |= (index > (S32) nCount);
|
||||
if(skip) {continue;}
|
||||
world->navMesh->nodes[nCount].connections[world->navMesh->nodes[nCount].connectionCount].NodeIndex = index;
|
||||
world->navMesh->nodes[nCount].connections[world->navMesh->nodes[nCount].connectionCount].Cost = cast(F32) cost;
|
||||
world->navMesh->nodes[nCount].connections[world->navMesh->nodes[nCount].connectionCount].Cost = cost;
|
||||
world->navMesh->nodes[index].connections[world->navMesh->nodes[index].connectionCount].NodeIndex = nCount;
|
||||
world->navMesh->nodes[index].connections[world->navMesh->nodes[index].connectionCount].Cost = cost;
|
||||
world->navMesh->nodes[nCount].connectionCount++;
|
||||
world->navMesh->nodes[index].connectionCount++;
|
||||
}
|
||||
}
|
||||
world->navMesh->nodeCount++;
|
||||
}
|
||||
for(U32 i = 0; i < world->npcCount; i++) {
|
||||
world->npcs[i].mode = NPC_ACTION_WAITING;
|
||||
world->npcs[i].maxWaitTime = Random_F32(&world->random, 20, 140);
|
||||
world->npcs[i].waitTime = 0;
|
||||
world->npcs[i].currentNavNode=0;
|
||||
world->npcs[i].pathIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user