Core/SAI/EAI: Pass struct parameters by reference instead of value, saves unneeded copying

This commit is contained in:
Shauren
2011-05-12 10:40:53 +02:00
parent bca01dd419
commit 339e8cb7e0
7 changed files with 43 additions and 39 deletions
+2 -2
View File
@@ -126,7 +126,7 @@ class UnitAI
Unit* SelectTarget(SelectAggroTarget targetType, uint32 position = 0, float dist = 0.0f, bool playerOnly = false, int32 aura = 0);
// Select the targets satifying the predicate.
// predicate shall extend std::unary_function<Unit* , bool>
template <class PREDICATE> Unit* SelectTarget(SelectAggroTarget targetType, uint32 position, PREDICATE predicate)
template <class PREDICATE> Unit* SelectTarget(SelectAggroTarget targetType, uint32 position, PREDICATE const& predicate)
{
const std::list<HostileReference* > &threatlist = me->getThreatManager().getThreatList();
if (position >= threatlist.size())
@@ -176,7 +176,7 @@ class UnitAI
// Select the targets satifying the predicate.
// predicate shall extend std::unary_function<Unit* , bool>
template <class PREDICATE> void SelectTargetList(std::list<Unit*> &targetList, PREDICATE predicate, uint32 maxTargets, SelectAggroTarget targetType)
template <class PREDICATE> void SelectTargetList(std::list<Unit*> &targetList, PREDICATE const& predicate, uint32 maxTargets, SelectAggroTarget targetType)
{
std::list<HostileReference*> const& threatlist = me->getThreatManager().getThreatList();
if (threatlist.empty())
@@ -350,14 +350,12 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
if (!action.text.TextId1)
return;
int32 temp = 0;
int32 temp = action.text.TextId1;
if (action.text.TextId2 && action.text.TextId3)
temp = RAND(action.text.TextId1, action.text.TextId2, action.text.TextId3);
else if (action.text.TextId2 && urand(0, 1))
temp = action.text.TextId2;
else
temp = action.text.TextId1;
if (temp)
{
@@ -1320,16 +1318,14 @@ bool CreatureEventAI::CanCast(Unit* Target, SpellEntry const *Spell, bool Trigge
if (!Triggered && me->GetPower((Powers)Spell->powerType) < CalculatePowerCost(Spell, me, GetSpellSchoolMask(Spell)))
return false;
SpellRangeEntry const *TempRange = NULL;
TempRange = GetSpellRangeStore()->LookupEntry(Spell->rangeIndex);
SpellRangeEntry const* tempRange = sSpellRangeStore.LookupEntry(Spell->rangeIndex);
//Spell has invalid range store so we can't use it
if (!TempRange)
if (!tempRange)
return false;
//Unit is out of range of this spell
if (!me->IsInRange(Target, TempRange->minRangeHostile, TempRange->maxRangeHostile))
if (!me->IsInRange(Target, tempRange->minRangeHostile, tempRange->maxRangeHostile))
return false;
return true;
+1 -1
View File
@@ -577,7 +577,7 @@ typedef UNORDERED_MAP<uint32, CreatureEventAI_Summon> CreatureEventAI_Summon_Map
struct CreatureEventAIHolder
{
CreatureEventAIHolder(CreatureEventAI_Event p) : Event(p), Time(0), Enabled(true){}
CreatureEventAIHolder(CreatureEventAI_Event const& p) : Event(p), Time(0), Enabled(true){}
CreatureEventAI_Event Event;
uint32 Time;
@@ -721,7 +721,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts()
break;
default:
sLog->outErrorDb("CreatureEventAI: Event %u Action %u have currently not checked at load action type (%u). Need check code update?", i, j+1, temp.action[j].type);
sLog->outErrorDb("CreatureEventAI: Event %u Action %u have currently not checked at load action type (%u). Need check code update?", i, j+1, action.type);
break;
}
}
@@ -1025,9 +1025,6 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
}
case SMART_ACTION_SUMMON_CREATURE:
{
WorldObject* obj = GetBaseObject();
if (!obj)
obj = unit;
float x, y, z, o;
ObjectList* targets = GetTargets(e, unit);
if (targets)
@@ -1356,6 +1353,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
ne.minMaxRepeat.repeatMin = e.action.timeEvent.repeatMin;
ne.minMaxRepeat.repeatMax = e.action.timeEvent.repeatMax;
ne.event_flags = 0;
if (!ne.minMaxRepeat.repeatMin && !ne.minMaxRepeat.repeatMax)
ne.event_flags |= SMART_EVENT_FLAG_NOT_REPEATABLE;
@@ -1395,9 +1393,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
goOrigGUID = go ? go->GetGUID() : 0;
go = NULL;
me = (*itr)->ToCreature();
delete targets;
return;
break;
}
else if (IsGameObject(*itr))
{
@@ -1407,9 +1403,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
goOrigGUID = go ? go->GetGUID() : 0;
go = (*itr)->ToGameObject();
me = NULL;
delete targets;
return;
break;
}
}
@@ -1532,7 +1526,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
if (e.action.cast.flags & SMARTCAST_INTERRUPT_PREVIOUS)
(*itr)->ToUnit()->InterruptNonMeleeSpells(false);
for (ObjectList::const_iterator it = targets->begin(); it != targets->end(); it++)
for (ObjectList::const_iterator it = targets->begin(); it != targets->end(); ++it)
if (IsUnit(*it))
(*itr)->ToUnit()->CastSpell((*it)->ToUnit(), e.action.cast.spell, (e.action.cast.flags & SMARTCAST_TRIGGERED) ? true : false);
}
@@ -1708,7 +1702,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
}
}
void SmartScript::InstallTemplate(SmartScriptHolder e)
void SmartScript::InstallTemplate(SmartScriptHolder const& e)
{
if (!GetBaseObject())
return;
@@ -1814,7 +1808,7 @@ SmartScriptHolder SmartScript::CreateEvent(SMART_EVENT e, uint32 event_flags, ui
return script;
}
ObjectList* SmartScript::GetTargets(SmartScriptHolder e, Unit* invoker)
ObjectList* SmartScript::GetTargets(SmartScriptHolder const& e, Unit* invoker /*= NULL*/)
{
Unit* trigger = NULL;
if (invoker)
@@ -221,7 +221,7 @@ void SmartAIMgr::LoadSmartAIFromDB()
sLog->outString();
}
bool SmartAIMgr::IsTargetValid(SmartScriptHolder e)
bool SmartAIMgr::IsTargetValid(SmartScriptHolder const& e)
{
if (e.GetActionType() == SMART_ACTION_INSTALL_AI_TEMPLATE)
return true; //AI template has special handling
@@ -780,7 +780,7 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder &e)
return true;
}
bool SmartAIMgr::IsTextValid(SmartScriptHolder e, uint32 id)
bool SmartAIMgr::IsTextValid(SmartScriptHolder const& e, uint32 id)
{
bool error = false;
uint32 entry = 0;
@@ -1225,7 +1225,8 @@ class SmartAIMgr
SmartAIEventMap mEventMap[SMART_SCRIPT_TYPE_MAX];
bool IsEventValid(SmartScriptHolder &e);
bool IsTargetValid(SmartScriptHolder e);
bool IsTargetValid(SmartScriptHolder const& e);
/*inline bool IsTargetValid(SmartScriptHolder e, int32 target)
{
if (target < SMART_TARGET_NONE || target >= SMART_TARGET_END)
@@ -1235,7 +1236,8 @@ class SmartAIMgr
}
return true;
}*/
inline bool IsMinMaxValid(SmartScriptHolder e, uint32 min, uint32 max)
bool IsMinMaxValid(SmartScriptHolder const& e, uint32 min, uint32 max)
{
if (max < min)
{
@@ -1244,6 +1246,7 @@ class SmartAIMgr
}
return true;
}
/*inline bool IsPercentValid(SmartScriptHolder e, int32 pct)
{
if (pct < -100 || pct > 100)
@@ -1253,7 +1256,8 @@ class SmartAIMgr
}
return true;
}*/
inline bool NotNULL(SmartScriptHolder e, uint32 data)
bool NotNULL(SmartScriptHolder const& e, uint32 data)
{
if (!data)
{
@@ -1262,7 +1266,8 @@ class SmartAIMgr
}
return true;
}
inline bool IsCreatureValid(SmartScriptHolder e, uint32 entry)
bool IsCreatureValid(SmartScriptHolder const& e, uint32 entry)
{
if (!sObjectMgr->GetCreatureTemplate(entry))
{
@@ -1271,7 +1276,8 @@ class SmartAIMgr
}
return true;
}
inline bool IsQuestValid(SmartScriptHolder e, uint32 entry)
bool IsQuestValid(SmartScriptHolder const& e, uint32 entry)
{
if (!sObjectMgr->GetQuestTemplate(entry))
{
@@ -1280,7 +1286,8 @@ class SmartAIMgr
}
return true;
}
inline bool IsGameObjectValid(SmartScriptHolder e, uint32 entry)
bool IsGameObjectValid(SmartScriptHolder const& e, uint32 entry)
{
if (!sObjectMgr->GetGameObjectTemplate(entry))
{
@@ -1289,7 +1296,8 @@ class SmartAIMgr
}
return true;
}
inline bool IsSpellValid(SmartScriptHolder e, uint32 entry)
bool IsSpellValid(SmartScriptHolder const& e, uint32 entry)
{
if (!sSpellStore.LookupEntry(entry))
{
@@ -1298,7 +1306,8 @@ class SmartAIMgr
}
return true;
}
inline bool IsItemValid(SmartScriptHolder e, uint32 entry)
bool IsItemValid(SmartScriptHolder const& e, uint32 entry)
{
if (!sItemStore.LookupEntry(entry))
{
@@ -1327,7 +1336,8 @@ class SmartAIMgr
}
return true;
}*/
inline bool IsTextEmoteValid(SmartScriptHolder e, uint32 entry)
bool IsTextEmoteValid(SmartScriptHolder const& e, uint32 entry)
{
if (!sEmotesTextStore.LookupEntry(entry))
{
@@ -1336,7 +1346,8 @@ class SmartAIMgr
}
return true;
}
inline bool IsEmoteValid(SmartScriptHolder e, uint32 entry)
bool IsEmoteValid(SmartScriptHolder const& e, uint32 entry)
{
if (!sEmotesStore.LookupEntry(entry))
{
@@ -1345,7 +1356,8 @@ class SmartAIMgr
}
return true;
}
inline bool IsAreaTriggerValid(SmartScriptHolder e, uint32 entry)
bool IsAreaTriggerValid(SmartScriptHolder const& e, uint32 entry)
{
if (!sAreaTriggerStore.LookupEntry(entry))
{
@@ -1354,7 +1366,8 @@ class SmartAIMgr
}
return true;
}
inline bool IsSoundValid(SmartScriptHolder e, uint32 entry)
bool IsSoundValid(SmartScriptHolder const& e, uint32 entry)
{
if (!sSoundEntriesStore.LookupEntry(entry))
{
@@ -1363,7 +1376,8 @@ class SmartAIMgr
}
return true;
}
bool IsTextValid(SmartScriptHolder e, uint32 id);
bool IsTextValid(SmartScriptHolder const& e, uint32 id);
};
#define sSmartScriptMgr ACE_Singleton<SmartAIMgr, ACE_Null_Mutex>::instance()