Connected Nodeboxes: Add `disconnected` boxes
authorThomas--S <Thomas--S@users.noreply.github.com>
Sat, 22 Apr 2017 19:17:46 +0000 (21:17 +0200)
committerparamat <mat.gregory@virginmedia.com>
Wed, 3 Jan 2018 04:05:21 +0000 (04:05 +0000)
The `disconnected_*` boxes are the opposites of the `connect_*` ones,
i.e. when a node has no suitable neighbours on the respective side, the
according disconnected box is drawn.

* disconnected_top
* disconnected_bottom
* disconnected_front
* disconnected_left
* disconnected_back
* disconnected_right
* disconnected (when there is *no* neighbour)
* disconnected_sides (when there are *no* neighbours to the sides)

doc/lua_api.txt
src/mapnode.cpp
src/network/networkprotocol.h
src/nodedef.cpp
src/nodedef.h
src/script/common/c_content.cpp

index 59884621b66ef92b2346fe47a083de9e2999d699..54a5e7b577187ba587984ac5b3900571a02437dd 100644 (file)
@@ -1032,6 +1032,17 @@ A nodebox is defined as any of:
         connect_left = box OR {box1, box2, ...}
         connect_back = box OR {box1, box2, ...}
         connect_right = box OR {box1, box2, ...}
+        -- The following `disconnected_*` boxes are the opposites of the
+        -- `connect_*` ones above, i.e. when a node has no suitable neighbour
+        -- on the respective side, the corresponding disconnected box is drawn.
+        disconnected_top = box OR {box1, box2, ...}
+        disconnected_bottom = box OR {box1, box2, ...}
+        disconnected_front = box OR {box1, box2, ...}
+        disconnected_left = box OR {box1, box2, ...}
+        disconnected_back = box OR {box1, box2, ...}
+        disconnected_right = box OR {box1, box2, ...}
+        disconnected = box OR {box1, box2, ...} -- when there is *no* neighbour
+        disconnected_sides = box OR {box1, box2, ...} -- when there are *no* neighbours to the sides
     }
 
 A `box` is defined as:
index 9d3459173d4eb83ac1ea0079f6416938dfab3eaa..3a12360f3c8b5ee7dcb2948d8fb5ed0e63a59d9f 100644 (file)
@@ -422,16 +422,40 @@ void transformNodeBox(const MapNode &n, const NodeBox &nodebox,
                boxes_size += nodebox.fixed.size();
                if (neighbors & 1)
                        boxes_size += nodebox.connect_top.size();
+               else
+                       boxes_size += nodebox.disconnected_top.size();
+
                if (neighbors & 2)
                        boxes_size += nodebox.connect_bottom.size();
+               else
+                       boxes_size += nodebox.disconnected_bottom.size();
+
                if (neighbors & 4)
                        boxes_size += nodebox.connect_front.size();
+               else
+                       boxes_size += nodebox.disconnected_front.size();
+
                if (neighbors & 8)
                        boxes_size += nodebox.connect_left.size();
+               else
+                       boxes_size += nodebox.disconnected_left.size();
+
                if (neighbors & 16)
                        boxes_size += nodebox.connect_back.size();
+               else
+                       boxes_size += nodebox.disconnected_back.size();
+
                if (neighbors & 32)
                        boxes_size += nodebox.connect_right.size();
+               else
+                       boxes_size += nodebox.disconnected_right.size();
+
+               if (neighbors == 0)
+                       boxes_size += nodebox.disconnected.size();
+
+               if (neighbors < 4)
+                       boxes_size += nodebox.disconnected_sides.size();
+
                boxes.reserve(boxes_size);
 
 #define BOXESPUSHBACK(c) \
@@ -442,18 +466,50 @@ void transformNodeBox(const MapNode &n, const NodeBox &nodebox,
 
                BOXESPUSHBACK(nodebox.fixed);
 
-               if (neighbors & 1)
+               if (neighbors & 1) {
                        BOXESPUSHBACK(nodebox.connect_top);
-               if (neighbors & 2)
+               } else {
+                       BOXESPUSHBACK(nodebox.disconnected_top);
+               }
+
+               if (neighbors & 2) {
                        BOXESPUSHBACK(nodebox.connect_bottom);
-               if (neighbors & 4)
+               } else {
+                       BOXESPUSHBACK(nodebox.disconnected_bottom);
+               }
+
+               if (neighbors & 4) {
                        BOXESPUSHBACK(nodebox.connect_front);
-               if (neighbors & 8)
+               } else {
+                       BOXESPUSHBACK(nodebox.disconnected_front);
+               }
+
+               if (neighbors & 8) {
                        BOXESPUSHBACK(nodebox.connect_left);
-               if (neighbors & 16)
+               } else {
+                       BOXESPUSHBACK(nodebox.disconnected_left);
+               }
+
+               if (neighbors & 16) {
                        BOXESPUSHBACK(nodebox.connect_back);
-               if (neighbors & 32)
+               } else {
+                       BOXESPUSHBACK(nodebox.disconnected_back);
+               }
+
+               if (neighbors & 32) {
                        BOXESPUSHBACK(nodebox.connect_right);
+               } else {
+                       BOXESPUSHBACK(nodebox.disconnected_right);
+               }
+
+               if (neighbors == 0) {
+                       BOXESPUSHBACK(nodebox.disconnected);
+               }
+
+               if (neighbors < 4) {
+                       BOXESPUSHBACK(nodebox.disconnected_sides);
+               }
+
        }
        else // NODEBOX_REGULAR
        {
index 1f10822e17a2d7ab5759981f462550e884b1b3ef..53d36e6669cd2571afc748ff0e00e863aadaf85d 100644 (file)
@@ -185,6 +185,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
                Mod channels
                Raise ObjectProperties version to 3 for removing 'can_zoom' and adding
                        'zoom_fov'.
+               Nodebox version 5
+               Add disconnected nodeboxes
 */
 
 #define LATEST_PROTOCOL_VERSION 36
index 790f7154c0cdd958e7c85959a6a1571fc49e1d88..f7ff6b2ebd311e00dda5db165ebd8e6f05d5a155 100644 (file)
@@ -61,12 +61,20 @@ void NodeBox::reset()
        connect_left.clear();
        connect_back.clear();
        connect_right.clear();
+       disconnected_top.clear();
+       disconnected_bottom.clear();
+       disconnected_front.clear();
+       disconnected_left.clear();
+       disconnected_back.clear();
+       disconnected_right.clear();
+       disconnected.clear();
+       disconnected_sides.clear();
 }
 
 void NodeBox::serialize(std::ostream &os, u16 protocol_version) const
 {
        // Protocol >= 36
-       int version = 4;
+       int version = 5;
        writeU8(os, version);
 
        switch (type) {
@@ -107,6 +115,14 @@ void NodeBox::serialize(std::ostream &os, u16 protocol_version) const
                WRITEBOX(connect_left);
                WRITEBOX(connect_back);
                WRITEBOX(connect_right);
+               WRITEBOX(disconnected_top);
+               WRITEBOX(disconnected_bottom);
+               WRITEBOX(disconnected_front);
+               WRITEBOX(disconnected_left);
+               WRITEBOX(disconnected_back);
+               WRITEBOX(disconnected_right);
+               WRITEBOX(disconnected);
+               WRITEBOX(disconnected_sides);
                break;
        default:
                writeU8(os, type);
@@ -163,6 +179,16 @@ void NodeBox::deSerialize(std::istream &is)
                READBOXES(connect_left);
                READBOXES(connect_back);
                READBOXES(connect_right);
+               if (version >= 5) {
+                       READBOXES(disconnected_top);
+                       READBOXES(disconnected_bottom);
+                       READBOXES(disconnected_front);
+                       READBOXES(disconnected_left);
+                       READBOXES(disconnected_back);
+                       READBOXES(disconnected_right);
+                       READBOXES(disconnected);
+                       READBOXES(disconnected_sides);
+               }
        }
 }
 
@@ -1245,13 +1271,21 @@ void getNodeBoxUnion(const NodeBox &nodebox, const ContentFeatures &features,
                }
                case NODEBOX_CONNECTED: {
                        // Add all possible connected boxes
-                       boxVectorUnion(nodebox.fixed,          box_union);
-                       boxVectorUnion(nodebox.connect_top,    box_union);
-                       boxVectorUnion(nodebox.connect_bottom, box_union);
-                       boxVectorUnion(nodebox.connect_front,  box_union);
-                       boxVectorUnion(nodebox.connect_left,   box_union);
-                       boxVectorUnion(nodebox.connect_back,   box_union);
-                       boxVectorUnion(nodebox.connect_right,  box_union);
+                       boxVectorUnion(nodebox.fixed,               box_union);
+                       boxVectorUnion(nodebox.connect_top,         box_union);
+                       boxVectorUnion(nodebox.connect_bottom,      box_union);
+                       boxVectorUnion(nodebox.connect_front,       box_union);
+                       boxVectorUnion(nodebox.connect_left,        box_union);
+                       boxVectorUnion(nodebox.connect_back,        box_union);
+                       boxVectorUnion(nodebox.connect_right,       box_union);
+                       boxVectorUnion(nodebox.disconnected_top,    box_union);
+                       boxVectorUnion(nodebox.disconnected_bottom, box_union);
+                       boxVectorUnion(nodebox.disconnected_front,  box_union);
+                       boxVectorUnion(nodebox.disconnected_left,   box_union);
+                       boxVectorUnion(nodebox.disconnected_back,   box_union);
+                       boxVectorUnion(nodebox.disconnected_right,  box_union);
+                       boxVectorUnion(nodebox.disconnected,        box_union);
+                       boxVectorUnion(nodebox.disconnected_sides,  box_union);
                        break;
                }
                default: {
index 790c7fd28ad822e4d191e7504b180cbeb81baf51..d46712310d5cc74b89668ac1bcd6d049739ea717 100644 (file)
@@ -107,6 +107,14 @@ struct NodeBox
        std::vector<aabb3f> connect_left;
        std::vector<aabb3f> connect_back;
        std::vector<aabb3f> connect_right;
+       std::vector<aabb3f> disconnected_top;
+       std::vector<aabb3f> disconnected_bottom;
+       std::vector<aabb3f> disconnected_front;
+       std::vector<aabb3f> disconnected_left;
+       std::vector<aabb3f> disconnected_back;
+       std::vector<aabb3f> disconnected_right;
+       std::vector<aabb3f> disconnected;
+       std::vector<aabb3f> disconnected_sides;
 
        NodeBox()
        { reset(); }
index af54a8b315610a981435b6edee2828a0f4cd127b..507fd58b4a27ad40a58bb72ba32e5b7a30df6150 100644 (file)
@@ -1062,6 +1062,14 @@ NodeBox read_nodebox(lua_State *L, int index)
                NODEBOXREADVEC(nodebox.connect_left, "connect_left");
                NODEBOXREADVEC(nodebox.connect_back, "connect_back");
                NODEBOXREADVEC(nodebox.connect_right, "connect_right");
+               NODEBOXREADVEC(nodebox.disconnected_top, "disconnected_top");
+               NODEBOXREADVEC(nodebox.disconnected_bottom, "disconnected_bottom");
+               NODEBOXREADVEC(nodebox.disconnected_front, "disconnected_front");
+               NODEBOXREADVEC(nodebox.disconnected_left, "disconnected_left");
+               NODEBOXREADVEC(nodebox.disconnected_back, "disconnected_back");
+               NODEBOXREADVEC(nodebox.disconnected_right, "disconnected_right");
+               NODEBOXREADVEC(nodebox.disconnected, "disconnected");
+               NODEBOXREADVEC(nodebox.disconnected_sides, "disconnected_sides");
        }
        return nodebox;
 }