From 3a2ff58e057126aadfffeecdfa3fff79d9ed42a7 Mon Sep 17 00:00:00 2001 From: Randy McShandy Date: Sat, 9 Aug 2025 20:25:25 -0500 Subject: [PATCH] Clean up old files on a New Game, and fix save loading. --- src/menufuncs.c | 18 +++++++++++------- src/utils.c | 23 ++++++++++++++++++++++- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/menufuncs.c b/src/menufuncs.c index 388e869..26273b8 100644 --- a/src/menufuncs.c +++ b/src/menufuncs.c @@ -5,6 +5,7 @@ #include #include "structs.h" +#include "utils.h" bool menu_action_MI_NONE() { return true; } @@ -14,9 +15,11 @@ bool menu_action_MI_NEW_GAME() bool response = false; resource_state = RENDER_RESOURCE_WAIT; + /* Clean up previous run's files and the old save. */ + cleanup_generated_files(); + pthread_create(&generation_info.generator_thread, NULL, generate_rd, NULL); pthread_detach(generation_info.generator_thread); - //pthread_join(generation_info.generator_thread, NULL); return response; } @@ -25,24 +28,25 @@ bool menu_action_MI_LOAD_GAME() { bool response = false; - ProcessInfo* process = &processes[SAVE_FILE_LOAD]; - process->state = WAITING; + ProcessInfo* process = &processes[SAVE_FILE_LOAD]; + process->state = WAITING; const int success = load_game(); if ((success == 0 ) && timers[STATUS_TEXT_FADE_TIME].time == 0.0) { process->state = FINISHED; + + memcpy(text_places[STATUS_TEXT_PLACE], process->info_text[process->state], 64); + timers[STATUS_TEXT_FADE_TIME].time = timers[STATUS_TEXT_FADE_TIME].max; + + resource_state = CONTROL_RESOURCE_READY; } else if (success != 0) { process->state = BAD; } - memcpy(text_places[STATUS_TEXT_PLACE], process->info_text[process->state], 64); - timers[STATUS_TEXT_FADE_TIME].time = timers[STATUS_TEXT_FADE_TIME].max; - - resource_state = CONTROL_RESOURCE_READY; return response; } diff --git a/src/utils.c b/src/utils.c index a168ed0..36c2faf 100644 --- a/src/utils.c +++ b/src/utils.c @@ -286,9 +286,30 @@ int save_game(PlaytimeData playtime) return success; } -int load_game() +int cleanup_generated_files() { + int success = -1; + + success |= delete_save(); + success |= remove("barrow.png"); + success |= remove("barrow_albedo.png"); + success |= remove("floor.png"); + success |= remove("floor_albedo.png"); + + return success; +} +int delete_save() +{ + int success = -1; + + success = remove("./save/save.dat"); + + return success; +} + +int load_game() +{ int success = -1; FILE* save_file = fopen("./save/save.dat", "r"); -- 2.49.0