DimensionGenerator.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 DimensionEnum
  11. {
  12. public:
  13. static const int OVERWORLD = 0;
  14. };
  15. class DimensionGenerator;
  16. class DimensionGeneratorFactory : public virtual Framework::ReferenceCounter
  17. {
  18. private:
  19. Framework::Text name;
  20. int dimensionId;
  21. public:
  22. DimensionGeneratorFactory(Framework::Text name, int dimensionId);
  23. virtual DimensionGenerator* createDimensionGenerator(
  24. int worldSeed, Framework::JSON::JSONValue* config)
  25. = 0;
  26. virtual Framework::JSON::Validator::JSONValidator* getConfigValidator() = 0;
  27. virtual Framework::JSON::JSONValue* getDefaultConfig() = 0;
  28. Framework::Text getName() const;
  29. int getDimensionId() const;
  30. };
  31. class WorldHeightLayer : public virtual Framework::ReferenceCounter
  32. {
  33. private:
  34. Noise* noise;
  35. Framework::Text name;
  36. JFloatExpression* value;
  37. public:
  38. WorldHeightLayer(
  39. Framework::JSON::JSONValue* zConfig, JExpressionMemory* zMemory);
  40. ~WorldHeightLayer();
  41. void calculateValue(JExpressionMemory* zMemory);
  42. static Framework::JSON::Validator::JSONValidator* getValidator();
  43. };
  44. class DimensionGenerator : public virtual Framework::ReferenceCounter
  45. {
  46. private:
  47. JExpressionMemory* jExpressionMemory;
  48. Framework::RCArray<WorldHeightLayer> heightLayers;
  49. const int dimensionId;
  50. protected:
  51. DimensionGenerator(Framework::JSON::JSONValue* zConfig, int worldSeed);
  52. ~DimensionGenerator();
  53. JExpressionMemory* zMemory() const;
  54. void calculateHeightLayers();
  55. public:
  56. virtual Chunk* generateChunk(int centerX, int centerY) = 0;
  57. virtual Framework::Either<Block*, int> generateBlock(
  58. Framework::Vec3<int> location)
  59. = 0;
  60. virtual bool spawnStructure(Framework::Vec3<int> location,
  61. std::function<bool(GeneratorTemplate* tmpl)> filter)
  62. = 0;
  63. int getDimensionId() const;
  64. template<typename T>
  65. static Framework::JSON::Validator::ObjectValidationBuilder<T>*
  66. addConfigAttributes(
  67. Framework::JSON::Validator::ObjectValidationBuilder<T>* zBuilder)
  68. {
  69. return zBuilder
  70. ->withRequiredAttribute(
  71. "dimensionSeed", JExpressionParser::getFloatValidator())
  72. ->withRequiredAttribute("heightLayers",
  73. Framework::JSON::Validator::JSONValidator::buildForArray()
  74. ->withDefault(new Framework::JSON::JSONArray())
  75. ->removeInvalidEntries()
  76. ->addAcceptedTypeInArray(WorldHeightLayer::getValidator())
  77. ->finishArray());
  78. }
  79. };
  80. class BiomGenerator;
  81. class BiomedCavedDimensionGenerator : public DimensionGenerator
  82. {
  83. private:
  84. Framework::RCArray<BiomGenerator> biomGenerators;
  85. CaveGenerator* caveGenerator;
  86. Noise* biomNoise;
  87. Framework::Vec3<int> minStructureOffset;
  88. Framework::Vec3<int> maxStructureOffset;
  89. BiomGenerator* zBiomGenerator();
  90. protected:
  91. Framework::RCArray<GeneratedStructure>* getGeneratedStructoresForArea(
  92. Framework::Vec3<int> minPos, Framework::Vec3<int> maxPos);
  93. public:
  94. BiomedCavedDimensionGenerator(
  95. Framework::JSON::JSONValue* zConfig, int worldSeed);
  96. ~BiomedCavedDimensionGenerator();
  97. Chunk* generateChunk(int centerX, int centerY);
  98. Framework::Either<Block*, int> generateBlock(Framework::Vec3<int> location);
  99. bool spawnStructure(Framework::Vec3<int> location,
  100. std::function<bool(GeneratorTemplate* tmpl)> filter);
  101. template<typename T>
  102. static Framework::JSON::Validator::ObjectValidationBuilder<T>*
  103. addConfigAttributes(
  104. Framework::JSON::Validator::ObjectValidationBuilder<T>* zBuilder)
  105. {
  106. return DimensionGenerator::addConfigAttributes(zBuilder
  107. ->withRequiredArray("bioms")
  108. ->addAcceptedTypeInArray(BiomGenerator::getConfigValidator())
  109. ->finishArray()
  110. ->withRequiredAttribute("biomNoise", JNoise::getValidator(false)));
  111. }
  112. };