terrain

Real-time terrain generation using marching cubes
git clone git://git.christianermann.dev/terrain
Log | Files | Refs | README | LICENSE

commit 47f16aed016bab5f5ba6824102ba43a4a3aaf14b
parent aaa37db9d511804e41d0957522557ec227363d0f
Author: Christian Ermann <christianermann@gmail.com>
Date:   Sun, 29 May 2022 16:32:53 -0700

Added basic save system.

Diffstat:
Ainclude/save.h | 10++++++++++
Msrc/main.c | 10++++++++++
Asrc/save.c | 23+++++++++++++++++++++++
3 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/include/save.h b/include/save.h @@ -0,0 +1,10 @@ +#ifndef SAVE_H +#define SAVE_H + +#include "input.h" +#include "vec.h" + +int save(const Vec3 position); +int load(Vec3 position); + +#endif diff --git a/src/main.c b/src/main.c @@ -3,6 +3,7 @@ #include "chunk_manager.h" #include "input.h" #include "perlin.h" +#include "save.h" #include "shader.h" #include "glad/glad.h" @@ -138,11 +139,20 @@ int main(int argc, char** argv) ChunkManager_recenter(&chunk_manager, camera->position); ChunkManager_drawChunks(&chunk_manager, camera); + + loop_count += 1; + if (loop_count % 100000 == 0) + { + save(camera->position); + } glfwSwapBuffers(app->window); glfwPollEvents(); } + save(camera->position); + ChunkManager_free(&chunk_manager); App_free(app); } + diff --git a/src/save.c b/src/save.c @@ -0,0 +1,23 @@ +#include "save.h" + +#include <stdio.h> + +int save(const Vec3 position) +{ + FILE *fp; + fp = fopen("savedata", "w"); + if (!fp) return -1; + fwrite(position, 3, sizeof(float), fp); + fclose(fp); + return 0; +} + +int load(Vec3 position) +{ + FILE *fp; + fp = fopen("savedata", "r"); + if (!fp) return -1; + fread(position, sizeof(float), 3, fp); + fclose(fp); + return 0; +}