From 1a274899047bf1f60f8701f29cd2dd5a14ca85ad Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 22 Sep 2018 18:36:57 +0300 Subject: [PATCH] Add special type for object id --- apps/openmw/mwworld/scene.cpp | 12 ++--- apps/openmw/mwworld/worldimp.cpp | 2 +- .../detournavigator/navigator.cpp | 26 +++++----- .../cachedrecastmeshmanager.cpp | 6 +-- .../cachedrecastmeshmanager.hpp | 6 +-- components/detournavigator/navigator.cpp | 26 +++++----- components/detournavigator/navigator.hpp | 24 ++++----- components/detournavigator/navmeshmanager.cpp | 10 ++-- components/detournavigator/navmeshmanager.hpp | 10 ++-- components/detournavigator/objectid.hpp | 50 +++++++++++++++++++ .../offmeshconnectionsmanager.hpp | 13 ++--- .../detournavigator/recastmeshmanager.cpp | 6 +-- .../detournavigator/recastmeshmanager.hpp | 9 ++-- .../tilecachedrecastmeshmanager.cpp | 6 +-- .../tilecachedrecastmeshmanager.hpp | 8 +-- 15 files changed, 133 insertions(+), 81 deletions(-) create mode 100644 components/detournavigator/objectid.hpp diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 18ceffba42..49a603d1d8 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -151,7 +151,7 @@ namespace const auto connectionEnd = endPoint.mHit ? endPoint.mHitPos : end; navigator.addObject( - reinterpret_cast(object), + DetourNavigator::ObjectId(object), DetourNavigator::DoorShapes( *shape, object->getShapeInstance()->getAvoidCollisionShape(), @@ -164,7 +164,7 @@ namespace else { navigator.addObject( - reinterpret_cast(object), + DetourNavigator::ObjectId(object), DetourNavigator::ObjectShapes { *object->getShapeInstance()->getCollisionShape(), object->getShapeInstance()->getAvoidCollisionShape() @@ -343,7 +343,7 @@ namespace MWWorld for (const auto& ptr : visitor.mObjects) { if (const auto object = mPhysics->getObject(ptr)) - navigator->removeObject(reinterpret_cast(object)); + navigator->removeObject(DetourNavigator::ObjectId(object)); else if (const auto actor = mPhysics->getActor(ptr)) { navigator->removeAgent(ptr.getCell()->isExterior() ? playerHalfExtents : actor->getHalfExtents()); @@ -365,7 +365,7 @@ namespace MWWorld if (land && land->mDataTypes&ESM::Land::DATA_VHGT) { if (const auto heightField = mPhysics->getHeightField(cellX, cellY)) - navigator->removeObject(reinterpret_cast(heightField)); + navigator->removeObject(DetourNavigator::ObjectId(heightField)); mPhysics->removeHeightField(cellX, cellY); } } @@ -420,7 +420,7 @@ namespace MWWorld } if (const auto heightField = mPhysics->getHeightField(cellX, cellY)) - navigator->addObject(reinterpret_cast(heightField), *heightField->getShape(), + navigator->addObject(DetourNavigator::ObjectId(heightField), *heightField->getShape(), heightField->getCollisionObject()->getWorldTransform()); } @@ -808,7 +808,7 @@ namespace MWWorld const auto navigator = MWBase::Environment::get().getWorld()->getNavigator(); if (const auto object = mPhysics->getObject(ptr)) { - navigator->removeObject(reinterpret_cast(object)); + navigator->removeObject(DetourNavigator::ObjectId(object)); const auto player = MWBase::Environment::get().getWorld()->getPlayerPtr(); navigator->update(player.getRefData().getPosition().asVec3()); } diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 83a2382803..c45d06c41e 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1569,7 +1569,7 @@ namespace MWWorld *object->getShapeInstance()->getCollisionShape(), object->getShapeInstance()->getAvoidCollisionShape() }; - return mNavigator->updateObject(std::size_t(object), shapes, object->getCollisionObject()->getWorldTransform()); + return mNavigator->updateObject(DetourNavigator::ObjectId(object), shapes, object->getCollisionObject()->getWorldTransform()); } bool World::castRay (float x1, float y1, float z1, float x2, float y2, float z2, bool ignoreDoors) diff --git a/apps/openmw_test_suite/detournavigator/navigator.cpp b/apps/openmw_test_suite/detournavigator/navigator.cpp index 7e188f8fdc..1b42b6d05c 100644 --- a/apps/openmw_test_suite/detournavigator/navigator.cpp +++ b/apps/openmw_test_suite/detournavigator/navigator.cpp @@ -102,7 +102,7 @@ namespace shape.setLocalScaling(btVector3(128, 128, 1)); mNavigator->addAgent(mAgentHalfExtents); - mNavigator->addObject(1, shape, btTransform::getIdentity()); + mNavigator->addObject(ObjectId(&shape), shape, btTransform::getIdentity()); mNavigator->update(mPlayerPosition); mNavigator->wait(); @@ -152,7 +152,7 @@ namespace compoundShape.addChildShape(btTransform(btMatrix3x3::getIdentity(), btVector3(0, 0, 0)), &boxShape); mNavigator->addAgent(mAgentHalfExtents); - mNavigator->addObject(1, heightfieldShape, btTransform::getIdentity()); + mNavigator->addObject(ObjectId(&heightfieldShape), heightfieldShape, btTransform::getIdentity()); mNavigator->update(mPlayerPosition); mNavigator->wait(); @@ -184,7 +184,7 @@ namespace osg::Vec3f(215, -215, 1.877177715301513671875), })) << mPath; - mNavigator->addObject(2, compoundShape, btTransform::getIdentity()); + mNavigator->addObject(ObjectId(&compoundShape), compoundShape, btTransform::getIdentity()); mNavigator->update(mPlayerPosition); mNavigator->wait(); @@ -235,8 +235,8 @@ namespace compoundShape.addChildShape(btTransform(btMatrix3x3::getIdentity(), btVector3(0, 0, 0)), &boxShape); mNavigator->addAgent(mAgentHalfExtents); - mNavigator->addObject(1, heightfieldShape, btTransform::getIdentity()); - mNavigator->addObject(2, compoundShape, btTransform::getIdentity()); + mNavigator->addObject(ObjectId(&heightfieldShape), heightfieldShape, btTransform::getIdentity()); + mNavigator->addObject(ObjectId(&compoundShape), compoundShape, btTransform::getIdentity()); mNavigator->update(mPlayerPosition); mNavigator->wait(); @@ -270,7 +270,7 @@ namespace compoundShape.updateChildTransform(0, btTransform(btMatrix3x3::getIdentity(), btVector3(1000, 0, 0))); - mNavigator->updateObject(2, compoundShape, btTransform::getIdentity()); + mNavigator->updateObject(ObjectId(&compoundShape), compoundShape, btTransform::getIdentity()); mNavigator->update(mPlayerPosition); mNavigator->wait(); @@ -327,8 +327,8 @@ namespace shape2.setLocalScaling(btVector3(128, 128, 1)); mNavigator->addAgent(mAgentHalfExtents); - mNavigator->addObject(1, shape, btTransform::getIdentity()); - mNavigator->addObject(2, shape2, btTransform::getIdentity()); + mNavigator->addObject(ObjectId(&shape), shape, btTransform::getIdentity()); + mNavigator->addObject(ObjectId(&shape2), shape2, btTransform::getIdentity()); mNavigator->update(mPlayerPosition); mNavigator->wait(); @@ -384,7 +384,7 @@ namespace shapeAvoid.setLocalScaling(btVector3(128, 128, 1)); mNavigator->addAgent(mAgentHalfExtents); - mNavigator->addObject(1, ObjectShapes {shape, &shapeAvoid}, btTransform::getIdentity()); + mNavigator->addObject(ObjectId(&shape), ObjectShapes {shape, &shapeAvoid}, btTransform::getIdentity()); mNavigator->update(mPlayerPosition); mNavigator->wait(); @@ -432,7 +432,7 @@ namespace mNavigator->addAgent(mAgentHalfExtents); mNavigator->addWater(osg::Vec2i(0, 0), 128 * 4, 300, btTransform::getIdentity()); - mNavigator->addObject(1, shape, btTransform::getIdentity()); + mNavigator->addObject(ObjectId(&shape), shape, btTransform::getIdentity()); mNavigator->update(mPlayerPosition); mNavigator->wait(); @@ -480,7 +480,7 @@ namespace mNavigator->addAgent(mAgentHalfExtents); mNavigator->addWater(osg::Vec2i(0, 0), 128 * 4, -25, btTransform::getIdentity()); - mNavigator->addObject(1, shape, btTransform::getIdentity()); + mNavigator->addObject(ObjectId(&shape), shape, btTransform::getIdentity()); mNavigator->update(mPlayerPosition); mNavigator->wait(); @@ -525,7 +525,7 @@ namespace shape.setLocalScaling(btVector3(128, 128, 1)); mNavigator->addAgent(mAgentHalfExtents); - mNavigator->addObject(1, shape, btTransform::getIdentity()); + mNavigator->addObject(ObjectId(&shape), shape, btTransform::getIdentity()); mNavigator->addWater(osg::Vec2i(0, 0), std::numeric_limits::max(), -25, btTransform::getIdentity()); mNavigator->update(mPlayerPosition); mNavigator->wait(); @@ -572,7 +572,7 @@ namespace mNavigator->addAgent(mAgentHalfExtents); mNavigator->addWater(osg::Vec2i(0, 0), 128 * 4, -25, btTransform::getIdentity()); - mNavigator->addObject(1, shape, btTransform::getIdentity()); + mNavigator->addObject(ObjectId(&shape), shape, btTransform::getIdentity()); mNavigator->update(mPlayerPosition); mNavigator->wait(); diff --git a/components/detournavigator/cachedrecastmeshmanager.cpp b/components/detournavigator/cachedrecastmeshmanager.cpp index 8a9fbd4ee8..5e145486b9 100644 --- a/components/detournavigator/cachedrecastmeshmanager.cpp +++ b/components/detournavigator/cachedrecastmeshmanager.cpp @@ -7,7 +7,7 @@ namespace DetourNavigator : mImpl(settings, bounds) {} - bool CachedRecastMeshManager::addObject(std::size_t id, const btCollisionShape& shape, + bool CachedRecastMeshManager::addObject(const ObjectId id, const btCollisionShape& shape, const btTransform& transform, const AreaType areaType) { if (!mImpl.addObject(id, shape, transform, areaType)) @@ -16,7 +16,7 @@ namespace DetourNavigator return true; } - bool CachedRecastMeshManager::updateObject(std::size_t id, const btTransform& transform, const AreaType areaType) + bool CachedRecastMeshManager::updateObject(const ObjectId id, const btTransform& transform, const AreaType areaType) { if (!mImpl.updateObject(id, transform, areaType)) return false; @@ -24,7 +24,7 @@ namespace DetourNavigator return true; } - boost::optional CachedRecastMeshManager::removeObject(std::size_t id) + boost::optional CachedRecastMeshManager::removeObject(const ObjectId id) { const auto object = mImpl.removeObject(id); if (object) diff --git a/components/detournavigator/cachedrecastmeshmanager.hpp b/components/detournavigator/cachedrecastmeshmanager.hpp index 048d002701..528e8dabc1 100644 --- a/components/detournavigator/cachedrecastmeshmanager.hpp +++ b/components/detournavigator/cachedrecastmeshmanager.hpp @@ -12,16 +12,16 @@ namespace DetourNavigator public: CachedRecastMeshManager(const Settings& settings, const TileBounds& bounds); - bool addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform, + bool addObject(const ObjectId id, const btCollisionShape& shape, const btTransform& transform, const AreaType areaType); - bool updateObject(std::size_t id, const btTransform& transform, const AreaType areaType); + bool updateObject(const ObjectId id, const btTransform& transform, const AreaType areaType); bool addWater(const osg::Vec2i& cellPosition, const int cellSize, const btTransform& transform); boost::optional removeWater(const osg::Vec2i& cellPosition); - boost::optional removeObject(std::size_t id); + boost::optional removeObject(const ObjectId id); std::shared_ptr getMesh(); diff --git a/components/detournavigator/navigator.cpp b/components/detournavigator/navigator.cpp index 1c232a17c5..d185ad02fa 100644 --- a/components/detournavigator/navigator.cpp +++ b/components/detournavigator/navigator.cpp @@ -27,17 +27,17 @@ namespace DetourNavigator mNavMeshManager.reset(agentHalfExtents); } - bool Navigator::addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform) + bool Navigator::addObject(const ObjectId id, const btCollisionShape& shape, const btTransform& transform) { return mNavMeshManager.addObject(id, shape, transform, AreaType_ground); } - bool Navigator::addObject(std::size_t id, const ObjectShapes& shapes, const btTransform& transform) + bool Navigator::addObject(const ObjectId id, const ObjectShapes& shapes, const btTransform& transform) { bool result = addObject(id, shapes.mShape, transform); if (shapes.mAvoid) { - const auto avoidId = reinterpret_cast(shapes.mAvoid); + const ObjectId avoidId(shapes.mAvoid); if (mNavMeshManager.addObject(avoidId, *shapes.mAvoid, transform, AreaType_null)) { updateAvoidShapeId(id, avoidId); @@ -47,7 +47,7 @@ namespace DetourNavigator return result; } - bool Navigator::addObject(std::size_t id, const DoorShapes& shapes, const btTransform& transform) + bool Navigator::addObject(const ObjectId id, const DoorShapes& shapes, const btTransform& transform) { if (addObject(id, static_cast(shapes), transform)) { @@ -61,17 +61,17 @@ namespace DetourNavigator return false; } - bool Navigator::updateObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform) + bool Navigator::updateObject(const ObjectId id, const btCollisionShape& shape, const btTransform& transform) { return mNavMeshManager.updateObject(id, shape, transform, AreaType_ground); } - bool Navigator::updateObject(std::size_t id, const ObjectShapes& shapes, const btTransform& transform) + bool Navigator::updateObject(const ObjectId id, const ObjectShapes& shapes, const btTransform& transform) { bool result = updateObject(id, shapes.mShape, transform); if (shapes.mAvoid) { - const auto avoidId = reinterpret_cast(shapes.mAvoid); + const ObjectId avoidId(shapes.mAvoid); if (mNavMeshManager.updateObject(avoidId, *shapes.mAvoid, transform, AreaType_null)) { updateAvoidShapeId(id, avoidId); @@ -81,12 +81,12 @@ namespace DetourNavigator return result; } - bool Navigator::updateObject(std::size_t id, const DoorShapes& shapes, const btTransform& transform) + bool Navigator::updateObject(const ObjectId id, const DoorShapes& shapes, const btTransform& transform) { return updateObject(id, static_cast(shapes), transform); } - bool Navigator::removeObject(std::size_t id) + bool Navigator::removeObject(const ObjectId id) { bool result = mNavMeshManager.removeObject(id); const auto avoid = mAvoidIds.find(id); @@ -132,23 +132,23 @@ namespace DetourNavigator return mSettings; } - void Navigator::updateAvoidShapeId(const std::size_t id, const std::size_t avoidId) + void Navigator::updateAvoidShapeId(const ObjectId id, const ObjectId avoidId) { updateId(id, avoidId, mWaterIds); } - void Navigator::updateWaterShapeId(const std::size_t id, const std::size_t waterId) + void Navigator::updateWaterShapeId(const ObjectId id, const ObjectId waterId) { updateId(id, waterId, mWaterIds); } - void Navigator::updateId(const std::size_t id, const std::size_t updateId, std::unordered_map& ids) + void Navigator::updateId(const ObjectId id, const ObjectId updateId, std::unordered_map& ids) { auto inserted = ids.insert(std::make_pair(id, updateId)); if (!inserted.second) { mNavMeshManager.removeObject(inserted.first->second); - inserted.second = updateId; + inserted.first->second = updateId; } } } diff --git a/components/detournavigator/navigator.hpp b/components/detournavigator/navigator.hpp index e33f7c4abf..78857ad3e0 100644 --- a/components/detournavigator/navigator.hpp +++ b/components/detournavigator/navigator.hpp @@ -41,19 +41,19 @@ namespace DetourNavigator void removeAgent(const osg::Vec3f& agentHalfExtents); - bool addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform); + bool addObject(const ObjectId id, const btCollisionShape& shape, const btTransform& transform); - bool addObject(std::size_t id, const ObjectShapes& shapes, const btTransform& transform); + bool addObject(const ObjectId id, const ObjectShapes& shapes, const btTransform& transform); - bool addObject(std::size_t id, const DoorShapes& shapes, const btTransform& transform); + bool addObject(const ObjectId id, const DoorShapes& shapes, const btTransform& transform); - bool updateObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform); + bool updateObject(const ObjectId id, const btCollisionShape& shape, const btTransform& transform); - bool updateObject(std::size_t id, const ObjectShapes& shapes, const btTransform& transform); + bool updateObject(const ObjectId id, const ObjectShapes& shapes, const btTransform& transform); - bool updateObject(std::size_t id, const DoorShapes& shapes, const btTransform& transform); + bool updateObject(const ObjectId id, const DoorShapes& shapes, const btTransform& transform); - bool removeObject(std::size_t id); + bool removeObject(const ObjectId id); bool addWater(const osg::Vec2i& cellPosition, const int cellSize, const btScalar level, const btTransform& transform); @@ -82,12 +82,12 @@ namespace DetourNavigator Settings mSettings; NavMeshManager mNavMeshManager; std::map mAgents; - std::unordered_map mAvoidIds; - std::unordered_map mWaterIds; + std::unordered_map mAvoidIds; + std::unordered_map mWaterIds; - void updateAvoidShapeId(const std::size_t id, const std::size_t avoidId); - void updateWaterShapeId(const std::size_t id, const std::size_t waterId); - void updateId(const std::size_t id, const std::size_t waterId, std::unordered_map& ids); + void updateAvoidShapeId(const ObjectId id, const ObjectId avoidId); + void updateWaterShapeId(const ObjectId id, const ObjectId waterId); + void updateId(const ObjectId id, const ObjectId waterId, std::unordered_map& ids); }; } diff --git a/components/detournavigator/navmeshmanager.cpp b/components/detournavigator/navmeshmanager.cpp index 67514b8b78..559aedebbf 100644 --- a/components/detournavigator/navmeshmanager.cpp +++ b/components/detournavigator/navmeshmanager.cpp @@ -32,7 +32,7 @@ namespace DetourNavigator , mAsyncNavMeshUpdater(settings, mRecastMeshManager, mOffMeshConnectionsManager) {} - bool NavMeshManager::addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform, + bool NavMeshManager::addObject(const ObjectId id, const btCollisionShape& shape, const btTransform& transform, const AreaType areaType) { if (!mRecastMeshManager.addObject(id, shape, transform, areaType)) @@ -41,7 +41,7 @@ namespace DetourNavigator return true; } - bool NavMeshManager::updateObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform, + bool NavMeshManager::updateObject(const ObjectId id, const btCollisionShape& shape, const btTransform& transform, const AreaType areaType) { if (!mRecastMeshManager.updateObject(id, transform, areaType)) @@ -50,7 +50,7 @@ namespace DetourNavigator return true; } - bool NavMeshManager::removeObject(std::size_t id) + bool NavMeshManager::removeObject(const ObjectId id) { const auto object = mRecastMeshManager.removeObject(id); if (!object) @@ -91,7 +91,7 @@ namespace DetourNavigator mCache.erase(agentHalfExtents); } - void NavMeshManager::addOffMeshConnection(std::size_t id, const osg::Vec3f& start, const osg::Vec3f& end) + void NavMeshManager::addOffMeshConnection(const ObjectId id, const osg::Vec3f& start, const osg::Vec3f& end) { if (!mOffMeshConnectionsManager.add(id, OffMeshConnection {start, end})) return; @@ -105,7 +105,7 @@ namespace DetourNavigator addChangedTile(endTilePosition, ChangeType::add); } - void NavMeshManager::removeOffMeshConnection(std::size_t id) + void NavMeshManager::removeOffMeshConnection(const ObjectId id) { if (const auto connection = mOffMeshConnectionsManager.remove(id)) { diff --git a/components/detournavigator/navmeshmanager.hpp b/components/detournavigator/navmeshmanager.hpp index cd8c55aa06..86d9ea5d48 100644 --- a/components/detournavigator/navmeshmanager.hpp +++ b/components/detournavigator/navmeshmanager.hpp @@ -22,13 +22,13 @@ namespace DetourNavigator public: NavMeshManager(const Settings& settings); - bool addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform, + bool addObject(const ObjectId id, const btCollisionShape& shape, const btTransform& transform, const AreaType areaType); - bool updateObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform, + bool updateObject(const ObjectId id, const btCollisionShape& shape, const btTransform& transform, const AreaType areaType); - bool removeObject(std::size_t id); + bool removeObject(const ObjectId id); void addAgent(const osg::Vec3f& agentHalfExtents); @@ -38,9 +38,9 @@ namespace DetourNavigator void reset(const osg::Vec3f& agentHalfExtents); - void addOffMeshConnection(std::size_t id, const osg::Vec3f& start, const osg::Vec3f& end); + void addOffMeshConnection(const ObjectId id, const osg::Vec3f& start, const osg::Vec3f& end); - void removeOffMeshConnection(std::size_t id); + void removeOffMeshConnection(const ObjectId id); void update(osg::Vec3f playerPosition, const osg::Vec3f& agentHalfExtents); diff --git a/components/detournavigator/objectid.hpp b/components/detournavigator/objectid.hpp new file mode 100644 index 0000000000..cbb933ba01 --- /dev/null +++ b/components/detournavigator/objectid.hpp @@ -0,0 +1,50 @@ +#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_OBJECTID_H +#define OPENMW_COMPONENTS_DETOURNAVIGATOR_OBJECTID_H + +#include +#include + +namespace DetourNavigator +{ + class ObjectId + { + public: + template + explicit ObjectId(const T* value) throw() + : mValue(reinterpret_cast(value)) + { + } + + std::size_t value() const throw() + { + return mValue; + } + + friend bool operator <(const ObjectId lhs, const ObjectId rhs) throw() + { + return lhs.mValue < rhs.mValue; + } + + friend bool operator ==(const ObjectId lhs, const ObjectId rhs) throw() + { + return lhs.mValue == rhs.mValue; + } + + private: + std::size_t mValue; + }; +} + +namespace std +{ + template <> + struct hash + { + std::size_t operator ()(const DetourNavigator::ObjectId value) const throw() + { + return value.value(); + } + }; +} + +#endif diff --git a/components/detournavigator/offmeshconnectionsmanager.hpp b/components/detournavigator/offmeshconnectionsmanager.hpp index 0b8f2010b9..0450724cfe 100644 --- a/components/detournavigator/offmeshconnectionsmanager.hpp +++ b/components/detournavigator/offmeshconnectionsmanager.hpp @@ -4,6 +4,7 @@ #include "settings.hpp" #include "settingsutils.hpp" #include "tileposition.hpp" +#include "objectid.hpp" #include @@ -30,7 +31,7 @@ namespace DetourNavigator : mSettings(settings) {} - bool add(const std::size_t id, const OffMeshConnection& value) + bool add(const ObjectId id, const OffMeshConnection& value) { const std::lock_guard lock(mMutex); @@ -48,7 +49,7 @@ namespace DetourNavigator return true; } - boost::optional remove(const std::size_t id) + boost::optional remove(const ObjectId id) { const std::lock_guard lock(mMutex); @@ -84,7 +85,7 @@ namespace DetourNavigator return result; std::for_each(itByTilePosition->second.begin(), itByTilePosition->second.end(), - [&] (const std::size_t v) + [&] (const ObjectId v) { const auto itById = mValuesById.find(v); if (itById != mValuesById.end()) @@ -97,10 +98,10 @@ namespace DetourNavigator private: const Settings& mSettings; std::mutex mMutex; - std::unordered_map mValuesById; - std::map> mValuesByTilePosition; + std::unordered_map mValuesById; + std::map> mValuesByTilePosition; - void removeByTilePosition(const TilePosition& tilePosition, const std::size_t id) + void removeByTilePosition(const TilePosition& tilePosition, const ObjectId id) { const auto it = mValuesByTilePosition.find(tilePosition); if (it != mValuesByTilePosition.end()) diff --git a/components/detournavigator/recastmeshmanager.cpp b/components/detournavigator/recastmeshmanager.cpp index cabde7fdf8..f9f81de962 100644 --- a/components/detournavigator/recastmeshmanager.cpp +++ b/components/detournavigator/recastmeshmanager.cpp @@ -11,7 +11,7 @@ namespace DetourNavigator { } - bool RecastMeshManager::addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform, + bool RecastMeshManager::addObject(const ObjectId id, const btCollisionShape& shape, const btTransform& transform, const AreaType areaType) { if (!mObjects.emplace(id, RecastMeshObject(shape, transform, areaType)).second) @@ -20,7 +20,7 @@ namespace DetourNavigator return mShouldRebuild; } - bool RecastMeshManager::updateObject(std::size_t id, const btTransform& transform, const AreaType areaType) + bool RecastMeshManager::updateObject(const ObjectId id, const btTransform& transform, const AreaType areaType) { const auto object = mObjects.find(id); if (object == mObjects.end()) @@ -31,7 +31,7 @@ namespace DetourNavigator return mShouldRebuild; } - boost::optional RecastMeshManager::removeObject(std::size_t id) + boost::optional RecastMeshManager::removeObject(const ObjectId id) { const auto object = mObjects.find(id); if (object == mObjects.end()) diff --git a/components/detournavigator/recastmeshmanager.hpp b/components/detournavigator/recastmeshmanager.hpp index c4391b6821..be0fc35817 100644 --- a/components/detournavigator/recastmeshmanager.hpp +++ b/components/detournavigator/recastmeshmanager.hpp @@ -3,6 +3,7 @@ #include "recastmeshbuilder.hpp" #include "recastmeshobject.hpp" +#include "objectid.hpp" #include @@ -34,16 +35,16 @@ namespace DetourNavigator RecastMeshManager(const Settings& settings, const TileBounds& bounds); - bool addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform, + bool addObject(const ObjectId id, const btCollisionShape& shape, const btTransform& transform, const AreaType areaType); - bool updateObject(std::size_t id, const btTransform& transform, const AreaType areaType); + bool updateObject(const ObjectId id, const btTransform& transform, const AreaType areaType); bool addWater(const osg::Vec2i& cellPosition, const int cellSize, const btTransform& transform); boost::optional removeWater(const osg::Vec2i& cellPosition); - boost::optional removeObject(std::size_t id); + boost::optional removeObject(const ObjectId id); std::shared_ptr getMesh(); @@ -52,7 +53,7 @@ namespace DetourNavigator private: bool mShouldRebuild; RecastMeshBuilder mMeshBuilder; - std::unordered_map mObjects; + std::unordered_map mObjects; std::map mWater; void rebuild(); diff --git a/components/detournavigator/tilecachedrecastmeshmanager.cpp b/components/detournavigator/tilecachedrecastmeshmanager.cpp index 164253f856..67959e42c0 100644 --- a/components/detournavigator/tilecachedrecastmeshmanager.cpp +++ b/components/detournavigator/tilecachedrecastmeshmanager.cpp @@ -9,7 +9,7 @@ namespace DetourNavigator : mSettings(settings) {} - bool TileCachedRecastMeshManager::addObject(std::size_t id, const btCollisionShape& shape, + bool TileCachedRecastMeshManager::addObject(const ObjectId id, const btCollisionShape& shape, const btTransform& transform, const AreaType areaType) { bool result = false; @@ -39,7 +39,7 @@ namespace DetourNavigator return result; } - bool TileCachedRecastMeshManager::updateObject(std::size_t id, const btTransform& transform, + bool TileCachedRecastMeshManager::updateObject(const ObjectId id, const btTransform& transform, const AreaType areaType) { const auto object = mObjectsTilesPositions.find(id); @@ -59,7 +59,7 @@ namespace DetourNavigator return result; } - boost::optional TileCachedRecastMeshManager::removeObject(std::size_t id) + boost::optional TileCachedRecastMeshManager::removeObject(const ObjectId id) { const auto object = mObjectsTilesPositions.find(id); if (object == mObjectsTilesPositions.end()) diff --git a/components/detournavigator/tilecachedrecastmeshmanager.hpp b/components/detournavigator/tilecachedrecastmeshmanager.hpp index f67d2c3922..2b237fddeb 100644 --- a/components/detournavigator/tilecachedrecastmeshmanager.hpp +++ b/components/detournavigator/tilecachedrecastmeshmanager.hpp @@ -14,12 +14,12 @@ namespace DetourNavigator public: TileCachedRecastMeshManager(const Settings& settings); - bool addObject(std::size_t id, const btCollisionShape& shape, const btTransform& transform, + bool addObject(const ObjectId id, const btCollisionShape& shape, const btTransform& transform, const AreaType areaType); - bool updateObject(std::size_t id, const btTransform& transform, const AreaType areaType); + bool updateObject(const ObjectId id, const btTransform& transform, const AreaType areaType); - boost::optional removeObject(std::size_t id); + boost::optional removeObject(const ObjectId id); bool addWater(const osg::Vec2i& cellPosition, const int cellSize, const btTransform& transform); @@ -43,7 +43,7 @@ namespace DetourNavigator const Settings& mSettings; std::mutex mTilesMutex; std::map mTiles; - std::unordered_map> mObjectsTilesPositions; + std::unordered_map> mObjectsTilesPositions; std::map> mWaterTilesPositions; std::size_t mRevision = 0; };