#include #include #include #include "common/world/Chunk.h" #include "common/block/Blocks.h" using namespace std; Chunk::Chunk(int chunkX, int chunkZ) : chunkX(chunkX), chunkZ(chunkZ) { for(int i = 0; i < HEIGHT_PARTIONS; i++) { dirty[i] = true; } for(int z = 0; z < DEPTH; z++) { for(int x = 0; x < WIDTH; x++) { int maxY = (int) (sinf((x + chunkX * WIDTH) * 0.3) * 20 + 22) + (sinf((z + chunkZ * DEPTH) * 0.3) * 20 + 22); //maxY = 10; if(maxY >= HEIGHT) { maxY = HEIGHT - 1; } for(int y = 0; y < maxY - 3; y++) { setBlock(x, y, z, Blocks::STONE); } for(int y = maxY - 3; y < maxY - 1; y++) { setBlock(x, y, z, Blocks::DIRT); } setBlock(x, maxY - 1, z, Blocks::GRASS); for(int y = maxY; y < HEIGHT; y++) { setBlock(x, y, z, Blocks::AIR); } } } } Chunk::~Chunk() { } void Chunk::setBlock(int x, int y, int z, const Block& block) { blocks[y & BITMASK_HEIGHT][x & BITMASK_WIDTH][z & BITMASK_DEPTH] = block.getId(); } const Block& Chunk::getBlock(int x, int y, int z) { return BlockRegistry::getBlockFromId(blocks[y & BITMASK_HEIGHT][x & BITMASK_WIDTH][z & BITMASK_DEPTH]); } int Chunk::getChunkX() const { return chunkX; } int Chunk::getChunkZ() const { return chunkZ; } bool Chunk::isDirty() const { for(int i = 0; i < HEIGHT_PARTIONS; i++) { if(dirty[i]) { return true; } } return false; } bool Chunk::isDirty(int index) const { if(index >= 0 && index < HEIGHT_PARTIONS) { return dirty[index]; } return false; } void Chunk::clearDirtyFlag(int index) { if(index >= 0 && index < HEIGHT_PARTIONS) { dirty[index] = false; } }