This commit is contained in:
Lars Mueller 2024-05-20 01:52:32 +02:00
parent 2bcb715386
commit e305d2c138
3 changed files with 7 additions and 3 deletions

@ -55,7 +55,7 @@ class ActiveObjectMgr
for (auto &it : m_active_objects.iter()) {
if (!it.second)
continue;
m_active_objects.remove(it.first);
removeObject(it.first);
}
} while (!m_active_objects.empty());
}

@ -41,7 +41,7 @@ void ActiveObjectMgr::clearIf(const std::function<bool(ServerActiveObject *, u16
continue;
if (cb(it.second.get(), it.first)) {
// Remove reference from m_active_objects
m_active_objects.remove(it.first);
removeObject(it.first);
}
}
}
@ -94,6 +94,7 @@ bool ActiveObjectMgr::registerObject(std::unique_ptr<ServerActiveObject> obj)
auto obj_id = obj->getId();
m_active_objects.put(obj_id, std::move(obj));
m_spatial_index.insert(pos.toArray(), obj_id);
assert(m_spatial_index.size() == m_active_objects.size());
auto new_size = m_active_objects.size();
verbosestream << "Server::ActiveObjectMgr::addActiveObjectRaw(): "

@ -418,7 +418,7 @@ class DynamicKdTrees {
trees.at(it->second.tree_idx).remove(it->second.in_tree);
del_entries.erase(it);
++deleted;
if (deleted > n_entries/2) // "shift out" the last tree
if (deleted >= (n_entries+1)/2) // "shift out" the last tree
shrink_to_half();
}
void update(const Point &newPos, Id id) {
@ -431,6 +431,9 @@ class DynamicKdTrees {
for (const auto &tree : trees)
tree.rangeQuery(min, max, cb);
}
Idx size() const {
return n_entries - deleted;
}
private:
void updateDelEntries(uint8_t tree_idx) {
trees[tree_idx].foreach([&](Idx in_tree_idx, auto _, Id id) {