FeatherMC/src/world/RegionFile.h

43 lines
1.1 KiB
C
Raw Normal View History

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