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
77 NODEBOX_REGULAR, // Regular block; allows buildable_to
78 NODEBOX_FIXED, // Static separately defined box(es)
79 NODEBOX_WALLMOUNTED, // Box for wall mounted nodes; (top, bottom, side)
80 NODEBOX_LEVELED, // Same as fixed, but with dynamic height from param2. for snow, ...
85 enum NodeBoxType type;
86 // NODEBOX_REGULAR (no parameters)
88 std::vector<aabb3f> fixed;
89 // NODEBOX_WALLMOUNTED
92 aabb3f wall_side; // being at the -X side
98 void serialize(std::ostream &os, u16 protocol_version) const;
99 void deSerialize(std::istream &is);
106 Stand-alone definition of a TileSpec (basically a server-side TileSpec)
108 enum TileAnimationType{
110 TAT_VERTICAL_FRAMES=1,
115 bool backface_culling; // Takes effect only in special cases
117 enum TileAnimationType type;
118 int aspect_w; // width for aspect ratio
119 int aspect_h; // height for aspect ratio
120 float length; // seconds
126 backface_culling = true;
127 animation.type = TAT_NONE;
128 animation.aspect_w = 1;
129 animation.aspect_h = 1;
130 animation.length = 1.0;
133 void serialize(std::ostream &os, u16 protocol_version) const;
134 void deSerialize(std::istream &is);
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
161 #define CF_SPECIAL_COUNT 6
163 struct ContentFeatures
170 // up down right left back front
173 // - Currently used for flowing liquids
174 TileSpec special_tiles[CF_SPECIAL_COUNT];
175 u8 solidness; // Used when choosing which face is drawn
176 u8 visual_solidness; // When solidness=0, this tells how it looks like
177 bool backface_culling;
180 // Server-side cached callback existence for fast skipping
181 bool has_on_construct;
182 bool has_on_destruct;
183 bool has_after_destruct;
189 std::string name; // "" = undefined node
190 ItemGroupList groups; // Same as in itemdef
193 enum NodeDrawType drawtype;
196 scene::IMesh *mesh_ptr[24];
197 video::SColor minimap_color;
199 float visual_scale; // Misc. scale parameter
201 TileDef tiledef_special[CF_SPECIAL_COUNT]; // eg. flowing liquid
204 // Post effect color, drawn when the camera is inside the node.
205 video::SColor post_effect_color;
207 // Type of MapNode::param1
208 ContentParamType param_type;
209 // Type of MapNode::param2
210 ContentParamType2 param_type_2;
211 // True for all ground-like things like stone and mud, false for eg. trees
212 bool is_ground_content;
213 bool light_propagates;
214 bool sunlight_propagates;
215 // This is used for collision detection.
216 // Also for general solidness queries.
218 // Player can point to these
220 // Player can dig these
222 // Player can climb these
224 // Player can build on these
226 // Player cannot build to these (placement prediction disabled)
228 // Flowing liquid or snow, value = default level
230 // Whether the node is non-liquid, source liquid or flowing liquid
231 enum LiquidType liquid_type;
232 // If the content is liquid, this is the flowing version of the liquid.
233 std::string liquid_alternative_flowing;
234 // If the content is liquid, this is the source version of the liquid.
235 std::string liquid_alternative_source;
236 // Viscosity for fluid flow, ranging from 1 to 7, with
237 // 1 giving almost instantaneous propagation and 7 being
238 // the slowest possible
240 // Is liquid renewable (new liquid source will be created between 2 existing)
241 bool liquid_renewable;
242 // Number of flowing liquids surrounding source
245 // Amount of light the node emits
247 u32 damage_per_second;
249 NodeBox selection_box;
250 NodeBox collision_box;
251 // Used for waving leaves/plants
253 // Compatibility with old maps
254 // Set to true if paramtype used to be 'facedir_simple'
255 bool legacy_facedir_simple;
256 // Set to true if wall_mounted used to be set to true
257 bool legacy_wallmounted;
260 SimpleSoundSpec sound_footstep;
261 SimpleSoundSpec sound_dig;
262 SimpleSoundSpec sound_dug;
271 void serialize(std::ostream &os, u16 protocol_version) const;
272 void deSerialize(std::istream &is);
273 void serializeOld(std::ostream &os, u16 protocol_version) const;
274 void deSerializeOld(std::istream &is, int version);
279 bool isLiquid() const{
280 return (liquid_type != LIQUID_NONE);
282 bool sameLiquid(const ContentFeatures &f) const{
283 if(!isLiquid() || !f.isLiquid()) return false;
284 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
288 class INodeDefManager {
291 virtual ~INodeDefManager(){}
292 // Get node definition
293 virtual const ContentFeatures &get(content_t c) const=0;
294 virtual const ContentFeatures &get(const MapNode &n) const=0;
295 virtual bool getId(const std::string &name, content_t &result) const=0;
296 virtual content_t getId(const std::string &name) const=0;
297 // Allows "group:name" in addition to regular node names
298 virtual void getIds(const std::string &name, std::set<content_t> &result)
300 virtual const ContentFeatures &get(const std::string &name) const=0;
302 virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
304 virtual bool getNodeRegistrationStatus() const=0;
306 virtual void pendNodeResolve(NodeResolver *nr)=0;
307 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
310 class IWritableNodeDefManager : public INodeDefManager {
312 IWritableNodeDefManager(){}
313 virtual ~IWritableNodeDefManager(){}
314 virtual IWritableNodeDefManager* clone()=0;
315 // Get node definition
316 virtual const ContentFeatures &get(content_t c) const=0;
317 virtual const ContentFeatures &get(const MapNode &n) const=0;
318 virtual bool getId(const std::string &name, content_t &result) const=0;
319 // If not found, returns CONTENT_IGNORE
320 virtual content_t getId(const std::string &name) const=0;
321 // Allows "group:name" in addition to regular node names
322 virtual void getIds(const std::string &name, std::set<content_t> &result)
324 // If not found, returns the features of CONTENT_UNKNOWN
325 virtual const ContentFeatures &get(const std::string &name) const=0;
327 // Register node definition by name (allocate an id)
328 // If returns CONTENT_IGNORE, could not allocate id
329 virtual content_t set(const std::string &name,
330 const ContentFeatures &def)=0;
331 // If returns CONTENT_IGNORE, could not allocate id
332 virtual content_t allocateDummy(const std::string &name)=0;
335 Update item alias mapping.
336 Call after updating item definitions.
338 virtual void updateAliases(IItemDefManager *idef)=0;
341 Override textures from servers with ones specified in texturepack/override.txt
343 virtual void applyTextureOverrides(const std::string &override_filepath)=0;
346 Update tile textures to latest return values of TextueSource.
348 virtual void updateTextures(IGameDef *gamedef,
349 void (*progress_cbk)(void *progress_args, u32 progress, u32 max_progress),
350 void *progress_cbk_args)=0;
352 virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
353 virtual void deSerialize(std::istream &is)=0;
355 virtual bool getNodeRegistrationStatus() const=0;
356 virtual void setNodeRegistrationStatus(bool completed)=0;
358 virtual void pendNodeResolve(NodeResolver *nr)=0;
359 virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
360 virtual void runNodeResolveCallbacks()=0;
361 virtual void resetNodeResolveState()=0;
364 IWritableNodeDefManager *createNodeDefManager();
369 virtual ~NodeResolver();
370 virtual void resolveNodeNames() = 0;
372 bool getIdFromNrBacklog(content_t *result_out,
373 const std::string &node_alt, content_t c_fallback);
374 bool getIdsFromNrBacklog(std::vector<content_t> *result_out,
375 bool all_required=false, content_t c_fallback=CONTENT_IGNORE);
377 void nodeResolveInternal();
380 u32 m_nnlistsizes_idx;
381 std::vector<std::string> m_nodenames;
382 std::vector<size_t> m_nnlistsizes;
383 INodeDefManager *m_ndef;