fix: save/load
This commit is contained in:
@@ -284,6 +284,7 @@ int main(int argc, char **argv)
|
|||||||
Abs(game->editor.cursor.y-game->editor.dragStart.y)
|
Abs(game->editor.cursor.y-game->editor.dragStart.y)
|
||||||
);
|
);
|
||||||
game->world->hitboxCount++;
|
game->world->hitboxCount++;
|
||||||
|
GenerateNavMesh(game->arena, game->world);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -106,9 +106,6 @@ void SaveWorld(M_Arena *arena, World *world) {
|
|||||||
offset += sizeof(F32);
|
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);
|
FS_FileWrite(file, &world->propCount, sizeof(U32), offset);
|
||||||
offset += sizeof(U32);
|
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);
|
world->props = M_ArenaPush(arena, World_Prop, .count=WORLD_PROP_MAX);
|
||||||
FS_FileRead(file, world->props, sizeof(World_Prop)*WORLD_PROP_MAX, offset);
|
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);
|
FS_FileRead(file, &world->hitboxCount, sizeof(U32), offset);
|
||||||
offset += sizeof(U32);
|
offset += sizeof(U32);
|
||||||
|
|
||||||
world->hitboxes = M_ArenaPush(arena, AABB, .count=WORLD_HITBOX_MAX);
|
world->hitboxes = M_ArenaPush(arena, AABB, .count=WORLD_HITBOX_MAX);
|
||||||
FS_FileRead(file, world->hitboxes, sizeof(AABB)*WORLD_HITBOX_MAX, offset);
|
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);
|
world->map = M_ArenaPush(arena, U32, .count=WORLD_MAP_MAX);
|
||||||
FS_FileRead(file, world->map, sizeof(U32)*WORLD_MAP_MAX, offset);
|
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++) {
|
for(int i = 0; i < WORLD_MAP_MAX; i++) {
|
||||||
U32 x = (i % 96);
|
U32 x = (i % 96);
|
||||||
U32 y = (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.x = x;
|
||||||
world->navMesh->nodes[world->navMesh->nodeCount].pos.y = y;
|
world->navMesh->nodes[world->navMesh->nodeCount].pos.y = y;
|
||||||
U32 cost = 20;
|
U32 cost = 20;
|
||||||
@@ -198,6 +203,14 @@ void GenerateNavMesh(M_Arena *arena, World *world) {
|
|||||||
if(y+ny < 0 || y+ny > 49) {
|
if(y+ny < 0 || y+ny > 49) {
|
||||||
continue;
|
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 index = x+nx + (y+ny)*96;
|
||||||
U32 nCount = world->navMesh->nodeCount;
|
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].NodeIndex = index;
|
||||||
|
|||||||
BIN
code/world.sgdat
BIN
code/world.sgdat
Binary file not shown.
Reference in New Issue
Block a user