fix: save/load

This commit is contained in:
2025-10-06 19:27:45 +01:00
parent d9957eead1
commit 7b7f088116
3 changed files with 19 additions and 5 deletions

View File

@@ -106,9 +106,6 @@ void SaveWorld(M_Arena *arena, World *world) {
offset += sizeof(F32);
}
FS_FileWrite(file, world->propTypes, sizeof(World_PropType)*WORLD_PROP_TYPE_MAX, offset);
offset += sizeof(World_PropType)*WORLD_PROP_TYPE_MAX;
FS_FileWrite(file, &world->propCount, sizeof(U32), offset);
offset += sizeof(U32);
@@ -159,14 +156,14 @@ void LoadWorld(M_Arena *arena, World *world) {
world->props = M_ArenaPush(arena, World_Prop, .count=WORLD_PROP_MAX);
FS_FileRead(file, world->props, sizeof(World_Prop)*WORLD_PROP_MAX, offset);
offset += sizeof(World_Prop)*world->propCount;
offset += sizeof(World_Prop)*WORLD_PROP_MAX;
FS_FileRead(file, &world->hitboxCount, sizeof(U32), offset);
offset += sizeof(U32);
world->hitboxes = M_ArenaPush(arena, AABB, .count=WORLD_HITBOX_MAX);
FS_FileRead(file, world->hitboxes, sizeof(AABB)*WORLD_HITBOX_MAX, offset);
offset += sizeof(AABB)*world->hitboxCount;
offset += sizeof(AABB)*WORLD_HITBOX_MAX;
world->map = M_ArenaPush(arena, U32, .count=WORLD_MAP_MAX);
FS_FileRead(file, world->map, sizeof(U32)*WORLD_MAP_MAX, offset);
@@ -182,6 +179,14 @@ void GenerateNavMesh(M_Arena *arena, World *world) {
for(int i = 0; i < WORLD_MAP_MAX; i++) {
U32 x = (i % 96);
U32 y = (i / 96);
bool skip = false;
for(int hi = 0; hi < world->hitboxCount; hi++) {
if(AABB_Point(world->hitboxes[hi], V2F(x, y))) {
skip = true;
break;
}
}
if(skip) {continue;}
world->navMesh->nodes[world->navMesh->nodeCount].pos.x = x;
world->navMesh->nodes[world->navMesh->nodeCount].pos.y = y;
U32 cost = 20;
@@ -198,6 +203,14 @@ void GenerateNavMesh(M_Arena *arena, World *world) {
if(y+ny < 0 || y+ny > 49) {
continue;
}
// It's quad for loop time :D
for(int hi = 0; hi < world->hitboxCount; hi++) {
if(AABB_Point(world->hitboxes[hi], V2F(x+nx, y+ny))) {
skip = true;
break;
}
}
if(skip) {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;