3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
24 #include "client/mesh.h"
25 #include "client/shader.h"
26 #include "client/client.h"
27 #include "client/renderingengine.h"
28 #include "client/tile.h"
29 #include <IMeshManipulator.h>
33 #include "nameidmapping.h"
34 #include "util/numeric.h"
35 #include "util/serialize.h"
36 #include "exceptions.h"
40 #include <fstream> // Used in applyTextureOverrides()
50 type = NODEBOX_REGULAR;
53 // default is sign/ladder-like
54 wall_top = aabb3f(-BS/2, BS/2-BS/16., -BS/2, BS/2, BS/2, BS/2);
55 wall_bottom = aabb3f(-BS/2, -BS/2, -BS/2, BS/2, -BS/2+BS/16., BS/2);
56 wall_side = aabb3f(-BS/2, -BS/2, -BS/2, -BS/2+BS/16., BS/2, BS/2);
57 // no default for other parts
59 connect_bottom.clear();
60 connect_front.clear();
63 connect_right.clear();
64 disconnected_top.clear();
65 disconnected_bottom.clear();
66 disconnected_front.clear();
67 disconnected_left.clear();
68 disconnected_back.clear();
69 disconnected_right.clear();
71 disconnected_sides.clear();
74 void NodeBox::serialize(std::ostream &os, u16 protocol_version) const
85 writeU16(os, fixed.size());
86 for (const aabb3f &nodebox : fixed) {
87 writeV3F32(os, nodebox.MinEdge);
88 writeV3F32(os, nodebox.MaxEdge);
91 case NODEBOX_WALLMOUNTED:
94 writeV3F32(os, wall_top.MinEdge);
95 writeV3F32(os, wall_top.MaxEdge);
96 writeV3F32(os, wall_bottom.MinEdge);
97 writeV3F32(os, wall_bottom.MaxEdge);
98 writeV3F32(os, wall_side.MinEdge);
99 writeV3F32(os, wall_side.MaxEdge);
101 case NODEBOX_CONNECTED:
104 #define WRITEBOX(box) \
105 writeU16(os, (box).size()); \
106 for (const aabb3f &i: (box)) { \
107 writeV3F32(os, i.MinEdge); \
108 writeV3F32(os, i.MaxEdge); \
112 WRITEBOX(connect_top);
113 WRITEBOX(connect_bottom);
114 WRITEBOX(connect_front);
115 WRITEBOX(connect_left);
116 WRITEBOX(connect_back);
117 WRITEBOX(connect_right);
118 WRITEBOX(disconnected_top);
119 WRITEBOX(disconnected_bottom);
120 WRITEBOX(disconnected_front);
121 WRITEBOX(disconnected_left);
122 WRITEBOX(disconnected_back);
123 WRITEBOX(disconnected_right);
124 WRITEBOX(disconnected);
125 WRITEBOX(disconnected_sides);
133 void NodeBox::deSerialize(std::istream &is)
135 int version = readU8(is);
137 throw SerializationError("unsupported NodeBox version");
141 type = (enum NodeBoxType)readU8(is);
143 if(type == NODEBOX_FIXED || type == NODEBOX_LEVELED)
145 u16 fixed_count = readU16(is);
149 box.MinEdge = readV3F32(is);
150 box.MaxEdge = readV3F32(is);
151 fixed.push_back(box);
154 else if(type == NODEBOX_WALLMOUNTED)
156 wall_top.MinEdge = readV3F32(is);
157 wall_top.MaxEdge = readV3F32(is);
158 wall_bottom.MinEdge = readV3F32(is);
159 wall_bottom.MaxEdge = readV3F32(is);
160 wall_side.MinEdge = readV3F32(is);
161 wall_side.MaxEdge = readV3F32(is);
163 else if (type == NODEBOX_CONNECTED)
165 #define READBOXES(box) { \
166 count = readU16(is); \
167 (box).reserve(count); \
169 v3f min = readV3F32(is); \
170 v3f max = readV3F32(is); \
171 (box).emplace_back(min, max); }; }
176 READBOXES(connect_top);
177 READBOXES(connect_bottom);
178 READBOXES(connect_front);
179 READBOXES(connect_left);
180 READBOXES(connect_back);
181 READBOXES(connect_right);
182 READBOXES(disconnected_top);
183 READBOXES(disconnected_bottom);
184 READBOXES(disconnected_front);
185 READBOXES(disconnected_left);
186 READBOXES(disconnected_back);
187 READBOXES(disconnected_right);
188 READBOXES(disconnected);
189 READBOXES(disconnected_sides);
197 #define TILE_FLAG_BACKFACE_CULLING (1 << 0)
198 #define TILE_FLAG_TILEABLE_HORIZONTAL (1 << 1)
199 #define TILE_FLAG_TILEABLE_VERTICAL (1 << 2)
200 #define TILE_FLAG_HAS_COLOR (1 << 3)
201 #define TILE_FLAG_HAS_SCALE (1 << 4)
202 #define TILE_FLAG_HAS_ALIGN_STYLE (1 << 5)
204 void TileDef::serialize(std::ostream &os, u16 protocol_version) const
206 // protocol_version >= 36
208 writeU8(os, version);
210 os << serializeString(name);
211 animation.serialize(os, version);
212 bool has_scale = scale > 0;
214 if (backface_culling)
215 flags |= TILE_FLAG_BACKFACE_CULLING;
216 if (tileable_horizontal)
217 flags |= TILE_FLAG_TILEABLE_HORIZONTAL;
218 if (tileable_vertical)
219 flags |= TILE_FLAG_TILEABLE_VERTICAL;
221 flags |= TILE_FLAG_HAS_COLOR;
223 flags |= TILE_FLAG_HAS_SCALE;
224 if (align_style != ALIGN_STYLE_NODE)
225 flags |= TILE_FLAG_HAS_ALIGN_STYLE;
228 writeU8(os, color.getRed());
229 writeU8(os, color.getGreen());
230 writeU8(os, color.getBlue());
234 if (align_style != ALIGN_STYLE_NODE)
235 writeU8(os, align_style);
238 void TileDef::deSerialize(std::istream &is, u8 contentfeatures_version,
239 NodeDrawType drawtype)
241 int version = readU8(is);
243 throw SerializationError("unsupported TileDef version");
244 name = deSerializeString(is);
245 animation.deSerialize(is, version);
246 u16 flags = readU16(is);
247 backface_culling = flags & TILE_FLAG_BACKFACE_CULLING;
248 tileable_horizontal = flags & TILE_FLAG_TILEABLE_HORIZONTAL;
249 tileable_vertical = flags & TILE_FLAG_TILEABLE_VERTICAL;
250 has_color = flags & TILE_FLAG_HAS_COLOR;
251 bool has_scale = flags & TILE_FLAG_HAS_SCALE;
252 bool has_align_style = flags & TILE_FLAG_HAS_ALIGN_STYLE;
254 color.setRed(readU8(is));
255 color.setGreen(readU8(is));
256 color.setBlue(readU8(is));
258 scale = has_scale ? readU8(is) : 0;
260 align_style = static_cast<AlignStyle>(readU8(is));
262 align_style = ALIGN_STYLE_NODE;
265 void TextureSettings::readSettings()
267 connected_glass = g_settings->getBool("connected_glass");
268 opaque_water = g_settings->getBool("opaque_water");
269 bool enable_shaders = g_settings->getBool("enable_shaders");
270 bool enable_bumpmapping = g_settings->getBool("enable_bumpmapping");
271 bool enable_parallax_occlusion = g_settings->getBool("enable_parallax_occlusion");
272 bool smooth_lighting = g_settings->getBool("smooth_lighting");
273 enable_mesh_cache = g_settings->getBool("enable_mesh_cache");
274 enable_minimap = g_settings->getBool("enable_minimap");
275 node_texture_size = g_settings->getU16("texture_min_size");
276 std::string leaves_style_str = g_settings->get("leaves_style");
277 std::string world_aligned_mode_str = g_settings->get("world_aligned_mode");
278 std::string autoscale_mode_str = g_settings->get("autoscale_mode");
280 // Mesh cache is not supported in combination with smooth lighting
282 enable_mesh_cache = false;
284 use_normal_texture = enable_shaders &&
285 (enable_bumpmapping || enable_parallax_occlusion);
286 if (leaves_style_str == "fancy") {
287 leaves_style = LEAVES_FANCY;
288 } else if (leaves_style_str == "simple") {
289 leaves_style = LEAVES_SIMPLE;
291 leaves_style = LEAVES_OPAQUE;
294 if (world_aligned_mode_str == "enable")
295 world_aligned_mode = WORLDALIGN_ENABLE;
296 else if (world_aligned_mode_str == "force_solid")
297 world_aligned_mode = WORLDALIGN_FORCE;
298 else if (world_aligned_mode_str == "force_nodebox")
299 world_aligned_mode = WORLDALIGN_FORCE_NODEBOX;
301 world_aligned_mode = WORLDALIGN_DISABLE;
303 if (autoscale_mode_str == "enable")
304 autoscale_mode = AUTOSCALE_ENABLE;
305 else if (autoscale_mode_str == "force")
306 autoscale_mode = AUTOSCALE_FORCE;
308 autoscale_mode = AUTOSCALE_DISABLE;
315 ContentFeatures::ContentFeatures()
320 void ContentFeatures::reset()
327 visual_solidness = 0;
328 backface_culling = true;
331 has_on_construct = false;
332 has_on_destruct = false;
333 has_after_destruct = false;
337 NOTE: Most of this is always overridden by the default values given
342 // Unknown nodes can be dug
343 groups["dig_immediate"] = 2;
344 drawtype = NDT_NORMAL;
347 for (auto &i : mesh_ptr)
349 minimap_color = video::SColor(0, 0, 0, 0);
352 for (auto &i : tiledef)
354 for (auto &j : tiledef_special)
357 post_effect_color = video::SColor(0, 0, 0, 0);
358 param_type = CPT_NONE;
359 param_type_2 = CPT2_NONE;
360 is_ground_content = false;
361 light_propagates = false;
362 sunlight_propagates = false;
367 buildable_to = false;
369 rightclickable = true;
371 liquid_type = LIQUID_NONE;
372 liquid_alternative_flowing = "";
373 liquid_alternative_source = "";
374 liquid_viscosity = 0;
375 liquid_renewable = true;
376 liquid_range = LIQUID_LEVEL_MAX+1;
379 damage_per_second = 0;
380 node_box = NodeBox();
381 selection_box = NodeBox();
382 collision_box = NodeBox();
384 legacy_facedir_simple = false;
385 legacy_wallmounted = false;
386 sound_footstep = SimpleSoundSpec();
387 sound_dig = SimpleSoundSpec("__group");
388 sound_dug = SimpleSoundSpec();
390 connects_to_ids.clear();
392 color = video::SColor(0xFFFFFFFF);
395 node_dig_prediction = "air";
398 void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const
400 const u8 version = CONTENTFEATURES_VERSION;
401 writeU8(os, version);
404 os << serializeString(name);
405 writeU16(os, groups.size());
406 for (const auto &group : groups) {
407 os << serializeString(group.first);
408 writeS16(os, group.second);
410 writeU8(os, param_type);
411 writeU8(os, param_type_2);
414 writeU8(os, drawtype);
415 os << serializeString(mesh);
416 writeF32(os, visual_scale);
418 for (const TileDef &td : tiledef)
419 td.serialize(os, protocol_version);
420 for (const TileDef &td : tiledef_overlay)
421 td.serialize(os, protocol_version);
422 writeU8(os, CF_SPECIAL_COUNT);
423 for (const TileDef &td : tiledef_special) {
424 td.serialize(os, protocol_version);
427 writeU8(os, color.getRed());
428 writeU8(os, color.getGreen());
429 writeU8(os, color.getBlue());
430 os << serializeString(palette_name);
432 writeU8(os, connect_sides);
433 writeU16(os, connects_to_ids.size());
434 for (u16 connects_to_id : connects_to_ids)
435 writeU16(os, connects_to_id);
436 writeARGB8(os, post_effect_color);
437 writeU8(os, leveled);
440 writeU8(os, light_propagates);
441 writeU8(os, sunlight_propagates);
442 writeU8(os, light_source);
445 writeU8(os, is_ground_content);
448 writeU8(os, walkable);
449 writeU8(os, pointable);
450 writeU8(os, diggable);
451 writeU8(os, climbable);
452 writeU8(os, buildable_to);
453 writeU8(os, rightclickable);
454 writeU32(os, damage_per_second);
457 writeU8(os, liquid_type);
458 os << serializeString(liquid_alternative_flowing);
459 os << serializeString(liquid_alternative_source);
460 writeU8(os, liquid_viscosity);
461 writeU8(os, liquid_renewable);
462 writeU8(os, liquid_range);
463 writeU8(os, drowning);
464 writeU8(os, floodable);
467 node_box.serialize(os, protocol_version);
468 selection_box.serialize(os, protocol_version);
469 collision_box.serialize(os, protocol_version);
472 sound_footstep.serialize(os, version);
473 sound_dig.serialize(os, version);
474 sound_dug.serialize(os, version);
477 writeU8(os, legacy_facedir_simple);
478 writeU8(os, legacy_wallmounted);
480 os << serializeString(node_dig_prediction);
483 void ContentFeatures::correctAlpha(TileDef *tiles, int length)
485 // alpha == 0 means that the node is using texture alpha
486 if (alpha == 0 || alpha == 255)
489 for (int i = 0; i < length; i++) {
490 if (tiles[i].name.empty())
493 s << tiles[i].name << "^[noalpha^[opacity:" << ((int)alpha);
494 tiles[i].name = s.str();
498 void ContentFeatures::deSerialize(std::istream &is)
501 const u8 version = readU8(is);
502 if (version < CONTENTFEATURES_VERSION)
503 throw SerializationError("unsupported ContentFeatures version");
506 name = deSerializeString(is);
508 u32 groups_size = readU16(is);
509 for (u32 i = 0; i < groups_size; i++) {
510 std::string name = deSerializeString(is);
511 int value = readS16(is);
512 groups[name] = value;
514 param_type = (enum ContentParamType) readU8(is);
515 param_type_2 = (enum ContentParamType2) readU8(is);
518 drawtype = (enum NodeDrawType) readU8(is);
519 mesh = deSerializeString(is);
520 visual_scale = readF32(is);
522 throw SerializationError("unsupported tile count");
523 for (TileDef &td : tiledef)
524 td.deSerialize(is, version, drawtype);
525 for (TileDef &td : tiledef_overlay)
526 td.deSerialize(is, version, drawtype);
527 if (readU8(is) != CF_SPECIAL_COUNT)
528 throw SerializationError("unsupported CF_SPECIAL_COUNT");
529 for (TileDef &td : tiledef_special)
530 td.deSerialize(is, version, drawtype);
532 color.setRed(readU8(is));
533 color.setGreen(readU8(is));
534 color.setBlue(readU8(is));
535 palette_name = deSerializeString(is);
537 connect_sides = readU8(is);
538 u16 connects_to_size = readU16(is);
539 connects_to_ids.clear();
540 for (u16 i = 0; i < connects_to_size; i++)
541 connects_to_ids.push_back(readU16(is));
542 post_effect_color = readARGB8(is);
543 leveled = readU8(is);
546 light_propagates = readU8(is);
547 sunlight_propagates = readU8(is);
548 light_source = readU8(is);
549 light_source = MYMIN(light_source, LIGHT_MAX);
552 is_ground_content = readU8(is);
555 walkable = readU8(is);
556 pointable = readU8(is);
557 diggable = readU8(is);
558 climbable = readU8(is);
559 buildable_to = readU8(is);
560 rightclickable = readU8(is);
561 damage_per_second = readU32(is);
564 liquid_type = (enum LiquidType) readU8(is);
565 liquid_alternative_flowing = deSerializeString(is);
566 liquid_alternative_source = deSerializeString(is);
567 liquid_viscosity = readU8(is);
568 liquid_renewable = readU8(is);
569 liquid_range = readU8(is);
570 drowning = readU8(is);
571 floodable = readU8(is);
574 node_box.deSerialize(is);
575 selection_box.deSerialize(is);
576 collision_box.deSerialize(is);
579 sound_footstep.deSerialize(is, version);
580 sound_dig.deSerialize(is, version);
581 sound_dug.deSerialize(is, version);
583 // read legacy properties
584 legacy_facedir_simple = readU8(is);
585 legacy_wallmounted = readU8(is);
588 node_dig_prediction = deSerializeString(is);
589 } catch(SerializationError &e) {};
593 static void fillTileAttribs(ITextureSource *tsrc, TileLayer *layer,
594 const TileSpec &tile, const TileDef &tiledef, video::SColor color,
595 u8 material_type, u32 shader_id, bool backface_culling,
596 const TextureSettings &tsettings)
598 layer->shader_id = shader_id;
599 layer->texture = tsrc->getTextureForMesh(tiledef.name, &layer->texture_id);
600 layer->material_type = material_type;
602 bool has_scale = tiledef.scale > 0;
603 if (((tsettings.autoscale_mode == AUTOSCALE_ENABLE) && !has_scale) ||
604 (tsettings.autoscale_mode == AUTOSCALE_FORCE)) {
605 auto texture_size = layer->texture->getOriginalSize();
606 float base_size = tsettings.node_texture_size;
607 float size = std::fmin(texture_size.Width, texture_size.Height);
608 layer->scale = std::fmax(base_size, size) / base_size;
609 } else if (has_scale) {
610 layer->scale = tiledef.scale;
614 if (!tile.world_aligned)
617 // Normal texture and shader flags texture
618 if (tsettings.use_normal_texture) {
619 layer->normal_texture = tsrc->getNormalTexture(tiledef.name);
621 layer->flags_texture = tsrc->getShaderFlagsTexture(layer->normal_texture ? true : false);
624 layer->material_flags = 0;
625 if (backface_culling)
626 layer->material_flags |= MATERIAL_FLAG_BACKFACE_CULLING;
627 if (tiledef.animation.type != TAT_NONE)
628 layer->material_flags |= MATERIAL_FLAG_ANIMATION;
629 if (tiledef.tileable_horizontal)
630 layer->material_flags |= MATERIAL_FLAG_TILEABLE_HORIZONTAL;
631 if (tiledef.tileable_vertical)
632 layer->material_flags |= MATERIAL_FLAG_TILEABLE_VERTICAL;
635 layer->has_color = tiledef.has_color;
636 if (tiledef.has_color)
637 layer->color = tiledef.color;
639 layer->color = color;
641 // Animation parameters
643 if (layer->material_flags & MATERIAL_FLAG_ANIMATION) {
645 tiledef.animation.determineParams(layer->texture->getOriginalSize(),
646 &frame_count, &frame_length_ms, NULL);
647 layer->animation_frame_count = frame_count;
648 layer->animation_frame_length_ms = frame_length_ms;
651 if (frame_count == 1) {
652 layer->material_flags &= ~MATERIAL_FLAG_ANIMATION;
654 std::ostringstream os(std::ios::binary);
655 if (!layer->frames) {
656 layer->frames = std::make_shared<std::vector<FrameSpec>>();
658 layer->frames->resize(frame_count);
660 for (int i = 0; i < frame_count; i++) {
666 tiledef.animation.getTextureModifer(os,
667 layer->texture->getOriginalSize(), i);
669 frame.texture = tsrc->getTextureForMesh(os.str(), &frame.texture_id);
670 if (layer->normal_texture)
671 frame.normal_texture = tsrc->getNormalTexture(os.str());
672 frame.flags_texture = layer->flags_texture;
673 (*layer->frames)[i] = frame;
680 bool isWorldAligned(AlignStyle style, WorldAlignMode mode, NodeDrawType drawtype)
682 if (style == ALIGN_STYLE_WORLD)
684 if (mode == WORLDALIGN_DISABLE)
686 if (style == ALIGN_STYLE_USER_DEFINED)
688 if (drawtype == NDT_NORMAL)
689 return mode >= WORLDALIGN_FORCE;
690 if (drawtype == NDT_NODEBOX)
691 return mode >= WORLDALIGN_FORCE_NODEBOX;
695 void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc,
696 scene::IMeshManipulator *meshmanip, Client *client, const TextureSettings &tsettings)
698 // minimap pixel color - the average color of a texture
699 if (tsettings.enable_minimap && !tiledef[0].name.empty())
700 minimap_color = tsrc->getTextureAverageColor(tiledef[0].name);
702 // Figure out the actual tiles to use
704 for (u32 j = 0; j < 6; j++) {
705 tdef[j] = tiledef[j];
706 if (tdef[j].name.empty())
707 tdef[j].name = "unknown_node.png";
709 // also the overlay tiles
710 TileDef tdef_overlay[6];
711 for (u32 j = 0; j < 6; j++)
712 tdef_overlay[j] = tiledef_overlay[j];
713 // also the special tiles
714 TileDef tdef_spec[6];
715 for (u32 j = 0; j < CF_SPECIAL_COUNT; j++)
716 tdef_spec[j] = tiledef_special[j];
718 bool is_liquid = false;
720 u8 material_type = (alpha == 255) ?
721 TILE_MATERIAL_BASIC : TILE_MATERIAL_ALPHA;
726 material_type = (alpha == 255) ?
727 TILE_MATERIAL_OPAQUE : TILE_MATERIAL_ALPHA;
734 assert(liquid_type == LIQUID_SOURCE);
735 if (tsettings.opaque_water)
740 case NDT_FLOWINGLIQUID:
741 assert(liquid_type == LIQUID_FLOWING);
743 if (tsettings.opaque_water)
749 visual_solidness = 1;
751 case NDT_GLASSLIKE_FRAMED:
753 visual_solidness = 1;
755 case NDT_GLASSLIKE_FRAMED_OPTIONAL:
757 visual_solidness = 1;
758 drawtype = tsettings.connected_glass ? NDT_GLASSLIKE_FRAMED : NDT_GLASSLIKE;
762 visual_solidness = 1;
764 case NDT_ALLFACES_OPTIONAL:
765 if (tsettings.leaves_style == LEAVES_FANCY) {
766 drawtype = NDT_ALLFACES;
768 visual_solidness = 1;
769 } else if (tsettings.leaves_style == LEAVES_SIMPLE) {
770 for (u32 j = 0; j < 6; j++) {
771 if (!tdef_spec[j].name.empty())
772 tdef[j].name = tdef_spec[j].name;
774 drawtype = NDT_GLASSLIKE;
776 visual_solidness = 1;
778 drawtype = NDT_NORMAL;
780 for (TileDef &td : tdef)
781 td.name += std::string("^[noalpha");
784 material_type = TILE_MATERIAL_WAVING_LEAVES;
789 material_type = TILE_MATERIAL_WAVING_PLANTS;
798 material_type = TILE_MATERIAL_WAVING_PLANTS;
799 else if (waving == 2)
800 material_type = TILE_MATERIAL_WAVING_LEAVES;
808 case NDT_PLANTLIKE_ROOTED:
814 // Vertex alpha is no longer supported, correct if necessary.
815 correctAlpha(tdef, 6);
816 correctAlpha(tdef_overlay, 6);
817 correctAlpha(tdef_spec, CF_SPECIAL_COUNT);
818 material_type = (alpha == 255) ?
819 TILE_MATERIAL_LIQUID_OPAQUE : TILE_MATERIAL_LIQUID_TRANSPARENT;
822 u32 tile_shader = shdsrc->getShader("nodes_shader", material_type, drawtype);
824 u8 overlay_material = material_type;
825 if (overlay_material == TILE_MATERIAL_OPAQUE)
826 overlay_material = TILE_MATERIAL_BASIC;
827 else if (overlay_material == TILE_MATERIAL_LIQUID_OPAQUE)
828 overlay_material = TILE_MATERIAL_LIQUID_TRANSPARENT;
830 u32 overlay_shader = shdsrc->getShader("nodes_shader", overlay_material, drawtype);
832 // Tiles (fill in f->tiles[])
833 for (u16 j = 0; j < 6; j++) {
834 tiles[j].world_aligned = isWorldAligned(tdef[j].align_style,
835 tsettings.world_aligned_mode, drawtype);
836 fillTileAttribs(tsrc, &tiles[j].layers[0], tiles[j], tdef[j],
837 color, material_type, tile_shader,
838 tdef[j].backface_culling, tsettings);
839 if (!tdef_overlay[j].name.empty())
840 fillTileAttribs(tsrc, &tiles[j].layers[1], tiles[j], tdef_overlay[j],
841 color, overlay_material, overlay_shader,
842 tdef[j].backface_culling, tsettings);
845 u8 special_material = material_type;
846 if (drawtype == NDT_PLANTLIKE_ROOTED) {
848 special_material = TILE_MATERIAL_WAVING_PLANTS;
849 else if (waving == 2)
850 special_material = TILE_MATERIAL_WAVING_LEAVES;
852 u32 special_shader = shdsrc->getShader("nodes_shader", special_material, drawtype);
854 // Special tiles (fill in f->special_tiles[])
855 for (u16 j = 0; j < CF_SPECIAL_COUNT; j++)
856 fillTileAttribs(tsrc, &special_tiles[j].layers[0], special_tiles[j], tdef_spec[j],
857 color, special_material, special_shader,
858 tdef_spec[j].backface_culling, tsettings);
860 if (param_type_2 == CPT2_COLOR ||
861 param_type_2 == CPT2_COLORED_FACEDIR ||
862 param_type_2 == CPT2_COLORED_WALLMOUNTED)
863 palette = tsrc->getPalette(palette_name);
865 if (drawtype == NDT_MESH && !mesh.empty()) {
867 // Read the mesh and apply scale
868 mesh_ptr[0] = client->getMesh(mesh);
870 v3f scale = v3f(1.0, 1.0, 1.0) * BS * visual_scale;
871 scaleMesh(mesh_ptr[0], scale);
872 recalculateBoundingBox(mesh_ptr[0]);
873 meshmanip->recalculateNormals(mesh_ptr[0], true, false);
877 //Cache 6dfacedir and wallmounted rotated clones of meshes
878 if (tsettings.enable_mesh_cache && mesh_ptr[0] &&
879 (param_type_2 == CPT2_FACEDIR
880 || param_type_2 == CPT2_COLORED_FACEDIR)) {
881 for (u16 j = 1; j < 24; j++) {
882 mesh_ptr[j] = cloneMesh(mesh_ptr[0]);
883 rotateMeshBy6dFacedir(mesh_ptr[j], j);
884 recalculateBoundingBox(mesh_ptr[j]);
885 meshmanip->recalculateNormals(mesh_ptr[j], true, false);
887 } else if (tsettings.enable_mesh_cache && mesh_ptr[0]
888 && (param_type_2 == CPT2_WALLMOUNTED ||
889 param_type_2 == CPT2_COLORED_WALLMOUNTED)) {
890 static const u8 wm_to_6d[6] = { 20, 0, 16 + 1, 12 + 3, 8, 4 + 2 };
891 for (u16 j = 1; j < 6; j++) {
892 mesh_ptr[j] = cloneMesh(mesh_ptr[0]);
893 rotateMeshBy6dFacedir(mesh_ptr[j], wm_to_6d[j]);
894 recalculateBoundingBox(mesh_ptr[j]);
895 meshmanip->recalculateNormals(mesh_ptr[j], true, false);
897 rotateMeshBy6dFacedir(mesh_ptr[0], wm_to_6d[0]);
898 recalculateBoundingBox(mesh_ptr[0]);
899 meshmanip->recalculateNormals(mesh_ptr[0], true, false);
911 NodeDefManager::NodeDefManager()
917 NodeDefManager::~NodeDefManager()
920 for (ContentFeatures &f : m_content_features) {
921 for (auto &j : f.mesh_ptr) {
930 void NodeDefManager::clear()
932 m_content_features.clear();
933 m_name_id_mapping.clear();
934 m_name_id_mapping_with_aliases.clear();
935 m_group_to_items.clear();
937 m_selection_box_union.reset(0,0,0);
938 m_selection_box_int_union.reset(0,0,0);
940 resetNodeResolveState();
942 u32 initial_length = 0;
943 initial_length = MYMAX(initial_length, CONTENT_UNKNOWN + 1);
944 initial_length = MYMAX(initial_length, CONTENT_AIR + 1);
945 initial_length = MYMAX(initial_length, CONTENT_IGNORE + 1);
946 m_content_features.resize(initial_length);
948 // Set CONTENT_UNKNOWN
952 // Insert directly into containers
953 content_t c = CONTENT_UNKNOWN;
954 m_content_features[c] = f;
955 addNameIdMapping(c, f.name);
962 f.drawtype = NDT_AIRLIKE;
963 f.param_type = CPT_LIGHT;
964 f.light_propagates = true;
965 f.sunlight_propagates = true;
969 f.buildable_to = true;
971 f.is_ground_content = true;
972 // Insert directly into containers
973 content_t c = CONTENT_AIR;
974 m_content_features[c] = f;
975 addNameIdMapping(c, f.name);
978 // Set CONTENT_IGNORE
982 f.drawtype = NDT_AIRLIKE;
983 f.param_type = CPT_NONE;
984 f.light_propagates = false;
985 f.sunlight_propagates = false;
989 f.buildable_to = true; // A way to remove accidental CONTENT_IGNOREs
990 f.is_ground_content = true;
991 // Insert directly into containers
992 content_t c = CONTENT_IGNORE;
993 m_content_features[c] = f;
994 addNameIdMapping(c, f.name);
999 bool NodeDefManager::getId(const std::string &name, content_t &result) const
1001 std::unordered_map<std::string, content_t>::const_iterator
1002 i = m_name_id_mapping_with_aliases.find(name);
1003 if(i == m_name_id_mapping_with_aliases.end())
1010 content_t NodeDefManager::getId(const std::string &name) const
1012 content_t id = CONTENT_IGNORE;
1018 bool NodeDefManager::getIds(const std::string &name,
1019 std::vector<content_t> &result) const
1021 //TimeTaker t("getIds", NULL, PRECISION_MICRO);
1022 if (name.substr(0,6) != "group:") {
1023 content_t id = CONTENT_IGNORE;
1024 bool exists = getId(name, id);
1026 result.push_back(id);
1029 std::string group = name.substr(6);
1031 std::unordered_map<std::string, std::vector<content_t>>::const_iterator
1032 i = m_group_to_items.find(group);
1033 if (i == m_group_to_items.end())
1036 const std::vector<content_t> &items = i->second;
1037 result.insert(result.end(), items.begin(), items.end());
1038 //printf("getIds: %dus\n", t.stop());
1043 const ContentFeatures& NodeDefManager::get(const std::string &name) const
1045 content_t id = CONTENT_UNKNOWN;
1051 // returns CONTENT_IGNORE if no free ID found
1052 content_t NodeDefManager::allocateId()
1054 for (content_t id = m_next_id;
1055 id >= m_next_id; // overflow?
1057 while (id >= m_content_features.size()) {
1058 m_content_features.emplace_back();
1060 const ContentFeatures &f = m_content_features[id];
1061 if (f.name.empty()) {
1066 // If we arrive here, an overflow occurred in id.
1067 // That means no ID was found
1068 return CONTENT_IGNORE;
1073 * Returns the smallest box that contains all boxes
1074 * in the vector. Box_union is expanded.
1075 * @param[in] boxes the vector containing the boxes
1076 * @param[in, out] box_union the union of the arguments
1078 void boxVectorUnion(const std::vector<aabb3f> &boxes, aabb3f *box_union)
1080 for (const aabb3f &box : boxes) {
1081 box_union->addInternalBox(box);
1087 * Returns a box that contains the nodebox in every case.
1088 * The argument node_union is expanded.
1089 * @param[in] nodebox the nodebox to be measured
1090 * @param[in] features used to decide whether the nodebox
1092 * @param[in, out] box_union the union of the arguments
1094 void getNodeBoxUnion(const NodeBox &nodebox, const ContentFeatures &features,
1097 switch(nodebox.type) {
1099 case NODEBOX_LEVELED: {
1101 aabb3f half_processed(0, 0, 0, 0, 0, 0);
1102 boxVectorUnion(nodebox.fixed, &half_processed);
1103 // Set leveled boxes to maximal
1104 if (nodebox.type == NODEBOX_LEVELED) {
1105 half_processed.MaxEdge.Y = +BS / 2;
1107 if (features.param_type_2 == CPT2_FACEDIR ||
1108 features.param_type_2 == CPT2_COLORED_FACEDIR) {
1109 // Get maximal coordinate
1111 fabsf(half_processed.MinEdge.X),
1112 fabsf(half_processed.MinEdge.Y),
1113 fabsf(half_processed.MinEdge.Z),
1114 fabsf(half_processed.MaxEdge.X),
1115 fabsf(half_processed.MaxEdge.Y),
1116 fabsf(half_processed.MaxEdge.Z) };
1118 for (float coord : coords) {
1123 // Add the union of all possible rotated boxes
1124 box_union->addInternalPoint(-max, -max, -max);
1125 box_union->addInternalPoint(+max, +max, +max);
1127 box_union->addInternalBox(half_processed);
1131 case NODEBOX_WALLMOUNTED: {
1133 box_union->addInternalBox(nodebox.wall_top);
1134 box_union->addInternalBox(nodebox.wall_bottom);
1135 // Find maximal coordinate in the X-Z plane
1137 fabsf(nodebox.wall_side.MinEdge.X),
1138 fabsf(nodebox.wall_side.MinEdge.Z),
1139 fabsf(nodebox.wall_side.MaxEdge.X),
1140 fabsf(nodebox.wall_side.MaxEdge.Z) };
1142 for (float coord : coords) {
1147 // Add the union of all possible rotated boxes
1148 box_union->addInternalPoint(-max, nodebox.wall_side.MinEdge.Y, -max);
1149 box_union->addInternalPoint(max, nodebox.wall_side.MaxEdge.Y, max);
1152 case NODEBOX_CONNECTED: {
1153 // Add all possible connected boxes
1154 boxVectorUnion(nodebox.fixed, box_union);
1155 boxVectorUnion(nodebox.connect_top, box_union);
1156 boxVectorUnion(nodebox.connect_bottom, box_union);
1157 boxVectorUnion(nodebox.connect_front, box_union);
1158 boxVectorUnion(nodebox.connect_left, box_union);
1159 boxVectorUnion(nodebox.connect_back, box_union);
1160 boxVectorUnion(nodebox.connect_right, box_union);
1161 boxVectorUnion(nodebox.disconnected_top, box_union);
1162 boxVectorUnion(nodebox.disconnected_bottom, box_union);
1163 boxVectorUnion(nodebox.disconnected_front, box_union);
1164 boxVectorUnion(nodebox.disconnected_left, box_union);
1165 boxVectorUnion(nodebox.disconnected_back, box_union);
1166 boxVectorUnion(nodebox.disconnected_right, box_union);
1167 boxVectorUnion(nodebox.disconnected, box_union);
1168 boxVectorUnion(nodebox.disconnected_sides, box_union);
1173 box_union->addInternalPoint(-BS / 2, -BS / 2, -BS / 2);
1174 box_union->addInternalPoint(+BS / 2, +BS / 2, +BS / 2);
1180 inline void NodeDefManager::fixSelectionBoxIntUnion()
1182 m_selection_box_int_union.MinEdge.X = floorf(
1183 m_selection_box_union.MinEdge.X / BS + 0.5f);
1184 m_selection_box_int_union.MinEdge.Y = floorf(
1185 m_selection_box_union.MinEdge.Y / BS + 0.5f);
1186 m_selection_box_int_union.MinEdge.Z = floorf(
1187 m_selection_box_union.MinEdge.Z / BS + 0.5f);
1188 m_selection_box_int_union.MaxEdge.X = ceilf(
1189 m_selection_box_union.MaxEdge.X / BS - 0.5f);
1190 m_selection_box_int_union.MaxEdge.Y = ceilf(
1191 m_selection_box_union.MaxEdge.Y / BS - 0.5f);
1192 m_selection_box_int_union.MaxEdge.Z = ceilf(
1193 m_selection_box_union.MaxEdge.Z / BS - 0.5f);
1197 // IWritableNodeDefManager
1198 content_t NodeDefManager::set(const std::string &name, const ContentFeatures &def)
1202 assert(name != "ignore");
1203 assert(name == def.name);
1205 content_t id = CONTENT_IGNORE;
1206 if (!m_name_id_mapping.getId(name, id)) { // ignore aliases
1209 if (id == CONTENT_IGNORE) {
1210 warningstream << "NodeDefManager: Absolute "
1211 "limit reached" << std::endl;
1212 return CONTENT_IGNORE;
1214 assert(id != CONTENT_IGNORE);
1215 addNameIdMapping(id, name);
1217 m_content_features[id] = def;
1218 verbosestream << "NodeDefManager: registering content id \"" << id
1219 << "\": name=\"" << def.name << "\""<<std::endl;
1221 getNodeBoxUnion(def.selection_box, def, &m_selection_box_union);
1222 fixSelectionBoxIntUnion();
1223 // Add this content to the list of all groups it belongs to
1224 // FIXME: This should remove a node from groups it no longer
1225 // belongs to when a node is re-registered
1226 for (const auto &group : def.groups) {
1227 const std::string &group_name = group.first;
1228 m_group_to_items[group_name].push_back(id);
1234 content_t NodeDefManager::allocateDummy(const std::string &name)
1236 assert(name != ""); // Pre-condition
1239 return set(name, f);
1243 void NodeDefManager::removeNode(const std::string &name)
1248 // Erase name from name ID mapping
1249 content_t id = CONTENT_IGNORE;
1250 if (m_name_id_mapping.getId(name, id)) {
1251 m_name_id_mapping.eraseName(name);
1252 m_name_id_mapping_with_aliases.erase(name);
1255 // Erase node content from all groups it belongs to
1256 for (std::unordered_map<std::string, std::vector<content_t>>::iterator iter_groups =
1257 m_group_to_items.begin(); iter_groups != m_group_to_items.end();) {
1258 std::vector<content_t> &items = iter_groups->second;
1259 items.erase(std::remove(items.begin(), items.end(), id), items.end());
1261 // Check if group is empty
1263 m_group_to_items.erase(iter_groups++);
1270 void NodeDefManager::updateAliases(IItemDefManager *idef)
1272 std::set<std::string> all;
1274 m_name_id_mapping_with_aliases.clear();
1275 for (const std::string &name : all) {
1276 const std::string &convert_to = idef->getAlias(name);
1278 if (m_name_id_mapping.getId(convert_to, id)) {
1279 m_name_id_mapping_with_aliases.insert(
1280 std::make_pair(name, id));
1285 void NodeDefManager::applyTextureOverrides(const std::string &override_filepath)
1287 infostream << "NodeDefManager::applyTextureOverrides(): Applying "
1288 "overrides to textures from " << override_filepath << std::endl;
1290 std::ifstream infile(override_filepath.c_str());
1293 while (std::getline(infile, line)) {
1295 if (trim(line).empty())
1297 std::vector<std::string> splitted = str_split(line, ' ');
1298 if (splitted.size() != 3) {
1299 errorstream << override_filepath
1300 << ":" << line_c << " Could not apply texture override \""
1301 << line << "\": Syntax error" << std::endl;
1306 if (!getId(splitted[0], id))
1307 continue; // Ignore unknown node
1309 ContentFeatures &nodedef = m_content_features[id];
1311 if (splitted[1] == "top")
1312 nodedef.tiledef[0].name = splitted[2];
1313 else if (splitted[1] == "bottom")
1314 nodedef.tiledef[1].name = splitted[2];
1315 else if (splitted[1] == "right")
1316 nodedef.tiledef[2].name = splitted[2];
1317 else if (splitted[1] == "left")
1318 nodedef.tiledef[3].name = splitted[2];
1319 else if (splitted[1] == "back")
1320 nodedef.tiledef[4].name = splitted[2];
1321 else if (splitted[1] == "front")
1322 nodedef.tiledef[5].name = splitted[2];
1323 else if (splitted[1] == "all" || splitted[1] == "*")
1324 for (TileDef &i : nodedef.tiledef)
1325 i.name = splitted[2];
1326 else if (splitted[1] == "sides")
1327 for (int i = 2; i < 6; i++)
1328 nodedef.tiledef[i].name = splitted[2];
1330 errorstream << override_filepath
1331 << ":" << line_c << " Could not apply texture override \""
1332 << line << "\": Unknown node side \""
1333 << splitted[1] << "\"" << std::endl;
1339 void NodeDefManager::updateTextures(IGameDef *gamedef,
1340 void (*progress_callback)(void *progress_args, u32 progress, u32 max_progress),
1341 void *progress_callback_args)
1344 infostream << "NodeDefManager::updateTextures(): Updating "
1345 "textures in node definitions" << std::endl;
1347 Client *client = (Client *)gamedef;
1348 ITextureSource *tsrc = client->tsrc();
1349 IShaderSource *shdsrc = client->getShaderSource();
1350 scene::IMeshManipulator *meshmanip =
1351 RenderingEngine::get_scene_manager()->getMeshManipulator();
1352 TextureSettings tsettings;
1353 tsettings.readSettings();
1355 u32 size = m_content_features.size();
1357 for (u32 i = 0; i < size; i++) {
1358 ContentFeatures *f = &(m_content_features[i]);
1359 f->updateTextures(tsrc, shdsrc, meshmanip, client, tsettings);
1360 progress_callback(progress_callback_args, i, size);
1365 void NodeDefManager::serialize(std::ostream &os, u16 protocol_version) const
1367 writeU8(os, 1); // version
1369 std::ostringstream os2(std::ios::binary);
1370 for (u32 i = 0; i < m_content_features.size(); i++) {
1371 if (i == CONTENT_IGNORE || i == CONTENT_AIR
1372 || i == CONTENT_UNKNOWN)
1374 const ContentFeatures *f = &m_content_features[i];
1375 if (f->name.empty())
1378 // Wrap it in a string to allow different lengths without
1379 // strict version incompatibilities
1380 std::ostringstream wrapper_os(std::ios::binary);
1381 f->serialize(wrapper_os, protocol_version);
1382 os2<<serializeString(wrapper_os.str());
1384 // must not overflow
1385 u16 next = count + 1;
1386 FATAL_ERROR_IF(next < count, "Overflow");
1389 writeU16(os, count);
1390 os << serializeLongString(os2.str());
1394 void NodeDefManager::deSerialize(std::istream &is)
1397 int version = readU8(is);
1399 throw SerializationError("unsupported NodeDefinitionManager version");
1400 u16 count = readU16(is);
1401 std::istringstream is2(deSerializeLongString(is), std::ios::binary);
1403 for (u16 n = 0; n < count; n++) {
1404 u16 i = readU16(is2);
1406 // Read it from the string wrapper
1407 std::string wrapper = deSerializeString(is2);
1408 std::istringstream wrapper_is(wrapper, std::ios::binary);
1409 f.deSerialize(wrapper_is);
1411 // Check error conditions
1412 if (i == CONTENT_IGNORE || i == CONTENT_AIR || i == CONTENT_UNKNOWN) {
1413 warningstream << "NodeDefManager::deSerialize(): "
1414 "not changing builtin node " << i << std::endl;
1417 if (f.name.empty()) {
1418 warningstream << "NodeDefManager::deSerialize(): "
1419 "received empty name" << std::endl;
1425 if (m_name_id_mapping.getId(f.name, existing_id) && i != existing_id) {
1426 warningstream << "NodeDefManager::deSerialize(): "
1427 "already defined with different ID: " << f.name << std::endl;
1431 // All is ok, add node definition with the requested ID
1432 if (i >= m_content_features.size())
1433 m_content_features.resize((u32)(i) + 1);
1434 m_content_features[i] = f;
1435 addNameIdMapping(i, f.name);
1436 verbosestream << "deserialized " << f.name << std::endl;
1438 getNodeBoxUnion(f.selection_box, f, &m_selection_box_union);
1439 fixSelectionBoxIntUnion();
1444 void NodeDefManager::addNameIdMapping(content_t i, std::string name)
1446 m_name_id_mapping.set(i, name);
1447 m_name_id_mapping_with_aliases.insert(std::make_pair(name, i));
1451 NodeDefManager *createNodeDefManager()
1453 return new NodeDefManager();
1457 void NodeDefManager::pendNodeResolve(NodeResolver *nr) const
1460 if (m_node_registration_complete)
1461 nr->nodeResolveInternal();
1463 m_pending_resolve_callbacks.push_back(nr);
1467 bool NodeDefManager::cancelNodeResolveCallback(NodeResolver *nr) const
1469 size_t len = m_pending_resolve_callbacks.size();
1470 for (size_t i = 0; i != len; i++) {
1471 if (nr != m_pending_resolve_callbacks[i])
1475 m_pending_resolve_callbacks[i] = m_pending_resolve_callbacks[len];
1476 m_pending_resolve_callbacks.resize(len);
1484 void NodeDefManager::runNodeResolveCallbacks()
1486 for (size_t i = 0; i != m_pending_resolve_callbacks.size(); i++) {
1487 NodeResolver *nr = m_pending_resolve_callbacks[i];
1488 nr->nodeResolveInternal();
1491 m_pending_resolve_callbacks.clear();
1495 void NodeDefManager::resetNodeResolveState()
1497 m_node_registration_complete = false;
1498 m_pending_resolve_callbacks.clear();
1501 void NodeDefManager::mapNodeboxConnections()
1503 for (ContentFeatures &f : m_content_features) {
1504 if (f.drawtype != NDT_NODEBOX || f.node_box.type != NODEBOX_CONNECTED)
1507 for (const std::string &name : f.connects_to) {
1508 getIds(name, f.connects_to_ids);
1513 bool NodeDefManager::nodeboxConnects(MapNode from, MapNode to,
1514 u8 connect_face) const
1516 const ContentFeatures &f1 = get(from);
1518 if ((f1.drawtype != NDT_NODEBOX) || (f1.node_box.type != NODEBOX_CONNECTED))
1521 // lookup target in connected set
1522 if (!CONTAINS(f1.connects_to_ids, to.param0))
1525 const ContentFeatures &f2 = get(to);
1527 if ((f2.drawtype == NDT_NODEBOX) && (f2.node_box.type == NODEBOX_CONNECTED))
1528 // ignores actually looking if back connection exists
1529 return CONTAINS(f2.connects_to_ids, from.param0);
1531 // does to node declare usable faces?
1532 if (f2.connect_sides > 0) {
1533 if ((f2.param_type_2 == CPT2_FACEDIR ||
1534 f2.param_type_2 == CPT2_COLORED_FACEDIR)
1535 && (connect_face >= 4)) {
1536 static const u8 rot[33 * 4] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1537 0, 0, 0, 0, 4, 32, 16, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1539 8, 4, 32, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1541 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 8, 4, 32, 0,
1542 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1544 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1545 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1546 0, 0, 0, 0, 0, 0, 32, 16, 8, 4 // 32 - left
1548 return (f2.connect_sides
1549 & rot[(connect_face * 4) + (to.param2 & 0x1F)]);
1551 return (f2.connect_sides & connect_face);
1553 // the target is just a regular node, so connect no matter back connection
1561 NodeResolver::NodeResolver()
1563 m_nodenames.reserve(16);
1564 m_nnlistsizes.reserve(4);
1568 NodeResolver::~NodeResolver()
1570 if (!m_resolve_done && m_ndef)
1571 m_ndef->cancelNodeResolveCallback(this);
1575 void NodeResolver::nodeResolveInternal()
1577 m_nodenames_idx = 0;
1578 m_nnlistsizes_idx = 0;
1581 m_resolve_done = true;
1583 m_nodenames.clear();
1584 m_nnlistsizes.clear();
1588 bool NodeResolver::getIdFromNrBacklog(content_t *result_out,
1589 const std::string &node_alt, content_t c_fallback, bool error_on_fallback)
1591 if (m_nodenames_idx == m_nodenames.size()) {
1592 *result_out = c_fallback;
1593 errorstream << "NodeResolver: no more nodes in list" << std::endl;
1598 std::string name = m_nodenames[m_nodenames_idx++];
1600 bool success = m_ndef->getId(name, c);
1601 if (!success && !node_alt.empty()) {
1603 success = m_ndef->getId(name, c);
1607 if (error_on_fallback)
1608 errorstream << "NodeResolver: failed to resolve node name '" << name
1609 << "'." << std::endl;
1618 bool NodeResolver::getIdsFromNrBacklog(std::vector<content_t> *result_out,
1619 bool all_required, content_t c_fallback)
1621 bool success = true;
1623 if (m_nnlistsizes_idx == m_nnlistsizes.size()) {
1624 errorstream << "NodeResolver: no more node lists" << std::endl;
1628 size_t length = m_nnlistsizes[m_nnlistsizes_idx++];
1631 if (m_nodenames_idx == m_nodenames.size()) {
1632 errorstream << "NodeResolver: no more nodes in list" << std::endl;
1637 std::string &name = m_nodenames[m_nodenames_idx++];
1639 if (name.substr(0,6) != "group:") {
1640 if (m_ndef->getId(name, c)) {
1641 result_out->push_back(c);
1642 } else if (all_required) {
1643 errorstream << "NodeResolver: failed to resolve node name '"
1644 << name << "'." << std::endl;
1645 result_out->push_back(c_fallback);
1649 m_ndef->getIds(name, *result_out);