.mipmap = true,
.render_distance = 255.0,
.vsync = true,
+ .meshgen_threads = 4,
};
__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);
}
#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"
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;
}
// 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);
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);
#include <dragonstd/queue.h>
#include "map.h"
#include "client/object.h"
-#define NUM_MESHGEN_THREADS 4
typedef enum
{
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