12345678910111213141516171819202122232425262728 |
- #include "common/world/World.h"
- #include "common/utils/Random.h"
- #include "common/world/HighMap.h"
- World::World(const BlockRegistry& blockRegistry) : blockRegistry(blockRegistry) {
- Block air = blockRegistry.getBlock("air");
- Block stone = blockRegistry.getBlock("stone");
- HighMap<WORLD_SIZE, WORLD_SIZE> map;
- for(uint x = 0; x < WORLD_SIZE; x++) {
- for(uint z = 0; z < WORLD_SIZE; z++) {
- uint height = map.getHeight(x, z, WORLD_SIZE);
- for(uint y = 0; y < height; y++) {
- setBlock(x, y, z, stone);
- }
- for(uint y = height; y < WORLD_SIZE; y++) {
- setBlock(x, y, z, air);
- }
- }
- }
- }
- void World::setBlock(uint x, uint y, uint z, const Block& block) {
- blocks[x & BITMASK][y & BITMASK][z & BITMASK] = block.getId();
- }
- const Block& World::getBlock(uint x, uint y, uint z) const {
- return blockRegistry.getBlock(blocks[x & BITMASK][y & BITMASK][z & BITMASK]);
- }
|