1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- #include "Chunk.h"
- #include <cstdlib>
- #include <cmath>
- #include "../block/Blocks.h"
- #include <iostream>
- 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;
- }
- }
|