implement blocks data saving/loading
This commit is contained in:
@@ -68,6 +68,9 @@ WorldRegions::WorldRegions(const fs::path& directory) : directory(directory) {
|
||||
layers[REGION_LAYER_INVENTORIES].folder =
|
||||
directory / fs::path("inventories");
|
||||
layers[REGION_LAYER_ENTITIES].folder = directory / fs::path("entities");
|
||||
|
||||
auto& blocksData = layers[REGION_LAYER_BLOCKS_DATA];
|
||||
blocksData.folder = directory / fs::path("blocksdata");
|
||||
}
|
||||
|
||||
WorldRegions::~WorldRegions() = default;
|
||||
@@ -188,6 +191,15 @@ void WorldRegions::put(Chunk* chunk, std::vector<ubyte> entitiesData) {
|
||||
std::move(data),
|
||||
entitiesData.size());
|
||||
}
|
||||
// Writing blocks data
|
||||
if (chunk->flags.blocksData) {
|
||||
auto bytes = chunk->blocksMetadata.serialize();
|
||||
put(chunk->x,
|
||||
chunk->z,
|
||||
REGION_LAYER_BLOCKS_DATA,
|
||||
bytes.release(),
|
||||
bytes.size());
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<ubyte[]> WorldRegions::getVoxels(int x, int z) {
|
||||
@@ -227,6 +239,18 @@ chunk_inventories_map WorldRegions::fetchInventories(int x, int z) {
|
||||
return load_inventories(bytes, bytesSize);
|
||||
}
|
||||
|
||||
BlocksMetadata WorldRegions::getBlocksData(int x, int z) {
|
||||
uint32_t bytesSize;
|
||||
uint32_t srcSize;
|
||||
auto bytes = layers[REGION_LAYER_BLOCKS_DATA].getData(x, z, bytesSize, srcSize);
|
||||
if (bytes == nullptr) {
|
||||
return {};
|
||||
}
|
||||
BlocksMetadata heap;
|
||||
heap.deserialize(bytes, bytesSize);
|
||||
return heap;
|
||||
}
|
||||
|
||||
void WorldRegions::processInventories(
|
||||
int x, int z, const inventoryproc& func
|
||||
) {
|
||||
|
||||
@@ -216,6 +216,8 @@ public:
|
||||
std::unique_ptr<light_t[]> getLights(int x, int z);
|
||||
|
||||
chunk_inventories_map fetchInventories(int x, int z);
|
||||
|
||||
BlocksMetadata getBlocksData(int x, int z);
|
||||
|
||||
/// @brief Load saved entities data for chunk
|
||||
/// @param x chunk.x
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
static inline size_t VOXELS_DATA_SIZE_V1 = CHUNK_VOL * 4;
|
||||
static inline size_t VOXELS_DATA_SIZE_V2 = CHUNK_VOL * 4;
|
||||
|
||||
#include <iostream>
|
||||
static util::Buffer<ubyte> convert_voxels_1to2(const ubyte* buffer, uint32_t size) {
|
||||
auto data = compression::decompress(
|
||||
buffer, size, VOXELS_DATA_SIZE_V1, compression::Method::EXTRLE8);
|
||||
@@ -40,11 +39,9 @@ static util::Buffer<ubyte> convert_voxels_1to2(const ubyte* buffer, uint32_t siz
|
||||
return util::Buffer<ubyte>(std::move(compressed), outLen);
|
||||
}
|
||||
|
||||
#include "util/timeutil.hpp"
|
||||
util::Buffer<ubyte> compatibility::convert_region_2to3(
|
||||
const util::Buffer<ubyte>& src, RegionLayerIndex layer
|
||||
) {
|
||||
timeutil::ScopeLogTimer log(555);
|
||||
const size_t REGION_CHUNKS = 1024;
|
||||
const size_t HEADER_SIZE = 10;
|
||||
const size_t OFFSET_TABLE_SIZE = REGION_CHUNKS * sizeof(uint32_t);
|
||||
@@ -95,7 +92,8 @@ util::Buffer<ubyte> compatibility::convert_region_2to3(
|
||||
builder.put(data, size);
|
||||
break;
|
||||
case REGION_LAYER_ENTITIES:
|
||||
case REGION_LAYER_INVENTORIES: {
|
||||
case REGION_LAYER_INVENTORIES:
|
||||
case REGION_LAYER_BLOCKS_DATA: {
|
||||
builder.putInt32(size);
|
||||
builder.putInt32(size);
|
||||
builder.put(data, size);
|
||||
|
||||
@@ -7,6 +7,7 @@ enum RegionLayerIndex : uint {
|
||||
REGION_LAYER_LIGHTS,
|
||||
REGION_LAYER_INVENTORIES,
|
||||
REGION_LAYER_ENTITIES,
|
||||
REGION_LAYER_BLOCKS_DATA,
|
||||
|
||||
REGION_LAYERS_COUNT
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user