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.
20 #ifndef NODEDEF_HEADER
21 #define NODEDEF_HEADER
23 #include "irrlichttypes_bloated.h"
28 #include "util/numeric.h"
31 #include "client/tile.h"
33 #include <IMeshManipulator.h>
36 #include "itemgroup.h"
37 #include "sound.h" // SimpleSoundSpec
38 #include "constants.h" // BS
39 #include "tileanimation.h"
41 class INodeDefManager;
42 class IItemDefManager;
48 typedef std::list<std::pair<content_t, int> > GroupItems;
56 enum ContentParamType2
61 // Flowing liquid properties
63 // Direction for chests and furnaces and such
65 // Direction for signs, torches and such
67 // Block level like FLOWINGLIQUID
69 // 2D rotation for things like plants
71 // Mesh options for plants
75 // 3 bits of palette index, then facedir
77 // 5 bits of palette index, then wallmounted
78 CPT2_COLORED_WALLMOUNTED,
79 // Glasslike framed drawtype internal liquid level, param2 values 0 to 63
80 CPT2_GLASSLIKE_LIQUID_LEVEL,
92 NODEBOX_REGULAR, // Regular block; allows buildable_to
93 NODEBOX_FIXED, // Static separately defined box(es)
94 NODEBOX_WALLMOUNTED, // Box for wall mounted nodes; (top, bottom, side)
95 NODEBOX_LEVELED, // Same as fixed, but with dynamic height from param2. for snow, ...
96 NODEBOX_CONNECTED, // optionally draws nodeboxes if a neighbor node attaches
101 enum NodeBoxType type;
102 // NODEBOX_REGULAR (no parameters)
104 std::vector<aabb3f> fixed;
105 // NODEBOX_WALLMOUNTED
108 aabb3f wall_side; // being at the -X side
110 std::vector<aabb3f> connect_top;
111 std::vector<aabb3f> connect_bottom;
112 std::vector<aabb3f> connect_front;
113 std::vector<aabb3f> connect_left;
114 std::vector<aabb3f> connect_back;
115 std::vector<aabb3f> connect_right;
121 void serialize(std::ostream &os, u16 protocol_version) const;
122 void deSerialize(std::istream &is);
134 class TextureSettings {
136 LeavesStyle leaves_style;
138 bool connected_glass;
139 bool use_normal_texture;
140 bool enable_mesh_cache;
150 // A basic solid block
154 // Do not draw face towards same kind of flowing/source liquid
156 // A very special kind of thing
158 // Glass-like, don't draw faces towards other glass
160 // Leaves-like, draw all faces no matter what
162 // Enabled -> ndt_allfaces, disabled -> ndt_normal
163 NDT_ALLFACES_OPTIONAL,
164 // Single plane perpendicular to a surface
166 // Single plane parallel to a surface
168 // 2 vertical planes in a 'X' shape diagonal to XZ axes.
169 // paramtype2 = "meshoptions" allows various forms, sizes and
170 // vertical and horizontal random offsets.
172 // Fenceposts that connect to neighbouring fenceposts with horizontal bars
174 // Selects appropriate junction texture to connect like rails to
175 // neighbouring raillikes.
177 // Custom Lua-definable structure of multiple cuboids
179 // Glass-like, draw connected frames and all visible faces.
180 // param2 > 0 defines 64 levels of internal liquid
181 // Uses 3 textures, one for frames, second for faces,
182 // optional third is a 'special tile' for the liquid.
183 NDT_GLASSLIKE_FRAMED,
184 // Draw faces slightly rotated and only on neighbouring nodes
186 // Enabled -> ndt_glasslike_framed, disabled -> ndt_glasslike
187 NDT_GLASSLIKE_FRAMED_OPTIONAL,
188 // Uses static meshes
192 // Mesh options for NDT_PLANTLIKE with CPT2_MESHOPTIONS
193 static const u8 MO_MASK_STYLE = 0x07;
194 static const u8 MO_BIT_RANDOM_OFFSET = 0x08;
195 static const u8 MO_BIT_SCALE_SQRT2 = 0x10;
196 static const u8 MO_BIT_RANDOM_OFFSET_Y = 0x20;
197 enum PlantlikeStyle {
206 Stand-alone definition of a TileSpec (basically a server-side TileSpec)
211 std::string name = "";
212 bool backface_culling = true; // Takes effect only in special cases
213 bool tileable_horizontal = true;
214 bool tileable_vertical = true;
215 //! If true, the tile has its own color.
216 bool has_color = false;
217 //! The color of the tile.
218 video::SColor color = video::SColor(0xFFFFFFFF);
220 struct TileAnimationParams animation;
224 animation.type = TAT_NONE;
227 void serialize(std::ostream &os, u16 protocol_version) const;
228 void deSerialize(std::istream &is, const u8 contentfeatures_version, const NodeDrawType drawtype);
231 #define CF_SPECIAL_COUNT 6
233 struct ContentFeatures
240 // up down right left back front
243 // - Currently used for flowing liquids
244 TileSpec special_tiles[CF_SPECIAL_COUNT];
245 u8 solidness; // Used when choosing which face is drawn
246 u8 visual_solidness; // When solidness=0, this tells how it looks like
247 bool backface_culling;
250 // Server-side cached callback existence for fast skipping
251 bool has_on_construct;
252 bool has_on_destruct;
253 bool has_after_destruct;
259 // --- GENERAL PROPERTIES ---
261 std::string name; // "" = undefined node
262 ItemGroupList groups; // Same as in itemdef
263 // Type of MapNode::param1
264 ContentParamType param_type;
265 // Type of MapNode::param2
266 ContentParamType2 param_type_2;
268 // --- VISUAL PROPERTIES ---
270 enum NodeDrawType drawtype;
273 scene::IMesh *mesh_ptr[24];
274 video::SColor minimap_color;
276 float visual_scale; // Misc. scale parameter
278 // These will be drawn over the base tiles.
279 TileDef tiledef_overlay[6];
280 TileDef tiledef_special[CF_SPECIAL_COUNT]; // eg. flowing liquid
281 // If 255, the node is opaque.
282 // Otherwise it uses texture alpha.
284 // The color of the node.
286 std::string palette_name;
287 std::vector<video::SColor> *palette;
288 // Used for waving leaves/plants
290 // for NDT_CONNECTED pairing
292 std::vector<std::string> connects_to;
293 std::set<content_t> connects_to_ids;
294 // Post effect color, drawn when the camera is inside the node.
295 video::SColor post_effect_color;
296 // Flowing liquid or snow, value = default level
299 // --- LIGHTING-RELATED ---
301 bool light_propagates;
302 bool sunlight_propagates;
303 // Amount of light the node emits
306 // --- MAP GENERATION ---
308 // True for all ground-like things like stone and mud, false for eg. trees
309 bool is_ground_content;
311 // --- INTERACTION PROPERTIES ---
313 // This is used for collision detection.
314 // Also for general solidness queries.
316 // Player can point to these
318 // Player can dig these
320 // Player can climb these
322 // Player can build on these
324 // Player cannot build to these (placement prediction disabled)
326 u32 damage_per_second;
328 // --- LIQUID PROPERTIES ---
330 // Whether the node is non-liquid, source liquid or flowing liquid
331 enum LiquidType liquid_type;
332 // If the content is liquid, this is the flowing version of the liquid.
333 std::string liquid_alternative_flowing;
334 // If the content is liquid, this is the source version of the liquid.
335 std::string liquid_alternative_source;
336 // Viscosity for fluid flow, ranging from 1 to 7, with
337 // 1 giving almost instantaneous propagation and 7 being
338 // the slowest possible
340 // Is liquid renewable (new liquid source will be created between 2 existing)
341 bool liquid_renewable;
342 // Number of flowing liquids surrounding source
345 // Liquids flow into and replace node
351 NodeBox selection_box;
352 NodeBox collision_box;
354 // --- SOUND PROPERTIES ---
356 SimpleSoundSpec sound_footstep;
357 SimpleSoundSpec sound_dig;
358 SimpleSoundSpec sound_dug;
362 // Compatibility with old maps
363 // Set to true if paramtype used to be 'facedir_simple'
364 bool legacy_facedir_simple;
365 // Set to true if wall_mounted used to be set to true
366 bool legacy_wallmounted;
375 void serialize(std::ostream &os, u16 protocol_version) const;
376 void deSerialize(std::istream &is);
377 void serializeOld(std::ostream &os, u16 protocol_version) const;
378 void deSerializeOld(std::istream &is, int version);
380 * Since vertex alpha is no longer supported, this method
381 * adds opacity directly to the texture pixels.
383 * \param tiles array of the tile definitions.
384 * \param length length of tiles
386 void correctAlpha(TileDef *tiles, int length);
391 bool isLiquid() const{
392 return (liquid_type != LIQUID_NONE);
394 bool sameLiquid(const ContentFeatures &f) const{
395 if(!isLiquid() || !f.isLiquid()) return false;
396 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
399 int getGroup(const std::string &group) const
401 return itemgroup_get(groups, group);
405 void fillTileAttribs(ITextureSource *tsrc, TileLayer *tile, TileDef *tiledef,
406 u32 shader_id, bool use_normal_texture, bool backface_culling,
408 void updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc,
409 scene::IMeshManipulator *meshmanip, Client *client, const TextureSettings &tsettings);
413 class INodeDefManager {
416 virtual ~INodeDefManager(){}
417 // Get node definition
418 virtual const ContentFeatures &get(content_t c) const=0;
419 virtual const ContentFeatures &get(const MapNode &n) const=0;
420 virtual bool getId(const std::string &name, content_t &result) const=0;
421 virtual content_t getId(const std::string &name) const=0;
422 // Allows "group:name" in addition to regular node names
423 // returns false if node name not found, true otherwise
424 virtual bool getIds(const std::string &name, std::set<content_t> &result)
426 virtual const ContentFeatures &get(const std::string &name) const=0;
428 virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
430 virtual void pendNodeResolve(NodeResolver *nr)=0;
431 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
432 virtual bool nodeboxConnects(const MapNode from, const MapNode to, u8 connect_face)=0;
434 * Returns the smallest box in node coordinates that
435 * contains all nodes' selection boxes.
437 virtual core::aabbox3d<s16> getSelectionBoxIntUnion() const=0;
440 class IWritableNodeDefManager : public INodeDefManager {
442 IWritableNodeDefManager(){}
443 virtual ~IWritableNodeDefManager(){}
444 virtual IWritableNodeDefManager* clone()=0;
445 // Get node definition
446 virtual const ContentFeatures &get(content_t c) const=0;
447 virtual const ContentFeatures &get(const MapNode &n) const=0;
448 virtual bool getId(const std::string &name, content_t &result) const=0;
449 // If not found, returns CONTENT_IGNORE
450 virtual content_t getId(const std::string &name) const=0;
451 // Allows "group:name" in addition to regular node names
452 virtual bool getIds(const std::string &name, std::set<content_t> &result)
454 // If not found, returns the features of CONTENT_UNKNOWN
455 virtual const ContentFeatures &get(const std::string &name) const=0;
457 // Register node definition by name (allocate an id)
458 // If returns CONTENT_IGNORE, could not allocate id
459 virtual content_t set(const std::string &name,
460 const ContentFeatures &def)=0;
461 // If returns CONTENT_IGNORE, could not allocate id
462 virtual content_t allocateDummy(const std::string &name)=0;
464 virtual void removeNode(const std::string &name)=0;
467 Update item alias mapping.
468 Call after updating item definitions.
470 virtual void updateAliases(IItemDefManager *idef)=0;
473 Override textures from servers with ones specified in texturepack/override.txt
475 virtual void applyTextureOverrides(const std::string &override_filepath)=0;
478 Update tile textures to latest return values of TextueSource.
480 virtual void updateTextures(IGameDef *gamedef,
481 void (*progress_cbk)(void *progress_args, u32 progress, u32 max_progress),
482 void *progress_cbk_args)=0;
484 virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
485 virtual void deSerialize(std::istream &is)=0;
487 virtual void setNodeRegistrationStatus(bool completed)=0;
489 virtual void pendNodeResolve(NodeResolver *nr)=0;
490 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
491 virtual void runNodeResolveCallbacks()=0;
492 virtual void resetNodeResolveState()=0;
493 virtual void mapNodeboxConnections()=0;
494 virtual core::aabbox3d<s16> getSelectionBoxIntUnion() const=0;
497 IWritableNodeDefManager *createNodeDefManager();
502 virtual ~NodeResolver();
503 virtual void resolveNodeNames() = 0;
505 bool getIdFromNrBacklog(content_t *result_out,
506 const std::string &node_alt, content_t c_fallback);
507 bool getIdsFromNrBacklog(std::vector<content_t> *result_out,
508 bool all_required=false, content_t c_fallback=CONTENT_IGNORE);
510 void nodeResolveInternal();
512 u32 m_nodenames_idx = 0;
513 u32 m_nnlistsizes_idx = 0;
514 std::vector<std::string> m_nodenames;
515 std::vector<size_t> m_nnlistsizes;
516 INodeDefManager *m_ndef = nullptr;
517 bool m_resolve_done = false;