Draft Working Version - Defintely not ready

This commit is contained in:
ExeVirus 2024-05-07 22:13:54 -04:00
parent 66866ba342
commit 1b1513e8e4
3 changed files with 27 additions and 1 deletions

View File

@ -62,7 +62,16 @@ void ActiveObjectMgr::step(
count++;
f(ao_it.second.get());
}
m_spatial_map.cacheUpdate([this](u16 id){ return getActiveObject(id)->getBasePosition(); });
m_spatial_map.cacheUpdate([this](u16 id)
{
auto obj = getActiveObject(id);
if(obj != nullptr) {
return obj->getBasePosition();
} else {
this->m_spatial_map.remove(id);
return v3f();
}
});
g_profiler->avg("ActiveObjectMgr: SAO count [#]", count);
}

View File

@ -49,6 +49,22 @@ void SpatialMap::invalidate(u16 id, v3f &pos)
}
}
void SpatialMap::remove(u16 id)
{
auto found = std::find(m_uncached.begin(), m_uncached.end(), id);
if (found != m_uncached.end()) {
m_uncached.erase(found);
return;
}
for (auto it = m_cached.begin(); it != m_cached.end();++it) {
if(it->second == id) {
m_cached.erase(it);
break;
}
}
// Error, this shouldn't ever be hit.
}
void SpatialMap::remove(u16 id, v3f pos)
{
SpatialKey key(pos);

View File

@ -36,6 +36,7 @@ public:
// On active_object removal, remove.
void remove(u16 id, v3f pos);
void remove(u16 id);
// Only when at least 64 uncached objects or 10% uncached overall
void cacheUpdate(const std::function<v3f(u16)> &getPos);