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, ...
83 NODEBOX_CONNECTED, // optionally draws nodeboxes if a neighbor node attaches
88 enum NodeBoxType type;
89 // NODEBOX_REGULAR (no parameters)
91 std::vector<aabb3f> fixed;
92 // NODEBOX_WALLMOUNTED
95 aabb3f wall_side; // being at the -X side
97 std::vector<aabb3f> connect_top;
98 std::vector<aabb3f> connect_bottom;
99 std::vector<aabb3f> connect_front;
100 std::vector<aabb3f> connect_left;
101 std::vector<aabb3f> connect_back;
102 std::vector<aabb3f> connect_right;
108 void serialize(std::ostream &os, u16 protocol_version) const;
109 void deSerialize(std::istream &is);
117 NDT_NORMAL, // A basic solid block
118 NDT_AIRLIKE, // Nothing is drawn
119 NDT_LIQUID, // Do not draw face towards same kind of flowing/source liquid
120 NDT_FLOWINGLIQUID, // A very special kind of thing
121 NDT_GLASSLIKE, // Glass-like, don't draw faces towards other glass
122 NDT_ALLFACES, // Leaves-like, draw all faces no matter what
123 NDT_ALLFACES_OPTIONAL, // Fancy -> allfaces, fast -> normal
130 NDT_GLASSLIKE_FRAMED, // Glass-like, draw connected frames and all all
132 // uses 2 textures, one for frames, second for faces
133 NDT_FIRELIKE, // Draw faces slightly rotated and only on connecting nodes,
134 NDT_GLASSLIKE_FRAMED_OPTIONAL, // enabled -> connected, disabled -> Glass-like
135 // uses 2 textures, one for frames, second for faces
136 NDT_MESH, // Uses static meshes
140 Stand-alone definition of a TileSpec (basically a server-side TileSpec)
142 enum TileAnimationType{
144 TAT_VERTICAL_FRAMES=1,
149 bool backface_culling; // Takes effect only in special cases
150 bool tileable_horizontal;
151 bool tileable_vertical;
153 enum TileAnimationType type;
154 int aspect_w; // width for aspect ratio
155 int aspect_h; // height for aspect ratio
156 float length; // seconds
162 backface_culling = true;
163 tileable_horizontal = true;
164 tileable_vertical = true;
165 animation.type = TAT_NONE;
166 animation.aspect_w = 1;
167 animation.aspect_h = 1;
168 animation.length = 1.0;
171 void serialize(std::ostream &os, u16 protocol_version) const;
172 void deSerialize(std::istream &is, const u8 contentfeatures_version, const NodeDrawType drawtype);
175 #define CF_SPECIAL_COUNT 6
177 struct ContentFeatures
184 // up down right left back front
187 // - Currently used for flowing liquids
188 TileSpec special_tiles[CF_SPECIAL_COUNT];
189 u8 solidness; // Used when choosing which face is drawn
190 u8 visual_solidness; // When solidness=0, this tells how it looks like
191 bool backface_culling;
194 // Server-side cached callback existence for fast skipping
195 bool has_on_construct;
196 bool has_on_destruct;
197 bool has_after_destruct;
203 std::string name; // "" = undefined node
204 ItemGroupList groups; // Same as in itemdef
207 enum NodeDrawType drawtype;
210 scene::IMesh *mesh_ptr[24];
211 video::SColor minimap_color;
213 float visual_scale; // Misc. scale parameter
215 TileDef tiledef_special[CF_SPECIAL_COUNT]; // eg. flowing liquid
218 // Post effect color, drawn when the camera is inside the node.
219 video::SColor post_effect_color;
221 // Type of MapNode::param1
222 ContentParamType param_type;
223 // Type of MapNode::param2
224 ContentParamType2 param_type_2;
225 // True for all ground-like things like stone and mud, false for eg. trees
226 bool is_ground_content;
227 bool light_propagates;
228 bool sunlight_propagates;
229 // This is used for collision detection.
230 // Also for general solidness queries.
232 // Player can point to these
234 // Player can dig these
236 // Player can climb these
238 // Player can build on these
240 // Liquids flow into and replace node
242 // Player cannot build to these (placement prediction disabled)
244 // Flowing liquid or snow, value = default level
246 // Whether the node is non-liquid, source liquid or flowing liquid
247 enum LiquidType liquid_type;
248 // If the content is liquid, this is the flowing version of the liquid.
249 std::string liquid_alternative_flowing;
250 // If the content is liquid, this is the source version of the liquid.
251 std::string liquid_alternative_source;
252 // Viscosity for fluid flow, ranging from 1 to 7, with
253 // 1 giving almost instantaneous propagation and 7 being
254 // the slowest possible
256 // Is liquid renewable (new liquid source will be created between 2 existing)
257 bool liquid_renewable;
258 // Number of flowing liquids surrounding source
261 // Amount of light the node emits
263 u32 damage_per_second;
265 NodeBox selection_box;
266 NodeBox collision_box;
267 // Used for waving leaves/plants
269 // Compatibility with old maps
270 // Set to true if paramtype used to be 'facedir_simple'
271 bool legacy_facedir_simple;
272 // Set to true if wall_mounted used to be set to true
273 bool legacy_wallmounted;
274 // for NDT_CONNECTED pairing
278 SimpleSoundSpec sound_footstep;
279 SimpleSoundSpec sound_dig;
280 SimpleSoundSpec sound_dug;
282 std::vector<std::string> connects_to;
283 std::set<content_t> connects_to_ids;
292 void serialize(std::ostream &os, u16 protocol_version) const;
293 void deSerialize(std::istream &is);
294 void serializeOld(std::ostream &os, u16 protocol_version) const;
295 void deSerializeOld(std::istream &is, int version);
300 bool isLiquid() const{
301 return (liquid_type != LIQUID_NONE);
303 bool sameLiquid(const ContentFeatures &f) const{
304 if(!isLiquid() || !f.isLiquid()) return false;
305 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
309 class INodeDefManager {
312 virtual ~INodeDefManager(){}
313 // Get node definition
314 virtual const ContentFeatures &get(content_t c) const=0;
315 virtual const ContentFeatures &get(const MapNode &n) const=0;
316 virtual bool getId(const std::string &name, content_t &result) const=0;
317 virtual content_t getId(const std::string &name) const=0;
318 // Allows "group:name" in addition to regular node names
319 // returns false if node name not found, true otherwise
320 virtual bool getIds(const std::string &name, std::set<content_t> &result)
322 virtual const ContentFeatures &get(const std::string &name) const=0;
324 virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
326 virtual bool getNodeRegistrationStatus() const=0;
328 virtual void pendNodeResolve(NodeResolver *nr)=0;
329 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
330 virtual bool nodeboxConnects(const MapNode from, const MapNode to, u8 connect_face)=0;
333 class IWritableNodeDefManager : public INodeDefManager {
335 IWritableNodeDefManager(){}
336 virtual ~IWritableNodeDefManager(){}
337 virtual IWritableNodeDefManager* clone()=0;
338 // Get node definition
339 virtual const ContentFeatures &get(content_t c) const=0;
340 virtual const ContentFeatures &get(const MapNode &n) const=0;
341 virtual bool getId(const std::string &name, content_t &result) const=0;
342 // If not found, returns CONTENT_IGNORE
343 virtual content_t getId(const std::string &name) const=0;
344 // Allows "group:name" in addition to regular node names
345 virtual bool getIds(const std::string &name, std::set<content_t> &result)
347 // If not found, returns the features of CONTENT_UNKNOWN
348 virtual const ContentFeatures &get(const std::string &name) const=0;
350 // Register node definition by name (allocate an id)
351 // If returns CONTENT_IGNORE, could not allocate id
352 virtual content_t set(const std::string &name,
353 const ContentFeatures &def)=0;
354 // If returns CONTENT_IGNORE, could not allocate id
355 virtual content_t allocateDummy(const std::string &name)=0;
358 Update item alias mapping.
359 Call after updating item definitions.
361 virtual void updateAliases(IItemDefManager *idef)=0;
364 Override textures from servers with ones specified in texturepack/override.txt
366 virtual void applyTextureOverrides(const std::string &override_filepath)=0;
369 Update tile textures to latest return values of TextueSource.
371 virtual void updateTextures(IGameDef *gamedef,
372 void (*progress_cbk)(void *progress_args, u32 progress, u32 max_progress),
373 void *progress_cbk_args)=0;
375 virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
376 virtual void deSerialize(std::istream &is)=0;
378 virtual bool getNodeRegistrationStatus() const=0;
379 virtual void setNodeRegistrationStatus(bool completed)=0;
381 virtual void pendNodeResolve(NodeResolver *nr)=0;
382 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
383 virtual void runNodeResolveCallbacks()=0;
384 virtual void resetNodeResolveState()=0;
385 virtual void mapNodeboxConnections()=0;
388 IWritableNodeDefManager *createNodeDefManager();
393 virtual ~NodeResolver();
394 virtual void resolveNodeNames() = 0;
396 bool getIdFromNrBacklog(content_t *result_out,
397 const std::string &node_alt, content_t c_fallback);
398 bool getIdsFromNrBacklog(std::vector<content_t> *result_out,
399 bool all_required=false, content_t c_fallback=CONTENT_IGNORE);
401 void nodeResolveInternal();
404 u32 m_nnlistsizes_idx;
405 std::vector<std::string> m_nodenames;
406 std::vector<size_t> m_nnlistsizes;
407 INodeDefManager *m_ndef;