]> git.mcshandy.xyz Git - barrow_crawler/commitdiff
WIP: Adjust generation states to supprt New Game button
authorRandy McShandy <randy@mcshandy.xyz>
Mon, 16 Jun 2025 02:49:43 +0000 (21:49 -0500)
committerRandy McShandy <randy@mcshandy.xyz>
Mon, 16 Jun 2025 02:49:43 +0000 (21:49 -0500)
bin/posix_BC
src/main.c
src/menufuncs.c
src/platforms/platform_posix.c
src/render_raylib.c
src/structs.h
src/utils.c

index 0ce3cc5eebdaf79b0ea2b08d02fc2573a1d50853..b8e1ba670ecf18583cf2cccd168b3054e1b48019 100755 (executable)
Binary files a/bin/posix_BC and b/bin/posix_BC differ
index c0949a1125932e4e3b4b768a6432c647876e48f1..cbf3174c95cd1a9febf90adacd805030768b2374 100755 (executable)
@@ -15,11 +15,12 @@ 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
+  playtime.room_count = 4;
        barrow.max_iterations *= 1;
+
        IVec2 grid_size = {.x = GRID_X*2.0, .y = GRID_Y * 2.0};
        GeneratorArgs gargs =
        {
index 76462dbe65d8540c282f42132e26d9cdb35751e6..b8105a854ee0c555feabd781fc45c814963ea101 100644 (file)
@@ -11,7 +11,7 @@ bool menu_action_MI_NEW_GAME()
 {
   bool response = false;
 
-
+  resource_state = RENDER_RESOURCE_WAIT;
 
   return response;
 }
index 729e0954ce1f502e050a6da1a2623d8085e1772c..d52b66bd91b731c9199d9bbe7192715f60846dd1 100644 (file)
@@ -60,7 +60,7 @@ void* iterator(void* _arg)
 
        // One last synchronization so boss thread doesn't die early
        pthread_barrier_wait(&barrier);
-       playtime.should_quit = 1;
+  playtime.generation_finished = 1;
 
        return _arg;
 }
@@ -96,6 +96,7 @@ int cleanup()
        for (int t = 0; t < warg.worker_count; t++)
        {
                pthread_join(threads[t], NULL);
+    printf("Joined worker %d\n", t);
        }
 
        /* TODO: Actually this probably shouldn't be freeing resources allocated outside of the unit. */
index 979171f11db9842f5546bba55a1e67e678e07f20..aca81b6f2a4bf3f3d2d332cbf199508edc580a6b 100644 (file)
@@ -419,6 +419,10 @@ void control_game_mode()
 
 void control_resource_wait_mode()
 {
+  if (playtime.generation_finished && playtime.resources_ready)
+  {
+    resource_state++;
+  }
 }
 
 
@@ -582,14 +586,14 @@ void initialize_renderer()
        SetWindowState(FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE);
 }
 
+/* Resource generation is done, but still have work to do before
+   gameplay proper can start.
+*/
 void control_resource_ready_mode()
 {
-               if(resource_state == 1)
-               {
-                       wait_initialize_resources();
-                       initialize_renderer();
-                       resource_state = 2;
-               }
+  wait_initialize_resources();
+  initialize_renderer();
+  resource_state++;
 }
 
 /* Values that are required to initialize Raylib. */
index 803c5411325e18377ac5d373790f72cec2f95184..83b8822552a08b39aa6a3939b92a031646287350 100644 (file)
@@ -77,7 +77,9 @@ typedef struct
 
 typedef struct
 {
-  uint32_t should_quit;
+  bool should_quit;
+  bool generation_finished;
+  bool resources_ready;
 
   uint32_t room_count;
   Vector3 room_positions[16];
index cf765c9ef4972571fc2c2bf9c5b57cb32cdcba0e..aad1c68325e3a5883573764e122ec217e4d75aae 100644 (file)
@@ -197,7 +197,7 @@ void* generate_rd(void* args)
        initialize(garg->worker_count, garg->rd_opts);
        start(garg->worker_count, garg->rd_opts);
 
-       while(!playtime.should_quit) {}
+       while(!playtime.generation_finished){}
 
        //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);
 
@@ -263,7 +263,7 @@ void* generate_rd(void* args)
        stbi_write_png(floor_albedo_name, grid_size.x*img_export_scale.x, grid_size.y*img_export_scale.y, 4, large_albedo_buffer, grid_size.x * sizeof(uint32_t)*img_export_scale.x);
 
        cleanup();
-       resource_state = 1;
+  playtime.resources_ready = 1;
 
        return 0;
 }