nodedef.cpp 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793
  1. /*
  2. Minetest
  3. Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #include "nodedef.h"
  17. #include "itemdef.h"
  18. #ifndef SERVER
  19. #include "client/mesh.h"
  20. #include "client/shader.h"
  21. #include "client/client.h"
  22. #include "client/renderingengine.h"
  23. #include "client/tile.h"
  24. #include <IMeshManipulator.h>
  25. #endif
  26. #include "log.h"
  27. #include "settings.h"
  28. #include "nameidmapping.h"
  29. #include "util/numeric.h"
  30. #include "util/serialize.h"
  31. #include "exceptions.h"
  32. #include "debug.h"
  33. #include "gamedef.h"
  34. #include "mapnode.h"
  35. #include <fstream> // Used in applyTextureOverrides()
  36. #include <algorithm>
  37. #include <cmath>
  38. /*
  39. NodeBox
  40. */
  41. void NodeBox::reset()
  42. {
  43. type = NODEBOX_REGULAR;
  44. // default is empty
  45. fixed.clear();
  46. // default is sign/ladder-like
  47. wall_top = aabb3f(-BS/2, BS/2-BS/16., -BS/2, BS/2, BS/2, BS/2);
  48. wall_bottom = aabb3f(-BS/2, -BS/2, -BS/2, BS/2, -BS/2+BS/16., BS/2);
  49. wall_side = aabb3f(-BS/2, -BS/2, -BS/2, -BS/2+BS/16., BS/2, BS/2);
  50. // no default for other parts
  51. connect_top.clear();
  52. connect_bottom.clear();
  53. connect_front.clear();
  54. connect_left.clear();
  55. connect_back.clear();
  56. connect_right.clear();
  57. disconnected_top.clear();
  58. disconnected_bottom.clear();
  59. disconnected_front.clear();
  60. disconnected_left.clear();
  61. disconnected_back.clear();
  62. disconnected_right.clear();
  63. disconnected.clear();
  64. disconnected_sides.clear();
  65. }
  66. void NodeBox::serialize(std::ostream &os, u16 protocol_version) const
  67. {
  68. // Protocol >= 36
  69. const u8 version = 6;
  70. writeU8(os, version);
  71. switch (type) {
  72. case NODEBOX_LEVELED:
  73. case NODEBOX_FIXED:
  74. writeU8(os, type);
  75. writeU16(os, fixed.size());
  76. for (const aabb3f &nodebox : fixed) {
  77. writeV3F32(os, nodebox.MinEdge);
  78. writeV3F32(os, nodebox.MaxEdge);
  79. }
  80. break;
  81. case NODEBOX_WALLMOUNTED:
  82. writeU8(os, type);
  83. writeV3F32(os, wall_top.MinEdge);
  84. writeV3F32(os, wall_top.MaxEdge);
  85. writeV3F32(os, wall_bottom.MinEdge);
  86. writeV3F32(os, wall_bottom.MaxEdge);
  87. writeV3F32(os, wall_side.MinEdge);
  88. writeV3F32(os, wall_side.MaxEdge);
  89. break;
  90. case NODEBOX_CONNECTED:
  91. writeU8(os, type);
  92. #define WRITEBOX(box) \
  93. writeU16(os, (box).size()); \
  94. for (const aabb3f &i: (box)) { \
  95. writeV3F32(os, i.MinEdge); \
  96. writeV3F32(os, i.MaxEdge); \
  97. };
  98. WRITEBOX(fixed);
  99. WRITEBOX(connect_top);
  100. WRITEBOX(connect_bottom);
  101. WRITEBOX(connect_front);
  102. WRITEBOX(connect_left);
  103. WRITEBOX(connect_back);
  104. WRITEBOX(connect_right);
  105. WRITEBOX(disconnected_top);
  106. WRITEBOX(disconnected_bottom);
  107. WRITEBOX(disconnected_front);
  108. WRITEBOX(disconnected_left);
  109. WRITEBOX(disconnected_back);
  110. WRITEBOX(disconnected_right);
  111. WRITEBOX(disconnected);
  112. WRITEBOX(disconnected_sides);
  113. break;
  114. default:
  115. writeU8(os, type);
  116. break;
  117. }
  118. }
  119. void NodeBox::deSerialize(std::istream &is)
  120. {
  121. int version = readU8(is);
  122. if (version < 6)
  123. throw SerializationError("unsupported NodeBox version");
  124. reset();
  125. type = (enum NodeBoxType)readU8(is);
  126. if(type == NODEBOX_FIXED || type == NODEBOX_LEVELED)
  127. {
  128. u16 fixed_count = readU16(is);
  129. while(fixed_count--)
  130. {
  131. aabb3f box;
  132. box.MinEdge = readV3F32(is);
  133. box.MaxEdge = readV3F32(is);
  134. fixed.push_back(box);
  135. }
  136. }
  137. else if(type == NODEBOX_WALLMOUNTED)
  138. {
  139. wall_top.MinEdge = readV3F32(is);
  140. wall_top.MaxEdge = readV3F32(is);
  141. wall_bottom.MinEdge = readV3F32(is);
  142. wall_bottom.MaxEdge = readV3F32(is);
  143. wall_side.MinEdge = readV3F32(is);
  144. wall_side.MaxEdge = readV3F32(is);
  145. }
  146. else if (type == NODEBOX_CONNECTED)
  147. {
  148. #define READBOXES(box) { \
  149. count = readU16(is); \
  150. (box).reserve(count); \
  151. while (count--) { \
  152. v3f min = readV3F32(is); \
  153. v3f max = readV3F32(is); \
  154. (box).emplace_back(min, max); }; }
  155. u16 count;
  156. READBOXES(fixed);
  157. READBOXES(connect_top);
  158. READBOXES(connect_bottom);
  159. READBOXES(connect_front);
  160. READBOXES(connect_left);
  161. READBOXES(connect_back);
  162. READBOXES(connect_right);
  163. READBOXES(disconnected_top);
  164. READBOXES(disconnected_bottom);
  165. READBOXES(disconnected_front);
  166. READBOXES(disconnected_left);
  167. READBOXES(disconnected_back);
  168. READBOXES(disconnected_right);
  169. READBOXES(disconnected);
  170. READBOXES(disconnected_sides);
  171. }
  172. }
  173. /*
  174. TileDef
  175. */
  176. #define TILE_FLAG_BACKFACE_CULLING (1 << 0)
  177. #define TILE_FLAG_TILEABLE_HORIZONTAL (1 << 1)
  178. #define TILE_FLAG_TILEABLE_VERTICAL (1 << 2)
  179. #define TILE_FLAG_HAS_COLOR (1 << 3)
  180. #define TILE_FLAG_HAS_SCALE (1 << 4)
  181. #define TILE_FLAG_HAS_ALIGN_STYLE (1 << 5)
  182. void TileDef::serialize(std::ostream &os, u16 protocol_version) const
  183. {
  184. // protocol_version >= 36
  185. u8 version = 6;
  186. writeU8(os, version);
  187. os << serializeString16(name);
  188. animation.serialize(os, version);
  189. bool has_scale = scale > 0;
  190. u16 flags = 0;
  191. if (backface_culling)
  192. flags |= TILE_FLAG_BACKFACE_CULLING;
  193. if (tileable_horizontal)
  194. flags |= TILE_FLAG_TILEABLE_HORIZONTAL;
  195. if (tileable_vertical)
  196. flags |= TILE_FLAG_TILEABLE_VERTICAL;
  197. if (has_color)
  198. flags |= TILE_FLAG_HAS_COLOR;
  199. if (has_scale)
  200. flags |= TILE_FLAG_HAS_SCALE;
  201. if (align_style != ALIGN_STYLE_NODE)
  202. flags |= TILE_FLAG_HAS_ALIGN_STYLE;
  203. writeU16(os, flags);
  204. if (has_color) {
  205. writeU8(os, color.getRed());
  206. writeU8(os, color.getGreen());
  207. writeU8(os, color.getBlue());
  208. }
  209. if (has_scale)
  210. writeU8(os, scale);
  211. if (align_style != ALIGN_STYLE_NODE)
  212. writeU8(os, align_style);
  213. }
  214. void TileDef::deSerialize(std::istream &is, u8 contentfeatures_version,
  215. NodeDrawType drawtype)
  216. {
  217. int version = readU8(is);
  218. if (version < 6)
  219. throw SerializationError("unsupported TileDef version");
  220. name = deSerializeString16(is);
  221. animation.deSerialize(is, version);
  222. u16 flags = readU16(is);
  223. backface_culling = flags & TILE_FLAG_BACKFACE_CULLING;
  224. tileable_horizontal = flags & TILE_FLAG_TILEABLE_HORIZONTAL;
  225. tileable_vertical = flags & TILE_FLAG_TILEABLE_VERTICAL;
  226. has_color = flags & TILE_FLAG_HAS_COLOR;
  227. bool has_scale = flags & TILE_FLAG_HAS_SCALE;
  228. bool has_align_style = flags & TILE_FLAG_HAS_ALIGN_STYLE;
  229. if (has_color) {
  230. color.setRed(readU8(is));
  231. color.setGreen(readU8(is));
  232. color.setBlue(readU8(is));
  233. }
  234. scale = has_scale ? readU8(is) : 0;
  235. if (has_align_style)
  236. align_style = static_cast<AlignStyle>(readU8(is));
  237. else
  238. align_style = ALIGN_STYLE_NODE;
  239. }
  240. void TextureSettings::readSettings()
  241. {
  242. connected_glass = g_settings->getBool("connected_glass");
  243. opaque_water = g_settings->getBool("opaque_water");
  244. bool smooth_lighting = g_settings->getBool("smooth_lighting");
  245. enable_mesh_cache = g_settings->getBool("enable_mesh_cache");
  246. enable_minimap = g_settings->getBool("enable_minimap");
  247. node_texture_size = g_settings->getU16("texture_min_size");
  248. std::string leaves_style_str = g_settings->get("leaves_style");
  249. std::string world_aligned_mode_str = g_settings->get("world_aligned_mode");
  250. std::string autoscale_mode_str = g_settings->get("autoscale_mode");
  251. // Mesh cache is not supported in combination with smooth lighting
  252. if (smooth_lighting)
  253. enable_mesh_cache = false;
  254. if (leaves_style_str == "fancy") {
  255. leaves_style = LEAVES_FANCY;
  256. } else if (leaves_style_str == "simple") {
  257. leaves_style = LEAVES_SIMPLE;
  258. } else {
  259. leaves_style = LEAVES_OPAQUE;
  260. }
  261. if (world_aligned_mode_str == "enable")
  262. world_aligned_mode = WORLDALIGN_ENABLE;
  263. else if (world_aligned_mode_str == "force_solid")
  264. world_aligned_mode = WORLDALIGN_FORCE;
  265. else if (world_aligned_mode_str == "force_nodebox")
  266. world_aligned_mode = WORLDALIGN_FORCE_NODEBOX;
  267. else
  268. world_aligned_mode = WORLDALIGN_DISABLE;
  269. if (autoscale_mode_str == "enable")
  270. autoscale_mode = AUTOSCALE_ENABLE;
  271. else if (autoscale_mode_str == "force")
  272. autoscale_mode = AUTOSCALE_FORCE;
  273. else
  274. autoscale_mode = AUTOSCALE_DISABLE;
  275. }
  276. /*
  277. ContentFeatures
  278. */
  279. ContentFeatures::ContentFeatures()
  280. {
  281. reset();
  282. }
  283. ContentFeatures::~ContentFeatures()
  284. {
  285. #ifndef SERVER
  286. for (u16 j = 0; j < 6; j++) {
  287. delete tiles[j].layers[0].frames;
  288. delete tiles[j].layers[1].frames;
  289. }
  290. for (u16 j = 0; j < CF_SPECIAL_COUNT; j++)
  291. delete special_tiles[j].layers[0].frames;
  292. #endif
  293. }
  294. void ContentFeatures::reset()
  295. {
  296. /*
  297. Cached stuff
  298. */
  299. #ifndef SERVER
  300. solidness = 2;
  301. visual_solidness = 0;
  302. backface_culling = true;
  303. #endif
  304. has_on_construct = false;
  305. has_on_destruct = false;
  306. has_after_destruct = false;
  307. /*
  308. Actual data
  309. NOTE: Most of this is always overridden by the default values given
  310. in builtin.lua
  311. */
  312. name = "";
  313. groups.clear();
  314. // Unknown nodes can be dug
  315. groups["dig_immediate"] = 2;
  316. drawtype = NDT_NORMAL;
  317. mesh = "";
  318. #ifndef SERVER
  319. for (auto &i : mesh_ptr)
  320. i = NULL;
  321. minimap_color = video::SColor(0, 0, 0, 0);
  322. #endif
  323. visual_scale = 1.0;
  324. for (auto &i : tiledef)
  325. i = TileDef();
  326. for (auto &j : tiledef_special)
  327. j = TileDef();
  328. alpha = ALPHAMODE_OPAQUE;
  329. post_effect_color = video::SColor(0, 0, 0, 0);
  330. param_type = CPT_NONE;
  331. param_type_2 = CPT2_NONE;
  332. is_ground_content = false;
  333. light_propagates = false;
  334. sunlight_propagates = false;
  335. walkable = true;
  336. pointable = true;
  337. diggable = true;
  338. climbable = false;
  339. buildable_to = false;
  340. floodable = false;
  341. rightclickable = true;
  342. leveled = 0;
  343. leveled_max = LEVELED_MAX;
  344. liquid_type = LIQUID_NONE;
  345. liquid_alternative_flowing = "";
  346. liquid_alternative_flowing_id = CONTENT_IGNORE;
  347. liquid_alternative_source = "";
  348. liquid_alternative_source_id = CONTENT_IGNORE;
  349. liquid_viscosity = 0;
  350. liquid_renewable = true;
  351. liquid_range = LIQUID_LEVEL_MAX+1;
  352. drowning = 0;
  353. light_source = 0;
  354. damage_per_second = 0;
  355. node_box = NodeBox();
  356. selection_box = NodeBox();
  357. collision_box = NodeBox();
  358. waving = 0;
  359. legacy_facedir_simple = false;
  360. legacy_wallmounted = false;
  361. sound_footstep = SimpleSoundSpec();
  362. sound_dig = SimpleSoundSpec("__group");
  363. sound_dug = SimpleSoundSpec();
  364. connects_to.clear();
  365. connects_to_ids.clear();
  366. connect_sides = 0;
  367. color = video::SColor(0xFFFFFFFF);
  368. palette_name = "";
  369. palette = NULL;
  370. node_dig_prediction = "air";
  371. }
  372. void ContentFeatures::setAlphaFromLegacy(u8 legacy_alpha)
  373. {
  374. // No special handling for nodebox/mesh here as it doesn't make sense to
  375. // throw warnings when the server is too old to support the "correct" way
  376. switch (drawtype) {
  377. case NDT_NORMAL:
  378. alpha = legacy_alpha == 255 ? ALPHAMODE_OPAQUE : ALPHAMODE_CLIP;
  379. break;
  380. case NDT_LIQUID:
  381. case NDT_FLOWINGLIQUID:
  382. alpha = legacy_alpha == 255 ? ALPHAMODE_OPAQUE : ALPHAMODE_BLEND;
  383. break;
  384. default:
  385. alpha = legacy_alpha == 255 ? ALPHAMODE_CLIP : ALPHAMODE_BLEND;
  386. break;
  387. }
  388. }
  389. u8 ContentFeatures::getAlphaForLegacy() const
  390. {
  391. // This is so simple only because 255 and 0 mean wildly different things
  392. // depending on drawtype...
  393. return alpha == ALPHAMODE_OPAQUE ? 255 : 0;
  394. }
  395. void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const
  396. {
  397. const u8 version = CONTENTFEATURES_VERSION;
  398. writeU8(os, version);
  399. // general
  400. os << serializeString16(name);
  401. writeU16(os, groups.size());
  402. for (const auto &group : groups) {
  403. os << serializeString16(group.first);
  404. writeS16(os, group.second);
  405. }
  406. writeU8(os, param_type);
  407. writeU8(os, param_type_2);
  408. // visual
  409. writeU8(os, drawtype);
  410. os << serializeString16(mesh);
  411. writeF32(os, visual_scale);
  412. writeU8(os, 6);
  413. for (const TileDef &td : tiledef)
  414. td.serialize(os, protocol_version);
  415. for (const TileDef &td : tiledef_overlay)
  416. td.serialize(os, protocol_version);
  417. writeU8(os, CF_SPECIAL_COUNT);
  418. for (const TileDef &td : tiledef_special) {
  419. td.serialize(os, protocol_version);
  420. }
  421. writeU8(os, getAlphaForLegacy());
  422. writeU8(os, color.getRed());
  423. writeU8(os, color.getGreen());
  424. writeU8(os, color.getBlue());
  425. os << serializeString16(palette_name);
  426. writeU8(os, waving);
  427. writeU8(os, connect_sides);
  428. writeU16(os, connects_to_ids.size());
  429. for (u16 connects_to_id : connects_to_ids)
  430. writeU16(os, connects_to_id);
  431. writeARGB8(os, post_effect_color);
  432. writeU8(os, leveled);
  433. // lighting
  434. writeU8(os, light_propagates);
  435. writeU8(os, sunlight_propagates);
  436. writeU8(os, light_source);
  437. // map generation
  438. writeU8(os, is_ground_content);
  439. // interaction
  440. writeU8(os, walkable);
  441. writeU8(os, pointable);
  442. writeU8(os, diggable);
  443. writeU8(os, climbable);
  444. writeU8(os, buildable_to);
  445. writeU8(os, rightclickable);
  446. writeU32(os, damage_per_second);
  447. // liquid
  448. writeU8(os, liquid_type);
  449. os << serializeString16(liquid_alternative_flowing);
  450. os << serializeString16(liquid_alternative_source);
  451. writeU8(os, liquid_viscosity);
  452. writeU8(os, liquid_renewable);
  453. writeU8(os, liquid_range);
  454. writeU8(os, drowning);
  455. writeU8(os, floodable);
  456. // node boxes
  457. node_box.serialize(os, protocol_version);
  458. selection_box.serialize(os, protocol_version);
  459. collision_box.serialize(os, protocol_version);
  460. // sound
  461. sound_footstep.serialize(os, version);
  462. sound_dig.serialize(os, version);
  463. sound_dug.serialize(os, version);
  464. // legacy
  465. writeU8(os, legacy_facedir_simple);
  466. writeU8(os, legacy_wallmounted);
  467. os << serializeString16(node_dig_prediction);
  468. writeU8(os, leveled_max);
  469. writeU8(os, alpha);
  470. }
  471. void ContentFeatures::deSerialize(std::istream &is)
  472. {
  473. // version detection
  474. const u8 version = readU8(is);
  475. if (version < CONTENTFEATURES_VERSION)
  476. throw SerializationError("unsupported ContentFeatures version");
  477. // general
  478. name = deSerializeString16(is);
  479. groups.clear();
  480. u32 groups_size = readU16(is);
  481. for (u32 i = 0; i < groups_size; i++) {
  482. std::string name = deSerializeString16(is);
  483. int value = readS16(is);
  484. groups[name] = value;
  485. }
  486. param_type = (enum ContentParamType) readU8(is);
  487. param_type_2 = (enum ContentParamType2) readU8(is);
  488. // visual
  489. drawtype = (enum NodeDrawType) readU8(is);
  490. mesh = deSerializeString16(is);
  491. visual_scale = readF32(is);
  492. if (readU8(is) != 6)
  493. throw SerializationError("unsupported tile count");
  494. for (TileDef &td : tiledef)
  495. td.deSerialize(is, version, drawtype);
  496. for (TileDef &td : tiledef_overlay)
  497. td.deSerialize(is, version, drawtype);
  498. if (readU8(is) != CF_SPECIAL_COUNT)
  499. throw SerializationError("unsupported CF_SPECIAL_COUNT");
  500. for (TileDef &td : tiledef_special)
  501. td.deSerialize(is, version, drawtype);
  502. setAlphaFromLegacy(readU8(is));
  503. color.setRed(readU8(is));
  504. color.setGreen(readU8(is));
  505. color.setBlue(readU8(is));
  506. palette_name = deSerializeString16(is);
  507. waving = readU8(is);
  508. connect_sides = readU8(is);
  509. u16 connects_to_size = readU16(is);
  510. connects_to_ids.clear();
  511. for (u16 i = 0; i < connects_to_size; i++)
  512. connects_to_ids.push_back(readU16(is));
  513. post_effect_color = readARGB8(is);
  514. leveled = readU8(is);
  515. // lighting-related
  516. light_propagates = readU8(is);
  517. sunlight_propagates = readU8(is);
  518. light_source = readU8(is);
  519. light_source = MYMIN(light_source, LIGHT_MAX);
  520. // map generation
  521. is_ground_content = readU8(is);
  522. // interaction
  523. walkable = readU8(is);
  524. pointable = readU8(is);
  525. diggable = readU8(is);
  526. climbable = readU8(is);
  527. buildable_to = readU8(is);
  528. rightclickable = readU8(is);
  529. damage_per_second = readU32(is);
  530. // liquid
  531. liquid_type = (enum LiquidType) readU8(is);
  532. liquid_alternative_flowing = deSerializeString16(is);
  533. liquid_alternative_source = deSerializeString16(is);
  534. liquid_viscosity = readU8(is);
  535. liquid_renewable = readU8(is);
  536. liquid_range = readU8(is);
  537. drowning = readU8(is);
  538. floodable = readU8(is);
  539. // node boxes
  540. node_box.deSerialize(is);
  541. selection_box.deSerialize(is);
  542. collision_box.deSerialize(is);
  543. // sounds
  544. sound_footstep.deSerialize(is, version);
  545. sound_dig.deSerialize(is, version);
  546. sound_dug.deSerialize(is, version);
  547. // read legacy properties
  548. legacy_facedir_simple = readU8(is);
  549. legacy_wallmounted = readU8(is);
  550. try {
  551. node_dig_prediction = deSerializeString16(is);
  552. u8 tmp = readU8(is);
  553. if (is.eof()) /* readU8 doesn't throw exceptions so we have to do this */
  554. throw SerializationError("");
  555. leveled_max = tmp;
  556. tmp = readU8(is);
  557. if (is.eof())
  558. throw SerializationError("");
  559. alpha = static_cast<enum AlphaMode>(tmp);
  560. } catch(SerializationError &e) {};
  561. }
  562. #ifndef SERVER
  563. static void fillTileAttribs(ITextureSource *tsrc, TileLayer *layer,
  564. const TileSpec &tile, const TileDef &tiledef, video::SColor color,
  565. u8 material_type, u32 shader_id, bool backface_culling,
  566. const TextureSettings &tsettings)
  567. {
  568. layer->shader_id = shader_id;
  569. layer->texture = tsrc->getTextureForMesh(tiledef.name, &layer->texture_id);
  570. layer->material_type = material_type;
  571. bool has_scale = tiledef.scale > 0;
  572. bool use_autoscale = tsettings.autoscale_mode == AUTOSCALE_FORCE ||
  573. (tsettings.autoscale_mode == AUTOSCALE_ENABLE && !has_scale);
  574. if (use_autoscale) {
  575. auto texture_size = layer->texture->getOriginalSize();
  576. float base_size = tsettings.node_texture_size;
  577. float size = std::fmin(texture_size.Width, texture_size.Height);
  578. layer->scale = std::fmax(base_size, size) / base_size;
  579. } else if (has_scale) {
  580. layer->scale = tiledef.scale;
  581. } else {
  582. layer->scale = 1;
  583. }
  584. if (!tile.world_aligned)
  585. layer->scale = 1;
  586. layer->flags_texture = tsrc->getShaderFlagsTexture(layer->normal_texture ? true : false);
  587. // Material flags
  588. layer->material_flags = 0;
  589. if (backface_culling)
  590. layer->material_flags |= MATERIAL_FLAG_BACKFACE_CULLING;
  591. if (tiledef.animation.type != TAT_NONE)
  592. layer->material_flags |= MATERIAL_FLAG_ANIMATION;
  593. if (tiledef.tileable_horizontal)
  594. layer->material_flags |= MATERIAL_FLAG_TILEABLE_HORIZONTAL;
  595. if (tiledef.tileable_vertical)
  596. layer->material_flags |= MATERIAL_FLAG_TILEABLE_VERTICAL;
  597. // Color
  598. layer->has_color = tiledef.has_color;
  599. if (tiledef.has_color)
  600. layer->color = tiledef.color;
  601. else
  602. layer->color = color;
  603. // Animation parameters
  604. int frame_count = 1;
  605. if (layer->material_flags & MATERIAL_FLAG_ANIMATION) {
  606. int frame_length_ms;
  607. tiledef.animation.determineParams(layer->texture->getOriginalSize(),
  608. &frame_count, &frame_length_ms, NULL);
  609. layer->animation_frame_count = frame_count;
  610. layer->animation_frame_length_ms = frame_length_ms;
  611. }
  612. if (frame_count == 1) {
  613. layer->material_flags &= ~MATERIAL_FLAG_ANIMATION;
  614. } else {
  615. std::ostringstream os(std::ios::binary);
  616. if (!layer->frames) {
  617. layer->frames = new std::vector<FrameSpec>();
  618. }
  619. layer->frames->resize(frame_count);
  620. for (int i = 0; i < frame_count; i++) {
  621. FrameSpec frame;
  622. os.str("");
  623. os << tiledef.name;
  624. tiledef.animation.getTextureModifer(os,
  625. layer->texture->getOriginalSize(), i);
  626. frame.texture = tsrc->getTextureForMesh(os.str(), &frame.texture_id);
  627. if (layer->normal_texture)
  628. frame.normal_texture = tsrc->getNormalTexture(os.str());
  629. frame.flags_texture = layer->flags_texture;
  630. (*layer->frames)[i] = frame;
  631. }
  632. }
  633. }
  634. bool ContentFeatures::textureAlphaCheck(ITextureSource *tsrc, const TileDef *tiles, int length)
  635. {
  636. video::IVideoDriver *driver = RenderingEngine::get_video_driver();
  637. static thread_local bool long_warning_printed = false;
  638. std::set<std::string> seen;
  639. for (int i = 0; i < length; i++) {
  640. if (seen.find(tiles[i].name) != seen.end())
  641. continue;
  642. seen.insert(tiles[i].name);
  643. // Load the texture and see if there's any transparent pixels
  644. video::ITexture *texture = tsrc->getTexture(tiles[i].name);
  645. video::IImage *image = driver->createImage(texture,
  646. core::position2d<s32>(0, 0), texture->getOriginalSize());
  647. if (!image)
  648. continue;
  649. core::dimension2d<u32> dim = image->getDimension();
  650. bool ok = true;
  651. for (u16 x = 0; x < dim.Width; x++) {
  652. for (u16 y = 0; y < dim.Height; y++) {
  653. if (image->getPixel(x, y).getAlpha() < 255) {
  654. ok = false;
  655. goto break_loop;
  656. }
  657. }
  658. }
  659. break_loop:
  660. image->drop();
  661. if (ok)
  662. continue;
  663. warningstream << "Texture \"" << tiles[i].name << "\" of "
  664. << name << " has transparency, assuming "
  665. "use_texture_alpha = \"clip\"." << std::endl;
  666. if (!long_warning_printed) {
  667. warningstream << " This warning can be a false-positive if "
  668. "unused pixels in the texture are transparent. However if "
  669. "it is meant to be transparent, you *MUST* update the "
  670. "nodedef and set use_texture_alpha = \"clip\"! This "
  671. "compatibility code will be removed in a few releases."
  672. << std::endl;
  673. long_warning_printed = true;
  674. }
  675. return true;
  676. }
  677. return false;
  678. }
  679. bool isWorldAligned(AlignStyle style, WorldAlignMode mode, NodeDrawType drawtype)
  680. {
  681. if (style == ALIGN_STYLE_WORLD)
  682. return true;
  683. if (mode == WORLDALIGN_DISABLE)
  684. return false;
  685. if (style == ALIGN_STYLE_USER_DEFINED)
  686. return true;
  687. if (drawtype == NDT_NORMAL)
  688. return mode >= WORLDALIGN_FORCE;
  689. if (drawtype == NDT_NODEBOX)
  690. return mode >= WORLDALIGN_FORCE_NODEBOX;
  691. return false;
  692. }
  693. void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc,
  694. scene::IMeshManipulator *meshmanip, Client *client, const TextureSettings &tsettings)
  695. {
  696. // minimap pixel color - the average color of a texture
  697. if (tsettings.enable_minimap && !tiledef[0].name.empty())
  698. minimap_color = tsrc->getTextureAverageColor(tiledef[0].name);
  699. // Figure out the actual tiles to use
  700. TileDef tdef[6];
  701. for (u32 j = 0; j < 6; j++) {
  702. tdef[j] = tiledef[j];
  703. if (tdef[j].name.empty())
  704. tdef[j].name = "unknown_node.png";
  705. }
  706. // also the overlay tiles
  707. TileDef tdef_overlay[6];
  708. for (u32 j = 0; j < 6; j++)
  709. tdef_overlay[j] = tiledef_overlay[j];
  710. // also the special tiles
  711. TileDef tdef_spec[6];
  712. for (u32 j = 0; j < CF_SPECIAL_COUNT; j++)
  713. tdef_spec[j] = tiledef_special[j];
  714. bool is_liquid = false;
  715. if (alpha == ALPHAMODE_LEGACY_COMPAT) {
  716. // Before working with the alpha mode, resolve any legacy kludges
  717. alpha = textureAlphaCheck(tsrc, tdef, 6) ? ALPHAMODE_CLIP : ALPHAMODE_OPAQUE;
  718. }
  719. MaterialType material_type = alpha == ALPHAMODE_OPAQUE ?
  720. TILE_MATERIAL_OPAQUE : (alpha == ALPHAMODE_CLIP ? TILE_MATERIAL_BASIC :
  721. TILE_MATERIAL_ALPHA);
  722. switch (drawtype) {
  723. default:
  724. case NDT_NORMAL:
  725. solidness = 2;
  726. break;
  727. case NDT_AIRLIKE:
  728. solidness = 0;
  729. break;
  730. case NDT_LIQUID:
  731. if (tsettings.opaque_water)
  732. alpha = ALPHAMODE_OPAQUE;
  733. solidness = 1;
  734. is_liquid = true;
  735. break;
  736. case NDT_FLOWINGLIQUID:
  737. solidness = 0;
  738. if (tsettings.opaque_water)
  739. alpha = ALPHAMODE_OPAQUE;
  740. is_liquid = true;
  741. break;
  742. case NDT_GLASSLIKE:
  743. solidness = 0;
  744. visual_solidness = 1;
  745. break;
  746. case NDT_GLASSLIKE_FRAMED:
  747. solidness = 0;
  748. visual_solidness = 1;
  749. break;
  750. case NDT_GLASSLIKE_FRAMED_OPTIONAL:
  751. solidness = 0;
  752. visual_solidness = 1;
  753. drawtype = tsettings.connected_glass ? NDT_GLASSLIKE_FRAMED : NDT_GLASSLIKE;
  754. break;
  755. case NDT_ALLFACES:
  756. solidness = 0;
  757. visual_solidness = 1;
  758. break;
  759. case NDT_ALLFACES_OPTIONAL:
  760. if (tsettings.leaves_style == LEAVES_FANCY) {
  761. drawtype = NDT_ALLFACES;
  762. solidness = 0;
  763. visual_solidness = 1;
  764. } else if (tsettings.leaves_style == LEAVES_SIMPLE) {
  765. for (u32 j = 0; j < 6; j++) {
  766. if (!tdef_spec[j].name.empty())
  767. tdef[j].name = tdef_spec[j].name;
  768. }
  769. drawtype = NDT_GLASSLIKE;
  770. solidness = 0;
  771. visual_solidness = 1;
  772. } else {
  773. drawtype = NDT_NORMAL;
  774. solidness = 2;
  775. for (TileDef &td : tdef)
  776. td.name += std::string("^[noalpha");
  777. }
  778. if (waving >= 1)
  779. material_type = TILE_MATERIAL_WAVING_LEAVES;
  780. break;
  781. case NDT_PLANTLIKE:
  782. solidness = 0;
  783. if (waving >= 1)
  784. material_type = TILE_MATERIAL_WAVING_PLANTS;
  785. break;
  786. case NDT_FIRELIKE:
  787. solidness = 0;
  788. break;
  789. case NDT_MESH:
  790. case NDT_NODEBOX:
  791. solidness = 0;
  792. if (waving == 1) {
  793. material_type = TILE_MATERIAL_WAVING_PLANTS;
  794. } else if (waving == 2) {
  795. material_type = TILE_MATERIAL_WAVING_LEAVES;
  796. } else if (waving == 3) {
  797. material_type = alpha == ALPHAMODE_OPAQUE ?
  798. TILE_MATERIAL_WAVING_LIQUID_OPAQUE : (alpha == ALPHAMODE_CLIP ?
  799. TILE_MATERIAL_WAVING_LIQUID_BASIC : TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT);
  800. }
  801. break;
  802. case NDT_TORCHLIKE:
  803. case NDT_SIGNLIKE:
  804. case NDT_FENCELIKE:
  805. case NDT_RAILLIKE:
  806. solidness = 0;
  807. break;
  808. case NDT_PLANTLIKE_ROOTED:
  809. solidness = 2;
  810. break;
  811. }
  812. if (is_liquid) {
  813. if (waving == 3) {
  814. material_type = alpha == ALPHAMODE_OPAQUE ?
  815. TILE_MATERIAL_WAVING_LIQUID_OPAQUE : (alpha == ALPHAMODE_CLIP ?
  816. TILE_MATERIAL_WAVING_LIQUID_BASIC : TILE_MATERIAL_WAVING_LIQUID_TRANSPARENT);
  817. } else {
  818. material_type = alpha == ALPHAMODE_OPAQUE ? TILE_MATERIAL_LIQUID_OPAQUE :
  819. TILE_MATERIAL_LIQUID_TRANSPARENT;
  820. }
  821. }
  822. u32 tile_shader = shdsrc->getShader("nodes_shader", material_type, drawtype);
  823. MaterialType overlay_material = material_type;
  824. if (overlay_material == TILE_MATERIAL_OPAQUE)
  825. overlay_material = TILE_MATERIAL_BASIC;
  826. else if (overlay_material == TILE_MATERIAL_LIQUID_OPAQUE)
  827. overlay_material = TILE_MATERIAL_LIQUID_TRANSPARENT;
  828. u32 overlay_shader = shdsrc->getShader("nodes_shader", overlay_material, drawtype);
  829. // Tiles (fill in f->tiles[])
  830. for (u16 j = 0; j < 6; j++) {
  831. tiles[j].world_aligned = isWorldAligned(tdef[j].align_style,
  832. tsettings.world_aligned_mode, drawtype);
  833. fillTileAttribs(tsrc, &tiles[j].layers[0], tiles[j], tdef[j],
  834. color, material_type, tile_shader,
  835. tdef[j].backface_culling, tsettings);
  836. if (!tdef_overlay[j].name.empty())
  837. fillTileAttribs(tsrc, &tiles[j].layers[1], tiles[j], tdef_overlay[j],
  838. color, overlay_material, overlay_shader,
  839. tdef[j].backface_culling, tsettings);
  840. }
  841. MaterialType special_material = material_type;
  842. if (drawtype == NDT_PLANTLIKE_ROOTED) {
  843. if (waving == 1)
  844. special_material = TILE_MATERIAL_WAVING_PLANTS;
  845. else if (waving == 2)
  846. special_material = TILE_MATERIAL_WAVING_LEAVES;
  847. }
  848. u32 special_shader = shdsrc->getShader("nodes_shader", special_material, drawtype);
  849. // Special tiles (fill in f->special_tiles[])
  850. for (u16 j = 0; j < CF_SPECIAL_COUNT; j++)
  851. fillTileAttribs(tsrc, &special_tiles[j].layers[0], special_tiles[j], tdef_spec[j],
  852. color, special_material, special_shader,
  853. tdef_spec[j].backface_culling, tsettings);
  854. if (param_type_2 == CPT2_COLOR ||
  855. param_type_2 == CPT2_COLORED_FACEDIR ||
  856. param_type_2 == CPT2_COLORED_WALLMOUNTED ||
  857. param_type_2 == CPT2_COLORED_DEGROTATE)
  858. palette = tsrc->getPalette(palette_name);
  859. if (drawtype == NDT_MESH && !mesh.empty()) {
  860. // Meshnode drawtype
  861. // Read the mesh and apply scale
  862. mesh_ptr[0] = client->getMesh(mesh);
  863. if (mesh_ptr[0]){
  864. v3f scale = v3f(1.0, 1.0, 1.0) * BS * visual_scale;
  865. scaleMesh(mesh_ptr[0], scale);
  866. recalculateBoundingBox(mesh_ptr[0]);
  867. meshmanip->recalculateNormals(mesh_ptr[0], true, false);
  868. }
  869. }
  870. //Cache 6dfacedir and wallmounted rotated clones of meshes
  871. if (tsettings.enable_mesh_cache && mesh_ptr[0] &&
  872. (param_type_2 == CPT2_FACEDIR
  873. || param_type_2 == CPT2_COLORED_FACEDIR)) {
  874. for (u16 j = 1; j < 24; j++) {
  875. mesh_ptr[j] = cloneMesh(mesh_ptr[0]);
  876. rotateMeshBy6dFacedir(mesh_ptr[j], j);
  877. recalculateBoundingBox(mesh_ptr[j]);
  878. meshmanip->recalculateNormals(mesh_ptr[j], true, false);
  879. }
  880. } else if (tsettings.enable_mesh_cache && mesh_ptr[0]
  881. && (param_type_2 == CPT2_WALLMOUNTED ||
  882. param_type_2 == CPT2_COLORED_WALLMOUNTED)) {
  883. static const u8 wm_to_6d[6] = { 20, 0, 16 + 1, 12 + 3, 8, 4 + 2 };
  884. for (u16 j = 1; j < 6; j++) {
  885. mesh_ptr[j] = cloneMesh(mesh_ptr[0]);
  886. rotateMeshBy6dFacedir(mesh_ptr[j], wm_to_6d[j]);
  887. recalculateBoundingBox(mesh_ptr[j]);
  888. meshmanip->recalculateNormals(mesh_ptr[j], true, false);
  889. }
  890. rotateMeshBy6dFacedir(mesh_ptr[0], wm_to_6d[0]);
  891. recalculateBoundingBox(mesh_ptr[0]);
  892. meshmanip->recalculateNormals(mesh_ptr[0], true, false);
  893. }
  894. }
  895. #endif
  896. /*
  897. NodeDefManager
  898. */
  899. NodeDefManager::NodeDefManager()
  900. {
  901. clear();
  902. }
  903. NodeDefManager::~NodeDefManager()
  904. {
  905. #ifndef SERVER
  906. for (ContentFeatures &f : m_content_features) {
  907. for (auto &j : f.mesh_ptr) {
  908. if (j)
  909. j->drop();
  910. }
  911. }
  912. #endif
  913. }
  914. void NodeDefManager::clear()
  915. {
  916. m_content_features.clear();
  917. m_name_id_mapping.clear();
  918. m_name_id_mapping_with_aliases.clear();
  919. m_group_to_items.clear();
  920. m_next_id = 0;
  921. m_selection_box_union.reset(0,0,0);
  922. m_selection_box_int_union.reset(0,0,0);
  923. resetNodeResolveState();
  924. u32 initial_length = 0;
  925. initial_length = MYMAX(initial_length, CONTENT_UNKNOWN + 1);
  926. initial_length = MYMAX(initial_length, CONTENT_AIR + 1);
  927. initial_length = MYMAX(initial_length, CONTENT_IGNORE + 1);
  928. m_content_features.resize(initial_length);
  929. // Set CONTENT_UNKNOWN
  930. {
  931. ContentFeatures f;
  932. f.name = "unknown";
  933. // Insert directly into containers
  934. content_t c = CONTENT_UNKNOWN;
  935. m_content_features[c] = f;
  936. addNameIdMapping(c, f.name);
  937. }
  938. // Set CONTENT_AIR
  939. {
  940. ContentFeatures f;
  941. f.name = "air";
  942. f.drawtype = NDT_AIRLIKE;
  943. f.param_type = CPT_LIGHT;
  944. f.light_propagates = true;
  945. f.sunlight_propagates = true;
  946. f.walkable = false;
  947. f.pointable = false;
  948. f.diggable = false;
  949. f.buildable_to = true;
  950. f.floodable = true;
  951. f.is_ground_content = true;
  952. // Insert directly into containers
  953. content_t c = CONTENT_AIR;
  954. m_content_features[c] = f;
  955. addNameIdMapping(c, f.name);
  956. }
  957. // Set CONTENT_IGNORE
  958. {
  959. ContentFeatures f;
  960. f.name = "ignore";
  961. f.drawtype = NDT_AIRLIKE;
  962. f.param_type = CPT_NONE;
  963. f.light_propagates = false;
  964. f.sunlight_propagates = false;
  965. f.walkable = false;
  966. f.pointable = false;
  967. f.diggable = false;
  968. f.buildable_to = true; // A way to remove accidental CONTENT_IGNOREs
  969. f.is_ground_content = true;
  970. // Insert directly into containers
  971. content_t c = CONTENT_IGNORE;
  972. m_content_features[c] = f;
  973. addNameIdMapping(c, f.name);
  974. }
  975. }
  976. bool NodeDefManager::getId(const std::string &name, content_t &result) const
  977. {
  978. std::unordered_map<std::string, content_t>::const_iterator
  979. i = m_name_id_mapping_with_aliases.find(name);
  980. if(i == m_name_id_mapping_with_aliases.end())
  981. return false;
  982. result = i->second;
  983. return true;
  984. }
  985. content_t NodeDefManager::getId(const std::string &name) const
  986. {
  987. content_t id = CONTENT_IGNORE;
  988. getId(name, id);
  989. return id;
  990. }
  991. bool NodeDefManager::getIds(const std::string &name,
  992. std::vector<content_t> &result) const
  993. {
  994. //TimeTaker t("getIds", NULL, PRECISION_MICRO);
  995. if (name.substr(0,6) != "group:") {
  996. content_t id = CONTENT_IGNORE;
  997. bool exists = getId(name, id);
  998. if (exists)
  999. result.push_back(id);
  1000. return exists;
  1001. }
  1002. std::string group = name.substr(6);
  1003. std::unordered_map<std::string, std::vector<content_t>>::const_iterator
  1004. i = m_group_to_items.find(group);
  1005. if (i == m_group_to_items.end())
  1006. return true;
  1007. const std::vector<content_t> &items = i->second;
  1008. result.insert(result.end(), items.begin(), items.end());
  1009. //printf("getIds: %dus\n", t.stop());
  1010. return true;
  1011. }
  1012. const ContentFeatures& NodeDefManager::get(const std::string &name) const
  1013. {
  1014. content_t id = CONTENT_UNKNOWN;
  1015. getId(name, id);
  1016. return get(id);
  1017. }
  1018. // returns CONTENT_IGNORE if no free ID found
  1019. content_t NodeDefManager::allocateId()
  1020. {
  1021. for (content_t id = m_next_id;
  1022. id >= m_next_id; // overflow?
  1023. ++id) {
  1024. while (id >= m_content_features.size()) {
  1025. m_content_features.emplace_back();
  1026. }
  1027. const ContentFeatures &f = m_content_features[id];
  1028. if (f.name.empty()) {
  1029. m_next_id = id + 1;
  1030. return id;
  1031. }
  1032. }
  1033. // If we arrive here, an overflow occurred in id.
  1034. // That means no ID was found
  1035. return CONTENT_IGNORE;
  1036. }
  1037. /*!
  1038. * Returns the smallest box that contains all boxes
  1039. * in the vector. Box_union is expanded.
  1040. * @param[in] boxes the vector containing the boxes
  1041. * @param[in, out] box_union the union of the arguments
  1042. */
  1043. void boxVectorUnion(const std::vector<aabb3f> &boxes, aabb3f *box_union)
  1044. {
  1045. for (const aabb3f &box : boxes) {
  1046. box_union->addInternalBox(box);
  1047. }
  1048. }
  1049. /*!
  1050. * Returns a box that contains the nodebox in every case.
  1051. * The argument node_union is expanded.
  1052. * @param[in] nodebox the nodebox to be measured
  1053. * @param[in] features used to decide whether the nodebox
  1054. * can be rotated
  1055. * @param[in, out] box_union the union of the arguments
  1056. */
  1057. void getNodeBoxUnion(const NodeBox &nodebox, const ContentFeatures &features,
  1058. aabb3f *box_union)
  1059. {
  1060. switch(nodebox.type) {
  1061. case NODEBOX_FIXED:
  1062. case NODEBOX_LEVELED: {
  1063. // Raw union
  1064. aabb3f half_processed(0, 0, 0, 0, 0, 0);
  1065. boxVectorUnion(nodebox.fixed, &half_processed);
  1066. // Set leveled boxes to maximal
  1067. if (nodebox.type == NODEBOX_LEVELED) {
  1068. half_processed.MaxEdge.Y = +BS / 2;
  1069. }
  1070. if (features.param_type_2 == CPT2_FACEDIR ||
  1071. features.param_type_2 == CPT2_COLORED_FACEDIR) {
  1072. // Get maximal coordinate
  1073. f32 coords[] = {
  1074. fabsf(half_processed.MinEdge.X),
  1075. fabsf(half_processed.MinEdge.Y),
  1076. fabsf(half_processed.MinEdge.Z),
  1077. fabsf(half_processed.MaxEdge.X),
  1078. fabsf(half_processed.MaxEdge.Y),
  1079. fabsf(half_processed.MaxEdge.Z) };
  1080. f32 max = 0;
  1081. for (float coord : coords) {
  1082. if (max < coord) {
  1083. max = coord;
  1084. }
  1085. }
  1086. // Add the union of all possible rotated boxes
  1087. box_union->addInternalPoint(-max, -max, -max);
  1088. box_union->addInternalPoint(+max, +max, +max);
  1089. } else {
  1090. box_union->addInternalBox(half_processed);
  1091. }
  1092. break;
  1093. }
  1094. case NODEBOX_WALLMOUNTED: {
  1095. // Add fix boxes
  1096. box_union->addInternalBox(nodebox.wall_top);
  1097. box_union->addInternalBox(nodebox.wall_bottom);
  1098. // Find maximal coordinate in the X-Z plane
  1099. f32 coords[] = {
  1100. fabsf(nodebox.wall_side.MinEdge.X),
  1101. fabsf(nodebox.wall_side.MinEdge.Z),
  1102. fabsf(nodebox.wall_side.MaxEdge.X),
  1103. fabsf(nodebox.wall_side.MaxEdge.Z) };
  1104. f32 max = 0;
  1105. for (float coord : coords) {
  1106. if (max < coord) {
  1107. max = coord;
  1108. }
  1109. }
  1110. // Add the union of all possible rotated boxes
  1111. box_union->addInternalPoint(-max, nodebox.wall_side.MinEdge.Y, -max);
  1112. box_union->addInternalPoint(max, nodebox.wall_side.MaxEdge.Y, max);
  1113. break;
  1114. }
  1115. case NODEBOX_CONNECTED: {
  1116. // Add all possible connected boxes
  1117. boxVectorUnion(nodebox.fixed, box_union);
  1118. boxVectorUnion(nodebox.connect_top, box_union);
  1119. boxVectorUnion(nodebox.connect_bottom, box_union);
  1120. boxVectorUnion(nodebox.connect_front, box_union);
  1121. boxVectorUnion(nodebox.connect_left, box_union);
  1122. boxVectorUnion(nodebox.connect_back, box_union);
  1123. boxVectorUnion(nodebox.connect_right, box_union);
  1124. boxVectorUnion(nodebox.disconnected_top, box_union);
  1125. boxVectorUnion(nodebox.disconnected_bottom, box_union);
  1126. boxVectorUnion(nodebox.disconnected_front, box_union);
  1127. boxVectorUnion(nodebox.disconnected_left, box_union);
  1128. boxVectorUnion(nodebox.disconnected_back, box_union);
  1129. boxVectorUnion(nodebox.disconnected_right, box_union);
  1130. boxVectorUnion(nodebox.disconnected, box_union);
  1131. boxVectorUnion(nodebox.disconnected_sides, box_union);
  1132. break;
  1133. }
  1134. default: {
  1135. // NODEBOX_REGULAR
  1136. box_union->addInternalPoint(-BS / 2, -BS / 2, -BS / 2);
  1137. box_union->addInternalPoint(+BS / 2, +BS / 2, +BS / 2);
  1138. }
  1139. }
  1140. }
  1141. inline void NodeDefManager::fixSelectionBoxIntUnion()
  1142. {
  1143. m_selection_box_int_union.MinEdge.X = floorf(
  1144. m_selection_box_union.MinEdge.X / BS + 0.5f);
  1145. m_selection_box_int_union.MinEdge.Y = floorf(
  1146. m_selection_box_union.MinEdge.Y / BS + 0.5f);
  1147. m_selection_box_int_union.MinEdge.Z = floorf(
  1148. m_selection_box_union.MinEdge.Z / BS + 0.5f);
  1149. m_selection_box_int_union.MaxEdge.X = ceilf(
  1150. m_selection_box_union.MaxEdge.X / BS - 0.5f);
  1151. m_selection_box_int_union.MaxEdge.Y = ceilf(
  1152. m_selection_box_union.MaxEdge.Y / BS - 0.5f);
  1153. m_selection_box_int_union.MaxEdge.Z = ceilf(
  1154. m_selection_box_union.MaxEdge.Z / BS - 0.5f);
  1155. }
  1156. void NodeDefManager::eraseIdFromGroups(content_t id)
  1157. {
  1158. // For all groups in m_group_to_items...
  1159. for (auto iter_groups = m_group_to_items.begin();
  1160. iter_groups != m_group_to_items.end();) {
  1161. // Get the group items vector.
  1162. std::vector<content_t> &items = iter_groups->second;
  1163. // Remove any occurence of the id in the group items vector.
  1164. items.erase(std::remove(items.begin(), items.end(), id), items.end());
  1165. // If group is empty, erase its vector from the map.
  1166. if (items.empty())
  1167. iter_groups = m_group_to_items.erase(iter_groups);
  1168. else
  1169. ++iter_groups;
  1170. }
  1171. }
  1172. // IWritableNodeDefManager
  1173. content_t NodeDefManager::set(const std::string &name, const ContentFeatures &def)
  1174. {
  1175. // Pre-conditions
  1176. assert(name != "");
  1177. assert(name != "ignore");
  1178. assert(name == def.name);
  1179. content_t id = CONTENT_IGNORE;
  1180. if (!m_name_id_mapping.getId(name, id)) { // ignore aliases
  1181. // Get new id
  1182. id = allocateId();
  1183. if (id == CONTENT_IGNORE) {
  1184. warningstream << "NodeDefManager: Absolute "
  1185. "limit reached" << std::endl;
  1186. return CONTENT_IGNORE;
  1187. }
  1188. assert(id != CONTENT_IGNORE);
  1189. addNameIdMapping(id, name);
  1190. }
  1191. // If there is already ContentFeatures registered for this id, clear old groups
  1192. if (id < m_content_features.size())
  1193. eraseIdFromGroups(id);
  1194. m_content_features[id] = def;
  1195. verbosestream << "NodeDefManager: registering content id \"" << id
  1196. << "\": name=\"" << def.name << "\""<<std::endl;
  1197. getNodeBoxUnion(def.selection_box, def, &m_selection_box_union);
  1198. fixSelectionBoxIntUnion();
  1199. // Add this content to the list of all groups it belongs to
  1200. for (const auto &group : def.groups) {
  1201. const std::string &group_name = group.first;
  1202. m_group_to_items[group_name].push_back(id);
  1203. }
  1204. return id;
  1205. }
  1206. content_t NodeDefManager::allocateDummy(const std::string &name)
  1207. {
  1208. assert(name != ""); // Pre-condition
  1209. ContentFeatures f;
  1210. f.name = name;
  1211. return set(name, f);
  1212. }
  1213. void NodeDefManager::removeNode(const std::string &name)
  1214. {
  1215. // Pre-condition
  1216. assert(name != "");
  1217. // Erase name from name ID mapping
  1218. content_t id = CONTENT_IGNORE;
  1219. if (m_name_id_mapping.getId(name, id)) {
  1220. m_name_id_mapping.eraseName(name);
  1221. m_name_id_mapping_with_aliases.erase(name);
  1222. }
  1223. eraseIdFromGroups(id);
  1224. }
  1225. void NodeDefManager::updateAliases(IItemDefManager *idef)
  1226. {
  1227. std::set<std::string> all;
  1228. idef->getAll(all);
  1229. m_name_id_mapping_with_aliases.clear();
  1230. for (const std::string &name : all) {
  1231. const std::string &convert_to = idef->getAlias(name);
  1232. content_t id;
  1233. if (m_name_id_mapping.getId(convert_to, id)) {
  1234. m_name_id_mapping_with_aliases.insert(
  1235. std::make_pair(name, id));
  1236. }
  1237. }
  1238. }
  1239. void NodeDefManager::applyTextureOverrides(const std::vector<TextureOverride> &overrides)
  1240. {
  1241. infostream << "NodeDefManager::applyTextureOverrides(): Applying "
  1242. "overrides to textures" << std::endl;
  1243. for (const TextureOverride& texture_override : overrides) {
  1244. content_t id;
  1245. if (!getId(texture_override.id, id))
  1246. continue; // Ignore unknown node
  1247. ContentFeatures &nodedef = m_content_features[id];
  1248. // Override tiles
  1249. if (texture_override.hasTarget(OverrideTarget::TOP))
  1250. nodedef.tiledef[0].name = texture_override.texture;
  1251. if (texture_override.hasTarget(OverrideTarget::BOTTOM))
  1252. nodedef.tiledef[1].name = texture_override.texture;
  1253. if (texture_override.hasTarget(OverrideTarget::RIGHT))
  1254. nodedef.tiledef[2].name = texture_override.texture;
  1255. if (texture_override.hasTarget(OverrideTarget::LEFT))
  1256. nodedef.tiledef[3].name = texture_override.texture;
  1257. if (texture_override.hasTarget(OverrideTarget::BACK))
  1258. nodedef.tiledef[4].name = texture_override.texture;
  1259. if (texture_override.hasTarget(OverrideTarget::FRONT))
  1260. nodedef.tiledef[5].name = texture_override.texture;
  1261. // Override special tiles, if applicable
  1262. if (texture_override.hasTarget(OverrideTarget::SPECIAL_1))
  1263. nodedef.tiledef_special[0].name = texture_override.texture;
  1264. if (texture_override.hasTarget(OverrideTarget::SPECIAL_2))
  1265. nodedef.tiledef_special[1].name = texture_override.texture;
  1266. if (texture_override.hasTarget(OverrideTarget::SPECIAL_3))
  1267. nodedef.tiledef_special[2].name = texture_override.texture;
  1268. if (texture_override.hasTarget(OverrideTarget::SPECIAL_4))
  1269. nodedef.tiledef_special[3].name = texture_override.texture;
  1270. if (texture_override.hasTarget(OverrideTarget::SPECIAL_5))
  1271. nodedef.tiledef_special[4].name = texture_override.texture;
  1272. if (texture_override.hasTarget(OverrideTarget::SPECIAL_6))
  1273. nodedef.tiledef_special[5].name = texture_override.texture;
  1274. }
  1275. }
  1276. void NodeDefManager::updateTextures(IGameDef *gamedef, void *progress_callback_args)
  1277. {
  1278. #ifndef SERVER
  1279. infostream << "NodeDefManager::updateTextures(): Updating "
  1280. "textures in node definitions" << std::endl;
  1281. Client *client = (Client *)gamedef;
  1282. ITextureSource *tsrc = client->tsrc();
  1283. IShaderSource *shdsrc = client->getShaderSource();
  1284. auto smgr = client->getSceneManager();
  1285. scene::IMeshManipulator *meshmanip = smgr->getMeshManipulator();
  1286. TextureSettings tsettings;
  1287. tsettings.readSettings();
  1288. u32 size = m_content_features.size();
  1289. for (u32 i = 0; i < size; i++) {
  1290. ContentFeatures *f = &(m_content_features[i]);
  1291. f->updateTextures(tsrc, shdsrc, meshmanip, client, tsettings);
  1292. client->showUpdateProgressTexture(progress_callback_args, i, size);
  1293. }
  1294. #endif
  1295. }
  1296. void NodeDefManager::serialize(std::ostream &os, u16 protocol_version) const
  1297. {
  1298. writeU8(os, 1); // version
  1299. u16 count = 0;
  1300. std::ostringstream os2(std::ios::binary);
  1301. for (u32 i = 0; i < m_content_features.size(); i++) {
  1302. if (i == CONTENT_IGNORE || i == CONTENT_AIR
  1303. || i == CONTENT_UNKNOWN)
  1304. continue;
  1305. const ContentFeatures *f = &m_content_features[i];
  1306. if (f->name.empty())
  1307. continue;
  1308. writeU16(os2, i);
  1309. // Wrap it in a string to allow different lengths without
  1310. // strict version incompatibilities
  1311. std::ostringstream wrapper_os(std::ios::binary);
  1312. f->serialize(wrapper_os, protocol_version);
  1313. os2<<serializeString16(wrapper_os.str());
  1314. // must not overflow
  1315. u16 next = count + 1;
  1316. FATAL_ERROR_IF(next < count, "Overflow");
  1317. count++;
  1318. }
  1319. writeU16(os, count);
  1320. os << serializeString32(os2.str());
  1321. }
  1322. void NodeDefManager::deSerialize(std::istream &is)
  1323. {
  1324. clear();
  1325. int version = readU8(is);
  1326. if (version != 1)
  1327. throw SerializationError("unsupported NodeDefinitionManager version");
  1328. u16 count = readU16(is);
  1329. std::istringstream is2(deSerializeString32(is), std::ios::binary);
  1330. ContentFeatures f;
  1331. for (u16 n = 0; n < count; n++) {
  1332. u16 i = readU16(is2);
  1333. // Read it from the string wrapper
  1334. std::string wrapper = deSerializeString16(is2);
  1335. std::istringstream wrapper_is(wrapper, std::ios::binary);
  1336. f.deSerialize(wrapper_is);
  1337. // Check error conditions
  1338. if (i == CONTENT_IGNORE || i == CONTENT_AIR || i == CONTENT_UNKNOWN) {
  1339. warningstream << "NodeDefManager::deSerialize(): "
  1340. "not changing builtin node " << i << std::endl;
  1341. continue;
  1342. }
  1343. if (f.name.empty()) {
  1344. warningstream << "NodeDefManager::deSerialize(): "
  1345. "received empty name" << std::endl;
  1346. continue;
  1347. }
  1348. // Ignore aliases
  1349. u16 existing_id;
  1350. if (m_name_id_mapping.getId(f.name, existing_id) && i != existing_id) {
  1351. warningstream << "NodeDefManager::deSerialize(): "
  1352. "already defined with different ID: " << f.name << std::endl;
  1353. continue;
  1354. }
  1355. // All is ok, add node definition with the requested ID
  1356. if (i >= m_content_features.size())
  1357. m_content_features.resize((u32)(i) + 1);
  1358. m_content_features[i] = f;
  1359. addNameIdMapping(i, f.name);
  1360. TRACESTREAM(<< "NodeDef: deserialized " << f.name << std::endl);
  1361. getNodeBoxUnion(f.selection_box, f, &m_selection_box_union);
  1362. fixSelectionBoxIntUnion();
  1363. }
  1364. // Since liquid_alternative_flowing_id and liquid_alternative_source_id
  1365. // are not sent, resolve them client-side too.
  1366. resolveCrossrefs();
  1367. }
  1368. void NodeDefManager::addNameIdMapping(content_t i, const std::string &name)
  1369. {
  1370. m_name_id_mapping.set(i, name);
  1371. m_name_id_mapping_with_aliases.emplace(name, i);
  1372. }
  1373. NodeDefManager *createNodeDefManager()
  1374. {
  1375. return new NodeDefManager();
  1376. }
  1377. void NodeDefManager::pendNodeResolve(NodeResolver *nr) const
  1378. {
  1379. nr->m_ndef = this;
  1380. if (m_node_registration_complete)
  1381. nr->nodeResolveInternal();
  1382. else
  1383. m_pending_resolve_callbacks.push_back(nr);
  1384. }
  1385. bool NodeDefManager::cancelNodeResolveCallback(NodeResolver *nr) const
  1386. {
  1387. size_t len = m_pending_resolve_callbacks.size();
  1388. for (size_t i = 0; i != len; i++) {
  1389. if (nr != m_pending_resolve_callbacks[i])
  1390. continue;
  1391. len--;
  1392. m_pending_resolve_callbacks[i] = m_pending_resolve_callbacks[len];
  1393. m_pending_resolve_callbacks.resize(len);
  1394. return true;
  1395. }
  1396. return false;
  1397. }
  1398. void NodeDefManager::runNodeResolveCallbacks()
  1399. {
  1400. for (size_t i = 0; i != m_pending_resolve_callbacks.size(); i++) {
  1401. NodeResolver *nr = m_pending_resolve_callbacks[i];
  1402. nr->nodeResolveInternal();
  1403. }
  1404. m_pending_resolve_callbacks.clear();
  1405. }
  1406. void NodeDefManager::resetNodeResolveState()
  1407. {
  1408. m_node_registration_complete = false;
  1409. m_pending_resolve_callbacks.clear();
  1410. }
  1411. static void removeDupes(std::vector<content_t> &list)
  1412. {
  1413. std::sort(list.begin(), list.end());
  1414. auto new_end = std::unique(list.begin(), list.end());
  1415. list.erase(new_end, list.end());
  1416. }
  1417. void NodeDefManager::resolveCrossrefs()
  1418. {
  1419. for (ContentFeatures &f : m_content_features) {
  1420. if (f.liquid_type != LIQUID_NONE || f.drawtype == NDT_LIQUID || f.drawtype == NDT_FLOWINGLIQUID) {
  1421. f.liquid_alternative_flowing_id = getId(f.liquid_alternative_flowing);
  1422. f.liquid_alternative_source_id = getId(f.liquid_alternative_source);
  1423. continue;
  1424. }
  1425. if (f.drawtype != NDT_NODEBOX || f.node_box.type != NODEBOX_CONNECTED)
  1426. continue;
  1427. for (const std::string &name : f.connects_to) {
  1428. getIds(name, f.connects_to_ids);
  1429. }
  1430. removeDupes(f.connects_to_ids);
  1431. }
  1432. }
  1433. bool NodeDefManager::nodeboxConnects(MapNode from, MapNode to,
  1434. u8 connect_face) const
  1435. {
  1436. const ContentFeatures &f1 = get(from);
  1437. if ((f1.drawtype != NDT_NODEBOX) || (f1.node_box.type != NODEBOX_CONNECTED))
  1438. return false;
  1439. // lookup target in connected set
  1440. if (!CONTAINS(f1.connects_to_ids, to.param0))
  1441. return false;
  1442. const ContentFeatures &f2 = get(to);
  1443. if ((f2.drawtype == NDT_NODEBOX) && (f2.node_box.type == NODEBOX_CONNECTED))
  1444. // ignores actually looking if back connection exists
  1445. return CONTAINS(f2.connects_to_ids, from.param0);
  1446. // does to node declare usable faces?
  1447. if (f2.connect_sides > 0) {
  1448. if ((f2.param_type_2 == CPT2_FACEDIR ||
  1449. f2.param_type_2 == CPT2_COLORED_FACEDIR)
  1450. && (connect_face >= 4)) {
  1451. static const u8 rot[33 * 4] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1452. 0, 0, 0, 0, 4, 32, 16, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1453. 0, // 4 - back
  1454. 8, 4, 32, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1455. 0, // 8 - right
  1456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 8, 4, 32, 0,
  1457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1458. 0, // 16 - front
  1459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  1461. 0, 0, 0, 0, 0, 0, 32, 16, 8, 4 // 32 - left
  1462. };
  1463. return (f2.connect_sides
  1464. & rot[(connect_face * 4) + (to.param2 & 0x1F)]);
  1465. }
  1466. return (f2.connect_sides & connect_face);
  1467. }
  1468. // the target is just a regular node, so connect no matter back connection
  1469. return true;
  1470. }
  1471. ////
  1472. //// NodeResolver
  1473. ////
  1474. NodeResolver::NodeResolver()
  1475. {
  1476. reset();
  1477. }
  1478. NodeResolver::~NodeResolver()
  1479. {
  1480. if (!m_resolve_done && m_ndef)
  1481. m_ndef->cancelNodeResolveCallback(this);
  1482. }
  1483. void NodeResolver::cloneTo(NodeResolver *res) const
  1484. {
  1485. FATAL_ERROR_IF(!m_resolve_done, "NodeResolver can only be cloned"
  1486. " after resolving has completed");
  1487. /* We don't actually do anything significant. Since the node resolving has
  1488. * already completed, the class that called us will already have the
  1489. * resolved IDs in its data structures (which it copies on its own) */
  1490. res->m_ndef = m_ndef;
  1491. res->m_resolve_done = true;
  1492. }
  1493. void NodeResolver::nodeResolveInternal()
  1494. {
  1495. m_nodenames_idx = 0;
  1496. m_nnlistsizes_idx = 0;
  1497. resolveNodeNames();
  1498. m_resolve_done = true;
  1499. m_nodenames.clear();
  1500. m_nnlistsizes.clear();
  1501. }
  1502. bool NodeResolver::getIdFromNrBacklog(content_t *result_out,
  1503. const std::string &node_alt, content_t c_fallback, bool error_on_fallback)
  1504. {
  1505. if (m_nodenames_idx == m_nodenames.size()) {
  1506. *result_out = c_fallback;
  1507. errorstream << "NodeResolver: no more nodes in list" << std::endl;
  1508. return false;
  1509. }
  1510. content_t c;
  1511. std::string name = m_nodenames[m_nodenames_idx++];
  1512. bool success = m_ndef->getId(name, c);
  1513. if (!success && !node_alt.empty()) {
  1514. name = node_alt;
  1515. success = m_ndef->getId(name, c);
  1516. }
  1517. if (!success) {
  1518. if (error_on_fallback)
  1519. errorstream << "NodeResolver: failed to resolve node name '" << name
  1520. << "'." << std::endl;
  1521. c = c_fallback;
  1522. }
  1523. *result_out = c;
  1524. return success;
  1525. }
  1526. bool NodeResolver::getIdsFromNrBacklog(std::vector<content_t> *result_out,
  1527. bool all_required, content_t c_fallback)
  1528. {
  1529. bool success = true;
  1530. if (m_nnlistsizes_idx == m_nnlistsizes.size()) {
  1531. errorstream << "NodeResolver: no more node lists" << std::endl;
  1532. return false;
  1533. }
  1534. size_t length = m_nnlistsizes[m_nnlistsizes_idx++];
  1535. while (length--) {
  1536. if (m_nodenames_idx == m_nodenames.size()) {
  1537. errorstream << "NodeResolver: no more nodes in list" << std::endl;
  1538. return false;
  1539. }
  1540. content_t c;
  1541. std::string &name = m_nodenames[m_nodenames_idx++];
  1542. if (name.substr(0,6) != "group:") {
  1543. if (m_ndef->getId(name, c)) {
  1544. result_out->push_back(c);
  1545. } else if (all_required) {
  1546. errorstream << "NodeResolver: failed to resolve node name '"
  1547. << name << "'." << std::endl;
  1548. result_out->push_back(c_fallback);
  1549. success = false;
  1550. }
  1551. } else {
  1552. m_ndef->getIds(name, *result_out);
  1553. }
  1554. }
  1555. return success;
  1556. }
  1557. void NodeResolver::reset(bool resolve_done)
  1558. {
  1559. m_nodenames.clear();
  1560. m_nodenames_idx = 0;
  1561. m_nnlistsizes.clear();
  1562. m_nnlistsizes_idx = 0;
  1563. m_resolve_done = resolve_done;
  1564. m_nodenames.reserve(16);
  1565. m_nnlistsizes.reserve(4);
  1566. }