]> git.lizzy.rs Git - dragonblocks_alpha.git/blob - src/client/client_map.h
b49f19917993a9d4ac4bbbba4069fcbeb4c0dafb
[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
10 typedef enum
11 {
12         MBS_RECIEVING, // currently deserializing
13         MBS_FRESH,     // first deserialisation finished, not processed by sync thread yet
14         MBS_READY,     // ready to use and processed by sync thread
15 } MapBlockState;
16
17 typedef struct
18 {
19         MapBlockState state; // keep track of the deserialisation and sync processing state
20         bool queue;          // whether the block is in meshgen queue
21         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)
22         Object *obj;         // mesh object, generated by blockmesh file
23         bool all_air;        // no thoughts brain empty
24 } MapBlockExtraData;
25
26 extern struct ClientMap
27 {
28         Map *map;                   // map object
29         Queue *queue;               // MapBlock * queue (thread safe)
30         atomic_bool cancel;         // used to notify meshgen and sync thread about quit
31         pthread_t *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