DimensionGenerator.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. #include "DimensionGenerator.h"
  2. #include <iostream>
  3. #include <Logging.h>
  4. #include <Zeit.h>
  5. #include "Constants.h"
  6. #include "Dimension.h"
  7. #include "Game.h"
  8. #include "NoBlock.h"
  9. #include "Noise.h"
  10. #include "RandNoise.h"
  11. #include "WormCaveGenerator.h"
  12. WorldHeightLayer::WorldHeightLayer()
  13. : ReferenceCounter(),
  14. noiseConfig(0),
  15. noise(0),
  16. value(0)
  17. {}
  18. WorldHeightLayer::~WorldHeightLayer()
  19. {
  20. if (noiseConfig) noiseConfig->release();
  21. if (noise) noise->release();
  22. if (value) value->release();
  23. }
  24. void WorldHeightLayer::initialize(JExpressionMemory* zMemory)
  25. {
  26. if (noise) noise->release();
  27. noise = JNoise::parseNoise(noiseConfig, zMemory);
  28. zMemory->setNoise(name, dynamic_cast<Noise*>(noise->getThis()));
  29. }
  30. void WorldHeightLayer::calculateValue(JExpressionMemory* zMemory)
  31. {
  32. zMemory->setFloatVariable(name, value->getValue(zMemory));
  33. }
  34. void WorldHeightLayer::setNoiseConfig(Framework::JSON::JSONObject* noiseConfig)
  35. {
  36. if (this->noiseConfig) this->noiseConfig->release();
  37. this->noiseConfig = noiseConfig;
  38. }
  39. Framework::JSON::JSONObject* WorldHeightLayer::zNoiseConfig() const
  40. {
  41. return noiseConfig;
  42. }
  43. void WorldHeightLayer::setName(Framework::Text name)
  44. {
  45. this->name = name;
  46. }
  47. Framework::Text WorldHeightLayer::getName() const
  48. {
  49. return name;
  50. }
  51. void WorldHeightLayer::setValue(JFloatExpression* value)
  52. {
  53. if (this->value) this->value->release();
  54. this->value = value;
  55. }
  56. JFloatExpression* WorldHeightLayer::zValue() const
  57. {
  58. return value;
  59. }
  60. WorldHeightLayerFactory::WorldHeightLayerFactory() {}
  61. WorldHeightLayer* WorldHeightLayerFactory::createValue(
  62. Framework::JSON::JSONObject* zJson) const
  63. {
  64. return new WorldHeightLayer();
  65. }
  66. void WorldHeightLayerFactory::fromJson(
  67. WorldHeightLayer* zResult, Framework::JSON::JSONObject* zJson) const
  68. {
  69. zResult->setName(zJson->zValue("name")->asString()->getString());
  70. zResult->setNoiseConfig(zJson->getValue("noise")->asObject());
  71. zResult->setValue(
  72. Game::INSTANCE->zTypeRegistry()->fromJson<JFloatExpression>(
  73. zJson->zValue("value")));
  74. }
  75. void WorldHeightLayerFactory::toJson(
  76. WorldHeightLayer* zObject, Framework::JSON::JSONObject* zResult) const
  77. {
  78. zResult->addValue(
  79. "name", new Framework::JSON::JSONString(zObject->getName()));
  80. zResult->addValue("noise", zObject->zNoiseConfig());
  81. zResult->addValue("value",
  82. Game::INSTANCE->zTypeRegistry()->toJson<JFloatExpression>(
  83. zObject->zValue()));
  84. }
  85. JSONObjectValidationBuilder* WorldHeightLayerFactory::addToValidator(
  86. JSONObjectValidationBuilder* builder) const
  87. {
  88. return builder->withRequiredString("name")
  89. ->finishString()
  90. ->withRequiredAttribute("noise", JNoise::getValidator(false))
  91. ->withRequiredAttribute("value",
  92. Game::INSTANCE->zTypeRegistry()->getValidator<JFloatExpression>());
  93. }
  94. DimensionGenerator::DimensionGenerator()
  95. : ReferenceCounter(),
  96. jExpressionMemory(new JExpressionMemory()),
  97. seedExpression(0),
  98. dimensionId(0)
  99. {}
  100. DimensionGenerator::~DimensionGenerator()
  101. {
  102. jExpressionMemory->release();
  103. if (seedExpression) seedExpression->release();
  104. }
  105. JExpressionMemory* DimensionGenerator::zMemory() const
  106. {
  107. return jExpressionMemory;
  108. }
  109. void DimensionGenerator::calculateHeightLayers()
  110. {
  111. for (WorldHeightLayer* layer : heightLayers)
  112. {
  113. layer->calculateValue(jExpressionMemory);
  114. }
  115. }
  116. Dimension* DimensionGenerator::createDimension()
  117. {
  118. return new Dimension(getId());
  119. }
  120. void DimensionGenerator::initialize(int worldSeed)
  121. {
  122. jExpressionMemory->setFloatVariable("worldSeed", (float)worldSeed);
  123. jExpressionMemory->setFloatVariable(
  124. "dimensionSeed", seedExpression->getValue(jExpressionMemory));
  125. for (WorldHeightLayer* layer : heightLayers)
  126. {
  127. layer->initialize(jExpressionMemory);
  128. }
  129. }
  130. int DimensionGenerator::getDimensionId() const
  131. {
  132. return dimensionId;
  133. }
  134. void DimensionGenerator::addHeightLayer(WorldHeightLayer* layer)
  135. {
  136. heightLayers.add(layer);
  137. }
  138. const Framework::RCArray<WorldHeightLayer>&
  139. DimensionGenerator::getHeightLayers() const
  140. {
  141. return heightLayers;
  142. }
  143. void DimensionGenerator::setName(Framework::Text name)
  144. {
  145. this->name = name;
  146. }
  147. Framework::Text DimensionGenerator::getName() const
  148. {
  149. return name;
  150. }
  151. void DimensionGenerator::setId(int id)
  152. {
  153. dimensionId = id;
  154. }
  155. int DimensionGenerator::getId() const
  156. {
  157. return dimensionId;
  158. }
  159. void DimensionGenerator::setSeed(JFloatExpression* seed)
  160. {
  161. if (seedExpression) seedExpression->release();
  162. seedExpression = seed;
  163. }
  164. JFloatExpression* DimensionGenerator::zSeed() const
  165. {
  166. return seedExpression;
  167. }
  168. BiomedCavedDimensionGenerator::BiomedCavedDimensionGenerator()
  169. : DimensionGenerator(),
  170. caveGenerator(0),
  171. noiseConfig(0),
  172. biomNoise(0)
  173. {}
  174. BiomedCavedDimensionGenerator::~BiomedCavedDimensionGenerator()
  175. {
  176. if (noiseConfig) noiseConfig->release();
  177. if (biomNoise) biomNoise->release();
  178. if (caveGenerator) caveGenerator->release();
  179. }
  180. void BiomedCavedDimensionGenerator::initialize(int worldSeed)
  181. {
  182. if (biomNoise) biomNoise->release();
  183. if (caveGenerator) caveGenerator->release();
  184. DimensionGenerator::initialize(worldSeed);
  185. biomNoise = JNoise::parseNoise(noiseConfig, zMemory());
  186. for (BiomGenerator* gen : biomGenerators)
  187. {
  188. gen->initialize(zMemory());
  189. }
  190. caveGenerator = new WormCaveGenerator(75, 150, 1, 6, 0.1f, worldSeed - 1);
  191. }
  192. BiomGenerator* BiomedCavedDimensionGenerator::zBiomGenerator()
  193. {
  194. for (BiomGenerator* generator : biomGenerators)
  195. {
  196. if (generator->isApplicable(zMemory())) return generator;
  197. }
  198. return 0;
  199. }
  200. Framework::RCArray<GeneratedStructure>*
  201. BiomedCavedDimensionGenerator::getGeneratedStructoresForArea(
  202. Framework::Vec3<int> minPos, Framework::Vec3<int> maxPos)
  203. {
  204. int minSearchX = minPos.x - maxStructureOffset.x;
  205. int minSearchY = minPos.y - maxStructureOffset.y;
  206. int minSearchZ = MAX(minPos.z - maxStructureOffset.z, 0);
  207. int maxSearchX = maxPos.x - minStructureOffset.x;
  208. int maxSearchY = maxPos.y - minStructureOffset.y;
  209. int maxSearchZ = MIN(maxPos.z - minStructureOffset.z, WORLD_HEIGHT - 1);
  210. Framework::RCArray<GeneratedStructure>* result
  211. = new Framework::RCArray<GeneratedStructure>();
  212. for (int x = minSearchX; x <= maxSearchX; x++)
  213. {
  214. for (int y = minSearchY; y <= maxSearchY; y++)
  215. {
  216. zMemory()->setFloatVariable("x", (float)x);
  217. zMemory()->setFloatVariable("y", (float)y);
  218. calculateHeightLayers();
  219. BiomGenerator* gen = zBiomGenerator();
  220. for (int z = minSearchZ; z <= maxSearchZ; z++)
  221. {
  222. zMemory()->setFloatVariable("z", (float)z);
  223. gen->generateStructures(x,
  224. y,
  225. z,
  226. getDimensionId(),
  227. zMemory(),
  228. minPos,
  229. maxPos,
  230. result);
  231. }
  232. }
  233. }
  234. return result;
  235. }
  236. Chunk* BiomedCavedDimensionGenerator::generateChunk(int centerX, int centerY)
  237. {
  238. zMemory()->lock();
  239. Framework::Logging::debug()
  240. << "generating chunk " << centerX << ", " << centerY;
  241. double structureTime = 0;
  242. double structureTime2 = 0;
  243. double structureTime3 = 0;
  244. double caveTime = 0;
  245. double caveTime2 = 0;
  246. double blockGenTime = 0;
  247. double biomTime = 0;
  248. double layerTime = 0;
  249. Framework::ZeitMesser zm;
  250. Framework::ZeitMesser zmGlobal;
  251. zm.messungStart();
  252. zmGlobal.messungStart();
  253. Framework::RCArray<GeneratedStructure>* structures
  254. = getGeneratedStructoresForArea(
  255. Framework::Vec3<int>(
  256. centerX - CHUNK_SIZE / 2, centerY - CHUNK_SIZE / 2, 0),
  257. Framework::Vec3<int>(centerX + CHUNK_SIZE / 2,
  258. centerY + CHUNK_SIZE / 2,
  259. WORLD_HEIGHT - 1));
  260. zm.messungEnde();
  261. structureTime += zm.getSekunden();
  262. zm.messungStart();
  263. CaveChunkGenerator* caveGen
  264. = caveGenerator->getGeneratorForChunk(centerX, centerY);
  265. zm.messungEnde();
  266. caveTime += zm.getSekunden();
  267. Chunk* chunk
  268. = new Chunk(Framework::Punkt(centerX, centerY), getDimensionId());
  269. zMemory()->setCurrentChunk(dynamic_cast<Chunk*>(chunk->getThis()));
  270. for (int x = -CHUNK_SIZE / 2; x < CHUNK_SIZE / 2; x++)
  271. {
  272. for (int y = -CHUNK_SIZE / 2; y < CHUNK_SIZE / 2; y++)
  273. {
  274. zMemory()->setFloatVariable("x", (float)x + (float)centerX);
  275. zMemory()->setFloatVariable("y", (float)y + (float)centerY);
  276. // calculate height layers
  277. zm.messungStart();
  278. calculateHeightLayers();
  279. zm.messungEnde();
  280. layerTime += zm.getSekunden();
  281. // calculate biom
  282. zm.messungStart();
  283. BiomGenerator* biom = zBiomGenerator();
  284. zm.messungEnde();
  285. biomTime += zm.getSekunden();
  286. // generate blocks
  287. for (int z = 0; z < WORLD_HEIGHT; z++)
  288. {
  289. zMemory()->setFloatVariable("z", (float)z);
  290. Framework::Either<Block*, int> generated = BlockTypeEnum::AIR;
  291. bool structureAffected = 0;
  292. // check if the block is inside of a structure
  293. zm.messungStart();
  294. for (auto structure : *structures)
  295. {
  296. if (structure->isBlockAffected(
  297. Framework::Vec3<int>(x + centerX, y + centerY, z)))
  298. {
  299. zm.messungEnde();
  300. structureTime2 += zm.getSekunden();
  301. zm.messungStart();
  302. generated = structure->generateBlockAt(
  303. Framework::Vec3<int>(x + centerX, y + centerY, z),
  304. getDimensionId());
  305. structureAffected = 1;
  306. zm.messungEnde();
  307. structureTime3 += zm.getSekunden();
  308. zm.messungStart();
  309. break;
  310. }
  311. }
  312. zm.messungEnde();
  313. structureTime2 += zm.getSekunden();
  314. if (!structureAffected)
  315. {
  316. // check if block is a cave block
  317. zm.messungStart();
  318. bool inCave
  319. = caveGen->isInCave(x + centerX, y + centerY, z);
  320. zm.messungEnde();
  321. caveTime2 += zm.getSekunden();
  322. if (!inCave)
  323. {
  324. // generate biom block
  325. zm.messungStart();
  326. generated = biom->generateBlock(x + centerX,
  327. y + centerY,
  328. z,
  329. getDimensionId(),
  330. zMemory(),
  331. chunk);
  332. zm.messungEnde();
  333. blockGenTime += zm.getSekunden();
  334. }
  335. }
  336. if (generated.isA())
  337. chunk->putBlockAt(
  338. Framework::Vec3<int>(
  339. x + CHUNK_SIZE / 2, y + CHUNK_SIZE / 2, z),
  340. generated);
  341. else
  342. chunk->putBlockTypeAt(
  343. Framework::Vec3<int>(
  344. x + CHUNK_SIZE / 2, y + CHUNK_SIZE / 2, z),
  345. generated);
  346. }
  347. }
  348. }
  349. caveGen->release();
  350. structures->release();
  351. zmGlobal.messungEnde();
  352. Framework::Logging::trace() << "structureGenerationTime: " << structureTime;
  353. Framework::Logging::trace()
  354. << "structure.isBlockAffected: " << structureTime2;
  355. Framework::Logging::trace()
  356. << "structure.generateBlockAt: " << structureTime3;
  357. Framework::Logging::trace() << "caveGenerationTime: " << caveTime;
  358. Framework::Logging::trace() << "caveEvaluationTime: " << caveTime2;
  359. Framework::Logging::trace() << "blockGenTime: " << blockGenTime;
  360. Framework::Logging::trace() << "biomTime: " << biomTime;
  361. Framework::Logging::trace() << "layerTime: " << layerTime;
  362. Framework::Logging::debug() << "totalTime: " << zmGlobal.getSekunden();
  363. zMemory()->unlock();
  364. return chunk;
  365. }
  366. void BiomedCavedDimensionGenerator::generateEntities(Chunk* zChunk)
  367. {
  368. zMemory()->lock();
  369. zMemory()->setCurrentChunk(dynamic_cast<Chunk*>(zChunk->getThis()));
  370. zMemory()->setFloatVariable("x", (float)zChunk->getCenter().x);
  371. zMemory()->setFloatVariable("y", (float)zChunk->getCenter().y);
  372. calculateHeightLayers();
  373. BiomGenerator* biom = zBiomGenerator();
  374. for (int x = -CHUNK_SIZE / 2; x < CHUNK_SIZE / 2; x++)
  375. {
  376. for (int y = -CHUNK_SIZE / 2; y < CHUNK_SIZE / 2; y++)
  377. {
  378. for (int z = 0; z < WORLD_HEIGHT; z++)
  379. {
  380. if (zChunk->getBlockTypeAt(Framework::Vec3<int>(x, y, z))
  381. == BlockTypeEnum::AIR)
  382. {
  383. zMemory()->setFloatVariable("x", (float)z);
  384. zMemory()->setFloatVariable("y", (float)z);
  385. zMemory()->setFloatVariable("z", (float)z);
  386. biom->generateEntities(
  387. x, y, z, getDimensionId(), zMemory());
  388. }
  389. }
  390. }
  391. }
  392. zMemory()->unlock();
  393. }
  394. Framework::Either<Block*, int> BiomedCavedDimensionGenerator::generateBlock(
  395. Framework::Vec3<int> location)
  396. {
  397. Chunk* zChunk
  398. = Game::INSTANCE->zDimension(getDimensionId())
  399. ->zChunk(Game::INSTANCE->getChunkCenter(location.x, location.y));
  400. if (!zChunk)
  401. {
  402. return BlockTypeEnum::NO_BLOCK;
  403. }
  404. zMemory()->lock();
  405. zMemory()->setCurrentChunk(dynamic_cast<Chunk*>(zChunk->getThis()));
  406. Framework::RCArray<GeneratedStructure>* structures
  407. = getGeneratedStructoresForArea(location, location);
  408. zMemory()->setFloatVariable("x", (float)location.x);
  409. zMemory()->setFloatVariable("y", (float)location.y);
  410. calculateHeightLayers();
  411. BiomGenerator* biom = zBiomGenerator();
  412. zMemory()->setFloatVariable("z", (float)location.z);
  413. for (auto structure : *structures)
  414. {
  415. if (structure->isBlockAffected(location))
  416. {
  417. auto generated
  418. = structure->generateBlockAt(location, getDimensionId());
  419. structures->release();
  420. zMemory()->unlock();
  421. return generated;
  422. }
  423. }
  424. structures->release();
  425. Framework::Punkt chunkCenter = Game::getChunkCenter(location.x, location.y);
  426. CaveChunkGenerator* caveGen
  427. = caveGenerator->getGeneratorForChunk(chunkCenter.x, chunkCenter.y);
  428. if (caveGen->isInCave(location.x, location.y, location.z))
  429. {
  430. caveGen->release();
  431. zMemory()->unlock();
  432. return BlockTypeEnum::AIR;
  433. }
  434. caveGen->release();
  435. auto generated = biom->generateBlock(location.x,
  436. location.y,
  437. location.z,
  438. getDimensionId(),
  439. zMemory(),
  440. zChunk);
  441. zMemory()->unlock();
  442. return generated;
  443. }
  444. bool BiomedCavedDimensionGenerator::spawnStructure(
  445. Framework::Vec3<int> location,
  446. std::function<bool(GeneratorTemplate* tmpl)> filter)
  447. {
  448. zMemory()->lock();
  449. zMemory()->setFloatVariable("x", (float)location.x);
  450. zMemory()->setFloatVariable("y", (float)location.y);
  451. BiomGenerator* biom = zBiomGenerator();
  452. zMemory()->unlock();
  453. for (StructureTemplateCollection* tc : biom->getTemplates())
  454. {
  455. for (GeneratorTemplate* t : tc->getStructures())
  456. {
  457. if (filter(t))
  458. {
  459. RandNoise noise((int)time(0));
  460. GeneratedStructure* genStr
  461. = t->generateAt(location, &noise, getDimensionId());
  462. if (genStr)
  463. {
  464. int minSearchX = location.x + t->getMinAffectedOffset().x;
  465. int minSearchY = location.y + t->getMinAffectedOffset().y;
  466. int minSearchZ
  467. = MAX(location.z + t->getMinAffectedOffset().z, 0);
  468. int maxSearchX = location.x + t->getMaxAffectedOffset().x;
  469. int maxSearchY = location.y + t->getMaxAffectedOffset().y;
  470. int maxSearchZ
  471. = MIN(location.z + t->getMaxAffectedOffset().z,
  472. WORLD_HEIGHT - 1);
  473. for (int x = minSearchX; x <= maxSearchX; x++)
  474. {
  475. for (int y = minSearchY; y <= maxSearchY; y++)
  476. {
  477. for (int z = minSearchZ; z <= maxSearchZ; z++)
  478. {
  479. if (genStr->isBlockAffected(
  480. Framework::Vec3<int>(x, y, z)))
  481. {
  482. auto gen = genStr->generateBlockAt(
  483. Framework::Vec3<int>(x, y, z),
  484. getDimensionId());
  485. Game::INSTANCE->zDimension(getDimensionId())
  486. ->placeBlock(
  487. Framework::Vec3<int>(x, y, z), gen);
  488. }
  489. }
  490. }
  491. }
  492. genStr->release();
  493. zMemory()->unlock();
  494. return 1;
  495. }
  496. }
  497. }
  498. }
  499. return 0;
  500. }
  501. void BiomedCavedDimensionGenerator::addBiomGenerator(
  502. BiomGenerator* biomGenerator)
  503. {
  504. biomGenerators.add(biomGenerator);
  505. if (biomGenerators.getEintragAnzahl() == 1)
  506. {
  507. minStructureOffset = biomGenerator->getMinStructureOffset();
  508. maxStructureOffset = biomGenerator->getMaxStructureOffset();
  509. }
  510. else
  511. {
  512. Framework::Vec3<int> min = biomGenerator->getMinStructureOffset();
  513. Framework::Vec3<int> max = biomGenerator->getMaxStructureOffset();
  514. if (minStructureOffset.x > min.x) minStructureOffset.x = min.x;
  515. if (minStructureOffset.y > min.y) minStructureOffset.y = min.y;
  516. if (minStructureOffset.z > min.z) minStructureOffset.z = min.z;
  517. if (maxStructureOffset.x < max.x) maxStructureOffset.x = max.x;
  518. if (maxStructureOffset.y < max.y) maxStructureOffset.y = max.y;
  519. if (maxStructureOffset.z < max.z) maxStructureOffset.z = max.z;
  520. }
  521. }
  522. const Framework::RCArray<BiomGenerator>&
  523. BiomedCavedDimensionGenerator::getBiomGenerators() const
  524. {
  525. return biomGenerators;
  526. }
  527. void BiomedCavedDimensionGenerator::setBiomNoiseConfig(
  528. Framework::JSON::JSONObject* biomNoiseConfig)
  529. {
  530. if (noiseConfig) noiseConfig->release();
  531. noiseConfig = biomNoiseConfig;
  532. }
  533. Framework::JSON::JSONObject*
  534. BiomedCavedDimensionGenerator::zBiomNoiseConfig() const
  535. {
  536. return noiseConfig;
  537. }
  538. BiomedCavedDimensionGeneratorFactory::BiomedCavedDimensionGeneratorFactory() {}
  539. BiomedCavedDimensionGenerator*
  540. BiomedCavedDimensionGeneratorFactory::createValue(
  541. Framework::JSON::JSONObject* zJson) const
  542. {
  543. return new BiomedCavedDimensionGenerator();
  544. }
  545. void BiomedCavedDimensionGeneratorFactory::fromJson(
  546. BiomedCavedDimensionGenerator* zResult,
  547. Framework::JSON::JSONObject* zJson) const
  548. {
  549. zResult->setBiomNoiseConfig(zJson->getValue("biomNoise")->asObject());
  550. for (Framework::JSON::JSONValue* value : *zJson->zValue("bioms")->asArray())
  551. {
  552. zResult->addBiomGenerator(
  553. Game::INSTANCE->zTypeRegistry()->fromJson<BiomGenerator>(value));
  554. }
  555. DimensionGeneratorFactory::fromJson(zResult, zJson);
  556. }
  557. void BiomedCavedDimensionGeneratorFactory::toJson(
  558. BiomedCavedDimensionGenerator* zObject,
  559. Framework::JSON::JSONObject* zResult) const
  560. {
  561. Framework::JSON::JSONArray* bioms = new Framework::JSON::JSONArray();
  562. for (BiomGenerator* biom : zObject->getBiomGenerators())
  563. {
  564. bioms->addValue(
  565. Game::INSTANCE->zTypeRegistry()->toJson<BiomGenerator>(biom));
  566. }
  567. zResult->addValue("bioms", bioms);
  568. zResult->addValue("biomNoise",
  569. dynamic_cast<Framework::JSON::JSONValue*>(
  570. zObject->zBiomNoiseConfig()->getThis()));
  571. DimensionGeneratorFactory::toJson(zObject, zResult);
  572. }
  573. JSONObjectValidationBuilder*
  574. BiomedCavedDimensionGeneratorFactory::addToValidator(
  575. JSONObjectValidationBuilder* builder) const
  576. {
  577. return DimensionGeneratorFactory::addToValidator(
  578. builder->withRequiredArray("bioms")
  579. ->addAcceptedTypeInArray(
  580. Game::INSTANCE->zTypeRegistry()->getValidator<BiomGenerator>())
  581. ->finishArray()
  582. ->withRequiredAttribute("biomNoise", JNoise::getValidator(false)));
  583. }
  584. Framework::Text BiomedCavedDimensionGeneratorFactory::getTypeToken() const
  585. {
  586. return "cavedBioms";
  587. }