feat: save world written

This commit is contained in:
2025-10-06 01:10:44 +01:00
parent 64a84e3a8d
commit 2f52bb3097
3 changed files with 24 additions and 0 deletions

View File

@@ -75,6 +75,7 @@ int main(int argc, char **argv)
game->draw.camera = camera;
World *world = M_ArenaPush(arena, World);
game->world = world;
world->arena = arena;
world->random = Random_Seed(29237489723847);
world->npcCount = 2;
for(U32 i = 0; i < world->npcCount; i++) {

View File

@@ -3,6 +3,8 @@
#include "../player.h"
#include "../aabb.h"
#include <SDL3/SDL_events.h>
#include <SDL3/SDL_keycode.h>
#include <SDL3/SDL_oldnames.h>
void UpdateWorld(F32 delta, World *world)
{
@@ -30,6 +32,9 @@ void UpdateNPCs(F32 delta, World *world)
void ProcessEvents(SDL_Event *event, World *world)
{
PlayerInput(event, &world->player);
if(event->type == SDL_EVENT_KEY_DOWN && event->key.key == SDLK_F5){
SaveWorld(world->arena, world);
}
}
void RenderWorld(World *world, D_Context *draw) {
@@ -69,3 +74,16 @@ void G_WorldDraw(G_State *game, World *world) {
}
}
}
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);
}
World *load(Str8 levelData) {
}

View File

@@ -16,6 +16,8 @@ typedef struct World World;
#include "bandit.h"
struct World {
//// Utils
M_Arena *arena;
//// Static stuff
NavMesh *navMesh;
Random random;
@@ -43,4 +45,7 @@ function void UpdateNPCs(F32 delta, World *world);
function void UpdateNPC(F32 delta, NPC *npc, World *world);
function void UpdateBandit(F32 delta, Bandit *bandit, World *world);
function World *LoadWorld(Str8 levelData);
function void SaveWorld(M_Arena *arena, World *world);
#endif // LD_GAME_WORLD_H_