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
38 class INodeDefManager;
39 class IItemDefManager;
45 typedef std::list<std::pair<content_t, int> > GroupItems;
53 enum ContentParamType2
58 // Flowing liquid properties
60 // Direction for chests and furnaces and such
62 // Direction for signs, torches and such
64 // Block level like FLOWINGLIQUID
66 // 2D rotation for things like plants
79 NODEBOX_REGULAR, // Regular block; allows buildable_to
80 NODEBOX_FIXED, // Static separately defined box(es)
81 NODEBOX_WALLMOUNTED, // Box for wall mounted nodes; (top, bottom, side)
82 NODEBOX_LEVELED, // Same as fixed, but with dynamic height from param2. for snow, ...
87 enum NodeBoxType type;
88 // NODEBOX_REGULAR (no parameters)
90 std::vector<aabb3f> fixed;
91 // NODEBOX_WALLMOUNTED
94 aabb3f wall_side; // being at the -X side
100 void serialize(std::ostream &os, u16 protocol_version) const;
101 void deSerialize(std::istream &is);
108 Stand-alone definition of a TileSpec (basically a server-side TileSpec)
110 enum TileAnimationType{
112 TAT_VERTICAL_FRAMES=1,
117 bool backface_culling; // Takes effect only in special cases
118 bool tileable_horizontal;
119 bool tileable_vertical;
121 enum TileAnimationType type;
122 int aspect_w; // width for aspect ratio
123 int aspect_h; // height for aspect ratio
124 float length; // seconds
130 backface_culling = true;
131 tileable_horizontal = true;
132 tileable_vertical = true;
133 animation.type = TAT_NONE;
134 animation.aspect_w = 1;
135 animation.aspect_h = 1;
136 animation.length = 1.0;
139 void serialize(std::ostream &os, u16 protocol_version) const;
140 void deSerialize(std::istream &is);
145 NDT_NORMAL, // A basic solid block
146 NDT_AIRLIKE, // Nothing is drawn
147 NDT_LIQUID, // Do not draw face towards same kind of flowing/source liquid
148 NDT_FLOWINGLIQUID, // A very special kind of thing
149 NDT_GLASSLIKE, // Glass-like, don't draw faces towards other glass
150 NDT_ALLFACES, // Leaves-like, draw all faces no matter what
151 NDT_ALLFACES_OPTIONAL, // Fancy -> allfaces, fast -> normal
158 NDT_GLASSLIKE_FRAMED, // Glass-like, draw connected frames and all all
160 // uses 2 textures, one for frames, second for faces
161 NDT_FIRELIKE, // Draw faces slightly rotated and only on connecting nodes,
162 NDT_GLASSLIKE_FRAMED_OPTIONAL, // enabled -> connected, disabled -> Glass-like
163 // uses 2 textures, one for frames, second for faces
164 NDT_MESH, // Uses static meshes
167 #define CF_SPECIAL_COUNT 6
169 struct ContentFeatures
176 // up down right left back front
179 // - Currently used for flowing liquids
180 TileSpec special_tiles[CF_SPECIAL_COUNT];
181 u8 solidness; // Used when choosing which face is drawn
182 u8 visual_solidness; // When solidness=0, this tells how it looks like
183 bool backface_culling;
186 // Server-side cached callback existence for fast skipping
187 bool has_on_construct;
188 bool has_on_destruct;
189 bool has_after_destruct;
195 std::string name; // "" = undefined node
196 ItemGroupList groups; // Same as in itemdef
199 enum NodeDrawType drawtype;
202 scene::IMesh *mesh_ptr[24];
203 video::SColor minimap_color;
205 float visual_scale; // Misc. scale parameter
207 TileDef tiledef_special[CF_SPECIAL_COUNT]; // eg. flowing liquid
210 // Post effect color, drawn when the camera is inside the node.
211 video::SColor post_effect_color;
213 // Type of MapNode::param1
214 ContentParamType param_type;
215 // Type of MapNode::param2
216 ContentParamType2 param_type_2;
217 // True for all ground-like things like stone and mud, false for eg. trees
218 bool is_ground_content;
219 bool light_propagates;
220 bool sunlight_propagates;
221 // This is used for collision detection.
222 // Also for general solidness queries.
224 // Player can point to these
226 // Player can dig these
228 // Player can climb these
230 // Player can build on these
232 // Player cannot build to these (placement prediction disabled)
234 // Flowing liquid or snow, value = default level
236 // Whether the node is non-liquid, source liquid or flowing liquid
237 enum LiquidType liquid_type;
238 // If the content is liquid, this is the flowing version of the liquid.
239 std::string liquid_alternative_flowing;
240 // If the content is liquid, this is the source version of the liquid.
241 std::string liquid_alternative_source;
242 // Viscosity for fluid flow, ranging from 1 to 7, with
243 // 1 giving almost instantaneous propagation and 7 being
244 // the slowest possible
246 // Is liquid renewable (new liquid source will be created between 2 existing)
247 bool liquid_renewable;
248 // Number of flowing liquids surrounding source
251 // Amount of light the node emits
253 u32 damage_per_second;
255 NodeBox selection_box;
256 NodeBox collision_box;
257 // Used for waving leaves/plants
259 // Compatibility with old maps
260 // Set to true if paramtype used to be 'facedir_simple'
261 bool legacy_facedir_simple;
262 // Set to true if wall_mounted used to be set to true
263 bool legacy_wallmounted;
266 SimpleSoundSpec sound_footstep;
267 SimpleSoundSpec sound_dig;
268 SimpleSoundSpec sound_dug;
277 void serialize(std::ostream &os, u16 protocol_version) const;
278 void deSerialize(std::istream &is);
279 void serializeOld(std::ostream &os, u16 protocol_version) const;
280 void deSerializeOld(std::istream &is, int version);
285 bool isLiquid() const{
286 return (liquid_type != LIQUID_NONE);
288 bool sameLiquid(const ContentFeatures &f) const{
289 if(!isLiquid() || !f.isLiquid()) return false;
290 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
294 class INodeDefManager {
297 virtual ~INodeDefManager(){}
298 // Get node definition
299 virtual const ContentFeatures &get(content_t c) const=0;
300 virtual const ContentFeatures &get(const MapNode &n) const=0;
301 virtual bool getId(const std::string &name, content_t &result) const=0;
302 virtual content_t getId(const std::string &name) const=0;
303 // Allows "group:name" in addition to regular node names
304 virtual void getIds(const std::string &name, std::set<content_t> &result)
306 virtual const ContentFeatures &get(const std::string &name) const=0;
308 virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
310 virtual bool getNodeRegistrationStatus() const=0;
312 virtual void pendNodeResolve(NodeResolver *nr)=0;
313 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
316 class IWritableNodeDefManager : public INodeDefManager {
318 IWritableNodeDefManager(){}
319 virtual ~IWritableNodeDefManager(){}
320 virtual IWritableNodeDefManager* clone()=0;
321 // Get node definition
322 virtual const ContentFeatures &get(content_t c) const=0;
323 virtual const ContentFeatures &get(const MapNode &n) const=0;
324 virtual bool getId(const std::string &name, content_t &result) const=0;
325 // If not found, returns CONTENT_IGNORE
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 // If not found, returns the features of CONTENT_UNKNOWN
331 virtual const ContentFeatures &get(const std::string &name) const=0;
333 // Register node definition by name (allocate an id)
334 // If returns CONTENT_IGNORE, could not allocate id
335 virtual content_t set(const std::string &name,
336 const ContentFeatures &def)=0;
337 // If returns CONTENT_IGNORE, could not allocate id
338 virtual content_t allocateDummy(const std::string &name)=0;
341 Update item alias mapping.
342 Call after updating item definitions.
344 virtual void updateAliases(IItemDefManager *idef)=0;
347 Override textures from servers with ones specified in texturepack/override.txt
349 virtual void applyTextureOverrides(const std::string &override_filepath)=0;
352 Update tile textures to latest return values of TextueSource.
354 virtual void updateTextures(IGameDef *gamedef,
355 void (*progress_cbk)(void *progress_args, u32 progress, u32 max_progress),
356 void *progress_cbk_args)=0;
358 virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
359 virtual void deSerialize(std::istream &is)=0;
361 virtual bool getNodeRegistrationStatus() const=0;
362 virtual void setNodeRegistrationStatus(bool completed)=0;
364 virtual void pendNodeResolve(NodeResolver *nr)=0;
365 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
366 virtual void runNodeResolveCallbacks()=0;
367 virtual void resetNodeResolveState()=0;
370 IWritableNodeDefManager *createNodeDefManager();
375 virtual ~NodeResolver();
376 virtual void resolveNodeNames() = 0;
378 bool getIdFromNrBacklog(content_t *result_out,
379 const std::string &node_alt, content_t c_fallback);
380 bool getIdsFromNrBacklog(std::vector<content_t> *result_out,
381 bool all_required=false, content_t c_fallback=CONTENT_IGNORE);
383 void nodeResolveInternal();
386 u32 m_nnlistsizes_idx;
387 std::vector<std::string> m_nodenames;
388 std::vector<size_t> m_nnlistsizes;
389 INodeDefManager *m_ndef;