1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-25 16:43:33 +00:00

Remove redundant store lookups

This commit is contained in:
Evil Eye 2022-09-04 15:42:40 +02:00
parent 325081dc07
commit 06d6de50e6
4 changed files with 21 additions and 40 deletions

View File

@ -1426,30 +1426,31 @@ bool CharacterController::updateWeaponState()
else if (!spellid.empty() && spellCastResult != MWWorld::SpellCastState::PowerAlreadyUsed) else if (!spellid.empty() && spellCastResult != MWWorld::SpellCastState::PowerAlreadyUsed)
{ {
world->breakInvisibility(mPtr); world->breakInvisibility(mPtr);
MWMechanics::CastSpell cast(mPtr, nullptr, false, mCastingManualSpell); MWMechanics::CastSpell cast(mPtr, {}, false, mCastingManualSpell);
cast.playSpellCastingEffects(spellid, isMagicItem);
std::vector<ESM::ENAMstruct> effects; const std::vector<ESM::ENAMstruct>* effects{nullptr};
const MWWorld::ESMStore &store = world->getStore(); const MWWorld::ESMStore &store = world->getStore();
if (isMagicItem) if (isMagicItem)
{ {
const ESM::Enchantment *enchantment = store.get<ESM::Enchantment>().find(spellid); const ESM::Enchantment *enchantment = store.get<ESM::Enchantment>().find(spellid);
effects = enchantment->mEffects.mList; effects = &enchantment->mEffects.mList;
cast.playSpellCastingEffects(enchantment);
} }
else else
{ {
const ESM::Spell *spell = store.get<ESM::Spell>().find(spellid); const ESM::Spell *spell = store.get<ESM::Spell>().find(spellid);
effects = spell->mEffects.mList; effects = &spell->mEffects.mList;
cast.playSpellCastingEffects(spell);
} }
if (mCanCast) if (mCanCast)
{ {
const ESM::MagicEffect *effect = store.get<ESM::MagicEffect>().find(effects.back().mEffectID); // use last effect of list for color of VFX_Hands const ESM::MagicEffect *effect = store.get<ESM::MagicEffect>().find(effects->back().mEffectID); // use last effect of list for color of VFX_Hands
const ESM::Static* castStatic = world->getStore().get<ESM::Static>().find ("VFX_Hands"); const ESM::Static* castStatic = world->getStore().get<ESM::Static>().find ("VFX_Hands");
const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS(); const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
for (size_t iter = 0; iter < effects.size(); ++iter) // play hands vfx for each effect if (!effects->empty())
{ {
if (mAnimation->getNode("Bip01 L Hand")) if (mAnimation->getNode("Bip01 L Hand"))
mAnimation->addEffect( mAnimation->addEffect(
@ -1463,7 +1464,7 @@ bool CharacterController::updateWeaponState()
} }
} }
const ESM::ENAMstruct &firstEffect = effects.at(0); // first effect used for casting animation const ESM::ENAMstruct& firstEffect = effects->at(0); // first effect used for casting animation
std::string startKey; std::string startKey;
std::string stopKey; std::string stopKey;

View File

@ -169,24 +169,6 @@ namespace MWMechanics
if (!found) if (!found)
return; return;
const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search (mId);
if (spell && targetIsActor && (spell->mData.mType == ESM::Spell::ST_Disease || spell->mData.mType == ESM::Spell::ST_Blight))
{
int requiredResistance = (spell->mData.mType == ESM::Spell::ST_Disease) ?
ESM::MagicEffect::ResistCommonDisease
: ESM::MagicEffect::ResistBlightDisease;
float x = target.getClass().getCreatureStats(target).getMagicEffects().get(requiredResistance).getMagnitude();
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
if (Misc::Rng::roll0to99(prng) <= x)
{
// Fully resisted, show message
if (target == getPlayer())
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicPCResisted}");
return;
}
}
ActiveSpells::ActiveSpellParams params(*this, mCaster); ActiveSpells::ActiveSpellParams params(*this, mCaster);
bool castByPlayer = (!mCaster.isEmpty() && mCaster == getPlayer()); bool castByPlayer = (!mCaster.isEmpty() && mCaster == getPlayer());
@ -522,19 +504,14 @@ namespace MWMechanics
return true; return true;
} }
void CastSpell::playSpellCastingEffects(std::string_view spellid, bool enchantment) const void CastSpell::playSpellCastingEffects(const ESM::Enchantment* enchantment) const
{ {
const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); playSpellCastingEffects(enchantment->mEffects.mList);
if (enchantment) }
{
if (const auto spell = store.get<ESM::Enchantment>().search(spellid)) void CastSpell::playSpellCastingEffects(const ESM::Spell* spell) const
playSpellCastingEffects(spell->mEffects.mList); {
} playSpellCastingEffects(spell->mEffects.mList);
else
{
if (const auto spell = store.get<ESM::Spell>().search(spellid))
playSpellCastingEffects(spell->mEffects.mList);
}
} }
void CastSpell::playSpellCastingEffects(const std::vector<ESM::ENAMstruct>& effects) const void CastSpell::playSpellCastingEffects(const std::vector<ESM::ENAMstruct>& effects) const

View File

@ -12,6 +12,7 @@ namespace ESM
struct Ingredient; struct Ingredient;
struct Potion; struct Potion;
struct EffectList; struct EffectList;
struct Enchantment;
struct MagicEffect; struct MagicEffect;
} }
@ -58,7 +59,9 @@ namespace MWMechanics
/// @note Auto detects if spell, ingredient or potion /// @note Auto detects if spell, ingredient or potion
bool cast (const std::string& id); bool cast (const std::string& id);
void playSpellCastingEffects(std::string_view spellid, bool enchantment) const; void playSpellCastingEffects(const ESM::Enchantment* enchantment) const;
void playSpellCastingEffects(const ESM::Spell* spell) const;
/// @note \a target can be any type of object, not just actors. /// @note \a target can be any type of object, not just actors.
void inflict(const MWWorld::Ptr& target, const ESM::EffectList& effects, ESM::RangeType range, bool exploded = false) const; void inflict(const MWWorld::Ptr& target, const ESM::EffectList& effects, ESM::RangeType range, bool exploded = false) const;

View File

@ -1263,7 +1263,7 @@ namespace MWScript
return; return;
MWMechanics::CastSpell cast(ptr, target, false, true); MWMechanics::CastSpell cast(ptr, target, false, true);
cast.playSpellCastingEffects(spell->mId, false); cast.playSpellCastingEffects(spell);
cast.mHitPosition = target.getRefData().getPosition().asVec3(); cast.mHitPosition = target.getRefData().getPosition().asVec3();
cast.mAlwaysSucceed = true; cast.mAlwaysSucceed = true;
cast.cast(spell); cast.cast(spell);