Reduce using of the CPU

coverity_scan^2
Koncord 8 years ago
parent 56959ebfda
commit 799842b5da

@ -597,8 +597,9 @@ namespace MWClass
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr())
{ {
mwmp::Main::get().getLocalPlayer()->GetAttack()->success = true; mwmp::Main::get().getLocalPlayer()->GetAttack()->success = true;
if (mwmp::Main::get().getNetworking()->isDedicatedPlayer(victim)) mwmp::DedicatedPlayer *dedicatedPlayer = mwmp::Players::GetPlayer(victim);
mwmp::Main::get().getLocalPlayer()->GetAttack()->target =mwmp::Players::GetPlayer(victim)->guid; if (dedicatedPlayer != nullptr)
mwmp::Main::get().getLocalPlayer()->GetAttack()->target = dedicatedPlayer->guid;
} }
if(Misc::Rng::roll0to99() >= hitchance) if(Misc::Rng::roll0to99() >= hitchance)
@ -733,10 +734,11 @@ namespace MWClass
float knockdownTerm = getCreatureStats(ptr).getAttribute(ESM::Attribute::Agility).getModified() float knockdownTerm = getCreatureStats(ptr).getAttribute(ESM::Attribute::Agility).getModified()
* gmst.iKnockDownOddsMult->getInt() * 0.01f + gmst.iKnockDownOddsBase->getInt(); * gmst.iKnockDownOddsMult->getInt() * 0.01f + gmst.iKnockDownOddsBase->getInt();
bool isDedicated = mwmp::Main::get().getNetworking()->isDedicatedPlayer(attacker); mwmp::DedicatedPlayer *dedicatedPlayer = mwmp::Players::GetPlayer(attacker);
bool isDedicated = dedicatedPlayer != nullptr;
bool _knockdown = false; bool _knockdown = false;
if(isDedicated) if(isDedicated)
_knockdown = mwmp::Players::GetPlayer(attacker)->GetAttack()->knockdown; _knockdown = dedicatedPlayer->GetAttack()->knockdown;
if ((!isDedicated && ishealth && agilityTerm <= damage && knockdownTerm <= Misc::Rng::roll0to99()) || _knockdown) if ((!isDedicated && ishealth && agilityTerm <= damage && knockdownTerm <= Misc::Rng::roll0to99()) || _knockdown)
{ {
@ -843,12 +845,13 @@ namespace MWClass
} }
if (attacker == MWMechanics::getPlayer() && mwmp::Main::get().getNetworking()->isDedicatedPlayer(ptr)) mwmp::DedicatedPlayer *victimPlayer = mwmp::Players::GetPlayer(ptr);
if (attacker == MWMechanics::getPlayer() && victimPlayer != nullptr)
{ {
mwmp::Attack *_atk = mwmp::Main::get().getLocalPlayer()->GetAttack(); mwmp::Attack *_atk = mwmp::Main::get().getLocalPlayer()->GetAttack();
_atk->damage = damage; _atk->damage = damage;
_atk->attacker = mwmp::Main::get().getLocalPlayer()->guid; _atk->attacker = mwmp::Main::get().getLocalPlayer()->guid;
_atk->target = mwmp::Players::GetPlayer(ptr)->guid; _atk->target = victimPlayer->guid;
_atk->knockdown = getCreatureStats(ptr).getKnockedDown(); _atk->knockdown = getCreatureStats(ptr).getKnockedDown();
mwmp::Main::get().getLocalPlayer()->sendAttack(mwmp::Attack::MELEE); // todo: make this sensitive to different weapon types mwmp::Main::get().getLocalPlayer()->sendAttack(mwmp::Attack::MELEE); // todo: make this sensitive to different weapon types
} }

@ -116,12 +116,13 @@ namespace MWMechanics
x = std::min(iBlockMaxChance, std::max(iBlockMinChance, x)); x = std::min(iBlockMaxChance, std::max(iBlockMinChance, x));
bool isDedicated = mwmp::Main::get().getNetworking()->isDedicatedPlayer(blocker); mwmp::DedicatedPlayer *dedicatedPlayer = mwmp::Players::GetPlayer(blocker);
bool isDedicated = dedicatedPlayer != nullptr;
if (attacker == MWMechanics::getPlayer()) if (attacker == MWMechanics::getPlayer())
mwmp::Main::get().getLocalPlayer()->GetAttack()->block = false; mwmp::Main::get().getLocalPlayer()->GetAttack()->block = false;
if ((!isDedicated && Misc::Rng::roll0to99() < x) || if ((!isDedicated && Misc::Rng::roll0to99() < x) ||
(isDedicated && mwmp::Players::GetPlayer(blocker)->GetAttack()->block == 1)) (isDedicated && dedicatedPlayer->GetAttack()->block == 1))
{ {
if (attacker == MWMechanics::getPlayer()) if (attacker == MWMechanics::getPlayer())
mwmp::Main::get().getLocalPlayer()->GetAttack()->block = true; mwmp::Main::get().getLocalPlayer()->GetAttack()->block = true;

@ -797,13 +797,14 @@ namespace MWMechanics
// Check success // Check success
float successChance = getSpellSuccessChance(spell, mCaster); float successChance = getSpellSuccessChance(spell, mCaster);
bool isDedicated = mwmp::Main::get().getNetworking()->isDedicatedPlayer(mCaster); mwmp::DedicatedPlayer *dedicatedPlayer = mwmp::Players::GetPlayer(mCaster);
bool isDedicated = dedicatedPlayer != nullptr;
if (isDedicated) if (isDedicated)
mwmp::Players::GetPlayer(mCaster)->GetAttack()->pressed = false; dedicatedPlayer->GetAttack()->pressed = false;
if ((!isDedicated && !mwmp::Main::get().getLocalPlayer()->GetAttack()->success) || if ((!isDedicated && !mwmp::Main::get().getLocalPlayer()->GetAttack()->success) ||
(isDedicated && mwmp::Players::GetPlayer(mCaster)->GetAttack()->success == 0)) (isDedicated && dedicatedPlayer->GetAttack()->success == 0))
{ {
if (mCaster == getPlayer()) if (mCaster == getPlayer())
{ {

Loading…
Cancel
Save