feat (BROKEN): Save world code
This commit is contained in:
@@ -47,49 +47,35 @@ void RenderWorld(World *world, D_Context *draw) {
|
||||
if(npc.currentArea == world->player.currentArea) {
|
||||
V2f drawPos = AABB_Centre(npc.collision);
|
||||
D_Rect(draw, drawPos.x, drawPos.y, .texture = 1);
|
||||
D_Rect(draw, drawPos.x, drawPos.y, .texture = 0, .dim = npc.collision.size, .flags = D_RECT_IGNORE_ASPECT);
|
||||
}
|
||||
}
|
||||
if(world->bandit.currentArea == world->player.currentArea) {
|
||||
V2f drawPos = AABB_Centre(world->bandit.collision);
|
||||
D_Rect(draw, drawPos.x, drawPos.y, .texture = 9);
|
||||
D_Rect(draw, drawPos.x, drawPos.y, .texture = 0, .dim = world->bandit.collision.size, .flags = D_RECT_IGNORE_ASPECT);
|
||||
}
|
||||
D_Rect(draw, world->player.pos.x, world->player.pos.y, .texture = 1);
|
||||
}
|
||||
|
||||
void G_WorldDraw(G_State *game, World *world) {
|
||||
D_Context *draw = &game->draw;
|
||||
|
||||
(void) world;
|
||||
|
||||
U32 id = D_ImageHandle(&game->draw, S("tile_dirt_0"));
|
||||
U32 alt_id = D_ImageHandle(&game->draw, S("tile_dirt_1"));
|
||||
|
||||
for (F32 y = -128; y < 128; y += 1.0f) {
|
||||
for (F32 x = -128; x < 128; x += 1.0f) {
|
||||
U32 ux = (U32) x;
|
||||
U32 uy = (U32) y;
|
||||
|
||||
U32 tid = id;
|
||||
if ((ux % 11) == 0 || ((uy % 7) == 0)) {
|
||||
tid = alt_id;
|
||||
}
|
||||
|
||||
D_Rect(draw, x, y, .texture = tid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SaveWorld(M_Arena *arena, World *world) {
|
||||
printf("Saving world\n");
|
||||
World *saveWorld = M_ArenaPush(arena, World);
|
||||
NavMesh *saveNavMesh = M_ArenaPush(arena, NavMesh);
|
||||
M_CopySize(saveWorld, world, sizeof(World));
|
||||
M_CopySize(saveNavMesh, world->navMesh, sizeof(NavMesh));
|
||||
OS_Handle file =FS_FileOpen(S("world.sgdat"), FS_ACCESS_WRITE);
|
||||
FS_FileWrite(file, saveWorld, sizeof(World)+sizeof(NavMesh), 0);
|
||||
OS_Handle file = FS_FileOpen(S("world.sgdat"), FS_ACCESS_WRITE);
|
||||
FS_FileWrite(file, world, sizeof(World)+sizeof(NavMesh), 0);
|
||||
FS_FileWrite(file, world->navMesh, sizeof(World)+sizeof(NavMesh), sizeof(World));
|
||||
FS_FileClose(file);
|
||||
printf("Saved world :)\n");
|
||||
}
|
||||
|
||||
World *load(Str8 levelData) {
|
||||
World *LoadWorld(M_Arena *arena) {
|
||||
printf("loading world\n");
|
||||
OS_Handle file = FS_FileOpen(S("world.sgdat"), FS_ACCESS_WRITE);
|
||||
World *world = M_ArenaPush(arena, World);
|
||||
NavMesh *navMesh = M_ArenaPush(arena, NavMesh);
|
||||
FS_FileRead(file, world, sizeof(World), 0);
|
||||
FS_FileRead(file, navMesh, sizeof(NavMesh), sizeof(World));
|
||||
FS_FileClose(file);
|
||||
world->navMesh = navMesh;
|
||||
world->arena = arena;
|
||||
world->player.world = world;
|
||||
printf("loaded world\n");
|
||||
return world;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user