FeatherMC/src/world/Chunk.h

52 lines
1.1 KiB
C
Raw Normal View History

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