From: Randy McShandy Date: Sun, 10 Aug 2025 01:25:25 +0000 (-0500) Subject: Clean up old files on a New Game, and fix save loading. X-Git-Url: http://git.mcshandy.xyz/gitweb.cgi?a=commitdiff_plain;h=3a2ff58e057126aadfffeecdfa3fff79d9ed42a7;p=barrow_crawler Clean up old files on a New Game, and fix save loading. --- 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");