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"
35 #include "itemgroup.h"
36 #include "sound.h" // SimpleSoundSpec
37 #include "constants.h" // BS
38 #include "tileanimation.h"
40 class INodeDefManager;
41 class IItemDefManager;
47 typedef std::list<std::pair<content_t, int> > GroupItems;
55 enum ContentParamType2
60 // Flowing liquid properties
62 // Direction for chests and furnaces and such
64 // Direction for signs, torches and such
66 // Block level like FLOWINGLIQUID
68 // 2D rotation for things like plants
70 // Mesh options for plants
74 // 3 bits of palette index, then facedir
76 // 5 bits of palette index, then wallmounted
77 CPT2_COLORED_WALLMOUNTED,
78 // Glasslike framed drawtype internal liquid level, param2 values 0 to 63
79 CPT2_GLASSLIKE_LIQUID_LEVEL,
91 NODEBOX_REGULAR, // Regular block; allows buildable_to
92 NODEBOX_FIXED, // Static separately defined box(es)
93 NODEBOX_WALLMOUNTED, // Box for wall mounted nodes; (top, bottom, side)
94 NODEBOX_LEVELED, // Same as fixed, but with dynamic height from param2. for snow, ...
95 NODEBOX_CONNECTED, // optionally draws nodeboxes if a neighbor node attaches
100 enum NodeBoxType type;
101 // NODEBOX_REGULAR (no parameters)
103 std::vector<aabb3f> fixed;
104 // NODEBOX_WALLMOUNTED
107 aabb3f wall_side; // being at the -X side
109 std::vector<aabb3f> connect_top;
110 std::vector<aabb3f> connect_bottom;
111 std::vector<aabb3f> connect_front;
112 std::vector<aabb3f> connect_left;
113 std::vector<aabb3f> connect_back;
114 std::vector<aabb3f> connect_right;
120 void serialize(std::ostream &os, u16 protocol_version) const;
121 void deSerialize(std::istream &is);
133 class TextureSettings {
135 LeavesStyle leaves_style;
137 bool connected_glass;
138 bool use_normal_texture;
139 bool enable_mesh_cache;
149 // A basic solid block
153 // Do not draw face towards same kind of flowing/source liquid
155 // A very special kind of thing
157 // Glass-like, don't draw faces towards other glass
159 // Leaves-like, draw all faces no matter what
161 // Enabled -> ndt_allfaces, disabled -> ndt_normal
162 NDT_ALLFACES_OPTIONAL,
163 // Single plane perpendicular to a surface
165 // Single plane parallel to a surface
167 // 2 vertical planes in a 'X' shape diagonal to XZ axes.
168 // paramtype2 = "meshoptions" allows various forms, sizes and
169 // vertical and horizontal random offsets.
171 // Fenceposts that connect to neighbouring fenceposts with horizontal bars
173 // Selects appropriate junction texture to connect like rails to
174 // neighbouring raillikes.
176 // Custom Lua-definable structure of multiple cuboids
178 // Glass-like, draw connected frames and all visible faces.
179 // param2 > 0 defines 64 levels of internal liquid
180 // Uses 3 textures, one for frames, second for faces,
181 // optional third is a 'special tile' for the liquid.
182 NDT_GLASSLIKE_FRAMED,
183 // Draw faces slightly rotated and only on neighbouring nodes
185 // Enabled -> ndt_glasslike_framed, disabled -> ndt_glasslike
186 NDT_GLASSLIKE_FRAMED_OPTIONAL,
187 // Uses static meshes
191 // Mesh options for NDT_PLANTLIKE with CPT2_MESHOPTIONS
192 static const u8 MO_MASK_STYLE = 0x07;
193 static const u8 MO_BIT_RANDOM_OFFSET = 0x08;
194 static const u8 MO_BIT_SCALE_SQRT2 = 0x10;
195 static const u8 MO_BIT_RANDOM_OFFSET_Y = 0x20;
196 enum PlantlikeStyle {
205 Stand-alone definition of a TileSpec (basically a server-side TileSpec)
211 bool backface_culling; // Takes effect only in special cases
212 bool tileable_horizontal;
213 bool tileable_vertical;
214 //! If true, the tile has its own color.
216 //! The color of the tile.
219 struct TileAnimationParams animation;
223 backface_culling(true),
224 tileable_horizontal(true),
225 tileable_vertical(true),
227 color(video::SColor(0xFFFFFFFF))
229 animation.type = TAT_NONE;
232 void serialize(std::ostream &os, u16 protocol_version) const;
233 void deSerialize(std::istream &is, const u8 contentfeatures_version, const NodeDrawType drawtype);
236 #define CF_SPECIAL_COUNT 6
238 struct ContentFeatures
245 // up down right left back front
248 // - Currently used for flowing liquids
249 TileSpec special_tiles[CF_SPECIAL_COUNT];
250 u8 solidness; // Used when choosing which face is drawn
251 u8 visual_solidness; // When solidness=0, this tells how it looks like
252 bool backface_culling;
255 // Server-side cached callback existence for fast skipping
256 bool has_on_construct;
257 bool has_on_destruct;
258 bool has_after_destruct;
264 // --- GENERAL PROPERTIES ---
266 std::string name; // "" = undefined node
267 ItemGroupList groups; // Same as in itemdef
268 // Type of MapNode::param1
269 ContentParamType param_type;
270 // Type of MapNode::param2
271 ContentParamType2 param_type_2;
273 // --- VISUAL PROPERTIES ---
275 enum NodeDrawType drawtype;
278 scene::IMesh *mesh_ptr[24];
279 video::SColor minimap_color;
281 float visual_scale; // Misc. scale parameter
283 // These will be drawn over the base tiles.
284 TileDef tiledef_overlay[6];
285 TileDef tiledef_special[CF_SPECIAL_COUNT]; // eg. flowing liquid
286 // If 255, the node is opaque.
287 // Otherwise it uses texture alpha.
289 // The color of the node.
291 std::string palette_name;
292 std::vector<video::SColor> *palette;
293 // Used for waving leaves/plants
295 // for NDT_CONNECTED pairing
297 std::vector<std::string> connects_to;
298 std::set<content_t> connects_to_ids;
299 // Post effect color, drawn when the camera is inside the node.
300 video::SColor post_effect_color;
301 // Flowing liquid or snow, value = default level
304 // --- LIGHTING-RELATED ---
306 bool light_propagates;
307 bool sunlight_propagates;
308 // Amount of light the node emits
311 // --- MAP GENERATION ---
313 // True for all ground-like things like stone and mud, false for eg. trees
314 bool is_ground_content;
316 // --- INTERACTION PROPERTIES ---
318 // This is used for collision detection.
319 // Also for general solidness queries.
321 // Player can point to these
323 // Player can dig these
325 // Player can climb these
327 // Player can build on these
329 // Player cannot build to these (placement prediction disabled)
331 u32 damage_per_second;
333 // --- LIQUID PROPERTIES ---
335 // Whether the node is non-liquid, source liquid or flowing liquid
336 enum LiquidType liquid_type;
337 // If the content is liquid, this is the flowing version of the liquid.
338 std::string liquid_alternative_flowing;
339 // If the content is liquid, this is the source version of the liquid.
340 std::string liquid_alternative_source;
341 // Viscosity for fluid flow, ranging from 1 to 7, with
342 // 1 giving almost instantaneous propagation and 7 being
343 // the slowest possible
345 // Is liquid renewable (new liquid source will be created between 2 existing)
346 bool liquid_renewable;
347 // Number of flowing liquids surrounding source
350 // Liquids flow into and replace node
356 NodeBox selection_box;
357 NodeBox collision_box;
359 // --- SOUND PROPERTIES ---
361 SimpleSoundSpec sound_footstep;
362 SimpleSoundSpec sound_dig;
363 SimpleSoundSpec sound_dug;
367 // Compatibility with old maps
368 // Set to true if paramtype used to be 'facedir_simple'
369 bool legacy_facedir_simple;
370 // Set to true if wall_mounted used to be set to true
371 bool legacy_wallmounted;
380 void serialize(std::ostream &os, u16 protocol_version) const;
381 void deSerialize(std::istream &is);
382 void serializeOld(std::ostream &os, u16 protocol_version) const;
383 void deSerializeOld(std::istream &is, int version);
385 * Since vertex alpha is no lnger supported, this method
386 * adds instructions to the texture names to blend alpha there.
388 * tiledef, tiledef_special and alpha must be initialized
389 * before calling this.
396 bool isLiquid() const{
397 return (liquid_type != LIQUID_NONE);
399 bool sameLiquid(const ContentFeatures &f) const{
400 if(!isLiquid() || !f.isLiquid()) return false;
401 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
404 int getGroup(const std::string &group) const
406 return itemgroup_get(groups, group);
410 void fillTileAttribs(ITextureSource *tsrc, TileLayer *tile, TileDef *tiledef,
411 u32 shader_id, bool use_normal_texture, bool backface_culling,
413 void updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc,
414 scene::IMeshManipulator *meshmanip, Client *client, const TextureSettings &tsettings);
418 class INodeDefManager {
421 virtual ~INodeDefManager(){}
422 // Get node definition
423 virtual const ContentFeatures &get(content_t c) const=0;
424 virtual const ContentFeatures &get(const MapNode &n) const=0;
425 virtual bool getId(const std::string &name, content_t &result) const=0;
426 virtual content_t getId(const std::string &name) const=0;
427 // Allows "group:name" in addition to regular node names
428 // returns false if node name not found, true otherwise
429 virtual bool getIds(const std::string &name, std::set<content_t> &result)
431 virtual const ContentFeatures &get(const std::string &name) const=0;
433 virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
435 virtual bool getNodeRegistrationStatus() const=0;
437 virtual void pendNodeResolve(NodeResolver *nr)=0;
438 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
439 virtual bool nodeboxConnects(const MapNode from, const MapNode to, u8 connect_face)=0;
441 * Returns the smallest box in node coordinates that
442 * contains all nodes' selection boxes.
444 virtual core::aabbox3d<s16> getSelectionBoxIntUnion() const=0;
447 class IWritableNodeDefManager : public INodeDefManager {
449 IWritableNodeDefManager(){}
450 virtual ~IWritableNodeDefManager(){}
451 virtual IWritableNodeDefManager* clone()=0;
452 // Get node definition
453 virtual const ContentFeatures &get(content_t c) const=0;
454 virtual const ContentFeatures &get(const MapNode &n) const=0;
455 virtual bool getId(const std::string &name, content_t &result) const=0;
456 // If not found, returns CONTENT_IGNORE
457 virtual content_t getId(const std::string &name) const=0;
458 // Allows "group:name" in addition to regular node names
459 virtual bool getIds(const std::string &name, std::set<content_t> &result)
461 // If not found, returns the features of CONTENT_UNKNOWN
462 virtual const ContentFeatures &get(const std::string &name) const=0;
464 // Register node definition by name (allocate an id)
465 // If returns CONTENT_IGNORE, could not allocate id
466 virtual content_t set(const std::string &name,
467 const ContentFeatures &def)=0;
468 // If returns CONTENT_IGNORE, could not allocate id
469 virtual content_t allocateDummy(const std::string &name)=0;
471 virtual void removeNode(const std::string &name)=0;
474 Update item alias mapping.
475 Call after updating item definitions.
477 virtual void updateAliases(IItemDefManager *idef)=0;
480 Override textures from servers with ones specified in texturepack/override.txt
482 virtual void applyTextureOverrides(const std::string &override_filepath)=0;
485 Update tile textures to latest return values of TextueSource.
487 virtual void updateTextures(IGameDef *gamedef,
488 void (*progress_cbk)(void *progress_args, u32 progress, u32 max_progress),
489 void *progress_cbk_args)=0;
491 virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
492 virtual void deSerialize(std::istream &is)=0;
494 virtual bool getNodeRegistrationStatus() const=0;
495 virtual void setNodeRegistrationStatus(bool completed)=0;
497 virtual void pendNodeResolve(NodeResolver *nr)=0;
498 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
499 virtual void runNodeResolveCallbacks()=0;
500 virtual void resetNodeResolveState()=0;
501 virtual void mapNodeboxConnections()=0;
502 virtual core::aabbox3d<s16> getSelectionBoxIntUnion() const=0;
505 IWritableNodeDefManager *createNodeDefManager();
510 virtual ~NodeResolver();
511 virtual void resolveNodeNames() = 0;
513 bool getIdFromNrBacklog(content_t *result_out,
514 const std::string &node_alt, content_t c_fallback);
515 bool getIdsFromNrBacklog(std::vector<content_t> *result_out,
516 bool all_required=false, content_t c_fallback=CONTENT_IGNORE);
518 void nodeResolveInternal();
521 u32 m_nnlistsizes_idx;
522 std::vector<std::string> m_nodenames;
523 std::vector<size_t> m_nnlistsizes;
524 INodeDefManager *m_ndef;