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:
parent
46044e6d77
commit
1f82226a76
3 changed files with 12 additions and 13 deletions
|
@ -230,17 +230,16 @@ void MapBlock::copyFrom(const VoxelManipulator &src)
|
||||||
tryShrinkNodes();
|
tryShrinkNodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapBlock::reallocate(u32 c, MapNode n)
|
void MapBlock::reallocate(u32 count, MapNode n)
|
||||||
{
|
{
|
||||||
delete[] data;
|
delete[] data;
|
||||||
if (!m_is_mono_block && c == 1)
|
if (!m_is_mono_block && count == 1)
|
||||||
porting::TrackFreedMemory(sizeof(MapNode) * nodecount);
|
porting::TrackFreedMemory(sizeof(MapNode) * nodecount);
|
||||||
|
|
||||||
data = new MapNode[c];
|
data = new MapNode[count];
|
||||||
for (u32 i = 0; i < c; i++)
|
std::fill_n(data, count, n);
|
||||||
data[i] = n;
|
|
||||||
|
|
||||||
m_is_mono_block = (c == 1);
|
m_is_mono_block = (count == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapBlock::tryShrinkNodes()
|
void MapBlock::tryShrinkNodes()
|
||||||
|
@ -308,7 +307,7 @@ void MapBlock::expireIsAirCache()
|
||||||
// Renumbers the content IDs (starting at 0 and incrementing)
|
// Renumbers the content IDs (starting at 0 and incrementing)
|
||||||
// Note that there's no technical reason why we *have to* renumber the IDs,
|
// Note that there's no technical reason why we *have to* renumber the IDs,
|
||||||
// but we do it anyway as it also helps compressability.
|
// 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)
|
const NodeDefManager *nodedef, u32 nodecount)
|
||||||
{
|
{
|
||||||
IdIdMapping &mapping = IdIdMapping::giveClearedThreadLocalInstance();
|
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;
|
const size_t size = m_is_mono_block ? 1 : nodecount;
|
||||||
auto tmp_nodes = std::make_unique<MapNode[]>(size);
|
auto tmp_nodes = std::make_unique<MapNode[]>(size);
|
||||||
std::copy(data, data+size, tmp_nodes.get());
|
std::copy_n(data, size, tmp_nodes.get());
|
||||||
getBlockNodeIdMapping(&nimap, tmp_nodes, m_gamedef->ndef(), size);
|
getBlockNodeIdMapping(&nimap, tmp_nodes.get(), m_gamedef->ndef(), size);
|
||||||
|
|
||||||
buf = MapNode::serializeBulk(version, tmp_nodes.get(), nodecount,
|
buf = MapNode::serializeBulk(version, tmp_nodes.get(), nodecount,
|
||||||
content_width, params_width, m_is_mono_block);
|
content_width, params_width, m_is_mono_block);
|
||||||
|
|
|
@ -444,7 +444,7 @@ private:
|
||||||
void tryShrinkNodes();
|
void tryShrinkNodes();
|
||||||
// if only a single node is stored, expand storage back to the full array
|
// if only a single node is stored, expand storage back to the full array
|
||||||
void expandNodesIfNeeded();
|
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
|
* PLEASE NOTE: When adding something here be mindful of position and size
|
||||||
|
|
|
@ -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 z = 0; z < size.Z; z++) {
|
||||||
for (s16 y = 0; y < size.Y; y++) {
|
for (s16 y = 0; y < size.Y; y++) {
|
||||||
if (n_nodes == 1) {
|
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 {
|
} 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_src += src_step;
|
||||||
i_local += dest_step;
|
i_local += dest_step;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue