]> git.lizzy.rs Git - dragonfireclient.git/blob - src/nodedef.h
Handle particle spawners in env and delete expired ids
[dragonfireclient.git] / src / nodedef.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
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.
9
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.
14
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.
18 */
19
20 #ifndef NODEDEF_HEADER
21 #define NODEDEF_HEADER
22
23 #include "irrlichttypes_bloated.h"
24 #include <string>
25 #include <iostream>
26 #include <map>
27 #include <list>
28 #include "util/numeric.h"
29 #include "mapnode.h"
30 #ifndef SERVER
31 #include "client/tile.h"
32 #include "shader.h"
33 #endif
34 #include "itemgroup.h"
35 #include "sound.h" // SimpleSoundSpec
36 #include "constants.h" // BS
37
38 class INodeDefManager;
39 class IItemDefManager;
40 class ITextureSource;
41 class IShaderSource;
42 class IGameDef;
43 class NodeResolver;
44
45 typedef std::list<std::pair<content_t, int> > GroupItems;
46
47 enum ContentParamType
48 {
49         CPT_NONE,
50         CPT_LIGHT,
51 };
52
53 enum ContentParamType2
54 {
55         CPT2_NONE,
56         // Need 8-bit param2
57         CPT2_FULL,
58         // Flowing liquid properties
59         CPT2_FLOWINGLIQUID,
60         // Direction for chests and furnaces and such
61         CPT2_FACEDIR,
62         // Direction for signs, torches and such
63         CPT2_WALLMOUNTED,
64         // Block level like FLOWINGLIQUID
65         CPT2_LEVELED,
66         // 2D rotation for things like plants
67         CPT2_DEGROTATE,
68 };
69
70 enum LiquidType
71 {
72         LIQUID_NONE,
73         LIQUID_FLOWING,
74         LIQUID_SOURCE,
75 };
76
77 enum NodeBoxType
78 {
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
84 };
85
86 struct NodeBox
87 {
88         enum NodeBoxType type;
89         // NODEBOX_REGULAR (no parameters)
90         // NODEBOX_FIXED
91         std::vector<aabb3f> fixed;
92         // NODEBOX_WALLMOUNTED
93         aabb3f wall_top;
94         aabb3f wall_bottom;
95         aabb3f wall_side; // being at the -X side
96         // NODEBOX_CONNECTED
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;
103
104         NodeBox()
105         { reset(); }
106
107         void reset();
108         void serialize(std::ostream &os, u16 protocol_version) const;
109         void deSerialize(std::istream &is);
110 };
111
112 struct MapNode;
113 class NodeMetadata;
114
115 enum NodeDrawType
116 {
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
124         NDT_TORCHLIKE,
125         NDT_SIGNLIKE,
126         NDT_PLANTLIKE,
127         NDT_FENCELIKE,
128         NDT_RAILLIKE,
129         NDT_NODEBOX,
130         NDT_GLASSLIKE_FRAMED, // Glass-like, draw connected frames and all all
131                               // visible faces
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
137 };
138
139 /*
140         Stand-alone definition of a TileSpec (basically a server-side TileSpec)
141 */
142 enum TileAnimationType{
143         TAT_NONE=0,
144         TAT_VERTICAL_FRAMES=1,
145 };
146 struct TileDef
147 {
148         std::string name;
149         bool backface_culling; // Takes effect only in special cases
150         bool tileable_horizontal;
151         bool tileable_vertical;
152         struct{
153                 enum TileAnimationType type;
154                 int aspect_w; // width for aspect ratio
155                 int aspect_h; // height for aspect ratio
156                 float length; // seconds
157         } animation;
158
159         TileDef()
160         {
161                 name = "";
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;
169         }
170
171         void serialize(std::ostream &os, u16 protocol_version) const;
172         void deSerialize(std::istream &is, const u8 contentfeatures_version, const NodeDrawType drawtype);
173 };
174
175 #define CF_SPECIAL_COUNT 6
176
177 struct ContentFeatures
178 {
179         /*
180                 Cached stuff
181         */
182 #ifndef SERVER
183         // 0     1     2     3     4     5
184         // up    down  right left  back  front
185         TileSpec tiles[6];
186         // Special tiles
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;
192 #endif
193
194         // Server-side cached callback existence for fast skipping
195         bool has_on_construct;
196         bool has_on_destruct;
197         bool has_after_destruct;
198
199         /*
200                 Actual data
201         */
202
203         std::string name; // "" = undefined node
204         ItemGroupList groups; // Same as in itemdef
205
206         // Visual definition
207         enum NodeDrawType drawtype;
208         std::string mesh;
209 #ifndef SERVER
210         scene::IMesh *mesh_ptr[24];
211         video::SColor minimap_color;
212 #endif
213         float visual_scale; // Misc. scale parameter
214         TileDef tiledef[6];
215         TileDef tiledef_special[CF_SPECIAL_COUNT]; // eg. flowing liquid
216         u8 alpha;
217
218         // Post effect color, drawn when the camera is inside the node.
219         video::SColor post_effect_color;
220
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.
231         bool walkable;
232         // Player can point to these
233         bool pointable;
234         // Player can dig these
235         bool diggable;
236         // Player can climb these
237         bool climbable;
238         // Player can build on these
239         bool buildable_to;
240         // Liquids flow into and replace node
241         bool floodable;
242         // Player cannot build to these (placement prediction disabled)
243         bool rightclickable;
244         // Flowing liquid or snow, value = default level
245         u8 leveled;
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
255         u8 liquid_viscosity;
256         // Is liquid renewable (new liquid source will be created between 2 existing)
257         bool liquid_renewable;
258         // Number of flowing liquids surrounding source
259         u8 liquid_range;
260         u8 drowning;
261         // Amount of light the node emits
262         u8 light_source;
263         u32 damage_per_second;
264         NodeBox node_box;
265         NodeBox selection_box;
266         NodeBox collision_box;
267         // Used for waving leaves/plants
268         u8 waving;
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
275         u8 connect_sides;
276
277         // Sound properties
278         SimpleSoundSpec sound_footstep;
279         SimpleSoundSpec sound_dig;
280         SimpleSoundSpec sound_dug;
281
282         std::vector<std::string> connects_to;
283         std::set<content_t> connects_to_ids;
284
285         /*
286                 Methods
287         */
288
289         ContentFeatures();
290         ~ContentFeatures();
291         void reset();
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);
296
297         /*
298                 Some handy methods
299         */
300         bool isLiquid() const{
301                 return (liquid_type != LIQUID_NONE);
302         }
303         bool sameLiquid(const ContentFeatures &f) const{
304                 if(!isLiquid() || !f.isLiquid()) return false;
305                 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
306         }
307 };
308
309 class INodeDefManager {
310 public:
311         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)
321                         const=0;
322         virtual const ContentFeatures &get(const std::string &name) const=0;
323
324         virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
325
326         virtual bool getNodeRegistrationStatus() const=0;
327
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;
331 };
332
333 class IWritableNodeDefManager : public INodeDefManager {
334 public:
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)
346                 const=0;
347         // If not found, returns the features of CONTENT_UNKNOWN
348         virtual const ContentFeatures &get(const std::string &name) const=0;
349
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;
356
357         /*
358                 Update item alias mapping.
359                 Call after updating item definitions.
360         */
361         virtual void updateAliases(IItemDefManager *idef)=0;
362
363         /*
364                 Override textures from servers with ones specified in texturepack/override.txt
365         */
366         virtual void applyTextureOverrides(const std::string &override_filepath)=0;
367
368         /*
369                 Update tile textures to latest return values of TextueSource.
370         */
371         virtual void updateTextures(IGameDef *gamedef,
372                 void (*progress_cbk)(void *progress_args, u32 progress, u32 max_progress),
373                 void *progress_cbk_args)=0;
374
375         virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
376         virtual void deSerialize(std::istream &is)=0;
377
378         virtual bool getNodeRegistrationStatus() const=0;
379         virtual void setNodeRegistrationStatus(bool completed)=0;
380
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;
386 };
387
388 IWritableNodeDefManager *createNodeDefManager();
389
390 class NodeResolver {
391 public:
392         NodeResolver();
393         virtual ~NodeResolver();
394         virtual void resolveNodeNames() = 0;
395
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);
400
401         void nodeResolveInternal();
402
403         u32 m_nodenames_idx;
404         u32 m_nnlistsizes_idx;
405         std::vector<std::string> m_nodenames;
406         std::vector<size_t> m_nnlistsizes;
407         INodeDefManager *m_ndef;
408         bool m_resolve_done;
409 };
410
411 #endif