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
170 Stand-alone definition of a TileSpec (basically a server-side TileSpec)
176 bool backface_culling; // Takes effect only in special cases
177 bool tileable_horizontal;
178 bool tileable_vertical;
179 //! If true, the tile has its own color.
181 //! The color of the tile.
184 struct TileAnimationParams animation;
189 backface_culling = true;
190 tileable_horizontal = true;
191 tileable_vertical = true;
193 color = video::SColor(0xFFFFFFFF);
194 animation.type = TAT_NONE;
197 void serialize(std::ostream &os, u16 protocol_version) const;
198 void deSerialize(std::istream &is, const u8 contentfeatures_version, const NodeDrawType drawtype);
201 #define CF_SPECIAL_COUNT 6
203 struct ContentFeatures
210 // up down right left back front
213 // - Currently used for flowing liquids
214 TileSpec special_tiles[CF_SPECIAL_COUNT];
215 u8 solidness; // Used when choosing which face is drawn
216 u8 visual_solidness; // When solidness=0, this tells how it looks like
217 bool backface_culling;
220 // Server-side cached callback existence for fast skipping
221 bool has_on_construct;
222 bool has_on_destruct;
223 bool has_after_destruct;
229 // --- GENERAL PROPERTIES ---
231 std::string name; // "" = undefined node
232 ItemGroupList groups; // Same as in itemdef
233 // Type of MapNode::param1
234 ContentParamType param_type;
235 // Type of MapNode::param2
236 ContentParamType2 param_type_2;
238 // --- VISUAL PROPERTIES ---
240 enum NodeDrawType drawtype;
243 scene::IMesh *mesh_ptr[24];
244 video::SColor minimap_color;
246 float visual_scale; // Misc. scale parameter
248 TileDef tiledef_special[CF_SPECIAL_COUNT]; // eg. flowing liquid
249 // If 255, the node is opaque.
250 // Otherwise it uses texture alpha.
252 // The color of the node.
254 std::string palette_name;
255 std::vector<video::SColor> *palette;
256 // Used for waving leaves/plants
258 // for NDT_CONNECTED pairing
260 std::vector<std::string> connects_to;
261 std::set<content_t> connects_to_ids;
262 // Post effect color, drawn when the camera is inside the node.
263 video::SColor post_effect_color;
264 // Flowing liquid or snow, value = default level
267 // --- LIGHTING-RELATED ---
269 bool light_propagates;
270 bool sunlight_propagates;
271 // Amount of light the node emits
274 // --- MAP GENERATION ---
276 // True for all ground-like things like stone and mud, false for eg. trees
277 bool is_ground_content;
279 // --- INTERACTION PROPERTIES ---
281 // This is used for collision detection.
282 // Also for general solidness queries.
284 // Player can point to these
286 // Player can dig these
288 // Player can climb these
290 // Player can build on these
292 // Player cannot build to these (placement prediction disabled)
294 u32 damage_per_second;
296 // --- LIQUID PROPERTIES ---
298 // Whether the node is non-liquid, source liquid or flowing liquid
299 enum LiquidType liquid_type;
300 // If the content is liquid, this is the flowing version of the liquid.
301 std::string liquid_alternative_flowing;
302 // If the content is liquid, this is the source version of the liquid.
303 std::string liquid_alternative_source;
304 // Viscosity for fluid flow, ranging from 1 to 7, with
305 // 1 giving almost instantaneous propagation and 7 being
306 // the slowest possible
308 // Is liquid renewable (new liquid source will be created between 2 existing)
309 bool liquid_renewable;
310 // Number of flowing liquids surrounding source
313 // Liquids flow into and replace node
319 NodeBox selection_box;
320 NodeBox collision_box;
322 // --- SOUND PROPERTIES ---
324 SimpleSoundSpec sound_footstep;
325 SimpleSoundSpec sound_dig;
326 SimpleSoundSpec sound_dug;
330 // Compatibility with old maps
331 // Set to true if paramtype used to be 'facedir_simple'
332 bool legacy_facedir_simple;
333 // Set to true if wall_mounted used to be set to true
334 bool legacy_wallmounted;
343 void serialize(std::ostream &os, u16 protocol_version) const;
344 void deSerialize(std::istream &is);
345 void serializeOld(std::ostream &os, u16 protocol_version) const;
346 void deSerializeOld(std::istream &is, int version);
348 * Since vertex alpha is no lnger supported, this method
349 * adds instructions to the texture names to blend alpha there.
351 * tiledef, tiledef_special and alpha must be initialized
352 * before calling this.
359 bool isLiquid() const{
360 return (liquid_type != LIQUID_NONE);
362 bool sameLiquid(const ContentFeatures &f) const{
363 if(!isLiquid() || !f.isLiquid()) return false;
364 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
368 void fillTileAttribs(ITextureSource *tsrc, TileSpec *tile, TileDef *tiledef,
369 u32 shader_id, bool use_normal_texture, bool backface_culling,
371 void updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc,
372 scene::IMeshManipulator *meshmanip, Client *client, const TextureSettings &tsettings);
376 class INodeDefManager {
379 virtual ~INodeDefManager(){}
380 // Get node definition
381 virtual const ContentFeatures &get(content_t c) const=0;
382 virtual const ContentFeatures &get(const MapNode &n) const=0;
383 virtual bool getId(const std::string &name, content_t &result) const=0;
384 virtual content_t getId(const std::string &name) const=0;
385 // Allows "group:name" in addition to regular node names
386 // returns false if node name not found, true otherwise
387 virtual bool getIds(const std::string &name, std::set<content_t> &result)
389 virtual const ContentFeatures &get(const std::string &name) const=0;
391 virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
393 virtual bool getNodeRegistrationStatus() const=0;
395 virtual void pendNodeResolve(NodeResolver *nr)=0;
396 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
397 virtual bool nodeboxConnects(const MapNode from, const MapNode to, u8 connect_face)=0;
399 * Returns the smallest box in node coordinates that
400 * contains all nodes' selection boxes.
402 virtual core::aabbox3d<s16> getSelectionBoxIntUnion() const=0;
405 class IWritableNodeDefManager : public INodeDefManager {
407 IWritableNodeDefManager(){}
408 virtual ~IWritableNodeDefManager(){}
409 virtual IWritableNodeDefManager* clone()=0;
410 // Get node definition
411 virtual const ContentFeatures &get(content_t c) const=0;
412 virtual const ContentFeatures &get(const MapNode &n) const=0;
413 virtual bool getId(const std::string &name, content_t &result) const=0;
414 // If not found, returns CONTENT_IGNORE
415 virtual content_t getId(const std::string &name) const=0;
416 // Allows "group:name" in addition to regular node names
417 virtual bool getIds(const std::string &name, std::set<content_t> &result)
419 // If not found, returns the features of CONTENT_UNKNOWN
420 virtual const ContentFeatures &get(const std::string &name) const=0;
422 // Register node definition by name (allocate an id)
423 // If returns CONTENT_IGNORE, could not allocate id
424 virtual content_t set(const std::string &name,
425 const ContentFeatures &def)=0;
426 // If returns CONTENT_IGNORE, could not allocate id
427 virtual content_t allocateDummy(const std::string &name)=0;
429 virtual void removeNode(const std::string &name)=0;
432 Update item alias mapping.
433 Call after updating item definitions.
435 virtual void updateAliases(IItemDefManager *idef)=0;
438 Override textures from servers with ones specified in texturepack/override.txt
440 virtual void applyTextureOverrides(const std::string &override_filepath)=0;
443 Update tile textures to latest return values of TextueSource.
445 virtual void updateTextures(IGameDef *gamedef,
446 void (*progress_cbk)(void *progress_args, u32 progress, u32 max_progress),
447 void *progress_cbk_args)=0;
449 virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
450 virtual void deSerialize(std::istream &is)=0;
452 virtual bool getNodeRegistrationStatus() const=0;
453 virtual void setNodeRegistrationStatus(bool completed)=0;
455 virtual void pendNodeResolve(NodeResolver *nr)=0;
456 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
457 virtual void runNodeResolveCallbacks()=0;
458 virtual void resetNodeResolveState()=0;
459 virtual void mapNodeboxConnections()=0;
460 virtual core::aabbox3d<s16> getSelectionBoxIntUnion() const=0;
463 IWritableNodeDefManager *createNodeDefManager();
468 virtual ~NodeResolver();
469 virtual void resolveNodeNames() = 0;
471 bool getIdFromNrBacklog(content_t *result_out,
472 const std::string &node_alt, content_t c_fallback);
473 bool getIdsFromNrBacklog(std::vector<content_t> *result_out,
474 bool all_required=false, content_t c_fallback=CONTENT_IGNORE);
476 void nodeResolveInternal();
479 u32 m_nnlistsizes_idx;
480 std::vector<std::string> m_nodenames;
481 std::vector<size_t> m_nnlistsizes;
482 INodeDefManager *m_ndef;