mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-30 09:06:43 +00:00
Merge branch 'fix_find_path_freeze' into 'master'
Fix freezes in pathfinding (#5954) See merge request OpenMW/openmw!740
This commit is contained in:
commit
fcb3fffb9a
1 changed files with 18 additions and 9 deletions
|
@ -25,6 +25,14 @@
|
||||||
|
|
||||||
#include <osg/Quat>
|
#include <osg/Quat>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
float divOrMax(float dividend, float divisor)
|
||||||
|
{
|
||||||
|
return divisor == 0 ? std::numeric_limits<float>::max() * std::numeric_limits<float>::epsilon() : dividend / divisor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MWMechanics::AiPackage::AiPackage(AiPackageTypeId typeId, const Options& options) :
|
MWMechanics::AiPackage::AiPackage(AiPackageTypeId typeId, const Options& options) :
|
||||||
mTypeId(typeId),
|
mTypeId(typeId),
|
||||||
mOptions(options),
|
mOptions(options),
|
||||||
|
@ -416,14 +424,15 @@ DetourNavigator::Flags MWMechanics::AiPackage::getNavigatorFlags(const MWWorld::
|
||||||
const MWWorld::Class& actorClass = actor.getClass();
|
const MWWorld::Class& actorClass = actor.getClass();
|
||||||
DetourNavigator::Flags result = DetourNavigator::Flag_none;
|
DetourNavigator::Flags result = DetourNavigator::Flag_none;
|
||||||
|
|
||||||
if (actorClass.isPureWaterCreature(actor)
|
if ((actorClass.isPureWaterCreature(actor)
|
||||||
|| (getTypeId() != AiPackageTypeId::Wander
|
|| (getTypeId() != AiPackageTypeId::Wander
|
||||||
&& ((allowToFollowOverWaterSurface && getTypeId() == AiPackageTypeId::Follow)
|
&& ((allowToFollowOverWaterSurface && getTypeId() == AiPackageTypeId::Follow)
|
||||||
|| actorClass.canSwim(actor)
|
|| actorClass.canSwim(actor)
|
||||||
|| hasWaterWalking(actor))))
|
|| hasWaterWalking(actor)))
|
||||||
|
) && actorClass.getSwimSpeed(actor) > 0)
|
||||||
result |= DetourNavigator::Flag_swim;
|
result |= DetourNavigator::Flag_swim;
|
||||||
|
|
||||||
if (actorClass.canWalk(actor))
|
if (actorClass.canWalk(actor) && actor.getClass().getWalkSpeed(actor) > 0)
|
||||||
result |= DetourNavigator::Flag_walk;
|
result |= DetourNavigator::Flag_walk;
|
||||||
|
|
||||||
if (actorClass.isBipedal(actor) && getTypeId() != AiPackageTypeId::Wander)
|
if (actorClass.isBipedal(actor) && getTypeId() != AiPackageTypeId::Wander)
|
||||||
|
@ -439,15 +448,15 @@ DetourNavigator::AreaCosts MWMechanics::AiPackage::getAreaCosts(const MWWorld::P
|
||||||
const MWWorld::Class& actorClass = actor.getClass();
|
const MWWorld::Class& actorClass = actor.getClass();
|
||||||
|
|
||||||
if (flags & DetourNavigator::Flag_swim)
|
if (flags & DetourNavigator::Flag_swim)
|
||||||
costs.mWater = costs.mWater / actorClass.getSwimSpeed(actor);
|
costs.mWater = divOrMax(costs.mWater, actorClass.getSwimSpeed(actor));
|
||||||
|
|
||||||
if (flags & DetourNavigator::Flag_walk)
|
if (flags & DetourNavigator::Flag_walk)
|
||||||
{
|
{
|
||||||
float walkCost;
|
float walkCost;
|
||||||
if (getTypeId() == AiPackageTypeId::Wander)
|
if (getTypeId() == AiPackageTypeId::Wander)
|
||||||
walkCost = 1.0 / actorClass.getWalkSpeed(actor);
|
walkCost = divOrMax(1.0, actorClass.getWalkSpeed(actor));
|
||||||
else
|
else
|
||||||
walkCost = 1.0 / actorClass.getRunSpeed(actor);
|
walkCost = divOrMax(1.0, actorClass.getRunSpeed(actor));
|
||||||
costs.mDoor = costs.mDoor * walkCost;
|
costs.mDoor = costs.mDoor * walkCost;
|
||||||
costs.mPathgrid = costs.mPathgrid * walkCost;
|
costs.mPathgrid = costs.mPathgrid * walkCost;
|
||||||
costs.mGround = costs.mGround * walkCost;
|
costs.mGround = costs.mGround * walkCost;
|
||||||
|
|
Loading…
Reference in a new issue