1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-04-10 06:44:29 +00:00

Reduce calls in CharacterController::refreshHitRecoilAnims

This commit is contained in:
ζeh Matt 2022-04-09 01:06:15 +03:00
parent 9275b3c08f
commit 25b26f6fa7
No known key found for this signature in database
GPG Key ID: 18CE582C71A225B0

View File

@ -207,15 +207,17 @@ std::string CharacterController::chooseRandomGroup (const std::string& prefix, i
void CharacterController::refreshHitRecoilAnims(CharacterState& idle) void CharacterController::refreshHitRecoilAnims(CharacterState& idle)
{ {
bool recovery = mPtr.getClass().getCreatureStats(mPtr).getHitRecovery(); auto* world = MWBase::Environment::get().getWorld();
bool knockdown = mPtr.getClass().getCreatureStats(mPtr).getKnockedDown(); auto& charClass = mPtr.getClass();
bool block = mPtr.getClass().getCreatureStats(mPtr).getBlock(); auto& stats = charClass.getCreatureStats(mPtr);
bool isSwimming = MWBase::Environment::get().getWorld()->isSwimming(mPtr); bool recovery = stats.getHitRecovery();
auto& prng = MWBase::Environment::get().getWorld()->getPrng(); bool knockdown = stats.getKnockedDown();
bool block = stats.getBlock();
bool isSwimming = world->isSwimming(mPtr);
auto& prng = world->getPrng();
if(mHitState == CharState_None) if(mHitState == CharState_None)
{ {
if ((mPtr.getClass().getCreatureStats(mPtr).getFatigue().getCurrent() < 0 if (stats.getFatigue().getCurrent() < 0 || stats.getFatigue().getBase() == 0)
|| mPtr.getClass().getCreatureStats(mPtr).getFatigue().getBase() == 0))
{ {
mTimeUntilWake = Misc::Rng::rollClosedProbability(prng) * 2 + 1; // Wake up after 1 to 3 seconds mTimeUntilWake = Misc::Rng::rollClosedProbability(prng) * 2 + 1; // Wake up after 1 to 3 seconds
if (isSwimming && mAnimation->hasAnimation("swimknockout")) if (isSwimming && mAnimation->hasAnimation("swimknockout"))
@ -236,7 +238,7 @@ void CharacterController::refreshHitRecoilAnims(CharacterState& idle)
mCurrentHit.erase(); mCurrentHit.erase();
} }
mPtr.getClass().getCreatureStats(mPtr).setKnockedDown(true); stats.setKnockedDown(true);
} }
else if (knockdown) else if (knockdown)
{ {
@ -255,7 +257,7 @@ void CharacterController::refreshHitRecoilAnims(CharacterState& idle)
else else
{ {
// Knockdown animation is missing. Cancel knockdown state. // Knockdown animation is missing. Cancel knockdown state.
mPtr.getClass().getCreatureStats(mPtr).setKnockedDown(false); stats.setKnockedDown(false);
} }
} }
else if (recovery) else if (recovery)
@ -311,15 +313,14 @@ void CharacterController::refreshHitRecoilAnims(CharacterState& idle)
{ {
mCurrentHit.erase(); mCurrentHit.erase();
if (knockdown) if (knockdown)
mPtr.getClass().getCreatureStats(mPtr).setKnockedDown(false); stats.setKnockedDown(false);
if (recovery) if (recovery)
mPtr.getClass().getCreatureStats(mPtr).setHitRecovery(false); stats.setHitRecovery(false);
if (block) if (block)
mPtr.getClass().getCreatureStats(mPtr).setBlock(false); stats.setBlock(false);
mHitState = CharState_None; mHitState = CharState_None;
} }
else if (isKnockedOut() && mPtr.getClass().getCreatureStats(mPtr).getFatigue().getCurrent() > 0 else if (isKnockedOut() && stats.getFatigue().getCurrent() > 0 && mTimeUntilWake <= 0)
&& mTimeUntilWake <= 0)
{ {
mHitState = isSwimming ? CharState_SwimKnockDown : CharState_KnockDown; mHitState = isSwimming ? CharState_SwimKnockDown : CharState_KnockDown;
mAnimation->disable(mCurrentHit); mAnimation->disable(mCurrentHit);