]> git.lizzy.rs Git - dragonfireclient.git/blob - src/nodedef.h
Remove old comments
[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 <iostream>
26 #include <set>
27 #include "mapnode.h"
28 #ifndef SERVER
29 #include "tile.h"
30 #endif
31 #include "materials.h" // MaterialProperties
32 class ITextureSource;
33 class IGameDef;
34
35 enum ContentParamType
36 {
37         CPT_NONE,
38         CPT_LIGHT,
39         CPT_MINERAL,
40         // Direction for chests and furnaces and such
41         CPT_FACEDIR_SIMPLE
42 };
43
44 enum LiquidType
45 {
46         LIQUID_NONE,
47         LIQUID_FLOWING,
48         LIQUID_SOURCE
49 };
50
51 enum NodeBoxType
52 {
53         NODEBOX_REGULAR, // Regular block; allows buildable_to
54         NODEBOX_FIXED, // Static separately defined box
55         NODEBOX_WALLMOUNTED, // Box for wall_mounted nodes; (top, bottom, side)
56 };
57
58 struct NodeBox
59 {
60         enum NodeBoxType type;
61         // NODEBOX_REGULAR (no parameters)
62         // NODEBOX_FIXED
63         core::aabbox3d<f32> fixed;
64         // NODEBOX_WALLMOUNTED
65         core::aabbox3d<f32> wall_top;
66         core::aabbox3d<f32> wall_bottom;
67         core::aabbox3d<f32> wall_side; // being at the -X side
68
69         NodeBox():
70                 type(NODEBOX_REGULAR),
71                 // default is rail-like
72                 fixed(-BS/2, -BS/2, -BS/2, BS/2, -BS/2+BS/16., BS/2),
73                 // default is sign/ladder-like
74                 wall_top(-BS/2, BS/2-BS/16., -BS/2, BS/2, BS/2, BS/2),
75                 wall_bottom(-BS/2, -BS/2, -BS/2, BS/2, -BS/2+BS/16., BS/2),
76                 wall_side(-BS/2, -BS/2, -BS/2, -BS/2+BS/16., BS/2, BS/2)
77         {}
78
79         void serialize(std::ostream &os) const;
80         void deSerialize(std::istream &is);
81 };
82
83 struct MapNode;
84 class NodeMetadata;
85
86 struct MaterialSpec
87 {
88         std::string tname;
89         bool backface_culling;
90         
91         MaterialSpec(const std::string &tname_="", bool backface_culling_=true):
92                 tname(tname_),
93                 backface_culling(backface_culling_)
94         {}
95
96         void serialize(std::ostream &os) const;
97         void deSerialize(std::istream &is);
98 };
99
100 enum NodeDrawType
101 {
102         NDT_NORMAL, // A basic solid block
103         NDT_AIRLIKE, // Nothing is drawn
104         NDT_LIQUID, // Do not draw face towards same kind of flowing/source liquid
105         NDT_FLOWINGLIQUID, // A very special kind of thing
106         NDT_GLASSLIKE, // Glass-like, don't draw faces towards other glass
107         NDT_ALLFACES, // Leaves-like, draw all faces no matter what
108         NDT_ALLFACES_OPTIONAL, // Fancy -> allfaces, fast -> normal
109         NDT_TORCHLIKE,
110         NDT_SIGNLIKE,
111         NDT_PLANTLIKE,
112         NDT_FENCELIKE,
113         NDT_RAILLIKE,
114 };
115
116 #define CF_SPECIAL_COUNT 2
117
118 struct ContentFeatures
119 {
120         /*
121                 Cached stuff
122         */
123 #ifndef SERVER
124         // 0     1     2     3     4     5
125         // up    down  right left  back  front 
126         TileSpec tiles[6];
127         video::ITexture *inventory_texture;
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         u8 solidness; // Used when choosing which face is drawn
133         u8 visual_solidness; // When solidness=0, this tells how it looks like
134         bool backface_culling;
135 #endif
136         
137         // List of textures that are used and are wanted to be included in
138         // the texture atlas
139         std::set<std::string> used_texturenames;
140         
141         // True if this actually contains non-default data
142         bool modified;
143
144         /*
145                 Actual data
146         */
147
148         // Visual definition
149         enum NodeDrawType drawtype;
150         float visual_scale; // Misc. scale parameter
151         std::string tname_tiles[6];
152         std::string tname_inventory;
153         MaterialSpec mspec_special[CF_SPECIAL_COUNT]; // Use setter methods
154         u8 alpha;
155
156         // Post effect color, drawn when the camera is inside the node.
157         video::SColor post_effect_color;
158         // Type of MapNode::param1
159         ContentParamType param_type;
160         // True for all ground-like things like stone and mud, false for eg. trees
161         bool is_ground_content;
162         bool light_propagates;
163         bool sunlight_propagates;
164         // This is used for collision detection.
165         // Also for general solidness queries.
166         bool walkable;
167         // Player can point to these
168         bool pointable;
169         // Player can dig these
170         bool diggable;
171         // Player can climb these
172         bool climbable;
173         // Player can build on these
174         bool buildable_to;
175         // If true, param2 is set to direction when placed. Used for torches.
176         // NOTE: the direction format is quite inefficient and should be changed
177         bool wall_mounted;
178         // If true, node is equivalent to air. Torches are, air is. Water is not.
179         // Is used for example to check whether a mud block can have grass on.
180         bool air_equivalent;
181         // Whether this content type often contains mineral.
182         // Used for texture atlas creation.
183         // Currently only enabled for CONTENT_STONE.
184         bool often_contains_mineral;
185         // Inventory item string as which the node appears in inventory when dug.
186         // Mineral overrides this.
187         std::string dug_item;
188         // Extra dug item and its rarity
189         std::string extra_dug_item;
190         // Usual get interval for extra dug item
191         s32 extra_dug_item_rarity;
192         // Initial metadata is cloned from this
193         NodeMetadata *initial_metadata;
194         // Whether the node is non-liquid, source liquid or flowing liquid
195         enum LiquidType liquid_type;
196         // If the content is liquid, this is the flowing version of the liquid.
197         content_t liquid_alternative_flowing;
198         // If the content is liquid, this is the source version of the liquid.
199         content_t liquid_alternative_source;
200         // Viscosity for fluid flow, ranging from 1 to 7, with
201         // 1 giving almost instantaneous propagation and 7 being
202         // the slowest possible
203         u8 liquid_viscosity;
204         // Amount of light the node emits
205         u8 light_source;
206         u32 damage_per_second;
207         NodeBox selection_box;
208         MaterialProperties material;
209         std::string cookresult_item;
210
211         /*
212                 Methods
213         */
214         
215         ContentFeatures();
216         ~ContentFeatures();
217         void reset();
218         void serialize(std::ostream &os);
219         void deSerialize(std::istream &is, IGameDef *gamedef);
220
221         /*
222                 Texture setters.
223                 
224         */
225         
226         // Texture setters. They also add stuff to used_texturenames.
227         void setTexture(u16 i, std::string name);
228         void setAllTextures(std::string name);
229         void setSpecialMaterial(u16 i, const MaterialSpec &mspec);
230
231         void setInventoryTexture(std::string imgname);
232         void setInventoryTextureCube(std::string top,
233                         std::string left, std::string right);
234         
235         /*
236                 Some handy methods
237         */
238         bool isLiquid() const{
239                 return (liquid_type != LIQUID_NONE);
240         }
241         bool sameLiquid(const ContentFeatures &f) const{
242                 if(!isLiquid() || !f.isLiquid()) return false;
243                 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
244         }
245 };
246
247 class INodeDefManager
248 {
249 public:
250         INodeDefManager(){}
251         virtual ~INodeDefManager(){}
252         // Get node definition
253         virtual const ContentFeatures& get(content_t c) const=0;
254         virtual const ContentFeatures& get(const MapNode &n) const=0;
255         
256         virtual void serialize(std::ostream &os)=0;
257 };
258
259 class IWritableNodeDefManager : public INodeDefManager
260 {
261 public:
262         IWritableNodeDefManager(){}
263         virtual ~IWritableNodeDefManager(){}
264         virtual IWritableNodeDefManager* clone()=0;
265         // Get node definition
266         virtual const ContentFeatures& get(content_t c) const=0;
267         virtual const ContentFeatures& get(const MapNode &n) const=0;
268                 
269         // Register node definition
270         virtual void set(content_t c, const ContentFeatures &def)=0;
271         virtual ContentFeatures* getModifiable(content_t c)=0;
272
273         /*
274                 Update tile textures to latest return values of TextueSource.
275                 Call after updating the texture atlas of a TextureSource.
276         */
277         virtual void updateTextures(ITextureSource *tsrc)=0;
278
279         virtual void serialize(std::ostream &os)=0;
280         virtual void deSerialize(std::istream &is, IGameDef *gamedef)=0;
281 };
282
283 IWritableNodeDefManager* createNodeDefManager();
284
285 #endif
286