mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-10 21:41:50 +00:00
feat: pre-read region chunks offsets table
This commit is contained in:
parent
2e44aa7d19
commit
1f73dc5d5e
2 changed files with 17 additions and 4 deletions
|
|
@ -50,6 +50,20 @@ regfile::regfile(io::path filename) : file(filename), filename(filename) {
|
||||||
" is not supported in " + filename.string()
|
" is not supported in " + filename.string()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t file_size = file.length();
|
||||||
|
size_t table_offset = file_size - REGION_CHUNKS_COUNT * 4;
|
||||||
|
|
||||||
|
file.seekg(table_offset);
|
||||||
|
file.read(
|
||||||
|
reinterpret_cast<char*>(offsets.data()),
|
||||||
|
sizeof(uint32_t) * REGION_CHUNKS_COUNT
|
||||||
|
);
|
||||||
|
if (dataio::is_big_endian()) {
|
||||||
|
for (size_t i = 0; i < offsets.size(); i++) {
|
||||||
|
offsets[i] = dataio::le2h(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<ubyte[]> regfile::read(
|
std::unique_ptr<ubyte[]> regfile::read(
|
||||||
|
|
@ -58,14 +72,12 @@ std::unique_ptr<ubyte[]> regfile::read(
|
||||||
size_t file_size = file.length();
|
size_t file_size = file.length();
|
||||||
size_t table_offset = file_size - REGION_CHUNKS_COUNT * 4;
|
size_t table_offset = file_size - REGION_CHUNKS_COUNT * 4;
|
||||||
|
|
||||||
uint32_t buff32;
|
uint32_t offset = offsets.at(index);
|
||||||
file.seekg(table_offset + index * 4);
|
|
||||||
file.read(reinterpret_cast<char*>(&buff32), 4);
|
|
||||||
uint32_t offset = dataio::le2h(buff32);
|
|
||||||
if (offset == 0) {
|
if (offset == 0) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t buff32;
|
||||||
file.seekg(offset);
|
file.seekg(offset);
|
||||||
file.read(reinterpret_cast<char*>(&buff32), 4);
|
file.read(reinterpret_cast<char*>(&buff32), 4);
|
||||||
size = dataio::le2h(buff32);
|
size = dataio::le2h(buff32);
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ struct regfile {
|
||||||
io::path filename;
|
io::path filename;
|
||||||
int version;
|
int version;
|
||||||
bool inUse = false;
|
bool inUse = false;
|
||||||
|
std::array<uint32_t, REGION_CHUNKS_COUNT> offsets;
|
||||||
|
|
||||||
regfile(io::path filename);
|
regfile(io::path filename);
|
||||||
regfile(const regfile&) = delete;
|
regfile(const regfile&) = delete;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue