GrasslandBiom.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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.02f,
  12. BlockTypeEnum::WOOD_BIRCH,
  13. BlockTypeEnum::LEAVES_WOOD_BIRCH,
  14. 8,
  15. 15));
  16. addTemplateGenerator(new TreeTemplate(0.01f,
  17. BlockTypeEnum::WOOD_BEECH,
  18. BlockTypeEnum::LEAVES_WOOD_BEECH,
  19. 8,
  20. 13));
  21. addTemplateGenerator(new TreeTemplate(0.005f,
  22. BlockTypeEnum::WOOD_OAK,
  23. BlockTypeEnum::LEAVES_WOOD_OAK,
  24. 10,
  25. 15));
  26. addTemplateGenerator(new TreeTemplate(0.0025f,
  27. BlockTypeEnum::WOOD_PINE,
  28. BlockTypeEnum::LEAVES_WOOD_PINE,
  29. 15,
  30. 24));
  31. heightNoise = 0;
  32. }
  33. GrasslandBiom::~GrasslandBiom()
  34. {
  35. if (heightNoise) heightNoise->release();
  36. }
  37. Framework::Either<Block*, int> GrasslandBiom::generateSurfaceBlock(
  38. int x, int y, int z)
  39. {
  40. if (((float)rand() / (float)RAND_MAX) < 0.05f) // TODO: use random noise
  41. return BlockTypeEnum::STONE_COBBLE;
  42. return BlockTypeEnum::DIRT;
  43. }
  44. Framework::Either<Block*, int> GrasslandBiom::generateBelowSurfaceBlock(
  45. int x, int y, int z)
  46. {
  47. return BlockTypeEnum::STONE;
  48. }
  49. Framework::Either<Block*, int> GrasslandBiom::generateCaveBlock(
  50. int x, int y, int z)
  51. {
  52. return BlockTypeEnum::AIR;
  53. }
  54. Noise* GrasslandBiom::zHeightMapNoise(int seed)
  55. {
  56. if (heightNoise) return heightNoise;
  57. FastNoiseLite* noise = new FastNoiseLite(seed);
  58. noise->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_ValueCubic);
  59. FastNoiseWrapper* wrapper = new FastNoiseWrapper(noise, seed);
  60. wrapper->setMultiplier(0.2f);
  61. heightNoise = wrapper;
  62. return heightNoise;
  63. }