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"
30 #include "client/tile.h"
33 #include "itemgroup.h"
34 #include "sound.h" // SimpleSoundSpec
35 #include "constants.h" // BS
37 class IItemDefManager;
42 typedef std::list<std::pair<content_t, int> > GroupItems;
50 enum ContentParamType2
55 // Flowing liquid properties
57 // Direction for chests and furnaces and such
59 // Direction for signs, torches and such
61 // Block level like FLOWINGLIQUID
74 NODEBOX_REGULAR, // Regular block; allows buildable_to
75 NODEBOX_FIXED, // Static separately defined box(es)
76 NODEBOX_WALLMOUNTED, // Box for wall mounted nodes; (top, bottom, side)
77 NODEBOX_LEVELED, // Same as fixed, but with dynamic height from param2. for snow, ...
82 enum NodeBoxType type;
83 // NODEBOX_REGULAR (no parameters)
85 std::vector<aabb3f> fixed;
86 // NODEBOX_WALLMOUNTED
89 aabb3f wall_side; // being at the -X side
95 void serialize(std::ostream &os, u16 protocol_version) const;
96 void deSerialize(std::istream &is);
103 Stand-alone definition of a TileSpec (basically a server-side TileSpec)
105 enum TileAnimationType{
107 TAT_VERTICAL_FRAMES=1,
112 bool backface_culling; // Takes effect only in special cases
114 enum TileAnimationType type;
115 int aspect_w; // width for aspect ratio
116 int aspect_h; // height for aspect ratio
117 float length; // seconds
123 backface_culling = true;
124 animation.type = TAT_NONE;
125 animation.aspect_w = 1;
126 animation.aspect_h = 1;
127 animation.length = 1.0;
130 void serialize(std::ostream &os, u16 protocol_version) const;
131 void deSerialize(std::istream &is);
136 NDT_NORMAL, // A basic solid block
137 NDT_AIRLIKE, // Nothing is drawn
138 NDT_LIQUID, // Do not draw face towards same kind of flowing/source liquid
139 NDT_FLOWINGLIQUID, // A very special kind of thing
140 NDT_GLASSLIKE, // Glass-like, don't draw faces towards other glass
141 NDT_ALLFACES, // Leaves-like, draw all faces no matter what
142 NDT_ALLFACES_OPTIONAL, // Fancy -> allfaces, fast -> normal
149 NDT_GLASSLIKE_FRAMED, // Glass-like, draw connected frames and all all
151 // uses 2 textures, one for frames, second for faces
152 NDT_FIRELIKE, // Draw faces slightly rotated and only on connecting nodes,
153 NDT_GLASSLIKE_FRAMED_OPTIONAL, // enabled -> connected, disabled -> Glass-like
154 // uses 2 textures, one for frames, second for faces
155 NDT_MESH, // Uses static meshes
158 #define CF_SPECIAL_COUNT 6
160 struct ContentFeatures
167 // up down right left back front
170 // - Currently used for flowing liquids
171 TileSpec special_tiles[CF_SPECIAL_COUNT];
172 u8 solidness; // Used when choosing which face is drawn
173 u8 visual_solidness; // When solidness=0, this tells how it looks like
174 bool backface_culling;
177 // Server-side cached callback existence for fast skipping
178 bool has_on_construct;
179 bool has_on_destruct;
180 bool has_after_destruct;
186 std::string name; // "" = undefined node
187 ItemGroupList groups; // Same as in itemdef
190 enum NodeDrawType drawtype;
193 scene::IMesh *mesh_ptr[24];
195 float visual_scale; // Misc. scale parameter
197 TileDef tiledef_special[CF_SPECIAL_COUNT]; // eg. flowing liquid
200 // Post effect color, drawn when the camera is inside the node.
201 video::SColor post_effect_color;
202 // Type of MapNode::param1
203 ContentParamType param_type;
204 // Type of MapNode::param2
205 ContentParamType2 param_type_2;
206 // True for all ground-like things like stone and mud, false for eg. trees
207 bool is_ground_content;
208 bool light_propagates;
209 bool sunlight_propagates;
210 // This is used for collision detection.
211 // Also for general solidness queries.
213 // Player can point to these
215 // Player can dig these
217 // Player can climb these
219 // Player can build on these
221 // Player cannot build to these (placement prediction disabled)
223 // Flowing liquid or snow, value = default level
225 // Whether the node is non-liquid, source liquid or flowing liquid
226 enum LiquidType liquid_type;
227 // If the content is liquid, this is the flowing version of the liquid.
228 std::string liquid_alternative_flowing;
229 // If the content is liquid, this is the source version of the liquid.
230 std::string liquid_alternative_source;
231 // Viscosity for fluid flow, ranging from 1 to 7, with
232 // 1 giving almost instantaneous propagation and 7 being
233 // the slowest possible
235 // Is liquid renewable (new liquid source will be created between 2 existing)
236 bool liquid_renewable;
237 // Number of flowing liquids surrounding source
240 // Amount of light the node emits
242 u32 damage_per_second;
244 NodeBox selection_box;
245 NodeBox collision_box;
246 // Used for waving leaves/plants
248 // Compatibility with old maps
249 // Set to true if paramtype used to be 'facedir_simple'
250 bool legacy_facedir_simple;
251 // Set to true if wall_mounted used to be set to true
252 bool legacy_wallmounted;
255 SimpleSoundSpec sound_footstep;
256 SimpleSoundSpec sound_dig;
257 SimpleSoundSpec sound_dug;
266 void serialize(std::ostream &os, u16 protocol_version);
267 void deSerialize(std::istream &is);
268 void serializeOld(std::ostream &os, u16 protocol_version);
269 void deSerializeOld(std::istream &is, int version);
274 bool isLiquid() const{
275 return (liquid_type != LIQUID_NONE);
277 bool sameLiquid(const ContentFeatures &f) const{
278 if(!isLiquid() || !f.isLiquid()) return false;
279 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
284 class INodeDefManager;
286 struct NodeListInfo {
287 NodeListInfo(u32 len)
290 all_required = false;
291 c_fallback = CONTENT_IGNORE;
294 NodeListInfo(u32 len, content_t fallback)
298 c_fallback = fallback;
303 content_t c_fallback;
306 struct NodeResolveInfo {
307 NodeResolveInfo(NodeResolver *nr)
312 std::list<std::string> nodenames;
313 std::list<NodeListInfo> nodelistinfo;
314 NodeResolver *resolver;
317 class INodeDefManager
321 virtual ~INodeDefManager(){}
322 // Get node definition
323 virtual const ContentFeatures& get(content_t c) const=0;
324 virtual const ContentFeatures& get(const MapNode &n) const=0;
325 virtual bool getId(const std::string &name, content_t &result) const=0;
326 virtual content_t getId(const std::string &name) const=0;
327 // Allows "group:name" in addition to regular node names
328 virtual void getIds(const std::string &name, std::set<content_t> &result)
330 virtual const ContentFeatures& get(const std::string &name) const=0;
332 virtual void serialize(std::ostream &os, u16 protocol_version)=0;
334 virtual bool getNodeRegistrationStatus() const=0;
335 virtual void setNodeRegistrationStatus(bool completed)=0;
337 virtual void pendNodeResolve(NodeResolveInfo *nri)=0;
338 virtual void cancelNodeResolve(NodeResolver *resolver)=0;
339 virtual void runNodeResolverCallbacks()=0;
341 virtual bool getIdFromResolveInfo(NodeResolveInfo *nri,
342 const std::string &node_alt, content_t c_fallback, content_t &result)=0;
343 virtual bool getIdsFromResolveInfo(NodeResolveInfo *nri,
344 std::vector<content_t> &result)=0;
347 class IWritableNodeDefManager : public INodeDefManager
350 IWritableNodeDefManager(){}
351 virtual ~IWritableNodeDefManager(){}
352 virtual IWritableNodeDefManager* clone()=0;
353 // Get node definition
354 virtual const ContentFeatures& get(content_t c) const=0;
355 virtual const ContentFeatures& get(const MapNode &n) const=0;
356 virtual bool getId(const std::string &name, content_t &result) const=0;
357 // If not found, returns CONTENT_IGNORE
358 virtual content_t getId(const std::string &name) const=0;
359 // Allows "group:name" in addition to regular node names
360 virtual void getIds(const std::string &name, std::set<content_t> &result)
362 // If not found, returns the features of CONTENT_UNKNOWN
363 virtual const ContentFeatures& get(const std::string &name) const=0;
365 // Register node definition by name (allocate an id)
366 // If returns CONTENT_IGNORE, could not allocate id
367 virtual content_t set(const std::string &name,
368 const ContentFeatures &def)=0;
369 // If returns CONTENT_IGNORE, could not allocate id
370 virtual content_t allocateDummy(const std::string &name)=0;
373 Update item alias mapping.
374 Call after updating item definitions.
376 virtual void updateAliases(IItemDefManager *idef)=0;
379 Update tile textures to latest return values of TextueSource.
381 virtual void updateTextures(IGameDef *gamedef)=0;
383 virtual void serialize(std::ostream &os, u16 protocol_version)=0;
384 virtual void deSerialize(std::istream &is)=0;
386 virtual bool getNodeRegistrationStatus() const=0;
387 virtual void setNodeRegistrationStatus(bool completed)=0;
389 virtual void pendNodeResolve(NodeResolveInfo *nri)=0;
390 virtual void cancelNodeResolve(NodeResolver *resolver)=0;
391 virtual void runNodeResolverCallbacks()=0;
393 virtual bool getIdFromResolveInfo(NodeResolveInfo *nri,
394 const std::string &node_alt, content_t c_fallback, content_t &result)=0;
395 virtual bool getIdsFromResolveInfo(NodeResolveInfo *nri,
396 std::vector<content_t> &result)=0;
399 IWritableNodeDefManager *createNodeDefManager();
405 m_lookup_done = false;
409 virtual ~NodeResolver()
411 if (!m_lookup_done && m_ndef)
412 m_ndef->cancelNodeResolve(this);
415 virtual void resolveNodeNames(NodeResolveInfo *nri) = 0;
418 INodeDefManager *m_ndef;