From: Randy McShandy Date: Sat, 9 Aug 2025 16:32:40 +0000 (-0500) Subject: New Game mode seems to work well now. Updated generation data organization for clean... X-Git-Url: http://git.mcshandy.xyz/gitweb.cgi?a=commitdiff_plain;h=6f897eecde63f284663da18168b8d825d4803a20;p=barrow_crawler New Game mode seems to work well now. Updated generation data organization for clean worker thread access. Small adjustments in generation params etc, along with quantified barrow sizes to introduce difficulty options once I feel like it. --- diff --git a/bin/posix_BC b/bin/posix_BC index b8e1ba6..7224631 100755 Binary files a/bin/posix_BC and b/bin/posix_BC differ diff --git a/src/main.c b/src/main.c index cbf3174..0374df9 100755 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,4 @@ #include -#include #include #include "structs.h" @@ -17,32 +16,8 @@ int main(int argc, char** argv) /* 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 = - { - .worker_count = 8, - .rd_opts = barrow, - .grid_size = grid_size, - .grid = (FVec2**)malloc(grid_size.x * sizeof(FVec2*)) - }; - - for (int n = 0; n < gargs.grid_size.x; n++) - { - gargs.grid[n] = (FVec2*)malloc(gargs.grid_size.y * sizeof(FVec2)); - } - - pthread_t generator_thread; - pthread_create(&generator_thread, NULL, generate_rd, (void*)&gargs); - start_render_loop(); - pthread_join(generator_thread, NULL); -#else resource_state = 0; start_render_loop(); -#endif /* ENABLE_BARROWGEN */ return 0; } diff --git a/src/menufuncs.c b/src/menufuncs.c index b8105a8..1b95b6b 100644 --- a/src/menufuncs.c +++ b/src/menufuncs.c @@ -1,4 +1,5 @@ #include +#include #include #include @@ -10,9 +11,12 @@ bool menu_action_MI_NONE() bool menu_action_MI_NEW_GAME() { bool response = false; - resource_state = RENDER_RESOURCE_WAIT; + pthread_create(&generation_info.generator_thread, NULL, generate_rd, NULL); + pthread_detach(generation_info.generator_thread); + //pthread_join(generation_info.generator_thread, NULL); + return response; } diff --git a/src/platform.h b/src/platform.h index caf46c9..94538d7 100644 --- a/src/platform.h +++ b/src/platform.h @@ -1,10 +1,9 @@ #ifndef PLATFORM_POSIX #define PLATFORM_POSIX -#include "structs.h" - void* iterator(void* _arg); -void start(int worker_count, RD_Opts active_opt); +void start(); int cleanup(); #endif /* PLATFORM_POSIX */ + diff --git a/src/platforms/platform_posix.c b/src/platforms/platform_posix.c index d52b66b..76efe69 100644 --- a/src/platforms/platform_posix.c +++ b/src/platforms/platform_posix.c @@ -2,25 +2,24 @@ #include #include #include "../structs.h" +#include "../utils.h" worker_arg warg; int waiting_workers; -extern FVec2 ** grid; -extern FVec2 ** grid_prime; -extern FVec2 ** grid_temp; -extern IVec2 grid_size; - pthread_t* threads; pthread_mutex_t mutex; pthread_barrier_t barrier; /* TODO: This should go in a header, platforms don't care. */ -float rd_a_prime(FVec2 **source_grid, RD_Opts opts, int x, int y, Mat3 kernel, float A, float B); +float rd_a_prime(FVec2** source_grid, RD_Opts opts, int x, int y, Mat3 kernel, float A, float B); float rd_b_prime(FVec2** source_grid, RD_Opts opts, int x, int y, Mat3 kernel, float A, float B); void* iterator(void* _arg) { + printf("starting a worker\n"); + GenerationInfo *ginfo = &generation_info; + worker_arg* warg = (worker_arg*)_arg; RD_Opts opts = warg->opts; int start_x = warg->start_x; @@ -30,30 +29,31 @@ void* iterator(void* _arg) for (warg->iterations = 0; warg->iterations < warg->max_iterations; warg->iterations++) { - for (int x = start_x; x < w + start_x && x < grid_size.x; x++) + for (int x = start_x; x < w + start_x && x < ginfo->rd_grid_size.x; x++) { - for (int y = start_y; y < h + start_y && y < grid_size.y; y++) + for (int y = start_y; y < h + start_y && y < ginfo->rd_grid_size.y; y++) { - FVec2 each = grid[x][y]; + FVec2 each = ginfo->grid[x][y]; if (each.c >= 0.5f) { each.b = 1.0f; each.c -= 5.0f/((float)(opts.max_iterations/100.0f)); } - grid_prime[x][y].a = rd_a_prime(grid, opts, x, y, laplacian_kernel, each.a, each.b); - grid_prime[x][y].b = rd_b_prime(grid, opts, x, y, laplacian_kernel, each.a, each.b); + ginfo->grid_prime[x][y].a = rd_a_prime(ginfo->grid, opts, x, y, laplacian_kernel, each.a, each.b); + ginfo->grid_prime[x][y].b = rd_b_prime(ginfo->grid, opts, x, y, laplacian_kernel, each.a, each.b); } } pthread_mutex_lock(&mutex); if (++waiting_workers == warg->worker_count) { - grid_temp = grid; - grid = grid_prime; - grid_prime = grid_temp; + ginfo->grid_temp = ginfo->grid; + ginfo->grid = ginfo->grid_prime; + ginfo->grid_prime = ginfo->grid_temp; waiting_workers = 0; - resource_generation_progress = ((float)warg->iterations/(float)warg->max_iterations); + ginfo->generation_progress = ((float)warg->iterations/(float)warg->max_iterations); } + pthread_mutex_unlock(&mutex); pthread_barrier_wait(&barrier); } @@ -65,27 +65,29 @@ void* iterator(void* _arg) return _arg; } -void start(int worker_count, RD_Opts active_opt) +void start() { + GenerationInfo ginfo = generation_info; + worker_arg warg = (worker_arg){ - active_opt, grid, grid_prime, - 0, 0, (grid_size.x), (grid_size.y), - .worker_count = worker_count, - .max_iterations = active_opt.max_iterations + ginfo.rd_opt, ginfo.grid, ginfo.grid_prime, + 0, 0, (ginfo.rd_grid_size.x), (ginfo.rd_grid_size.y), + .worker_count = ginfo.worker_count, + .max_iterations = ginfo.rd_opt.max_iterations }; - threads = (pthread_t*)malloc(sizeof(pthread_t) * worker_count); + threads = (pthread_t*)malloc(sizeof(pthread_t) * ginfo.worker_count); pthread_mutex_init(&mutex, NULL); pthread_barrier_init(&barrier, NULL, warg.worker_count); - worker_arg wargs[worker_count]; + worker_arg wargs[ginfo.worker_count]; for (int t = 0; t < warg.worker_count; t++) { - wargs[t] = warg; + wargs[t] = warg; wargs[t].worker_id = t; - wargs[t].width = (grid_size.x/worker_count) + ((t == worker_count-1) ? 0 : 4); - wargs[t].start_x = (wargs[t].width * t); + wargs[t].width = (ginfo.rd_grid_size.x/ginfo.worker_count) + ((t == ginfo.worker_count-1) ? 0 : 4); + wargs[t].start_x = (wargs[t].width * t); pthread_create(&threads[t], NULL, iterator, &wargs[t]); } } @@ -100,9 +102,8 @@ int cleanup() } /* TODO: Actually this probably shouldn't be freeing resources allocated outside of the unit. */ - free(grid); - free(grid_prime); free(threads); + deinitialize_generation_info(); return 0; } diff --git a/src/render_raylib.c b/src/render_raylib.c index aca81b6..658ebc8 100644 --- a/src/render_raylib.c +++ b/src/render_raylib.c @@ -9,6 +9,7 @@ #endif #include +#include "utils.h" #include "structs.h" #include "ui.h" @@ -213,8 +214,17 @@ void drawing_game_mode() DrawTextureEx(hand_01_texture, hand_position, hand_rotation, hand_scale, orb_color); - 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}; + Rectangle minimap_dest = { + .width = 64.0f*generation_info.img_export_scale.x, + .height = 64.0f*generation_info.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 (timers[STATUS_TEXT_FADE_TIME].time > 0.0) { @@ -269,7 +279,7 @@ void drawing_resource_wait_mode() const int text_width = MeasureText(wait_string, font_size); ClearBackground(LIGHTGRAY); - DrawText(TextFormat(format_string, wait_string, 100 * resource_generation_progress), + DrawText(TextFormat(format_string, wait_string, 100 * generation_info.generation_progress), (fscreen_dims.x/2.0f) - (text_width/2.0f), fscreen_dims.y/2.0f, font_size, BLACK); DrawCircleSector(sector_center, sector_radius, (status_phase % 360), @@ -601,6 +611,13 @@ void initialize_prerenderer() { fscreen_dims = (Vector2){.x=screen_dims.x, .y=screen_dims.y}; + const float density = 1.6f; + const size_t barrow_size = sizes[0]; + + initialize_generation_info((IVec2){.x = barrow_size * density, .y = barrow_size * density}, 8); + + playtime.room_count = generation_info.room_count; + /* Mode handler setup */ { renderfuncs[RENDER_MAIN_MENU] = drawing_main_menu_mode; diff --git a/src/structs.c b/src/structs.c index 72e729f..620a025 100644 --- a/src/structs.c +++ b/src/structs.c @@ -1,3 +1,4 @@ +#include #include #include "structs.h" @@ -83,9 +84,9 @@ ProcessInfo processes[PROCESSES] = /* Process { STATE Progress, { E_UNKNOWN, E_GOOD, E_BAD, E_WAITING, E_FINISHED } } */ /* E_SAVE_FILE_LOAD */ { UNKNOWN, 0.0f, { "", "", "Failed to load save.", "Loading...", "Loaded" } }, /* E_SAVE_FILE_SAVE */ { UNKNOWN, 0.0f, { "", "", "Failed to create save.", "Saving...", "Saved" } } + /* TODO: Consider ProcessInfo manager for RD generation. */ }; - char text_places[TEXT_PLACES][64]; const char chars[6] = {' ', ' ', ' ', '+', '#', '@'}; @@ -95,8 +96,9 @@ const IVec2 screen_dims = {.x = 1600, .y = 900}; const char* screen_title = "Barrow Crawler"; const int target_fps = 60; -const IVec2 img_export_scale = {.x = 2, .y = 2}; -float resource_generation_progress = 0.0f; +GenerationInfo generation_info; + +const size_t sizes[3] = {128, 168, 208}; // Move this into menuinfo // Actually merge all of them into a display manager diff --git a/src/structs.h b/src/structs.h index 83b8822..8ab908a 100644 --- a/src/structs.h +++ b/src/structs.h @@ -1,7 +1,8 @@ #ifndef __RD_STRUCTS__ #define __RD_STRUCTS__ -#define GRID_X 128 +#include +#define GRID_X 256 #define GRID_Y GRID_X #include @@ -67,14 +68,6 @@ typedef struct int worker_id; } worker_arg; -typedef struct -{ - size_t worker_count; - RD_Opts rd_opts; - FVec2** grid; - IVec2 grid_size; -} GeneratorArgs; - typedef struct { bool should_quit; @@ -105,6 +98,24 @@ typedef struct char info_text[STATES][64]; } ProcessInfo; +typedef struct +{ + IVec2 img_export_scale; + IVec2 rd_grid_size; + float generation_progress; + uint32_t worker_count; + uint32_t room_count; + + RD_Opts rd_opt; + + pthread_t generator_thread; + + FVec2 ** grid; + FVec2 ** grid_prime; + FVec2 ** grid_temp; +} GenerationInfo; + +extern GenerationInfo generation_info; extern PlaytimeData playtime; extern MenuInfo menu_info; @@ -122,9 +133,8 @@ extern const IVec2 screen_dims; extern const char* screen_title; extern const int target_fps; -extern const IVec2 img_export_scale; -extern float resource_generation_progress; extern int resource_state; +extern const size_t sizes[3]; //int generate_rd(int worker_count, RD_Opts active_opt, FVec2 **grid_buffer, IVec2 pgrid_size); void* generate_rd(void* args); diff --git a/src/utils.c b/src/utils.c index aad1c68..a168ed0 100644 --- a/src/utils.c +++ b/src/utils.c @@ -9,6 +9,7 @@ #include #include +#include "utils.h" #include "structs.h" #include "platform.h" @@ -26,11 +27,6 @@ #define V3_UNROLL(v3) v3.x, v3.y, v3.z #define V3_FORMAT(v3) #v3 ":{%.4f %.4f %.4f}" -FVec2 ** grid; -FVec2 ** grid_prime; -FVec2 ** grid_temp; -IVec2 grid_size; - float iv2_inverse_sqrt(IVec2 a, IVec2 b) { return 1.0f/sqrt(pow(a.x-b.x, 2) + pow(a.y-b.y, 2)); @@ -50,20 +46,21 @@ float kernel_sum(Mat3 kernel, Mat3 source) { } float rd_a_prime(FVec2 **source_grid, RD_Opts opts, int x, int y, Mat3 kernel, float A, float B) { + GenerationInfo ginfo = generation_info; float a_prime = 1.0f; int x_less = (x - 1 < 0) ? x : x - 1; int y_less = (y - 1 < 0) ? y : y - 1; - int x_more = (x + 1 == grid_size.x) ? x : x + 1; - int y_more = (y + 1 == grid_size.y) ? y : y + 1; + int x_more = (x + 1 == ginfo.rd_grid_size.x) ? x : x + 1; + int y_more = (y + 1 == ginfo.rd_grid_size.y) ? y : y + 1; // Use species A in the convolution, b_prime will need B // For now we won't iterate over edge rows and columns to avoid special case // vomit Mat3 source = { .v = { - {grid[x_less][y_less].a, grid[x][y_less].a, grid[x_more][y_less].a}, - {grid[x_less][y + 0].a, grid[x][y + 0].a, grid[x_more][y + 0].a}, - {grid[x_less][y_more].a, grid[x][y_more].a, grid[x_more][y_more].a}, + {ginfo.grid[x_less][y_less].a, ginfo.grid[x][y_less].a, ginfo.grid[x_more][y_less].a}, + {ginfo.grid[x_less][y + 0].a, ginfo.grid[x][y + 0].a, ginfo.grid[x_more][y + 0].a}, + {ginfo.grid[x_less][y_more].a, ginfo.grid[x][y_more].a, ginfo.grid[x_more][y_more].a}, }}; a_prime = A + (opts.diff_a * (kernel_sum(kernel, source)) - (A * B * B) + @@ -74,20 +71,21 @@ float rd_a_prime(FVec2 **source_grid, RD_Opts opts, int x, int y, Mat3 kernel, f float rd_b_prime(FVec2** source_grid, RD_Opts opts, int x, int y, Mat3 kernel, float A, float B) { + GenerationInfo ginfo = generation_info; float b_prime = 1.0f; int x_less = (x-1 < 0) ? x : x-1; int y_less = (y-1 < 0) ? y : y-1; - int x_more = (x+1 == grid_size.x) ? x : x+1; - int y_more = (y+1 == grid_size.y) ? y : y+1; + int x_more = (x+1 == ginfo.rd_grid_size.x) ? x : x+1; + int y_more = (y+1 == ginfo.rd_grid_size.y) ? y : y+1; // Use species A in the convolution, b_prime will need B Mat3 source = { .v = { - {grid[x_less][y_less].b, grid[x][y_less].b, grid[x_more][y_less].b}, - {grid[x_less][y+0].b, grid[x][y+0].b, grid[x_more][y+0].b}, - {grid[x_less][y_more].b, grid[x][y_more].b, grid[x_more][y_more].b}, + {ginfo.grid[x_less][y_less].b, ginfo.grid[x][y_less].b, ginfo.grid[x_more][y_less].b}, + {ginfo.grid[x_less][y+0].b, ginfo.grid[x][y+0].b, ginfo.grid[x_more][y+0].b}, + {ginfo.grid[x_less][y_more].b, ginfo.grid[x][y_more].b, ginfo.grid[x_more][y_more].b}, } }; @@ -95,50 +93,38 @@ float rd_b_prime(FVec2** source_grid, RD_Opts opts, int x, int y, Mat3 kernel, f return b_prime; } -int initialize(int worker_count, RD_Opts active_opt) +int initialize_grid() { - grid_prime = (FVec2**)malloc(grid_size.x * sizeof(FVec2*)); - for (int n = 0; n < grid_size.x; n++) - { - grid_prime[n] = (FVec2*)malloc(grid_size.y * sizeof(FVec2)); - } - + GenerationInfo ginfo = generation_info; srand(time(NULL)); /* Set up as a circle */ - float barrow_radius = grid_size.x/2.1f; - int center_x = grid_size.x/2; - int center_y = grid_size.y/2; + float barrow_radius = ginfo.rd_grid_size.x/2.1f; + int center_x = ginfo.rd_grid_size.x/2; + int center_y = ginfo.rd_grid_size.y/2; float central_chamber_radius = barrow_radius/6; - for (int x = 0; x < grid_size.x; x++) + for (int x = 0; x < ginfo.rd_grid_size.x; x++) { - for (int y = 0; y < grid_size.y; y++) + for (int y = 0; y < ginfo.rd_grid_size.y; y++) { - grid[x][y].a = 1.0f; - grid[x][y].b = 0.0f; + ginfo.grid[x][y].a = 1.0f; + ginfo.grid[x][y].b = 0.0f; - if ((sqrtf(((x-center_x)*(x-center_x))+((y-center_y)*(y-center_y))) < barrow_radius)) - { - grid[x][y].c = 0.0f; - } - /* Outside the barrow walls */ - else - { - grid[x][y].c = 1.0f; - } + /* Keep C high outside of the barrow radius, else low inside. */ + ginfo.grid[x][y].c = (float)!(sqrtf(((x-center_x)*(x-center_x))+((y-center_y)*(y-center_y))) < barrow_radius); const float distance_from_center = sqrtf(((x-center_x)*(x-center_x))+((y-center_y)*(y-center_y))); if ((distance_from_center < central_chamber_radius) || - ((abs(x-center_x) < 1.0f) && (abs(y-center_y) < (central_chamber_radius*1.5f)))) + ((abs(x-center_x) < 1.0f) && (abs(y-center_y) < (central_chamber_radius*1.8f)))) { - grid[x][y].c = 1.0f; + ginfo.grid[x][y].c = 1.0f; } } } /* Set up seed-points to create connected rooms */ - const int seed_count = playtime.room_count; + const int seed_count = ginfo.room_count; const float small_room_radius = 8.0f; const float phase = ((rand() % 360)/(float)360) * (M_PI*2); @@ -149,17 +135,17 @@ int initialize(int worker_count, RD_Opts active_opt) float dist_offset = ((rand() % 14) + 1); angle += phase; - int seed_x = ((cosf(angle) * (dist_offset + (grid_size.x/4.0f))) + (grid_size.x/2.0f)); - int seed_y = ((sinf(angle) * (dist_offset + (grid_size.y/4.0f))) + (grid_size.y/2.0f)); + int seed_x = ((cosf(angle) * (dist_offset + (ginfo.rd_grid_size.x/4.0f))) + (ginfo.rd_grid_size.x/2.0f)); + int seed_y = ((sinf(angle) * (dist_offset + (ginfo.rd_grid_size.y/4.0f))) + (ginfo.rd_grid_size.y/2.0f)); // Swap dimensions prepping for rendering playtime.room_positions[n] = (Vector3){.x = seed_y, .y = 0.0f, .z = seed_x}; // mirror this across axis - playtime.room_positions[n].z = grid_size.y - playtime.room_positions[n].z; + playtime.room_positions[n].z = ginfo.rd_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; + ginfo.grid[seed_x][seed_y].b = 1.0f; + ginfo.grid[seed_x][seed_y].c = 0.0f; const float x_start = (seed_x-((small_room_radius))); const float y_start = (seed_y-((small_room_radius))); @@ -177,7 +163,7 @@ int initialize(int worker_count, RD_Opts active_opt) const float distance_from_center = sqrtf(((x-center_x)*(x-center_x))+((y-center_y)*(y-center_y))); if (distance_from_center >= distance_seed_to_center) { - grid[x][y].c = 1.0f; + ginfo.grid[x][y].c = 1.0f; } } } @@ -188,33 +174,41 @@ int initialize(int worker_count, RD_Opts active_opt) } void* generate_rd(void* args) -//int generate_rd(int worker_count, RD_Opts active_opt, FVec2 **grid_buffer, IVec2 pgrid_size) { - GeneratorArgs* garg = (GeneratorArgs*)args; - grid = garg->grid; - grid_size = garg->grid_size; + GenerationInfo ginfo = generation_info; - initialize(garg->worker_count, garg->rd_opts); - start(garg->worker_count, garg->rd_opts); + initialize_grid(); + start(); 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); /* png for the heightmap */ - unsigned char barrow_mesh_buffer[grid_size.x][grid_size.y]; - unsigned char floor_mesh_buffer[grid_size.x][grid_size.y]; - unsigned char large_barrow_mesh_buffer[grid_size.x*img_export_scale.x][grid_size.y*img_export_scale.y]; - unsigned char large_floor_mesh_buffer[grid_size.x*img_export_scale.x][grid_size.y*img_export_scale.y]; + unsigned char barrow_mesh_buffer[ginfo.rd_grid_size.x][ginfo.rd_grid_size.y]; + unsigned char floor_mesh_buffer[ginfo.rd_grid_size.x][ginfo.rd_grid_size.y]; + unsigned char large_barrow_mesh_buffer[ginfo.rd_grid_size.x*ginfo.img_export_scale.x][ginfo.rd_grid_size.y*ginfo.img_export_scale.y]; + unsigned char large_floor_mesh_buffer[ginfo.rd_grid_size.x*ginfo.img_export_scale.x][ginfo.rd_grid_size.y*ginfo.img_export_scale.y]; /* png for albedo buffer */ - uint32_t albedo_buffer[grid_size.x][grid_size.y]; - uint32_t large_albedo_buffer[grid_size.x*img_export_scale.x][grid_size.y*img_export_scale.y]; + uint32_t albedo_buffer[ginfo.rd_grid_size.x][ginfo.rd_grid_size.y]; + uint32_t large_albedo_buffer[ginfo.rd_grid_size.x*ginfo.img_export_scale.x][ginfo.rd_grid_size.y*ginfo.img_export_scale.y]; - for (int x = 0; x < grid_size.x; x++) + for (int x = 0; x < ginfo.rd_grid_size.x; x++) { - for (int y = 0; y < grid_size.y; y++) + for (int y = 0; y < ginfo.rd_grid_size.y; y++) { - float a = round(-0.05f + grid[x][y].a); + + float barrow_radius = ginfo.rd_grid_size.x/2.1f; + int center_x = ginfo.rd_grid_size.x/2; + int center_y = ginfo.rd_grid_size.y/2; + + if (sqrtf(((x-center_x)*(x-center_x))+((y-center_y)*(y-center_y))) > barrow_radius) + { + ginfo.grid[x][y].a = 1.0f; + } + + float a = round(-0.05f + ginfo.grid[x][y].a); barrow_mesh_buffer[x][y] = (uint8_t)(255.0f * a); floor_mesh_buffer[x][y] = barrow_mesh_buffer[x][y]; @@ -223,7 +217,7 @@ void* generate_rd(void* args) /* ABGR */ /* Color everything stone */ /* If it's below some height threshold, color it dirt */ - a = grid[x][y].a; + a = ginfo.grid[x][y].a; albedo_buffer[x][y] = 0xFF848484; if(a < 0.4) { @@ -237,30 +231,30 @@ void* generate_rd(void* args) char floor_mesh_name[64] = {0}; char albedo_name[64] = {0}; char floor_albedo_name[64] = {0}; - sprintf(mesh_name, "./%s.png", garg->rd_opts.name); - sprintf(albedo_name, "./%s_albedo.png", garg->rd_opts.name); + sprintf(mesh_name, "./%s.png", ginfo.rd_opt.name); + sprintf(albedo_name, "./%s_albedo.png", ginfo.rd_opt.name); sprintf(floor_mesh_name, "./floor.png"); sprintf(floor_albedo_name, "./floor_albedo.png"); stbir_resize_uint8_linear( - (unsigned char*)barrow_mesh_buffer, grid_size.x, grid_size.y, sizeof(uint8_t) * grid_size.x, - (unsigned char*)large_barrow_mesh_buffer, grid_size.x*img_export_scale.x, grid_size.y*img_export_scale.y, sizeof(uint8_t) * grid_size.x * img_export_scale.x, + (unsigned char*)barrow_mesh_buffer, ginfo.rd_grid_size.x, ginfo.rd_grid_size.y, sizeof(uint8_t) * ginfo.rd_grid_size.x, + (unsigned char*)large_barrow_mesh_buffer, ginfo.rd_grid_size.x*ginfo.img_export_scale.x, ginfo.rd_grid_size.y*ginfo.img_export_scale.y, sizeof(uint8_t) * ginfo.rd_grid_size.x * ginfo.img_export_scale.x, STBIR_1CHANNEL); stbir_resize_uint8_linear( - (unsigned char*)floor_mesh_buffer, grid_size.x, grid_size.y, sizeof(uint8_t) * grid_size.x, - (unsigned char*)large_floor_mesh_buffer, grid_size.x*img_export_scale.x, grid_size.y*img_export_scale.y, sizeof(uint8_t) * grid_size.x * img_export_scale.x, + (unsigned char*)floor_mesh_buffer, ginfo.rd_grid_size.x, ginfo.rd_grid_size.y, sizeof(uint8_t) * ginfo.rd_grid_size.x, + (unsigned char*)large_floor_mesh_buffer, ginfo.rd_grid_size.x*ginfo.img_export_scale.x, ginfo.rd_grid_size.y*ginfo.img_export_scale.y, sizeof(uint8_t) * ginfo.rd_grid_size.x * ginfo.img_export_scale.x, STBIR_1CHANNEL); stbir_resize_uint8_linear( - (unsigned char*)albedo_buffer, grid_size.x, grid_size.y, sizeof(uint32_t) * grid_size.x, - (unsigned char*)large_albedo_buffer, grid_size.x*img_export_scale.x, grid_size.y*img_export_scale.y, sizeof(uint32_t) * grid_size.x * img_export_scale.x, + (unsigned char*)albedo_buffer, ginfo.rd_grid_size.x, ginfo.rd_grid_size.y, sizeof(uint32_t) * ginfo.rd_grid_size.x, + (unsigned char*)large_albedo_buffer, ginfo.rd_grid_size.x*ginfo.img_export_scale.x, ginfo.rd_grid_size.y*ginfo.img_export_scale.y, sizeof(uint32_t) * ginfo.rd_grid_size.x * ginfo.img_export_scale.x, STBIR_RGBA); - stbi_write_png(mesh_name, grid_size.x*img_export_scale.x, grid_size.y*img_export_scale.y, 1, large_barrow_mesh_buffer, grid_size.x * sizeof(uint8_t)*img_export_scale.x); - stbi_write_png(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); + stbi_write_png(mesh_name, ginfo.rd_grid_size.x*ginfo.img_export_scale.x, ginfo.rd_grid_size.y*ginfo.img_export_scale.y, 1, large_barrow_mesh_buffer, ginfo.rd_grid_size.x * sizeof(uint8_t)*ginfo.img_export_scale.x); + stbi_write_png(albedo_name, ginfo.rd_grid_size.x*ginfo.img_export_scale.x, ginfo.rd_grid_size.y*ginfo.img_export_scale.y, 4, large_albedo_buffer, ginfo.rd_grid_size.x * sizeof(uint32_t)*ginfo.img_export_scale.x); stbi_flip_vertically_on_write(1); - stbi_write_png(floor_mesh_name, grid_size.x*img_export_scale.x, grid_size.y*img_export_scale.y, 1, large_floor_mesh_buffer, grid_size.x * sizeof(uint8_t)*img_export_scale.x); - 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); + stbi_write_png(floor_mesh_name, ginfo.rd_grid_size.x*ginfo.img_export_scale.x, ginfo.rd_grid_size.y*ginfo.img_export_scale.y, 1, large_floor_mesh_buffer, ginfo.rd_grid_size.x * sizeof(uint8_t)*ginfo.img_export_scale.x); + stbi_write_png(floor_albedo_name, ginfo.rd_grid_size.x*ginfo.img_export_scale.x, ginfo.rd_grid_size.y*ginfo.img_export_scale.y, 4, large_albedo_buffer, ginfo.rd_grid_size.x * sizeof(uint32_t)*ginfo.img_export_scale.x); cleanup(); playtime.resources_ready = 1; @@ -314,3 +308,39 @@ int load_game() return success; } +bool initialize_generation_info(const IVec2 pgrid_size, const int pworker_count) +{ + bool response = false; + IVec2 grid_size = pgrid_size; + + generation_info.img_export_scale = (IVec2){.x = 2.0f, .y = 2.0f}; + generation_info.rd_grid_size = pgrid_size; + generation_info.generation_progress = 0.0f; + generation_info.worker_count = pworker_count; + generation_info.rd_opt = barrow; + generation_info.room_count = 4; + + response |= !(generation_info.grid = (FVec2**)malloc(grid_size.x * sizeof(FVec2*))); + for (int n = 0; n < grid_size.x; n++) + { + response |= !(generation_info.grid[n] = (FVec2*)malloc(grid_size.y * sizeof(FVec2))); + } + + response |= !(generation_info.grid_prime = (FVec2**)malloc(grid_size.x * sizeof(FVec2*))); + for (int n = 0; n < grid_size.x; n++) + { + response |= !(generation_info.grid_prime[n] = (FVec2*)malloc(grid_size.y * sizeof(FVec2))); + } + + return response; +} + +bool deinitialize_generation_info() +{ + free(generation_info.grid); + free(generation_info.grid_prime); + generation_info.grid_temp = NULL; + + return true; +} +