[7835] Store structures (with size = uint32) insteed pointer to structure in PetSpellMap. Author: VladimirMangos

--HG--
branch : trunk
This commit is contained in:
megamage
2009-05-15 16:46:02 -05:00
parent f5af5ea9e3
commit 9b4d3bf0af
3 changed files with 56 additions and 73 deletions
+51 -66
View File
@@ -58,15 +58,6 @@ m_declinedname(NULL), m_owner(owner)
Pet::~Pet() Pet::~Pet()
{ {
if(m_uint32Values) // only for fully created Object
{
//if(GetOwnerGUID())
// sLog.outCrash("Pet %u is deconstructed but it still has owner guid", GetEntry());
for (PetSpellMap::const_iterator i = m_spells.begin(); i != m_spells.end(); ++i)
delete i->second;
}
delete m_declinedname; delete m_declinedname;
} }
@@ -1114,19 +1105,32 @@ void Pet::_LoadSpells()
void Pet::_SaveSpells() void Pet::_SaveSpells()
{ {
for (PetSpellMap::const_iterator itr = m_spells.begin(), next = m_spells.begin(); itr != m_spells.end(); itr = next) for (PetSpellMap::iterator itr = m_spells.begin(), next = m_spells.begin(); itr != m_spells.end(); itr = next)
{ {
++next; ++next;
if (itr->second->type == PETSPELL_FAMILY) continue; // prevent saving family passives to DB
if (itr->second->state == PETSPELL_REMOVED || itr->second->state == PETSPELL_CHANGED)
CharacterDatabase.PExecute("DELETE FROM pet_spell WHERE guid = '%u' and spell = '%u'", m_charmInfo->GetPetNumber(), itr->first);
if (itr->second->state == PETSPELL_NEW || itr->second->state == PETSPELL_CHANGED)
CharacterDatabase.PExecute("INSERT INTO pet_spell (guid,spell,active) VALUES ('%u', '%u', '%u')", m_charmInfo->GetPetNumber(), itr->first, itr->second->active);
if (itr->second->state == PETSPELL_REMOVED) // prevent saving family passives to DB
_removeSpell(itr->first); if (itr->second.type == PETSPELL_FAMILY)
else continue;
itr->second->state = PETSPELL_UNCHANGED;
switch(itr->second.state)
{
case PETSPELL_REMOVED:
CharacterDatabase.PExecute("DELETE FROM pet_spell WHERE guid = '%u' and spell = '%u'", m_charmInfo->GetPetNumber(), itr->first);
m_spells.erase(itr);
continue;
case PETSPELL_CHANGED:
CharacterDatabase.PExecute("DELETE FROM pet_spell WHERE guid = '%u' and spell = '%u'", m_charmInfo->GetPetNumber(), itr->first);
CharacterDatabase.PExecute("INSERT INTO pet_spell (guid,spell,active) VALUES ('%u', '%u', '%u')", m_charmInfo->GetPetNumber(), itr->first, itr->second.active);
break;
case PETSPELL_NEW:
CharacterDatabase.PExecute("INSERT INTO pet_spell (guid,spell,active) VALUES ('%u', '%u', '%u')", m_charmInfo->GetPetNumber(), itr->first, itr->second.active);
break;
case PETSPELL_UNCHANGED:
continue;
}
itr->second.state = PETSPELL_UNCHANGED;
} }
} }
@@ -1223,7 +1227,7 @@ void Pet::_SaveAuras()
} }
} }
bool Pet::addSpell(uint32 spell_id, uint16 active, PetSpellState state, PetSpellType type) bool Pet::addSpell(uint32 spell_id,uint16 active /*= ACT_DECIDE*/, PetSpellState state /*= PETSPELL_NEW*/, PetSpellType type /*= PETSPELL_NORMAL*/)
{ {
SpellEntry const *spellInfo = sSpellStore.LookupEntry(spell_id); SpellEntry const *spellInfo = sSpellStore.LookupEntry(spell_id);
if (!spellInfo) if (!spellInfo)
@@ -1247,16 +1251,15 @@ bool Pet::addSpell(uint32 spell_id, uint16 active, PetSpellState state, PetSpell
PetSpellMap::iterator itr = m_spells.find(spell_id); PetSpellMap::iterator itr = m_spells.find(spell_id);
if (itr != m_spells.end()) if (itr != m_spells.end())
{ {
if (itr->second->state == PETSPELL_REMOVED) if (itr->second.state == PETSPELL_REMOVED)
{ {
delete itr->second;
m_spells.erase(itr); m_spells.erase(itr);
state = PETSPELL_CHANGED; state = PETSPELL_CHANGED;
} }
else if (state == PETSPELL_UNCHANGED && itr->second->state != PETSPELL_UNCHANGED) else if (state == PETSPELL_UNCHANGED && itr->second.state != PETSPELL_UNCHANGED)
{ {
// can be in case spell loading but learned at some previous spell loading // can be in case spell loading but learned at some previous spell loading
itr->second->state = PETSPELL_UNCHANGED; itr->second.state = PETSPELL_UNCHANGED;
if(active == ACT_ENABLED) if(active == ACT_ENABLED)
ToggleAutocast(spell_id, true); ToggleAutocast(spell_id, true);
@@ -1271,19 +1274,19 @@ bool Pet::addSpell(uint32 spell_id, uint16 active, PetSpellState state, PetSpell
uint32 oldspell_id = 0; uint32 oldspell_id = 0;
PetSpell *newspell = new PetSpell; PetSpell newspell;
newspell->state = state; newspell.state = state;
newspell->type = type; newspell.type = type;
if(active == ACT_DECIDE) //active was not used before, so we save it's autocast/passive state here if(active == ACT_DECIDE) //active was not used before, so we save it's autocast/passive state here
{ {
if(IsPassiveSpell(spell_id)) if(IsPassiveSpell(spell_id))
newspell->active = ACT_PASSIVE; newspell.active = ACT_PASSIVE;
else else
newspell->active = ACT_DISABLED; newspell.active = ACT_DISABLED;
} }
else else
newspell->active = active; newspell.active = active;
// talent: unlearn all other talent ranks (high and low) // talent: unlearn all other talent ranks (high and low)
if(TalentSpellPos const* talentPos = GetTalentSpellPos(spell_id)) if(TalentSpellPos const* talentPos = GetTalentSpellPos(spell_id))
@@ -1308,13 +1311,13 @@ bool Pet::addSpell(uint32 spell_id, uint16 active, PetSpellState state, PetSpell
{ {
for (PetSpellMap::const_iterator itr2 = m_spells.begin(); itr2 != m_spells.end(); ++itr2) for (PetSpellMap::const_iterator itr2 = m_spells.begin(); itr2 != m_spells.end(); ++itr2)
{ {
if(itr2->second->state == PETSPELL_REMOVED) continue; if(itr2->second.state == PETSPELL_REMOVED) continue;
if(spellmgr.GetFirstSpellInChain(itr2->first) == chainstart) if(spellmgr.GetFirstSpellInChain(itr2->first) == chainstart)
{ {
newspell->active = itr2->second->active; newspell.active = itr2->second.active;
if(newspell->active == ACT_ENABLED) if(newspell.active == ACT_ENABLED)
ToggleAutocast(itr2->first, false); ToggleAutocast(itr2->first, false);
oldspell_id = itr2->first; oldspell_id = itr2->first;
@@ -1331,7 +1334,7 @@ bool Pet::addSpell(uint32 spell_id, uint16 active, PetSpellState state, PetSpell
else if(state == PETSPELL_NEW) else if(state == PETSPELL_NEW)
m_charmInfo->AddSpellToAB(oldspell_id, spell_id, (ActiveStates)active); m_charmInfo->AddSpellToAB(oldspell_id, spell_id, (ActiveStates)active);
if(newspell->active == ACT_ENABLED) if(newspell.active == ACT_ENABLED)
ToggleAutocast(spell_id, true); ToggleAutocast(spell_id, true);
uint32 talentCost = GetTalentSpellCost(spell_id); uint32 talentCost = GetTalentSpellCost(spell_id);
@@ -1396,16 +1399,13 @@ bool Pet::removeSpell(uint32 spell_id)
if (itr == m_spells.end()) if (itr == m_spells.end())
return false; return false;
if(itr->second->state == PETSPELL_REMOVED) if(itr->second.state == PETSPELL_REMOVED)
return false; return false;
if(itr->second->state == PETSPELL_NEW) if(itr->second.state == PETSPELL_NEW)
{
delete itr->second;
m_spells.erase(itr); m_spells.erase(itr);
}
else else
itr->second->state = PETSPELL_REMOVED; itr->second.state = PETSPELL_REMOVED;
RemoveAurasDueToSpell(spell_id); RemoveAurasDueToSpell(spell_id);
@@ -1424,24 +1424,9 @@ bool Pet::removeSpell(uint32 spell_id)
return true; return true;
} }
bool Pet::_removeSpell(uint32 spell_id)
{
PetSpellMap::iterator itr = m_spells.find(spell_id);
if (itr != m_spells.end())
{
delete itr->second;
m_spells.erase(itr);
return true;
}
return false;
}
void Pet::InitPetCreateSpells() void Pet::InitPetCreateSpells()
{ {
m_charmInfo->InitPetActionBar(); m_charmInfo->InitPetActionBar();
for (PetSpellMap::const_iterator i = m_spells.begin(); i != m_spells.end(); ++i)
delete i->second;
m_spells.clear(); m_spells.clear();
uint32 petspellid; uint32 petspellid;
@@ -1561,7 +1546,7 @@ bool Pet::resetTalents(bool no_cost)
{ {
for(PetSpellMap::const_iterator itr = m_spells.begin(); itr != m_spells.end();) for(PetSpellMap::const_iterator itr = m_spells.begin(); itr != m_spells.end();)
{ {
if(itr->second->state == PETSPELL_REMOVED) if(itr->second.state == PETSPELL_REMOVED)
{ {
++itr; ++itr;
continue; continue;
@@ -1641,7 +1626,7 @@ void Pet::ToggleAutocast(uint32 spellid, bool apply)
if(IsPassiveSpell(spellid)) if(IsPassiveSpell(spellid))
return; return;
PetSpellMap::const_iterator itr = m_spells.find(spellid); PetSpellMap::iterator itr = m_spells.find(spellid);
if(itr == m_spells.end()) if(itr == m_spells.end())
return; return;
@@ -1656,11 +1641,11 @@ void Pet::ToggleAutocast(uint32 spellid, bool apply)
{ {
m_autospells.push_back(spellid); m_autospells.push_back(spellid);
if(itr->second->active != ACT_ENABLED) if(itr->second.active != ACT_ENABLED)
{ {
itr->second->active = ACT_ENABLED; itr->second.active = ACT_ENABLED;
if(itr->second->state != PETSPELL_NEW) if(itr->second.state != PETSPELL_NEW)
itr->second->state = PETSPELL_CHANGED; itr->second.state = PETSPELL_CHANGED;
} }
} }
} }
@@ -1673,11 +1658,11 @@ void Pet::ToggleAutocast(uint32 spellid, bool apply)
if (i < m_autospells.size()) if (i < m_autospells.size())
{ {
m_autospells.erase(itr2); m_autospells.erase(itr2);
if(itr->second->active != ACT_DISABLED) if(itr->second.active != ACT_DISABLED)
{ {
itr->second->active = ACT_DISABLED; itr->second.active = ACT_DISABLED;
if(itr->second->state != PETSPELL_NEW) if(itr->second.state != PETSPELL_NEW)
itr->second->state = PETSPELL_CHANGED; itr->second.state = PETSPELL_CHANGED;
} }
} }
} }
@@ -1726,7 +1711,7 @@ bool Pet::Create(uint32 guidlow, Map *map, uint32 phaseMask, uint32 Entry, uint3
bool Pet::HasSpell(uint32 spell) const bool Pet::HasSpell(uint32 spell) const
{ {
PetSpellMap::const_iterator itr = m_spells.find(spell); PetSpellMap::const_iterator itr = m_spells.find(spell);
return (itr != m_spells.end() && itr->second->state != PETSPELL_REMOVED ); return (itr != m_spells.end() && itr->second.state != PETSPELL_REMOVED );
} }
// Get all passive spells in our skill line // Get all passive spells in our skill line
+3 -5
View File
@@ -72,8 +72,8 @@ struct PetSpell
{ {
uint16 active; uint16 active;
PetSpellState state : 16; PetSpellState state : 8;
PetSpellType type : 16; PetSpellType type : 8;
}; };
enum ActionFeedback enum ActionFeedback
@@ -113,7 +113,7 @@ enum PetNameInvalidReason
PET_NAME_DECLENSION_DOESNT_MATCH_BASE_NAME = 16 PET_NAME_DECLENSION_DOESNT_MATCH_BASE_NAME = 16
}; };
typedef UNORDERED_MAP<uint32, PetSpell*> PetSpellMap; typedef UNORDERED_MAP<uint32, PetSpell> PetSpellMap;
typedef std::map<uint32,uint32> TeachSpellMap; typedef std::map<uint32,uint32> TeachSpellMap;
typedef std::vector<uint32> AutoSpellList; typedef std::vector<uint32> AutoSpellList;
@@ -205,8 +205,6 @@ class Pet : public Guardian
void learnLevelupSpells(); void learnLevelupSpells();
bool unlearnSpell(uint32 spell_id); bool unlearnSpell(uint32 spell_id);
bool removeSpell(uint32 spell_id); bool removeSpell(uint32 spell_id);
bool _removeSpell(uint32 spell_id);
void _resetSpells();
PetSpellMap m_spells; PetSpellMap m_spells;
TeachSpellMap m_teachspells; TeachSpellMap m_teachspells;
+2 -2
View File
@@ -16814,11 +16814,11 @@ void Player::PetSpellInitialize()
// spells loop // spells loop
for (PetSpellMap::iterator itr = pet->m_spells.begin(); itr != pet->m_spells.end(); ++itr) for (PetSpellMap::iterator itr = pet->m_spells.begin(); itr != pet->m_spells.end(); ++itr)
{ {
if(itr->second->state == PETSPELL_REMOVED) if(itr->second.state == PETSPELL_REMOVED)
continue; continue;
data << uint16(itr->first); data << uint16(itr->first);
data << uint16(itr->second->active); // pet spell active state isn't boolean data << uint16(itr->second.active); // pet spell active state isn't boolean
++addlist; ++addlist;
} }
} }