]> git.lizzy.rs Git - dragonblocks_alpha.git/commitdiff
Speed up logistics of all air mapblocks 0.2.2
authorElias Fleckenstein <eliasfleckenstein@web.de>
Sun, 13 Feb 2022 20:59:33 +0000 (21:59 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Sun, 13 Feb 2022 20:59:33 +0000 (21:59 +0100)
deps/dragonnet
deps/dragontype
src/client/client.c
src/client/client_map.c
src/client/client_map.h
src/map.c

index 8bcc4ba04baea8f4d1f86524e58bd81d4df67bf6..164e1ed7f93e1889c36b549a995e93fc0992c888 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 8bcc4ba04baea8f4d1f86524e58bd81d4df67bf6
+Subproject commit 164e1ed7f93e1889c36b549a995e93fc0992c888
index 61292ea8a973ba03f93ebf4acde705071e15ccaf..18ae77e35da46f97f3b06562a4a892ebdeeb9750 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 61292ea8a973ba03f93ebf4acde705071e15ccaf
+Subproject commit 18ae77e35da46f97f3b06562a4a892ebdeeb9750
index 04364af9dc14172d19cc4772347b9d479d1114a7..63d3c5946e2c2cae69a64234a79e3a5c3eda0814 100644 (file)
@@ -45,6 +45,7 @@ static void on_ToClientBlock(unused DragonnetPeer *peer, ToClientBlock *pkt)
        MapBlock *block = map_get_block(client_map.map, pkt->pos, true);
 
        map_deserialize_block(block, pkt->data);
+       ((MapBlockExtraData *) block->extra)->all_air = (pkt->data.siz == 0);
        client_map_block_received(block);
 }
 
index f61734102b905900af3d99254c37241f02d81f89..43252dd589619954e289051d1ef0946ac5fc499e 100644 (file)
@@ -133,6 +133,7 @@ static void on_create_block(MapBlock *block)
        extra->queue = false;
        extra->last_synced = 0;
        extra->obj = NULL;
+       extra->all_air = false;
 }
 
 // callback for deleting a block
@@ -236,9 +237,17 @@ void client_map_schedule_update_block_mesh(MapBlock *block)
 
        pthread_mutex_lock(&block->mtx);
        MapBlockExtraData *extra = block->extra;
+
        if (! extra->queue) {
-               extra->queue = true;
-               queue_enqueue(client_map.queue, block);
+               if (extra->all_air) {
+                       if (extra->obj) {
+                               extra->obj->remove = true;
+                               extra->obj = NULL;
+                       }
+               } else {
+                       extra->queue = true;
+                       queue_enqueue(client_map.queue, block);
+               }
        }
        pthread_mutex_unlock(&block->mtx);
 }
index f340a9aa8afae4b1bdb65cc2776818dd75c8d194..b49f19917993a9d4ac4bbbba4069fcbeb4c0dafb 100644 (file)
@@ -20,6 +20,7 @@ typedef struct
        bool queue;          // whether the block is in meshgen queue
        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)
        Object *obj;         // mesh object, generated by blockmesh file
+       bool all_air;        // no thoughts brain empty
 } MapBlockExtraData;
 
 extern struct ClientMap
index a9a83befb97c8502fc90ccdaecbcaf7d390edc70..8c75756e79e713d752d64eba8ee3dd7a43d31aa7 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -145,6 +145,18 @@ void map_free_block(MapBlock *block)
 
 Blob map_serialize_block(MapBlock *block)
 {
+       bool all_air = true;
+
+       ITERATE_MAPBLOCK {
+               if (block->data[x][y][z].type != NODE_AIR) {
+                       all_air = false;
+                       break;
+               }
+       }
+
+       if (all_air)
+               return (Blob) {0, NULL};
+
        SerializedMapBlock block_data;
 
        ITERATE_MAPBLOCK {
@@ -174,6 +186,13 @@ Blob map_serialize_block(MapBlock *block)
 
 bool map_deserialize_block(MapBlock *block, Blob buffer)
 {
+       if (buffer.siz == 0) {
+               ITERATE_MAPBLOCK
+                       block->data[x][y][z] = map_node_create(NODE_AIR, (Blob) {0, NULL});
+
+               return true;
+       }
+
        // it's important to copy Blobs that have been malloc'd before reading from them
        // because reading from a Blob modifies its data and size pointer,
        // but does not free anything