World.cpp 983 B

12345678910111213141516171819202122232425262728
  1. #include "common/world/World.h"
  2. #include "common/utils/Random.h"
  3. #include "common/world/HighMap.h"
  4. World::World(const BlockRegistry& blockRegistry) : blockRegistry(blockRegistry) {
  5. Block air = blockRegistry.getBlock("air");
  6. Block stone = blockRegistry.getBlock("stone");
  7. HighMap<WORLD_SIZE, WORLD_SIZE> map;
  8. for(uint x = 0; x < WORLD_SIZE; x++) {
  9. for(uint z = 0; z < WORLD_SIZE; z++) {
  10. uint height = map.getHeight(x, z, WORLD_SIZE);
  11. for(uint y = 0; y < height; y++) {
  12. setBlock(x, y, z, stone);
  13. }
  14. for(uint y = height; y < WORLD_SIZE; y++) {
  15. setBlock(x, y, z, air);
  16. }
  17. }
  18. }
  19. }
  20. void World::setBlock(uint x, uint y, uint z, const Block& block) {
  21. blocks[x & BITMASK][y & BITMASK][z & BITMASK] = block.getId();
  22. }
  23. const Block& World::getBlock(uint x, uint y, uint z) const {
  24. return blockRegistry.getBlock(blocks[x & BITMASK][y & BITMASK][z & BITMASK]);
  25. }