mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-22 18:39:42 +00:00
Merge branch 'navmesh_optimize_get_recast_mesh' into 'master'
Reduce waiting while creating RecastMesh See merge request OpenMW/openmw!1097
This commit is contained in:
commit
e89b304fed
3 changed files with 30 additions and 17 deletions
|
@ -123,7 +123,13 @@ namespace DetourNavigator
|
||||||
tileBounds.mMin /= mSettings.mRecastScaleFactor;
|
tileBounds.mMin /= mSettings.mRecastScaleFactor;
|
||||||
tileBounds.mMax /= mSettings.mRecastScaleFactor;
|
tileBounds.mMax /= mSettings.mRecastScaleFactor;
|
||||||
RecastMeshBuilder builder(tileBounds);
|
RecastMeshBuilder builder(tileBounds);
|
||||||
std::vector<RecastMeshObject> objects;
|
using Object = std::tuple<
|
||||||
|
osg::ref_ptr<const osg::Referenced>,
|
||||||
|
std::reference_wrapper<const btCollisionShape>,
|
||||||
|
btTransform,
|
||||||
|
AreaType
|
||||||
|
>;
|
||||||
|
std::vector<Object> objects;
|
||||||
std::size_t revision;
|
std::size_t revision;
|
||||||
{
|
{
|
||||||
const std::lock_guard lock(mMutex);
|
const std::lock_guard lock(mMutex);
|
||||||
|
@ -133,11 +139,14 @@ namespace DetourNavigator
|
||||||
std::visit(AddHeightfield {v.mCell, builder}, v.mShape);
|
std::visit(AddHeightfield {v.mCell, builder}, v.mShape);
|
||||||
objects.reserve(mObjects.size());
|
objects.reserve(mObjects.size());
|
||||||
for (const auto& [k, object] : mObjects)
|
for (const auto& [k, object] : mObjects)
|
||||||
objects.push_back(object.getImpl());
|
{
|
||||||
|
const RecastMeshObject& impl = object.getImpl();
|
||||||
|
objects.emplace_back(impl.getHolder(), impl.getShape(), impl.getTransform(), impl.getAreaType());
|
||||||
|
}
|
||||||
revision = mRevision;
|
revision = mRevision;
|
||||||
}
|
}
|
||||||
for (const auto& v : objects)
|
for (const auto& [holder, shape, transform, areaType] : objects)
|
||||||
builder.addObject(v.getShape(), v.getTransform(), v.getAreaType());
|
builder.addObject(shape, transform, areaType);
|
||||||
return std::move(builder).create(mGeneration, revision);
|
return std::move(builder).create(mGeneration, revision);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,35 +23,35 @@ namespace DetourNavigator
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<RecastMeshObject> makeChildrenObjects(const osg::ref_ptr<const Resource::BulletShapeInstance>& instance,
|
std::vector<RecastMeshObject> makeChildrenObjects(const osg::ref_ptr<const osg::Referenced>& holder,
|
||||||
const btCompoundShape& shape, const AreaType areaType)
|
const btCompoundShape& shape, const AreaType areaType)
|
||||||
{
|
{
|
||||||
std::vector<RecastMeshObject> result;
|
std::vector<RecastMeshObject> result;
|
||||||
for (int i = 0, num = shape.getNumChildShapes(); i < num; ++i)
|
for (int i = 0, num = shape.getNumChildShapes(); i < num; ++i)
|
||||||
{
|
{
|
||||||
const CollisionShape collisionShape {instance, *shape.getChildShape(i)};
|
const CollisionShape collisionShape {holder, *shape.getChildShape(i)};
|
||||||
result.emplace_back(collisionShape, shape.getChildTransform(i), areaType);
|
result.emplace_back(collisionShape, shape.getChildTransform(i), areaType);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<RecastMeshObject> makeChildrenObjects(const osg::ref_ptr<const Resource::BulletShapeInstance>& instance,
|
std::vector<RecastMeshObject> makeChildrenObjects(const osg::ref_ptr<const osg::Referenced>& holder,
|
||||||
const btCollisionShape& shape, const AreaType areaType)
|
const btCollisionShape& shape, const AreaType areaType)
|
||||||
{
|
{
|
||||||
if (shape.isCompound())
|
if (shape.isCompound())
|
||||||
return makeChildrenObjects(std::move(instance), static_cast<const btCompoundShape&>(shape), areaType);
|
return makeChildrenObjects(holder, static_cast<const btCompoundShape&>(shape), areaType);
|
||||||
return std::vector<RecastMeshObject>();
|
return std::vector<RecastMeshObject>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RecastMeshObject::RecastMeshObject(const CollisionShape& shape, const btTransform& transform,
|
RecastMeshObject::RecastMeshObject(const CollisionShape& shape, const btTransform& transform,
|
||||||
const AreaType areaType)
|
const AreaType areaType)
|
||||||
: mShapeInstance(shape.getShapeInstance())
|
: mHolder(shape.getHolder())
|
||||||
, mShape(shape.getShape())
|
, mShape(shape.getShape())
|
||||||
, mTransform(transform)
|
, mTransform(transform)
|
||||||
, mAreaType(areaType)
|
, mAreaType(areaType)
|
||||||
, mLocalScaling(mShape.get().getLocalScaling())
|
, mLocalScaling(mShape.get().getLocalScaling())
|
||||||
, mChildren(makeChildrenObjects(mShapeInstance, mShape.get(), mAreaType))
|
, mChildren(makeChildrenObjects(mHolder, mShape.get(), mAreaType))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,10 @@
|
||||||
|
|
||||||
#include "areatype.hpp"
|
#include "areatype.hpp"
|
||||||
|
|
||||||
#include <components/resource/bulletshape.hpp>
|
|
||||||
|
|
||||||
#include <LinearMath/btTransform.h>
|
#include <LinearMath/btTransform.h>
|
||||||
|
|
||||||
#include <osg/ref_ptr>
|
#include <osg/ref_ptr>
|
||||||
|
#include <osg/Referenced>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -20,16 +19,16 @@ namespace DetourNavigator
|
||||||
class CollisionShape
|
class CollisionShape
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CollisionShape(osg::ref_ptr<const Resource::BulletShapeInstance> instance, const btCollisionShape& shape)
|
CollisionShape(osg::ref_ptr<const osg::Referenced> holder, const btCollisionShape& shape)
|
||||||
: mShapeInstance(std::move(instance))
|
: mHolder(std::move(holder))
|
||||||
, mShape(shape)
|
, mShape(shape)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
const osg::ref_ptr<const Resource::BulletShapeInstance>& getShapeInstance() const { return mShapeInstance; }
|
const osg::ref_ptr<const osg::Referenced>& getHolder() const { return mHolder; }
|
||||||
const btCollisionShape& getShape() const { return mShape; }
|
const btCollisionShape& getShape() const { return mShape; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
osg::ref_ptr<const Resource::BulletShapeInstance> mShapeInstance;
|
osg::ref_ptr<const osg::Referenced> mHolder;
|
||||||
std::reference_wrapper<const btCollisionShape> mShape;
|
std::reference_wrapper<const btCollisionShape> mShape;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -40,6 +39,11 @@ namespace DetourNavigator
|
||||||
|
|
||||||
bool update(const btTransform& transform, const AreaType areaType);
|
bool update(const btTransform& transform, const AreaType areaType);
|
||||||
|
|
||||||
|
const osg::ref_ptr<const osg::Referenced>& getHolder() const
|
||||||
|
{
|
||||||
|
return mHolder;
|
||||||
|
}
|
||||||
|
|
||||||
const btCollisionShape& getShape() const
|
const btCollisionShape& getShape() const
|
||||||
{
|
{
|
||||||
return mShape;
|
return mShape;
|
||||||
|
@ -56,7 +60,7 @@ namespace DetourNavigator
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
osg::ref_ptr<const Resource::BulletShapeInstance> mShapeInstance;
|
osg::ref_ptr<const osg::Referenced> mHolder;
|
||||||
std::reference_wrapper<const btCollisionShape> mShape;
|
std::reference_wrapper<const btCollisionShape> mShape;
|
||||||
btTransform mTransform;
|
btTransform mTransform;
|
||||||
AreaType mAreaType;
|
AreaType mAreaType;
|
||||||
|
|
Loading…
Reference in a new issue