|
@@ -1,98 +1,26 @@
|
|
|
-#include <cstdlib>
|
|
|
-#include <cmath>
|
|
|
-#include <iostream>
|
|
|
-
|
|
|
#include "common/world/Chunk.h"
|
|
|
-#include "common/block/Blocks.h"
|
|
|
-
|
|
|
-using namespace std;
|
|
|
+#include "common/block/BlockRegistry.h"
|
|
|
|
|
|
-Chunk::Chunk(int chunkX, int chunkZ) : chunkX(chunkX), chunkZ(chunkZ)
|
|
|
+Chunk::Chunk()
|
|
|
{
|
|
|
- for(int i = 0; i < HEIGHT_PARTIONS; i++)
|
|
|
+ for(u32 y = 0; y < HEIGHT; y++)
|
|
|
{
|
|
|
- dirty[i] = true;
|
|
|
- }
|
|
|
- for(int z = 0; z < DEPTH; z++)
|
|
|
- {
|
|
|
- for(int x = 0; x < WIDTH; x++)
|
|
|
+ for(u32 x = 0; x < CHUNK_PARTION_SIZE; x++)
|
|
|
{
|
|
|
- int maxY = (int) (sinf((x + chunkX * WIDTH) * 0.3) * 20 + 22) + (sinf((z + chunkZ * DEPTH) * 0.3) * 20 + 22);
|
|
|
-
|
|
|
- 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++)
|
|
|
+ for(u32 z = 0; z < CHUNK_PARTION_SIZE; z++)
|
|
|
{
|
|
|
- setBlock(x, y, z, Blocks::DIRT);
|
|
|
+ blocks[y][x][z] = 0;
|
|
|
}
|
|
|
-
|
|
|
- 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
|
|
|
+const Block& Chunk::getBlock(u32 x, u32 y, u32 z) const
|
|
|
{
|
|
|
- if(index >= 0 && index < HEIGHT_PARTIONS)
|
|
|
- {
|
|
|
- return dirty[index];
|
|
|
- }
|
|
|
- return false;
|
|
|
+ return BlockRegistry::getBlock(blocks[y & BITMASK_HEIGHT][x & CHUNK_PARTION_SIZE][z & CHUNK_PARTION_SIZE]);
|
|
|
}
|
|
|
|
|
|
-void Chunk::clearDirtyFlag(int index)
|
|
|
+void Chunk::setBlock(u32 x, u32 y, u32 z, const Block& block)
|
|
|
{
|
|
|
- if(index >= 0 && index < HEIGHT_PARTIONS)
|
|
|
- {
|
|
|
- dirty[index] = false;
|
|
|
- }
|
|
|
-}
|
|
|
+ blocks[y & BITMASK_HEIGHT][x & CHUNK_PARTION_SIZE][z & CHUNK_PARTION_SIZE] = block.getId();
|
|
|
+}
|