1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-09-15 18:57:08 +00:00

minor cleanups

This commit is contained in:
Lars 2025-06-16 18:58:54 -07:00
parent 46044e6d77
commit 1f82226a76
3 changed files with 12 additions and 13 deletions

View file

@ -230,17 +230,16 @@ void MapBlock::copyFrom(const VoxelManipulator &src)
tryShrinkNodes();
}
void MapBlock::reallocate(u32 c, MapNode n)
void MapBlock::reallocate(u32 count, MapNode n)
{
delete[] data;
if (!m_is_mono_block && c == 1)
if (!m_is_mono_block && count == 1)
porting::TrackFreedMemory(sizeof(MapNode) * nodecount);
data = new MapNode[c];
for (u32 i = 0; i < c; i++)
data[i] = n;
data = new MapNode[count];
std::fill_n(data, count, n);
m_is_mono_block = (c == 1);
m_is_mono_block = (count == 1);
}
void MapBlock::tryShrinkNodes()
@ -308,7 +307,7 @@ void MapBlock::expireIsAirCache()
// Renumbers the content IDs (starting at 0 and incrementing)
// Note that there's no technical reason why we *have to* renumber the IDs,
// but we do it anyway as it also helps compressability.
static void getBlockNodeIdMapping(NameIdMapping *nimap, const std::unique_ptr<MapNode[]> &nodes,
static void getBlockNodeIdMapping(NameIdMapping *nimap, MapNode *nodes,
const NodeDefManager *nodedef, u32 nodecount)
{
IdIdMapping &mapping = IdIdMapping::giveClearedThreadLocalInstance();
@ -429,8 +428,8 @@ void MapBlock::serialize(std::ostream &os_compressed, u8 version, bool disk, int
{
const size_t size = m_is_mono_block ? 1 : nodecount;
auto tmp_nodes = std::make_unique<MapNode[]>(size);
std::copy(data, data+size, tmp_nodes.get());
getBlockNodeIdMapping(&nimap, tmp_nodes, m_gamedef->ndef(), size);
std::copy_n(data, size, tmp_nodes.get());
getBlockNodeIdMapping(&nimap, tmp_nodes.get(), m_gamedef->ndef(), size);
buf = MapNode::serializeBulk(version, tmp_nodes.get(), nodecount,
content_width, params_width, m_is_mono_block);

View file

@ -444,7 +444,7 @@ private:
void tryShrinkNodes();
// if only a single node is stored, expand storage back to the full array
void expandNodesIfNeeded();
void reallocate(u32 c, MapNode n);
void reallocate(u32 count, MapNode n);
/*
* PLEASE NOTE: When adding something here be mindful of position and size

View file

@ -217,11 +217,11 @@ void VoxelManipulator::copyFrom(MapNode *src, size_t n_nodes, const VoxelArea& s
for (s16 z = 0; z < size.Z; z++) {
for (s16 y = 0; y < size.Y; y++) {
if (n_nodes == 1) {
std::fill(m_data + i_local, m_data + i_local + size.X, src[0]);
std::fill_n(m_data + i_local, size.X, src[0]);
} else {
std::copy(src + i_src, src + i_src + size.X, m_data + i_local);
std::copy_n(src + i_src, size.X, m_data + i_local);
}
std::fill(m_flags + i_local, m_flags + i_local + size.X, 0);
std::fill_n(m_flags + i_local, size.X, 0);
i_src += src_step;
i_local += dest_step;
}