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
83 NODEBOX_REGULAR, // Regular block; allows buildable_to
84 NODEBOX_FIXED, // Static separately defined box(es)
85 NODEBOX_WALLMOUNTED, // Box for wall mounted nodes; (top, bottom, side)
86 NODEBOX_LEVELED, // Same as fixed, but with dynamic height from param2. for snow, ...
87 NODEBOX_CONNECTED, // optionally draws nodeboxes if a neighbor node attaches
92 enum NodeBoxType type;
93 // NODEBOX_REGULAR (no parameters)
95 std::vector<aabb3f> fixed;
96 // NODEBOX_WALLMOUNTED
99 aabb3f wall_side; // being at the -X side
101 std::vector<aabb3f> connect_top;
102 std::vector<aabb3f> connect_bottom;
103 std::vector<aabb3f> connect_front;
104 std::vector<aabb3f> connect_left;
105 std::vector<aabb3f> connect_back;
106 std::vector<aabb3f> connect_right;
112 void serialize(std::ostream &os, u16 protocol_version) const;
113 void deSerialize(std::istream &is);
125 class TextureSettings {
127 LeavesStyle leaves_style;
129 bool connected_glass;
130 bool use_normal_texture;
131 bool enable_mesh_cache;
141 NDT_NORMAL, // A basic solid block
142 NDT_AIRLIKE, // Nothing is drawn
143 NDT_LIQUID, // Do not draw face towards same kind of flowing/source liquid
144 NDT_FLOWINGLIQUID, // A very special kind of thing
145 NDT_GLASSLIKE, // Glass-like, don't draw faces towards other glass
146 NDT_ALLFACES, // Leaves-like, draw all faces no matter what
147 NDT_ALLFACES_OPTIONAL, // Fancy -> allfaces, fast -> normal
154 NDT_GLASSLIKE_FRAMED, // Glass-like, draw connected frames and all all
156 // uses 2 textures, one for frames, second for faces
157 NDT_FIRELIKE, // Draw faces slightly rotated and only on connecting nodes,
158 NDT_GLASSLIKE_FRAMED_OPTIONAL, // enabled -> connected, disabled -> Glass-like
159 // uses 2 textures, one for frames, second for faces
160 NDT_MESH, // Uses static meshes
164 Stand-alone definition of a TileSpec (basically a server-side TileSpec)
170 bool backface_culling; // Takes effect only in special cases
171 bool tileable_horizontal;
172 bool tileable_vertical;
173 struct TileAnimationParams animation;
178 backface_culling = true;
179 tileable_horizontal = true;
180 tileable_vertical = true;
181 animation.type = TAT_NONE;
184 void serialize(std::ostream &os, u16 protocol_version) const;
185 void deSerialize(std::istream &is, const u8 contentfeatures_version, const NodeDrawType drawtype);
188 #define CF_SPECIAL_COUNT 6
190 struct ContentFeatures
197 // up down right left back front
200 // - Currently used for flowing liquids
201 TileSpec special_tiles[CF_SPECIAL_COUNT];
202 u8 solidness; // Used when choosing which face is drawn
203 u8 visual_solidness; // When solidness=0, this tells how it looks like
204 bool backface_culling;
207 // Server-side cached callback existence for fast skipping
208 bool has_on_construct;
209 bool has_on_destruct;
210 bool has_after_destruct;
216 std::string name; // "" = undefined node
217 ItemGroupList groups; // Same as in itemdef
220 enum NodeDrawType drawtype;
223 scene::IMesh *mesh_ptr[24];
224 video::SColor minimap_color;
226 float visual_scale; // Misc. scale parameter
228 TileDef tiledef_special[CF_SPECIAL_COUNT]; // eg. flowing liquid
231 // Post effect color, drawn when the camera is inside the node.
232 video::SColor post_effect_color;
234 // Type of MapNode::param1
235 ContentParamType param_type;
236 // Type of MapNode::param2
237 ContentParamType2 param_type_2;
238 // True for all ground-like things like stone and mud, false for eg. trees
239 bool is_ground_content;
240 bool light_propagates;
241 bool sunlight_propagates;
242 // This is used for collision detection.
243 // Also for general solidness queries.
245 // Player can point to these
247 // Player can dig these
249 // Player can climb these
251 // Player can build on these
253 // Liquids flow into and replace node
255 // Player cannot build to these (placement prediction disabled)
257 // Flowing liquid or snow, value = default level
259 // Whether the node is non-liquid, source liquid or flowing liquid
260 enum LiquidType liquid_type;
261 // If the content is liquid, this is the flowing version of the liquid.
262 std::string liquid_alternative_flowing;
263 // If the content is liquid, this is the source version of the liquid.
264 std::string liquid_alternative_source;
265 // Viscosity for fluid flow, ranging from 1 to 7, with
266 // 1 giving almost instantaneous propagation and 7 being
267 // the slowest possible
269 // Is liquid renewable (new liquid source will be created between 2 existing)
270 bool liquid_renewable;
271 // Number of flowing liquids surrounding source
274 // Amount of light the node emits
276 u32 damage_per_second;
278 NodeBox selection_box;
279 NodeBox collision_box;
280 // Used for waving leaves/plants
282 // Compatibility with old maps
283 // Set to true if paramtype used to be 'facedir_simple'
284 bool legacy_facedir_simple;
285 // Set to true if wall_mounted used to be set to true
286 bool legacy_wallmounted;
287 // for NDT_CONNECTED pairing
291 SimpleSoundSpec sound_footstep;
292 SimpleSoundSpec sound_dig;
293 SimpleSoundSpec sound_dug;
295 std::vector<std::string> connects_to;
296 std::set<content_t> connects_to_ids;
305 void serialize(std::ostream &os, u16 protocol_version) const;
306 void deSerialize(std::istream &is);
307 void serializeOld(std::ostream &os, u16 protocol_version) const;
308 void deSerializeOld(std::istream &is, int version);
313 bool isLiquid() const{
314 return (liquid_type != LIQUID_NONE);
316 bool sameLiquid(const ContentFeatures &f) const{
317 if(!isLiquid() || !f.isLiquid()) return false;
318 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
322 void fillTileAttribs(ITextureSource *tsrc, TileSpec *tile, TileDef *tiledef,
323 u32 shader_id, bool use_normal_texture, bool backface_culling,
324 u8 alpha, u8 material_type);
325 void updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc,
326 scene::IMeshManipulator *meshmanip, Client *client, const TextureSettings &tsettings);
330 class INodeDefManager {
333 virtual ~INodeDefManager(){}
334 // Get node definition
335 virtual const ContentFeatures &get(content_t c) const=0;
336 virtual const ContentFeatures &get(const MapNode &n) const=0;
337 virtual bool getId(const std::string &name, content_t &result) const=0;
338 virtual content_t getId(const std::string &name) const=0;
339 // Allows "group:name" in addition to regular node names
340 // returns false if node name not found, true otherwise
341 virtual bool getIds(const std::string &name, std::set<content_t> &result)
343 virtual const ContentFeatures &get(const std::string &name) const=0;
345 virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
347 virtual bool getNodeRegistrationStatus() const=0;
349 virtual void pendNodeResolve(NodeResolver *nr)=0;
350 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
351 virtual bool nodeboxConnects(const MapNode from, const MapNode to, u8 connect_face)=0;
353 * Returns the smallest box in node coordinates that
354 * contains all nodes' selection boxes.
356 virtual core::aabbox3d<s16> getSelectionBoxIntUnion() const=0;
359 class IWritableNodeDefManager : public INodeDefManager {
361 IWritableNodeDefManager(){}
362 virtual ~IWritableNodeDefManager(){}
363 virtual IWritableNodeDefManager* clone()=0;
364 // Get node definition
365 virtual const ContentFeatures &get(content_t c) const=0;
366 virtual const ContentFeatures &get(const MapNode &n) const=0;
367 virtual bool getId(const std::string &name, content_t &result) const=0;
368 // If not found, returns CONTENT_IGNORE
369 virtual content_t getId(const std::string &name) const=0;
370 // Allows "group:name" in addition to regular node names
371 virtual bool getIds(const std::string &name, std::set<content_t> &result)
373 // If not found, returns the features of CONTENT_UNKNOWN
374 virtual const ContentFeatures &get(const std::string &name) const=0;
376 // Register node definition by name (allocate an id)
377 // If returns CONTENT_IGNORE, could not allocate id
378 virtual content_t set(const std::string &name,
379 const ContentFeatures &def)=0;
380 // If returns CONTENT_IGNORE, could not allocate id
381 virtual content_t allocateDummy(const std::string &name)=0;
383 virtual void removeNode(const std::string &name)=0;
386 Update item alias mapping.
387 Call after updating item definitions.
389 virtual void updateAliases(IItemDefManager *idef)=0;
392 Override textures from servers with ones specified in texturepack/override.txt
394 virtual void applyTextureOverrides(const std::string &override_filepath)=0;
397 Update tile textures to latest return values of TextueSource.
399 virtual void updateTextures(IGameDef *gamedef,
400 void (*progress_cbk)(void *progress_args, u32 progress, u32 max_progress),
401 void *progress_cbk_args)=0;
403 virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
404 virtual void deSerialize(std::istream &is)=0;
406 virtual bool getNodeRegistrationStatus() const=0;
407 virtual void setNodeRegistrationStatus(bool completed)=0;
409 virtual void pendNodeResolve(NodeResolver *nr)=0;
410 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
411 virtual void runNodeResolveCallbacks()=0;
412 virtual void resetNodeResolveState()=0;
413 virtual void mapNodeboxConnections()=0;
414 virtual core::aabbox3d<s16> getSelectionBoxIntUnion() const=0;
417 IWritableNodeDefManager *createNodeDefManager();
422 virtual ~NodeResolver();
423 virtual void resolveNodeNames() = 0;
425 bool getIdFromNrBacklog(content_t *result_out,
426 const std::string &node_alt, content_t c_fallback);
427 bool getIdsFromNrBacklog(std::vector<content_t> *result_out,
428 bool all_required=false, content_t c_fallback=CONTENT_IGNORE);
430 void nodeResolveInternal();
433 u32 m_nnlistsizes_idx;
434 std::vector<std::string> m_nodenames;
435 std::vector<size_t> m_nnlistsizes;
436 INodeDefManager *m_ndef;