From: Randy McShandy Date: Wed, 11 Jun 2025 04:46:27 +0000 (-0500) Subject: Start adding status and process management systems to support things like timed text... X-Git-Url: http://git.mcshandy.xyz/gitweb.cgi?a=commitdiff_plain;h=ce7200056d5de40d97fcf5d91bbe83a4c0f2ed80;p=barrow_crawler Start adding status and process management systems to support things like timed text reports, etc. EOD --- diff --git a/bin/posix_BC b/bin/posix_BC index f485cce..f2e806d 100755 Binary files a/bin/posix_BC and b/bin/posix_BC differ diff --git a/src/render_raylib.c b/src/render_raylib.c index 1390350..009b8c7 100644 --- a/src/render_raylib.c +++ b/src/render_raylib.c @@ -1,7 +1,8 @@ #include #include #include -#include +#include +#include #if POSIX_BC==1 #define RAYMATH_IMPLEMENTATION @@ -187,7 +188,13 @@ void drawing_game_mode() Rectangle minimap_dest = {.width = 64.0f*img_export_scale.x, .height = 64.0f*img_export_scale.y, .x = 0.0f, .y = 0.0f}; Rectangle minimap_src = {.width = barrow_texture.width, .height = barrow_texture.height, .x = 0.0f, .y = 0.0f}; - if(map_visible) + if (timers[E_TEXT_FADE_TIME].time > 0.0f) + { + const char* text = text_places[E_STATUS_TEXT_PLACE]; + DrawText(TextFormat("%s", text), 0, screen_dims.y - 32, 32, GREEN); + } + + if (map_visible) { const int line_height = 32; DrawFPS(fscreen_dims.x - 80, 10); @@ -309,12 +316,41 @@ void control_game_mode() if (IsKeyReleased(KEY_F4)) { + processes[E_SAVE_FILE_SAVE].progress = 0.0; + processes[E_SAVE_FILE_SAVE].state = E_WAITING; + const int success = save_game(playtime); + timers[E_TEXT_FADE_TIME].time = timers[E_TEXT_FADE_TIME].max; + + if (success == 0 && timers[E_TEXT_FADE_TIME].time == 0.0f) + { + processes[E_SAVE_FILE_SAVE].state = E_FINISHED; + } + else if (success != 0) + { + processes[E_SAVE_FILE_SAVE].state = E_BAD; + } } if (IsKeyReleased(KEY_F5)) { + ProcessInfo* process = &processes[E_SAVE_FILE_LOAD]; + process->progress = 0.0; + process->state = E_WAITING; + const int success = load_game(); + timers[E_TEXT_FADE_TIME].time = timers[E_TEXT_FADE_TIME].max; + + if (success == 0 && timers[E_TEXT_FADE_TIME].time == 0.0f) + { + process->state = E_FINISHED; + } + else if (success != 0) + { + process->state = E_BAD; + } + + memcpy(text_places[E_STATUS_TEXT_PLACE], process->info_text[process->state], 64); } if (IsKeyReleased(KEY_ONE)) @@ -336,7 +372,6 @@ void control_game_mode() if (player_collision.hit && player_collision.distance < 1.30f) { - playtime.player_velocity.x *= -1.05; } else @@ -543,6 +578,17 @@ void initialize_prerenderer() } } +void update_timers() +{ + for (int t = 0; t < E_STATUS_TIMERS; t++) + { + if (timers[t].time > 0.0f) + { + timers[t].time = MAX(timers[t].time - (((float)1.0/target_fps) * 1000.0f), 0.0f); + } + } +} + void start_render_loop() { initialize_prerenderer(); @@ -553,6 +599,8 @@ void start_render_loop() SetTargetFPS(target_fps); while (!WindowShouldClose()) { + update_timers(); + int func_idx = resource_state; player_collide_point = playtime.cam.position; diff --git a/src/structs.c b/src/structs.c index cd14b10..877604c 100644 --- a/src/structs.c +++ b/src/structs.c @@ -72,6 +72,21 @@ const Mat3 laplacian_kernel = PlaytimeData playtime; +TimedStatus timers[E_STATUS_TIMERS] = +{ + /* timer time max */ + /* E_TEXT_FADE_TIME */ { 0.0f, 4000.0f } +}; + +ProcessInfo processes[E_PROCESSES] = +{ + /* Process { STATE Progress, { E_UNKNOWN, E_GOOD, E_BAD, E_WAITING, E_FINISHED } } */ + /* E_SAVE_FILE_LOAD */ { E_UNKNOWN, 0.0f, { "", "", "Failed to load save.", "Loading...", "Loaded" } }, + /* E_SAVE_FILE_SAVE */ { E_UNKNOWN, 0.0f, { "", "", "Failed to create save.", "Saving...", "Saved" } } +}; + +char text_places[E_TEXT_PLACES][64]; + const char chars[6] = {' ', ' ', ' ', '+', '#', '@'}; const int max_chars = sizeof(chars) / sizeof(chars[0]) - 1; diff --git a/src/structs.h b/src/structs.h index 35b5451..fb6d14c 100644 --- a/src/structs.h +++ b/src/structs.h @@ -94,8 +94,57 @@ typedef struct } PlaytimeData; +typedef struct +{ + float time; + float max; +} TimedStatus; + +typedef enum +{ + E_TEXT_FADE_TIME = 0, + E_STATUS_TIMERS +} eTimerStatus; + +typedef enum +{ + E_UNKNOWN = 0, + E_GOOD, + E_BAD, + E_WAITING, + E_FINISHED, + E_STATES +} eState; + +typedef enum +{ + E_SAVE_FILE_LOAD = 0, + E_SAVE_FILE_SAVE, + + /* Resource load and generation here eventually too */ + + E_PROCESSES +} eProcess; + +typedef struct +{ + eState state; + float progress; + char info_text[E_STATES][64]; +} ProcessInfo; + +typedef enum +{ + E_STATUS_TEXT_PLACE = 0, + E_TEXT_PLACES, +} eTextPlaces; + extern PlaytimeData playtime; +extern ProcessInfo processes[E_PROCESSES]; +extern TimedStatus timers[E_STATUS_TIMERS]; +extern char text_places[E_TEXT_PLACES][64]; + extern RD_Opts barrow; extern RD_Opts puffer; extern RD_Opts worms;