GrasslandBiom.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "GrasslandBiom.h"
  2. #include "BlockType.h"
  3. #include "BasicBlocks.h"
  4. #include "FastNoiseLite.h"
  5. #include "FastNoiseWrapper.h"
  6. #include "TreeTemplate.h"
  7. GrasslandBiom::GrasslandBiom()
  8. : BiomGenerator()
  9. {
  10. addTemplateGenerator(new TreeTemplate(0.02f, BirchBlockType::INSTANCE, LeavesBlockType::INSTANCE, 8, 15));
  11. addTemplateGenerator(new TreeTemplate(0.01f, BeechBlockType::INSTANCE, LeavesBlockType::INSTANCE, 8, 13));
  12. addTemplateGenerator(new TreeTemplate(0.005f, OakBlockType::INSTANCE, LeavesBlockType::INSTANCE, 10, 15));
  13. heightNoise = 0;
  14. }
  15. GrasslandBiom::~GrasslandBiom()
  16. {
  17. if (heightNoise)
  18. heightNoise->release();
  19. }
  20. Framework::Either<Block*, int> GrasslandBiom::generateSurfaceBlock(int x, int y, int z)
  21. {
  22. if (((float)rand() / (float)RAND_MAX) < 0.05f) // TODO: use random noise
  23. return CobbleBlockType::ID;
  24. return DirtBlockType::ID;
  25. }
  26. Framework::Either<Block*, int> GrasslandBiom::generateBelowSurfaceBlock(int x, int y, int z)
  27. {
  28. return StoneBlockType::ID;
  29. }
  30. Noise* GrasslandBiom::zHeightMapNoise(int seed)
  31. {
  32. if (heightNoise)
  33. return heightNoise;
  34. FastNoiseLite* noise = new FastNoiseLite(seed);
  35. noise->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_ValueCubic);
  36. FastNoiseWrapper* wrapper = new FastNoiseWrapper(noise, seed);
  37. wrapper->setMultiplier(0.2f);
  38. heightNoise = wrapper;
  39. return heightNoise;
  40. }