mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-21 12:53:51 +00:00
Use actor half extent for interior cells
This commit is contained in:
parent
346e9e3141
commit
ff478aba6d
14 changed files with 90 additions and 23 deletions
|
@ -601,6 +601,8 @@ namespace MWBase
|
||||||
|
|
||||||
virtual void updateActorPath(const MWWorld::ConstPtr& actor, const std::deque<osg::Vec3f>& path,
|
virtual void updateActorPath(const MWWorld::ConstPtr& actor, const std::deque<osg::Vec3f>& path,
|
||||||
const osg::Vec3f& halfExtents, const osg::Vec3f& start, const osg::Vec3f& end) const = 0;
|
const osg::Vec3f& halfExtents, const osg::Vec3f& start, const osg::Vec3f& end) const = 0;
|
||||||
|
|
||||||
|
virtual void setNavMeshNumberToRender(const std::size_t value) = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,12 +31,13 @@ namespace MWRender
|
||||||
return mEnabled;
|
return mEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavMesh::update(const DetourNavigator::SharedNavMesh& sharedNavMesh, std::size_t generation,
|
void NavMesh::update(const DetourNavigator::SharedNavMesh& sharedNavMesh, const std::size_t id,
|
||||||
std::size_t revision, const DetourNavigator::Settings& settings)
|
const std::size_t generation, const std::size_t revision, const DetourNavigator::Settings& settings)
|
||||||
{
|
{
|
||||||
if (!mEnabled || (mGeneration >= generation && mRevision >= revision))
|
if (!mEnabled || (mId == id && mGeneration >= generation && mRevision >= revision))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
mId = id;
|
||||||
mGeneration = generation;
|
mGeneration = generation;
|
||||||
mRevision = revision;
|
mRevision = revision;
|
||||||
if (mGroup)
|
if (mGroup)
|
||||||
|
@ -49,6 +50,12 @@ namespace MWRender
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NavMesh::reset()
|
||||||
|
{
|
||||||
|
if (mGroup)
|
||||||
|
mRootNode->removeChild(mGroup);
|
||||||
|
}
|
||||||
|
|
||||||
void NavMesh::enable()
|
void NavMesh::enable()
|
||||||
{
|
{
|
||||||
if (mGroup)
|
if (mGroup)
|
||||||
|
@ -58,8 +65,7 @@ namespace MWRender
|
||||||
|
|
||||||
void NavMesh::disable()
|
void NavMesh::disable()
|
||||||
{
|
{
|
||||||
if (mGroup)
|
reset();
|
||||||
mRootNode->removeChild(mGroup);
|
|
||||||
mEnabled = false;
|
mEnabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,9 +21,12 @@ namespace MWRender
|
||||||
|
|
||||||
bool toggle();
|
bool toggle();
|
||||||
|
|
||||||
void update(const DetourNavigator::SharedNavMesh& sharedNavMesh, std::size_t generation, std::size_t revision,
|
void update(const DetourNavigator::SharedNavMesh& sharedNavMesh,
|
||||||
|
const std::size_t number, const std::size_t generation, const std::size_t revision,
|
||||||
const DetourNavigator::Settings& settings);
|
const DetourNavigator::Settings& settings);
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
|
||||||
void enable();
|
void enable();
|
||||||
|
|
||||||
void disable();
|
void disable();
|
||||||
|
@ -31,6 +34,7 @@ namespace MWRender
|
||||||
private:
|
private:
|
||||||
osg::ref_ptr<osg::Group> mRootNode;
|
osg::ref_ptr<osg::Group> mRootNode;
|
||||||
bool mEnabled;
|
bool mEnabled;
|
||||||
|
std::size_t mId = std::numeric_limits<std::size_t>::max();
|
||||||
std::size_t mGeneration;
|
std::size_t mGeneration;
|
||||||
std::size_t mRevision;
|
std::size_t mRevision;
|
||||||
osg::ref_ptr<osg::Group> mGroup;
|
osg::ref_ptr<osg::Group> mGroup;
|
||||||
|
|
|
@ -600,12 +600,20 @@ namespace MWRender
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto navMeshes = mNavigator.getNavMeshes();
|
const auto navMeshes = mNavigator.getNavMeshes();
|
||||||
if (!navMeshes.empty())
|
|
||||||
|
auto it = navMeshes.begin();
|
||||||
|
for (std::size_t i = 0; it != navMeshes.end() && i < mNavMeshNumber; ++i)
|
||||||
|
++it;
|
||||||
|
if (it == navMeshes.end())
|
||||||
|
{
|
||||||
|
mNavMesh->reset();
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
mNavMesh->update(navMeshes.begin()->second->mValue, navMeshes.begin()->second->mGeneration,
|
mNavMesh->update(it->second->mValue, mNavMeshNumber, it->second->mGeneration,
|
||||||
navMeshes.begin()->second->mNavMeshRevision, mNavigator.getSettings());
|
it->second->mNavMeshRevision, mNavigator.getSettings());
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
|
@ -1388,4 +1396,9 @@ namespace MWRender
|
||||||
{
|
{
|
||||||
mActorsPaths->remove(actor);
|
mActorsPaths->remove(actor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RenderingManager::setNavMeshNumber(const std::size_t value)
|
||||||
|
{
|
||||||
|
mNavMeshNumber = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -228,6 +228,8 @@ namespace MWRender
|
||||||
|
|
||||||
void removeActorPath(const MWWorld::ConstPtr& actor) const;
|
void removeActorPath(const MWWorld::ConstPtr& actor) const;
|
||||||
|
|
||||||
|
void setNavMeshNumber(const std::size_t value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateProjectionMatrix();
|
void updateProjectionMatrix();
|
||||||
void updateTextureFiltering();
|
void updateTextureFiltering();
|
||||||
|
@ -254,6 +256,7 @@ namespace MWRender
|
||||||
|
|
||||||
DetourNavigator::Navigator& mNavigator;
|
DetourNavigator::Navigator& mNavigator;
|
||||||
std::unique_ptr<NavMesh> mNavMesh;
|
std::unique_ptr<NavMesh> mNavMesh;
|
||||||
|
std::size_t mNavMeshNumber = 0;
|
||||||
std::unique_ptr<ActorsPaths> mActorsPaths;
|
std::unique_ptr<ActorsPaths> mActorsPaths;
|
||||||
std::unique_ptr<Pathgrid> mPathgrid;
|
std::unique_ptr<Pathgrid> mPathgrid;
|
||||||
std::unique_ptr<Objects> mObjects;
|
std::unique_ptr<Objects> mObjects;
|
||||||
|
|
|
@ -457,5 +457,6 @@ op 0x2000306: OnActivate, explicit
|
||||||
op 0x2000307: ToggleBorders, tb
|
op 0x2000307: ToggleBorders, tb
|
||||||
op 0x2000308: ToggleNavMesh
|
op 0x2000308: ToggleNavMesh
|
||||||
op 0x2000309: ToggleActorsPaths
|
op 0x2000309: ToggleActorsPaths
|
||||||
|
op 0x200030a: SetNavMeshNumber
|
||||||
|
|
||||||
opcodes 0x200030a-0x3ffffff unused
|
opcodes 0x200030b-0x3ffffff unused
|
||||||
|
|
|
@ -1345,6 +1345,25 @@ namespace MWScript
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class OpSetNavMeshNumberToRender : public Interpreter::Opcode0
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual void execute (Interpreter::Runtime& runtime)
|
||||||
|
{
|
||||||
|
const auto navMeshNumber = runtime[0].mInteger;
|
||||||
|
runtime.pop();
|
||||||
|
|
||||||
|
if (navMeshNumber < 0)
|
||||||
|
{
|
||||||
|
runtime.getContext().report("Invalid navmesh number: use not less than zero values");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MWBase::Environment::get().getWorld()->setNavMeshNumberToRender(static_cast<std::size_t>(navMeshNumber));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void installOpcodes (Interpreter::Interpreter& interpreter)
|
void installOpcodes (Interpreter::Interpreter& interpreter)
|
||||||
{
|
{
|
||||||
interpreter.installSegment5 (Compiler::Misc::opcodeXBox, new OpXBox);
|
interpreter.installSegment5 (Compiler::Misc::opcodeXBox, new OpXBox);
|
||||||
|
@ -1447,6 +1466,7 @@ namespace MWScript
|
||||||
interpreter.installSegment5 (Compiler::Misc::opcodeToggleBorders, new OpToggleBorders);
|
interpreter.installSegment5 (Compiler::Misc::opcodeToggleBorders, new OpToggleBorders);
|
||||||
interpreter.installSegment5 (Compiler::Misc::opcodeToggleNavMesh, new OpToggleNavMesh);
|
interpreter.installSegment5 (Compiler::Misc::opcodeToggleNavMesh, new OpToggleNavMesh);
|
||||||
interpreter.installSegment5 (Compiler::Misc::opcodeToggleActorsPaths, new OpToggleActorsPaths);
|
interpreter.installSegment5 (Compiler::Misc::opcodeToggleActorsPaths, new OpToggleActorsPaths);
|
||||||
|
interpreter.installSegment5 (Compiler::Misc::opcodeSetNavMeshNumberToRender, new OpSetNavMeshNumberToRender);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,8 +175,10 @@ namespace
|
||||||
}
|
}
|
||||||
else if (const auto actor = physics.getActor(ptr))
|
else if (const auto actor = physics.getActor(ptr))
|
||||||
{
|
{
|
||||||
const auto playerHalfExtents = physics.getHalfExtents(MWBase::Environment::get().getWorld()->getPlayerPtr());
|
const auto halfExtents = ptr.getCell()->isExterior()
|
||||||
navigator.addAgent(playerHalfExtents);
|
? physics.getHalfExtents(MWBase::Environment::get().getWorld()->getPlayerPtr())
|
||||||
|
: actor->getHalfExtents();
|
||||||
|
navigator.addAgent(halfExtents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,7 +346,7 @@ namespace MWWorld
|
||||||
navigator->removeObject(reinterpret_cast<std::size_t>(object));
|
navigator->removeObject(reinterpret_cast<std::size_t>(object));
|
||||||
else if (const auto actor = mPhysics->getActor(ptr))
|
else if (const auto actor = mPhysics->getActor(ptr))
|
||||||
{
|
{
|
||||||
navigator->removeAgent(playerHalfExtents);
|
navigator->removeAgent(ptr.getCell()->isExterior() ? playerHalfExtents : actor->getHalfExtents());
|
||||||
mRendering.removeActorPath(ptr);
|
mRendering.removeActorPath(ptr);
|
||||||
}
|
}
|
||||||
mPhysics->remove(ptr);
|
mPhysics->remove(ptr);
|
||||||
|
@ -812,8 +814,10 @@ namespace MWWorld
|
||||||
}
|
}
|
||||||
else if (const auto actor = mPhysics->getActor(ptr))
|
else if (const auto actor = mPhysics->getActor(ptr))
|
||||||
{
|
{
|
||||||
const auto playerHalfExtents = mPhysics->getHalfExtents(MWBase::Environment::get().getWorld()->getPlayerPtr());
|
const auto& halfExtents = ptr.getCell()->isExterior()
|
||||||
navigator->removeAgent(playerHalfExtents);
|
? mPhysics->getHalfExtents(MWBase::Environment::get().getWorld()->getPlayerPtr())
|
||||||
|
: actor->getHalfExtents();
|
||||||
|
navigator->removeAgent(halfExtents);
|
||||||
}
|
}
|
||||||
mPhysics->remove(ptr);
|
mPhysics->remove(ptr);
|
||||||
mRendering.removeObject (ptr);
|
mRendering.removeObject (ptr);
|
||||||
|
|
|
@ -3767,4 +3767,9 @@ namespace MWWorld
|
||||||
mRendering->updateActorPath(actor, path, halfExtents, start, end);
|
mRendering->updateActorPath(actor, path, halfExtents, start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void World::setNavMeshNumberToRender(const std::size_t value)
|
||||||
|
{
|
||||||
|
mRendering->setNavMeshNumber(value);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -703,6 +703,8 @@ namespace MWWorld
|
||||||
|
|
||||||
void updateActorPath(const MWWorld::ConstPtr& actor, const std::deque<osg::Vec3f>& path,
|
void updateActorPath(const MWWorld::ConstPtr& actor, const std::deque<osg::Vec3f>& path,
|
||||||
const osg::Vec3f& halfExtents, const osg::Vec3f& start, const osg::Vec3f& end) const override;
|
const osg::Vec3f& halfExtents, const osg::Vec3f& start, const osg::Vec3f& end) const override;
|
||||||
|
|
||||||
|
void setNavMeshNumberToRender(const std::size_t value) override;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -322,6 +322,7 @@ namespace Compiler
|
||||||
extensions.registerInstruction ("toggleborders", "", opcodeToggleBorders);
|
extensions.registerInstruction ("toggleborders", "", opcodeToggleBorders);
|
||||||
extensions.registerInstruction ("togglenavmesh", "", opcodeToggleNavMesh);
|
extensions.registerInstruction ("togglenavmesh", "", opcodeToggleNavMesh);
|
||||||
extensions.registerInstruction ("toggleactorspaths", "", opcodeToggleActorsPaths);
|
extensions.registerInstruction ("toggleactorspaths", "", opcodeToggleActorsPaths);
|
||||||
|
extensions.registerInstruction ("setnavmeshnumber", "l", opcodeSetNavMeshNumberToRender);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -298,6 +298,7 @@ namespace Compiler
|
||||||
const int opcodeToggleBorders = 0x2000307;
|
const int opcodeToggleBorders = 0x2000307;
|
||||||
const int opcodeToggleNavMesh = 0x2000308;
|
const int opcodeToggleNavMesh = 0x2000308;
|
||||||
const int opcodeToggleActorsPaths = 0x2000309;
|
const int opcodeToggleActorsPaths = 0x2000309;
|
||||||
|
const int opcodeSetNavMeshNumberToRender = 0x200030a;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Sky
|
namespace Sky
|
||||||
|
|
|
@ -122,11 +122,16 @@ namespace DetourNavigator
|
||||||
void NavMeshManager::update(osg::Vec3f playerPosition, const osg::Vec3f& agentHalfExtents)
|
void NavMeshManager::update(osg::Vec3f playerPosition, const osg::Vec3f& agentHalfExtents)
|
||||||
{
|
{
|
||||||
const auto playerTile = getTilePosition(mSettings, toNavMeshCoordinates(mSettings, playerPosition));
|
const auto playerTile = getTilePosition(mSettings, toNavMeshCoordinates(mSettings, playerPosition));
|
||||||
if (mLastRecastMeshManagerRevision >= mRecastMeshManager.getRevision() && mPlayerTile
|
auto& lastRevision = mLastRecastMeshManagerRevision[agentHalfExtents];
|
||||||
&& *mPlayerTile == playerTile)
|
auto lastPlayerTile = mPlayerTile.find(agentHalfExtents);
|
||||||
|
if (lastRevision >= mRecastMeshManager.getRevision() && lastPlayerTile != mPlayerTile.end()
|
||||||
|
&& lastPlayerTile->second == playerTile)
|
||||||
return;
|
return;
|
||||||
mLastRecastMeshManagerRevision = mRecastMeshManager.getRevision();
|
lastRevision = mRecastMeshManager.getRevision();
|
||||||
mPlayerTile = playerTile;
|
if (lastPlayerTile == mPlayerTile.end())
|
||||||
|
lastPlayerTile = mPlayerTile.insert(std::make_pair(agentHalfExtents, playerTile)).first;
|
||||||
|
else
|
||||||
|
lastPlayerTile->second = playerTile;
|
||||||
std::map<TilePosition, ChangeType> tilesToPost;
|
std::map<TilePosition, ChangeType> tilesToPost;
|
||||||
const auto& cached = getCached(agentHalfExtents);
|
const auto& cached = getCached(agentHalfExtents);
|
||||||
const auto changedTiles = mChangedTiles.find(agentHalfExtents);
|
const auto changedTiles = mChangedTiles.find(agentHalfExtents);
|
||||||
|
@ -163,8 +168,8 @@ namespace DetourNavigator
|
||||||
}
|
}
|
||||||
mAsyncNavMeshUpdater.post(agentHalfExtents, cached, playerTile, tilesToPost);
|
mAsyncNavMeshUpdater.post(agentHalfExtents, cached, playerTile, tilesToPost);
|
||||||
log("cache update posted for agent=", agentHalfExtents,
|
log("cache update posted for agent=", agentHalfExtents,
|
||||||
" playerTile=", *mPlayerTile,
|
" playerTile=", lastPlayerTile->second,
|
||||||
" recastMeshManagerRevision=", mLastRecastMeshManagerRevision,
|
" recastMeshManagerRevision=", lastRevision,
|
||||||
" changedTiles=", changedTiles->second.size());
|
" changedTiles=", changedTiles->second.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,8 +58,8 @@ namespace DetourNavigator
|
||||||
std::map<osg::Vec3f, std::map<TilePosition, ChangeType>> mChangedTiles;
|
std::map<osg::Vec3f, std::map<TilePosition, ChangeType>> mChangedTiles;
|
||||||
AsyncNavMeshUpdater mAsyncNavMeshUpdater;
|
AsyncNavMeshUpdater mAsyncNavMeshUpdater;
|
||||||
std::size_t mGenerationCounter = 0;
|
std::size_t mGenerationCounter = 0;
|
||||||
boost::optional<TilePosition> mPlayerTile;
|
std::map<osg::Vec3f, TilePosition> mPlayerTile;
|
||||||
std::size_t mLastRecastMeshManagerRevision = 0;
|
std::map<osg::Vec3f, std::size_t> mLastRecastMeshManagerRevision;
|
||||||
|
|
||||||
void addChangedTiles(const btCollisionShape& shape, const btTransform& transform, const ChangeType changeType);
|
void addChangedTiles(const btCollisionShape& shape, const btTransform& transform, const ChangeType changeType);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue