]> git.lizzy.rs Git - dragonfireclient.git/blob - src/nodedef.h
Translated using Weblate (Korean)
[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 };
67
68 enum LiquidType
69 {
70         LIQUID_NONE,
71         LIQUID_FLOWING,
72         LIQUID_SOURCE,
73 };
74
75 enum NodeBoxType
76 {
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, ...
81 };
82
83 struct NodeBox
84 {
85         enum NodeBoxType type;
86         // NODEBOX_REGULAR (no parameters)
87         // NODEBOX_FIXED
88         std::vector<aabb3f> fixed;
89         // NODEBOX_WALLMOUNTED
90         aabb3f wall_top;
91         aabb3f wall_bottom;
92         aabb3f wall_side; // being at the -X side
93
94         NodeBox()
95         { reset(); }
96
97         void reset();
98         void serialize(std::ostream &os, u16 protocol_version) const;
99         void deSerialize(std::istream &is);
100 };
101
102 struct MapNode;
103 class NodeMetadata;
104
105 /*
106         Stand-alone definition of a TileSpec (basically a server-side TileSpec)
107 */
108 enum TileAnimationType{
109         TAT_NONE=0,
110         TAT_VERTICAL_FRAMES=1,
111 };
112 struct TileDef
113 {
114         std::string name;
115         bool backface_culling; // Takes effect only in special cases
116         bool tileable_horizontal;
117         bool tileable_vertical;
118         struct{
119                 enum TileAnimationType type;
120                 int aspect_w; // width for aspect ratio
121                 int aspect_h; // height for aspect ratio
122                 float length; // seconds
123         } animation;
124
125         TileDef()
126         {
127                 name = "";
128                 backface_culling = true;
129                 tileable_horizontal = true;
130                 tileable_vertical = true;
131                 animation.type = TAT_NONE;
132                 animation.aspect_w = 1;
133                 animation.aspect_h = 1;
134                 animation.length = 1.0;
135         }
136
137         void serialize(std::ostream &os, u16 protocol_version) const;
138         void deSerialize(std::istream &is);
139 };
140
141 enum NodeDrawType
142 {
143         NDT_NORMAL, // A basic solid block
144         NDT_AIRLIKE, // Nothing is drawn
145         NDT_LIQUID, // Do not draw face towards same kind of flowing/source liquid
146         NDT_FLOWINGLIQUID, // A very special kind of thing
147         NDT_GLASSLIKE, // Glass-like, don't draw faces towards other glass
148         NDT_ALLFACES, // Leaves-like, draw all faces no matter what
149         NDT_ALLFACES_OPTIONAL, // Fancy -> allfaces, fast -> normal
150         NDT_TORCHLIKE,
151         NDT_SIGNLIKE,
152         NDT_PLANTLIKE,
153         NDT_FENCELIKE,
154         NDT_RAILLIKE,
155         NDT_NODEBOX,
156         NDT_GLASSLIKE_FRAMED, // Glass-like, draw connected frames and all all
157                               // visible faces
158                                                   // uses 2 textures, one for frames, second for faces
159         NDT_FIRELIKE, // Draw faces slightly rotated and only on connecting nodes,
160         NDT_GLASSLIKE_FRAMED_OPTIONAL,  // enabled -> connected, disabled -> Glass-like
161                                                                         // uses 2 textures, one for frames, second for faces
162         NDT_MESH, // Uses static meshes
163 };
164
165 #define CF_SPECIAL_COUNT 6
166
167 struct ContentFeatures
168 {
169         /*
170                 Cached stuff
171         */
172 #ifndef SERVER
173         // 0     1     2     3     4     5
174         // up    down  right left  back  front
175         TileSpec tiles[6];
176         // Special tiles
177         // - Currently used for flowing liquids
178         TileSpec special_tiles[CF_SPECIAL_COUNT];
179         u8 solidness; // Used when choosing which face is drawn
180         u8 visual_solidness; // When solidness=0, this tells how it looks like
181         bool backface_culling;
182 #endif
183
184         // Server-side cached callback existence for fast skipping
185         bool has_on_construct;
186         bool has_on_destruct;
187         bool has_after_destruct;
188
189         /*
190                 Actual data
191         */
192
193         std::string name; // "" = undefined node
194         ItemGroupList groups; // Same as in itemdef
195
196         // Visual definition
197         enum NodeDrawType drawtype;
198         std::string mesh;
199 #ifndef SERVER
200         scene::IMesh *mesh_ptr[24];
201         video::SColor minimap_color;
202 #endif
203         float visual_scale; // Misc. scale parameter
204         TileDef tiledef[6];
205         TileDef tiledef_special[CF_SPECIAL_COUNT]; // eg. flowing liquid
206         u8 alpha;
207
208         // Post effect color, drawn when the camera is inside the node.
209         video::SColor post_effect_color;
210
211         // Type of MapNode::param1
212         ContentParamType param_type;
213         // Type of MapNode::param2
214         ContentParamType2 param_type_2;
215         // True for all ground-like things like stone and mud, false for eg. trees
216         bool is_ground_content;
217         bool light_propagates;
218         bool sunlight_propagates;
219         // This is used for collision detection.
220         // Also for general solidness queries.
221         bool walkable;
222         // Player can point to these
223         bool pointable;
224         // Player can dig these
225         bool diggable;
226         // Player can climb these
227         bool climbable;
228         // Player can build on these
229         bool buildable_to;
230         // Player cannot build to these (placement prediction disabled)
231         bool rightclickable;
232         // Flowing liquid or snow, value = default level
233         u8 leveled;
234         // Whether the node is non-liquid, source liquid or flowing liquid
235         enum LiquidType liquid_type;
236         // If the content is liquid, this is the flowing version of the liquid.
237         std::string liquid_alternative_flowing;
238         // If the content is liquid, this is the source version of the liquid.
239         std::string liquid_alternative_source;
240         // Viscosity for fluid flow, ranging from 1 to 7, with
241         // 1 giving almost instantaneous propagation and 7 being
242         // the slowest possible
243         u8 liquid_viscosity;
244         // Is liquid renewable (new liquid source will be created between 2 existing)
245         bool liquid_renewable;
246         // Number of flowing liquids surrounding source
247         u8 liquid_range;
248         u8 drowning;
249         // Amount of light the node emits
250         u8 light_source;
251         u32 damage_per_second;
252         NodeBox node_box;
253         NodeBox selection_box;
254         NodeBox collision_box;
255         // Used for waving leaves/plants
256         u8 waving;
257         // Compatibility with old maps
258         // Set to true if paramtype used to be 'facedir_simple'
259         bool legacy_facedir_simple;
260         // Set to true if wall_mounted used to be set to true
261         bool legacy_wallmounted;
262
263         // Sound properties
264         SimpleSoundSpec sound_footstep;
265         SimpleSoundSpec sound_dig;
266         SimpleSoundSpec sound_dug;
267
268         /*
269                 Methods
270         */
271
272         ContentFeatures();
273         ~ContentFeatures();
274         void reset();
275         void serialize(std::ostream &os, u16 protocol_version) const;
276         void deSerialize(std::istream &is);
277         void serializeOld(std::ostream &os, u16 protocol_version) const;
278         void deSerializeOld(std::istream &is, int version);
279
280         /*
281                 Some handy methods
282         */
283         bool isLiquid() const{
284                 return (liquid_type != LIQUID_NONE);
285         }
286         bool sameLiquid(const ContentFeatures &f) const{
287                 if(!isLiquid() || !f.isLiquid()) return false;
288                 return (liquid_alternative_flowing == f.liquid_alternative_flowing);
289         }
290 };
291
292 class INodeDefManager {
293 public:
294         INodeDefManager(){}
295         virtual ~INodeDefManager(){}
296         // Get node definition
297         virtual const ContentFeatures &get(content_t c) const=0;
298         virtual const ContentFeatures &get(const MapNode &n) const=0;
299         virtual bool getId(const std::string &name, content_t &result) const=0;
300         virtual content_t getId(const std::string &name) const=0;
301         // Allows "group:name" in addition to regular node names
302         virtual void getIds(const std::string &name, std::set<content_t> &result)
303                         const=0;
304         virtual const ContentFeatures &get(const std::string &name) const=0;
305
306         virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
307
308         virtual bool getNodeRegistrationStatus() const=0;
309
310         virtual void pendNodeResolve(NodeResolver *nr)=0;
311         virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
312 };
313
314 class IWritableNodeDefManager : public INodeDefManager {
315 public:
316         IWritableNodeDefManager(){}
317         virtual ~IWritableNodeDefManager(){}
318         virtual IWritableNodeDefManager* clone()=0;
319         // Get node definition
320         virtual const ContentFeatures &get(content_t c) const=0;
321         virtual const ContentFeatures &get(const MapNode &n) const=0;
322         virtual bool getId(const std::string &name, content_t &result) const=0;
323         // If not found, returns CONTENT_IGNORE
324         virtual content_t getId(const std::string &name) const=0;
325         // Allows "group:name" in addition to regular node names
326         virtual void getIds(const std::string &name, std::set<content_t> &result)
327                 const=0;
328         // If not found, returns the features of CONTENT_UNKNOWN
329         virtual const ContentFeatures &get(const std::string &name) const=0;
330
331         // Register node definition by name (allocate an id)
332         // If returns CONTENT_IGNORE, could not allocate id
333         virtual content_t set(const std::string &name,
334                         const ContentFeatures &def)=0;
335         // If returns CONTENT_IGNORE, could not allocate id
336         virtual content_t allocateDummy(const std::string &name)=0;
337
338         /*
339                 Update item alias mapping.
340                 Call after updating item definitions.
341         */
342         virtual void updateAliases(IItemDefManager *idef)=0;
343
344         /*
345                 Override textures from servers with ones specified in texturepack/override.txt
346         */
347         virtual void applyTextureOverrides(const std::string &override_filepath)=0;
348
349         /*
350                 Update tile textures to latest return values of TextueSource.
351         */
352         virtual void updateTextures(IGameDef *gamedef,
353                 void (*progress_cbk)(void *progress_args, u32 progress, u32 max_progress),
354                 void *progress_cbk_args)=0;
355
356         virtual void serialize(std::ostream &os, u16 protocol_version) const=0;
357         virtual void deSerialize(std::istream &is)=0;
358
359         virtual bool getNodeRegistrationStatus() const=0;
360         virtual void setNodeRegistrationStatus(bool completed)=0;
361
362         virtual void pendNodeResolve(NodeResolver *nr)=0;
363         virtual bool cancelNodeResolveCallback(NodeResolver *nr)=0;
364         virtual void runNodeResolveCallbacks()=0;
365         virtual void resetNodeResolveState()=0;
366 };
367
368 IWritableNodeDefManager *createNodeDefManager();
369
370 class NodeResolver {
371 public:
372         NodeResolver();
373         virtual ~NodeResolver();
374         virtual void resolveNodeNames() = 0;
375
376         bool getIdFromNrBacklog(content_t *result_out,
377                 const std::string &node_alt, content_t c_fallback);
378         bool getIdsFromNrBacklog(std::vector<content_t> *result_out,
379                 bool all_required=false, content_t c_fallback=CONTENT_IGNORE);
380
381         void nodeResolveInternal();
382
383         u32 m_nodenames_idx;
384         u32 m_nnlistsizes_idx;
385         std::vector<std::string> m_nodenames;
386         std::vector<size_t> m_nnlistsizes;
387         INodeDefManager *m_ndef;
388         bool m_resolve_done;
389 };
390
391 #endif