3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "irrlichttypes_bloated.h"
28 #include "client/tile.h"
29 #include <IMeshManipulator.h>
32 #include "itemgroup.h"
33 #include "sound.h" // SimpleSoundSpec
34 #include "constants.h" // BS
35 #include "tileanimation.h"
37 class INodeDefManager;
38 class IItemDefManager;
50 enum ContentParamType2
55 // Flowing liquid properties
57 // Direction for chests and furnaces and such
59 // Direction for signs, torches and such
61 // Block level like FLOWINGLIQUID
63 // 2D rotation for things like plants
65 // Mesh options for plants
69 // 3 bits of palette index, then facedir
71 // 5 bits of palette index, then wallmounted
72 CPT2_COLORED_WALLMOUNTED,
73 // Glasslike framed drawtype internal liquid level, param2 values 0 to 63
74 CPT2_GLASSLIKE_LIQUID_LEVEL,
86 NODEBOX_REGULAR, // Regular block; allows buildable_to
87 NODEBOX_FIXED, // Static separately defined box(es)
88 NODEBOX_WALLMOUNTED, // Box for wall mounted nodes; (top, bottom, side)
89 NODEBOX_LEVELED, // Same as fixed, but with dynamic height from param2. for snow, ...
90 NODEBOX_CONNECTED, // optionally draws nodeboxes if a neighbor node attaches
95 enum NodeBoxType type;
96 // NODEBOX_REGULAR (no parameters)
98 std::vector<aabb3f> fixed;
99 // NODEBOX_WALLMOUNTED
102 aabb3f wall_side; // being at the -X side
104 std::vector<aabb3f> connect_top;
105 std::vector<aabb3f> connect_bottom;
106 std::vector<aabb3f> connect_front;
107 std::vector<aabb3f> connect_left;
108 std::vector<aabb3f> connect_back;
109 std::vector<aabb3f> connect_right;
110 std::vector<aabb3f> disconnected_top;
111 std::vector<aabb3f> disconnected_bottom;
112 std::vector<aabb3f> disconnected_front;
113 std::vector<aabb3f> disconnected_left;
114 std::vector<aabb3f> disconnected_back;
115 std::vector<aabb3f> disconnected_right;
116 std::vector<aabb3f> disconnected;
117 std::vector<aabb3f> disconnected_sides;
123 void serialize(std::ostream &os, u16 protocol_version) const;
124 void deSerialize(std::istream &is);
136 enum AutoScale : u8 {
142 enum WorldAlignMode : u8 {
146 WORLDALIGN_FORCE_NODEBOX,
149 class TextureSettings {
151 LeavesStyle leaves_style;
152 WorldAlignMode world_aligned_mode;
153 AutoScale autoscale_mode;
154 int node_texture_size;
156 bool connected_glass;
157 bool use_normal_texture;
158 bool enable_mesh_cache;
161 TextureSettings() = default;
168 // A basic solid block
172 // Do not draw face towards same kind of flowing/source liquid
174 // A very special kind of thing
176 // Glass-like, don't draw faces towards other glass
178 // Leaves-like, draw all faces no matter what
180 // Enabled -> ndt_allfaces, disabled -> ndt_normal
181 NDT_ALLFACES_OPTIONAL,
182 // Single plane perpendicular to a surface
184 // Single plane parallel to a surface
186 // 2 vertical planes in a 'X' shape diagonal to XZ axes.
187 // paramtype2 = "meshoptions" allows various forms, sizes and
188 // vertical and horizontal random offsets.
190 // Fenceposts that connect to neighbouring fenceposts with horizontal bars
192 // Selects appropriate junction texture to connect like rails to
193 // neighbouring raillikes.
195 // Custom Lua-definable structure of multiple cuboids
197 // Glass-like, draw connected frames and all visible faces.
198 // param2 > 0 defines 64 levels of internal liquid
199 // Uses 3 textures, one for frames, second for faces,
200 // optional third is a 'special tile' for the liquid.
201 NDT_GLASSLIKE_FRAMED,
202 // Draw faces slightly rotated and only on neighbouring nodes
204 // Enabled -> ndt_glasslike_framed, disabled -> ndt_glasslike
205 NDT_GLASSLIKE_FRAMED_OPTIONAL,
206 // Uses static meshes
208 // Combined plantlike-on-solid
209 NDT_PLANTLIKE_ROOTED,
212 // Mesh options for NDT_PLANTLIKE with CPT2_MESHOPTIONS
213 static const u8 MO_MASK_STYLE = 0x07;
214 static const u8 MO_BIT_RANDOM_OFFSET = 0x08;
215 static const u8 MO_BIT_SCALE_SQRT2 = 0x10;
216 static const u8 MO_BIT_RANDOM_OFFSET_Y = 0x20;
217 enum PlantlikeStyle {
225 enum AlignStyle : u8 {
228 ALIGN_STYLE_USER_DEFINED,
232 Stand-alone definition of a TileSpec (basically a server-side TileSpec)
237 std::string name = "";
238 bool backface_culling = true; // Takes effect only in special cases
239 bool tileable_horizontal = true;
240 bool tileable_vertical = true;
241 //! If true, the tile has its own color.
242 bool has_color = false;
243 //! The color of the tile.
244 video::SColor color = video::SColor(0xFFFFFFFF);
245 AlignStyle align_style = ALIGN_STYLE_NODE;
248 struct TileAnimationParams animation;
252 animation.type = TAT_NONE;
255 void serialize(std::ostream &os, u16 protocol_version) const;
256 void deSerialize(std::istream &is, u8 contentfeatures_version,
257 NodeDrawType drawtype);
260 #define CF_SPECIAL_COUNT 6
262 struct ContentFeatures
269 // up down right left back front
272 // - Currently used for flowing liquids
273 TileSpec special_tiles[CF_SPECIAL_COUNT];
274 u8 solidness; // Used when choosing which face is drawn
275 u8 visual_solidness; // When solidness=0, this tells how it looks like
276 bool backface_culling;
279 // Server-side cached callback existence for fast skipping
280 bool has_on_construct;
281 bool has_on_destruct;
282 bool has_after_destruct;
288 // --- GENERAL PROPERTIES ---
290 std::string name; // "" = undefined node
291 ItemGroupList groups; // Same as in itemdef
292 // Type of MapNode::param1
293 ContentParamType param_type;
294 // Type of MapNode::param2
295 ContentParamType2 param_type_2;
297 // --- VISUAL PROPERTIES ---
299 enum NodeDrawType drawtype;
302 scene::IMesh *mesh_ptr[24];
303 video::SColor minimap_color;
305 float visual_scale; // Misc. scale parameter
307 // These will be drawn over the base tiles.
308 TileDef tiledef_overlay[6];
309 TileDef tiledef_special[CF_SPECIAL_COUNT]; // eg. flowing liquid
310 // If 255, the node is opaque.
311 // Otherwise it uses texture alpha.
313 // The color of the node.
315 std::string palette_name;
316 std::vector<video::SColor> *palette;
317 // Used for waving leaves/plants
319 // for NDT_CONNECTED pairing
321 std::vector<std::string> connects_to;
322 std::vector<content_t> connects_to_ids;
323 // Post effect color, drawn when the camera is inside the node.
324 video::SColor post_effect_color;
325 // Flowing liquid or snow, value = default level
328 // --- LIGHTING-RELATED ---
330 bool light_propagates;
331 bool sunlight_propagates;
332 // Amount of light the node emits
335 // --- MAP GENERATION ---
337 // True for all ground-like things like stone and mud, false for eg. trees
338 bool is_ground_content;
340 // --- INTERACTION PROPERTIES ---
342 // This is used for collision detection.
343 // Also for general solidness queries.
345 // Player can point to these
347 // Player can dig these
349 // Player can climb these
351 // Player can build on these
353 // Player cannot build to these (placement prediction disabled)
355 u32 damage_per_second;
356 // client dig prediction
357 std::string node_dig_prediction;
359 // --- LIQUID PROPERTIES ---
361 // Whether the node is non-liquid, source liquid or flowing liquid
362 enum LiquidType liquid_type;
363 // If the content is liquid, this is the flowing version of the liquid.
364 std::string liquid_alternative_flowing;
365 // If the content is liquid, this is the source version of the liquid.
366 std::string liquid_alternative_source;
367 // Viscosity for fluid flow, ranging from 1 to 7, with
368 // 1 giving almost instantaneous propagation and 7 being
369 // the slowest possible
371 // Is liquid renewable (new liquid source will be created between 2 existing)
372 bool liquid_renewable;
373 // Number of flowing liquids surrounding source
376 // Liquids flow into and replace node
382 NodeBox selection_box;
383 NodeBox collision_box;
385 // --- SOUND PROPERTIES ---
387 SimpleSoundSpec sound_footstep;
388 SimpleSoundSpec sound_dig;
389 SimpleSoundSpec sound_dug;
393 // Compatibility with old maps
394 // Set to true if paramtype used to be 'facedir_simple'
395 bool legacy_facedir_simple;
396 // Set to true if wall_mounted used to be set to true
397 bool legacy_wallmounted;
404 ~ContentFeatures() = default;
406 void serialize(std::ostream &os, u16 protocol_version) const;
407 void deSerialize(std::istream &is);
408 void serializeOld(std::ostream &os, u16 protocol_version) const;
409 void deSerializeOld(std::istream &is, int version);
411 * Since vertex alpha is no longer supported, this method
412 * adds opacity directly to the texture pixels.
414 * \param tiles array of the tile definitions.
415 * \param length length of tiles
417 void correctAlpha(TileDef *tiles, int length);
422 bool isLiquid() const{
423 return (liquid_type != LIQUID_NONE);
425 bool sameLiquid(const ContentFeatures &f) const{
426 if(!isLiquid() || !f.isLiquid()) return false;
427 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
430 int getGroup(const std::string &group) const
432 return itemgroup_get(groups, group);
436 void updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc,
437 scene::IMeshManipulator *meshmanip, Client *client, const TextureSettings &tsettings);
441 class INodeDefManager {
443 INodeDefManager() = default;
444 virtual ~INodeDefManager() = default;
446 // Get node definition
447 virtual const ContentFeatures &get(content_t c) const=0;
448 virtual const ContentFeatures &get(const MapNode &n) const=0;
449 virtual bool getId(const std::string &name, content_t &result) const=0;
450 virtual content_t getId(const std::string &name) const=0;
451 // Allows "group:name" in addition to regular node names
452 // returns false if node name not found, true otherwise
453 virtual bool getIds(const std::string &name, std::vector<content_t> &result)
455 virtual const ContentFeatures &get(const std::string &name) const=0;
457 virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
459 virtual void pendNodeResolve(NodeResolver *nr)=0;
460 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
461 virtual bool nodeboxConnects(const MapNode from, const MapNode to, u8 connect_face)=0;
463 * Returns the smallest box in node coordinates that
464 * contains all nodes' selection boxes.
466 virtual core::aabbox3d<s16> getSelectionBoxIntUnion() const=0;
469 class IWritableNodeDefManager : public INodeDefManager {
471 IWritableNodeDefManager() = default;
472 virtual ~IWritableNodeDefManager() = default;
474 // Get node definition
475 virtual const ContentFeatures &get(content_t c) const=0;
476 virtual const ContentFeatures &get(const MapNode &n) const=0;
477 virtual bool getId(const std::string &name, content_t &result) const=0;
478 // If not found, returns CONTENT_IGNORE
479 virtual content_t getId(const std::string &name) const=0;
480 // Allows "group:name" in addition to regular node names
481 virtual bool getIds(const std::string &name, std::vector<content_t> &result)
483 // If not found, returns the features of CONTENT_UNKNOWN
484 virtual const ContentFeatures &get(const std::string &name) const=0;
486 // Register node definition by name (allocate an id)
487 // If returns CONTENT_IGNORE, could not allocate id
488 virtual content_t set(const std::string &name,
489 const ContentFeatures &def)=0;
490 // If returns CONTENT_IGNORE, could not allocate id
491 virtual content_t allocateDummy(const std::string &name)=0;
493 virtual void removeNode(const std::string &name)=0;
496 Update item alias mapping.
497 Call after updating item definitions.
499 virtual void updateAliases(IItemDefManager *idef)=0;
502 Override textures from servers with ones specified in texturepack/override.txt
504 virtual void applyTextureOverrides(const std::string &override_filepath)=0;
507 Update tile textures to latest return values of TextueSource.
509 virtual void updateTextures(IGameDef *gamedef,
510 void (*progress_cbk)(void *progress_args, u32 progress, u32 max_progress),
511 void *progress_cbk_args)=0;
513 virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
514 virtual void deSerialize(std::istream &is)=0;
516 virtual void setNodeRegistrationStatus(bool completed)=0;
518 virtual void pendNodeResolve(NodeResolver *nr)=0;
519 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
520 virtual void runNodeResolveCallbacks()=0;
521 virtual void resetNodeResolveState()=0;
522 virtual void mapNodeboxConnections()=0;
523 virtual core::aabbox3d<s16> getSelectionBoxIntUnion() const=0;
526 IWritableNodeDefManager *createNodeDefManager();
531 virtual ~NodeResolver();
532 virtual void resolveNodeNames() = 0;
534 bool getIdFromNrBacklog(content_t *result_out,
535 const std::string &node_alt, content_t c_fallback);
536 bool getIdsFromNrBacklog(std::vector<content_t> *result_out,
537 bool all_required=false, content_t c_fallback=CONTENT_IGNORE);
539 void nodeResolveInternal();
541 u32 m_nodenames_idx = 0;
542 u32 m_nnlistsizes_idx = 0;
543 std::vector<std::string> m_nodenames;
544 std::vector<size_t> m_nnlistsizes;
545 INodeDefManager *m_ndef = nullptr;
546 bool m_resolve_done = false;