]> git.lizzy.rs Git - dragonfireclient.git/blob - src/nodedef.h
Merge branch 'master' of https://github.com/minetest/minetest
[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 #pragma once
21
22 #include "irrlichttypes_bloated.h"
23 #include <string>
24 #include <iostream>
25 #include <map>
26 #include "mapnode.h"
27 #include "nameidmapping.h"
28 #ifndef SERVER
29 #include "client/tile.h"
30 #include <IMeshManipulator.h>
31 class Client;
32 #endif
33 #include "itemgroup.h"
34 #include "sound.h" // SimpleSoundSpec
35 #include "constants.h" // BS
36 #include "texture_override.h" // TextureOverride
37 #include "tileanimation.h"
38
39 // PROTOCOL_VERSION >= 37
40 static const u8 CONTENTFEATURES_VERSION = 13;
41
42 class IItemDefManager;
43 class ITextureSource;
44 class IShaderSource;
45 class IGameDef;
46 class NodeResolver;
47 #if BUILD_UNITTESTS
48 class TestSchematic;
49 #endif
50
51 enum ContentParamType
52 {
53         CPT_NONE,
54         CPT_LIGHT,
55 };
56
57 enum ContentParamType2
58 {
59         CPT2_NONE,
60         // Need 8-bit param2
61         CPT2_FULL,
62         // Flowing liquid properties
63         CPT2_FLOWINGLIQUID,
64         // Direction for chests and furnaces and such
65         CPT2_FACEDIR,
66         // Direction for signs, torches and such
67         CPT2_WALLMOUNTED,
68         // Block level like FLOWINGLIQUID
69         CPT2_LEVELED,
70         // 2D rotation for things like plants
71         CPT2_DEGROTATE,
72         // Mesh options for plants
73         CPT2_MESHOPTIONS,
74         // Index for palette
75         CPT2_COLOR,
76         // 3 bits of palette index, then facedir
77         CPT2_COLORED_FACEDIR,
78         // 5 bits of palette index, then wallmounted
79         CPT2_COLORED_WALLMOUNTED,
80         // Glasslike framed drawtype internal liquid level, param2 values 0 to 63
81         CPT2_GLASSLIKE_LIQUID_LEVEL,
82 };
83
84 enum LiquidType
85 {
86         LIQUID_NONE,
87         LIQUID_FLOWING,
88         LIQUID_SOURCE,
89 };
90
91 enum NodeBoxType
92 {
93         NODEBOX_REGULAR, // Regular block; allows buildable_to
94         NODEBOX_FIXED, // Static separately defined box(es)
95         NODEBOX_WALLMOUNTED, // Box for wall mounted nodes; (top, bottom, side)
96         NODEBOX_LEVELED, // Same as fixed, but with dynamic height from param2. for snow, ...
97         NODEBOX_CONNECTED, // optionally draws nodeboxes if a neighbor node attaches
98 };
99
100 struct NodeBox
101 {
102         enum NodeBoxType type;
103         // NODEBOX_REGULAR (no parameters)
104         // NODEBOX_FIXED
105         std::vector<aabb3f> fixed;
106         // NODEBOX_WALLMOUNTED
107         aabb3f wall_top;
108         aabb3f wall_bottom;
109         aabb3f wall_side; // being at the -X side
110         // NODEBOX_CONNECTED
111         std::vector<aabb3f> connect_top;
112         std::vector<aabb3f> connect_bottom;
113         std::vector<aabb3f> connect_front;
114         std::vector<aabb3f> connect_left;
115         std::vector<aabb3f> connect_back;
116         std::vector<aabb3f> connect_right;
117         std::vector<aabb3f> disconnected_top;
118         std::vector<aabb3f> disconnected_bottom;
119         std::vector<aabb3f> disconnected_front;
120         std::vector<aabb3f> disconnected_left;
121         std::vector<aabb3f> disconnected_back;
122         std::vector<aabb3f> disconnected_right;
123         std::vector<aabb3f> disconnected;
124         std::vector<aabb3f> disconnected_sides;
125
126         NodeBox()
127         { reset(); }
128
129         void reset();
130         void serialize(std::ostream &os, u16 protocol_version) const;
131         void deSerialize(std::istream &is);
132 };
133
134 struct MapNode;
135 class NodeMetadata;
136
137 enum LeavesStyle {
138         LEAVES_FANCY,
139         LEAVES_SIMPLE,
140         LEAVES_OPAQUE,
141 };
142
143 enum AutoScale : u8 {
144         AUTOSCALE_DISABLE,
145         AUTOSCALE_ENABLE,
146         AUTOSCALE_FORCE,
147 };
148
149 enum WorldAlignMode : u8 {
150         WORLDALIGN_DISABLE,
151         WORLDALIGN_ENABLE,
152         WORLDALIGN_FORCE,
153         WORLDALIGN_FORCE_NODEBOX,
154 };
155
156 class TextureSettings {
157 public:
158         LeavesStyle leaves_style;
159         WorldAlignMode world_aligned_mode;
160         AutoScale autoscale_mode;
161         int node_texture_size;
162         bool opaque_water;
163         bool connected_glass;
164         bool enable_mesh_cache;
165         bool enable_minimap;
166
167         TextureSettings() = default;
168
169         void readSettings();
170 };
171
172 enum NodeDrawType
173 {
174         // A basic solid block
175         NDT_NORMAL,
176         // Nothing is drawn
177         NDT_AIRLIKE,
178         // Do not draw face towards same kind of flowing/source liquid
179         NDT_LIQUID,
180         // A very special kind of thing
181         NDT_FLOWINGLIQUID,
182         // Glass-like, don't draw faces towards other glass
183         NDT_GLASSLIKE,
184         // Leaves-like, draw all faces no matter what
185         NDT_ALLFACES,
186         // Enabled -> ndt_allfaces, disabled -> ndt_normal
187         NDT_ALLFACES_OPTIONAL,
188         // Single plane perpendicular to a surface
189         NDT_TORCHLIKE,
190         // Single plane parallel to a surface
191         NDT_SIGNLIKE,
192         // 2 vertical planes in a 'X' shape diagonal to XZ axes.
193         // paramtype2 = "meshoptions" allows various forms, sizes and
194         // vertical and horizontal random offsets.
195         NDT_PLANTLIKE,
196         // Fenceposts that connect to neighbouring fenceposts with horizontal bars
197         NDT_FENCELIKE,
198         // Selects appropriate junction texture to connect like rails to
199         // neighbouring raillikes.
200         NDT_RAILLIKE,
201         // Custom Lua-definable structure of multiple cuboids
202         NDT_NODEBOX,
203         // Glass-like, draw connected frames and all visible faces.
204         // param2 > 0 defines 64 levels of internal liquid
205         // Uses 3 textures, one for frames, second for faces,
206         // optional third is a 'special tile' for the liquid.
207         NDT_GLASSLIKE_FRAMED,
208         // Draw faces slightly rotated and only on neighbouring nodes
209         NDT_FIRELIKE,
210         // Enabled -> ndt_glasslike_framed, disabled -> ndt_glasslike
211         NDT_GLASSLIKE_FRAMED_OPTIONAL,
212         // Uses static meshes
213         NDT_MESH,
214         // Combined plantlike-on-solid
215         NDT_PLANTLIKE_ROOTED,
216 };
217
218 // Mesh options for NDT_PLANTLIKE with CPT2_MESHOPTIONS
219 static const u8 MO_MASK_STYLE          = 0x07;
220 static const u8 MO_BIT_RANDOM_OFFSET   = 0x08;
221 static const u8 MO_BIT_SCALE_SQRT2     = 0x10;
222 static const u8 MO_BIT_RANDOM_OFFSET_Y = 0x20;
223 enum PlantlikeStyle {
224         PLANT_STYLE_CROSS,
225         PLANT_STYLE_CROSS2,
226         PLANT_STYLE_STAR,
227         PLANT_STYLE_HASH,
228         PLANT_STYLE_HASH2,
229 };
230
231 enum AlignStyle : u8 {
232         ALIGN_STYLE_NODE,
233         ALIGN_STYLE_WORLD,
234         ALIGN_STYLE_USER_DEFINED,
235 };
236
237 enum AlphaMode : u8 {
238         ALPHAMODE_BLEND,
239         ALPHAMODE_CLIP,
240         ALPHAMODE_OPAQUE,
241         ALPHAMODE_LEGACY_COMPAT, /* means either opaque or clip */
242 };
243
244
245 /*
246         Stand-alone definition of a TileSpec (basically a server-side TileSpec)
247 */
248
249 struct TileDef
250 {
251         std::string name = "";
252         bool backface_culling = true; // Takes effect only in special cases
253         bool tileable_horizontal = true;
254         bool tileable_vertical = true;
255         //! If true, the tile has its own color.
256         bool has_color = false;
257         //! The color of the tile.
258         video::SColor color = video::SColor(0xFFFFFFFF);
259         AlignStyle align_style = ALIGN_STYLE_NODE;
260         u8 scale = 0;
261
262         struct TileAnimationParams animation;
263
264         TileDef()
265         {
266                 animation.type = TAT_NONE;
267         }
268
269         void serialize(std::ostream &os, u16 protocol_version) const;
270         void deSerialize(std::istream &is, u8 contentfeatures_version,
271                 NodeDrawType drawtype);
272 };
273
274 // Defines the number of special tiles per nodedef
275 //
276 // NOTE: When changing this value, the enum entries of OverrideTarget and
277 //       parser in TextureOverrideSource must be updated so that all special
278 //       tiles can be overridden.
279 #define CF_SPECIAL_COUNT 6
280
281 struct ContentFeatures
282 {
283         /*
284                 Cached stuff
285          */
286 #ifndef SERVER
287         // 0     1     2     3     4     5
288         // up    down  right left  back  front
289         TileSpec tiles[6];
290         // Special tiles
291         // - Currently used for flowing liquids
292         TileSpec special_tiles[CF_SPECIAL_COUNT];
293         u8 solidness; // Used when choosing which face is drawn
294         u8 visual_solidness; // When solidness=0, this tells how it looks like
295         bool backface_culling;
296 #endif
297
298         // Server-side cached callback existence for fast skipping
299         bool has_on_construct;
300         bool has_on_destruct;
301         bool has_after_destruct;
302
303         /*
304                 Actual data
305          */
306
307         // --- GENERAL PROPERTIES ---
308
309         std::string name; // "" = undefined node
310         ItemGroupList groups; // Same as in itemdef
311         // Type of MapNode::param1
312         ContentParamType param_type;
313         // Type of MapNode::param2
314         ContentParamType2 param_type_2;
315
316         // --- VISUAL PROPERTIES ---
317
318         enum NodeDrawType drawtype;
319         std::string mesh;
320 #ifndef SERVER
321         scene::IMesh *mesh_ptr[24];
322         video::SColor minimap_color;
323 #endif
324         float visual_scale; // Misc. scale parameter
325         TileDef tiledef[6];
326         // These will be drawn over the base tiles.
327         TileDef tiledef_overlay[6];
328         TileDef tiledef_special[CF_SPECIAL_COUNT]; // eg. flowing liquid
329         AlphaMode alpha;
330         // The color of the node.
331         video::SColor color;
332         std::string palette_name;
333         std::vector<video::SColor> *palette;
334         // Used for waving leaves/plants
335         u8 waving;
336         // for NDT_CONNECTED pairing
337         u8 connect_sides;
338         std::vector<std::string> connects_to;
339         std::vector<content_t> connects_to_ids;
340         // Post effect color, drawn when the camera is inside the node.
341         video::SColor post_effect_color;
342         // Flowing liquid or leveled nodebox, value = default level
343         u8 leveled;
344         // Maximum value for leveled nodes
345         u8 leveled_max;
346
347         // --- LIGHTING-RELATED ---
348
349         bool light_propagates;
350         bool sunlight_propagates;
351         // Amount of light the node emits
352         u8 light_source;
353
354         // --- MAP GENERATION ---
355
356         // True for all ground-like things like stone and mud, false for eg. trees
357         bool is_ground_content;
358
359         // --- INTERACTION PROPERTIES ---
360
361         // This is used for collision detection.
362         // Also for general solidness queries.
363         bool walkable;
364         // Player can point to these
365         bool pointable;
366         // Player can dig these
367         bool diggable;
368         // Player can climb these
369         bool climbable;
370         // Player can build on these
371         bool buildable_to;
372         // Player cannot build to these (placement prediction disabled)
373         bool rightclickable;
374         u32 damage_per_second;
375         // client dig prediction
376         std::string node_dig_prediction;
377
378         // --- LIQUID PROPERTIES ---
379
380         // Whether the node is non-liquid, source liquid or flowing liquid
381         enum LiquidType liquid_type;
382         // If the content is liquid, this is the flowing version of the liquid.
383         std::string liquid_alternative_flowing;
384         content_t liquid_alternative_flowing_id;
385         // If the content is liquid, this is the source version of the liquid.
386         std::string liquid_alternative_source;
387         content_t liquid_alternative_source_id;
388         // Viscosity for fluid flow, ranging from 1 to 7, with
389         // 1 giving almost instantaneous propagation and 7 being
390         // the slowest possible
391         u8 liquid_viscosity;
392         // Is liquid renewable (new liquid source will be created between 2 existing)
393         bool liquid_renewable;
394         // Number of flowing liquids surrounding source
395         u8 liquid_range;
396         u8 drowning;
397         // Liquids flow into and replace node
398         bool floodable;
399
400         // --- NODEBOXES ---
401
402         NodeBox node_box;
403         NodeBox selection_box;
404         NodeBox collision_box;
405
406         // --- SOUND PROPERTIES ---
407
408         SimpleSoundSpec sound_footstep;
409         SimpleSoundSpec sound_dig;
410         SimpleSoundSpec sound_dug;
411
412         // --- LEGACY ---
413
414         // Compatibility with old maps
415         // Set to true if paramtype used to be 'facedir_simple'
416         bool legacy_facedir_simple;
417         // Set to true if wall_mounted used to be set to true
418         bool legacy_wallmounted;
419
420         /*
421                 Methods
422         */
423
424         ContentFeatures();
425         ~ContentFeatures();
426         void reset();
427         void serialize(std::ostream &os, u16 protocol_version) const;
428         void deSerialize(std::istream &is);
429
430         /*
431                 Some handy methods
432         */
433         void setDefaultAlphaMode()
434         {
435                 switch (drawtype) {
436                 case NDT_NORMAL:
437                 case NDT_LIQUID:
438                 case NDT_FLOWINGLIQUID:
439                         alpha = ALPHAMODE_OPAQUE;
440                         break;
441                 case NDT_NODEBOX:
442                 case NDT_MESH:
443                         alpha = ALPHAMODE_LEGACY_COMPAT; // this should eventually be OPAQUE
444                         break;
445                 default:
446                         alpha = ALPHAMODE_CLIP;
447                         break;
448                 }
449         }
450
451         bool needsBackfaceCulling() const
452         {
453                 switch (drawtype) {
454                 case NDT_TORCHLIKE:
455                 case NDT_SIGNLIKE:
456                 case NDT_FIRELIKE:
457                 case NDT_RAILLIKE:
458                 case NDT_PLANTLIKE:
459                 case NDT_PLANTLIKE_ROOTED:
460                 case NDT_MESH:
461                         return false;
462                 default:
463                         return true;
464                 }
465         }
466
467         bool isLiquid() const{
468                 return (liquid_type != LIQUID_NONE);
469         }
470         bool sameLiquid(const ContentFeatures &f) const{
471                 if(!isLiquid() || !f.isLiquid()) return false;
472                 return (liquid_alternative_flowing_id == f.liquid_alternative_flowing_id);
473         }
474
475         int getGroup(const std::string &group) const
476         {
477                 return itemgroup_get(groups, group);
478         }
479
480 #ifndef SERVER
481         void updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc,
482                 scene::IMeshManipulator *meshmanip, Client *client, const TextureSettings &tsettings);
483 #endif
484
485 private:
486 #ifndef SERVER
487         /*
488          * Checks if any tile texture has any transparent pixels.
489          * Prints a warning and returns true if that is the case, false otherwise.
490          * This is supposed to be used for use_texture_alpha backwards compatibility.
491          */
492         bool textureAlphaCheck(ITextureSource *tsrc, const TileDef *tiles,
493                 int length);
494 #endif
495
496         void setAlphaFromLegacy(u8 legacy_alpha);
497
498         u8 getAlphaForLegacy() const;
499 };
500
501 /*!
502  * @brief This class is for getting the actual properties of nodes from their
503  * content ID.
504  *
505  * @details The nodes on the map are represented by three numbers (see MapNode).
506  * The first number (param0) is the type of a node. All node types have own
507  * properties (see ContentFeatures). This class is for storing and getting the
508  * properties of nodes.
509  * The manager is first filled with registered nodes, then as the game begins,
510  * functions only get `const` pointers to it, to prevent modification of
511  * registered nodes.
512  */
513 class NodeDefManager {
514 public:
515         /*!
516          * Creates a NodeDefManager, and registers three ContentFeatures:
517          * \ref CONTENT_AIR, \ref CONTENT_UNKNOWN and \ref CONTENT_IGNORE.
518          */
519         NodeDefManager();
520         ~NodeDefManager();
521
522         /*!
523          * Returns the properties for the given content type.
524          * @param c content type of a node
525          * @return properties of the given content type, or \ref CONTENT_UNKNOWN
526          * if the given content type is not registered.
527          */
528         inline const ContentFeatures& get(content_t c) const {
529                 return
530                         c < m_content_features.size() ?
531                                 m_content_features[c] : m_content_features[CONTENT_UNKNOWN];
532         }
533
534         /*!
535          * Returns the properties of the given node.
536          * @param n a map node
537          * @return properties of the given node or @ref CONTENT_UNKNOWN if the
538          * given content type is not registered.
539          */
540         inline const ContentFeatures& get(const MapNode &n) const {
541                 return get(n.getContent());
542         }
543
544         /*!
545          * Returns the node properties for a node name.
546          * @param name name of a node
547          * @return properties of the given node or @ref CONTENT_UNKNOWN if
548          * not found
549          */
550         const ContentFeatures& get(const std::string &name) const;
551
552         /*!
553          * Returns the content ID for the given name.
554          * @param name a node name
555          * @param[out] result will contain the content ID if found, otherwise
556          * remains unchanged
557          * @return true if the ID was found, false otherwise
558          */
559         bool getId(const std::string &name, content_t &result) const;
560
561         /*!
562          * Returns the content ID for the given name.
563          * @param name a node name
564          * @return ID of the node or @ref CONTENT_IGNORE if not found
565          */
566         content_t getId(const std::string &name) const;
567
568         /*!
569          * Returns the content IDs of the given node name or node group name.
570          * Group names start with "group:".
571          * @param name a node name or node group name
572          * @param[out] result will be appended with matching IDs
573          * @return true if `name` is a valid node name or a (not necessarily
574          * valid) group name
575          */
576         bool getIds(const std::string &name, std::vector<content_t> &result) const;
577
578         /*!
579          * Returns the smallest box in integer node coordinates that
580          * contains all nodes' selection boxes. The returned box might be larger
581          * than the minimal size if the largest node is removed from the manager.
582          */
583         inline core::aabbox3d<s16> getSelectionBoxIntUnion() const {
584                 return m_selection_box_int_union;
585         }
586
587         /*!
588          * Checks whether a node connects to an adjacent node.
589          * @param from the node to be checked
590          * @param to the adjacent node
591          * @param connect_face a bit field indicating which face of the node is
592          * adjacent to the other node.
593          * Bits: +y (least significant), -y, -z, -x, +z, +x (most significant).
594          * @return true if the node connects, false otherwise
595          */
596         bool nodeboxConnects(MapNode from, MapNode to,
597                         u8 connect_face) const;
598
599         /*!
600          * Registers a NodeResolver to wait for the registration of
601          * ContentFeatures. Once the node registration finishes, all
602          * listeners are notified.
603          */
604         void pendNodeResolve(NodeResolver *nr) const;
605
606         /*!
607          * Stops listening to the NodeDefManager.
608          * @return true if the listener was registered before, false otherwise
609          */
610         bool cancelNodeResolveCallback(NodeResolver *nr) const;
611
612         /*!
613          * Registers a new node type with the given name and allocates a new
614          * content ID.
615          * Should not be called with an already existing name.
616          * @param name name of the node, must match with `def.name`.
617          * @param def definition of the registered node type.
618          * @return ID of the registered node or @ref CONTENT_IGNORE if
619          * the function could not allocate an ID.
620          */
621         content_t set(const std::string &name, const ContentFeatures &def);
622
623         /*!
624          * Allocates a blank node ID for the given name.
625          * @param name name of a node
626          * @return allocated ID or @ref CONTENT_IGNORE if could not allocate
627          * an ID.
628          */
629         content_t allocateDummy(const std::string &name);
630
631         /*!
632          * Removes the given node name from the manager.
633          * The node ID will remain in the manager, but won't be linked to any name.
634          * @param name name to be removed
635          */
636         void removeNode(const std::string &name);
637
638         /*!
639          * Regenerates the alias list (a map from names to node IDs).
640          * @param idef the item definition manager containing alias information
641          */
642         void updateAliases(IItemDefManager *idef);
643
644         /*!
645          * Replaces the textures of registered nodes with the ones specified in
646          * the texturepack's override.txt file
647          *
648          * @param overrides the texture overrides
649          */
650         void applyTextureOverrides(const std::vector<TextureOverride> &overrides);
651
652         /*!
653          * Only the client uses this. Loads textures and shaders required for
654          * rendering the nodes.
655          * @param gamedef must be a Client.
656          * @param progress_cbk called each time a node is loaded. Arguments:
657          * `progress_cbk_args`, number of loaded ContentFeatures, number of
658          * total ContentFeatures.
659          * @param progress_cbk_args passed to the callback function
660          */
661         void updateTextures(IGameDef *gamedef,
662                 void (*progress_cbk)(void *progress_args, u32 progress, u32 max_progress),
663                 void *progress_cbk_args);
664
665         /*!
666          * Writes the content of this manager to the given output stream.
667          * @param protocol_version serialization version of ContentFeatures
668          */
669         void serialize(std::ostream &os, u16 protocol_version) const;
670
671         /*!
672          * Restores the manager from a serialized stream.
673          * This clears the previous state.
674          * @param is input stream containing a serialized NodeDefManager
675          */
676         void deSerialize(std::istream &is);
677
678         /*!
679          * Used to indicate that node registration has finished.
680          * @param completed tells whether registration is complete
681          */
682         inline void setNodeRegistrationStatus(bool completed) {
683                 m_node_registration_complete = completed;
684         }
685
686         /*!
687          * Notifies the registered NodeResolver instances that node registration
688          * has finished, then unregisters all listeners.
689          * Must be called after node registration has finished!
690          */
691         void runNodeResolveCallbacks();
692
693         /*!
694          * Sets the registration completion flag to false and unregisters all
695          * NodeResolver instances listening to the manager.
696          */
697         void resetNodeResolveState();
698
699         /*!
700          * Resolves (caches the IDs) cross-references between nodes,
701          * like liquid alternatives.
702          * Must be called after node registration has finished!
703          */
704         void resolveCrossrefs();
705
706 private:
707         /*!
708          * Resets the manager to its initial state.
709          * See the documentation of the constructor.
710          */
711         void clear();
712
713         /*!
714          * Allocates a new content ID, and returns it.
715          * @return the allocated ID or \ref CONTENT_IGNORE if could not allocate
716          */
717         content_t allocateId();
718
719         /*!
720          * Binds the given content ID and node name.
721          * Registers them in \ref m_name_id_mapping and
722          * \ref m_name_id_mapping_with_aliases.
723          * @param i a content ID
724          * @param name a node name
725          */
726         void addNameIdMapping(content_t i, std::string name);
727
728         /*!
729          * Removes a content ID from all groups.
730          * Erases content IDs from vectors in \ref m_group_to_items and
731          * removes empty vectors.
732          * @param id Content ID
733          */
734         void eraseIdFromGroups(content_t id);
735
736         /*!
737          * Recalculates m_selection_box_int_union based on
738          * m_selection_box_union.
739          */
740         void fixSelectionBoxIntUnion();
741
742         //! Features indexed by ID.
743         std::vector<ContentFeatures> m_content_features;
744
745         //! A mapping for fast conversion between names and IDs
746         NameIdMapping m_name_id_mapping;
747
748         /*!
749          * Like @ref m_name_id_mapping, but maps only from names to IDs, and
750          * includes aliases too. Updated by \ref updateAliases().
751          * Note: Not serialized.
752          */
753         std::unordered_map<std::string, content_t> m_name_id_mapping_with_aliases;
754
755         /*!
756          * A mapping from group names to a vector of content types that belong
757          * to it. Necessary for a direct lookup in \ref getIds().
758          * Note: Not serialized.
759          */
760         std::unordered_map<std::string, std::vector<content_t>> m_group_to_items;
761
762         /*!
763          * The next ID that might be free to allocate.
764          * It can be allocated already, because \ref CONTENT_AIR,
765          * \ref CONTENT_UNKNOWN and \ref CONTENT_IGNORE are registered when the
766          * manager is initialized, and new IDs are allocated from 0.
767          */
768         content_t m_next_id;
769
770         //! True if all nodes have been registered.
771         bool m_node_registration_complete;
772
773         /*!
774          * The union of all nodes' selection boxes.
775          * Might be larger if big nodes are removed from the manager.
776          */
777         aabb3f m_selection_box_union;
778
779         /*!
780          * The smallest box in integer node coordinates that
781          * contains all nodes' selection boxes.
782          * Might be larger if big nodes are removed from the manager.
783          */
784         core::aabbox3d<s16> m_selection_box_int_union;
785
786         /*!
787          * NodeResolver instances to notify once node registration has finished.
788          * Even constant NodeDefManager instances can register listeners.
789          */
790         mutable std::vector<NodeResolver *> m_pending_resolve_callbacks;
791 };
792
793 NodeDefManager *createNodeDefManager();
794
795 // NodeResolver: Queue for node names which are then translated
796 // to content_t after the NodeDefManager was initialized
797 class NodeResolver {
798 public:
799         NodeResolver();
800         virtual ~NodeResolver();
801         // Callback which is run as soon NodeDefManager is ready
802         virtual void resolveNodeNames() = 0;
803
804         // required because this class is used as mixin for ObjDef
805         void cloneTo(NodeResolver *res) const;
806
807         bool getIdFromNrBacklog(content_t *result_out,
808                 const std::string &node_alt, content_t c_fallback,
809                 bool error_on_fallback = true);
810         bool getIdsFromNrBacklog(std::vector<content_t> *result_out,
811                 bool all_required = false, content_t c_fallback = CONTENT_IGNORE);
812
813         inline bool isResolveDone() const { return m_resolve_done; }
814         void reset(bool resolve_done = false);
815
816         // Vector containing all node names in the resolve "queue"
817         std::vector<std::string> m_nodenames;
818         // Specifies the "set size" of node names which are to be processed
819         // this is used for getIdsFromNrBacklog
820         // TODO: replace or remove
821         std::vector<size_t> m_nnlistsizes;
822
823 protected:
824         friend class NodeDefManager; // m_ndef
825
826         const NodeDefManager *m_ndef = nullptr;
827         // Index of the next "m_nodenames" entry to resolve
828         u32 m_nodenames_idx = 0;
829
830 private:
831 #if BUILD_UNITTESTS
832         // Unittest requires access to m_resolve_done
833         friend class TestSchematic;
834 #endif
835         void nodeResolveInternal();
836
837         // Index of the next "m_nnlistsizes" entry to process
838         u32 m_nnlistsizes_idx = 0;
839         bool m_resolve_done = false;
840 };