]> git.lizzy.rs Git - minetest.git/blob - src/nodedef.h
Add firelike drawtype
[minetest.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 "mapnode.h"
29 #ifndef SERVER
30 #include "tile.h"
31 #include "shader.h"
32 #endif
33 #include "itemgroup.h"
34 #include "sound.h" // SimpleSoundSpec
35 #include "constants.h" // BS
36
37 class IItemDefManager;
38 class ITextureSource;
39 class IShaderSource;
40 class IGameDef;
41
42 typedef std::list<std::pair<content_t, int> > GroupItems;
43
44 enum ContentParamType
45 {
46         CPT_NONE,
47         CPT_LIGHT,
48 };
49
50 enum ContentParamType2
51 {
52         CPT2_NONE,
53         // Need 8-bit param2
54         CPT2_FULL,
55         // Flowing liquid properties
56         CPT2_FLOWINGLIQUID,
57         // Direction for chests and furnaces and such
58         CPT2_FACEDIR,
59         // Direction for signs, torches and such
60         CPT2_WALLMOUNTED,
61         // Block level like FLOWINGLIQUID
62         CPT2_LEVELED,
63 };
64
65 enum LiquidType
66 {
67         LIQUID_NONE,
68         LIQUID_FLOWING,
69         LIQUID_SOURCE,
70 };
71
72 enum NodeBoxType
73 {
74         NODEBOX_REGULAR, // Regular block; allows buildable_to
75         NODEBOX_FIXED, // Static separately defined box(es)
76         NODEBOX_WALLMOUNTED, // Box for wall mounted nodes; (top, bottom, side)
77         NODEBOX_LEVELED, // Same as fixed, but with dynamic height from param2. for snow, ...
78 };
79
80 struct NodeBox
81 {
82         enum NodeBoxType type;
83         // NODEBOX_REGULAR (no parameters)
84         // NODEBOX_FIXED
85         std::vector<aabb3f> fixed;
86         // NODEBOX_WALLMOUNTED
87         aabb3f wall_top;
88         aabb3f wall_bottom;
89         aabb3f wall_side; // being at the -X side
90
91         NodeBox()
92         { reset(); }
93
94         void reset();
95         void serialize(std::ostream &os, u16 protocol_version) const;
96         void deSerialize(std::istream &is);
97 };
98
99 struct MapNode;
100 class NodeMetadata;
101
102 /*
103         Stand-alone definition of a TileSpec (basically a server-side TileSpec)
104 */
105 enum TileAnimationType{
106         TAT_NONE=0,
107         TAT_VERTICAL_FRAMES=1,
108 };
109 struct TileDef
110 {
111         std::string name;
112         bool backface_culling; // Takes effect only in special cases
113         struct{
114                 enum TileAnimationType type;
115                 int aspect_w; // width for aspect ratio
116                 int aspect_h; // height for aspect ratio
117                 float length; // seconds
118         } animation;
119
120         TileDef()
121         {
122                 name = "";
123                 backface_culling = true;
124                 animation.type = TAT_NONE;
125                 animation.aspect_w = 1;
126                 animation.aspect_h = 1;
127                 animation.length = 1.0;
128         }
129
130         void serialize(std::ostream &os, u16 protocol_version) const;
131         void deSerialize(std::istream &is);
132 };
133
134 enum NodeDrawType
135 {
136         NDT_NORMAL, // A basic solid block
137         NDT_AIRLIKE, // Nothing is drawn
138         NDT_LIQUID, // Do not draw face towards same kind of flowing/source liquid
139         NDT_FLOWINGLIQUID, // A very special kind of thing
140         NDT_GLASSLIKE, // Glass-like, don't draw faces towards other glass
141         NDT_ALLFACES, // Leaves-like, draw all faces no matter what
142         NDT_ALLFACES_OPTIONAL, // Fancy -> allfaces, fast -> normal
143         NDT_TORCHLIKE,
144         NDT_SIGNLIKE,
145         NDT_PLANTLIKE,
146         NDT_FENCELIKE,
147         NDT_RAILLIKE,
148         NDT_NODEBOX,
149         NDT_GLASSLIKE_FRAMED, // Glass-like, draw connected frames and all all
150                               // visible faces
151                                                   // uses 2 textures, one for frames, second for faces
152         NDT_FIRELIKE, // Draw faces slightly rotated and only on connecting nodes
153 };
154
155 #define CF_SPECIAL_COUNT 6
156
157 struct ContentFeatures
158 {
159         /*
160                 Cached stuff
161         */
162 #ifndef SERVER
163         // 0     1     2     3     4     5
164         // up    down  right left  back  front 
165         TileSpec tiles[6];
166         // Special tiles
167         // - Currently used for flowing liquids
168         TileSpec special_tiles[CF_SPECIAL_COUNT];
169         u8 solidness; // Used when choosing which face is drawn
170         u8 visual_solidness; // When solidness=0, this tells how it looks like
171         bool backface_culling;
172 #endif
173
174         // Server-side cached callback existence for fast skipping
175         bool has_on_construct;
176         bool has_on_destruct;
177         bool has_after_destruct;
178
179         /*
180                 Actual data
181         */
182
183         std::string name; // "" = undefined node
184         ItemGroupList groups; // Same as in itemdef
185
186         // Visual definition
187         enum NodeDrawType drawtype;
188         float visual_scale; // Misc. scale parameter
189         TileDef tiledef[6];
190         TileDef tiledef_special[CF_SPECIAL_COUNT]; // eg. flowing liquid
191         u8 alpha;
192
193         // Post effect color, drawn when the camera is inside the node.
194         video::SColor post_effect_color;
195         // Type of MapNode::param1
196         ContentParamType param_type;
197         // Type of MapNode::param2
198         ContentParamType2 param_type_2;
199         // True for all ground-like things like stone and mud, false for eg. trees
200         bool is_ground_content;
201         bool light_propagates;
202         bool sunlight_propagates;
203         // This is used for collision detection.
204         // Also for general solidness queries.
205         bool walkable;
206         // Player can point to these
207         bool pointable;
208         // Player can dig these
209         bool diggable;
210         // Player can climb these
211         bool climbable;
212         // Player can build on these
213         bool buildable_to;
214         // Player cannot build to these (placement prediction disabled)
215         bool rightclickable;
216         // Flowing liquid or snow, value = default level
217         u8 leveled;
218         // Whether the node is non-liquid, source liquid or flowing liquid
219         enum LiquidType liquid_type;
220         // If the content is liquid, this is the flowing version of the liquid.
221         std::string liquid_alternative_flowing;
222         // If the content is liquid, this is the source version of the liquid.
223         std::string liquid_alternative_source;
224         // Viscosity for fluid flow, ranging from 1 to 7, with
225         // 1 giving almost instantaneous propagation and 7 being
226         // the slowest possible
227         u8 liquid_viscosity;
228         // Is liquid renewable (new liquid source will be created between 2 existing)
229         bool liquid_renewable;
230         // Ice for water, water for ice
231         std::string freezemelt;
232         // Number of flowing liquids surrounding source
233         u8 liquid_range;
234         u8 drowning;
235         // Amount of light the node emits
236         u8 light_source;
237         u32 damage_per_second;
238         NodeBox node_box;
239         NodeBox selection_box;
240         // Used for waving leaves/plants
241         u8 waving;
242         // Compatibility with old maps
243         // Set to true if paramtype used to be 'facedir_simple'
244         bool legacy_facedir_simple;
245         // Set to true if wall_mounted used to be set to true
246         bool legacy_wallmounted;
247
248         // Sound properties
249         SimpleSoundSpec sound_footstep;
250         SimpleSoundSpec sound_dig;
251         SimpleSoundSpec sound_dug;
252
253         /*
254                 Methods
255         */
256         
257         ContentFeatures();
258         ~ContentFeatures();
259         void reset();
260         void serialize(std::ostream &os, u16 protocol_version);
261         void deSerialize(std::istream &is);
262         void serializeOld(std::ostream &os, u16 protocol_version);
263         void deSerializeOld(std::istream &is, int version);
264
265         /*
266                 Some handy methods
267         */
268         bool isLiquid() const{
269                 return (liquid_type != LIQUID_NONE);
270         }
271         bool sameLiquid(const ContentFeatures &f) const{
272                 if(!isLiquid() || !f.isLiquid()) return false;
273                 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
274         }
275 };
276
277 class INodeDefManager
278 {
279 public:
280         INodeDefManager(){}
281         virtual ~INodeDefManager(){}
282         // Get node definition
283         virtual const ContentFeatures& get(content_t c) const=0;
284         virtual const ContentFeatures& get(const MapNode &n) const=0;
285         virtual bool getId(const std::string &name, content_t &result) const=0;
286         virtual content_t getId(const std::string &name) const=0;
287         // Allows "group:name" in addition to regular node names
288         virtual void getIds(const std::string &name, std::set<content_t> &result)
289                         const=0;
290         virtual const ContentFeatures& get(const std::string &name) const=0;
291         
292         virtual void serialize(std::ostream &os, u16 protocol_version)=0;
293 };
294
295 class IWritableNodeDefManager : public INodeDefManager
296 {
297 public:
298         IWritableNodeDefManager(){}
299         virtual ~IWritableNodeDefManager(){}
300         virtual IWritableNodeDefManager* clone()=0;
301         // Get node definition
302         virtual const ContentFeatures& get(content_t c) const=0;
303         virtual const ContentFeatures& get(const MapNode &n) const=0;
304         virtual bool getId(const std::string &name, content_t &result) const=0;
305         // If not found, returns CONTENT_IGNORE
306         virtual content_t getId(const std::string &name) const=0;
307         // Allows "group:name" in addition to regular node names
308         virtual void getIds(const std::string &name, std::set<content_t> &result)
309                         const=0;
310         // If not found, returns the features of CONTENT_UNKNOWN
311         virtual const ContentFeatures& get(const std::string &name) const=0;
312
313         // Register node definition by name (allocate an id)
314         // If returns CONTENT_IGNORE, could not allocate id
315         virtual content_t set(const std::string &name,
316                         const ContentFeatures &def)=0;
317         // If returns CONTENT_IGNORE, could not allocate id
318         virtual content_t allocateDummy(const std::string &name)=0;
319
320         /*
321                 Update item alias mapping.
322                 Call after updating item definitions.
323         */
324         virtual void updateAliases(IItemDefManager *idef)=0;
325
326         /*
327                 Update tile textures to latest return values of TextueSource.
328         */
329         virtual void updateTextures(ITextureSource *tsrc,
330                 IShaderSource *shdsrc)=0;
331
332         virtual void serialize(std::ostream &os, u16 protocol_version)=0;
333         virtual void deSerialize(std::istream &is)=0;
334 };
335
336 IWritableNodeDefManager* createNodeDefManager();
337
338 #endif
339