GrasslandBiom.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #include "GrasslandBiom.h"
  2. #include "BasicBlocks.h"
  3. #include "BlockType.h"
  4. #include "FastNoiseLite.h"
  5. #include "FastNoiseWrapper.h"
  6. #include "NoBlock.h"
  7. #include "TreeTemplate.h"
  8. GrasslandBiom::GrasslandBiom()
  9. : BiomGenerator()
  10. {
  11. addTemplateGenerator(new TreeTemplate(0.002f,
  12. BlockTypeEnum::WOOD_BIRCH,
  13. BlockTypeEnum::LEAVES_WOOD_BIRCH,
  14. 8,
  15. 15));
  16. addTemplateGenerator(new TreeTemplate(0.001f,
  17. BlockTypeEnum::WOOD_BEECH,
  18. BlockTypeEnum::LEAVES_WOOD_BEECH,
  19. 8,
  20. 13));
  21. addTemplateGenerator(new TreeTemplate(0.0005f,
  22. BlockTypeEnum::WOOD_OAK,
  23. BlockTypeEnum::LEAVES_WOOD_OAK,
  24. 10,
  25. 15));
  26. addTemplateGenerator(new TreeTemplate(0.00025f,
  27. BlockTypeEnum::WOOD_PINE,
  28. BlockTypeEnum::LEAVES_WOOD_PINE,
  29. 15,
  30. 24));
  31. heightNoise = 0;
  32. undergroundDirdNoise = 0;
  33. surfaceSandNoise = 0;
  34. undergroundGravelNoise = 0;
  35. }
  36. GrasslandBiom::~GrasslandBiom()
  37. {
  38. if (heightNoise) heightNoise->release();
  39. }
  40. Framework::Either<Block*, int> GrasslandBiom::generateSurfaceBlock(
  41. int x, int y, int z)
  42. {
  43. if (surfaceSandNoise->getNoise((double)x, (double)y, (double)z) < 0.35)
  44. {
  45. return BlockTypeEnum::SAND;
  46. }
  47. if (undergroundGravelNoise->getNoise((double)x, (double)y, (double)z)
  48. < 0.35)
  49. {
  50. return BlockTypeEnum::GRAVEL;
  51. }
  52. return BlockTypeEnum::DIRT;
  53. }
  54. Framework::Either<Block*, int> GrasslandBiom::generateBelowSurfaceBlock(
  55. int x, int y, int z)
  56. {
  57. if (undergroundDirdNoise->getNoise((double)x, (double)y, (double)z)
  58. < 0.35)
  59. {
  60. return BlockTypeEnum::DIRT;
  61. }
  62. if (undergroundGravelNoise->getNoise((double)x, (double)y, (double)z)
  63. < 0.35)
  64. {
  65. return BlockTypeEnum::GRAVEL;
  66. }
  67. return BlockTypeEnum::STONE;
  68. }
  69. Framework::Either<Block*, int> GrasslandBiom::generateCaveBlock(
  70. int x, int y, int z)
  71. {
  72. return BlockTypeEnum::AIR;
  73. }
  74. void GrasslandBiom::setSeed(int seed)
  75. {
  76. BiomGenerator::setSeed(seed);
  77. if (heightNoise) heightNoise->release();
  78. FastNoiseLite* noise = new FastNoiseLite(seed);
  79. noise->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_ValueCubic);
  80. FastNoiseWrapper* wrapper = new FastNoiseWrapper(noise, seed);
  81. wrapper->setMultiplier(0.2f);
  82. heightNoise = wrapper;
  83. noise = new FastNoiseLite(seed);
  84. noise->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_ValueCubic);
  85. noise->SetFrequency(0.15f);
  86. undergroundDirdNoise = new FastNoiseWrapper(noise, seed);
  87. noise = new FastNoiseLite(seed + 1);
  88. noise->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_ValueCubic);
  89. noise->SetFrequency(0.125f);
  90. undergroundGravelNoise = new FastNoiseWrapper(noise, seed + 1);
  91. noise = new FastNoiseLite(seed + 2);
  92. noise->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_ValueCubic);
  93. noise->SetFrequency(0.1f);
  94. surfaceSandNoise = new FastNoiseWrapper(noise, seed + 2);
  95. }
  96. Noise* GrasslandBiom::zHeightMapNoise()
  97. {
  98. return heightNoise;
  99. }