#include "Chunk.hpp" #include #include "../geometry/math.hpp" using namespace world; Chunk::Chunk(std::istream& str) { voxels.resize(CHUNK_SIZE); if constexpr(RLE) { uint16_t i = 0; while(!str.eof()) { uint16_t count; Voxel voxel; str.read(reinterpret_cast(&count), sizeof(count)); str.read(reinterpret_cast(&voxel), sizeof(voxel)); str.peek(); for (; count > 0; count--) { voxels[i] = voxel; i++; } } assert((i == 1 || i == CHUNK_SIZE) && "Mismatch data length"); if (i == 1) { voxels.resize(1); voxels.shrink_to_fit(); } } else { for(auto& voxel: voxels) { str.read(reinterpret_cast(&voxel), sizeof(voxel)); } } } Chunk::Chunk(Voxel v): voxels({v}) { } Chunk::~Chunk() { } const Voxel &Chunk::getAt(const chunk_voxel_pos &pos) const { return get(glm::toIdx(pos)); }