feat (BROKEN): Save world code
This commit is contained in:
@@ -95,7 +95,7 @@ int main(int argc, char **argv)
|
|||||||
camera->farp = 1000.0f;
|
camera->farp = 1000.0f;
|
||||||
|
|
||||||
game->draw.camera = camera;
|
game->draw.camera = camera;
|
||||||
World *world = M_ArenaPush(arena, World);
|
World *world = LoadWorld(arena);
|
||||||
game->world = world;
|
game->world = world;
|
||||||
world->arena = arena;
|
world->arena = arena;
|
||||||
world->random = Random_Seed(29237489723847);
|
world->random = Random_Seed(29237489723847);
|
||||||
@@ -127,7 +127,6 @@ int main(int argc, char **argv)
|
|||||||
badman->pointsOfInterest[0] = 937;
|
badman->pointsOfInterest[0] = 937;
|
||||||
badman->pointsOfInterest[1] = 12;
|
badman->pointsOfInterest[1] = 12;
|
||||||
|
|
||||||
world->navMesh = &TestNavMesh;
|
|
||||||
world->npcPOI[0] = 100;
|
world->npcPOI[0] = 100;
|
||||||
world->player.world = world;
|
world->player.world = world;
|
||||||
world->player.pos.x = 0;
|
world->player.pos.x = 0;
|
||||||
@@ -214,8 +213,6 @@ int main(int argc, char **argv)
|
|||||||
// D_Rect(&game->draw, -8.0f, 0.0f, .texture = 2, .scale = 2.0f);
|
// D_Rect(&game->draw, -8.0f, 0.0f, .texture = 2, .scale = 2.0f);
|
||||||
// D_Rect(&game->draw, 6.0f, 0.0f, .texture = 3);
|
// D_Rect(&game->draw, 6.0f, 0.0f, .texture = 3);
|
||||||
|
|
||||||
G_WorldDraw(game, game->world);
|
|
||||||
|
|
||||||
R2f aframe = D_AnimationFrame(&animation);
|
R2f aframe = D_AnimationFrame(&animation);
|
||||||
D_Rect(&game->draw, 0, 0, .texture = animation.id, .uv = aframe, .flags = D_RECT_UV_ASPECT);
|
D_Rect(&game->draw, 0, 0, .texture = animation.id, .uv = aframe, .flags = D_RECT_UV_ASPECT);
|
||||||
|
|
||||||
|
|||||||
@@ -47,49 +47,35 @@ void RenderWorld(World *world, D_Context *draw) {
|
|||||||
if(npc.currentArea == world->player.currentArea) {
|
if(npc.currentArea == world->player.currentArea) {
|
||||||
V2f drawPos = AABB_Centre(npc.collision);
|
V2f drawPos = AABB_Centre(npc.collision);
|
||||||
D_Rect(draw, drawPos.x, drawPos.y, .texture = 1);
|
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) {
|
if(world->bandit.currentArea == world->player.currentArea) {
|
||||||
V2f drawPos = AABB_Centre(world->bandit.collision);
|
V2f drawPos = AABB_Centre(world->bandit.collision);
|
||||||
D_Rect(draw, drawPos.x, drawPos.y, .texture = 9);
|
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);
|
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) {
|
void SaveWorld(M_Arena *arena, World *world) {
|
||||||
printf("Saving world\n");
|
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);
|
OS_Handle file = FS_FileOpen(S("world.sgdat"), FS_ACCESS_WRITE);
|
||||||
FS_FileWrite(file, saveWorld, sizeof(World)+sizeof(NavMesh), 0);
|
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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ function void UpdateNPCs(F32 delta, World *world);
|
|||||||
function void UpdateNPC(F32 delta, NPC *npc, World *world);
|
function void UpdateNPC(F32 delta, NPC *npc, World *world);
|
||||||
function void UpdateBandit(F32 delta, Bandit *bandit, World *world);
|
function void UpdateBandit(F32 delta, Bandit *bandit, World *world);
|
||||||
|
|
||||||
function World *LoadWorld(Str8 levelData);
|
function World *LoadWorld(M_Arena *arena);
|
||||||
function void SaveWorld(M_Arena *arena, World *world);
|
function void SaveWorld(M_Arena *arena, World *world);
|
||||||
|
|
||||||
#endif // LD_GAME_WORLD_H_
|
#endif // LD_GAME_WORLD_H_
|
||||||
|
|||||||
Reference in New Issue
Block a user