GrasslandBiom.cpp 1.8 KB

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