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
89 NODEBOX_REGULAR, // Regular block; allows buildable_to
90 NODEBOX_FIXED, // Static separately defined box(es)
91 NODEBOX_WALLMOUNTED, // Box for wall mounted nodes; (top, bottom, side)
92 NODEBOX_LEVELED, // Same as fixed, but with dynamic height from param2. for snow, ...
93 NODEBOX_CONNECTED, // optionally draws nodeboxes if a neighbor node attaches
98 enum NodeBoxType type;
99 // NODEBOX_REGULAR (no parameters)
101 std::vector<aabb3f> fixed;
102 // NODEBOX_WALLMOUNTED
105 aabb3f wall_side; // being at the -X side
107 std::vector<aabb3f> connect_top;
108 std::vector<aabb3f> connect_bottom;
109 std::vector<aabb3f> connect_front;
110 std::vector<aabb3f> connect_left;
111 std::vector<aabb3f> connect_back;
112 std::vector<aabb3f> connect_right;
118 void serialize(std::ostream &os, u16 protocol_version) const;
119 void deSerialize(std::istream &is);
131 class TextureSettings {
133 LeavesStyle leaves_style;
135 bool connected_glass;
136 bool use_normal_texture;
137 bool enable_mesh_cache;
147 NDT_NORMAL, // A basic solid block
148 NDT_AIRLIKE, // Nothing is drawn
149 NDT_LIQUID, // Do not draw face towards same kind of flowing/source liquid
150 NDT_FLOWINGLIQUID, // A very special kind of thing
151 NDT_GLASSLIKE, // Glass-like, don't draw faces towards other glass
152 NDT_ALLFACES, // Leaves-like, draw all faces no matter what
153 NDT_ALLFACES_OPTIONAL, // Fancy -> allfaces, fast -> normal
160 NDT_GLASSLIKE_FRAMED, // Glass-like, draw connected frames and all all
162 // uses 2 textures, one for frames, second for faces
163 NDT_FIRELIKE, // Draw faces slightly rotated and only on connecting nodes,
164 NDT_GLASSLIKE_FRAMED_OPTIONAL, // enabled -> connected, disabled -> Glass-like
165 // uses 2 textures, one for frames, second for faces
166 NDT_MESH, // Uses static meshes
169 // Mesh options for NDT_PLANTLIKE with CPT2_MESHOPTIONS
170 static const u8 MO_MASK_STYLE = 0x07;
171 static const u8 MO_BIT_RANDOM_OFFSET = 0x08;
172 static const u8 MO_BIT_SCALE_SQRT2 = 0x10;
173 static const u8 MO_BIT_RANDOM_OFFSET_Y = 0x20;
174 enum PlantlikeStyle {
183 Stand-alone definition of a TileSpec (basically a server-side TileSpec)
189 bool backface_culling; // Takes effect only in special cases
190 bool tileable_horizontal;
191 bool tileable_vertical;
192 //! If true, the tile has its own color.
194 //! The color of the tile.
197 struct TileAnimationParams animation;
202 backface_culling = true;
203 tileable_horizontal = true;
204 tileable_vertical = true;
206 color = video::SColor(0xFFFFFFFF);
207 animation.type = TAT_NONE;
210 void serialize(std::ostream &os, u16 protocol_version) const;
211 void deSerialize(std::istream &is, const u8 contentfeatures_version, const NodeDrawType drawtype);
214 #define CF_SPECIAL_COUNT 6
216 struct ContentFeatures
223 // up down right left back front
226 // - Currently used for flowing liquids
227 TileSpec special_tiles[CF_SPECIAL_COUNT];
228 u8 solidness; // Used when choosing which face is drawn
229 u8 visual_solidness; // When solidness=0, this tells how it looks like
230 bool backface_culling;
233 // Server-side cached callback existence for fast skipping
234 bool has_on_construct;
235 bool has_on_destruct;
236 bool has_after_destruct;
242 // --- GENERAL PROPERTIES ---
244 std::string name; // "" = undefined node
245 ItemGroupList groups; // Same as in itemdef
246 // Type of MapNode::param1
247 ContentParamType param_type;
248 // Type of MapNode::param2
249 ContentParamType2 param_type_2;
251 // --- VISUAL PROPERTIES ---
253 enum NodeDrawType drawtype;
256 scene::IMesh *mesh_ptr[24];
257 video::SColor minimap_color;
259 float visual_scale; // Misc. scale parameter
261 TileDef tiledef_special[CF_SPECIAL_COUNT]; // eg. flowing liquid
262 // If 255, the node is opaque.
263 // Otherwise it uses texture alpha.
265 // The color of the node.
267 std::string palette_name;
268 std::vector<video::SColor> *palette;
269 // Used for waving leaves/plants
271 // for NDT_CONNECTED pairing
273 std::vector<std::string> connects_to;
274 std::set<content_t> connects_to_ids;
275 // Post effect color, drawn when the camera is inside the node.
276 video::SColor post_effect_color;
277 // Flowing liquid or snow, value = default level
280 // --- LIGHTING-RELATED ---
282 bool light_propagates;
283 bool sunlight_propagates;
284 // Amount of light the node emits
287 // --- MAP GENERATION ---
289 // True for all ground-like things like stone and mud, false for eg. trees
290 bool is_ground_content;
292 // --- INTERACTION PROPERTIES ---
294 // This is used for collision detection.
295 // Also for general solidness queries.
297 // Player can point to these
299 // Player can dig these
301 // Player can climb these
303 // Player can build on these
305 // Player cannot build to these (placement prediction disabled)
307 u32 damage_per_second;
309 // --- LIQUID PROPERTIES ---
311 // Whether the node is non-liquid, source liquid or flowing liquid
312 enum LiquidType liquid_type;
313 // If the content is liquid, this is the flowing version of the liquid.
314 std::string liquid_alternative_flowing;
315 // If the content is liquid, this is the source version of the liquid.
316 std::string liquid_alternative_source;
317 // Viscosity for fluid flow, ranging from 1 to 7, with
318 // 1 giving almost instantaneous propagation and 7 being
319 // the slowest possible
321 // Is liquid renewable (new liquid source will be created between 2 existing)
322 bool liquid_renewable;
323 // Number of flowing liquids surrounding source
326 // Liquids flow into and replace node
332 NodeBox selection_box;
333 NodeBox collision_box;
335 // --- SOUND PROPERTIES ---
337 SimpleSoundSpec sound_footstep;
338 SimpleSoundSpec sound_dig;
339 SimpleSoundSpec sound_dug;
343 // Compatibility with old maps
344 // Set to true if paramtype used to be 'facedir_simple'
345 bool legacy_facedir_simple;
346 // Set to true if wall_mounted used to be set to true
347 bool legacy_wallmounted;
356 void serialize(std::ostream &os, u16 protocol_version) const;
357 void deSerialize(std::istream &is);
358 void serializeOld(std::ostream &os, u16 protocol_version) const;
359 void deSerializeOld(std::istream &is, int version);
361 * Since vertex alpha is no lnger supported, this method
362 * adds instructions to the texture names to blend alpha there.
364 * tiledef, tiledef_special and alpha must be initialized
365 * before calling this.
372 bool isLiquid() const{
373 return (liquid_type != LIQUID_NONE);
375 bool sameLiquid(const ContentFeatures &f) const{
376 if(!isLiquid() || !f.isLiquid()) return false;
377 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
380 int getGroup(const std::string &group) const
382 return itemgroup_get(groups, group);
386 void fillTileAttribs(ITextureSource *tsrc, TileSpec *tile, TileDef *tiledef,
387 u32 shader_id, bool use_normal_texture, bool backface_culling,
389 void updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc,
390 scene::IMeshManipulator *meshmanip, Client *client, const TextureSettings &tsettings);
394 class INodeDefManager {
397 virtual ~INodeDefManager(){}
398 // Get node definition
399 virtual const ContentFeatures &get(content_t c) const=0;
400 virtual const ContentFeatures &get(const MapNode &n) const=0;
401 virtual bool getId(const std::string &name, content_t &result) const=0;
402 virtual content_t getId(const std::string &name) const=0;
403 // Allows "group:name" in addition to regular node names
404 // returns false if node name not found, true otherwise
405 virtual bool getIds(const std::string &name, std::set<content_t> &result)
407 virtual const ContentFeatures &get(const std::string &name) const=0;
409 virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
411 virtual bool getNodeRegistrationStatus() const=0;
413 virtual void pendNodeResolve(NodeResolver *nr)=0;
414 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
415 virtual bool nodeboxConnects(const MapNode from, const MapNode to, u8 connect_face)=0;
417 * Returns the smallest box in node coordinates that
418 * contains all nodes' selection boxes.
420 virtual core::aabbox3d<s16> getSelectionBoxIntUnion() const=0;
423 class IWritableNodeDefManager : public INodeDefManager {
425 IWritableNodeDefManager(){}
426 virtual ~IWritableNodeDefManager(){}
427 virtual IWritableNodeDefManager* clone()=0;
428 // Get node definition
429 virtual const ContentFeatures &get(content_t c) const=0;
430 virtual const ContentFeatures &get(const MapNode &n) const=0;
431 virtual bool getId(const std::string &name, content_t &result) const=0;
432 // If not found, returns CONTENT_IGNORE
433 virtual content_t getId(const std::string &name) const=0;
434 // Allows "group:name" in addition to regular node names
435 virtual bool getIds(const std::string &name, std::set<content_t> &result)
437 // If not found, returns the features of CONTENT_UNKNOWN
438 virtual const ContentFeatures &get(const std::string &name) const=0;
440 // Register node definition by name (allocate an id)
441 // If returns CONTENT_IGNORE, could not allocate id
442 virtual content_t set(const std::string &name,
443 const ContentFeatures &def)=0;
444 // If returns CONTENT_IGNORE, could not allocate id
445 virtual content_t allocateDummy(const std::string &name)=0;
447 virtual void removeNode(const std::string &name)=0;
450 Update item alias mapping.
451 Call after updating item definitions.
453 virtual void updateAliases(IItemDefManager *idef)=0;
456 Override textures from servers with ones specified in texturepack/override.txt
458 virtual void applyTextureOverrides(const std::string &override_filepath)=0;
461 Update tile textures to latest return values of TextueSource.
463 virtual void updateTextures(IGameDef *gamedef,
464 void (*progress_cbk)(void *progress_args, u32 progress, u32 max_progress),
465 void *progress_cbk_args)=0;
467 virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
468 virtual void deSerialize(std::istream &is)=0;
470 virtual bool getNodeRegistrationStatus() const=0;
471 virtual void setNodeRegistrationStatus(bool completed)=0;
473 virtual void pendNodeResolve(NodeResolver *nr)=0;
474 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
475 virtual void runNodeResolveCallbacks()=0;
476 virtual void resetNodeResolveState()=0;
477 virtual void mapNodeboxConnections()=0;
478 virtual core::aabbox3d<s16> getSelectionBoxIntUnion() const=0;
481 IWritableNodeDefManager *createNodeDefManager();
486 virtual ~NodeResolver();
487 virtual void resolveNodeNames() = 0;
489 bool getIdFromNrBacklog(content_t *result_out,
490 const std::string &node_alt, content_t c_fallback);
491 bool getIdsFromNrBacklog(std::vector<content_t> *result_out,
492 bool all_required=false, content_t c_fallback=CONTENT_IGNORE);
494 void nodeResolveInternal();
497 u32 m_nnlistsizes_idx;
498 std::vector<std::string> m_nodenames;
499 std::vector<size_t> m_nnlistsizes;
500 INodeDefManager *m_ndef;