#pragma once #include #include "Voxel.hpp" namespace world { constexpr auto RLE = true; //NOTE: only ~2.5% gain after zstd /// World part as linear 3d voxel array or just a single one (32x LOD) class Chunk { public: Chunk(std::istream& str); virtual ~Chunk(); /// Get voxel from index inline const Voxel& get(chunk_voxel_idx idx) const { assert(isAllocated()); return voxels[isHeavy() ? idx : 0]; } /// Get voxel from position const Voxel &getAt(const chunk_voxel_pos &pos) const; inline bool isAllocated() const noexcept { return !voxels.empty(); } inline bool isHeavy() const noexcept { return voxels.size() > 1; } protected: Chunk(Voxel v); /// NOTE: voxels must be allocated by child constructor Chunk() { } /// Chunk data std::vector voxels; //MAYBE: manual handle }; }