Skip to content

Commit 1aa6d4e

Browse files
committed
Core/Players: Directly store PlayerTalent in talent map, not as pointer
1 parent f03d493 commit 1aa6d4e

2 files changed

Lines changed: 26 additions & 43 deletions

File tree

src/server/game/Entities/Player/Player.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2908,7 +2908,7 @@ bool Player::AddTalent(uint32 spellId, uint8 spec, bool learning)
29082908

29092909
PlayerTalentMap::iterator itr = GetTalentMap(spec)->find(spellId);
29102910
if (itr != GetTalentMap(spec)->end())
2911-
itr->second->state = PLAYERSPELL_UNCHANGED;
2911+
itr->second.state = PLAYERSPELL_UNCHANGED;
29122912
else if (TalentSpellPos const* talentPos = GetTalentSpellPos(spellId))
29132913
{
29142914
if (TalentEntry const* talentInfo = sTalentStore.LookupEntry(talentPos->talent_id))
@@ -2922,16 +2922,13 @@ bool Player::AddTalent(uint32 spellId, uint8 spec, bool learning)
29222922

29232923
itr = GetTalentMap(spec)->find(rankSpellId);
29242924
if (itr != GetTalentMap(spec)->end())
2925-
itr->second->state = PLAYERSPELL_REMOVED;
2925+
itr->second.state = PLAYERSPELL_REMOVED;
29262926
}
29272927
}
29282928

2929-
PlayerTalent* newtalent = new PlayerTalent();
2930-
2931-
newtalent->state = learning ? PLAYERSPELL_NEW : PLAYERSPELL_UNCHANGED;
2932-
newtalent->spec = spec;
2933-
2934-
(*GetTalentMap(spec))[spellId] = newtalent;
2929+
PlayerTalent& newtalent = (*GetTalentMap(spec))[spellId];
2930+
newtalent.state = learning ? PLAYERSPELL_NEW : PLAYERSPELL_UNCHANGED;
2931+
newtalent.spec = spec;
29352932
return true;
29362933
}
29372934
return false;
@@ -3770,7 +3767,7 @@ bool Player::ResetTalents(bool involuntarily /*= false*/)
37703767
// if this talent rank can be found in the PlayerTalentMap, mark the talent as removed so it gets deleted
37713768
PlayerTalentMap::iterator plrTalent = GetTalentMap(GetActiveSpec())->find(talentInfo->SpellRank[rank]);
37723769
if (plrTalent != GetTalentMap(GetActiveSpec())->end())
3773-
plrTalent->second->state = PLAYERSPELL_REMOVED;
3770+
plrTalent->second.state = PLAYERSPELL_REMOVED;
37743771
}
37753772
}
37763773

@@ -3874,7 +3871,7 @@ bool Player::HasSpell(uint32 spell) const
38743871
bool Player::HasTalent(uint32 spell, uint8 spec) const
38753872
{
38763873
PlayerTalentMap::const_iterator itr = GetTalentMap(spec)->find(spell);
3877-
return (itr != GetTalentMap(spec)->end() && itr->second->state != PLAYERSPELL_REMOVED);
3874+
return (itr != GetTalentMap(spec)->end() && itr->second.state != PLAYERSPELL_REMOVED);
38783875
}
38793876

38803877
bool Player::HasActiveSpell(uint32 spell) const
@@ -25728,32 +25725,31 @@ void Player::_SaveTalents(CharacterDatabaseTransaction trans)
2572825725
{
2572925726
for (PlayerTalentMap::iterator itr = GetTalentMap(i)->begin(); itr != GetTalentMap(i)->end();)
2573025727
{
25731-
if (itr->second->state == PLAYERSPELL_REMOVED || itr->second->state == PLAYERSPELL_CHANGED)
25728+
if (itr->second.state == PLAYERSPELL_REMOVED || itr->second.state == PLAYERSPELL_CHANGED)
2573225729
{
2573325730
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_TALENT_BY_SPELL_SPEC);
2573425731
stmt->setUInt32(0, GetGUID().GetCounter());
2573525732
stmt->setUInt32(1, itr->first);
25736-
stmt->setUInt8(2, itr->second->spec);
25733+
stmt->setUInt8(2, itr->second.spec);
2573725734
trans->Append(stmt);
2573825735
}
2573925736

25740-
if (itr->second->state == PLAYERSPELL_NEW || itr->second->state == PLAYERSPELL_CHANGED)
25737+
if (itr->second.state == PLAYERSPELL_NEW || itr->second.state == PLAYERSPELL_CHANGED)
2574125738
{
2574225739
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHAR_TALENT);
2574325740
stmt->setUInt32(0, GetGUID().GetCounter());
2574425741
stmt->setUInt32(1, itr->first);
25745-
stmt->setUInt8(2, itr->second->spec);
25742+
stmt->setUInt8(2, itr->second.spec);
2574625743
trans->Append(stmt);
2574725744
}
2574825745

25749-
if (itr->second->state == PLAYERSPELL_REMOVED)
25746+
if (itr->second.state == PLAYERSPELL_REMOVED)
2575025747
{
25751-
delete itr->second;
25752-
GetTalentMap(i)->erase(itr++);
25748+
itr = GetTalentMap(i)->erase(itr);
2575325749
}
2575425750
else
2575525751
{
25756-
itr->second->state = PLAYERSPELL_UNCHANGED;
25752+
itr->second.state = PLAYERSPELL_UNCHANGED;
2575725753
++itr;
2575825754
}
2575925755
}

src/server/game/Entities/Player/Player.h

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ struct SpellModifier
168168
Aura* const ownerAura;
169169
};
170170

171-
typedef std::unordered_map<uint32, PlayerTalent*> PlayerTalentMap;
171+
typedef std::unordered_map<uint32, PlayerTalent> PlayerTalentMap;
172172
typedef std::unordered_map<uint32, PlayerSpell> PlayerSpellMap;
173173
typedef std::unordered_set<SpellModifier*> SpellModContainer;
174174

@@ -886,36 +886,22 @@ struct ResurrectionData
886886

887887
#define SPELL_DK_RAISE_ALLY 46619
888888

889+
struct TalentSpecInfo
890+
{
891+
PlayerTalentMap Talents;
892+
uint32 Glyphs[MAX_GLYPH_SLOT_INDEX] = { };
893+
};
894+
889895
struct PlayerTalentInfo
890896
{
891897
PlayerTalentInfo() :
892898
UsedTalentCount(0), QuestRewardedTalentCount(0),
893899
ResetTalentsCost(0), ResetTalentsTime(0),
894900
ActiveSpec(0), SpecsCount(1)
895901
{
896-
for (uint8 i = 0; i < MAX_TALENT_SPECS; ++i)
897-
{
898-
SpecInfo[i].Talents = new PlayerTalentMap();
899-
memset(SpecInfo[i].Glyphs, 0, MAX_GLYPH_SLOT_INDEX * sizeof(uint32));
900-
}
901-
}
902-
903-
~PlayerTalentInfo()
904-
{
905-
for (uint8 i = 0; i < MAX_TALENT_SPECS; ++i)
906-
{
907-
for (PlayerTalentMap::const_iterator itr = SpecInfo[i].Talents->begin(); itr != SpecInfo[i].Talents->end(); ++itr)
908-
delete itr->second;
909-
delete SpecInfo[i].Talents;
910-
}
911902
}
912903

913-
struct TalentSpecInfo
914-
{
915-
PlayerTalentMap* Talents;
916-
uint32 Glyphs[MAX_GLYPH_SLOT_INDEX];
917-
} SpecInfo[MAX_TALENT_SPECS];
918-
904+
TalentSpecInfo SpecInfo[MAX_TALENT_SPECS];
919905
uint32 UsedTalentCount;
920906
uint32 QuestRewardedTalentCount;
921907
uint32 ResetTalentsCost;
@@ -924,7 +910,8 @@ struct PlayerTalentInfo
924910
uint8 SpecsCount;
925911

926912
private:
927-
PlayerTalentInfo(PlayerTalentInfo const&);
913+
PlayerTalentInfo(PlayerTalentInfo const&) = delete;
914+
PlayerTalentInfo& operator=(PlayerTalentInfo const&) = delete;
928915
};
929916

930917
class TC_GAME_API Player : public Unit, public GridObject<Player>
@@ -1530,8 +1517,8 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
15301517
void SetGlyph(uint8 slot, uint32 glyph);
15311518
uint32 GetGlyph(uint8 spec, uint8 slot) const { return _talentMgr->SpecInfo[spec].Glyphs[slot]; }
15321519

1533-
PlayerTalentMap const* GetTalentMap(uint8 spec) const { return _talentMgr->SpecInfo[spec].Talents; }
1534-
PlayerTalentMap* GetTalentMap(uint8 spec) { return _talentMgr->SpecInfo[spec].Talents; }
1520+
PlayerTalentMap const* GetTalentMap(uint8 spec) const { return &_talentMgr->SpecInfo[spec].Talents; }
1521+
PlayerTalentMap* GetTalentMap(uint8 spec) { return &_talentMgr->SpecInfo[spec].Talents; }
15351522
ActionButtonList const& GetActionButtons() const { return m_actionButtons; }
15361523

15371524
uint32 GetFreePrimaryProfessionPoints() const { return GetUInt32Value(PLAYER_CHARACTER_POINTS2); }

0 commit comments

Comments
 (0)