1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-21 09:23:51 +00:00

Add special type for object id

This commit is contained in:
elsid 2018-09-22 18:36:57 +03:00
parent 7c80bb9411
commit 1a27489904
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40
15 changed files with 133 additions and 81 deletions

View file

@ -151,7 +151,7 @@ namespace
const auto connectionEnd = endPoint.mHit ? endPoint.mHitPos : end; const auto connectionEnd = endPoint.mHit ? endPoint.mHitPos : end;
navigator.addObject( navigator.addObject(
reinterpret_cast<std::size_t>(object), DetourNavigator::ObjectId(object),
DetourNavigator::DoorShapes( DetourNavigator::DoorShapes(
*shape, *shape,
object->getShapeInstance()->getAvoidCollisionShape(), object->getShapeInstance()->getAvoidCollisionShape(),
@ -164,7 +164,7 @@ namespace
else else
{ {
navigator.addObject( navigator.addObject(
reinterpret_cast<std::size_t>(object), DetourNavigator::ObjectId(object),
DetourNavigator::ObjectShapes { DetourNavigator::ObjectShapes {
*object->getShapeInstance()->getCollisionShape(), *object->getShapeInstance()->getCollisionShape(),
object->getShapeInstance()->getAvoidCollisionShape() object->getShapeInstance()->getAvoidCollisionShape()
@ -343,7 +343,7 @@ namespace MWWorld
for (const auto& ptr : visitor.mObjects) for (const auto& ptr : visitor.mObjects)
{ {
if (const auto object = mPhysics->getObject(ptr)) if (const auto object = mPhysics->getObject(ptr))
navigator->removeObject(reinterpret_cast<std::size_t>(object)); navigator->removeObject(DetourNavigator::ObjectId(object));
else if (const auto actor = mPhysics->getActor(ptr)) else if (const auto actor = mPhysics->getActor(ptr))
{ {
navigator->removeAgent(ptr.getCell()->isExterior() ? playerHalfExtents : actor->getHalfExtents()); navigator->removeAgent(ptr.getCell()->isExterior() ? playerHalfExtents : actor->getHalfExtents());
@ -365,7 +365,7 @@ namespace MWWorld
if (land && land->mDataTypes&ESM::Land::DATA_VHGT) if (land && land->mDataTypes&ESM::Land::DATA_VHGT)
{ {
if (const auto heightField = mPhysics->getHeightField(cellX, cellY)) if (const auto heightField = mPhysics->getHeightField(cellX, cellY))
navigator->removeObject(reinterpret_cast<std::size_t>(heightField)); navigator->removeObject(DetourNavigator::ObjectId(heightField));
mPhysics->removeHeightField(cellX, cellY); mPhysics->removeHeightField(cellX, cellY);
} }
} }
@ -420,7 +420,7 @@ namespace MWWorld
} }
if (const auto heightField = mPhysics->getHeightField(cellX, cellY)) if (const auto heightField = mPhysics->getHeightField(cellX, cellY))
navigator->addObject(reinterpret_cast<std::size_t>(heightField), *heightField->getShape(), navigator->addObject(DetourNavigator::ObjectId(heightField), *heightField->getShape(),
heightField->getCollisionObject()->getWorldTransform()); heightField->getCollisionObject()->getWorldTransform());
} }
@ -808,7 +808,7 @@ namespace MWWorld
const auto navigator = MWBase::Environment::get().getWorld()->getNavigator(); const auto navigator = MWBase::Environment::get().getWorld()->getNavigator();
if (const auto object = mPhysics->getObject(ptr)) if (const auto object = mPhysics->getObject(ptr))
{ {
navigator->removeObject(reinterpret_cast<std::size_t>(object)); navigator->removeObject(DetourNavigator::ObjectId(object));
const auto player = MWBase::Environment::get().getWorld()->getPlayerPtr(); const auto player = MWBase::Environment::get().getWorld()->getPlayerPtr();
navigator->update(player.getRefData().getPosition().asVec3()); navigator->update(player.getRefData().getPosition().asVec3());
} }

View file

@ -1569,7 +1569,7 @@ namespace MWWorld
*object->getShapeInstance()->getCollisionShape(), *object->getShapeInstance()->getCollisionShape(),
object->getShapeInstance()->getAvoidCollisionShape() 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) bool World::castRay (float x1, float y1, float z1, float x2, float y2, float z2, bool ignoreDoors)

View file

@ -102,7 +102,7 @@ namespace
shape.setLocalScaling(btVector3(128, 128, 1)); shape.setLocalScaling(btVector3(128, 128, 1));
mNavigator->addAgent(mAgentHalfExtents); mNavigator->addAgent(mAgentHalfExtents);
mNavigator->addObject(1, shape, btTransform::getIdentity()); mNavigator->addObject(ObjectId(&shape), shape, btTransform::getIdentity());
mNavigator->update(mPlayerPosition); mNavigator->update(mPlayerPosition);
mNavigator->wait(); mNavigator->wait();
@ -152,7 +152,7 @@ namespace
compoundShape.addChildShape(btTransform(btMatrix3x3::getIdentity(), btVector3(0, 0, 0)), &boxShape); compoundShape.addChildShape(btTransform(btMatrix3x3::getIdentity(), btVector3(0, 0, 0)), &boxShape);
mNavigator->addAgent(mAgentHalfExtents); mNavigator->addAgent(mAgentHalfExtents);
mNavigator->addObject(1, heightfieldShape, btTransform::getIdentity()); mNavigator->addObject(ObjectId(&heightfieldShape), heightfieldShape, btTransform::getIdentity());
mNavigator->update(mPlayerPosition); mNavigator->update(mPlayerPosition);
mNavigator->wait(); mNavigator->wait();
@ -184,7 +184,7 @@ namespace
osg::Vec3f(215, -215, 1.877177715301513671875), osg::Vec3f(215, -215, 1.877177715301513671875),
})) << mPath; })) << mPath;
mNavigator->addObject(2, compoundShape, btTransform::getIdentity()); mNavigator->addObject(ObjectId(&compoundShape), compoundShape, btTransform::getIdentity());
mNavigator->update(mPlayerPosition); mNavigator->update(mPlayerPosition);
mNavigator->wait(); mNavigator->wait();
@ -235,8 +235,8 @@ namespace
compoundShape.addChildShape(btTransform(btMatrix3x3::getIdentity(), btVector3(0, 0, 0)), &boxShape); compoundShape.addChildShape(btTransform(btMatrix3x3::getIdentity(), btVector3(0, 0, 0)), &boxShape);
mNavigator->addAgent(mAgentHalfExtents); mNavigator->addAgent(mAgentHalfExtents);
mNavigator->addObject(1, heightfieldShape, btTransform::getIdentity()); mNavigator->addObject(ObjectId(&heightfieldShape), heightfieldShape, btTransform::getIdentity());
mNavigator->addObject(2, compoundShape, btTransform::getIdentity()); mNavigator->addObject(ObjectId(&compoundShape), compoundShape, btTransform::getIdentity());
mNavigator->update(mPlayerPosition); mNavigator->update(mPlayerPosition);
mNavigator->wait(); mNavigator->wait();
@ -270,7 +270,7 @@ namespace
compoundShape.updateChildTransform(0, btTransform(btMatrix3x3::getIdentity(), btVector3(1000, 0, 0))); 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->update(mPlayerPosition);
mNavigator->wait(); mNavigator->wait();
@ -327,8 +327,8 @@ namespace
shape2.setLocalScaling(btVector3(128, 128, 1)); shape2.setLocalScaling(btVector3(128, 128, 1));
mNavigator->addAgent(mAgentHalfExtents); mNavigator->addAgent(mAgentHalfExtents);
mNavigator->addObject(1, shape, btTransform::getIdentity()); mNavigator->addObject(ObjectId(&shape), shape, btTransform::getIdentity());
mNavigator->addObject(2, shape2, btTransform::getIdentity()); mNavigator->addObject(ObjectId(&shape2), shape2, btTransform::getIdentity());
mNavigator->update(mPlayerPosition); mNavigator->update(mPlayerPosition);
mNavigator->wait(); mNavigator->wait();
@ -384,7 +384,7 @@ namespace
shapeAvoid.setLocalScaling(btVector3(128, 128, 1)); shapeAvoid.setLocalScaling(btVector3(128, 128, 1));
mNavigator->addAgent(mAgentHalfExtents); mNavigator->addAgent(mAgentHalfExtents);
mNavigator->addObject(1, ObjectShapes {shape, &shapeAvoid}, btTransform::getIdentity()); mNavigator->addObject(ObjectId(&shape), ObjectShapes {shape, &shapeAvoid}, btTransform::getIdentity());
mNavigator->update(mPlayerPosition); mNavigator->update(mPlayerPosition);
mNavigator->wait(); mNavigator->wait();
@ -432,7 +432,7 @@ namespace
mNavigator->addAgent(mAgentHalfExtents); mNavigator->addAgent(mAgentHalfExtents);
mNavigator->addWater(osg::Vec2i(0, 0), 128 * 4, 300, btTransform::getIdentity()); 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->update(mPlayerPosition);
mNavigator->wait(); mNavigator->wait();
@ -480,7 +480,7 @@ namespace
mNavigator->addAgent(mAgentHalfExtents); mNavigator->addAgent(mAgentHalfExtents);
mNavigator->addWater(osg::Vec2i(0, 0), 128 * 4, -25, btTransform::getIdentity()); 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->update(mPlayerPosition);
mNavigator->wait(); mNavigator->wait();
@ -525,7 +525,7 @@ namespace
shape.setLocalScaling(btVector3(128, 128, 1)); shape.setLocalScaling(btVector3(128, 128, 1));
mNavigator->addAgent(mAgentHalfExtents); 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<int>::max(), -25, btTransform::getIdentity()); mNavigator->addWater(osg::Vec2i(0, 0), std::numeric_limits<int>::max(), -25, btTransform::getIdentity());
mNavigator->update(mPlayerPosition); mNavigator->update(mPlayerPosition);
mNavigator->wait(); mNavigator->wait();
@ -572,7 +572,7 @@ namespace
mNavigator->addAgent(mAgentHalfExtents); mNavigator->addAgent(mAgentHalfExtents);
mNavigator->addWater(osg::Vec2i(0, 0), 128 * 4, -25, btTransform::getIdentity()); 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->update(mPlayerPosition);
mNavigator->wait(); mNavigator->wait();

View file

@ -7,7 +7,7 @@ namespace DetourNavigator
: mImpl(settings, bounds) : 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) const btTransform& transform, const AreaType areaType)
{ {
if (!mImpl.addObject(id, shape, transform, areaType)) if (!mImpl.addObject(id, shape, transform, areaType))
@ -16,7 +16,7 @@ namespace DetourNavigator
return true; 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)) if (!mImpl.updateObject(id, transform, areaType))
return false; return false;
@ -24,7 +24,7 @@ namespace DetourNavigator
return true; return true;
} }
boost::optional<RemovedRecastMeshObject> CachedRecastMeshManager::removeObject(std::size_t id) boost::optional<RemovedRecastMeshObject> CachedRecastMeshManager::removeObject(const ObjectId id)
{ {
const auto object = mImpl.removeObject(id); const auto object = mImpl.removeObject(id);
if (object) if (object)

View file

@ -12,16 +12,16 @@ namespace DetourNavigator
public: public:
CachedRecastMeshManager(const Settings& settings, const TileBounds& bounds); 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); 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); bool addWater(const osg::Vec2i& cellPosition, const int cellSize, const btTransform& transform);
boost::optional<RecastMeshManager::Water> removeWater(const osg::Vec2i& cellPosition); boost::optional<RecastMeshManager::Water> removeWater(const osg::Vec2i& cellPosition);
boost::optional<RemovedRecastMeshObject> removeObject(std::size_t id); boost::optional<RemovedRecastMeshObject> removeObject(const ObjectId id);
std::shared_ptr<RecastMesh> getMesh(); std::shared_ptr<RecastMesh> getMesh();

View file

@ -27,17 +27,17 @@ namespace DetourNavigator
mNavMeshManager.reset(agentHalfExtents); 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); 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); bool result = addObject(id, shapes.mShape, transform);
if (shapes.mAvoid) if (shapes.mAvoid)
{ {
const auto avoidId = reinterpret_cast<std::size_t>(shapes.mAvoid); const ObjectId avoidId(shapes.mAvoid);
if (mNavMeshManager.addObject(avoidId, *shapes.mAvoid, transform, AreaType_null)) if (mNavMeshManager.addObject(avoidId, *shapes.mAvoid, transform, AreaType_null))
{ {
updateAvoidShapeId(id, avoidId); updateAvoidShapeId(id, avoidId);
@ -47,7 +47,7 @@ namespace DetourNavigator
return result; 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<const ObjectShapes&>(shapes), transform)) if (addObject(id, static_cast<const ObjectShapes&>(shapes), transform))
{ {
@ -61,17 +61,17 @@ namespace DetourNavigator
return false; 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); 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); bool result = updateObject(id, shapes.mShape, transform);
if (shapes.mAvoid) if (shapes.mAvoid)
{ {
const auto avoidId = reinterpret_cast<std::size_t>(shapes.mAvoid); const ObjectId avoidId(shapes.mAvoid);
if (mNavMeshManager.updateObject(avoidId, *shapes.mAvoid, transform, AreaType_null)) if (mNavMeshManager.updateObject(avoidId, *shapes.mAvoid, transform, AreaType_null))
{ {
updateAvoidShapeId(id, avoidId); updateAvoidShapeId(id, avoidId);
@ -81,12 +81,12 @@ namespace DetourNavigator
return result; 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<const ObjectShapes&>(shapes), transform); return updateObject(id, static_cast<const ObjectShapes&>(shapes), transform);
} }
bool Navigator::removeObject(std::size_t id) bool Navigator::removeObject(const ObjectId id)
{ {
bool result = mNavMeshManager.removeObject(id); bool result = mNavMeshManager.removeObject(id);
const auto avoid = mAvoidIds.find(id); const auto avoid = mAvoidIds.find(id);
@ -132,23 +132,23 @@ namespace DetourNavigator
return mSettings; 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); 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); updateId(id, waterId, mWaterIds);
} }
void Navigator::updateId(const std::size_t id, const std::size_t updateId, std::unordered_map<std::size_t, std::size_t>& ids) void Navigator::updateId(const ObjectId id, const ObjectId updateId, std::unordered_map<ObjectId, ObjectId>& ids)
{ {
auto inserted = ids.insert(std::make_pair(id, updateId)); auto inserted = ids.insert(std::make_pair(id, updateId));
if (!inserted.second) if (!inserted.second)
{ {
mNavMeshManager.removeObject(inserted.first->second); mNavMeshManager.removeObject(inserted.first->second);
inserted.second = updateId; inserted.first->second = updateId;
} }
} }
} }

View file

@ -41,19 +41,19 @@ namespace DetourNavigator
void removeAgent(const osg::Vec3f& agentHalfExtents); 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, bool addWater(const osg::Vec2i& cellPosition, const int cellSize, const btScalar level,
const btTransform& transform); const btTransform& transform);
@ -82,12 +82,12 @@ namespace DetourNavigator
Settings mSettings; Settings mSettings;
NavMeshManager mNavMeshManager; NavMeshManager mNavMeshManager;
std::map<osg::Vec3f, std::size_t> mAgents; std::map<osg::Vec3f, std::size_t> mAgents;
std::unordered_map<std::size_t, std::size_t> mAvoidIds; std::unordered_map<ObjectId, ObjectId> mAvoidIds;
std::unordered_map<std::size_t, std::size_t> mWaterIds; std::unordered_map<ObjectId, ObjectId> mWaterIds;
void updateAvoidShapeId(const std::size_t id, const std::size_t avoidId); void updateAvoidShapeId(const ObjectId id, const ObjectId avoidId);
void updateWaterShapeId(const std::size_t id, const std::size_t waterId); void updateWaterShapeId(const ObjectId id, const ObjectId waterId);
void updateId(const std::size_t id, const std::size_t waterId, std::unordered_map<std::size_t, std::size_t>& ids); void updateId(const ObjectId id, const ObjectId waterId, std::unordered_map<ObjectId, ObjectId>& ids);
}; };
} }

View file

@ -32,7 +32,7 @@ namespace DetourNavigator
, mAsyncNavMeshUpdater(settings, mRecastMeshManager, mOffMeshConnectionsManager) , 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) const AreaType areaType)
{ {
if (!mRecastMeshManager.addObject(id, shape, transform, areaType)) if (!mRecastMeshManager.addObject(id, shape, transform, areaType))
@ -41,7 +41,7 @@ namespace DetourNavigator
return true; 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) const AreaType areaType)
{ {
if (!mRecastMeshManager.updateObject(id, transform, areaType)) if (!mRecastMeshManager.updateObject(id, transform, areaType))
@ -50,7 +50,7 @@ namespace DetourNavigator
return true; return true;
} }
bool NavMeshManager::removeObject(std::size_t id) bool NavMeshManager::removeObject(const ObjectId id)
{ {
const auto object = mRecastMeshManager.removeObject(id); const auto object = mRecastMeshManager.removeObject(id);
if (!object) if (!object)
@ -91,7 +91,7 @@ namespace DetourNavigator
mCache.erase(agentHalfExtents); 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})) if (!mOffMeshConnectionsManager.add(id, OffMeshConnection {start, end}))
return; return;
@ -105,7 +105,7 @@ namespace DetourNavigator
addChangedTile(endTilePosition, ChangeType::add); addChangedTile(endTilePosition, ChangeType::add);
} }
void NavMeshManager::removeOffMeshConnection(std::size_t id) void NavMeshManager::removeOffMeshConnection(const ObjectId id)
{ {
if (const auto connection = mOffMeshConnectionsManager.remove(id)) if (const auto connection = mOffMeshConnectionsManager.remove(id))
{ {

View file

@ -22,13 +22,13 @@ namespace DetourNavigator
public: public:
NavMeshManager(const Settings& settings); 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); 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); const AreaType areaType);
bool removeObject(std::size_t id); bool removeObject(const ObjectId id);
void addAgent(const osg::Vec3f& agentHalfExtents); void addAgent(const osg::Vec3f& agentHalfExtents);
@ -38,9 +38,9 @@ namespace DetourNavigator
void reset(const osg::Vec3f& agentHalfExtents); 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); void update(osg::Vec3f playerPosition, const osg::Vec3f& agentHalfExtents);

View file

@ -0,0 +1,50 @@
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_OBJECTID_H
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_OBJECTID_H
#include <cstddef>
#include <unordered_map>
namespace DetourNavigator
{
class ObjectId
{
public:
template <class T>
explicit ObjectId(const T* value) throw()
: mValue(reinterpret_cast<std::size_t>(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<DetourNavigator::ObjectId>
{
std::size_t operator ()(const DetourNavigator::ObjectId value) const throw()
{
return value.value();
}
};
}
#endif

View file

@ -4,6 +4,7 @@
#include "settings.hpp" #include "settings.hpp"
#include "settingsutils.hpp" #include "settingsutils.hpp"
#include "tileposition.hpp" #include "tileposition.hpp"
#include "objectid.hpp"
#include <osg/Vec3f> #include <osg/Vec3f>
@ -30,7 +31,7 @@ namespace DetourNavigator
: mSettings(settings) : mSettings(settings)
{} {}
bool add(const std::size_t id, const OffMeshConnection& value) bool add(const ObjectId id, const OffMeshConnection& value)
{ {
const std::lock_guard<std::mutex> lock(mMutex); const std::lock_guard<std::mutex> lock(mMutex);
@ -48,7 +49,7 @@ namespace DetourNavigator
return true; return true;
} }
boost::optional<OffMeshConnection> remove(const std::size_t id) boost::optional<OffMeshConnection> remove(const ObjectId id)
{ {
const std::lock_guard<std::mutex> lock(mMutex); const std::lock_guard<std::mutex> lock(mMutex);
@ -84,7 +85,7 @@ namespace DetourNavigator
return result; return result;
std::for_each(itByTilePosition->second.begin(), itByTilePosition->second.end(), std::for_each(itByTilePosition->second.begin(), itByTilePosition->second.end(),
[&] (const std::size_t v) [&] (const ObjectId v)
{ {
const auto itById = mValuesById.find(v); const auto itById = mValuesById.find(v);
if (itById != mValuesById.end()) if (itById != mValuesById.end())
@ -97,10 +98,10 @@ namespace DetourNavigator
private: private:
const Settings& mSettings; const Settings& mSettings;
std::mutex mMutex; std::mutex mMutex;
std::unordered_map<std::size_t, OffMeshConnection> mValuesById; std::unordered_map<ObjectId, OffMeshConnection> mValuesById;
std::map<TilePosition, std::unordered_set<std::size_t>> mValuesByTilePosition; std::map<TilePosition, std::unordered_set<ObjectId>> 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); const auto it = mValuesByTilePosition.find(tilePosition);
if (it != mValuesByTilePosition.end()) if (it != mValuesByTilePosition.end())

View file

@ -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) const AreaType areaType)
{ {
if (!mObjects.emplace(id, RecastMeshObject(shape, transform, areaType)).second) if (!mObjects.emplace(id, RecastMeshObject(shape, transform, areaType)).second)
@ -20,7 +20,7 @@ namespace DetourNavigator
return mShouldRebuild; 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); const auto object = mObjects.find(id);
if (object == mObjects.end()) if (object == mObjects.end())
@ -31,7 +31,7 @@ namespace DetourNavigator
return mShouldRebuild; return mShouldRebuild;
} }
boost::optional<RemovedRecastMeshObject> RecastMeshManager::removeObject(std::size_t id) boost::optional<RemovedRecastMeshObject> RecastMeshManager::removeObject(const ObjectId id)
{ {
const auto object = mObjects.find(id); const auto object = mObjects.find(id);
if (object == mObjects.end()) if (object == mObjects.end())

View file

@ -3,6 +3,7 @@
#include "recastmeshbuilder.hpp" #include "recastmeshbuilder.hpp"
#include "recastmeshobject.hpp" #include "recastmeshobject.hpp"
#include "objectid.hpp"
#include <LinearMath/btTransform.h> #include <LinearMath/btTransform.h>
@ -34,16 +35,16 @@ namespace DetourNavigator
RecastMeshManager(const Settings& settings, const TileBounds& bounds); 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); 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); bool addWater(const osg::Vec2i& cellPosition, const int cellSize, const btTransform& transform);
boost::optional<Water> removeWater(const osg::Vec2i& cellPosition); boost::optional<Water> removeWater(const osg::Vec2i& cellPosition);
boost::optional<RemovedRecastMeshObject> removeObject(std::size_t id); boost::optional<RemovedRecastMeshObject> removeObject(const ObjectId id);
std::shared_ptr<RecastMesh> getMesh(); std::shared_ptr<RecastMesh> getMesh();
@ -52,7 +53,7 @@ namespace DetourNavigator
private: private:
bool mShouldRebuild; bool mShouldRebuild;
RecastMeshBuilder mMeshBuilder; RecastMeshBuilder mMeshBuilder;
std::unordered_map<std::size_t, RecastMeshObject> mObjects; std::unordered_map<ObjectId, RecastMeshObject> mObjects;
std::map<osg::Vec2i, Water> mWater; std::map<osg::Vec2i, Water> mWater;
void rebuild(); void rebuild();

View file

@ -9,7 +9,7 @@ namespace DetourNavigator
: mSettings(settings) : 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) const btTransform& transform, const AreaType areaType)
{ {
bool result = false; bool result = false;
@ -39,7 +39,7 @@ namespace DetourNavigator
return result; 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 AreaType areaType)
{ {
const auto object = mObjectsTilesPositions.find(id); const auto object = mObjectsTilesPositions.find(id);
@ -59,7 +59,7 @@ namespace DetourNavigator
return result; return result;
} }
boost::optional<RemovedRecastMeshObject> TileCachedRecastMeshManager::removeObject(std::size_t id) boost::optional<RemovedRecastMeshObject> TileCachedRecastMeshManager::removeObject(const ObjectId id)
{ {
const auto object = mObjectsTilesPositions.find(id); const auto object = mObjectsTilesPositions.find(id);
if (object == mObjectsTilesPositions.end()) if (object == mObjectsTilesPositions.end())

View file

@ -14,12 +14,12 @@ namespace DetourNavigator
public: public:
TileCachedRecastMeshManager(const Settings& settings); 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); 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<RemovedRecastMeshObject> removeObject(std::size_t id); boost::optional<RemovedRecastMeshObject> removeObject(const ObjectId id);
bool addWater(const osg::Vec2i& cellPosition, const int cellSize, const btTransform& transform); bool addWater(const osg::Vec2i& cellPosition, const int cellSize, const btTransform& transform);
@ -43,7 +43,7 @@ namespace DetourNavigator
const Settings& mSettings; const Settings& mSettings;
std::mutex mTilesMutex; std::mutex mTilesMutex;
std::map<TilePosition, CachedRecastMeshManager> mTiles; std::map<TilePosition, CachedRecastMeshManager> mTiles;
std::unordered_map<std::size_t, std::vector<TilePosition>> mObjectsTilesPositions; std::unordered_map<ObjectId, std::vector<TilePosition>> mObjectsTilesPositions;
std::map<osg::Vec2i, std::vector<TilePosition>> mWaterTilesPositions; std::map<osg::Vec2i, std::vector<TilePosition>> mWaterTilesPositions;
std::size_t mRevision = 0; std::size_t mRevision = 0;
}; };