]> git.mcshandy.xyz Git - barrow_crawler/commitdiff
Starting to build for windows via mingw
authorRandy McShandy <randy@mcshandy.xyz>
Mon, 20 May 2024 03:46:47 +0000 (22:46 -0500)
committerRandy McShandy <randy@mcshandy.xyz>
Mon, 20 May 2024 03:46:47 +0000 (22:46 -0500)
src/main.c
src/platforms/platform_win.c
src/render_raylib.c

index dfafb6c6ed77d545fb74bc2ddbbbaba17827f063..9d60b64de2095659ae8ac5b2db97d37a1080aed3 100755 (executable)
@@ -16,7 +16,7 @@ int main(int argc, char** argv)
 {
 
 /* TODO: Clean this up and integrate into platform system. */
-#define ENABLE_BARROWGEN 0
+#define ENABLE_BARROWGEN 1
 #if ENABLE_BARROWGEN
        barrow.max_iterations *= 1;
        IVec2 grid_size = {.x = GRID_X*1.5, .y = GRID_Y * 1.5};
index 4fc78549edd1c5178273e22f47824abc5a9d9852..ced43c8d5a59cfa3098b5bf6a1a4000cd654babb 100644 (file)
-#error TODO: Support windowschuds
+#warning TODO: Support windowschuds
 
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include "../structs.h"
 
+worker_arg warg;
+int waiting_workers;
+int should_quit = 0;
+
+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_b_prime(FVec2** source_grid, RD_Opts opts, int x, int y, Mat3 kernel, float A, float B);
+
 void* iterator(void* _arg)
-{}
+{
+       worker_arg* warg = (worker_arg*)_arg;
+       RD_Opts opts = warg->opts;
+       int start_x = warg->start_x;
+       int start_y = warg->start_y;
+       int w = warg->width;
+       int h = warg->height;
+
+       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 y = start_y; y < h + start_y && y < grid_size.y; y++)
+                       {
+                               FVec2 each = 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);
+                       }
+               }
+
+               pthread_mutex_lock(&mutex);
+               if (++waiting_workers == warg->worker_count)
+               {
+                       grid_temp = grid;
+                       grid = grid_prime;
+                       grid_prime = grid_temp;
+                       waiting_workers = 0;
+                       resource_generation_progress = ((float)warg->iterations/(float)warg->max_iterations);
+               }
+               pthread_mutex_unlock(&mutex);
+               pthread_barrier_wait(&barrier);
+       }
+
+       // One last synchronization so boss thread doesn't die early
+       pthread_barrier_wait(&barrier);
+       should_quit = 1;
+
+       return _arg;
+}
 
 void start(int worker_count, RD_Opts active_opt)
-{}
+{
+       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
+       };
+
+       threads = (pthread_t*)malloc(sizeof(pthread_t) * worker_count);
+       pthread_mutex_init(&mutex, NULL);
+       pthread_barrier_init(&barrier, NULL, warg.worker_count);
+
+       worker_arg wargs[worker_count];
+
+       for (int t = 0; t < warg.worker_count; t++)
+       {
+               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);
+               pthread_create(&threads[t], NULL, iterator, &wargs[t]);
+       }
+}
 
+/* TODO: Revisit this for any new additions. */
 int cleanup()
-{}
+{
+       for (int t = 0; t < warg.worker_count; t++)
+       {
+               pthread_join(threads[t], NULL);
+       }
+
+       /* TODO: Actually this probably shouldn't be freeing resources allocated outside of the unit. */
+       free(grid);
+       free(grid_prime);
+       free(threads);
+
+       return 0;
+}
+
index 0398812082d39897b14446e09fd5cb29aed41bc5..89242cbb236269965b5f8cc4822350cc9bcbfd57 100644 (file)
@@ -109,7 +109,7 @@ void drawing_game_mode()
 
        DrawTextureEx(hand_01_texture, hand_position, hand_rotation, hand_scale, orb_color);
 
-#define DEBUG_GAME_INFO 1
+#define DEBUG_GAME_INFO 0
 #if DEBUG_GAME_INFO==1
        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};