FeatherMC/src/world/RegionFile.h

29 lines
833 B
C++

#pragma once
#include "Common.h"
#include "Types.h"
#include <string>
namespace Feather
{
class RegionFile
{
char m_header[8KB];
int32_t m_offsets[1KB];
inline int GetOffsetIndex(RegionLocalPos pos) { return pos.x + pos.z * 32; }
public:
RegionFile(std::string path);
// Packed data about the offset into the region file to parse chunk data from
inline int GetOffset(RegionLocalPos pos) { return m_offsets[GetOffsetIndex(pos)]; }
// Contains data for this chunk?
inline bool HasChunk(ChunkPos pos) { return GetOffset(RegionLocalPos(pos)) != 0; }
// Unpack sector num from result of GetOffset()
static int GetSectorNumber(int packedOffset) { return packedOffset >> 8; }
// Unpack sector count from result of GetOffset()
static int GetSectorCount(int packedOffset) { return packedOffset & 0xFF; }
};
}