]> git.mcshandy.xyz Git - barrow_crawler/commitdiff
Moved basics into a consistent struct that can be targeted for serialization
authorRandy McShandy <randy@mcshandy.xyz>
Wed, 11 Jun 2025 01:17:34 +0000 (20:17 -0500)
committerRandy McShandy <randy@mcshandy.xyz>
Wed, 11 Jun 2025 01:17:34 +0000 (20:17 -0500)
bin/posix_BC
src/main.c
src/platforms/platform_posix.c
src/platforms/platform_win.c
src/render_raylib.c
src/structs.c
src/structs.h
src/utils.c

index b8910fd95a55b6b58dc105d25742a2afd834e1d4..097076403d474c4c454fc6013391db4a114bdeb5 100755 (executable)
Binary files a/bin/posix_BC and b/bin/posix_BC differ
index f511ccbe91b383bbe311c636b9636aadf584b164..6359d2b9bc056c5b176a28b7b02003ae626b4677 100755 (executable)
@@ -15,6 +15,8 @@ void print_rlog(int logLevel, const char* text, va_list args)
 int main(int argc, char** argv)
 {
 
+  playtime.room_count = 4;
+
 /* TODO: Clean this up and integrate into platform system. */
 #ifdef ENABLE_BARROWGEN
        barrow.max_iterations *= 1;
index d488be816935998206218a0bd0f0a1b9c5c2842b..729e0954ce1f502e050a6da1a2623d8085e1772c 100644 (file)
@@ -5,7 +5,6 @@
 
 worker_arg warg;
 int waiting_workers;
-int should_quit = 0;
 
 extern FVec2 ** grid;
 extern FVec2 ** grid_prime;
@@ -61,7 +60,7 @@ void* iterator(void* _arg)
 
        // One last synchronization so boss thread doesn't die early
        pthread_barrier_wait(&barrier);
-       should_quit = 1;
+       playtime.should_quit = 1;
 
        return _arg;
 }
index ced43c8d5a59cfa3098b5bf6a1a4000cd654babb..77cb6fad4b2069f6f291942992be74729163968b 100644 (file)
@@ -7,7 +7,6 @@
 
 worker_arg warg;
 int waiting_workers;
-int should_quit = 0;
 
 extern FVec2 ** grid;
 extern FVec2 ** grid_prime;
@@ -63,7 +62,7 @@ void* iterator(void* _arg)
 
        // One last synchronization so boss thread doesn't die early
        pthread_barrier_wait(&barrier);
-       should_quit = 1;
+       playtime.should_quit = 1;
 
        return _arg;
 }
index 774b7e5c6a6ca68a2491b1dc068009cf82be293f..0aa05d923625af9246035252a2bb1bb707fc61e8 100644 (file)
@@ -34,7 +34,6 @@
     m.m15
 
 Vector2 fscreen_dims;
-Camera3D cam;
 Vector3 cam_reset_position;
 Image barrow_image;
 Texture barrow_texture;
@@ -45,7 +44,7 @@ Mesh barrow_meshes[1U];
 // Absolute position of the center of the barrow model in the world
 Vector3 barrow_position;
 
-// Dead center of the barrow, used for camera spawn etc
+// Dead center of the barrow, used for playtime.camera spawn etc
 Vector3 map_center;
 
 // Scale factor from image -> model
@@ -93,9 +92,6 @@ int orb_directionality_shader_loc;
 Vector3 player_collide_point;
 Ray player_collide_ray;
 RayCollision player_collision;
-Vector3 player_velocity;
-Vector3 player_rotation;
-Vector3 player_angles;
 Vector3 map_center;
 
 float forward_speed                            = 0.015f;
@@ -143,15 +139,15 @@ NOTE: Only call inside a Raylib BeginDrawing() block!
 */
 void drawing_game_mode()
 {
-       Vector2 from_center_coords = (Vector2){cam.position.x, cam.position.z};
+       Vector2 from_center_coords = (Vector2){playtime.cam.position.x, playtime.cam.position.z};
        from_center_coords.x -= barrow_scale_factor.x/2;
        from_center_coords.y += barrow_scale_factor.z/2;
        /* -PI, PI */
-       player_angles.y = Vector2Angle(Vector2Normalize(from_center_coords), (Vector2){1.0f, 0.0f});
+       playtime.player_angles.y = Vector2Angle(Vector2Normalize(from_center_coords), (Vector2){1.0f, 0.0f});
 
        ClearBackground(BLACK);
 
-       BeginMode3D(cam);
+       BeginMode3D(playtime.cam);
        BeginShaderMode(shader);
 
   if (barrow_visible)
@@ -167,9 +163,9 @@ void drawing_game_mode()
 
        EndShaderMode();
 
-       for (int n = 0; n < room_count; n++)
+       for (int n = 0; n < playtime.room_count; n++)
        {
-               Vector3 each = room_positions[n];
+               Vector3 each = playtime.room_positions[n];
                DrawSphere(each, 0.1, RED);
        }
 
@@ -184,7 +180,7 @@ void drawing_game_mode()
 
        orb_normal_color = ColorNormalize(orb_color);
        orb_intensity = 84.0f; /* TODO: normalized distance from center, but lighting shader already has this. */
-       orb_directionality = player_angles;
+       orb_directionality = playtime.player_angles;
 
        DrawTextureEx(hand_01_texture, hand_position, hand_rotation, hand_scale, orb_color);
 
@@ -196,12 +192,12 @@ void drawing_game_mode()
                const int line_height = 32;
                DrawFPS(fscreen_dims.x - 80, 10);
                DrawTexturePro(floor_texture, minimap_src, minimap_dest, (Vector2){0.0f, 0.0f}, 0.0f, RAYWHITE);
-               DrawText(TextFormat(V3_FORMAT(cam.position), V3_UNROLL(cam.position)), 0, 128, 16, GREEN);
-               DrawText(TextFormat(V3_FORMAT(cam.target), V3_UNROLL(cam.target)), 0, 128+line_height, 16, GREEN);
-               DrawText(TextFormat(V3_FORMAT(player_angles), V3_UNROLL(player_angles)), 0, 128+(line_height*2), 16, GREEN);
+               DrawText(TextFormat(V3_FORMAT(playtime.cam.position), V3_UNROLL(playtime.cam.position)), 0, 128, 16, GREEN);
+               DrawText(TextFormat(V3_FORMAT(playtime.cam.target), V3_UNROLL(playtime.cam.target)), 0, 128+line_height, 16, GREEN);
+               DrawText(TextFormat(V3_FORMAT(playtime.player_angles), V3_UNROLL(playtime.player_angles)), 0, 128+(line_height*2), 16, GREEN);
                DrawText(TextFormat("ray hit:%d length %.2f" V3_FORMAT(player_collision.point), player_collision.hit, player_collision.distance, player_collision.point), 0, 128+(line_height*3), 16, GREEN);
                DrawText(TextFormat(V3_FORMAT(player_collide_ray.position), V3_UNROLL(player_collide_ray.position), V3_UNROLL(player_collide_ray.direction)), 0, 128+(line_height*4), 16, GREEN);
-               DrawText(TextFormat(V3_FORMAT(room_positions[0]), V3_UNROLL(room_positions[0])), 0, 128+(line_height*5), 16, GREEN);
+               DrawText(TextFormat(V3_FORMAT(playtime.room_positions[0]), V3_UNROLL(playtime.room_positions[0])), 0, 128+(line_height*5), 16, GREEN);
                DrawText(TextFormat(V3_FORMAT(barrow_position), V3_UNROLL(barrow_position)), 0, 128+(line_height*6), 16, GREEN);
                DrawText(TextFormat(V3_FORMAT(floor_position), V3_UNROLL(floor_position)), 0, 128+(line_height*7), 16, GREEN);
                DrawText(TextFormat(V3_FORMAT(barrow_size), V3_UNROLL(barrow_extent)), 0, 128+(line_height*8), 16, GREEN);
@@ -210,9 +206,7 @@ void drawing_game_mode()
 
 void drawing_resource_ready_mode()
 {
-       static int status_phase = 0;
        const float font_size = 32.0f;
-       const char format_string[] = "%s\n\n%3.2f%%";
        const char tribute_string[] = "This game is dedicated to the North American Muskrat, Ondatra zibethicus";
 
        ClearBackground(LIGHTGRAY);
@@ -260,37 +254,37 @@ void control_game_mode()
 {
        const float frame_time = GetFrameTime();
 
-       Vector3 new_player_velocity = player_velocity;
-       Vector3 new_player_rotation = player_rotation;
+       Vector3 player_velocity = playtime.player_velocity;
+       Vector3 player_rotation = playtime.player_rotation;
 
        KeyboardKey key = GetKeyPressed();
        do
        {
                if (IsKeyDown(KEY_W) || IsKeyDown(KEY_K))
                {
-                       new_player_velocity.x = forward_speed * frame_time;
+                       player_velocity.x = forward_speed * frame_time;
                }
                else if (IsKeyDown(KEY_S) || IsKeyDown(KEY_J))
                {
-                       new_player_velocity.x = -forward_speed * frame_time;
+                       player_velocity.x = -forward_speed * frame_time;
                }
 
                if (IsKeyDown(KEY_A) || IsKeyDown(KEY_H))
                {
-                       new_player_rotation.x = -rotate_speed * frame_time;
+                       player_rotation.x = -rotate_speed * frame_time;
                }
                else if (IsKeyDown(KEY_D) || IsKeyDown(KEY_L))
                {
-                       new_player_rotation.x = rotate_speed * frame_time;
+                       player_rotation.x = rotate_speed * frame_time;
                }
 
                if (IsKeyDown(KEY_T))
                {
-                       cam.target.y += DEG2RAD * 20.0;
+                       playtime.cam.target.y += DEG2RAD * 20.0;
                }
                else if (IsKeyDown(KEY_G))
                {
-                       cam.target.y -= DEG2RAD * 20.0;
+                       playtime.cam.target.y -= DEG2RAD * 20.0;
                }
 
     if (IsKeyReleased(KEY_B))
@@ -310,7 +304,7 @@ void control_game_mode()
 
                if (IsKeyReleased(KEY_Z))
                {
-                       cam.position = cam_reset_position;
+                       playtime.cam.position = cam_reset_position;
                }
 
                if (IsKeyReleased(KEY_ONE))
@@ -326,17 +320,17 @@ void control_game_mode()
 
                /* Collision test */
                /* Cast straight up */
-               player_collide_ray = (Ray){cam.position, vec3_up};
+               player_collide_ray = (Ray){playtime.cam.position, vec3_up};
                player_collision = GetRayCollisionMesh(player_collide_ray, barrow_model.meshes[0U], barrow_mat);
-               player_rotation = new_player_rotation;
+               playtime.player_rotation = player_rotation;
 
                if (false && player_collision.hit && player_collision.distance < 1.30f)
                {
-                       player_velocity.x *= -1.05;
+                       playtime.player_velocity.x *= -1.05;
                }
                else
                {
-                       player_velocity = new_player_velocity;
+                       playtime.player_velocity = player_velocity;
                }
 
                switch(key)
@@ -448,15 +442,15 @@ void wait_initialize_resources()
 
   Vector3 axis = map_center;
   float angle = DEG2RAD*0.0f;
-       for (int n = 0; n < room_count; n++)
+       for (int n = 0; n < playtime.room_count; n++)
        {
                // Scale room positions down from gentime positions
-               printf("room %d at %f %f %f\n", n, V3_UNROLL(room_positions[n]));
-    room_positions[n].x /= 4;
-    room_positions[n].z /= 4;
-    room_positions[n].y += 0.6f;
-    room_positions[n] = Vector3RotateByAxisAngle(room_positions[n], axis, angle);
-               printf("room moved to %f %f %f\n", V3_UNROLL(room_positions[n]));
+               printf("room %d at %f %f %f\n", n, V3_UNROLL(playtime.room_positions[n]));
+    playtime.room_positions[n].x /= 4;
+    playtime.room_positions[n].z /= 4;
+    playtime.room_positions[n].y += 0.6f;
+    playtime.room_positions[n] = Vector3RotateByAxisAngle(playtime.room_positions[n], axis, angle);
+               printf("room moved to %f %f %f\n", V3_UNROLL(playtime.room_positions[n]));
        }
 
        /* Grab the full transformation matrix of the upper barrow for use in collision */
@@ -483,13 +477,22 @@ void initialize_renderer()
 
        cam_reset_position = map_center;
        cam_reset_position.y = 1.0f;
-       cam                                             = (Camera3D){0};
-       cam.position            = cam_reset_position;
-       cam.target                      = cam.position;
-       cam.target.x   += 3.0f;
-       cam.up                                  = (Vector3){0.0f, 1.0f, 0.0f};
-       cam.fovy                                = 90.0f;
-       cam.projection  = CAMERA_PERSPECTIVE;
+
+  /* if not loading a save */
+  if (1)
+  {
+    playtime.cam             = (Camera3D){0};
+    playtime.cam.position    = cam_reset_position;
+    playtime.cam.target      = playtime.cam.position;
+    playtime.cam.target.x   += 3.0f;
+    playtime.cam.up          = (Vector3){0.0f, 1.0f, 0.0f};
+    playtime.cam.fovy        = 90.0f;
+    playtime.cam.projection  = CAMERA_PERSPECTIVE;
+  }
+  else
+  {
+    /* Load a save */
+  }
 
        /*
                 I know these are good at 60 fps. Per-second speed to move to FPS/independent movement.
@@ -541,29 +544,29 @@ void start_render_loop()
        {
                int func_idx = resource_state;
 
-               player_collide_point = cam.position;
+               player_collide_point = playtime.cam.position;
                //player_collide_point.y -= 1.0f;
                controlfuncs[func_idx]();
 
-               SetShaderValue(shader, cam_position_shader_loc, &cam.position, SHADER_UNIFORM_VEC3);
+               SetShaderValue(shader, cam_position_shader_loc, &playtime.cam.position, SHADER_UNIFORM_VEC3);
                SetShaderValue(shader, screen_dims_shader_loc, &fscreen_dims, SHADER_UNIFORM_VEC2);
                SetShaderValue(shader, map_center_shader_loc, &map_center, SHADER_UNIFORM_VEC3);
                SetShaderValue(shader, orb_color_shader_loc, &orb_normal_color, SHADER_UNIFORM_VEC4);
                SetShaderValue(shader, orb_intensity_shader_loc, &orb_intensity, SHADER_UNIFORM_FLOAT);
                SetShaderValue(shader, orb_directionality_shader_loc, &orb_directionality, SHADER_UNIFORM_VEC3);
 
-               UpdateCameraPro(&cam, player_velocity, player_rotation, 0.0f);
+               UpdateCameraPro(&playtime.cam, playtime.player_velocity, playtime.player_rotation, 0.0f);
                BeginDrawing();
                        renderfuncs[func_idx]();
                EndDrawing();
 
                const float frame_time = GetFrameTime();
                /* Decay forward velocity and rotation */
-               player_velocity.x = Lerp(player_velocity.x, 0.0f, forward_speed_decay * frame_time);
-               player_rotation.x = Lerp(player_rotation.x, 0.0f, rotate_speed_decay * frame_time);
+               playtime.player_velocity.x = Lerp(playtime.player_velocity.x, 0.0f, forward_speed_decay * frame_time);
+               playtime.player_rotation.x = Lerp(playtime.player_rotation.x, 0.0f, rotate_speed_decay * frame_time);
        }
 
-       should_quit = 1;
+       playtime.should_quit = 1;
 
        UnloadImage(barrow_image);
        UnloadTexture(barrow_texture);
index b2bc9b0a9935ffaf78fc832c31ad1c8989e06863..cd14b10d22136da749c5f1dae0afc0dbfde7f5c5 100644 (file)
@@ -70,6 +70,8 @@ const Mat3 laplacian_kernel =
        }
 };
 
+PlaytimeData playtime;
+
 const char chars[6] = {' ', ' ', ' ', '+', '#', '@'};
 const int max_chars = sizeof(chars) / sizeof(chars[0]) - 1;
 
@@ -81,6 +83,3 @@ const IVec2 img_export_scale = {.x = 2, .y = 2};
 float resource_generation_progress = 0.0f;
 int resource_state = 0;
 
-const int room_count = 4;
-Vector3 room_positions[16];
-
index 46d742d33be0fdb6f654247644594a2994259f54..e2420cd0bf3315be858bc2575be7743278e2b0a3 100644 (file)
@@ -5,6 +5,7 @@
 #define GRID_Y GRID_X
 
 #include <stddef.h>
+#include <stdint.h>
 #include <raylib.h>
 
 typedef enum
@@ -29,8 +30,8 @@ typedef struct
 
 typedef struct
 {
-       int x;
-       int y;
+       int32_t x;
+       int32_t y;
 } IVec2;
 
 typedef struct
@@ -78,7 +79,22 @@ typedef struct
        IVec2 grid_size;
 } GeneratorArgs;
 
-extern int should_quit;
+typedef struct
+{
+  uint32_t should_quit;
+
+  uint32_t room_count;
+  Vector3 room_positions[16];
+
+  Camera3D cam;
+
+  Vector3 player_velocity;
+  Vector3 player_rotation;
+  Vector3 player_angles;
+
+} PlaytimeData;
+
+extern PlaytimeData playtime;
 
 extern RD_Opts barrow;
 extern RD_Opts puffer;
@@ -94,9 +110,6 @@ extern const IVec2 img_export_scale;
 extern float resource_generation_progress;
 extern int resource_state;
 
-extern const int room_count;
-extern Vector3 room_positions[16];
-
 //int generate_rd(int worker_count, RD_Opts active_opt, FVec2 **grid_buffer, IVec2 pgrid_size);
 void* generate_rd(void* args);
 #endif //__RD_STRUCTS__
index 49ce354f9d84cebc517ba0445a69f51e23f6be8e..7961a91f958e5c9f0ce3d25d0fa1360eebc65d7b 100644 (file)
@@ -136,7 +136,7 @@ int initialize(int worker_count, RD_Opts active_opt)
        }
 
        /* Set up seed-points to create connected rooms */
-       const int seed_count = room_count;
+       const int seed_count = playtime.room_count;
        const float small_room_radius = 8.0f;
        const float phase = ((rand() % 360)/(float)360) * (M_PI*2);
 
@@ -151,10 +151,10 @@ int initialize(int worker_count, RD_Opts active_opt)
                int seed_y = ((sinf(angle) * (dist_offset + (grid_size.y/4.0f))) + (grid_size.y/2.0f));
 
     // Swap dimensions prepping for rendering
-               room_positions[n] = (Vector3){.x = seed_y, .y = 0.0f, .z = seed_x};
+               playtime.room_positions[n] = (Vector3){.x = seed_y, .y = 0.0f, .z = seed_x};
     // mirror this across axis
-    room_positions[n].z = grid_size.y - room_positions[n].z;
-               printf("Set room %d to {%f %f %f}\n", n, V3_UNROLL(room_positions[n]));
+    playtime.room_positions[n].z = grid_size.y - playtime.room_positions[n].z;
+               printf("Set room %d to {%f %f %f}\n", n, V3_UNROLL(playtime.room_positions[n]));
 
                grid[seed_x][seed_y].b = 1.0f;
                grid[seed_x][seed_y].c = 0.0f;
@@ -195,7 +195,7 @@ void* generate_rd(void* args)
        initialize(garg->worker_count, garg->rd_opts);
        start(garg->worker_count, garg->rd_opts);
 
-       while(!should_quit) {}
+       while(!playtime.should_quit) {}
 
        //printf("Opts: {\nIterations: %d\nTime delta: %f\nDiffA: %f\nDiffB: %f\nFeed: %f\nKill: %f\n\n}\n", active_opt.max_iterations, active_opt.delta_t, active_opt.diff_a, active_opt.diff_b, active_opt.feed, active_opt.kill);