mirror of https://github.com/OpenMW/openmw.git
Detect and ignore updates for oscillating objects
To avoid triggering NavMesh update when RecastMesh change should not change NavMesh. Based on the following assumption: Given a set of transformations and a bounding shape for all these tranformations, a new object transformation that does not change this bounding shape also should not change navmesh if for all of this object transformations resulting navmesh tiles are equivalent The idea is to report back to RecastMeshManager all changes of NavMesh if there are any assiciated with RecastMesh version. So we know the last time when RecastMesh change resulted into the NavMesh change. When later report shows that there was no NavMesh change for a new RecastMesh version we can assume that any object transformation within the same bounding box should not change NavMesh.pull/3072/head
parent
64fb700ae9
commit
3e67f5ffa5
@ -0,0 +1,29 @@
|
||||
#ifndef OPENMW_COMPONENTS_BULLETHELPERS_AABB_H
|
||||
#define OPENMW_COMPONENTS_BULLETHELPERS_AABB_H
|
||||
|
||||
#include <LinearMath/btVector3.h>
|
||||
#include <LinearMath/btTransform.h>
|
||||
#include <BulletCollision/CollisionShapes/btCollisionShape.h>
|
||||
#include <BulletCollision/Gimpact/btBoxCollision.h>
|
||||
|
||||
inline bool operator==(const btAABB& lhs, const btAABB& rhs)
|
||||
{
|
||||
return lhs.m_min == rhs.m_min && lhs.m_max == rhs.m_max;
|
||||
}
|
||||
|
||||
inline bool operator!=(const btAABB& lhs, const btAABB& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
namespace BulletHelpers
|
||||
{
|
||||
inline btAABB getAabb(const btCollisionShape& shape, const btTransform& transform)
|
||||
{
|
||||
btAABB result;
|
||||
shape.getAabb(transform, result.m_min, result.m_max);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,35 @@
|
||||
#include "oscillatingrecastmeshobject.hpp"
|
||||
|
||||
#include <components/bullethelpers/aabb.hpp>
|
||||
|
||||
namespace DetourNavigator
|
||||
{
|
||||
OscillatingRecastMeshObject::OscillatingRecastMeshObject(RecastMeshObject impl, std::size_t lastChangeRevision)
|
||||
: mImpl(std::move(impl))
|
||||
, mLastChangeRevision(lastChangeRevision)
|
||||
, mAabb(BulletHelpers::getAabb(mImpl.getShape(), mImpl.getTransform()))
|
||||
{
|
||||
}
|
||||
|
||||
bool OscillatingRecastMeshObject::update(const btTransform& transform, const AreaType areaType,
|
||||
std::size_t lastChangeRevision)
|
||||
{
|
||||
const btTransform oldTransform = mImpl.getTransform();
|
||||
if (!mImpl.update(transform, areaType))
|
||||
return false;
|
||||
if (transform == oldTransform)
|
||||
return true;
|
||||
if (mLastChangeRevision != lastChangeRevision)
|
||||
{
|
||||
mLastChangeRevision = lastChangeRevision;
|
||||
// btAABB doesn't have copy-assignment operator
|
||||
const btAABB aabb = BulletHelpers::getAabb(mImpl.getShape(), transform);
|
||||
mAabb.m_min = aabb.m_min;
|
||||
mAabb.m_max = aabb.m_max;
|
||||
return true;
|
||||
}
|
||||
const btAABB currentAabb = mAabb;
|
||||
mAabb.merge(BulletHelpers::getAabb(mImpl.getShape(), transform));
|
||||
return currentAabb != mAabb;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_OSCILLATINGRECASTMESHOBJECT_H
|
||||
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_OSCILLATINGRECASTMESHOBJECT_H
|
||||
|
||||
#include "areatype.hpp"
|
||||
#include "recastmeshobject.hpp"
|
||||
|
||||
#include <LinearMath/btTransform.h>
|
||||
#include <BulletCollision/Gimpact/btBoxCollision.h>
|
||||
|
||||
namespace DetourNavigator
|
||||
{
|
||||
class OscillatingRecastMeshObject
|
||||
{
|
||||
public:
|
||||
explicit OscillatingRecastMeshObject(RecastMeshObject impl, std::size_t lastChangeRevision);
|
||||
|
||||
bool update(const btTransform& transform, const AreaType areaType, std::size_t lastChangeRevision);
|
||||
|
||||
const RecastMeshObject& getImpl() const { return mImpl; }
|
||||
|
||||
private:
|
||||
RecastMeshObject mImpl;
|
||||
std::size_t mLastChangeRevision;
|
||||
btAABB mAabb;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,21 @@
|
||||
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_VERSION_H
|
||||
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_VERSION_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <tuple>
|
||||
|
||||
namespace DetourNavigator
|
||||
{
|
||||
struct Version
|
||||
{
|
||||
std::size_t mGeneration;
|
||||
std::size_t mRevision;
|
||||
|
||||
friend inline bool operator<(const Version& lhs, const Version& rhs)
|
||||
{
|
||||
return std::tie(lhs.mGeneration, lhs.mRevision) < std::tie(rhs.mGeneration, rhs.mRevision);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue