mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-04-01 07:06:46 +00:00
Optimize drowning state update
This commit is contained in:
parent
1634284739
commit
2ac2d01432
2 changed files with 10 additions and 21 deletions
|
@ -501,12 +501,6 @@ namespace MWMechanics
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Actors::updateNpc (const MWWorld::Ptr& ptr, float duration)
|
|
||||||
{
|
|
||||||
updateDrowning(ptr, duration);
|
|
||||||
calculateNpcStatModifiers(ptr, duration);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Actors::adjustMagicEffects (const MWWorld::Ptr& creature)
|
void Actors::adjustMagicEffects (const MWWorld::Ptr& creature)
|
||||||
{
|
{
|
||||||
CreatureStats& creatureStats = creature.getClass().getCreatureStats (creature);
|
CreatureStats& creatureStats = creature.getClass().getCreatureStats (creature);
|
||||||
|
@ -926,13 +920,8 @@ namespace MWMechanics
|
||||||
return ctrl->isSneaking();
|
return ctrl->isSneaking();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Actors::updateDrowning(const MWWorld::Ptr& ptr, float duration)
|
void Actors::updateDrowning(const MWWorld::Ptr& ptr, float duration, bool isKnockedOut, bool isPlayer)
|
||||||
{
|
{
|
||||||
PtrActorMap::iterator it = mActors.find(ptr);
|
|
||||||
if (it == mActors.end())
|
|
||||||
return;
|
|
||||||
CharacterController* ctrl = it->second->getCharacterController();
|
|
||||||
|
|
||||||
NpcStats &stats = ptr.getClass().getNpcStats(ptr);
|
NpcStats &stats = ptr.getClass().getNpcStats(ptr);
|
||||||
|
|
||||||
// When npc stats are just initialized, mTimeToStartDrowning == -1 and we should get value from GMST
|
// When npc stats are just initialized, mTimeToStartDrowning == -1 and we should get value from GMST
|
||||||
|
@ -940,9 +929,10 @@ namespace MWMechanics
|
||||||
if (stats.getTimeToStartDrowning() == -1.f)
|
if (stats.getTimeToStartDrowning() == -1.f)
|
||||||
stats.setTimeToStartDrowning(fHoldBreathTime);
|
stats.setTimeToStartDrowning(fHoldBreathTime);
|
||||||
|
|
||||||
if (ptr.getClass().isNpc() && stats.getTimeToStartDrowning() < fHoldBreathTime / 2)
|
if (stats.getTimeToStartDrowning() < fHoldBreathTime / 2)
|
||||||
{
|
{
|
||||||
if(ptr != MWMechanics::getPlayer() ) {
|
if(!isPlayer)
|
||||||
|
{
|
||||||
MWMechanics::AiSequence& seq = ptr.getClass().getCreatureStats(ptr).getAiSequence();
|
MWMechanics::AiSequence& seq = ptr.getClass().getCreatureStats(ptr).getAiSequence();
|
||||||
if(seq.getTypeId() != MWMechanics::AiPackage::TypeIdBreathe) //Only add it once
|
if(seq.getTypeId() != MWMechanics::AiPackage::TypeIdBreathe) //Only add it once
|
||||||
seq.stack(MWMechanics::AiBreathe(), ptr);
|
seq.stack(MWMechanics::AiBreathe(), ptr);
|
||||||
|
@ -950,7 +940,7 @@ namespace MWMechanics
|
||||||
}
|
}
|
||||||
|
|
||||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||||
bool knockedOutUnderwater = (ctrl->isKnockedOut() && world->isUnderwater(ptr.getCell(), osg::Vec3f(ptr.getRefData().getPosition().asVec3())));
|
bool knockedOutUnderwater = (isKnockedOut && world->isUnderwater(ptr.getCell(), osg::Vec3f(ptr.getRefData().getPosition().asVec3())));
|
||||||
if((world->isSubmerged(ptr) || knockedOutUnderwater)
|
if((world->isSubmerged(ptr) || knockedOutUnderwater)
|
||||||
&& stats.getMagicEffects().get(ESM::MagicEffect::WaterBreathing).getMagnitude() == 0)
|
&& stats.getMagicEffects().get(ESM::MagicEffect::WaterBreathing).getMagnitude() == 0)
|
||||||
{
|
{
|
||||||
|
@ -965,7 +955,7 @@ namespace MWMechanics
|
||||||
stats.setTimeToStartDrowning(timeLeft);
|
stats.setTimeToStartDrowning(timeLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool godmode = ptr == MWMechanics::getPlayer() && MWBase::Environment::get().getWorld()->getGodModeState();
|
bool godmode = isPlayer && MWBase::Environment::get().getWorld()->getGodModeState();
|
||||||
|
|
||||||
if(timeLeft == 0.0f && !godmode)
|
if(timeLeft == 0.0f && !godmode)
|
||||||
{
|
{
|
||||||
|
@ -980,7 +970,7 @@ namespace MWMechanics
|
||||||
if(!sndmgr->getSoundPlaying(ptr, "drown"))
|
if(!sndmgr->getSoundPlaying(ptr, "drown"))
|
||||||
sndmgr->playSound3D(ptr, "drown", 1.0f, 1.0f);
|
sndmgr->playSound3D(ptr, "drown", 1.0f, 1.0f);
|
||||||
|
|
||||||
if(ptr == world->getPlayerPtr())
|
if(isPlayer)
|
||||||
MWBase::Environment::get().getWindowManager()->activateHitOverlay(false);
|
MWBase::Environment::get().getWindowManager()->activateHitOverlay(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1406,7 +1396,8 @@ namespace MWMechanics
|
||||||
|
|
||||||
if(iter->first.getTypeName() == typeid(ESM::NPC).name())
|
if(iter->first.getTypeName() == typeid(ESM::NPC).name())
|
||||||
{
|
{
|
||||||
updateNpc(iter->first, duration);
|
updateDrowning(iter->first, duration, iter->second->getCharacterController()->isKnockedOut(), isPlayer);
|
||||||
|
calculateNpcStatModifiers(iter->first, duration);
|
||||||
|
|
||||||
if (timerUpdateEquippedLight == 0)
|
if (timerUpdateEquippedLight == 0)
|
||||||
updateEquippedLight(iter->first, updateEquippedLightInterval, showTorches);
|
updateEquippedLight(iter->first, updateEquippedLightInterval, showTorches);
|
||||||
|
|
|
@ -28,8 +28,6 @@ namespace MWMechanics
|
||||||
void addBoundItem (const std::string& itemId, const MWWorld::Ptr& actor);
|
void addBoundItem (const std::string& itemId, const MWWorld::Ptr& actor);
|
||||||
void removeBoundItem (const std::string& itemId, const MWWorld::Ptr& actor);
|
void removeBoundItem (const std::string& itemId, const MWWorld::Ptr& actor);
|
||||||
|
|
||||||
void updateNpc(const MWWorld::Ptr &ptr, float duration);
|
|
||||||
|
|
||||||
void adjustMagicEffects (const MWWorld::Ptr& creature);
|
void adjustMagicEffects (const MWWorld::Ptr& creature);
|
||||||
|
|
||||||
void calculateDynamicStats (const MWWorld::Ptr& ptr);
|
void calculateDynamicStats (const MWWorld::Ptr& ptr);
|
||||||
|
@ -39,7 +37,7 @@ namespace MWMechanics
|
||||||
|
|
||||||
void calculateRestoration (const MWWorld::Ptr& ptr, float duration);
|
void calculateRestoration (const MWWorld::Ptr& ptr, float duration);
|
||||||
|
|
||||||
void updateDrowning (const MWWorld::Ptr& ptr, float duration);
|
void updateDrowning (const MWWorld::Ptr& ptr, float duration, bool isKnockedOut, bool isPlayer);
|
||||||
|
|
||||||
void updateEquippedLight (const MWWorld::Ptr& ptr, float duration, bool mayEquip);
|
void updateEquippedLight (const MWWorld::Ptr& ptr, float duration, bool mayEquip);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue