upgrade regions format version to 3
This commit is contained in:
+1
-59
@@ -77,33 +77,6 @@ std::unique_ptr<Chunk> Chunk::clone() const {
|
||||
return other;
|
||||
}
|
||||
|
||||
/**
|
||||
Current chunk format:
|
||||
- byte-order: big-endian
|
||||
- [don't panic!] first and second bytes are separated for RLE efficiency
|
||||
|
||||
```cpp
|
||||
uint8_t voxel_id_first_byte[CHUNK_VOL];
|
||||
uint8_t voxel_id_second_byte[CHUNK_VOL];
|
||||
uint8_t voxel_states_first_byte[CHUNK_VOL];
|
||||
uint8_t voxel_states_second_byte[CHUNK_VOL];
|
||||
```
|
||||
|
||||
Total size: (CHUNK_VOL * 4) bytes
|
||||
*/
|
||||
std::unique_ptr<ubyte[]> Chunk::encode() const {
|
||||
auto buffer = std::make_unique<ubyte[]>(CHUNK_DATA_LEN);
|
||||
for (uint i = 0; i < CHUNK_VOL; i++) {
|
||||
buffer[i] = voxels[i].id >> 8;
|
||||
buffer[CHUNK_VOL + i] = voxels[i].id & 0xFF;
|
||||
|
||||
blockstate_t state = blockstate2int(voxels[i].state);
|
||||
buffer[CHUNK_VOL * 2 + i] = state >> 8;
|
||||
buffer[CHUNK_VOL * 3 + i] = state & 0xFF;
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
Current chunk format:
|
||||
- byte-order: little-endian
|
||||
@@ -115,7 +88,7 @@ std::unique_ptr<ubyte[]> Chunk::encode() const {
|
||||
|
||||
Total size: (CHUNK_VOL * 4) bytes
|
||||
*/
|
||||
std::unique_ptr<ubyte[]> Chunk::encodeV2() const {
|
||||
std::unique_ptr<ubyte[]> Chunk::encode() const {
|
||||
auto buffer = std::make_unique<ubyte[]>(CHUNK_DATA_LEN);
|
||||
auto dst = reinterpret_cast<uint16_t*>(buffer.get());
|
||||
for (uint i = 0; i < CHUNK_VOL; i++) {
|
||||
@@ -126,26 +99,6 @@ std::unique_ptr<ubyte[]> Chunk::encodeV2() const {
|
||||
}
|
||||
|
||||
bool Chunk::decode(const ubyte* data) {
|
||||
for (uint i = 0; i < CHUNK_VOL; i++) {
|
||||
voxel& vox = voxels[i];
|
||||
|
||||
ubyte bid1 = data[i];
|
||||
ubyte bid2 = data[CHUNK_VOL + i];
|
||||
|
||||
ubyte bst1 = data[CHUNK_VOL * 2 + i];
|
||||
ubyte bst2 = data[CHUNK_VOL * 3 + i];
|
||||
|
||||
vox.id =
|
||||
(static_cast<blockid_t>(bid1) << 8) | static_cast<blockid_t>(bid2);
|
||||
vox.state = int2blockstate(
|
||||
(static_cast<blockstate_t>(bst1) << 8) |
|
||||
static_cast<blockstate_t>(bst2)
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Chunk::decodeV2(const ubyte* data) {
|
||||
auto src = reinterpret_cast<const uint16_t*>(data);
|
||||
for (uint i = 0; i < CHUNK_VOL; i++) {
|
||||
voxel& vox = voxels[i];
|
||||
@@ -157,17 +110,6 @@ bool Chunk::decodeV2(const ubyte* data) {
|
||||
}
|
||||
|
||||
void Chunk::convert(ubyte* data, const ContentReport* report) {
|
||||
for (uint i = 0; i < CHUNK_VOL; i++) {
|
||||
blockid_t id =
|
||||
((static_cast<blockid_t>(data[i]) << 8) |
|
||||
static_cast<blockid_t>(data[CHUNK_VOL + i]));
|
||||
blockid_t replacement = report->blocks.getId(id);
|
||||
data[i] = replacement >> 8;
|
||||
data[CHUNK_VOL + i] = replacement & 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
void Chunk::convertV2(ubyte* data, const ContentReport* report) {
|
||||
auto buffer = reinterpret_cast<uint16_t*>(data);
|
||||
for (uint i = 0; i < CHUNK_VOL; i++) {
|
||||
blockid_t id = dataio::le2h(buffer[i]);
|
||||
|
||||
Reference in New Issue
Block a user