]> git.mcshandy.xyz Git - barrow_crawler/commitdiff
Start adding status and process management systems to support things like timed text...
authorRandy McShandy <randy@mcshandy.xyz>
Wed, 11 Jun 2025 04:46:27 +0000 (23:46 -0500)
committerRandy McShandy <randy@mcshandy.xyz>
Wed, 11 Jun 2025 04:46:27 +0000 (23:46 -0500)
bin/posix_BC
src/render_raylib.c
src/structs.c
src/structs.h

index f485cce99d866178deb167b981b21e446ecd4a5c..f2e806d35439e344e71b7844e86e6a1131541e01 100755 (executable)
Binary files a/bin/posix_BC and b/bin/posix_BC differ
index 13903504825478922862109ad3b2654c0beb7ee2..009b8c78217eec5a0c24eefd10029e3627983160 100644 (file)
@@ -1,7 +1,8 @@
 #include <stdio.h>
 #include <stddef.h>
 #include <raylib.h>
-#include <stdlib.h>
+#include <sys/param.h>
+#include <string.h>
 
 #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;
index cd14b10d22136da749c5f1dae0afc0dbfde7f5c5..877604c8415320b4ad68cbbef9fc8af850e3864d 100644 (file)
@@ -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;
 
index 35b54514233f3f58a3e25483666b47cb20b028bd..fb6d14cee33985879d901dbaaf7cd1e572fd01a0 100644 (file)
@@ -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;