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
68 // Mesh options for plants
81 NODEBOX_REGULAR, // Regular block; allows buildable_to
82 NODEBOX_FIXED, // Static separately defined box(es)
83 NODEBOX_WALLMOUNTED, // Box for wall mounted nodes; (top, bottom, side)
84 NODEBOX_LEVELED, // Same as fixed, but with dynamic height from param2. for snow, ...
85 NODEBOX_CONNECTED, // optionally draws nodeboxes if a neighbor node attaches
90 enum NodeBoxType type;
91 // NODEBOX_REGULAR (no parameters)
93 std::vector<aabb3f> fixed;
94 // NODEBOX_WALLMOUNTED
97 aabb3f wall_side; // being at the -X side
99 std::vector<aabb3f> connect_top;
100 std::vector<aabb3f> connect_bottom;
101 std::vector<aabb3f> connect_front;
102 std::vector<aabb3f> connect_left;
103 std::vector<aabb3f> connect_back;
104 std::vector<aabb3f> connect_right;
110 void serialize(std::ostream &os, u16 protocol_version) const;
111 void deSerialize(std::istream &is);
123 class TextureSettings {
125 LeavesStyle leaves_style;
127 bool connected_glass;
128 bool use_normal_texture;
129 bool enable_mesh_cache;
139 NDT_NORMAL, // A basic solid block
140 NDT_AIRLIKE, // Nothing is drawn
141 NDT_LIQUID, // Do not draw face towards same kind of flowing/source liquid
142 NDT_FLOWINGLIQUID, // A very special kind of thing
143 NDT_GLASSLIKE, // Glass-like, don't draw faces towards other glass
144 NDT_ALLFACES, // Leaves-like, draw all faces no matter what
145 NDT_ALLFACES_OPTIONAL, // Fancy -> allfaces, fast -> normal
152 NDT_GLASSLIKE_FRAMED, // Glass-like, draw connected frames and all all
154 // uses 2 textures, one for frames, second for faces
155 NDT_FIRELIKE, // Draw faces slightly rotated and only on connecting nodes,
156 NDT_GLASSLIKE_FRAMED_OPTIONAL, // enabled -> connected, disabled -> Glass-like
157 // uses 2 textures, one for frames, second for faces
158 NDT_MESH, // Uses static meshes
162 Stand-alone definition of a TileSpec (basically a server-side TileSpec)
166 AT_VERTICAL_FRAMES = 1,
167 AT_2D_ANIMATION_SHEET = 2,
172 bool backface_culling; // Takes effect only in special cases
173 bool tileable_horizontal;
174 bool tileable_vertical;
176 enum AnimationType type;
177 int aspect_w; // width for aspect ratio
178 int aspect_h; // height for aspect ratio
179 float length; // seconds
185 backface_culling = true;
186 tileable_horizontal = true;
187 tileable_vertical = true;
188 animation.type = AT_NONE;
189 animation.aspect_w = 1;
190 animation.aspect_h = 1;
191 animation.length = 1.0;
194 void serialize(std::ostream &os, u16 protocol_version) const;
195 void deSerialize(std::istream &is, const u8 contentfeatures_version, const NodeDrawType drawtype);
198 #define CF_SPECIAL_COUNT 6
200 struct ContentFeatures
207 // up down right left back front
210 // - Currently used for flowing liquids
211 TileSpec special_tiles[CF_SPECIAL_COUNT];
212 u8 solidness; // Used when choosing which face is drawn
213 u8 visual_solidness; // When solidness=0, this tells how it looks like
214 bool backface_culling;
217 // Server-side cached callback existence for fast skipping
218 bool has_on_construct;
219 bool has_on_destruct;
220 bool has_after_destruct;
226 std::string name; // "" = undefined node
227 ItemGroupList groups; // Same as in itemdef
230 enum NodeDrawType drawtype;
233 scene::IMesh *mesh_ptr[24];
234 video::SColor minimap_color;
236 float visual_scale; // Misc. scale parameter
238 TileDef tiledef_special[CF_SPECIAL_COUNT]; // eg. flowing liquid
241 // Post effect color, drawn when the camera is inside the node.
242 video::SColor post_effect_color;
244 // Type of MapNode::param1
245 ContentParamType param_type;
246 // Type of MapNode::param2
247 ContentParamType2 param_type_2;
248 // True for all ground-like things like stone and mud, false for eg. trees
249 bool is_ground_content;
250 bool light_propagates;
251 bool sunlight_propagates;
252 // This is used for collision detection.
253 // Also for general solidness queries.
255 // Player can point to these
257 // Player can dig these
259 // Player can climb these
261 // Player can build on these
263 // Liquids flow into and replace node
265 // Player cannot build to these (placement prediction disabled)
267 // Flowing liquid or snow, value = default level
269 // Whether the node is non-liquid, source liquid or flowing liquid
270 enum LiquidType liquid_type;
271 // If the content is liquid, this is the flowing version of the liquid.
272 std::string liquid_alternative_flowing;
273 // If the content is liquid, this is the source version of the liquid.
274 std::string liquid_alternative_source;
275 // Viscosity for fluid flow, ranging from 1 to 7, with
276 // 1 giving almost instantaneous propagation and 7 being
277 // the slowest possible
279 // Is liquid renewable (new liquid source will be created between 2 existing)
280 bool liquid_renewable;
281 // Number of flowing liquids surrounding source
284 // Amount of light the node emits
286 u32 damage_per_second;
288 NodeBox selection_box;
289 NodeBox collision_box;
290 // Used for waving leaves/plants
292 // Compatibility with old maps
293 // Set to true if paramtype used to be 'facedir_simple'
294 bool legacy_facedir_simple;
295 // Set to true if wall_mounted used to be set to true
296 bool legacy_wallmounted;
297 // for NDT_CONNECTED pairing
301 SimpleSoundSpec sound_footstep;
302 SimpleSoundSpec sound_dig;
303 SimpleSoundSpec sound_dug;
305 std::vector<std::string> connects_to;
306 std::set<content_t> connects_to_ids;
315 void serialize(std::ostream &os, u16 protocol_version) const;
316 void deSerialize(std::istream &is);
317 void serializeOld(std::ostream &os, u16 protocol_version) const;
318 void deSerializeOld(std::istream &is, int version);
323 bool isLiquid() const{
324 return (liquid_type != LIQUID_NONE);
326 bool sameLiquid(const ContentFeatures &f) const{
327 if(!isLiquid() || !f.isLiquid()) return false;
328 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
332 void fillTileAttribs(ITextureSource *tsrc, TileSpec *tile, TileDef *tiledef,
333 u32 shader_id, bool use_normal_texture, bool backface_culling,
334 u8 alpha, u8 material_type);
335 void updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc,
336 scene::ISceneManager *smgr, scene::IMeshManipulator *meshmanip,
337 IGameDef *gamedef, const TextureSettings &tsettings);
341 class INodeDefManager {
344 virtual ~INodeDefManager(){}
345 // Get node definition
346 virtual const ContentFeatures &get(content_t c) const=0;
347 virtual const ContentFeatures &get(const MapNode &n) const=0;
348 virtual bool getId(const std::string &name, content_t &result) const=0;
349 virtual content_t getId(const std::string &name) const=0;
350 // Allows "group:name" in addition to regular node names
351 // returns false if node name not found, true otherwise
352 virtual bool getIds(const std::string &name, std::set<content_t> &result)
354 virtual const ContentFeatures &get(const std::string &name) const=0;
356 virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
358 virtual bool getNodeRegistrationStatus() const=0;
360 virtual void pendNodeResolve(NodeResolver *nr)=0;
361 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
362 virtual bool nodeboxConnects(const MapNode from, const MapNode to, u8 connect_face)=0;
365 class IWritableNodeDefManager : public INodeDefManager {
367 IWritableNodeDefManager(){}
368 virtual ~IWritableNodeDefManager(){}
369 virtual IWritableNodeDefManager* clone()=0;
370 // Get node definition
371 virtual const ContentFeatures &get(content_t c) const=0;
372 virtual const ContentFeatures &get(const MapNode &n) const=0;
373 virtual bool getId(const std::string &name, content_t &result) const=0;
374 // If not found, returns CONTENT_IGNORE
375 virtual content_t getId(const std::string &name) const=0;
376 // Allows "group:name" in addition to regular node names
377 virtual bool getIds(const std::string &name, std::set<content_t> &result)
379 // If not found, returns the features of CONTENT_UNKNOWN
380 virtual const ContentFeatures &get(const std::string &name) const=0;
382 // Register node definition by name (allocate an id)
383 // If returns CONTENT_IGNORE, could not allocate id
384 virtual content_t set(const std::string &name,
385 const ContentFeatures &def)=0;
386 // If returns CONTENT_IGNORE, could not allocate id
387 virtual content_t allocateDummy(const std::string &name)=0;
389 virtual void removeNode(const std::string &name)=0;
392 Update item alias mapping.
393 Call after updating item definitions.
395 virtual void updateAliases(IItemDefManager *idef)=0;
398 Override textures from servers with ones specified in texturepack/override.txt
400 virtual void applyTextureOverrides(const std::string &override_filepath)=0;
403 Update tile textures to latest return values of TextueSource.
405 virtual void updateTextures(IGameDef *gamedef,
406 void (*progress_cbk)(void *progress_args, u32 progress, u32 max_progress),
407 void *progress_cbk_args)=0;
409 virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
410 virtual void deSerialize(std::istream &is)=0;
412 virtual bool getNodeRegistrationStatus() const=0;
413 virtual void setNodeRegistrationStatus(bool completed)=0;
415 virtual void pendNodeResolve(NodeResolver *nr)=0;
416 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
417 virtual void runNodeResolveCallbacks()=0;
418 virtual void resetNodeResolveState()=0;
419 virtual void mapNodeboxConnections()=0;
422 IWritableNodeDefManager *createNodeDefManager();
427 virtual ~NodeResolver();
428 virtual void resolveNodeNames() = 0;
430 bool getIdFromNrBacklog(content_t *result_out,
431 const std::string &node_alt, content_t c_fallback);
432 bool getIdsFromNrBacklog(std::vector<content_t> *result_out,
433 bool all_required=false, content_t c_fallback=CONTENT_IGNORE);
435 void nodeResolveInternal();
438 u32 m_nnlistsizes_idx;
439 std::vector<std::string> m_nodenames;
440 std::vector<size_t> m_nnlistsizes;
441 INodeDefManager *m_ndef;