Connected Nodeboxes: Add disconnected boxes

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)
This commit is contained in:
Thomas--S 2017-04-22 21:17:46 +02:00 committed by paramat
parent 345e1041a2
commit f3b9d87076
6 changed files with 133 additions and 14 deletions

@ -1032,6 +1032,17 @@ A nodebox is defined as any of:
connect_left = box OR {box1, box2, ...} connect_left = box OR {box1, box2, ...}
connect_back = box OR {box1, box2, ...} connect_back = box OR {box1, box2, ...}
connect_right = 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: A `box` is defined as:

@ -422,16 +422,40 @@ void transformNodeBox(const MapNode &n, const NodeBox &nodebox,
boxes_size += nodebox.fixed.size(); boxes_size += nodebox.fixed.size();
if (neighbors & 1) if (neighbors & 1)
boxes_size += nodebox.connect_top.size(); boxes_size += nodebox.connect_top.size();
else
boxes_size += nodebox.disconnected_top.size();
if (neighbors & 2) if (neighbors & 2)
boxes_size += nodebox.connect_bottom.size(); boxes_size += nodebox.connect_bottom.size();
else
boxes_size += nodebox.disconnected_bottom.size();
if (neighbors & 4) if (neighbors & 4)
boxes_size += nodebox.connect_front.size(); boxes_size += nodebox.connect_front.size();
else
boxes_size += nodebox.disconnected_front.size();
if (neighbors & 8) if (neighbors & 8)
boxes_size += nodebox.connect_left.size(); boxes_size += nodebox.connect_left.size();
else
boxes_size += nodebox.disconnected_left.size();
if (neighbors & 16) if (neighbors & 16)
boxes_size += nodebox.connect_back.size(); boxes_size += nodebox.connect_back.size();
else
boxes_size += nodebox.disconnected_back.size();
if (neighbors & 32) if (neighbors & 32)
boxes_size += nodebox.connect_right.size(); 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); boxes.reserve(boxes_size);
#define BOXESPUSHBACK(c) \ #define BOXESPUSHBACK(c) \
@ -442,18 +466,50 @@ void transformNodeBox(const MapNode &n, const NodeBox &nodebox,
BOXESPUSHBACK(nodebox.fixed); BOXESPUSHBACK(nodebox.fixed);
if (neighbors & 1) if (neighbors & 1) {
BOXESPUSHBACK(nodebox.connect_top); BOXESPUSHBACK(nodebox.connect_top);
if (neighbors & 2) } else {
BOXESPUSHBACK(nodebox.disconnected_top);
}
if (neighbors & 2) {
BOXESPUSHBACK(nodebox.connect_bottom); BOXESPUSHBACK(nodebox.connect_bottom);
if (neighbors & 4) } else {
BOXESPUSHBACK(nodebox.disconnected_bottom);
}
if (neighbors & 4) {
BOXESPUSHBACK(nodebox.connect_front); BOXESPUSHBACK(nodebox.connect_front);
if (neighbors & 8) } else {
BOXESPUSHBACK(nodebox.disconnected_front);
}
if (neighbors & 8) {
BOXESPUSHBACK(nodebox.connect_left); BOXESPUSHBACK(nodebox.connect_left);
if (neighbors & 16) } else {
BOXESPUSHBACK(nodebox.disconnected_left);
}
if (neighbors & 16) {
BOXESPUSHBACK(nodebox.connect_back); BOXESPUSHBACK(nodebox.connect_back);
if (neighbors & 32) } else {
BOXESPUSHBACK(nodebox.disconnected_back);
}
if (neighbors & 32) {
BOXESPUSHBACK(nodebox.connect_right); 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 else // NODEBOX_REGULAR
{ {

@ -185,6 +185,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Mod channels Mod channels
Raise ObjectProperties version to 3 for removing 'can_zoom' and adding Raise ObjectProperties version to 3 for removing 'can_zoom' and adding
'zoom_fov'. 'zoom_fov'.
Nodebox version 5
Add disconnected nodeboxes
*/ */
#define LATEST_PROTOCOL_VERSION 36 #define LATEST_PROTOCOL_VERSION 36

@ -61,12 +61,20 @@ void NodeBox::reset()
connect_left.clear(); connect_left.clear();
connect_back.clear(); connect_back.clear();
connect_right.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 void NodeBox::serialize(std::ostream &os, u16 protocol_version) const
{ {
// Protocol >= 36 // Protocol >= 36
int version = 4; int version = 5;
writeU8(os, version); writeU8(os, version);
switch (type) { switch (type) {
@ -107,6 +115,14 @@ void NodeBox::serialize(std::ostream &os, u16 protocol_version) const
WRITEBOX(connect_left); WRITEBOX(connect_left);
WRITEBOX(connect_back); WRITEBOX(connect_back);
WRITEBOX(connect_right); 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; break;
default: default:
writeU8(os, type); writeU8(os, type);
@ -163,6 +179,16 @@ void NodeBox::deSerialize(std::istream &is)
READBOXES(connect_left); READBOXES(connect_left);
READBOXES(connect_back); READBOXES(connect_back);
READBOXES(connect_right); 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);
}
} }
} }
@ -1252,6 +1278,14 @@ void getNodeBoxUnion(const NodeBox &nodebox, const ContentFeatures &features,
boxVectorUnion(nodebox.connect_left, box_union); boxVectorUnion(nodebox.connect_left, box_union);
boxVectorUnion(nodebox.connect_back, box_union); boxVectorUnion(nodebox.connect_back, box_union);
boxVectorUnion(nodebox.connect_right, 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; break;
} }
default: { default: {

@ -107,6 +107,14 @@ struct NodeBox
std::vector<aabb3f> connect_left; std::vector<aabb3f> connect_left;
std::vector<aabb3f> connect_back; std::vector<aabb3f> connect_back;
std::vector<aabb3f> connect_right; 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() NodeBox()
{ reset(); } { reset(); }

@ -1062,6 +1062,14 @@ NodeBox read_nodebox(lua_State *L, int index)
NODEBOXREADVEC(nodebox.connect_left, "connect_left"); NODEBOXREADVEC(nodebox.connect_left, "connect_left");
NODEBOXREADVEC(nodebox.connect_back, "connect_back"); NODEBOXREADVEC(nodebox.connect_back, "connect_back");
NODEBOXREADVEC(nodebox.connect_right, "connect_right"); 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; return nodebox;
} }