FeatherMC/src/world/RegionFile.cpp

34 lines
799 B
C++
Raw Normal View History

2020-08-07 05:48:54 +01:00
#include "RegionFile.h"
#include "util/ByteUtil.h"
#include <fstream>
using std::string;
namespace Feather
{
RegionFile::RegionFile(string path)
2020-08-13 04:15:51 +01:00
: m_path(path)
2020-08-07 05:48:54 +01:00
{
2020-08-13 04:15:51 +01:00
m_stream = new std::ifstream(path, std::ifstream::binary);
m_stream->read(m_header, 8KB);
2020-08-07 05:48:54 +01:00
// Populate m_offsets
2020-08-08 03:45:04 +01:00
for (int i = 0; i < 1024; i++)
2020-08-07 05:48:54 +01:00
{
int32_t readInt = 0;
2020-08-13 04:15:51 +01:00
std::memcpy(&readInt, &m_header[i * sizeof(int32_t)], sizeof(int32_t));
2020-08-07 05:48:54 +01:00
// Read big endian ints.
readInt = ReverseBytes(readInt);
m_offsets[i] = readInt;
if (readInt == 0) continue;
//int sector = GetSectorNumber(readInt);
//int sectorCount = GetSectorCount(readInt);
2020-08-13 04:15:51 +01:00
//Log::Trace("{}: Sector [{:x}] Count:{} Num:{}", i, readInt, sectorCount, sector);
2020-08-07 05:48:54 +01:00
// We can record which sectors are used by this region here
}
}
}