]> git.mcshandy.xyz Git - barrow_crawler/commitdiff
Loading and saving looks okay
authorRandy McShandy <randy@mcshandy.xyz>
Wed, 11 Jun 2025 03:40:18 +0000 (22:40 -0500)
committerRandy McShandy <randy@mcshandy.xyz>
Wed, 11 Jun 2025 03:40:18 +0000 (22:40 -0500)
bin/posix_BC
src/render_raylib.c
src/shaders/lighting.fs
src/structs.h
src/utils.c

index 097076403d474c4c454fc6013391db4a114bdeb5..f485cce99d866178deb167b981b21e446ecd4a5c 100755 (executable)
Binary files a/bin/posix_BC and b/bin/posix_BC differ
index 0aa05d923625af9246035252a2bb1bb707fc61e8..13903504825478922862109ad3b2654c0beb7ee2 100644 (file)
@@ -307,6 +307,16 @@ void control_game_mode()
                        playtime.cam.position = cam_reset_position;
                }
 
+    if (IsKeyReleased(KEY_F4))
+    {
+      const int success = save_game(playtime);
+    }
+
+    if (IsKeyReleased(KEY_F5))
+    {
+      const int success = load_game();
+    }
+
                if (IsKeyReleased(KEY_ONE))
                        orb_target_color = SKYBLUE;
                if (IsKeyReleased(KEY_TWO))
@@ -324,8 +334,9 @@ void control_game_mode()
                player_collision = GetRayCollisionMesh(player_collide_ray, barrow_model.meshes[0U], barrow_mat);
                playtime.player_rotation = player_rotation;
 
-               if (false && player_collision.hit && player_collision.distance < 1.30f)
+               if (player_collision.hit && player_collision.distance < 1.30f)
                {
+
                        playtime.player_velocity.x *= -1.05;
                }
                else
index 41357dc33e5a6208655c1bee511d502f42f00375..4d0f16354ba3b9628665a6697413332932cd02eb 100644 (file)
@@ -139,9 +139,9 @@ void main()
                lumWeights = vec4(1.0f) * lumWeight;
                lumWeights *= dot(finalColor, lumWeights);
 
-               //lighting_color = vec4(mix(orb_color.rgb * candle_weight, lumWeights.rgb, 0.2f), 1.0f);
+               lighting_color = vec4(mix(orb_color.rgb * candle_weight, lumWeights.rgb, 0.2f), 1.0f);
                //lighting_color = vec4(mix(candle_color.rgb * candle_weight, lumWeights.rgb, 0.4f), 1.0f);
-               //finalColor = finalColor * lighting_color;
+               finalColor = finalColor * lighting_color;
 
     float factor = 35.0;
     finalColor.r = round((finalColor.r) * factor) / factor;
@@ -151,6 +151,4 @@ void main()
                // All single color channel variations with this looks cool as FUCK
                // turns this into three levels going b-r-g
                //finalColor.b = 0.0f;
-
-    finalColor.a = 0.5f;
 }
index e2420cd0bf3315be858bc2575be7743278e2b0a3..35b54514233f3f58a3e25483666b47cb20b028bd 100644 (file)
@@ -112,5 +112,7 @@ extern int resource_state;
 
 //int generate_rd(int worker_count, RD_Opts active_opt, FVec2 **grid_buffer, IVec2 pgrid_size);
 void* generate_rd(void* args);
+int save_game(PlaytimeData playtime);
+int load_game();
 #endif //__RD_STRUCTS__
 
index 7961a91f958e5c9f0ce3d25d0fa1360eebc65d7b..cf765c9ef4972571fc2c2bf9c5b57cb32cdcba0e 100644 (file)
@@ -5,6 +5,8 @@
 
 #warning "TODO: I think these are only posix, check for alt platform replacements"
 #include <sys/param.h>
+#include <errno.h>
+#include <sys/stat.h>
 #include <time.h>
 
 #include "structs.h"
@@ -266,3 +268,49 @@ void* generate_rd(void* args)
        return 0;
 }
 
+int save_game(PlaytimeData playtime)
+{
+  int success = -1;
+  success = mkdir("./save", 0755);
+
+  if ((success == 0) || (errno == EEXIST))
+  {
+
+    FILE* save_file = fopen("./save/save.dat", "w");
+    char  buf[sizeof(PlaytimeData)];
+
+    memcpy(buf, (char*)&playtime, sizeof(PlaytimeData));
+
+    if (save_file)
+    {
+      success = fwrite(buf, sizeof(PlaytimeData), 1U, save_file);
+    }
+
+    success = fclose(save_file);
+  }
+
+  return success;
+}
+
+int load_game()
+{
+
+  int success = -1;
+
+  FILE* save_file = fopen("./save/save.dat", "r");
+
+  if (save_file)
+  {
+    char          buf[sizeof(PlaytimeData)];
+    const size_t  bytes_read = fread(buf, 1U, sizeof(PlaytimeData), save_file);
+
+    if (bytes_read == sizeof(PlaytimeData))
+    {
+      memcpy((char*)&playtime, buf, sizeof(PlaytimeData));
+      success = fclose(save_file);
+    }
+  }
+
+  return success;
+}
+