[10273] Avoid some redundent and recursive calls to SpellMgr singleton.

This commit is contained in:
VladimirMangos 2010-07-26 16:34:25 +04:00
parent 730b4deaaf
commit 6a4cae890e
4 changed files with 29 additions and 19 deletions

View file

@ -3011,7 +3011,7 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen
{ {
uint32 next_active_spell_id = 0; uint32 next_active_spell_id = 0;
// fix activate state for non-stackable low rank (and find next spell for !active case) // fix activate state for non-stackable low rank (and find next spell for !active case)
if(!SpellMgr::canStackSpellRanks(spellInfo) && sSpellMgr.GetSpellRank(spellInfo->Id) != 0) if(sSpellMgr.IsRankedSpellNonStackableInSpellBook(spellInfo))
{ {
SpellChainMapNext const& nextMap = sSpellMgr.GetSpellChainNext(); SpellChainMapNext const& nextMap = sSpellMgr.GetSpellChainNext();
for(SpellChainMapNext::const_iterator next_itr = nextMap.lower_bound(spell_id); next_itr != nextMap.upper_bound(spell_id); ++next_itr) for(SpellChainMapNext::const_iterator next_itr = nextMap.lower_bound(spell_id); next_itr != nextMap.upper_bound(spell_id); ++next_itr)
@ -3149,7 +3149,7 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen
newspell.disabled = disabled; newspell.disabled = disabled;
// replace spells in action bars and spellbook to bigger rank if only one spell rank must be accessible // replace spells in action bars and spellbook to bigger rank if only one spell rank must be accessible
if(newspell.active && !newspell.disabled && !SpellMgr::canStackSpellRanks(spellInfo) && sSpellMgr.GetSpellRank(spellInfo->Id) != 0) if(newspell.active && !newspell.disabled && sSpellMgr.IsRankedSpellNonStackableInSpellBook(spellInfo))
{ {
for( PlayerSpellMap::iterator itr2 = m_spells.begin(); itr2 != m_spells.end(); ++itr2 ) for( PlayerSpellMap::iterator itr2 = m_spells.begin(); itr2 != m_spells.end(); ++itr2 )
{ {
@ -3546,8 +3546,8 @@ void Player::removeSpell(uint32 spell_id, bool disabled, bool learn_low_rank, bo
if(learn_low_rank) if(learn_low_rank)
learnSpell(prev_id, false); learnSpell(prev_id, false);
} }
// if ranked non-stackable spell: need activate lesser rank and update dendence state // if ranked non-stackable spell: need activate lesser rank and update dependence state
else if (cur_active && !SpellMgr::canStackSpellRanks(spellInfo) && sSpellMgr.GetSpellRank(spellInfo->Id) != 0) else if (cur_active && sSpellMgr.IsRankedSpellNonStackableInSpellBook(spellInfo))
{ {
// need manually update dependence state (learn spell ignore like attempts) // need manually update dependence state (learn spell ignore like attempts)
PlayerSpellMap::iterator prev_itr = m_spells.find(prev_id); PlayerSpellMap::iterator prev_itr = m_spells.find(prev_id);

View file

@ -1255,8 +1255,10 @@ void SpellMgr::LoadSpellProcEvents()
struct DoSpellProcItemEnchant struct DoSpellProcItemEnchant
{ {
DoSpellProcItemEnchant(float _ppm) : ppm(_ppm) {} DoSpellProcItemEnchant(SpellProcItemEnchantMap& _procMap, float _ppm) : procMap(_procMap), ppm(_ppm) {}
void operator() (uint32 spell_id) { sSpellMgr.mSpellProcItemEnchantMap[spell_id] = ppm; } void operator() (uint32 spell_id) { procMap[spell_id] = ppm; }
SpellProcItemEnchantMap& procMap;
float ppm; float ppm;
}; };
@ -1311,7 +1313,7 @@ void SpellMgr::LoadSpellProcItemEnchant()
mSpellProcItemEnchantMap[entry] = ppmRate; mSpellProcItemEnchantMap[entry] = ppmRate;
// also add to high ranks // also add to high ranks
DoSpellProcItemEnchant worker(ppmRate); DoSpellProcItemEnchant worker(mSpellProcItemEnchantMap, ppmRate);
doForHighRanks(entry,worker); doForHighRanks(entry,worker);
++count; ++count;
@ -1325,8 +1327,10 @@ void SpellMgr::LoadSpellProcItemEnchant()
struct DoSpellBonuses struct DoSpellBonuses
{ {
DoSpellBonuses(SpellBonusEntry const& _spellBonus) : spellBonus(_spellBonus) {} DoSpellBonuses(SpellBonusMap& _spellBonusMap, SpellBonusEntry const& _spellBonus) : spellBonusMap(spellBonusMap), spellBonus(_spellBonus) {}
void operator() (uint32 spell_id) { sSpellMgr.mSpellBonusMap[spell_id] = spellBonus; } void operator() (uint32 spell_id) { spellBonusMap[spell_id] = spellBonus; }
SpellBonusMap& spellBonusMap;
SpellBonusEntry const& spellBonus; SpellBonusEntry const& spellBonus;
}; };
@ -1468,7 +1472,7 @@ void SpellMgr::LoadSpellBonuses()
mSpellBonusMap[entry] = sbe; mSpellBonusMap[entry] = sbe;
// also add to high ranks // also add to high ranks
DoSpellBonuses worker(sbe); DoSpellBonuses worker(mSpellBonusMap, sbe);
doForHighRanks(entry,worker); doForHighRanks(entry,worker);
++count; ++count;
@ -1643,16 +1647,16 @@ bool SpellMgr::IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellI
return GetFirstSpellInChain(spellInfo_1->Id)==GetFirstSpellInChain(spellId_2); return GetFirstSpellInChain(spellInfo_1->Id)==GetFirstSpellInChain(spellId_2);
} }
bool SpellMgr::canStackSpellRanks(SpellEntry const *spellInfo) bool SpellMgr::canStackSpellRanksInSpellBook(SpellEntry const *spellInfo) const
{ {
if(IsPassiveSpell(spellInfo)) // ranked passive spell if (IsPassiveSpell(spellInfo)) // ranked passive spell
return false; return false;
if(spellInfo->powerType != POWER_MANA && spellInfo->powerType != POWER_HEALTH) if (spellInfo->powerType != POWER_MANA && spellInfo->powerType != POWER_HEALTH)
return false; return false;
if(IsProfessionOrRidingSpell(spellInfo->Id)) if (IsProfessionOrRidingSpell(spellInfo->Id))
return false; return false;
if(sSpellMgr.IsSkillBonusSpell(spellInfo->Id)) if (IsSkillBonusSpell(spellInfo->Id))
return false; return false;
// All stance spells. if any better way, change it. // All stance spells. if any better way, change it.
@ -2926,7 +2930,7 @@ void SpellMgr::LoadPetLevelupSpellMap()
sLog.outString( ">> Loaded %u pet levelup and default spells for %u families", count, family_count ); sLog.outString( ">> Loaded %u pet levelup and default spells for %u families", count, family_count );
} }
bool LoadPetDefaultSpells_helper(CreatureInfo const* cInfo, PetDefaultSpellsEntry& petDefSpells) bool SpellMgr::LoadPetDefaultSpells_helper(CreatureInfo const* cInfo, PetDefaultSpellsEntry& petDefSpells)
{ {
// skip empty list; // skip empty list;
bool have_spell = false; bool have_spell = false;
@ -2942,7 +2946,7 @@ bool LoadPetDefaultSpells_helper(CreatureInfo const* cInfo, PetDefaultSpellsEntr
return false; return false;
// remove duplicates with levelupSpells if any // remove duplicates with levelupSpells if any
if(PetLevelupSpellSet const *levelupSpells = cInfo->family ? sSpellMgr.GetPetLevelupSpellList(cInfo->family) : NULL) if(PetLevelupSpellSet const *levelupSpells = cInfo->family ? GetPetLevelupSpellList(cInfo->family) : NULL)
{ {
for(int j = 0; j < MAX_CREATURE_SPELL_DATA_SLOT; ++j) for(int j = 0; j < MAX_CREATURE_SPELL_DATA_SLOT; ++j)
{ {

View file

@ -967,8 +967,12 @@ class SpellMgr
} }
bool IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellId_2) const; bool IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellId_2) const;
static bool canStackSpellRanks(SpellEntry const *spellInfo);
bool IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2) const; bool IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2) const;
bool canStackSpellRanksInSpellBook(SpellEntry const *spellInfo) const;
bool IsRankedSpellNonStackableInSpellBook(SpellEntry const *spellInfo) const
{
return !canStackSpellRanksInSpellBook(spellInfo) && GetSpellRank(spellInfo->Id) != 0;
}
SpellEntry const* SelectAuraRankForLevel(SpellEntry const* spellInfo, uint32 Level) const; SpellEntry const* SelectAuraRankForLevel(SpellEntry const* spellInfo, uint32 Level) const;
@ -1104,6 +1108,8 @@ class SpellMgr
void LoadSpellAreas(); void LoadSpellAreas();
private: private:
bool LoadPetDefaultSpells_helper(CreatureInfo const* cInfo, PetDefaultSpellsEntry& petDefSpells);
SpellScriptTarget mSpellScriptTarget; SpellScriptTarget mSpellScriptTarget;
SpellChainMap mSpellChains; SpellChainMap mSpellChains;
SpellChainMapNext mSpellChainsNext; SpellChainMapNext mSpellChainsNext;

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "10272" #define REVISION_NR "10273"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__