reduce allocations while reading chunks data

This commit is contained in:
MihailRis 2025-12-06 00:58:13 +03:00
parent 21f7390265
commit 9dc9441902
12 changed files with 93 additions and 43 deletions

View file

@ -130,11 +130,11 @@ static int l_get_chunk_data(lua::State* L) {
int z = static_cast<int>(lua::tointeger(L, 2));
const auto& chunk = level->chunks->getChunk(x, z);
auto voxelData = std::make_unique<ubyte[]>(CHUNK_DATA_LEN);
std::vector<ubyte> chunkData;
if (chunk == nullptr) {
auto& regions = level->getWorld()->wfile->getRegions();
auto voxelData = regions.getVoxels(x, z);
if (voxelData == nullptr) {
if (!regions.getVoxels(x, z, voxelData.get())) {
return 0;
}
static util::Buffer<ubyte> rleBuffer(CHUNK_DATA_LEN * 2);