Skip to content

Commit 47464c9

Browse files
sofarest31
authored andcommittedFeb 9, 2016
Fix backface culling when connecting to new servers.
Introduce a new contentfeatures version (8). When clients connect using v27 protocol version, they can assume that the tiledef.backface_culling is trustable, but if clients connect to servers providing contentfeatures version 7, then the v27 clients know that backface culling settings provided by the server in tiledefs are bogus for mesh, plantlike, firelike or liquid drawtype nodes. thanks to hmmmm, est31, nerzhul. Tested on new client - new server, new client - old server old client - new server.
1 parent ba8fa9e commit 47464c9

File tree

2 files changed

+43
-50
lines changed

2 files changed

+43
-50
lines changed
 

‎src/nodedef.cpp

+18-25
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void TileDef::serialize(std::ostream &os, u16 protocol_version) const
139139
}
140140
}
141141

142-
void TileDef::deSerialize(std::istream &is, bool culling_ignore)
142+
void TileDef::deSerialize(std::istream &is, const u8 contenfeatures_version, const NodeDrawType drawtype)
143143
{
144144
int version = readU8(is);
145145
name = deSerializeString(is);
@@ -153,10 +153,12 @@ void TileDef::deSerialize(std::istream &is, bool culling_ignore)
153153
tileable_horizontal = readU8(is);
154154
tileable_vertical = readU8(is);
155155
}
156-
// when connecting to old servers - do not use
157-
// provided values here since culling needs to be
158-
// disabled by default for these drawtypes
159-
if (culling_ignore)
156+
157+
if ((contenfeatures_version < 8) &&
158+
((drawtype == NDT_MESH) ||
159+
(drawtype == NDT_FIRELIKE) ||
160+
(drawtype == NDT_LIQUID) ||
161+
(drawtype == NDT_PLANTLIKE)))
160162
backface_culling = false;
161163
}
162164

@@ -268,7 +270,8 @@ void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const
268270
return;
269271
}
270272

271-
writeU8(os, 7); // version
273+
writeU8(os, protocol_version < 27 ? 7 : 8);
274+
272275
os<<serializeString(name);
273276
writeU16(os, groups.size());
274277
for(ItemGroupList::const_iterator
@@ -330,9 +333,11 @@ void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const
330333
void ContentFeatures::deSerialize(std::istream &is)
331334
{
332335
int version = readU8(is);
333-
if(version != 7){
336+
if (version < 7) {
334337
deSerializeOld(is, version);
335338
return;
339+
} else if (version > 8) {
340+
throw SerializationError("unsupported ContentFeatures version");
336341
}
337342

338343
name = deSerializeString(is);
@@ -345,21 +350,15 @@ void ContentFeatures::deSerialize(std::istream &is)
345350
}
346351
drawtype = (enum NodeDrawType)readU8(is);
347352

348-
bool ignore_culling = ((version <= 26) &&
349-
((drawtype == NDT_MESH) ||
350-
(drawtype == NDT_PLANTLIKE) ||
351-
(drawtype == NDT_FIRELIKE) ||
352-
(drawtype == NDT_LIQUID)));
353-
354353
visual_scale = readF1000(is);
355354
if(readU8(is) != 6)
356355
throw SerializationError("unsupported tile count");
357356
for(u32 i = 0; i < 6; i++)
358-
tiledef[i].deSerialize(is, ignore_culling);
357+
tiledef[i].deSerialize(is, version, drawtype);
359358
if(readU8(is) != CF_SPECIAL_COUNT)
360359
throw SerializationError("unsupported CF_SPECIAL_COUNT");
361360
for(u32 i = 0; i < CF_SPECIAL_COUNT; i++)
362-
tiledef_special[i].deSerialize(is, ignore_culling);
361+
tiledef_special[i].deSerialize(is, version, drawtype);
363362
alpha = readU8(is);
364363
post_effect_color.setAlpha(readU8(is));
365364
post_effect_color.setRed(readU8(is));
@@ -1284,21 +1283,15 @@ void ContentFeatures::deSerializeOld(std::istream &is, int version)
12841283
}
12851284
drawtype = (enum NodeDrawType)readU8(is);
12861285

1287-
bool ignore_culling = ((version <= 26) &&
1288-
((drawtype == NDT_MESH) ||
1289-
(drawtype == NDT_PLANTLIKE) ||
1290-
(drawtype == NDT_FIRELIKE) ||
1291-
(drawtype == NDT_LIQUID)));
1292-
12931286
visual_scale = readF1000(is);
12941287
if (readU8(is) != 6)
12951288
throw SerializationError("unsupported tile count");
12961289
for (u32 i = 0; i < 6; i++)
1297-
tiledef[i].deSerialize(is, ignore_culling);
1290+
tiledef[i].deSerialize(is, version, drawtype);
12981291
if (readU8(is) != CF_SPECIAL_COUNT)
12991292
throw SerializationError("unsupported CF_SPECIAL_COUNT");
13001293
for (u32 i = 0; i < CF_SPECIAL_COUNT; i++)
1301-
tiledef_special[i].deSerialize(is, ignore_culling);
1294+
tiledef_special[i].deSerialize(is, version, drawtype);
13021295
alpha = readU8(is);
13031296
post_effect_color.setAlpha(readU8(is));
13041297
post_effect_color.setRed(readU8(is));
@@ -1342,12 +1335,12 @@ void ContentFeatures::deSerializeOld(std::istream &is, int version)
13421335
if (readU8(is) != 6)
13431336
throw SerializationError("unsupported tile count");
13441337
for (u32 i = 0; i < 6; i++)
1345-
tiledef[i].deSerialize(is, drawtype);
1338+
tiledef[i].deSerialize(is, version, drawtype);
13461339
// CF_SPECIAL_COUNT in version 6 = 2
13471340
if (readU8(is) != 2)
13481341
throw SerializationError("unsupported CF_SPECIAL_COUNT");
13491342
for (u32 i = 0; i < 2; i++)
1350-
tiledef_special[i].deSerialize(is, drawtype);
1343+
tiledef_special[i].deSerialize(is, version, drawtype);
13511344
alpha = readU8(is);
13521345
post_effect_color.setAlpha(readU8(is));
13531346
post_effect_color.setRed(readU8(is));

‎src/nodedef.h

+25-25
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,30 @@ struct NodeBox
104104
struct MapNode;
105105
class NodeMetadata;
106106

107+
enum NodeDrawType
108+
{
109+
NDT_NORMAL, // A basic solid block
110+
NDT_AIRLIKE, // Nothing is drawn
111+
NDT_LIQUID, // Do not draw face towards same kind of flowing/source liquid
112+
NDT_FLOWINGLIQUID, // A very special kind of thing
113+
NDT_GLASSLIKE, // Glass-like, don't draw faces towards other glass
114+
NDT_ALLFACES, // Leaves-like, draw all faces no matter what
115+
NDT_ALLFACES_OPTIONAL, // Fancy -> allfaces, fast -> normal
116+
NDT_TORCHLIKE,
117+
NDT_SIGNLIKE,
118+
NDT_PLANTLIKE,
119+
NDT_FENCELIKE,
120+
NDT_RAILLIKE,
121+
NDT_NODEBOX,
122+
NDT_GLASSLIKE_FRAMED, // Glass-like, draw connected frames and all all
123+
// visible faces
124+
// uses 2 textures, one for frames, second for faces
125+
NDT_FIRELIKE, // Draw faces slightly rotated and only on connecting nodes,
126+
NDT_GLASSLIKE_FRAMED_OPTIONAL, // enabled -> connected, disabled -> Glass-like
127+
// uses 2 textures, one for frames, second for faces
128+
NDT_MESH, // Uses static meshes
129+
};
130+
107131
/*
108132
Stand-alone definition of a TileSpec (basically a server-side TileSpec)
109133
*/
@@ -137,31 +161,7 @@ struct TileDef
137161
}
138162

139163
void serialize(std::ostream &os, u16 protocol_version) const;
140-
void deSerialize(std::istream &is, bool culling_ignore);
141-
};
142-
143-
enum NodeDrawType
144-
{
145-
NDT_NORMAL, // A basic solid block
146-
NDT_AIRLIKE, // Nothing is drawn
147-
NDT_LIQUID, // Do not draw face towards same kind of flowing/source liquid
148-
NDT_FLOWINGLIQUID, // A very special kind of thing
149-
NDT_GLASSLIKE, // Glass-like, don't draw faces towards other glass
150-
NDT_ALLFACES, // Leaves-like, draw all faces no matter what
151-
NDT_ALLFACES_OPTIONAL, // Fancy -> allfaces, fast -> normal
152-
NDT_TORCHLIKE,
153-
NDT_SIGNLIKE,
154-
NDT_PLANTLIKE,
155-
NDT_FENCELIKE,
156-
NDT_RAILLIKE,
157-
NDT_NODEBOX,
158-
NDT_GLASSLIKE_FRAMED, // Glass-like, draw connected frames and all all
159-
// visible faces
160-
// uses 2 textures, one for frames, second for faces
161-
NDT_FIRELIKE, // Draw faces slightly rotated and only on connecting nodes,
162-
NDT_GLASSLIKE_FRAMED_OPTIONAL, // enabled -> connected, disabled -> Glass-like
163-
// uses 2 textures, one for frames, second for faces
164-
NDT_MESH, // Uses static meshes
164+
void deSerialize(std::istream &is, const u8 contentfeatures_version, const NodeDrawType drawtype);
165165
};
166166

167167
#define CF_SPECIAL_COUNT 6

0 commit comments

Comments
 (0)
Please sign in to comment.