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"
34 #include "itemgroup.h"
35 #include "sound.h" // SimpleSoundSpec
36 #include "constants.h" // BS
37 #include "tileanimation.h"
39 class INodeDefManager;
40 class IItemDefManager;
46 typedef std::list<std::pair<content_t, int> > GroupItems;
54 enum ContentParamType2
59 // Flowing liquid properties
61 // Direction for chests and furnaces and such
63 // Direction for signs, torches and such
65 // Block level like FLOWINGLIQUID
67 // 2D rotation for things like plants
69 // Mesh options for plants
82 NODEBOX_REGULAR, // Regular block; allows buildable_to
83 NODEBOX_FIXED, // Static separately defined box(es)
84 NODEBOX_WALLMOUNTED, // Box for wall mounted nodes; (top, bottom, side)
85 NODEBOX_LEVELED, // Same as fixed, but with dynamic height from param2. for snow, ...
86 NODEBOX_CONNECTED, // optionally draws nodeboxes if a neighbor node attaches
91 enum NodeBoxType type;
92 // NODEBOX_REGULAR (no parameters)
94 std::vector<aabb3f> fixed;
95 // NODEBOX_WALLMOUNTED
98 aabb3f wall_side; // being at the -X side
100 std::vector<aabb3f> connect_top;
101 std::vector<aabb3f> connect_bottom;
102 std::vector<aabb3f> connect_front;
103 std::vector<aabb3f> connect_left;
104 std::vector<aabb3f> connect_back;
105 std::vector<aabb3f> connect_right;
111 void serialize(std::ostream &os, u16 protocol_version) const;
112 void deSerialize(std::istream &is);
124 class TextureSettings {
126 LeavesStyle leaves_style;
128 bool connected_glass;
129 bool use_normal_texture;
130 bool enable_mesh_cache;
140 NDT_NORMAL, // A basic solid block
141 NDT_AIRLIKE, // Nothing is drawn
142 NDT_LIQUID, // Do not draw face towards same kind of flowing/source liquid
143 NDT_FLOWINGLIQUID, // A very special kind of thing
144 NDT_GLASSLIKE, // Glass-like, don't draw faces towards other glass
145 NDT_ALLFACES, // Leaves-like, draw all faces no matter what
146 NDT_ALLFACES_OPTIONAL, // Fancy -> allfaces, fast -> normal
153 NDT_GLASSLIKE_FRAMED, // Glass-like, draw connected frames and all all
155 // uses 2 textures, one for frames, second for faces
156 NDT_FIRELIKE, // Draw faces slightly rotated and only on connecting nodes,
157 NDT_GLASSLIKE_FRAMED_OPTIONAL, // enabled -> connected, disabled -> Glass-like
158 // uses 2 textures, one for frames, second for faces
159 NDT_MESH, // Uses static meshes
163 Stand-alone definition of a TileSpec (basically a server-side TileSpec)
169 bool backface_culling; // Takes effect only in special cases
170 bool tileable_horizontal;
171 bool tileable_vertical;
172 struct TileAnimationParams animation;
177 backface_culling = true;
178 tileable_horizontal = true;
179 tileable_vertical = true;
180 animation.type = TAT_NONE;
183 void serialize(std::ostream &os, u16 protocol_version) const;
184 void deSerialize(std::istream &is, const u8 contentfeatures_version, const NodeDrawType drawtype);
187 #define CF_SPECIAL_COUNT 6
189 struct ContentFeatures
196 // up down right left back front
199 // - Currently used for flowing liquids
200 TileSpec special_tiles[CF_SPECIAL_COUNT];
201 u8 solidness; // Used when choosing which face is drawn
202 u8 visual_solidness; // When solidness=0, this tells how it looks like
203 bool backface_culling;
206 // Server-side cached callback existence for fast skipping
207 bool has_on_construct;
208 bool has_on_destruct;
209 bool has_after_destruct;
215 std::string name; // "" = undefined node
216 ItemGroupList groups; // Same as in itemdef
219 enum NodeDrawType drawtype;
222 scene::IMesh *mesh_ptr[24];
223 video::SColor minimap_color;
225 float visual_scale; // Misc. scale parameter
227 TileDef tiledef_special[CF_SPECIAL_COUNT]; // eg. flowing liquid
230 // Post effect color, drawn when the camera is inside the node.
231 video::SColor post_effect_color;
233 // Type of MapNode::param1
234 ContentParamType param_type;
235 // Type of MapNode::param2
236 ContentParamType2 param_type_2;
237 // True for all ground-like things like stone and mud, false for eg. trees
238 bool is_ground_content;
239 bool light_propagates;
240 bool sunlight_propagates;
241 // This is used for collision detection.
242 // Also for general solidness queries.
244 // Player can point to these
246 // Player can dig these
248 // Player can climb these
250 // Player can build on these
252 // Liquids flow into and replace node
254 // Player cannot build to these (placement prediction disabled)
256 // Flowing liquid or snow, value = default level
258 // Whether the node is non-liquid, source liquid or flowing liquid
259 enum LiquidType liquid_type;
260 // If the content is liquid, this is the flowing version of the liquid.
261 std::string liquid_alternative_flowing;
262 // If the content is liquid, this is the source version of the liquid.
263 std::string liquid_alternative_source;
264 // Viscosity for fluid flow, ranging from 1 to 7, with
265 // 1 giving almost instantaneous propagation and 7 being
266 // the slowest possible
268 // Is liquid renewable (new liquid source will be created between 2 existing)
269 bool liquid_renewable;
270 // Number of flowing liquids surrounding source
273 // Amount of light the node emits
275 u32 damage_per_second;
277 NodeBox selection_box;
278 NodeBox collision_box;
279 // Used for waving leaves/plants
281 // Compatibility with old maps
282 // Set to true if paramtype used to be 'facedir_simple'
283 bool legacy_facedir_simple;
284 // Set to true if wall_mounted used to be set to true
285 bool legacy_wallmounted;
286 // for NDT_CONNECTED pairing
290 SimpleSoundSpec sound_footstep;
291 SimpleSoundSpec sound_dig;
292 SimpleSoundSpec sound_dug;
294 std::vector<std::string> connects_to;
295 std::set<content_t> connects_to_ids;
304 void serialize(std::ostream &os, u16 protocol_version) const;
305 void deSerialize(std::istream &is);
306 void serializeOld(std::ostream &os, u16 protocol_version) const;
307 void deSerializeOld(std::istream &is, int version);
312 bool isLiquid() const{
313 return (liquid_type != LIQUID_NONE);
315 bool sameLiquid(const ContentFeatures &f) const{
316 if(!isLiquid() || !f.isLiquid()) return false;
317 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
321 void fillTileAttribs(ITextureSource *tsrc, TileSpec *tile, TileDef *tiledef,
322 u32 shader_id, bool use_normal_texture, bool backface_culling,
323 u8 alpha, u8 material_type);
324 void updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc,
325 scene::ISceneManager *smgr, scene::IMeshManipulator *meshmanip,
326 IGameDef *gamedef, 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;
354 class IWritableNodeDefManager : public INodeDefManager {
356 IWritableNodeDefManager(){}
357 virtual ~IWritableNodeDefManager(){}
358 virtual IWritableNodeDefManager* clone()=0;
359 // Get node definition
360 virtual const ContentFeatures &get(content_t c) const=0;
361 virtual const ContentFeatures &get(const MapNode &n) const=0;
362 virtual bool getId(const std::string &name, content_t &result) const=0;
363 // If not found, returns CONTENT_IGNORE
364 virtual content_t getId(const std::string &name) const=0;
365 // Allows "group:name" in addition to regular node names
366 virtual bool getIds(const std::string &name, std::set<content_t> &result)
368 // If not found, returns the features of CONTENT_UNKNOWN
369 virtual const ContentFeatures &get(const std::string &name) const=0;
371 // Register node definition by name (allocate an id)
372 // If returns CONTENT_IGNORE, could not allocate id
373 virtual content_t set(const std::string &name,
374 const ContentFeatures &def)=0;
375 // If returns CONTENT_IGNORE, could not allocate id
376 virtual content_t allocateDummy(const std::string &name)=0;
378 virtual void removeNode(const std::string &name)=0;
381 Update item alias mapping.
382 Call after updating item definitions.
384 virtual void updateAliases(IItemDefManager *idef)=0;
387 Override textures from servers with ones specified in texturepack/override.txt
389 virtual void applyTextureOverrides(const std::string &override_filepath)=0;
392 Update tile textures to latest return values of TextueSource.
394 virtual void updateTextures(IGameDef *gamedef,
395 void (*progress_cbk)(void *progress_args, u32 progress, u32 max_progress),
396 void *progress_cbk_args)=0;
398 virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
399 virtual void deSerialize(std::istream &is)=0;
401 virtual bool getNodeRegistrationStatus() const=0;
402 virtual void setNodeRegistrationStatus(bool completed)=0;
404 virtual void pendNodeResolve(NodeResolver *nr)=0;
405 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
406 virtual void runNodeResolveCallbacks()=0;
407 virtual void resetNodeResolveState()=0;
408 virtual void mapNodeboxConnections()=0;
411 IWritableNodeDefManager *createNodeDefManager();
416 virtual ~NodeResolver();
417 virtual void resolveNodeNames() = 0;
419 bool getIdFromNrBacklog(content_t *result_out,
420 const std::string &node_alt, content_t c_fallback);
421 bool getIdsFromNrBacklog(std::vector<content_t> *result_out,
422 bool all_required=false, content_t c_fallback=CONTENT_IGNORE);
424 void nodeResolveInternal();
427 u32 m_nnlistsizes_idx;
428 std::vector<std::string> m_nodenames;
429 std::vector<size_t> m_nnlistsizes;
430 INodeDefManager *m_ndef;