]> git.lizzy.rs Git - dragonblocks_alpha.git/blob - src/client/client_map.h
b9e06168531385c4c6f5bc7ebb65c742f5bd5f42
[dragonblocks_alpha.git] / src / client / client_map.h
1 #ifndef _CLIENT_MAP_H_
2 #define _CLIENT_MAP_H_
3
4 #include <stdbool.h>
5 #include <pthread.h>
6 #include <dragonstd/queue.h>
7 #include "map.h"
8 #include "client/object.h"
9 #define NUM_MESHGEN_THREADS 4
10
11 typedef enum
12 {
13         MBS_RECIEVING, // currently deserializing
14         MBS_FRESH,     // first deserialisation finished, not processed by sync thread yet
15         MBS_READY,     // ready to use and processed by sync thread
16 } MapBlockState;
17
18 typedef struct
19 {
20         MapBlockState state; // keep track of the deserialisation and sync processing state
21         bool queue;          // whether the block is in meshgen queue
22         u64 last_synced;     // keep track of when a block was synced the last time (used to detect when a block got out of and then back into range)
23         Object *obj;         // mesh object, generated by blockmesh file
24 } MapBlockExtraData;
25
26 extern struct ClientMap
27 {
28         Map *map;                                       // map object
29         Queue *queue;                                   // MapBlock * queue (thread safe)
30         bool cancel;                                    // used to notify meshgen and sync thread about quit
31         pthread_t meshgen_threads[NUM_MESHGEN_THREADS]; // consumer threads for meshgen queue
32         pthread_t sync_thread;                          // this thread requests new / changed blocks from server
33         u32 simulation_distance;                        // simulation distance sent by server
34         size_t blocks_count;                            // cached number of facecache positions to process every sync step (matches simulation distance)
35 } client_map;
36
37 void client_map_init();                                           // ClientMap singleton constructor
38 void client_map_deinit();                                         // ClientMap singleton destructor
39 void client_map_set_simulation_distance(u32 simulation_distance); // update simulation distance
40 void client_map_start();                                          // start meshgen and sync threads
41 void client_map_stop();                                           // stop meshgen and sync threads
42 void client_map_block_received(MapBlock *block);                  // called when a block was actually recieved from server
43 void client_map_schedule_update_block_mesh(MapBlock *block);      // enqueue block to mesh update queue
44
45 #endif