12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- #include "Chunk.h"
- #include <cstdlib>
- #include <cmath>
- 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;
- }
-
- for(int y = 0; y < maxY; y++)
- {
- blocks[y][x][z] = 1;
- }
- for(int y = maxY; y < HEIGHT; y++)
- {
- blocks[y][x][z] = 0;
- }
- }
- }
- }
- Chunk::~Chunk()
- {
- }
- void Chunk::setBlock(int x, int y, int z, unsigned short block)
- {
- blocks[y & BITMASK_HEIGHT][x & BITMASK_WIDTH][z & BITMASK_DEPTH] = block;
- }
- unsigned short Chunk::getBlock(int x, int y, int z)
- {
- return 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;
- }
- }
|