mirror of
https://github.com/minetest/minetest.git
synced 2024-07-04 15:05:27 +02:00
Code Cleanup
This commit is contained in:
parent
7e504cbd37
commit
42fdaa9838
@ -26,14 +26,15 @@ namespace server
|
||||
// all inserted entires go into the uncached vector
|
||||
void SpatialMap::insert(u16 id, const v3f &pos, bool postIteration)
|
||||
{
|
||||
if(!m_iterators_stopping_insertion_and_deletion) {
|
||||
if (m_iterators_stopping_insertion_and_deletion) {
|
||||
m_pending_inserts.insert(SpatialKey(pos, id));
|
||||
return;
|
||||
}
|
||||
|
||||
SpatialKey key(pos);
|
||||
if (postIteration)
|
||||
key = SpatialKey(pos.X, pos.Y, pos.Z, true);
|
||||
m_cached.insert({key, id});
|
||||
} else {
|
||||
m_pending_inserts.insert(SpatialKey(pos,id));
|
||||
}
|
||||
}
|
||||
|
||||
// Invalidates upon position update
|
||||
@ -53,7 +54,11 @@ void SpatialMap::updatePosition(u16 id, const v3f &oldPos, const v3f &newPos)
|
||||
|
||||
void SpatialMap::remove(u16 id, const v3f &pos, bool postIteration)
|
||||
{
|
||||
if(!m_iterators_stopping_insertion_and_deletion) {
|
||||
if (m_iterators_stopping_insertion_and_deletion) {
|
||||
m_pending_deletes.insert(SpatialKey(pos, id));
|
||||
return;
|
||||
}
|
||||
|
||||
SpatialKey key(pos);
|
||||
if (postIteration)
|
||||
key = SpatialKey(pos.X, pos.Y, pos.Z, true);
|
||||
@ -66,40 +71,40 @@ void SpatialMap::remove(u16 id, const v3f &pos, bool postIteration)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
m_pending_deletes.insert(SpatialKey(pos, id));
|
||||
return;
|
||||
}
|
||||
|
||||
remove(id); // should never be hit
|
||||
}
|
||||
|
||||
void SpatialMap::remove(u16 id)
|
||||
{
|
||||
if(!m_iterators_stopping_insertion_and_deletion) {
|
||||
if(m_iterators_stopping_insertion_and_deletion) {
|
||||
m_pending_deletes.insert(SpatialKey(v3f(), id));
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto it = m_cached.begin(); it != m_cached.end(); ++it) {
|
||||
if (it->second == id) {
|
||||
m_cached.erase(it);
|
||||
break; // Erase and leave early
|
||||
return; // Erase and leave early
|
||||
}
|
||||
}
|
||||
} else {
|
||||
m_pending_deletes.insert(SpatialKey(v3f(), id));
|
||||
}
|
||||
}
|
||||
|
||||
void SpatialMap::removeAll()
|
||||
{
|
||||
if(!m_iterators_stopping_insertion_and_deletion) {
|
||||
m_cached.clear();
|
||||
} else {
|
||||
if(m_iterators_stopping_insertion_and_deletion) {
|
||||
m_remove_all = true;
|
||||
} else {
|
||||
m_cached.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void SpatialMap::getRelevantObjectIds(const aabb3f &box, const std::function<void(u16 id)> &callback)
|
||||
{
|
||||
if(!m_cached.empty()) {
|
||||
// when searching, we must round to maximum extent of relevant mapblock indexes
|
||||
if (m_cached.empty()) return;
|
||||
|
||||
// When searching, we must round to maximum extent of relevant mapblock indexes.
|
||||
// Since we're using floats, always assume +-1
|
||||
auto low = [](f32 val) -> s16 {
|
||||
s16 _val = static_cast<s16>(val / BS);
|
||||
return (_val >> 4) - 1;
|
||||
@ -143,11 +148,12 @@ void SpatialMap::getRelevantObjectIds(const aabb3f &box, const std::function<voi
|
||||
handleInsertsAndDeletes();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SpatialMap::handleInsertsAndDeletes()
|
||||
{
|
||||
if(!m_iterators_stopping_insertion_and_deletion) {
|
||||
if (m_iterators_stopping_insertion_and_deletion)
|
||||
return;
|
||||
|
||||
if(!m_remove_all) {
|
||||
for (auto key : m_pending_deletes) {
|
||||
remove(key.padding_or_optional_id, v3f(key.x, key.y, key.z), true);
|
||||
@ -162,6 +168,5 @@ void SpatialMap::handleInsertsAndDeletes()
|
||||
m_pending_inserts.clear();
|
||||
m_pending_deletes.clear();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace server
|
||||
|
Loading…
Reference in New Issue
Block a user