Permalink
Browse files

Core/Misc: Minor optimizations (+ code changes to reduce differences …

…with 4.3.4 branch)
  • Loading branch information...
1 parent 70e4891 commit 7c36e3a298ce243631848b94364c185a863d1526 @Spp- Spp- committed Mar 25, 2013
@@ -29,13 +29,13 @@
#include <list>
-class SpellInfo;
-
class CreatureAI;
+class CreatureGroup;
+class Group;
class Quest;
class Player;
+class SpellInfo;
class WorldSession;
-class CreatureGroup;
enum CreatureFlagsExtra
{
@@ -27,6 +27,7 @@
#include "DatabaseEnv.h"
class GameObjectAI;
+class Group;
#define MAX_GAMEOBJECT_QUEST_ITEMS 6

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -21,10 +21,8 @@
#include "Common.h"
#include "UpdateMask.h"
-#include "UpdateData.h"
#include "GridReference.h"
#include "ObjectDefines.h"
-#include "GridDefines.h"
#include "Map.h"
#include <set>
@@ -101,20 +99,21 @@ enum NotifyFlags
NOTIFY_ALL = 0xFF
};
-class WorldPacket;
-class UpdateData;
-class ByteBuffer;
-class WorldSession;
+class Corpse;
class Creature;
-class Player;
-class InstanceScript;
+class CreatureAI;
+class DynamicObject;
class GameObject;
+class Map;
+class InstanceScript;
+class Player;
class TempSummon;
-class Vehicle;
-class CreatureAI;
-class ZoneScript;
-class Unit;
class Transport;
+class Unit;
+class UpdateData;
+class WorldObject;
+class WorldPacket;
+class ZoneScript;
typedef UNORDERED_MAP<Player*, UpdateData> UpdateDataMapType;
@@ -225,6 +224,9 @@ class Object
Corpse* ToCorpse() { if (GetTypeId() == TYPEID_CORPSE) return reinterpret_cast<Corpse*>(this); else return NULL; }
Corpse const* ToCorpse() const { if (GetTypeId() == TYPEID_CORPSE) return reinterpret_cast<Corpse const*>(this); else return NULL; }
+ DynamicObject* ToDynObject() { if (GetTypeId() == TYPEID_DYNAMICOBJECT) return reinterpret_cast<DynamicObject*>(this); else return NULL; }
+ DynamicObject const* ToDynObject() const { if (GetTypeId() == TYPEID_DYNAMICOBJECT) return reinterpret_cast<DynamicObject const*>(this); else return NULL; }
+
protected:
Object();
@@ -288,21 +290,31 @@ struct Position
float m_positionX;
float m_positionY;
float m_positionZ;
+// Better to limit access to m_orientation field, but this will be hard to achieve with many scripts using array initialization for this structure
+//private:
float m_orientation;
+//public:
+
+ bool operator==(Position const &a);
+
+ inline bool operator!=(Position const &a)
+ {
+ return !(operator==(a));
+ }
void Relocate(float x, float y)
{ m_positionX = x; m_positionY = y;}
void Relocate(float x, float y, float z)
{ m_positionX = x; m_positionY = y; m_positionZ = z; }
void Relocate(float x, float y, float z, float orientation)
- { m_positionX = x; m_positionY = y; m_positionZ = z; m_orientation = orientation; }
- void Relocate(const Position &pos)
- { m_positionX = pos.m_positionX; m_positionY = pos.m_positionY; m_positionZ = pos.m_positionZ; m_orientation = pos.m_orientation; }
- void Relocate(const Position* pos)
- { m_positionX = pos->m_positionX; m_positionY = pos->m_positionY; m_positionZ = pos->m_positionZ; m_orientation = pos->m_orientation; }
- void RelocateOffset(const Position &offset);
+ { m_positionX = x; m_positionY = y; m_positionZ = z; SetOrientation(orientation); }
+ void Relocate(Position const &pos)
+ { m_positionX = pos.m_positionX; m_positionY = pos.m_positionY; m_positionZ = pos.m_positionZ; SetOrientation(pos.m_orientation); }
+ void Relocate(Position const* pos)
+ { m_positionX = pos->m_positionX; m_positionY = pos->m_positionY; m_positionZ = pos->m_positionZ; SetOrientation(pos->m_orientation); }
+ void RelocateOffset(Position const &offset);
void SetOrientation(float orientation)
- { m_orientation = orientation; }
+ { m_orientation = NormalizeOrientation(orientation); }
float GetPositionX() const { return m_positionX; }
float GetPositionY() const { return m_positionY; }
@@ -336,39 +348,54 @@ struct Position
{ float dx = m_positionX - x; float dy = m_positionY - y; return dx*dx + dy*dy; }
float GetExactDist2d(const float x, const float y) const
{ return sqrt(GetExactDist2dSq(x, y)); }
- float GetExactDist2dSq(const Position* pos) const
+ float GetExactDist2dSq(Position const* pos) const
{ float dx = m_positionX - pos->m_positionX; float dy = m_positionY - pos->m_positionY; return dx*dx + dy*dy; }
- float GetExactDist2d(const Position* pos) const
+ float GetExactDist2d(Position const* pos) const
{ return sqrt(GetExactDist2dSq(pos)); }
float GetExactDistSq(float x, float y, float z) const
{ float dz = m_positionZ - z; return GetExactDist2dSq(x, y) + dz*dz; }
float GetExactDist(float x, float y, float z) const
{ return sqrt(GetExactDistSq(x, y, z)); }
- float GetExactDistSq(const Position* pos) const
+ float GetExactDistSq(Position const* pos) const
{ float dx = m_positionX - pos->m_positionX; float dy = m_positionY - pos->m_positionY; float dz = m_positionZ - pos->m_positionZ; return dx*dx + dy*dy + dz*dz; }
- float GetExactDist(const Position* pos) const
+ float GetExactDist(Position const* pos) const
{ return sqrt(GetExactDistSq(pos)); }
- void GetPositionOffsetTo(const Position & endPos, Position & retOffset) const;
+ void GetPositionOffsetTo(Position const & endPos, Position & retOffset) const;
- float GetAngle(const Position* pos) const;
+ float GetAngle(Position const* pos) const;
float GetAngle(float x, float y) const;
- float GetRelativeAngle(const Position* pos) const
+ float GetRelativeAngle(Position const* pos) const
{ return GetAngle(pos) - m_orientation; }
float GetRelativeAngle(float x, float y) const { return GetAngle(x, y) - m_orientation; }
void GetSinCos(float x, float y, float &vsin, float &vcos) const;
bool IsInDist2d(float x, float y, float dist) const
{ return GetExactDist2dSq(x, y) < dist * dist; }
- bool IsInDist2d(const Position* pos, float dist) const
+ bool IsInDist2d(Position const* pos, float dist) const
{ return GetExactDist2dSq(pos) < dist * dist; }
bool IsInDist(float x, float y, float z, float dist) const
{ return GetExactDistSq(x, y, z) < dist * dist; }
- bool IsInDist(const Position* pos, float dist) const
+ bool IsInDist(Position const* pos, float dist) const
{ return GetExactDistSq(pos) < dist * dist; }
- bool HasInArc(float arcangle, const Position* pos) const;
+ bool HasInArc(float arcangle, Position const* pos, float border = 2.0f) const;
bool HasInLine(WorldObject const* target, float width) const;
std::string ToString() const;
+
+ // modulos a radian orientation to the range of 0..2PI
+ static float NormalizeOrientation(float o)
+ {
+ // fmod only supports positive numbers. Thus we have
+ // to emulate negative numbers
+ if (o < 0)
+ {
+ float mod = o *-1;
+ mod = fmod(mod, 2.0f * static_cast<float>(M_PI));
+ mod = -mod + 2.0f * static_cast<float>(M_PI);
+ return mod;
+ }
+ return fmod(o, 2.0f * static_cast<float>(M_PI));
+ }
};
ByteBuffer& operator>>(ByteBuffer& buf, Position::PositionXYZOStreamer const& streamer);
ByteBuffer& operator<<(ByteBuffer& buf, Position::PositionXYZStreamer const& streamer);
@@ -378,39 +405,31 @@ ByteBuffer& operator<<(ByteBuffer& buf, Position::PositionXYZOStreamer const& st
struct MovementInfo
{
// common
- uint64 guid;
- uint32 flags;
- uint16 flags2;
+ uint64 guid;
+ uint32 flags;
+ uint16 flags2;
Position pos;
- uint32 time;
+ uint32 time;
// transport
- uint64 t_guid;
+ uint64 t_guid;
Position t_pos;
- uint32 t_time;
- uint32 t_time2;
- int8 t_seat;
+ int8 t_seat;
+ uint32 t_time;
+ uint32 t_time2;
// swimming/flying
- float pitch;
+ float pitch;
// falling
- uint32 fallTime;
+ uint32 fallTime;
// jumping
- float j_zspeed, j_sinAngle, j_cosAngle, j_xyspeed;
+ float j_zspeed, j_sinAngle, j_cosAngle, j_xyspeed;
// spline
- float splineElevation;
+ float splineElevation;
- MovementInfo()
- {
- pos.Relocate(0, 0, 0, 0);
- guid = 0;
- flags = 0;
- flags2 = 0;
- time = t_time = t_time2 = fallTime = 0;
- splineElevation = 0;
- pitch = j_zspeed = j_sinAngle = j_cosAngle = j_xyspeed = 0.0f;
- t_guid = 0;
- t_pos.Relocate(0, 0, 0, 0);
- t_seat = -1;
- }
+ MovementInfo() :
+ guid(), flags(), flags2(), pos(), time(), t_guid(), t_pos(),
+ t_seat(-1), t_time(), t_time2(), pitch(), fallTime(),
+ j_zspeed(), j_sinAngle(), j_cosAngle(), j_xyspeed()
+ { }
uint32 GetMovementFlags() const { return flags; }
void SetMovementFlags(uint32 flag) { flags = flag; }
@@ -498,14 +517,14 @@ class WorldObject : public Object, public WorldLocation
void MovePositionToFirstCollision(Position &pos, float dist, float angle);
void GetFirstCollisionPosition(Position &pos, float dist, float angle);
void GetRandomNearPosition(Position &pos, float radius);
- void GetContactPoint(const WorldObject* obj, float &x, float &y, float &z, float distance2d = CONTACT_DISTANCE) const;
+ void GetContactPoint(WorldObject const* obj, float &x, float &y, float &z, float distance2d = CONTACT_DISTANCE) const;
float GetObjectSize() const;
void UpdateGroundPositionZ(float x, float y, float &z) const;
void UpdateAllowedPositionZ(float x, float y, float &z) const;
- void GetRandomPoint(const Position &srcPos, float distance, float &rand_x, float &rand_y, float &rand_z) const;
- void GetRandomPoint(const Position &srcPos, float distance, Position &pos) const;
+ void GetRandomPoint(Position const &srcPos, float distance, float &rand_x, float &rand_y, float &rand_z) const;
+ void GetRandomPoint(Position const &srcPos, float distance, Position &pos) const;
uint32 GetInstanceId() const { return m_InstanceId; }
@@ -525,32 +544,32 @@ class WorldObject : public Object, public WorldLocation
virtual std::string const& GetNameForLocaleIdx(LocaleConstant /*locale_idx*/) const { return m_name; }
- float GetDistance(const WorldObject* obj) const;
- float GetDistance(const Position &pos) const;
+ float GetDistance(WorldObject const* obj) const;
+ float GetDistance(Position const &pos) const;
float GetDistance(float x, float y, float z) const;
- float GetDistance2d(const WorldObject* obj) const;
+ float GetDistance2d(WorldObject const* obj) const;
float GetDistance2d(float x, float y) const;
- float GetDistanceZ(const WorldObject* obj) const;
+ float GetDistanceZ(WorldObject const* obj) const;
- bool IsSelfOrInSameMap(const WorldObject* obj) const;
- bool IsInMap(const WorldObject* obj) const;
+ bool IsSelfOrInSameMap(WorldObject const* obj) const;
+ bool IsInMap(WorldObject const* obj) const;
bool IsWithinDist3d(float x, float y, float z, float dist) const;
- bool IsWithinDist3d(const Position* pos, float dist) const;
+ bool IsWithinDist3d(Position const* pos, float dist) const;
bool IsWithinDist2d(float x, float y, float dist) const;
- bool IsWithinDist2d(const Position* pos, float dist) const;
+ bool IsWithinDist2d(Position const* pos, float dist) const;
// use only if you will sure about placing both object at same map
bool IsWithinDist(WorldObject const* obj, float dist2compare, bool is3D = true) const;
bool IsWithinDistInMap(WorldObject const* obj, float dist2compare, bool is3D = true) const;
bool IsWithinLOS(float x, float y, float z) const;
- bool IsWithinLOSInMap(const WorldObject* obj) const;
+ bool IsWithinLOSInMap(WorldObject const* obj) const;
bool GetDistanceOrder(WorldObject const* obj1, WorldObject const* obj2, bool is3D = true) const;
bool IsInRange(WorldObject const* obj, float minRange, float maxRange, bool is3D = true) const;
bool IsInRange2d(float x, float y, float minRange, float maxRange) const;
bool IsInRange3d(float x, float y, float z, float minRange, float maxRange) const;
bool isInFront(WorldObject const* target, float arc = M_PI) const;
bool isInBack(WorldObject const* target, float arc = M_PI) const;
- bool IsInBetween(const WorldObject* obj1, const WorldObject* obj2, float size = 0) const;
+ bool IsInBetween(WorldObject const* obj1, WorldObject const* obj2, float size = 0) const;
virtual void CleanupsBeforeDelete(bool finalCleanup = true); // used in destructor or explicitly before mass creature delete to remove cross-references to already deleted units
@@ -581,7 +600,7 @@ class WorldObject : public Object, public WorldLocation
float GetGridActivationRange() const;
float GetVisibilityRange() const;
- float GetSightRange(const WorldObject* target = NULL) const;
+ float GetSightRange(WorldObject const* target = NULL) const;
bool canSeeOrDetect(WorldObject const* obj, bool ignoreStealth = false, bool distanceCheck = false) const;
FlaggedValuesArray32<int32, uint32, StealthType, TOTAL_STEALTH_TYPES> m_stealth;
@@ -608,7 +627,7 @@ class WorldObject : public Object, public WorldLocation
void SetZoneScript();
ZoneScript* GetZoneScript() const { return m_zoneScript; }
- TempSummon* SummonCreature(uint32 id, const Position &pos, TempSummonType spwtype = TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime = 0, uint32 vehId = 0) const;
+ TempSummon* SummonCreature(uint32 id, Position const &pos, TempSummonType spwtype = TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime = 0, uint32 vehId = 0) const;
TempSummon* SummonCreature(uint32 id, float x, float y, float z, float ang = 0, TempSummonType spwtype = TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime = 0) const;
GameObject* SummonGameObject(uint32 entry, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime);
Creature* SummonTrigger(float x, float y, float z, float ang, uint32 dur, CreatureAI* (*GetAI)(Creature*) = NULL);
@@ -710,13 +729,13 @@ namespace Trinity
class ObjectDistanceOrderPred
{
public:
- ObjectDistanceOrderPred(const WorldObject* pRefObj, bool ascending = true) : m_refObj(pRefObj), m_ascending(ascending) {}
- bool operator()(const WorldObject* pLeft, const WorldObject* pRight) const
+ ObjectDistanceOrderPred(WorldObject const* pRefObj, bool ascending = true) : m_refObj(pRefObj), m_ascending(ascending) {}
+ bool operator()(WorldObject const* pLeft, WorldObject const* pRight) const
{
return m_ascending ? m_refObj->GetDistanceOrder(pLeft, pRight) : !m_refObj->GetDistanceOrder(pLeft, pRight);
}
private:
- const WorldObject* m_refObj;
+ WorldObject const* m_refObj;
const bool m_ascending;
};
}
@@ -9934,7 +9934,7 @@ uint32 Unit::SpellDamageBonusDone(Unit* victim, SpellInfo const* spellProto, uin
AddPct(DoneTotalMod, (*i)->GetAmount());
// done scripted mod (take it from owner)
- Unit const * const owner = GetOwner() ? GetOwner() : this;
+ Unit const* owner = GetOwner() ? GetOwner() : this;
AuraEffectList const& mOverrideClassScript= owner->GetAuraEffectsByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
for (AuraEffectList::const_iterator i = mOverrideClassScript.begin(); i != mOverrideClassScript.end(); ++i)
{
@@ -19,6 +19,7 @@
#ifndef __UNIT_H
#define __UNIT_H
+#include "DBCStructure.h"
#include "EventProcessor.h"
#include "FollowerReference.h"
#include "FollowerRefManager.h"
@@ -672,7 +672,7 @@ class boss_fathomguard_caribdis : public CreatureScript
if (Creature* Cyclone = me->SummonCreature(CREATURE_CYCLONE, me->GetPositionX(), me->GetPositionY(), me->GetPositionZ(), float(rand()%5), TEMPSUMMON_TIMED_DESPAWN, 15000))
{
- Cyclone->ToCreature()->SetObjectScale(3.0f);
+ Cyclone->SetObjectScale(3.0f);
Cyclone->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
Cyclone->setFaction(me->getFaction());
Cyclone->CastSpell(Cyclone, SPELL_CYCLONE_CYCLONE, true);
@@ -164,24 +164,24 @@ class boss_warchief_kargath_bladefist : public CreatureScript
{
for (std::vector<uint64>::const_iterator itr = adds.begin(); itr!= adds.end(); ++itr)
{
- Unit* temp = Unit::GetUnit(*me, *itr);
- if (temp && temp->isAlive())
+ Creature* creature = Unit::GetCreature(*me, *itr);
+ if (creature && creature->isAlive())
{
- temp->GetMotionMaster()->Clear(true);
- me->DealDamage(temp, temp->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
- temp->ToCreature()->RemoveCorpse();
+ creature->GetMotionMaster()->Clear(true);
+ me->DealDamage(creature, creature->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
+ creature->RemoveCorpse();
}
}
adds.clear();
for (std::vector<uint64>::const_iterator itr = assassins.begin(); itr!= assassins.end(); ++itr)
{
- Unit* temp = Unit::GetUnit(*me, *itr);
- if (temp && temp->isAlive())
+ Creature* creature = Unit::GetCreature(*me, *itr);
+ if (creature && creature->isAlive())
{
- temp->GetMotionMaster()->Clear(true);
- me->DealDamage(temp, temp->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
- temp->ToCreature()->RemoveCorpse();
+ creature->GetMotionMaster()->Clear(true);
+ me->DealDamage(creature, creature->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
+ creature->RemoveCorpse();
}
}
assassins.clear();
Oops, something went wrong.

0 comments on commit 7c36e3a

Please sign in to comment.