GrasslandBiom.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. addTemplateGenerator(new TreeTemplate(0.0025f, PineBlockType::INSTANCE, LeavesBlockType::INSTANCE, 15, 24));
  14. heightNoise = 0;
  15. }
  16. GrasslandBiom::~GrasslandBiom()
  17. {
  18. if (heightNoise)
  19. heightNoise->release();
  20. }
  21. Framework::Either<Block*, int> GrasslandBiom::generateSurfaceBlock(int x, int y, int z)
  22. {
  23. if (((float)rand() / (float)RAND_MAX) < 0.05f) // TODO: use random noise
  24. return CobbleBlockType::ID;
  25. return DirtBlockType::ID;
  26. }
  27. Framework::Either<Block*, int> GrasslandBiom::generateBelowSurfaceBlock(int x, int y, int z)
  28. {
  29. return StoneBlockType::ID;
  30. }
  31. Noise* GrasslandBiom::zHeightMapNoise(int seed)
  32. {
  33. if (heightNoise)
  34. return heightNoise;
  35. FastNoiseLite* noise = new FastNoiseLite(seed);
  36. noise->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_ValueCubic);
  37. FastNoiseWrapper* wrapper = new FastNoiseWrapper(noise, seed);
  38. wrapper->setMultiplier(0.2f);
  39. heightNoise = wrapper;
  40. return heightNoise;
  41. }