]> git.lizzy.rs Git - dragonfireclient.git/blob - src/nodedef.h
e70295616647abb93aa63250a0faee409406d3fb
[dragonfireclient.git] / src / nodedef.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010-2011 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 General Public License as published by
7 the Free Software Foundation; either version 2 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 General Public License for more details.
14
15 You should have received a copy of the GNU 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 "common_irrlicht.h"
24 #include <string>
25 #include <set>
26 #include "mapnode.h"
27 #ifndef SERVER
28 #include "tile.h"
29 #endif
30 #include "materials.h" // MaterialProperties
31 class ITextureSource;
32
33 /*
34         TODO: Rename to nodedef.h
35 */
36
37 #if 0
38
39 /*
40         Content feature list
41         
42         Used for determining properties of MapNodes by content type without
43         storing such properties in the nodes itself.
44 */
45
46 /*
47         Initialize content feature table.
48
49         Must be called before accessing the table.
50 */
51 void init_contentfeatures(ITextureSource *tsrc);
52
53 #endif
54
55 enum ContentParamType
56 {
57         CPT_NONE,
58         CPT_LIGHT,
59         CPT_MINERAL,
60         // Direction for chests and furnaces and such
61         CPT_FACEDIR_SIMPLE
62 };
63
64 enum LiquidType
65 {
66         LIQUID_NONE,
67         LIQUID_FLOWING,
68         LIQUID_SOURCE
69 };
70
71 enum NodeBoxType
72 {
73         NODEBOX_REGULAR, // Regular block; allows buildable_to
74         NODEBOX_FIXED, // Static separately defined box
75         NODEBOX_WALLMOUNTED, // Box for wall_mounted nodes; (top, bottom, side)
76 };
77
78 struct NodeBox
79 {
80         enum NodeBoxType type;
81         // NODEBOX_REGULAR (no parameters)
82         // NODEBOX_FIXED
83         core::aabbox3d<f32> fixed;
84         // NODEBOX_WALLMOUNTED
85         core::aabbox3d<f32> wall_top;
86         core::aabbox3d<f32> wall_bottom;
87         core::aabbox3d<f32> wall_side; // being at the -X side
88
89         NodeBox():
90                 type(NODEBOX_REGULAR),
91                 // default is rail-like
92                 fixed(-BS/2, -BS/2, -BS/2, BS/2, -BS/2+BS/16., BS/2),
93                 // default is sign/ladder-like
94                 wall_top(-BS/2, BS/2-BS/16., -BS/2, BS/2, BS/2, BS/2),
95                 wall_bottom(-BS/2, -BS/2, -BS/2, BS/2, -BS/2+BS/16., BS/2),
96                 wall_side(-BS/2, -BS/2, -BS/2, -BS/2+BS/16., BS/2, BS/2)
97         {}
98 };
99
100 struct MapNode;
101 class NodeMetadata;
102
103 struct MaterialSpec
104 {
105         std::string tname;
106         bool backface_culling;
107         
108         MaterialSpec(const std::string &tname_="", bool backface_culling_=true):
109                 tname(tname_),
110                 backface_culling(backface_culling_)
111         {}
112 };
113
114 #define CF_SPECIAL_COUNT 2
115
116 struct ContentFeatures
117 {
118 #ifndef SERVER
119         // 0     1     2     3     4     5
120         // up    down  right left  back  front 
121         TileSpec tiles[6];
122         
123         video::ITexture *inventory_texture;
124
125         // Post effect color, drawn when the camera is inside the node.
126         video::SColor post_effect_color;
127
128         // Special material/texture
129         // - Currently used for flowing liquids
130         video::SMaterial *special_materials[CF_SPECIAL_COUNT];
131         AtlasPointer *special_aps[CF_SPECIAL_COUNT];
132 #endif
133         
134         // Visual definition
135         std::string tname_tiles[6];
136         std::string tname_inventory;
137         MaterialSpec mspec_special[CF_SPECIAL_COUNT];
138         u8 alpha;
139         bool backface_culling;
140         u8 solidness; // Used when choosing which face is drawn
141         u8 visual_solidness; // When solidness=0, this tells how it looks like
142
143         // List of all block textures that have been used (value is dummy)
144         // Used for texture atlas making.
145         // Exists on server too for cleaner code in content_mapnode.cpp.
146         std::set<std::string> used_texturenames;
147         
148         // Type of MapNode::param1
149         ContentParamType param_type;
150         // True for all ground-like things like stone and mud, false for eg. trees
151         bool is_ground_content;
152         bool light_propagates;
153         bool sunlight_propagates;
154         // This is used for collision detection.
155         // Also for general solidness queries.
156         bool walkable;
157         // Player can point to these
158         bool pointable;
159         // Player can dig these
160         bool diggable;
161         // Player can climb these
162         bool climbable;
163         // Player can build on these
164         bool buildable_to;
165         // If true, param2 is set to direction when placed. Used for torches.
166         // NOTE: the direction format is quite inefficient and should be changed
167         bool wall_mounted;
168         // If true, node is equivalent to air. Torches are, air is. Water is not.
169         // Is used for example to check whether a mud block can have grass on.
170         bool air_equivalent;
171         // Whether this content type often contains mineral.
172         // Used for texture atlas creation.
173         // Currently only enabled for CONTENT_STONE.
174         bool often_contains_mineral;
175         
176         // Inventory item string as which the node appears in inventory when dug.
177         // Mineral overrides this.
178         std::string dug_item;
179
180         // Extra dug item and its rarity
181         std::string extra_dug_item;
182         s32 extra_dug_item_rarity;
183
184         // Initial metadata is cloned from this
185         NodeMetadata *initial_metadata;
186         
187         // Whether the node is non-liquid, source liquid or flowing liquid
188         enum LiquidType liquid_type;
189         // If the content is liquid, this is the flowing version of the liquid.
190         content_t liquid_alternative_flowing;
191         // If the content is liquid, this is the source version of the liquid.
192         content_t liquid_alternative_source;
193         // Viscosity for fluid flow, ranging from 1 to 7, with
194         // 1 giving almost instantaneous propagation and 7 being
195         // the slowest possible
196         u8 liquid_viscosity;
197         
198         // Amount of light the node emits
199         u8 light_source;
200         
201         u32 damage_per_second;
202
203         NodeBox selection_box;
204
205         MaterialProperties material;
206         
207         // NOTE: Move relevant properties to here from elsewhere
208
209         void reset()
210         {
211                 // This isn't exactly complete due to lazyness
212                 // TODO: Make it completely reset everything
213 #ifndef SERVER
214                 inventory_texture = NULL;
215                 
216                 post_effect_color = video::SColor(0, 0, 0, 0);
217                 for(u16 j=0; j<CF_SPECIAL_COUNT; j++){
218                         special_materials[j] = NULL;
219                         special_aps[j] = NULL;
220                 }
221 #endif
222                 for(u32 i=0; i<6; i++)
223                         tname_tiles[i] = "";
224                 for(u16 j=0; j<CF_SPECIAL_COUNT; j++)
225                         mspec_special[j] = MaterialSpec();
226                 tname_inventory = "";
227                 alpha = 255;
228                 backface_culling = true;
229                 solidness = 2;
230                 visual_solidness = 0;
231                 used_texturenames.clear();
232                 param_type = CPT_NONE;
233                 is_ground_content = false;
234                 light_propagates = false;
235                 sunlight_propagates = false;
236                 walkable = true;
237                 pointable = true;
238                 diggable = true;
239                 climbable = false;
240                 buildable_to = false;
241                 wall_mounted = false;
242                 air_equivalent = false;
243                 often_contains_mineral = false;
244                 dug_item = "";
245                 initial_metadata = NULL;
246                 liquid_type = LIQUID_NONE;
247                 liquid_alternative_flowing = CONTENT_IGNORE;
248                 liquid_alternative_source = CONTENT_IGNORE;
249                 liquid_viscosity = 0;
250                 light_source = 0;
251                 damage_per_second = 0;
252                 selection_box = NodeBox();
253                 material = MaterialProperties();
254         }
255
256         ContentFeatures()
257         {
258                 reset();
259         }
260
261         ~ContentFeatures();
262         
263         /*
264                 Quickhands for simple materials
265         */
266         
267         void setTexture(u16 i, std::string name);
268
269         void setAllTextures(std::string name, u8 alpha=255)
270         {
271                 for(u16 i=0; i<6; i++)
272                         setTexture(i, name);
273                 alpha = alpha;
274                 // Force inventory texture too
275                 setInventoryTexture(name);
276         }
277
278         void setInventoryTexture(std::string imgname);
279         void setInventoryTextureCube(std::string top,
280                         std::string left, std::string right);
281
282         /*
283                 Some handy methods
284         */
285         bool isLiquid() const{
286                 return (liquid_type != LIQUID_NONE);
287         }
288         bool sameLiquid(const ContentFeatures &f) const{
289                 if(!isLiquid() || !f.isLiquid()) return false;
290                 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
291         }
292 };
293
294 class INodeDefManager
295 {
296 public:
297         INodeDefManager(){}
298         virtual ~INodeDefManager(){}
299         // Get node definition
300         virtual const ContentFeatures& get(content_t c) const=0;
301         virtual const ContentFeatures& get(const MapNode &n) const=0;
302 };
303
304 class IWritableNodeDefManager : public INodeDefManager
305 {
306 public:
307         IWritableNodeDefManager(){}
308         virtual ~IWritableNodeDefManager(){}
309         virtual IWritableNodeDefManager* clone()=0;
310         // Get node definition
311         virtual const ContentFeatures& get(content_t c) const=0;
312         virtual const ContentFeatures& get(const MapNode &n) const=0;
313                 
314         // Register node definition
315         virtual void set(content_t c, const ContentFeatures &def)=0;
316         virtual ContentFeatures* getModifiable(content_t c)=0;
317
318         /*
319                 Update tile textures to latest return values of TextueSource.
320                 Call after updating the texture atlas of a TextureSource.
321         */
322         virtual void updateTextures(ITextureSource *tsrc)=0;
323 };
324
325 IWritableNodeDefManager* createNodeDefManager();
326
327 #endif
328