DimensionGenerator.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #pragma once
  2. #include <Array.h>
  3. #include <Either.h>
  4. #include <ReferenceCounter.h>
  5. #include "BiomGenerator.h"
  6. #include "CaveGenerator.h"
  7. #include "Chunk.h"
  8. #include "JNoise.h"
  9. #include "JsonExpression.h"
  10. class DimensionGenerator;
  11. class WorldHeightLayer : public virtual Framework::ReferenceCounter
  12. {
  13. private:
  14. Noise* noise;
  15. Framework::Text name;
  16. JFloatExpression* value;
  17. public:
  18. WorldHeightLayer(
  19. Framework::JSON::JSONValue* zConfig, JExpressionMemory* zMemory);
  20. ~WorldHeightLayer();
  21. void calculateValue(JExpressionMemory* zMemory);
  22. static Framework::JSON::Validator::JSONValidator* getValidator();
  23. };
  24. class DimensionGenerator : public virtual Framework::ReferenceCounter
  25. {
  26. private:
  27. JExpressionMemory* jExpressionMemory;
  28. Framework::RCArray<WorldHeightLayer> heightLayers;
  29. const int dimensionId;
  30. protected:
  31. DimensionGenerator(Framework::JSON::JSONValue* zConfig, int worldSeed);
  32. ~DimensionGenerator();
  33. JExpressionMemory* zMemory() const;
  34. void calculateHeightLayers();
  35. public:
  36. virtual Chunk* generateChunk(int centerX, int centerY) = 0;
  37. virtual Framework::Either<Block*, int> generateBlock(
  38. Framework::Vec3<int> location)
  39. = 0;
  40. virtual bool spawnStructure(Framework::Vec3<int> location,
  41. std::function<bool(GeneratorTemplate* tmpl)> filter)
  42. = 0;
  43. int getDimensionId() const;
  44. template<typename T>
  45. static Framework::JSON::Validator::ObjectValidationBuilder<T>*
  46. addConfigAttributes(
  47. Framework::JSON::Validator::ObjectValidationBuilder<T>* zBuilder)
  48. {
  49. return zBuilder
  50. ->withRequiredAttribute(
  51. "dimensionSeed", JExpressionParser::getFloatValidator())
  52. ->withRequiredAttribute("heightLayers",
  53. Framework::JSON::Validator::JSONValidator::buildForArray()
  54. ->withDefault(new Framework::JSON::JSONArray())
  55. ->removeInvalidEntries()
  56. ->addAcceptedTypeInArray(WorldHeightLayer::getValidator())
  57. ->finishArray());
  58. }
  59. };
  60. class BiomGenerator;
  61. class BiomedCavedDimensionGenerator : public DimensionGenerator
  62. {
  63. private:
  64. Framework::RCArray<BiomGenerator> biomGenerators;
  65. CaveGenerator* caveGenerator;
  66. Noise* biomNoise;
  67. Framework::Vec3<int> minStructureOffset;
  68. Framework::Vec3<int> maxStructureOffset;
  69. BiomGenerator* zBiomGenerator();
  70. protected:
  71. Framework::RCArray<GeneratedStructure>* getGeneratedStructoresForArea(
  72. Framework::Vec3<int> minPos, Framework::Vec3<int> maxPos);
  73. public:
  74. BiomedCavedDimensionGenerator(
  75. Framework::JSON::JSONValue* zConfig, int worldSeed);
  76. ~BiomedCavedDimensionGenerator();
  77. Chunk* generateChunk(int centerX, int centerY);
  78. Framework::Either<Block*, int> generateBlock(Framework::Vec3<int> location);
  79. bool spawnStructure(Framework::Vec3<int> location,
  80. std::function<bool(GeneratorTemplate* tmpl)> filter);
  81. template<typename T>
  82. static Framework::JSON::Validator::ObjectValidationBuilder<T>*
  83. addConfigAttributes(
  84. Framework::JSON::Validator::ObjectValidationBuilder<T>* zBuilder)
  85. {
  86. return DimensionGenerator::addConfigAttributes(zBuilder
  87. ->withRequiredArray("bioms")
  88. ->addAcceptedTypeInArray(BiomGenerator::getConfigValidator())
  89. ->finishArray()
  90. ->withRequiredAttribute("biomNoise", JNoise::getValidator(false)));
  91. }
  92. };