52 lines
1.1 KiB
C++
52 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include "Common.h"
|
|
#include "Types.h"
|
|
|
|
#include "nbt/NBT.h"
|
|
#include "PalettedContainer.h"
|
|
#include "block/state/BlockState.h"
|
|
|
|
namespace Feather
|
|
{
|
|
// 16x16x16 sections of a chunk
|
|
struct ChunkSection
|
|
{
|
|
static constexpr size_t NUM_BLOCKS = (16 * 16 * 16);
|
|
|
|
static constexpr size_t MAX_BITS = Math::CeilLog2(NUM_BLOCKS);
|
|
|
|
static constexpr size_t DEFAULT_BITS = 4;
|
|
|
|
PalettedContainer<uint64, NUM_BLOCKS, MAX_BITS> blockStates;
|
|
|
|
public:
|
|
ChunkSection() : blockStates(NUM_BLOCKS, DEFAULT_BITS) {}
|
|
};
|
|
|
|
// Chunk: 16x256x16 world chunk
|
|
class Chunk
|
|
{
|
|
public:
|
|
static constexpr int NUM_SECTIONS = 16;
|
|
|
|
// Each chunk is made of up 16 ChunkSections
|
|
ChunkSection sections[NUM_SECTIONS];
|
|
|
|
ChunkPos pos;
|
|
|
|
// TODO: Nuke this shit!
|
|
std::unique_ptr<NBT::CompoundTag> nbt;
|
|
|
|
// TODO: save heightmaps here
|
|
// UNSERIALIZED
|
|
//const NBT::CompoundTag* heightmaps;
|
|
|
|
Chunk(ChunkPos& pos, std::unique_ptr<NBT::CompoundTag> tag);
|
|
|
|
inline int GetSection(BlockPos& pos) { return pos.y >> 4; }
|
|
|
|
bool SetBlock(BlockPos& pos, BlockState& state);
|
|
};
|
|
};
|