DimensionGenerator.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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(
  32. Framework::JSON::JSONValue* zConfig, int worldSeed, int dimensionId);
  33. ~DimensionGenerator();
  34. JExpressionMemory* zMemory() const;
  35. void calculateHeightLayers();
  36. public:
  37. virtual Chunk* generateChunk(int centerX, int centerY) = 0;
  38. virtual Framework::Either<Block*, int> generateBlock(
  39. Framework::Vec3<int> location)
  40. = 0;
  41. virtual bool spawnStructure(Framework::Vec3<int> location,
  42. std::function<bool(GeneratorTemplate* tmpl)> filter)
  43. = 0;
  44. int getDimensionId() const;
  45. template<typename T>
  46. static Framework::JSON::Validator::ObjectValidationBuilder<T>*
  47. addConfigAttributes(
  48. Framework::JSON::Validator::ObjectValidationBuilder<T>* zBuilder)
  49. {
  50. return zBuilder
  51. ->withRequiredAttribute(
  52. "dimensionSeed", JExpressionParser::getFloatValidator())
  53. ->withRequiredAttribute("heightLayers",
  54. Framework::JSON::Validator::JSONValidator::buildForArray()
  55. ->withDefault(new Framework::JSON::JSONArray())
  56. ->removeInvalidEntries()
  57. ->addAcceptedTypeInArray(WorldHeightLayer::getValidator())
  58. ->finishArray());
  59. }
  60. };
  61. class BiomGenerator;
  62. class BiomedCavedDimensionGenerator : public DimensionGenerator
  63. {
  64. private:
  65. Framework::RCArray<BiomGenerator> biomGenerators;
  66. CaveGenerator* caveGenerator;
  67. Noise* biomNoise;
  68. Framework::Vec3<int> minStructureOffset;
  69. Framework::Vec3<int> maxStructureOffset;
  70. BiomGenerator* zBiomGenerator();
  71. protected:
  72. Framework::RCArray<GeneratedStructure>* getGeneratedStructoresForArea(
  73. Framework::Vec3<int> minPos, Framework::Vec3<int> maxPos);
  74. public:
  75. BiomedCavedDimensionGenerator(
  76. Framework::JSON::JSONValue* zConfig, int worldSeed, int dimensionId);
  77. ~BiomedCavedDimensionGenerator();
  78. Chunk* generateChunk(int centerX, int centerY);
  79. Framework::Either<Block*, int> generateBlock(Framework::Vec3<int> location);
  80. bool spawnStructure(Framework::Vec3<int> location,
  81. std::function<bool(GeneratorTemplate* tmpl)> filter);
  82. template<typename T>
  83. static Framework::JSON::Validator::ObjectValidationBuilder<T>*
  84. addConfigAttributes(
  85. Framework::JSON::Validator::ObjectValidationBuilder<T>* zBuilder)
  86. {
  87. return DimensionGenerator::addConfigAttributes(zBuilder
  88. ->withRequiredArray("bioms")
  89. ->addAcceptedTypeInArray(BiomGenerator::getConfigValidator())
  90. ->finishArray()
  91. ->withRequiredAttribute("biomNoise", JNoise::getValidator(false)));
  92. }
  93. };