]> git.lizzy.rs Git - dragonblocks_alpha.git/commitdiff
Add meshgen_threads setting
authorElias Fleckenstein <eliasfleckenstein@web.de>
Sun, 13 Feb 2022 19:06:27 +0000 (20:06 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Sun, 13 Feb 2022 19:06:27 +0000 (20:06 +0100)
src/client/client_config.c
src/client/client_config.h
src/client/client_map.c
src/client/client_map.h

index 658fe5e1fe714e8dca7c1469720de6a4f4ab6037..2dbe24b07bef27f6aa0b8cbce9fdc210b1e4dfdc 100644 (file)
@@ -6,6 +6,7 @@ struct ClientConfig client_config = {
        .mipmap = true,
        .render_distance = 255.0,
        .vsync = true,
+       .meshgen_threads = 4,
 };
 
 __attribute__((constructor)) static void client_config_init()
@@ -30,7 +31,12 @@ __attribute__((constructor)) static void client_config_init()
                        .type = CT_BOOL,
                        .key = "vsync",
                        .value = &client_config.vsync,
-               }
-       }, 4);
+               },
+               {
+                       .type = CT_UINT,
+                       .key = "meshgen_threads",
+                       .value = &client_config.meshgen_threads,
+               },
+       }, 5);
 }
 
index 21b40ddb45e4ab80e32ecb3de9b40fb5d1e094e7..4850e4548b4cd9339362300e3b53f0e3298489e0 100644 (file)
@@ -8,6 +8,7 @@ extern struct ClientConfig {
        bool mipmap;
        double render_distance;
        bool vsync;
+       unsigned int meshgen_threads;
 } client_config;
 
 #endif
index 12a7a94638cf38cdd7eb2c3743651375fc1744a2..5d2d50eab6ea2d279c0bbeb6acd42aeb69d36007 100644 (file)
@@ -2,6 +2,7 @@
 #include <stdlib.h>
 #include "client/blockmesh.h"
 #include "client/facecache.h"
+#include "client/client_config.h"
 #include "client/client_map.h"
 #include "client/client_player.h"
 #include "client/debug_menu.h"
@@ -165,7 +166,8 @@ void client_map_init()
        client_map.sync_thread = 0;
        client_map_set_simulation_distance(10);
 
-       for (int i = 0; i < NUM_MESHGEN_THREADS; i++)
+       client_map.meshgen_threads = malloc(sizeof *client_map.meshgen_threads * client_config.meshgen_threads);
+       for (unsigned int i = 0; i < client_config.meshgen_threads; i++)
                client_map.meshgen_threads[i] = 0;
 }
 
@@ -179,7 +181,7 @@ void client_map_deinit()
 // start meshgen and sync threads
 void client_map_start()
 {
-       for (int i = 0; i < NUM_MESHGEN_THREADS; i++)
+       for (unsigned int i = 0; i < client_config.meshgen_threads; i++)
                pthread_create(&client_map.meshgen_threads[i], NULL, &meshgen_thread, NULL);
 
        pthread_create(&client_map.sync_thread, NULL, &sync_thread, NULL);
@@ -191,9 +193,10 @@ void client_map_stop()
        client_map.cancel = true;
        queue_cancel(client_map.queue);
 
-       for (int i = 0; i < NUM_MESHGEN_THREADS; i++)
+       for (unsigned int i = 0; i < client_config.meshgen_threads; i++)
                if (client_map.meshgen_threads[i])
                        pthread_join(client_map.meshgen_threads[i], NULL);
+       free(client_map.meshgen_threads);
 
        if (client_map.sync_thread)
                pthread_join(client_map.sync_thread, NULL);
index 34998b5a8172299bbeb4c0d20d5e926aae63cdb1..f340a9aa8afae4b1bdb65cc2776818dd75c8d194 100644 (file)
@@ -6,7 +6,6 @@
 #include <dragonstd/queue.h>
 #include "map.h"
 #include "client/object.h"
-#define NUM_MESHGEN_THREADS 4
 
 typedef enum
 {
@@ -25,13 +24,13 @@ typedef struct
 
 extern struct ClientMap
 {
-       Map *map;                                       // map object
-       Queue *queue;                                   // MapBlock * queue (thread safe)
-       atomic_bool cancel;                             // used to notify meshgen and sync thread about quit
-       pthread_t meshgen_threads[NUM_MESHGEN_THREADS]; // consumer threads for meshgen queue
-       pthread_t sync_thread;                          // this thread requests new / changed blocks from server
-       u32 simulation_distance;                        // simulation distance sent by server
-       size_t blocks_count;                            // cached number of facecache positions to process every sync step (matches simulation distance)
+       Map *map;                   // map object
+       Queue *queue;               // MapBlock * queue (thread safe)
+       atomic_bool cancel;         // used to notify meshgen and sync thread about quit
+       pthread_t *meshgen_threads; // consumer threads for meshgen queue
+       pthread_t sync_thread;      // this thread requests new / changed blocks from server
+       u32 simulation_distance;    // simulation distance sent by server
+       size_t blocks_count;        // cached number of facecache positions to process every sync step (matches simulation distance)
 } client_map;
 
 void client_map_init();                                           // ClientMap singleton constructor