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 // Liquids flow into and replace node
234 // Player cannot build to these (placement prediction disabled)
236 // Flowing liquid or snow, value = default level
238 // Whether the node is non-liquid, source liquid or flowing liquid
239 enum LiquidType liquid_type;
240 // If the content is liquid, this is the flowing version of the liquid.
241 std::string liquid_alternative_flowing;
242 // If the content is liquid, this is the source version of the liquid.
243 std::string liquid_alternative_source;
244 // Viscosity for fluid flow, ranging from 1 to 7, with
245 // 1 giving almost instantaneous propagation and 7 being
246 // the slowest possible
248 // Is liquid renewable (new liquid source will be created between 2 existing)
249 bool liquid_renewable;
250 // Number of flowing liquids surrounding source
253 // Amount of light the node emits
255 u32 damage_per_second;
257 NodeBox selection_box;
258 NodeBox collision_box;
259 // Used for waving leaves/plants
261 // Compatibility with old maps
262 // Set to true if paramtype used to be 'facedir_simple'
263 bool legacy_facedir_simple;
264 // Set to true if wall_mounted used to be set to true
265 bool legacy_wallmounted;
268 SimpleSoundSpec sound_footstep;
269 SimpleSoundSpec sound_dig;
270 SimpleSoundSpec sound_dug;
279 void serialize(std::ostream &os, u16 protocol_version) const;
280 void deSerialize(std::istream &is);
281 void serializeOld(std::ostream &os, u16 protocol_version) const;
282 void deSerializeOld(std::istream &is, int version);
287 bool isLiquid() const{
288 return (liquid_type != LIQUID_NONE);
290 bool sameLiquid(const ContentFeatures &f) const{
291 if(!isLiquid() || !f.isLiquid()) return false;
292 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
296 class INodeDefManager {
299 virtual ~INodeDefManager(){}
300 // Get node definition
301 virtual const ContentFeatures &get(content_t c) const=0;
302 virtual const ContentFeatures &get(const MapNode &n) const=0;
303 virtual bool getId(const std::string &name, content_t &result) const=0;
304 virtual content_t getId(const std::string &name) const=0;
305 // Allows "group:name" in addition to regular node names
306 virtual void getIds(const std::string &name, std::set<content_t> &result)
308 virtual const ContentFeatures &get(const std::string &name) const=0;
310 virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
312 virtual bool getNodeRegistrationStatus() const=0;
314 virtual void pendNodeResolve(NodeResolver *nr)=0;
315 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
318 class IWritableNodeDefManager : public INodeDefManager {
320 IWritableNodeDefManager(){}
321 virtual ~IWritableNodeDefManager(){}
322 virtual IWritableNodeDefManager* clone()=0;
323 // Get node definition
324 virtual const ContentFeatures &get(content_t c) const=0;
325 virtual const ContentFeatures &get(const MapNode &n) const=0;
326 virtual bool getId(const std::string &name, content_t &result) const=0;
327 // If not found, returns CONTENT_IGNORE
328 virtual content_t getId(const std::string &name) const=0;
329 // Allows "group:name" in addition to regular node names
330 virtual void getIds(const std::string &name, std::set<content_t> &result)
332 // If not found, returns the features of CONTENT_UNKNOWN
333 virtual const ContentFeatures &get(const std::string &name) const=0;
335 // Register node definition by name (allocate an id)
336 // If returns CONTENT_IGNORE, could not allocate id
337 virtual content_t set(const std::string &name,
338 const ContentFeatures &def)=0;
339 // If returns CONTENT_IGNORE, could not allocate id
340 virtual content_t allocateDummy(const std::string &name)=0;
343 Update item alias mapping.
344 Call after updating item definitions.
346 virtual void updateAliases(IItemDefManager *idef)=0;
349 Override textures from servers with ones specified in texturepack/override.txt
351 virtual void applyTextureOverrides(const std::string &override_filepath)=0;
354 Update tile textures to latest return values of TextueSource.
356 virtual void updateTextures(IGameDef *gamedef,
357 void (*progress_cbk)(void *progress_args, u32 progress, u32 max_progress),
358 void *progress_cbk_args)=0;
360 virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
361 virtual void deSerialize(std::istream &is)=0;
363 virtual bool getNodeRegistrationStatus() const=0;
364 virtual void setNodeRegistrationStatus(bool completed)=0;
366 virtual void pendNodeResolve(NodeResolver *nr)=0;
367 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
368 virtual void runNodeResolveCallbacks()=0;
369 virtual void resetNodeResolveState()=0;
372 IWritableNodeDefManager *createNodeDefManager();
377 virtual ~NodeResolver();
378 virtual void resolveNodeNames() = 0;
380 bool getIdFromNrBacklog(content_t *result_out,
381 const std::string &node_alt, content_t c_fallback);
382 bool getIdsFromNrBacklog(std::vector<content_t> *result_out,
383 bool all_required=false, content_t c_fallback=CONTENT_IGNORE);
385 void nodeResolveInternal();
388 u32 m_nnlistsizes_idx;
389 std::vector<std::string> m_nodenames;
390 std::vector<size_t> m_nnlistsizes;
391 INodeDefManager *m_ndef;