mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-28 13:09:42 +00:00
Merge setWorldspace and updateBounds
This commit is contained in:
parent
9854d42d56
commit
49db37ee29
8 changed files with 33 additions and 63 deletions
|
@ -591,8 +591,8 @@ namespace MWWorld
|
|||
else
|
||||
unloadCell(cell, navigatorUpdateGuard.get());
|
||||
}
|
||||
mNavigator.setWorldspace(playerCellIndex.mWorldspace, navigatorUpdateGuard.get());
|
||||
mNavigator.updateBounds(pos, navigatorUpdateGuard.get());
|
||||
|
||||
mNavigator.updateBounds(playerCellIndex.mWorldspace, pos, navigatorUpdateGuard.get());
|
||||
|
||||
mCurrentGridCenter = osg::Vec2i(playerCellX, playerCellY);
|
||||
osg::Vec4i newGrid = gridCenterToBounds(mCurrentGridCenter);
|
||||
|
@ -694,10 +694,9 @@ namespace MWWorld
|
|||
|
||||
CellStore& cell = mWorld.getWorldModel().getExterior(
|
||||
ESM::ExteriorCellLocation(it->mData.mX, it->mData.mY, ESM::Cell::sDefaultWorldspaceId));
|
||||
mNavigator.setWorldspace(cell.getCell()->getWorldSpace(), navigatorUpdateGuard.get());
|
||||
const osg::Vec3f position
|
||||
= osg::Vec3f(it->mData.mX + 0.5f, it->mData.mY + 0.5f, 0) * Constants::CellSizeInUnits;
|
||||
mNavigator.updateBounds(position, navigatorUpdateGuard.get());
|
||||
mNavigator.updateBounds(ESM::Cell::sDefaultWorldspaceId, position, navigatorUpdateGuard.get());
|
||||
loadCell(cell, nullptr, false, position, navigatorUpdateGuard.get());
|
||||
|
||||
mNavigator.update(position, navigatorUpdateGuard.get());
|
||||
|
@ -751,10 +750,9 @@ namespace MWWorld
|
|||
+ std::to_string(cells.getIntSize()) + ")...");
|
||||
|
||||
CellStore& cell = mWorld.getWorldModel().getInterior(it->mName);
|
||||
mNavigator.setWorldspace(cell.getCell()->getWorldSpace(), navigatorUpdateGuard.get());
|
||||
ESM::Position position;
|
||||
mWorld.findInteriorPosition(it->mName, position);
|
||||
mNavigator.updateBounds(position.asVec3(), navigatorUpdateGuard.get());
|
||||
mNavigator.updateBounds(cell.getCell()->getWorldSpace(), position.asVec3(), navigatorUpdateGuard.get());
|
||||
loadCell(cell, nullptr, false, position.asVec3(), navigatorUpdateGuard.get());
|
||||
|
||||
mNavigator.update(position.asVec3(), navigatorUpdateGuard.get());
|
||||
|
@ -904,8 +902,7 @@ namespace MWWorld
|
|||
|
||||
loadingListener->setProgressRange(cell.count());
|
||||
|
||||
mNavigator.setWorldspace(cell.getCell()->getWorldSpace(), navigatorUpdateGuard.get());
|
||||
mNavigator.updateBounds(position.asVec3(), navigatorUpdateGuard.get());
|
||||
mNavigator.updateBounds(cell.getCell()->getWorldSpace(), position.asVec3(), navigatorUpdateGuard.get());
|
||||
|
||||
// Load cell.
|
||||
mPagedRefs.clear();
|
||||
|
|
|
@ -44,31 +44,21 @@ namespace
|
|||
struct DetourNavigatorNavigatorTest : Test
|
||||
{
|
||||
Settings mSettings = makeSettings();
|
||||
std::unique_ptr<Navigator> mNavigator;
|
||||
const osg::Vec3f mPlayerPosition;
|
||||
const std::string mWorldspace;
|
||||
std::unique_ptr<Navigator> mNavigator = std::make_unique<NavigatorImpl>(
|
||||
mSettings, std::make_unique<NavMeshDb>(":memory:", std::numeric_limits<std::uint64_t>::max()));
|
||||
const osg::Vec3f mPlayerPosition{ 256, 256, 0 };
|
||||
const ESM::RefId mWorldspace = ESM::RefId::stringRefId("sys::default");
|
||||
const AgentBounds mAgentBounds{ CollisionShapeType::Aabb, { 29, 29, 66 } };
|
||||
osg::Vec3f mStart;
|
||||
osg::Vec3f mEnd;
|
||||
osg::Vec3f mStart{ 52, 460, 1 };
|
||||
osg::Vec3f mEnd{ 460, 52, 1 };
|
||||
std::deque<osg::Vec3f> mPath;
|
||||
std::back_insert_iterator<std::deque<osg::Vec3f>> mOut;
|
||||
std::back_insert_iterator<std::deque<osg::Vec3f>> mOut{ mPath };
|
||||
AreaCosts mAreaCosts;
|
||||
Loading::Listener mListener;
|
||||
const osg::Vec2i mCellPosition{ 0, 0 };
|
||||
const float mEndTolerance = 0;
|
||||
const btTransform mTransform{ btMatrix3x3::getIdentity(), btVector3(256, 256, 0) };
|
||||
const ObjectTransform mObjectTransform{ ESM::Position{ { 256, 256, 0 }, { 0, 0, 0 } }, 0.0f };
|
||||
|
||||
DetourNavigatorNavigatorTest()
|
||||
: mPlayerPosition(256, 256, 0)
|
||||
, mWorldspace("sys::default")
|
||||
, mStart(52, 460, 1)
|
||||
, mEnd(460, 52, 1)
|
||||
, mOut(mPath)
|
||||
{
|
||||
mNavigator.reset(new NavigatorImpl(
|
||||
mSettings, std::make_unique<NavMeshDb>(":memory:", std::numeric_limits<std::uint64_t>::max())));
|
||||
}
|
||||
};
|
||||
|
||||
constexpr std::array<float, 5 * 5> defaultHeightfieldData{ {
|
||||
|
@ -878,7 +868,7 @@ namespace
|
|||
.mScale = 1.0f,
|
||||
};
|
||||
|
||||
mNavigator->updateBounds(mPlayerPosition, nullptr);
|
||||
mNavigator->updateBounds(mWorldspace, mPlayerPosition, nullptr);
|
||||
ASSERT_TRUE(mNavigator->addAgent(mAgentBounds));
|
||||
mNavigator->addObject(ObjectId(&bigBox.shape()), ObjectShapes(bigBox.instance(), objectTransform),
|
||||
btTransform::getIdentity(), nullptr);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "updateguard.hpp"
|
||||
#include "waitconditiontype.hpp"
|
||||
|
||||
#include <components/esm/refid.hpp>
|
||||
#include <components/resource/bulletshape.hpp>
|
||||
|
||||
namespace ESM
|
||||
|
@ -87,17 +88,9 @@ namespace DetourNavigator
|
|||
*/
|
||||
virtual void removeAgent(const AgentBounds& agentBounds) = 0;
|
||||
|
||||
/**
|
||||
* @brief setWorldspace should be called before adding object from new worldspace
|
||||
* @param worldspace
|
||||
*/
|
||||
virtual void setWorldspace(ESM::RefId worldspace, const UpdateGuard* guard) = 0;
|
||||
|
||||
/**
|
||||
* @brief updateBounds should be called before adding object from loading cell
|
||||
* @param playerPosition corresponds to the bounds center
|
||||
*/
|
||||
virtual void updateBounds(const osg::Vec3f& playerPosition, const UpdateGuard* guard) = 0;
|
||||
// Updates bounds for recast mesh and navmesh tiles, removes tiles outside the range.
|
||||
virtual void updateBounds(ESM::RefId worldspace, const osg::Vec3f& playerPosition, const UpdateGuard* guard)
|
||||
= 0;
|
||||
|
||||
/**
|
||||
* @brief addObject is used to add complex object with allowed to walk and avoided to walk shapes
|
||||
|
|
|
@ -33,14 +33,9 @@ namespace DetourNavigator
|
|||
--it->second;
|
||||
}
|
||||
|
||||
void NavigatorImpl::setWorldspace(ESM::RefId worldspace, const UpdateGuard* guard)
|
||||
void NavigatorImpl::updateBounds(ESM::RefId worldspace, const osg::Vec3f& playerPosition, const UpdateGuard* guard)
|
||||
{
|
||||
mNavMeshManager.setWorldspace(worldspace, guard);
|
||||
}
|
||||
|
||||
void NavigatorImpl::updateBounds(const osg::Vec3f& playerPosition, const UpdateGuard* guard)
|
||||
{
|
||||
mNavMeshManager.updateBounds(playerPosition, guard);
|
||||
mNavMeshManager.updateBounds(worldspace, playerPosition, guard);
|
||||
}
|
||||
|
||||
void NavigatorImpl::addObject(
|
||||
|
|
|
@ -27,9 +27,7 @@ namespace DetourNavigator
|
|||
|
||||
void removeAgent(const AgentBounds& agentBounds) override;
|
||||
|
||||
void setWorldspace(ESM::RefId worldspace, const UpdateGuard* guard) override;
|
||||
|
||||
void updateBounds(const osg::Vec3f& playerPosition, const UpdateGuard* guard) override;
|
||||
void updateBounds(ESM::RefId worldspace, const osg::Vec3f& playerPosition, const UpdateGuard* guard) override;
|
||||
|
||||
void addObject(const ObjectId id, const ObjectShapes& shapes, const btTransform& transform,
|
||||
const UpdateGuard* guard) override;
|
||||
|
|
|
@ -24,7 +24,10 @@ namespace DetourNavigator
|
|||
|
||||
void removeAgent(const AgentBounds& /*agentBounds*/) override {}
|
||||
|
||||
void setWorldspace(ESM::RefId /*worldspace*/, const UpdateGuard* /*guard*/) override {}
|
||||
void updateBounds(
|
||||
ESM::RefId /*worldspace*/, const osg::Vec3f& /*playerPosition*/, const UpdateGuard* /*guard*/) override
|
||||
{
|
||||
}
|
||||
|
||||
void addObject(const ObjectId /*id*/, const ObjectShapes& /*shapes*/, const btTransform& /*transform*/,
|
||||
const UpdateGuard* /*guard*/) override
|
||||
|
@ -68,8 +71,6 @@ namespace DetourNavigator
|
|||
|
||||
void update(const osg::Vec3f& /*playerPosition*/, const UpdateGuard* /*guard*/) override {}
|
||||
|
||||
void updateBounds(const osg::Vec3f& /*playerPosition*/, const UpdateGuard* /*guard*/) override {}
|
||||
|
||||
void wait(WaitConditionType /*waitConditionType*/, Loading::Listener* /*listener*/) override {}
|
||||
|
||||
SharedNavMeshCacheItem getNavMesh(const AgentBounds& /*agentBounds*/) const override
|
||||
|
|
|
@ -58,18 +58,16 @@ namespace DetourNavigator
|
|||
{
|
||||
}
|
||||
|
||||
void NavMeshManager::setWorldspace(ESM::RefId worldspace, const UpdateGuard* guard)
|
||||
void NavMeshManager::updateBounds(ESM::RefId worldspace, const osg::Vec3f& playerPosition, const UpdateGuard* guard)
|
||||
{
|
||||
if (worldspace == mWorldspace)
|
||||
return;
|
||||
mRecastMeshManager.setWorldspace(worldspace, guard);
|
||||
for (auto& [agent, cache] : mCache)
|
||||
cache = std::make_shared<GuardedNavMeshCacheItem>(++mGenerationCounter, mSettings);
|
||||
mWorldspace = worldspace;
|
||||
}
|
||||
if (worldspace != mWorldspace)
|
||||
{
|
||||
mRecastMeshManager.setWorldspace(worldspace, guard);
|
||||
for (auto& [agent, cache] : mCache)
|
||||
cache = std::make_shared<GuardedNavMeshCacheItem>(++mGenerationCounter, mSettings);
|
||||
mWorldspace = worldspace;
|
||||
}
|
||||
|
||||
void NavMeshManager::updateBounds(const osg::Vec3f& playerPosition, const UpdateGuard* guard)
|
||||
{
|
||||
const TilePosition playerTile = toNavMeshTilePosition(mSettings.mRecast, playerPosition);
|
||||
const TilesPositionsRange range = makeRange(playerTile, mSettings.mMaxTilesNumber);
|
||||
mRecastMeshManager.setRange(range, guard);
|
||||
|
|
|
@ -24,9 +24,7 @@ namespace DetourNavigator
|
|||
|
||||
ScopedUpdateGuard makeUpdateGuard() { return mRecastMeshManager.makeUpdateGuard(); }
|
||||
|
||||
void setWorldspace(ESM::RefId worldspace, const UpdateGuard* guard);
|
||||
|
||||
void updateBounds(const osg::Vec3f& playerPosition, const UpdateGuard* guard);
|
||||
void updateBounds(ESM::RefId worldspace, const osg::Vec3f& playerPosition, const UpdateGuard* guard);
|
||||
|
||||
bool addObject(const ObjectId id, const CollisionShape& shape, const btTransform& transform,
|
||||
const AreaType areaType, const UpdateGuard* guard);
|
||||
|
|
Loading…
Reference in a new issue