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 INodeDefManager;
38 class IItemDefManager;
44 typedef std::list<std::pair<content_t, int> > GroupItems;
52 enum ContentParamType2
57 // Flowing liquid properties
59 // Direction for chests and furnaces and such
61 // Direction for signs, torches and such
63 // Block level like FLOWINGLIQUID
76 NODEBOX_REGULAR, // Regular block; allows buildable_to
77 NODEBOX_FIXED, // Static separately defined box(es)
78 NODEBOX_WALLMOUNTED, // Box for wall mounted nodes; (top, bottom, side)
79 NODEBOX_LEVELED, // Same as fixed, but with dynamic height from param2. for snow, ...
84 enum NodeBoxType type;
85 // NODEBOX_REGULAR (no parameters)
87 std::vector<aabb3f> fixed;
88 // NODEBOX_WALLMOUNTED
91 aabb3f wall_side; // being at the -X side
97 void serialize(std::ostream &os, u16 protocol_version) const;
98 void deSerialize(std::istream &is);
105 Stand-alone definition of a TileSpec (basically a server-side TileSpec)
107 enum TileAnimationType{
109 TAT_VERTICAL_FRAMES=1,
114 bool backface_culling; // Takes effect only in special cases
116 enum TileAnimationType type;
117 int aspect_w; // width for aspect ratio
118 int aspect_h; // height for aspect ratio
119 float length; // seconds
125 backface_culling = true;
126 animation.type = TAT_NONE;
127 animation.aspect_w = 1;
128 animation.aspect_h = 1;
129 animation.length = 1.0;
132 void serialize(std::ostream &os, u16 protocol_version) const;
133 void deSerialize(std::istream &is);
138 NDT_NORMAL, // A basic solid block
139 NDT_AIRLIKE, // Nothing is drawn
140 NDT_LIQUID, // Do not draw face towards same kind of flowing/source liquid
141 NDT_FLOWINGLIQUID, // A very special kind of thing
142 NDT_GLASSLIKE, // Glass-like, don't draw faces towards other glass
143 NDT_ALLFACES, // Leaves-like, draw all faces no matter what
144 NDT_ALLFACES_OPTIONAL, // Fancy -> allfaces, fast -> normal
151 NDT_GLASSLIKE_FRAMED, // Glass-like, draw connected frames and all all
153 // uses 2 textures, one for frames, second for faces
154 NDT_FIRELIKE, // Draw faces slightly rotated and only on connecting nodes,
155 NDT_GLASSLIKE_FRAMED_OPTIONAL, // enabled -> connected, disabled -> Glass-like
156 // uses 2 textures, one for frames, second for faces
157 NDT_MESH, // Uses static meshes
160 #define CF_SPECIAL_COUNT 6
162 struct ContentFeatures
169 // up down right left back front
172 // - Currently used for flowing liquids
173 TileSpec special_tiles[CF_SPECIAL_COUNT];
174 u8 solidness; // Used when choosing which face is drawn
175 u8 visual_solidness; // When solidness=0, this tells how it looks like
176 bool backface_culling;
179 // Server-side cached callback existence for fast skipping
180 bool has_on_construct;
181 bool has_on_destruct;
182 bool has_after_destruct;
188 std::string name; // "" = undefined node
189 ItemGroupList groups; // Same as in itemdef
192 enum NodeDrawType drawtype;
195 scene::IMesh *mesh_ptr[24];
197 float visual_scale; // Misc. scale parameter
199 TileDef tiledef_special[CF_SPECIAL_COUNT]; // eg. flowing liquid
202 // Post effect color, drawn when the camera is inside the node.
203 video::SColor post_effect_color;
204 // Type of MapNode::param1
205 ContentParamType param_type;
206 // Type of MapNode::param2
207 ContentParamType2 param_type_2;
208 // True for all ground-like things like stone and mud, false for eg. trees
209 bool is_ground_content;
210 bool light_propagates;
211 bool sunlight_propagates;
212 // This is used for collision detection.
213 // Also for general solidness queries.
215 // Player can point to these
217 // Player can dig these
219 // Player can climb these
221 // Player can build on these
223 // Player cannot build to these (placement prediction disabled)
225 // Flowing liquid or snow, value = default level
227 // Whether the node is non-liquid, source liquid or flowing liquid
228 enum LiquidType liquid_type;
229 // If the content is liquid, this is the flowing version of the liquid.
230 std::string liquid_alternative_flowing;
231 // If the content is liquid, this is the source version of the liquid.
232 std::string liquid_alternative_source;
233 // Viscosity for fluid flow, ranging from 1 to 7, with
234 // 1 giving almost instantaneous propagation and 7 being
235 // the slowest possible
237 // Is liquid renewable (new liquid source will be created between 2 existing)
238 bool liquid_renewable;
239 // Number of flowing liquids surrounding source
242 // Amount of light the node emits
244 u32 damage_per_second;
246 NodeBox selection_box;
247 NodeBox collision_box;
248 // Used for waving leaves/plants
250 // Compatibility with old maps
251 // Set to true if paramtype used to be 'facedir_simple'
252 bool legacy_facedir_simple;
253 // Set to true if wall_mounted used to be set to true
254 bool legacy_wallmounted;
257 SimpleSoundSpec sound_footstep;
258 SimpleSoundSpec sound_dig;
259 SimpleSoundSpec sound_dug;
268 void serialize(std::ostream &os, u16 protocol_version);
269 void deSerialize(std::istream &is);
270 void serializeOld(std::ostream &os, u16 protocol_version);
271 void deSerializeOld(std::istream &is, int version);
276 bool isLiquid() const{
277 return (liquid_type != LIQUID_NONE);
279 bool sameLiquid(const ContentFeatures &f) const{
280 if(!isLiquid() || !f.isLiquid()) return false;
281 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
285 enum NodeResolveMethod {
288 NODE_RESOLVE_DEFERRED,
291 class INodeDefManager
295 virtual ~INodeDefManager(){}
296 // Get node definition
297 virtual const ContentFeatures& get(content_t c) const=0;
298 virtual const ContentFeatures& get(const MapNode &n) const=0;
299 virtual bool getId(const std::string &name, content_t &result) const=0;
300 virtual content_t getId(const std::string &name) const=0;
301 // Allows "group:name" in addition to regular node names
302 virtual void getIds(const std::string &name, std::set<content_t> &result)
304 virtual const ContentFeatures& get(const std::string &name) const=0;
306 virtual void serialize(std::ostream &os, u16 protocol_version)=0;
308 virtual bool getNodeRegistrationStatus() const=0;
309 virtual void setNodeRegistrationStatus(bool completed)=0;
311 virtual void pendNodeResolve(NodeResolver *nr, NodeResolveMethod how)=0;
312 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
313 virtual void runNodeResolveCallbacks()=0;
316 class IWritableNodeDefManager : public INodeDefManager
319 IWritableNodeDefManager(){}
320 virtual ~IWritableNodeDefManager(){}
321 virtual IWritableNodeDefManager* clone()=0;
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 // If not found, returns CONTENT_IGNORE
327 virtual content_t getId(const std::string &name) const=0;
328 // Allows "group:name" in addition to regular node names
329 virtual void getIds(const std::string &name, std::set<content_t> &result)
331 // If not found, returns the features of CONTENT_UNKNOWN
332 virtual const ContentFeatures& get(const std::string &name) const=0;
334 // Register node definition by name (allocate an id)
335 // If returns CONTENT_IGNORE, could not allocate id
336 virtual content_t set(const std::string &name,
337 const ContentFeatures &def)=0;
338 // If returns CONTENT_IGNORE, could not allocate id
339 virtual content_t allocateDummy(const std::string &name)=0;
342 Update item alias mapping.
343 Call after updating item definitions.
345 virtual void updateAliases(IItemDefManager *idef)=0;
348 Update tile textures to latest return values of TextueSource.
350 virtual void updateTextures(IGameDef *gamedef,
351 /*argument: */void (*progress_callback)(void *progress_args, u32 progress, u32 max_progress),
352 /*argument: */void *progress_callback_args)=0;
354 virtual void serialize(std::ostream &os, u16 protocol_version)=0;
355 virtual void deSerialize(std::istream &is)=0;
357 virtual bool getNodeRegistrationStatus() const=0;
358 virtual void setNodeRegistrationStatus(bool completed)=0;
360 virtual void pendNodeResolve(NodeResolver *nr, NodeResolveMethod how)=0;
361 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
362 virtual void runNodeResolveCallbacks()=0;
365 IWritableNodeDefManager *createNodeDefManager();
370 virtual ~NodeResolver();
371 virtual void resolveNodeNames() = 0;
373 bool getIdFromNrBacklog(content_t *result_out,
374 const std::string &node_alt, content_t c_fallback);
375 bool getIdsFromNrBacklog(std::vector<content_t> *result_out,
376 bool all_required=false, content_t c_fallback=CONTENT_IGNORE);
377 const std::string &getNodeName(content_t c) const;
379 void nodeResolveInternal();
382 u32 m_nnlistsizes_idx;
383 std::vector<std::string> m_nodenames;
384 std::vector<size_t> m_nnlistsizes;
385 INodeDefManager *m_ndef;