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)
164 enum TileAnimationType{
166 TAT_VERTICAL_FRAMES=1,
171 bool backface_culling; // Takes effect only in special cases
172 bool tileable_horizontal;
173 bool tileable_vertical;
175 enum TileAnimationType type;
176 int aspect_w; // width for aspect ratio
177 int aspect_h; // height for aspect ratio
178 float length; // seconds
184 backface_culling = true;
185 tileable_horizontal = true;
186 tileable_vertical = true;
187 animation.type = TAT_NONE;
188 animation.aspect_w = 1;
189 animation.aspect_h = 1;
190 animation.length = 1.0;
193 void serialize(std::ostream &os, u16 protocol_version) const;
194 void deSerialize(std::istream &is, const u8 contentfeatures_version, const NodeDrawType drawtype);
197 #define CF_SPECIAL_COUNT 6
199 struct ContentFeatures
206 // up down right left back front
209 // - Currently used for flowing liquids
210 TileSpec special_tiles[CF_SPECIAL_COUNT];
211 u8 solidness; // Used when choosing which face is drawn
212 u8 visual_solidness; // When solidness=0, this tells how it looks like
213 bool backface_culling;
216 // Server-side cached callback existence for fast skipping
217 bool has_on_construct;
218 bool has_on_destruct;
219 bool has_after_destruct;
225 std::string name; // "" = undefined node
226 ItemGroupList groups; // Same as in itemdef
229 enum NodeDrawType drawtype;
232 scene::IMesh *mesh_ptr[24];
233 video::SColor minimap_color;
235 float visual_scale; // Misc. scale parameter
237 TileDef tiledef_special[CF_SPECIAL_COUNT]; // eg. flowing liquid
240 // Post effect color, drawn when the camera is inside the node.
241 video::SColor post_effect_color;
243 // Type of MapNode::param1
244 ContentParamType param_type;
245 // Type of MapNode::param2
246 ContentParamType2 param_type_2;
247 // True for all ground-like things like stone and mud, false for eg. trees
248 bool is_ground_content;
249 bool light_propagates;
250 bool sunlight_propagates;
251 // This is used for collision detection.
252 // Also for general solidness queries.
254 // Player can point to these
256 // Player can dig these
258 // Player can climb these
260 // Player can build on these
262 // Liquids flow into and replace node
264 // Player cannot build to these (placement prediction disabled)
266 // Flowing liquid or snow, value = default level
268 // Whether the node is non-liquid, source liquid or flowing liquid
269 enum LiquidType liquid_type;
270 // If the content is liquid, this is the flowing version of the liquid.
271 std::string liquid_alternative_flowing;
272 // If the content is liquid, this is the source version of the liquid.
273 std::string liquid_alternative_source;
274 // Viscosity for fluid flow, ranging from 1 to 7, with
275 // 1 giving almost instantaneous propagation and 7 being
276 // the slowest possible
278 // Is liquid renewable (new liquid source will be created between 2 existing)
279 bool liquid_renewable;
280 // Number of flowing liquids surrounding source
283 // Amount of light the node emits
285 u32 damage_per_second;
287 NodeBox selection_box;
288 NodeBox collision_box;
289 // Used for waving leaves/plants
291 // Compatibility with old maps
292 // Set to true if paramtype used to be 'facedir_simple'
293 bool legacy_facedir_simple;
294 // Set to true if wall_mounted used to be set to true
295 bool legacy_wallmounted;
296 // for NDT_CONNECTED pairing
300 SimpleSoundSpec sound_footstep;
301 SimpleSoundSpec sound_dig;
302 SimpleSoundSpec sound_dug;
304 std::vector<std::string> connects_to;
305 std::set<content_t> connects_to_ids;
314 void serialize(std::ostream &os, u16 protocol_version) const;
315 void deSerialize(std::istream &is);
316 void serializeOld(std::ostream &os, u16 protocol_version) const;
317 void deSerializeOld(std::istream &is, int version);
322 bool isLiquid() const{
323 return (liquid_type != LIQUID_NONE);
325 bool sameLiquid(const ContentFeatures &f) const{
326 if(!isLiquid() || !f.isLiquid()) return false;
327 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
331 void fillTileAttribs(ITextureSource *tsrc, TileSpec *tile, TileDef *tiledef,
332 u32 shader_id, bool use_normal_texture, bool backface_culling,
333 u8 alpha, u8 material_type);
334 void updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc,
335 scene::ISceneManager *smgr, scene::IMeshManipulator *meshmanip,
336 IGameDef *gamedef, const TextureSettings &tsettings);
340 class INodeDefManager {
343 virtual ~INodeDefManager(){}
344 // Get node definition
345 virtual const ContentFeatures &get(content_t c) const=0;
346 virtual const ContentFeatures &get(const MapNode &n) const=0;
347 virtual bool getId(const std::string &name, content_t &result) const=0;
348 virtual content_t getId(const std::string &name) const=0;
349 // Allows "group:name" in addition to regular node names
350 // returns false if node name not found, true otherwise
351 virtual bool getIds(const std::string &name, std::set<content_t> &result)
353 virtual const ContentFeatures &get(const std::string &name) const=0;
355 virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
357 virtual bool getNodeRegistrationStatus() const=0;
359 virtual void pendNodeResolve(NodeResolver *nr)=0;
360 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
361 virtual bool nodeboxConnects(const MapNode from, const MapNode to, u8 connect_face)=0;
364 class IWritableNodeDefManager : public INodeDefManager {
366 IWritableNodeDefManager(){}
367 virtual ~IWritableNodeDefManager(){}
368 virtual IWritableNodeDefManager* clone()=0;
369 // Get node definition
370 virtual const ContentFeatures &get(content_t c) const=0;
371 virtual const ContentFeatures &get(const MapNode &n) const=0;
372 virtual bool getId(const std::string &name, content_t &result) const=0;
373 // If not found, returns CONTENT_IGNORE
374 virtual content_t getId(const std::string &name) const=0;
375 // Allows "group:name" in addition to regular node names
376 virtual bool getIds(const std::string &name, std::set<content_t> &result)
378 // If not found, returns the features of CONTENT_UNKNOWN
379 virtual const ContentFeatures &get(const std::string &name) const=0;
381 // Register node definition by name (allocate an id)
382 // If returns CONTENT_IGNORE, could not allocate id
383 virtual content_t set(const std::string &name,
384 const ContentFeatures &def)=0;
385 // If returns CONTENT_IGNORE, could not allocate id
386 virtual content_t allocateDummy(const std::string &name)=0;
388 virtual void removeNode(const std::string &name)=0;
391 Update item alias mapping.
392 Call after updating item definitions.
394 virtual void updateAliases(IItemDefManager *idef)=0;
397 Override textures from servers with ones specified in texturepack/override.txt
399 virtual void applyTextureOverrides(const std::string &override_filepath)=0;
402 Update tile textures to latest return values of TextueSource.
404 virtual void updateTextures(IGameDef *gamedef,
405 void (*progress_cbk)(void *progress_args, u32 progress, u32 max_progress),
406 void *progress_cbk_args)=0;
408 virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
409 virtual void deSerialize(std::istream &is)=0;
411 virtual bool getNodeRegistrationStatus() const=0;
412 virtual void setNodeRegistrationStatus(bool completed)=0;
414 virtual void pendNodeResolve(NodeResolver *nr)=0;
415 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
416 virtual void runNodeResolveCallbacks()=0;
417 virtual void resetNodeResolveState()=0;
418 virtual void mapNodeboxConnections()=0;
421 IWritableNodeDefManager *createNodeDefManager();
426 virtual ~NodeResolver();
427 virtual void resolveNodeNames() = 0;
429 bool getIdFromNrBacklog(content_t *result_out,
430 const std::string &node_alt, content_t c_fallback);
431 bool getIdsFromNrBacklog(std::vector<content_t> *result_out,
432 bool all_required=false, content_t c_fallback=CONTENT_IGNORE);
434 void nodeResolveInternal();
437 u32 m_nnlistsizes_idx;
438 std::vector<std::string> m_nodenames;
439 std::vector<size_t> m_nnlistsizes;
440 INodeDefManager *m_ndef;