1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-31 07:06:45 +00:00

Replace unordered_map by map for storing objects

For small amount of items it gives better performance for find by key
for update.
This commit is contained in:
elsid 2021-05-27 16:38:04 +02:00
parent 22c2f106b7
commit ed91cf9397
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40
2 changed files with 5 additions and 7 deletions

View file

@ -12,13 +12,12 @@ namespace DetourNavigator
bool RecastMeshManager::addObject(const ObjectId id, const btCollisionShape& shape, const btTransform& transform, bool RecastMeshManager::addObject(const ObjectId id, const btCollisionShape& shape, const btTransform& transform,
const AreaType areaType) const AreaType areaType)
{ {
const auto object = mObjects.lower_bound(id);
if (object != mObjects.end() && object->first == id)
return false;
const auto iterator = mObjectsOrder.emplace(mObjectsOrder.end(), const auto iterator = mObjectsOrder.emplace(mObjectsOrder.end(),
OscillatingRecastMeshObject(RecastMeshObject(shape, transform, areaType), mRevision + 1)); OscillatingRecastMeshObject(RecastMeshObject(shape, transform, areaType), mRevision + 1));
if (!mObjects.emplace(id, iterator).second) mObjects.emplace_hint(object, id, iterator);
{
mObjectsOrder.erase(iterator);
return false;
}
++mRevision; ++mRevision;
return true; return true;
} }

View file

@ -13,7 +13,6 @@
#include <list> #include <list>
#include <map> #include <map>
#include <optional> #include <optional>
#include <unordered_map>
class btCollisionShape; class btCollisionShape;
@ -67,7 +66,7 @@ namespace DetourNavigator
RecastMeshBuilder mMeshBuilder; RecastMeshBuilder mMeshBuilder;
TileBounds mTileBounds; TileBounds mTileBounds;
std::list<OscillatingRecastMeshObject> mObjectsOrder; std::list<OscillatingRecastMeshObject> mObjectsOrder;
std::unordered_map<ObjectId, std::list<OscillatingRecastMeshObject>::iterator> mObjects; std::map<ObjectId, std::list<OscillatingRecastMeshObject>::iterator> mObjects;
std::list<Water> mWaterOrder; std::list<Water> mWaterOrder;
std::map<osg::Vec2i, std::list<Water>::iterator> mWater; std::map<osg::Vec2i, std::list<Water>::iterator> mWater;
std::optional<Report> mLastNavMeshReportedChange; std::optional<Report> mLastNavMeshReportedChange;