[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;
// 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();
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;
// 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 )
{
@ -3546,8 +3546,8 @@ void Player::removeSpell(uint32 spell_id, bool disabled, bool learn_low_rank, bo
if(learn_low_rank)
learnSpell(prev_id, false);
}
// if ranked non-stackable spell: need activate lesser rank and update dendence state
else if (cur_active && !SpellMgr::canStackSpellRanks(spellInfo) && sSpellMgr.GetSpellRank(spellInfo->Id) != 0)
// if ranked non-stackable spell: need activate lesser rank and update dependence state
else if (cur_active && sSpellMgr.IsRankedSpellNonStackableInSpellBook(spellInfo))
{
// need manually update dependence state (learn spell ignore like attempts)
PlayerSpellMap::iterator prev_itr = m_spells.find(prev_id);

View file

@ -1255,8 +1255,10 @@ void SpellMgr::LoadSpellProcEvents()
struct DoSpellProcItemEnchant
{
DoSpellProcItemEnchant(float _ppm) : ppm(_ppm) {}
void operator() (uint32 spell_id) { sSpellMgr.mSpellProcItemEnchantMap[spell_id] = ppm; }
DoSpellProcItemEnchant(SpellProcItemEnchantMap& _procMap, float _ppm) : procMap(_procMap), ppm(_ppm) {}
void operator() (uint32 spell_id) { procMap[spell_id] = ppm; }
SpellProcItemEnchantMap& procMap;
float ppm;
};
@ -1311,7 +1313,7 @@ void SpellMgr::LoadSpellProcItemEnchant()
mSpellProcItemEnchantMap[entry] = ppmRate;
// also add to high ranks
DoSpellProcItemEnchant worker(ppmRate);
DoSpellProcItemEnchant worker(mSpellProcItemEnchantMap, ppmRate);
doForHighRanks(entry,worker);
++count;
@ -1325,8 +1327,10 @@ void SpellMgr::LoadSpellProcItemEnchant()
struct DoSpellBonuses
{
DoSpellBonuses(SpellBonusEntry const& _spellBonus) : spellBonus(_spellBonus) {}
void operator() (uint32 spell_id) { sSpellMgr.mSpellBonusMap[spell_id] = spellBonus; }
DoSpellBonuses(SpellBonusMap& _spellBonusMap, SpellBonusEntry const& _spellBonus) : spellBonusMap(spellBonusMap), spellBonus(_spellBonus) {}
void operator() (uint32 spell_id) { spellBonusMap[spell_id] = spellBonus; }
SpellBonusMap& spellBonusMap;
SpellBonusEntry const& spellBonus;
};
@ -1468,7 +1472,7 @@ void SpellMgr::LoadSpellBonuses()
mSpellBonusMap[entry] = sbe;
// also add to high ranks
DoSpellBonuses worker(sbe);
DoSpellBonuses worker(mSpellBonusMap, sbe);
doForHighRanks(entry,worker);
++count;
@ -1643,7 +1647,7 @@ bool SpellMgr::IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellI
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
return false;
@ -1652,7 +1656,7 @@ bool SpellMgr::canStackSpellRanks(SpellEntry const *spellInfo)
if (IsProfessionOrRidingSpell(spellInfo->Id))
return false;
if(sSpellMgr.IsSkillBonusSpell(spellInfo->Id))
if (IsSkillBonusSpell(spellInfo->Id))
return false;
// 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 );
}
bool LoadPetDefaultSpells_helper(CreatureInfo const* cInfo, PetDefaultSpellsEntry& petDefSpells)
bool SpellMgr::LoadPetDefaultSpells_helper(CreatureInfo const* cInfo, PetDefaultSpellsEntry& petDefSpells)
{
// skip empty list;
bool have_spell = false;
@ -2942,7 +2946,7 @@ bool LoadPetDefaultSpells_helper(CreatureInfo const* cInfo, PetDefaultSpellsEntr
return false;
// 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)
{

View file

@ -967,8 +967,12 @@ class SpellMgr
}
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 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;
@ -1104,6 +1108,8 @@ class SpellMgr
void LoadSpellAreas();
private:
bool LoadPetDefaultSpells_helper(CreatureInfo const* cInfo, PetDefaultSpellsEntry& petDefSpells);
SpellScriptTarget mSpellScriptTarget;
SpellChainMap mSpellChains;
SpellChainMapNext mSpellChainsNext;

View file

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