Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code refactoring and optimizations #2841

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/game/AI/CreatureAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void CreatureAI::SetSpellsList(CreatureSpellsList const* pSpellsList)
m_CreatureSpells.clear();
for (const auto& entry : *pSpellsList)
{
m_CreatureSpells.push_back(CreatureAISpellsEntry(entry));
m_CreatureSpells.emplace_back(entry);
}
m_CreatureSpells.shrink_to_fit();
m_uiCastingDelay = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/game/AI/CreatureEventAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ CreatureEventAI::CreatureEventAI(Creature* c) : BasicAI(c)
if (i.event_type == EVENT_T_OOC_LOS)
c->EnableMoveInLosEvent();

m_CreatureEventAIList.push_back(CreatureEventAIHolder(i));
m_CreatureEventAIList.emplace_back(i);
}
}
else
Expand Down
6 changes: 3 additions & 3 deletions src/game/AI/PetAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ void PetAI::UpdateAI(uint32 const diff)
{
if (CanAttack(target) && spell->CanAutoCast(target))
{
targetSpellStore.push_back(std::make_pair(target, spell));
targetSpellStore.emplace_back(target, spell);
spellUsed = true;
}
}
Expand All @@ -281,7 +281,7 @@ void PetAI::UpdateAI(uint32 const diff)

if (spell->CanAutoCast(ally))
{
targetSpellStore.push_back(std::make_pair(ally, spell));
targetSpellStore.emplace_back(ally, spell);
spellUsed = true;
break;
}
Expand All @@ -296,7 +296,7 @@ void PetAI::UpdateAI(uint32 const diff)
{
Spell* spell = new Spell(m_creature, spellInfo, false);
if (spell->CanAutoCast(m_creature->GetVictim()))
targetSpellStore.push_back(std::make_pair(m_creature->GetVictim(), spell));
targetSpellStore.emplace_back(m_creature->GetVictim(), spell);
else
spell->Delete();
}
Expand Down
2 changes: 1 addition & 1 deletion src/game/GameEventMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ void GameEventMgr::LoadFromDB()
newData.spell_id_end = 0;
}

equiplist.push_back(GameEventCreatureDataPair(guid, newData));
equiplist.emplace_back(guid, newData);
mGameEventCreatureDataPerGuid.insert(GameEventCreatureDataPerGuidMap::value_type(guid, event_id));

}
Expand Down
6 changes: 3 additions & 3 deletions src/game/GossipDef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ uint32 GossipMenu::MenuItemAction(unsigned int ItemId)
return m_gItems[ ItemId ].m_gOptionId;
}

bool GossipMenu::MenuItemCoded(unsigned int ItemId)
bool GossipMenu::MenuItemCoded(unsigned int ItemId) const
{
if (ItemId >= m_gItems.size())
return 0;
return false;

return m_gItems[ ItemId ].m_gCoded;
}
Expand Down Expand Up @@ -148,7 +148,7 @@ uint32 PlayerMenu::GossipOptionAction(unsigned int Selection)
return mGossipMenu.MenuItemAction(Selection);
}

bool PlayerMenu::GossipOptionCoded(unsigned int Selection)
bool PlayerMenu::GossipOptionCoded(unsigned int Selection) const
{
return mGossipMenu.MenuItemCoded(Selection);
}
Expand Down
4 changes: 2 additions & 2 deletions src/game/GossipDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class GossipMenu

uint32 MenuItemSender(unsigned int ItemId);
uint32 MenuItemAction(unsigned int ItemId);
bool MenuItemCoded(unsigned int ItemId);
bool MenuItemCoded(unsigned int ItemId) const;

void ClearMenu();

Expand Down Expand Up @@ -295,7 +295,7 @@ class PlayerMenu
void ClearMenus();
uint32 GossipOptionSender(unsigned int Selection);
uint32 GossipOptionAction(unsigned int Selection);
bool GossipOptionCoded(unsigned int Selection);
bool GossipOptionCoded(unsigned int Selection) const;

void SendGossipMenu(uint32 titleTextId, ObjectGuid objectGuid);
void CloseGossip();
Expand Down
20 changes: 10 additions & 10 deletions src/game/HardcodedEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ ScourgeInvasionEvent::ScourgeInvasionEvent()
winterspring.zoneId = ZONEID_WINTERSPRING;
winterspring.remainingVar = VARIABLE_SI_WINTERSPRING_REMAINING;
winterspring.necroAmount = 3;
winterspring.mouth.push_back(Position(7736.56f, -4033.75f, 696.327f, 5.51524f));
winterspring.mouth.emplace_back(7736.56f, -4033.75f, 696.327f, 5.51524f);
}

InvasionZone tanaris;
Expand All @@ -536,7 +536,7 @@ ScourgeInvasionEvent::ScourgeInvasionEvent()
tanaris.zoneId = ZONEID_TANARIS;
tanaris.remainingVar = VARIABLE_SI_TANARIS_REMAINING;
tanaris.necroAmount = 3;
tanaris.mouth.push_back(Position(-8352.68f, -3972.68f, 10.0753f, 2.14675f));
tanaris.mouth.emplace_back(-8352.68f, -3972.68f, 10.0753f, 2.14675f);
}

InvasionZone azshara;
Expand All @@ -545,7 +545,7 @@ ScourgeInvasionEvent::ScourgeInvasionEvent()
azshara.zoneId = ZONEID_AZSHARA;
azshara.remainingVar = VARIABLE_SI_AZSHARA_REMAINING;
azshara.necroAmount = 2;
azshara.mouth.push_back(Position(3273.75f, -4276.98f, 125.509f, 5.44543f));
azshara.mouth.emplace_back(3273.75f, -4276.98f, 125.509f, 5.44543f);
}

InvasionZone blasted_lands;
Expand All @@ -554,7 +554,7 @@ ScourgeInvasionEvent::ScourgeInvasionEvent()
blasted_lands.zoneId = ZONEID_BLASTED_LANDS;
blasted_lands.remainingVar = VARIABLE_SI_BLASTED_LANDS_REMAINING;
blasted_lands.necroAmount = 2;
blasted_lands.mouth.push_back(Position(-11429.3f, -3327.82f, 7.73628f, 1.0821f));
blasted_lands.mouth.emplace_back(-11429.3f, -3327.82f, 7.73628f, 1.0821f);
}

InvasionZone eastern_plaguelands;
Expand All @@ -563,7 +563,7 @@ ScourgeInvasionEvent::ScourgeInvasionEvent()
eastern_plaguelands.zoneId = ZONEID_EASTERN_PLAGUELANDS;
eastern_plaguelands.remainingVar = VARIABLE_SI_EASTERN_PLAGUELANDS_REMAINING;
eastern_plaguelands.necroAmount = 2;
eastern_plaguelands.mouth.push_back(Position(2014.55f, -4934.52f, 73.9846f, 0.0698132f));
eastern_plaguelands.mouth.emplace_back(2014.55f, -4934.52f, 73.9846f, 0.0698132f);
}

InvasionZone burning_steppes;
Expand All @@ -572,7 +572,7 @@ ScourgeInvasionEvent::ScourgeInvasionEvent()
burning_steppes.zoneId = ZONEID_BURNING_STEPPES;
burning_steppes.remainingVar = VARIABLE_SI_BURNING_STEPPES_REMAINING;
burning_steppes.necroAmount = 2;
burning_steppes.mouth.push_back(Position(-8229.53f, -1118.11f, 144.012f, 6.17846f));
burning_steppes.mouth.emplace_back(-8229.53f, -1118.11f, 144.012f, 6.17846f);
}

invasionPoints.push_back(winterspring);
Expand All @@ -586,16 +586,16 @@ ScourgeInvasionEvent::ScourgeInvasionEvent()
{
undercity.map = 0;
undercity.zoneId = ZONEID_UNDERCITY;
undercity.pallid.push_back(Position(1595.87f, 440.539f, -46.3349f, 2.28207f)); // Royal Quarter
undercity.pallid.push_back(Position(1659.2f, 265.988f, -62.1788f, 3.64283f)); // Trade Quarter
undercity.pallid.emplace_back(1595.87f, 440.539f, -46.3349f, 2.28207f); // Royal Quarter
undercity.pallid.emplace_back(1659.2f, 265.988f, -62.1788f, 3.64283f); // Trade Quarter
}

CityAttack stormwind;
{
stormwind.map = 0;
stormwind.zoneId = ZONEID_STORMWIND;
stormwind.pallid.push_back(Position(-8578.15f, 886.382f, 87.3148f, 0.586275f)); // Stormwind Keep
stormwind.pallid.push_back(Position(-8578.15f, 886.382f, 87.3148f, 0.586275f)); // Trade District
stormwind.pallid.emplace_back(-8578.15f, 886.382f, 87.3148f, 0.586275f); // Stormwind Keep
stormwind.pallid.emplace_back(-8578.15f, 886.382f, 87.3148f, 0.586275f); // Trade District
}

attackPoints.push_back(undercity);
Expand Down
4 changes: 2 additions & 2 deletions src/game/ItemEnchantmentMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void LoadRandomEnchantmentsTable()

if (chance > 0.000001f && chance <= 100.0f)
{
RandomItemEnch[entry].push_back(EnchStoreItem(ench, chance));
RandomItemEnch[entry].emplace_back(ench, chance);
}
else
{
Expand Down Expand Up @@ -114,7 +114,7 @@ uint32 GetItemEnchantMod(uint32 entry)
chance += ench_iter.chance;
}

float const roll = rand_chance() * (chance / 100.f);
float const roll = rand_chance_f() * (chance / 100.f);
chance = 0.f;

for (auto const& ench_iter : enchantList)
Expand Down
26 changes: 13 additions & 13 deletions src/game/LootMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,10 @@ LootItem::LootItem(LootStoreItem const& li)

count = urand(li.mincountOrRef, li.maxcount); // constructor called for mincountOrRef > 0 only
randomPropertyId = Item::GenerateItemRandomPropertyId(itemid);
is_looted = 0;
is_blocked = 0;
is_underthreshold = 0;
is_counted = 0;
is_looted = false;
is_blocked = false;
is_underthreshold = false;
is_counted = false;
}

LootItem::LootItem(uint32 itemid_, uint32 count_, int32 randomPropertyId_)
Expand All @@ -368,10 +368,10 @@ LootItem::LootItem(uint32 itemid_, uint32 count_, int32 randomPropertyId_)

count = count_;
randomPropertyId = randomPropertyId_;
is_looted = 0;
is_blocked = 0;
is_underthreshold = 0;
is_counted = 0;
is_looted = false;
is_blocked = false;
is_underthreshold = false;
is_counted = false;
}

// Basic checks for player/item compatibility - if false no chance to see the item in the loot
Expand Down Expand Up @@ -470,11 +470,11 @@ void Loot::AddItem(LootStoreItem const& item)
if (item.needs_quest) // Quest drop
{
if (m_questItems.size() < MAX_NR_QUEST_ITEMS)
m_questItems.push_back(LootItem(item));
m_questItems.emplace_back(item);
}
else if (items.size() < MAX_NR_LOOT_ITEMS) // Non-quest drop
{
items.push_back(LootItem(item));
items.emplace_back(item);

// non-conditional one-player only items are counted here,
// free for all items are counted in FillFFALoot(),
Expand Down Expand Up @@ -581,7 +581,7 @@ QuestItemList* Loot::FillFFALoot(Player* player)
LootItem &item = items[i];
if (!item.is_looted && item.freeforall && item.AllowedForPlayer(player, GetLootTarget()))
{
ql->push_back(QuestItem(i));
ql->emplace_back(i);
++unlootedCount;
}
}
Expand All @@ -608,7 +608,7 @@ QuestItemList* Loot::FillQuestLoot(Player* player)
LootItem &item = m_questItems[i];
if (!item.is_looted && item.AllowedForPlayer(player, GetLootTarget()))
{
ql->push_back(QuestItem(i));
ql->emplace_back(i);

// questitems get blocked when they first apper in a
// player's quest vector
Expand Down Expand Up @@ -645,7 +645,7 @@ QuestItemList* Loot::FillNonQuestNonFFAConditionalLoot(Player* player)
LootItem &item = items[i];
if (!item.is_looted && !item.freeforall && item.conditionId && item.AllowedForPlayer(player, GetLootTarget()))
{
ql->push_back(QuestItem(i));
ql->emplace_back(i);
if (!item.is_counted)
{
++unlootedCount;
Expand Down
2 changes: 1 addition & 1 deletion src/game/LootMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ struct Loot
bool hasItemFor(Player* player) const;
bool hasOverThresholdItem() const;
bool IsAllowedLooter(ObjectGuid guid, bool doPersonalCheck = true) const;
bool IsOriginalLooter(ObjectGuid guid) { return IsAllowedLooter(guid, false); }
bool IsOriginalLooter(ObjectGuid guid) const { return IsAllowedLooter(guid, false); }

void FillNotNormalLootFor(Player* player);

Expand Down
2 changes: 1 addition & 1 deletion src/game/Maps/GridNotifiers.h
Original file line number Diff line number Diff line change
Expand Up @@ -1600,7 +1600,7 @@ namespace MaNGOS
explicit NearestHostileUnitInAttackDistanceCheck(Creature const* creature, float dist = 0) : me(creature)
{
m_range = (dist == 0 ? 9999 : dist);
m_force = (dist == 0 ? false : true);
m_force = dist != 0;
}
bool operator()(Unit* u)
{
Expand Down
4 changes: 2 additions & 2 deletions src/game/Maps/InstanceData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ void InstanceData::SaveToDB()
CharacterDatabase.escape_string(data);

if (instance->Instanceable())
CharacterDatabase.PExecute("UPDATE instance SET data = '%s' WHERE id = '%u'", data.c_str(), instance->GetInstanceId());
CharacterDatabase.PExecute("UPDATE `instance` SET `data` = '%s' WHERE `id` = %u", data.c_str(), instance->GetInstanceId());
else
CharacterDatabase.PExecute("UPDATE world SET data = '%s' WHERE map = '%u'", data.c_str(), instance->GetId());
CharacterDatabase.PExecute("UPDATE `world` SET `data` = '%s' WHERE `map` = %u", data.c_str(), instance->GetId());
}

bool InstanceData::CheckConditionCriteriaMeet(Player const* /*player*/, uint32 map_id, WorldObject const* source, uint32 instance_condition_id) const
Expand Down
2 changes: 1 addition & 1 deletion src/game/Movement/RandomMovementGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void RandomMovementGenerator::_setRandomLocation(Creature &creature)
uint32 ptsPerCycle = ceil(i_wanderDistance * 2);
static uint32 const nbCyclesPerPacket = 1;
for (uint32 i = 0; i <= nbCyclesPerPacket * ptsPerCycle; ++i)
path.push_back(Vector3(i_startPosition.x + i_wanderDistance * cos(i * 2 * M_PI / ptsPerCycle), i_startPosition.y + i_wanderDistance * sin(i * 2 * M_PI / ptsPerCycle), i_startPosition.z));
path.emplace_back(i_startPosition.x + i_wanderDistance * cos(i * 2 * M_PI / ptsPerCycle), i_startPosition.y + i_wanderDistance * sin(i * 2 * M_PI / ptsPerCycle), i_startPosition.z);
Movement::MoveSplineInit init(creature, "RandomMovementGenerator (CanFly)");
init.SetFly();
init.SetWalk(false);
Expand Down
4 changes: 2 additions & 2 deletions src/game/Movement/TargetedMovementGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ void TargetedMovementGeneratorMedium<T, D>::_setTargetLocation(T &owner)
{
float distFactor = 1.0f;
if (pOwner->IsMounted())
distFactor += 0.04 * (dist - speedupDistance * 2);
distFactor += 0.04f * (dist - speedupDistance * 2);
else
distFactor += 0.04 * (dist - speedupDistance);
distFactor += 0.04f * (dist - speedupDistance);
if (distFactor < 1.0f) distFactor = 1.0f;
if (distFactor > 2.1f) distFactor = 2.1f;
init.SetVelocity(distFactor * owner.GetSpeed(MOVE_RUN));
Expand Down
2 changes: 1 addition & 1 deletion src/game/Objects/Bag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ uint32 Bag::GetItemCount(uint32 item, Item const* eItem) const
uint8 Bag::GetSlotByItemGUID(ObjectGuid guid) const
{
for (uint32 i = 0; i < GetBagSize(); ++i)
if (m_bagslot[i] != 0)
if (m_bagslot[i] != nullptr)
if (m_bagslot[i]->GetObjectGuid() == guid)
return i;

Expand Down
2 changes: 1 addition & 1 deletion src/game/Objects/Corpse.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Corpse : public WorldObject

bool IsExpired(time_t t) const;
void SetFactionTemplate(FactionTemplateEntry const* entry) { m_faction = entry; }
FactionTemplateEntry const* GetFactionTemplate() { return m_faction; }
FactionTemplateEntry const* GetFactionTemplate() const { return m_faction; }
uint32 GetFactionTemplateId() const final;
private:
GridReference<Corpse> m_gridRef;
Expand Down
8 changes: 4 additions & 4 deletions src/game/Objects/Creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ class Creature : public Unit
bool CanInitiateAttack() const;
bool CanHaveTarget() const { return !HasExtraFlag(CREATURE_FLAG_EXTRA_NO_TARGET); }

uint32 GetDefaultMount() { return m_mountId; }
uint32 GetDefaultMount() const { return m_mountId; }
void SetDefaultMount(uint32 id) { m_mountId = id; }

MovementGeneratorType GetDefaultMovementType() const { return m_defaultMovementType; }
Expand Down Expand Up @@ -571,7 +571,7 @@ class Creature : public Unit
}

// (msecs)timer used for group loot
uint32 GetGroupLootTimer() { return m_groupLootTimer; }
uint32 GetGroupLootTimer() const { return m_groupLootTimer; }

void SetEscortable(bool escortable)
{
Expand All @@ -581,8 +581,8 @@ class Creature : public Unit
ClearCreatureState(CSTATE_ESCORTABLE);
}
bool IsEscortable() const { return HasCreatureState(CSTATE_ESCORTABLE); }
bool CanAssistPlayers() { return HasFactionTemplateFlag(FACTION_TEMPLATE_FLAG_ASSIST_PLAYERS) || HasExtraFlag(CREATURE_FLAG_EXTRA_CAN_ASSIST); }
bool CanSummonGuards() { return HasStaticFlag(CREATURE_STATIC_FLAG_CALLS_GUARDS); }
bool CanAssistPlayers() const { return HasFactionTemplateFlag(FACTION_TEMPLATE_FLAG_ASSIST_PLAYERS) || HasExtraFlag(CREATURE_FLAG_EXTRA_CAN_ASSIST); }
bool CanSummonGuards() const { return HasStaticFlag(CREATURE_STATIC_FLAG_CALLS_GUARDS); }
uint32 GetOriginalEntry() const { return m_originalEntry; }

protected:
Expand Down
6 changes: 3 additions & 3 deletions src/game/Objects/Item.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class Item : public Object

ObjectGuid const& GetOwnerGuid() const { return GetGuidValue(ITEM_FIELD_OWNER); }
void SetOwnerGuid(ObjectGuid guid) { SetGuidValue(ITEM_FIELD_OWNER, guid); }
Player* GetOwner()const;
Player* GetOwner() const;

void SetBinding(bool val) { ApplyModFlag(ITEM_FIELD_FLAGS, ITEM_DYNFLAG_BOUND, val); }
bool IsSoulBound() const { return HasFlag(ITEM_FIELD_FLAGS, ITEM_DYNFLAG_BOUND); }
Expand Down Expand Up @@ -303,7 +303,7 @@ class Item : public Object
InventoryResult CanBeMergedPartlyWith(ItemPrototype const* proto) const;

uint8 GetSlot() const {return m_slot;}
Bag* GetContainer() { return m_container; }
Bag* GetContainer() const { return m_container; }
uint8 GetBagSlot() const;
void SetSlot(uint8 slot) {m_slot = slot;}
uint16 GetPos() const { return uint16(GetBagSlot()) << 8 | GetSlot(); }
Expand Down Expand Up @@ -360,7 +360,7 @@ class Item : public Object
void RemoveFromClientUpdateList() override;
void BuildUpdateData(UpdateDataMapType& update_players) override;
void SetGeneratedLoot(bool value) { generatedLoot = value; }
bool HasGeneratedLootSecondary() { return generatedLoot; } // todo, remove and add condition to HasGeneratedLoot
bool HasGeneratedLootSecondary() const { return generatedLoot; } // todo, remove and add condition to HasGeneratedLoot

bool IsCharter() const { return GetEntry() == 5863u; }
static void GetLocalizedNameWithSuffix(std::string& name, ItemPrototype const* proto, ItemRandomPropertiesEntry const* randomProp, int dbLocale, LocaleConstant dbcLocale);
Expand Down
Loading
Loading