mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-09 13:01:49 +00:00
reduce allocations while reading chunks data
This commit is contained in:
parent
21f7390265
commit
9dc9441902
12 changed files with 93 additions and 43 deletions
|
|
@ -215,33 +215,29 @@ void WorldRegions::put(Chunk* chunk, std::vector<ubyte> entitiesData) {
|
|||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<ubyte[]> WorldRegions::getVoxels(int x, int z) {
|
||||
bool WorldRegions::getVoxels(int x, int z, ubyte* dst) {
|
||||
uint32_t size;
|
||||
uint32_t srcSize;
|
||||
auto& layer = layers[REGION_LAYER_VOXELS];
|
||||
auto* data = layer.getData(x, z, size, srcSize);
|
||||
if (data == nullptr) {
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
assert(srcSize == CHUNK_DATA_LEN);
|
||||
return compression::decompress(data, size, srcSize, layer.compression);
|
||||
compression::decompress({data, size}, dst, CHUNK_DATA_LEN, layer.compression);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::unique_ptr<light_t[]> WorldRegions::getLights(int x, int z) {
|
||||
bool WorldRegions::getLights(int x, int z, ubyte* dst) {
|
||||
uint32_t size;
|
||||
uint32_t srcSize;
|
||||
auto& layer = layers[REGION_LAYER_LIGHTS];
|
||||
auto* bytes = layer.getData(x, z, size, srcSize);
|
||||
if (bytes == nullptr) {
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
auto data = compression::decompress(
|
||||
bytes, size, srcSize, layer.compression
|
||||
);
|
||||
if (srcSize == LIGHTMAP_DATA_LEN) {
|
||||
return Lightmap::decode(data.get());
|
||||
}
|
||||
return nullptr;
|
||||
compression::decompress({bytes, size}, dst, srcSize, layer.compression);
|
||||
return true;
|
||||
}
|
||||
|
||||
ChunkInventoriesMap WorldRegions::fetchInventories(int x, int z) {
|
||||
|
|
|
|||
|
|
@ -207,12 +207,12 @@ public:
|
|||
/// @brief Get chunk voxels data
|
||||
/// @param x chunk.x
|
||||
/// @param z chunk.z
|
||||
/// @return voxels data buffer or nullptr
|
||||
std::unique_ptr<ubyte[]> getVoxels(int x, int z);
|
||||
/// @return true if data read
|
||||
bool getVoxels(int x, int z, ubyte* dst);
|
||||
|
||||
/// @brief Get cached lights for chunk at x,z
|
||||
/// @return lights data or nullptr
|
||||
std::unique_ptr<light_t[]> getLights(int x, int z);
|
||||
/// @return true if data read
|
||||
bool getLights(int x, int z, ubyte* dst);
|
||||
|
||||
ChunkInventoriesMap fetchInventories(int x, int z);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue