From: Randy McShandy Date: Mon, 16 Jun 2025 02:49:43 +0000 (-0500) Subject: WIP: Adjust generation states to supprt New Game button X-Git-Url: http://git.mcshandy.xyz/gitweb.cgi?a=commitdiff_plain;h=5a7d61f15140af40c308855725a9d48987a32f0a;p=barrow_crawler WIP: Adjust generation states to supprt New Game button --- diff --git a/bin/posix_BC b/bin/posix_BC index 0ce3cc5..b8e1ba6 100755 Binary files a/bin/posix_BC and b/bin/posix_BC differ diff --git a/src/main.c b/src/main.c index c0949a1..cbf3174 100755 --- a/src/main.c +++ b/src/main.c @@ -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 = { diff --git a/src/menufuncs.c b/src/menufuncs.c index 76462db..b8105a8 100644 --- a/src/menufuncs.c +++ b/src/menufuncs.c @@ -11,7 +11,7 @@ bool menu_action_MI_NEW_GAME() { bool response = false; - + resource_state = RENDER_RESOURCE_WAIT; return response; } diff --git a/src/platforms/platform_posix.c b/src/platforms/platform_posix.c index 729e095..d52b66b 100644 --- a/src/platforms/platform_posix.c +++ b/src/platforms/platform_posix.c @@ -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. */ diff --git a/src/render_raylib.c b/src/render_raylib.c index 979171f..aca81b6 100644 --- a/src/render_raylib.c +++ b/src/render_raylib.c @@ -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. */ diff --git a/src/structs.h b/src/structs.h index 803c541..83b8822 100644 --- a/src/structs.h +++ b/src/structs.h @@ -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]; diff --git a/src/utils.c b/src/utils.c index cf765c9..aad1c68 100644 --- a/src/utils.c +++ b/src/utils.c @@ -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; }