]> git.lizzy.rs Git - dragonblocks_alpha.git/blob - src/client/client_map.h
ce4056b9cdb280850ea5533b6e5a279d78522964
[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 <dragontype/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 } MapBlockExtraData;
24
25 extern struct ClientMap
26 {
27         Map *map;                                                                               // map object
28         Queue *queue;                                                                   // MapBlock * queue (thread safe)
29         bool cancel;                                                                    // used to notify meshgen and sync thread about quit
30         pthread_t meshgen_thread;                                               // consumer thread for meshgen queue
31         pthread_t sync_thread;                                                  // this thread requests new / changed blocks from server
32         u32 simulation_distance;                                                // simulation distance sent by server
33         size_t blocks_count;                                                    // cached number of facecache positions to process every sync step (matches simulation distance)
34 } client_map;
35
36 void client_map_init();                                                                                         // ClientMap singleton constructor
37 void client_map_deinit();                                                                                       // ClientMap singleton destructor
38 void client_map_set_simulation_distance(u32 simulation_distance);       // update simulation distance
39 void client_map_start();                                                                                        // start meshgen and sync threads
40 void client_map_stop();                                                                                         // stop meshgen and sync threads
41 void client_map_block_received(MapBlock *block);                                        // called when a block was actually recieved from server
42
43 #endif