FeatherMC/src/world/RegionFile.h

43 lines
1.1 KiB
C++

#pragma once
#include "Common.h"
#include "Types.h"
#include <string>
#include <iostream>
#include <fstream>
namespace Feather
{
class RegionFile
{
char m_header[8KB];
int32_t m_offsets[1KB];
// TEMP
std::ifstream* m_stream;
std::string m_path;
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; }
// TEMP
std::ifstream* GetChunkStream(RegionLocalPos pos) {
m_stream->seekg(GetSectorNumber(GetOffset(pos)));
return m_stream;
}
// Unpack sector num from result of GetOffset()
static int GetSectorNumber(int packedOffset) { return (packedOffset >> 8) * 4096; }
// Unpack sector count from result of GetOffset()
static int GetSectorCount(int packedOffset) { return packedOffset & 0xFF; }
};
}