mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 20:53:50 +00:00
Add special type for object id
This commit is contained in:
parent
7c80bb9411
commit
1a27489904
15 changed files with 133 additions and 81 deletions
|
@ -151,7 +151,7 @@ namespace
|
|||
const auto connectionEnd = endPoint.mHit ? endPoint.mHitPos : end;
|
||||
|
||||
navigator.addObject(
|
||||
reinterpret_cast<std::size_t>(object),
|
||||
DetourNavigator::ObjectId(object),
|
||||
DetourNavigator::DoorShapes(
|
||||
*shape,
|
||||
object->getShapeInstance()->getAvoidCollisionShape(),
|
||||
|
@ -164,7 +164,7 @@ namespace
|
|||
else
|
||||
{
|
||||
navigator.addObject(
|
||||
reinterpret_cast<std::size_t>(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<std::size_t>(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<std::size_t>(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<std::size_t>(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<std::size_t>(object));
|
||||
navigator->removeObject(DetourNavigator::ObjectId(object));
|
||||
const auto player = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
||||
navigator->update(player.getRefData().getPosition().asVec3());
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<int>::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();
|
||||
|
||||
|
|
|
@ -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<RemovedRecastMeshObject> CachedRecastMeshManager::removeObject(std::size_t id)
|
||||
boost::optional<RemovedRecastMeshObject> CachedRecastMeshManager::removeObject(const ObjectId id)
|
||||
{
|
||||
const auto object = mImpl.removeObject(id);
|
||||
if (object)
|
||||
|
|
|
@ -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<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();
|
||||
|
||||
|
|
|
@ -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<std::size_t>(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<const ObjectShapes&>(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<std::size_t>(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<const ObjectShapes&>(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<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));
|
||||
if (!inserted.second)
|
||||
{
|
||||
mNavMeshManager.removeObject(inserted.first->second);
|
||||
inserted.second = updateId;
|
||||
inserted.first->second = updateId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<osg::Vec3f, std::size_t> mAgents;
|
||||
std::unordered_map<std::size_t, std::size_t> mAvoidIds;
|
||||
std::unordered_map<std::size_t, std::size_t> mWaterIds;
|
||||
std::unordered_map<ObjectId, ObjectId> mAvoidIds;
|
||||
std::unordered_map<ObjectId, ObjectId> 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<std::size_t, std::size_t>& 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<ObjectId, ObjectId>& ids);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
50
components/detournavigator/objectid.hpp
Normal file
50
components/detournavigator/objectid.hpp
Normal 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
|
|
@ -4,6 +4,7 @@
|
|||
#include "settings.hpp"
|
||||
#include "settingsutils.hpp"
|
||||
#include "tileposition.hpp"
|
||||
#include "objectid.hpp"
|
||||
|
||||
#include <osg/Vec3f>
|
||||
|
||||
|
@ -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<std::mutex> lock(mMutex);
|
||||
|
||||
|
@ -48,7 +49,7 @@ namespace DetourNavigator
|
|||
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);
|
||||
|
||||
|
@ -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<std::size_t, OffMeshConnection> mValuesById;
|
||||
std::map<TilePosition, std::unordered_set<std::size_t>> mValuesByTilePosition;
|
||||
std::unordered_map<ObjectId, OffMeshConnection> mValuesById;
|
||||
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);
|
||||
if (it != mValuesByTilePosition.end())
|
||||
|
|
|
@ -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<RemovedRecastMeshObject> RecastMeshManager::removeObject(std::size_t id)
|
||||
boost::optional<RemovedRecastMeshObject> RecastMeshManager::removeObject(const ObjectId id)
|
||||
{
|
||||
const auto object = mObjects.find(id);
|
||||
if (object == mObjects.end())
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "recastmeshbuilder.hpp"
|
||||
#include "recastmeshobject.hpp"
|
||||
#include "objectid.hpp"
|
||||
|
||||
#include <LinearMath/btTransform.h>
|
||||
|
||||
|
@ -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<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();
|
||||
|
||||
|
@ -52,7 +53,7 @@ namespace DetourNavigator
|
|||
private:
|
||||
bool mShouldRebuild;
|
||||
RecastMeshBuilder mMeshBuilder;
|
||||
std::unordered_map<std::size_t, RecastMeshObject> mObjects;
|
||||
std::unordered_map<ObjectId, RecastMeshObject> mObjects;
|
||||
std::map<osg::Vec2i, Water> mWater;
|
||||
|
||||
void rebuild();
|
||||
|
|
|
@ -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<RemovedRecastMeshObject> TileCachedRecastMeshManager::removeObject(std::size_t id)
|
||||
boost::optional<RemovedRecastMeshObject> TileCachedRecastMeshManager::removeObject(const ObjectId id)
|
||||
{
|
||||
const auto object = mObjectsTilesPositions.find(id);
|
||||
if (object == mObjectsTilesPositions.end())
|
||||
|
|
|
@ -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<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);
|
||||
|
||||
|
@ -43,7 +43,7 @@ namespace DetourNavigator
|
|||
const Settings& mSettings;
|
||||
std::mutex mTilesMutex;
|
||||
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::size_t mRevision = 0;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue