GrasslandBiom.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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::generateAboveSurfaceBlock(
  41. int x, int y, int z, int surfaceHeight)
  42. {
  43. if (z > surfaceHeight)
  44. return BlockTypeEnum::AIR;
  45. return BlockTypeEnum::GRASS;
  46. }
  47. Framework::Either<Block*, int> GrasslandBiom::generateSurfaceBlock(
  48. int x, int y, int z)
  49. {
  50. if (surfaceSandNoise->getNoise((double)x, (double)y, (double)z) < 0.35)
  51. {
  52. return BlockTypeEnum::SAND;
  53. }
  54. if (undergroundGravelNoise->getNoise((double)x, (double)y, (double)z)
  55. < 0.35)
  56. {
  57. return BlockTypeEnum::GRAVEL;
  58. }
  59. return BlockTypeEnum::DIRT;
  60. }
  61. Framework::Either<Block*, int> GrasslandBiom::generateBelowSurfaceBlock(
  62. int x, int y, int z)
  63. {
  64. if (undergroundDirdNoise->getNoise((double)x, (double)y, (double)z)
  65. < 0.35)
  66. {
  67. return BlockTypeEnum::DIRT;
  68. }
  69. if (undergroundGravelNoise->getNoise((double)x, (double)y, (double)z)
  70. < 0.35)
  71. {
  72. return BlockTypeEnum::GRAVEL;
  73. }
  74. return BlockTypeEnum::STONE;
  75. }
  76. Framework::Either<Block*, int> GrasslandBiom::generateCaveBlock(
  77. int x, int y, int z)
  78. {
  79. return BlockTypeEnum::AIR;
  80. }
  81. void GrasslandBiom::setSeed(int seed)
  82. {
  83. BiomGenerator::setSeed(seed);
  84. if (heightNoise) heightNoise->release();
  85. FastNoiseLite* noise = new FastNoiseLite(seed);
  86. noise->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_ValueCubic);
  87. FastNoiseWrapper* wrapper = new FastNoiseWrapper(noise, seed);
  88. wrapper->setMultiplier(0.2f);
  89. heightNoise = wrapper;
  90. noise = new FastNoiseLite(seed);
  91. noise->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_ValueCubic);
  92. noise->SetFrequency(0.15f);
  93. undergroundDirdNoise = new FastNoiseWrapper(noise, seed);
  94. noise = new FastNoiseLite(seed + 1);
  95. noise->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_ValueCubic);
  96. noise->SetFrequency(0.125f);
  97. undergroundGravelNoise = new FastNoiseWrapper(noise, seed + 1);
  98. noise = new FastNoiseLite(seed + 2);
  99. noise->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_ValueCubic);
  100. noise->SetFrequency(0.1f);
  101. surfaceSandNoise = new FastNoiseWrapper(noise, seed + 2);
  102. }
  103. Noise* GrasslandBiom::zHeightMapNoise()
  104. {
  105. return heightNoise;
  106. }