[11806] A bit gameobject code refactoring

This commit is contained in:
SilverIce 2011-09-26 00:12:12 +03:00
parent 8057f774e8
commit 7a67f27ab3
9 changed files with 63 additions and 60 deletions

View file

@ -1396,7 +1396,7 @@ bool BattleGround::AddObject(uint32 type, uint32 entry, float x, float y, float
// so we must create it specific for this instance // so we must create it specific for this instance
GameObject * go = new GameObject; GameObject * go = new GameObject;
if (!go->Create(GetBgMap()->GenerateLocalLowGuid(HIGHGUID_GAMEOBJECT),entry, GetBgMap(), if (!go->Create(GetBgMap()->GenerateLocalLowGuid(HIGHGUID_GAMEOBJECT),entry, GetBgMap(),
PHASEMASK_NORMAL, x,y,z,o,rotation0,rotation1,rotation2,rotation3,GO_ANIMPROGRESS_DEFAULT,GO_STATE_READY)) PHASEMASK_NORMAL, x,y,z,o, QuaternionData(rotation0,rotation1,rotation2,rotation3)))
{ {
sLog.outErrorDb("Gameobject template %u not found in database! BattleGround not created!", entry); sLog.outErrorDb("Gameobject template %u not found in database! BattleGround not created!", entry);
sLog.outError("Cannot create gameobject template %u! BattleGround not created!", entry); sLog.outError("Cannot create gameobject template %u! BattleGround not created!", entry);

View file

@ -58,7 +58,7 @@ GameObject::GameObject() : WorldObject(),
m_spellId = 0; m_spellId = 0;
m_cooldownTime = 0; m_cooldownTime = 0;
m_rotation = 0; m_packedRotation = 0;
} }
GameObject::~GameObject() GameObject::~GameObject()
@ -97,7 +97,7 @@ void GameObject::RemoveFromWorld()
Object::RemoveFromWorld(); Object::RemoveFromWorld();
} }
bool GameObject::Create(uint32 guidlow, uint32 name_id, Map *map, uint32 phaseMask, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint8 animprogress, GOState go_state) bool GameObject::Create(uint32 guidlow, uint32 name_id, Map *map, uint32 phaseMask, float x, float y, float z, float ang, QuaternionData rotation, uint8 animprogress, GOState go_state)
{ {
MANGOS_ASSERT(map); MANGOS_ASSERT(map);
Relocate(x,y,z,ang); Relocate(x,y,z,ang);
@ -113,7 +113,7 @@ bool GameObject::Create(uint32 guidlow, uint32 name_id, Map *map, uint32 phaseMa
GameObjectInfo const* goinfo = ObjectMgr::GetGameObjectInfo(name_id); GameObjectInfo const* goinfo = ObjectMgr::GetGameObjectInfo(name_id);
if (!goinfo) if (!goinfo)
{ {
sLog.outErrorDb("Gameobject (GUID: %u) not created: Entry %u does not exist in `gameobject_template`. Map: %u (X: %f Y: %f Z: %f) ang: %f rotation0: %f rotation1: %f rotation2: %f rotation3: %f",guidlow, name_id, map->GetId(), x, y, z, ang, rotation0, rotation1, rotation2, rotation3); sLog.outErrorDb("Gameobject (GUID: %u) not created: Entry %u does not exist in `gameobject_template`. Map: %u (X: %f Y: %f Z: %f) ang: %f",guidlow, name_id, map->GetId(), x, y, z, ang);
return false; return false;
} }
@ -129,7 +129,7 @@ bool GameObject::Create(uint32 guidlow, uint32 name_id, Map *map, uint32 phaseMa
SetObjectScale(goinfo->size); SetObjectScale(goinfo->size);
SetWorldRotation(rotation0,rotation1,rotation2,rotation3); SetWorldRotation(rotation.x,rotation.y,rotation.z,rotation.w);
// For most of gameobjects is (0, 0, 0, 1) quaternion, only transports has not standart rotation // For most of gameobjects is (0, 0, 0, 1) quaternion, only transports has not standart rotation
// TODO: store these values in DB // TODO: store these values in DB
SetTransportPathRotation(0, 0, 0, 1.f); SetTransportPathRotation(0, 0, 0, 1.f);
@ -517,10 +517,10 @@ void GameObject::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
data.posY = GetPositionY(); data.posY = GetPositionY();
data.posZ = GetPositionZ(); data.posZ = GetPositionZ();
data.orientation = GetOrientation(); data.orientation = GetOrientation();
data.rotation0 = m_quatX; data.rotation.x = m_worldRotation.x;
data.rotation1 = m_quatY; data.rotation.y = m_worldRotation.y;
data.rotation2 = m_quatZ; data.rotation.z = m_worldRotation.z;
data.rotation3 = m_quatW; data.rotation.w = m_worldRotation.w;
data.spawntimesecs = m_spawnedByDefault ? (int32)m_respawnDelayTime : -(int32)m_respawnDelayTime; data.spawntimesecs = m_spawnedByDefault ? (int32)m_respawnDelayTime : -(int32)m_respawnDelayTime;
data.animprogress = GetGoAnimProgress(); data.animprogress = GetGoAnimProgress();
data.go_state = GetGoState(); data.go_state = GetGoState();
@ -538,10 +538,10 @@ void GameObject::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
<< GetPositionY() << ", " << GetPositionY() << ", "
<< GetPositionZ() << ", " << GetPositionZ() << ", "
<< GetOrientation() << ", " << GetOrientation() << ", "
<< m_quatX << ", " << m_worldRotation.x << ", "
<< m_quatY << ", " << m_worldRotation.y << ", "
<< m_quatZ << ", " << m_worldRotation.z << ", "
<< m_quatW << ", " << m_worldRotation.w << ", "
<< m_respawnDelayTime << ", " << m_respawnDelayTime << ", "
<< uint32(GetGoAnimProgress()) << ", " << uint32(GetGoAnimProgress()) << ", "
<< uint32(GetGoState()) << ")"; << uint32(GetGoState()) << ")";
@ -570,15 +570,10 @@ bool GameObject::LoadFromDB(uint32 guid, Map *map)
float z = data->posZ; float z = data->posZ;
float ang = data->orientation; float ang = data->orientation;
float rotation0 = data->rotation0;
float rotation1 = data->rotation1;
float rotation2 = data->rotation2;
float rotation3 = data->rotation3;
uint8 animprogress = data->animprogress; uint8 animprogress = data->animprogress;
GOState go_state = data->go_state; GOState go_state = data->go_state;
if (!Create(guid,entry, map, phaseMask, x, y, z, ang, rotation0, rotation1, rotation2, rotation3, animprogress, go_state) ) if (!Create(guid,entry, map, phaseMask, x, y, z, ang, data->rotation, animprogress, go_state))
return false; return false;
if (!GetGOInfo()->GetDespawnPossibility() && !GetGOInfo()->IsDespawnAtAction() && data->spawntimesecs >= 0) if (!GetGOInfo()->GetDespawnPossibility() && !GetGOInfo()->IsDespawnAtAction() && data->spawntimesecs >= 0)
@ -827,7 +822,7 @@ void GameObject::SummonLinkedTrapIfAny()
GameObject* linkedGO = new GameObject; GameObject* linkedGO = new GameObject;
if (!linkedGO->Create(GetMap()->GenerateLocalLowGuid(HIGHGUID_GAMEOBJECT), linkedEntry, GetMap(), if (!linkedGO->Create(GetMap()->GenerateLocalLowGuid(HIGHGUID_GAMEOBJECT), linkedEntry, GetMap(),
GetPhaseMask(), GetPositionX(), GetPositionY(), GetPositionZ(), GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, GO_ANIMPROGRESS_DEFAULT, GO_STATE_READY)) GetPhaseMask(), GetPositionX(), GetPositionY(), GetPositionZ(), GetOrientation()))
{ {
delete linkedGO; delete linkedGO;
return; return;
@ -1674,17 +1669,17 @@ struct QuaternionCompressed
void GameObject::SetWorldRotation(float qx, float qy, float qz, float qw) void GameObject::SetWorldRotation(float qx, float qy, float qz, float qw)
{ {
Quat quat(qx, qy, qz, qw); Quat rotation(qx, qy, qz, qw);
// Temporary solution for gameobjects that has no rotation data in DB: // Temporary solution for gameobjects that has no rotation data in DB:
if (qz == 0 && qw == 0) if (qz == 0.f && qw == 0.f)
quat = Quat::fromAxisAngleRotation(G3D::Vector3::unitZ(), GetOrientation()); rotation = Quat::fromAxisAngleRotation(G3D::Vector3::unitZ(), GetOrientation());
quat.unitize(); rotation.unitize();
m_rotation = QuaternionCompressed(quat).m_raw; m_packedRotation = QuaternionCompressed(rotation).m_raw;
m_quatX = quat.x; m_worldRotation.x = rotation.x;
m_quatY = quat.y; m_worldRotation.y = rotation.y;
m_quatZ = quat.z; m_worldRotation.z = rotation.z;
m_quatW = quat.w; m_worldRotation.w = rotation.w;
} }
void GameObject::SetTransportPathRotation(float qx, float qy, float qz, float qw) void GameObject::SetTransportPathRotation(float qx, float qy, float qz, float qw)

View file

@ -549,6 +549,16 @@ enum GOState
#define MAX_GO_STATE 3 #define MAX_GO_STATE 3
struct QuaternionData
{
float x, y, z, w;
QuaternionData() : x(0.f), y(0.f), z(0.f), w(0.f) {}
QuaternionData(float X, float Y, float Z, float W) : x(X), y(Y), z(Z), w(W) {}
bool isUnit() const { return fabs(x*x + y*y + z*z + w*w - 1.f) < 1e-5;}
};
// from `gameobject` // from `gameobject`
struct GameObjectData struct GameObjectData
{ {
@ -559,10 +569,7 @@ struct GameObjectData
float posY; float posY;
float posZ; float posZ;
float orientation; float orientation;
float rotation0; QuaternionData rotation;
float rotation1;
float rotation2;
float rotation3;
int32 spawntimesecs; int32 spawntimesecs;
uint32 animprogress; uint32 animprogress;
GOState go_state; GOState go_state;
@ -598,7 +605,8 @@ class MANGOS_DLL_SPEC GameObject : public WorldObject
void AddToWorld(); void AddToWorld();
void RemoveFromWorld(); void RemoveFromWorld();
bool Create(uint32 guidlow, uint32 name_id, Map *map, uint32 phaseMask, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint8 animprogress, GOState go_state); bool Create(uint32 guidlow, uint32 name_id, Map *map, uint32 phaseMask, float x, float y, float z, float ang,
QuaternionData rotation = QuaternionData(), uint8 animprogress = GO_ANIMPROGRESS_DEFAULT, GOState go_state = GO_STATE_READY);
void Update(uint32 update_diff, uint32 p_time) override; void Update(uint32 update_diff, uint32 p_time) override;
GameObjectInfo const* GetGOInfo() const; GameObjectInfo const* GetGOInfo() const;
@ -610,7 +618,7 @@ class MANGOS_DLL_SPEC GameObject : public WorldObject
void SetWorldRotationAngles(float z_rot, float y_rot, float x_rot); void SetWorldRotationAngles(float z_rot, float y_rot, float x_rot);
void SetWorldRotation(float qx, float qy, float qz, float qw); void SetWorldRotation(float qx, float qy, float qz, float qw);
void SetTransportPathRotation(float qx, float qy, float qz, float qw); // transforms(rotates) transport's path void SetTransportPathRotation(float qx, float qy, float qz, float qw); // transforms(rotates) transport's path
int64 GetRotation() const { return m_rotation; } int64 GetPackedWorldRotation() const { return m_packedRotation; }
// overwrite WorldObject function for proper name localization // overwrite WorldObject function for proper name localization
const char* GetNameForLocaleIdx(int32 locale_idx) const; const char* GetNameForLocaleIdx(int32 locale_idx) const;
@ -746,8 +754,8 @@ class MANGOS_DLL_SPEC GameObject : public WorldObject
GameObjectInfo const* m_goInfo; GameObjectInfo const* m_goInfo;
GameObjectDisplayInfoEntry const* m_displayInfo; GameObjectDisplayInfoEntry const* m_displayInfo;
int64 m_rotation; int64 m_packedRotation;
float m_quatX, m_quatY, m_quatZ, m_quatW; QuaternionData m_worldRotation;
private: private:
void SwitchDoorOrButton(bool activate, bool alternative = false); void SwitchDoorOrButton(bool activate, bool alternative = false);

View file

@ -1091,7 +1091,7 @@ bool ChatHandler::HandleGameObjectAddCommand(char* args)
return false; return false;
} }
if (!pGameObj->Create(db_lowGUID, gInfo->id, map, chr->GetPhaseMaskForSpawn(), x, y, z, o, 0.0f, 0.0f, 0.0f, 0.0f, GO_ANIMPROGRESS_DEFAULT, GO_STATE_READY)) if (!pGameObj->Create(db_lowGUID, gInfo->id, map, chr->GetPhaseMaskForSpawn(), x, y, z, o))
{ {
delete pGameObj; delete pGameObj;
return false; return false;

View file

@ -407,7 +407,7 @@ void Object::BuildMovementUpdate(ByteBuffer * data, uint16 updateFlags) const
// 0x200 // 0x200
if(updateFlags & UPDATEFLAG_ROTATION) if(updateFlags & UPDATEFLAG_ROTATION)
{ {
*data << int64(((GameObject*)this)->GetRotation()); *data << int64(((GameObject*)this)->GetPackedWorldRotation());
} }
} }

View file

@ -1476,10 +1476,10 @@ void ObjectMgr::LoadGameobjects()
data.posY = fields[ 4].GetFloat(); data.posY = fields[ 4].GetFloat();
data.posZ = fields[ 5].GetFloat(); data.posZ = fields[ 5].GetFloat();
data.orientation = fields[ 6].GetFloat(); data.orientation = fields[ 6].GetFloat();
data.rotation0 = fields[ 7].GetFloat(); data.rotation.x = fields[ 7].GetFloat();
data.rotation1 = fields[ 8].GetFloat(); data.rotation.y = fields[ 8].GetFloat();
data.rotation2 = fields[ 9].GetFloat(); data.rotation.z = fields[ 9].GetFloat();
data.rotation3 = fields[10].GetFloat(); data.rotation.w = fields[10].GetFloat();
data.spawntimesecs = fields[11].GetInt32(); data.spawntimesecs = fields[11].GetInt32();
MapEntry const* mapEntry = sMapStore.LookupEntry(data.mapid); MapEntry const* mapEntry = sMapStore.LookupEntry(data.mapid);
@ -1513,27 +1513,27 @@ void ObjectMgr::LoadGameobjects()
int16 GuidPoolId = fields[17].GetInt16(); int16 GuidPoolId = fields[17].GetInt16();
int16 EntryPoolId = fields[18].GetInt16(); int16 EntryPoolId = fields[18].GetInt16();
if (data.rotation0 < -1.0f || data.rotation0 > 1.0f) if (data.rotation.x < -1.0f || data.rotation.x > 1.0f)
{ {
sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid rotation0 (%f) value, skip", guid, data.id, data.rotation0); sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid rotation.x (%f) value, skip", guid, data.id, data.rotation.x);
continue; continue;
} }
if (data.rotation1 < -1.0f || data.rotation1 > 1.0f) if (data.rotation.y < -1.0f || data.rotation.y > 1.0f)
{ {
sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid rotation1 (%f) value, skip", guid, data.id, data.rotation1); sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid rotation.y (%f) value, skip", guid, data.id, data.rotation.y);
continue; continue;
} }
if (data.rotation2 < -1.0f || data.rotation2 > 1.0f) if (data.rotation.z < -1.0f || data.rotation.z > 1.0f)
{ {
sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid rotation2 (%f) value, skip", guid, data.id, data.rotation2); sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid rotation.z (%f) value, skip", guid, data.id, data.rotation.z);
continue; continue;
} }
if (data.rotation3 < -1.0f || data.rotation3 > 1.0f) if (data.rotation.w < -1.0f || data.rotation.w > 1.0f)
{ {
sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid rotation3 (%f) value, skip", guid, data.id, data.rotation3); sLog.outErrorDb("Table `gameobject` have gameobject (GUID: %u Entry: %u) with invalid rotation.w (%f) value, skip", guid, data.id, data.rotation.w);
continue; continue;
} }

View file

@ -4318,7 +4318,7 @@ void Aura::HandleAuraModStun(bool apply, bool Real)
{ {
GameObject* pObj = new GameObject; GameObject* pObj = new GameObject;
if(pObj->Create(target->GetMap()->GenerateLocalLowGuid(HIGHGUID_GAMEOBJECT), 185584, target->GetMap(), target->GetPhaseMask(), if(pObj->Create(target->GetMap()->GenerateLocalLowGuid(HIGHGUID_GAMEOBJECT), 185584, target->GetMap(), target->GetPhaseMask(),
target->GetPositionX(), target->GetPositionY(), target->GetPositionZ(), target->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, GO_ANIMPROGRESS_DEFAULT, GO_STATE_READY)) target->GetPositionX(), target->GetPositionY(), target->GetPositionZ(), target->GetOrientation()))
{ {
pObj->SetRespawnTime(GetAuraDuration()/IN_MILLISECONDS); pObj->SetRespawnTime(GetAuraDuration()/IN_MILLISECONDS);
pObj->SetSpellId(GetId()); pObj->SetSpellId(GetId());

View file

@ -1006,7 +1006,7 @@ void Spell::EffectDummy(SpellEffectIndex eff_idx)
if (!pGameObj->Create(map->GenerateLocalLowGuid(HIGHGUID_GAMEOBJECT), 177704, if (!pGameObj->Create(map->GenerateLocalLowGuid(HIGHGUID_GAMEOBJECT), 177704,
map, m_caster->GetPhaseMask(), map, m_caster->GetPhaseMask(),
unitTarget->GetPositionX(), unitTarget->GetPositionY(), unitTarget->GetPositionZ(), unitTarget->GetPositionX(), unitTarget->GetPositionY(), unitTarget->GetPositionZ(),
unitTarget->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, GO_ANIMPROGRESS_DEFAULT, GO_STATE_READY)) unitTarget->GetOrientation()))
{ {
delete pGameObj; delete pGameObj;
return; return;
@ -1061,7 +1061,7 @@ void Spell::EffectDummy(SpellEffectIndex eff_idx)
// create before death for get proper coordinates // create before death for get proper coordinates
if (!pGameObj->Create(map->GenerateLocalLowGuid(HIGHGUID_GAMEOBJECT), 179644, map, m_caster->GetPhaseMask(), if (!pGameObj->Create(map->GenerateLocalLowGuid(HIGHGUID_GAMEOBJECT), 179644, map, m_caster->GetPhaseMask(),
creatureTarget->GetPositionX(), creatureTarget->GetPositionY(), creatureTarget->GetPositionZ(), creatureTarget->GetPositionX(), creatureTarget->GetPositionY(), creatureTarget->GetPositionZ(),
creatureTarget->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, GO_ANIMPROGRESS_DEFAULT, GO_STATE_READY) ) creatureTarget->GetOrientation()) )
{ {
delete pGameObj; delete pGameObj;
return; return;
@ -6164,7 +6164,7 @@ void Spell::EffectSummonObjectWild(SpellEffectIndex eff_idx)
Map *map = target->GetMap(); Map *map = target->GetMap();
if(!pGameObj->Create(map->GenerateLocalLowGuid(HIGHGUID_GAMEOBJECT), gameobject_id, map, if(!pGameObj->Create(map->GenerateLocalLowGuid(HIGHGUID_GAMEOBJECT), gameobject_id, map,
m_caster->GetPhaseMask(), x, y, z, target->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, GO_ANIMPROGRESS_DEFAULT, GO_STATE_READY)) m_caster->GetPhaseMask(), x, y, z, target->GetOrientation()))
{ {
delete pGameObj; delete pGameObj;
return; return;
@ -7889,7 +7889,7 @@ void Spell::EffectDuel(SpellEffectIndex eff_idx)
m_caster->GetPositionX()+(unitTarget->GetPositionX()-m_caster->GetPositionX())/2 , m_caster->GetPositionX()+(unitTarget->GetPositionX()-m_caster->GetPositionX())/2 ,
m_caster->GetPositionY()+(unitTarget->GetPositionY()-m_caster->GetPositionY())/2 , m_caster->GetPositionY()+(unitTarget->GetPositionY()-m_caster->GetPositionY())/2 ,
m_caster->GetPositionZ(), m_caster->GetPositionZ(),
m_caster->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, GO_ANIMPROGRESS_DEFAULT, GO_STATE_READY)) m_caster->GetOrientation()))
{ {
delete pGameObj; delete pGameObj;
return; return;
@ -8254,7 +8254,7 @@ void Spell::EffectSummonObject(SpellEffectIndex eff_idx)
Map *map = m_caster->GetMap(); Map *map = m_caster->GetMap();
if(!pGameObj->Create(map->GenerateLocalLowGuid(HIGHGUID_GAMEOBJECT), go_id, map, if(!pGameObj->Create(map->GenerateLocalLowGuid(HIGHGUID_GAMEOBJECT), go_id, map,
m_caster->GetPhaseMask(), x, y, z, m_caster->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, GO_ANIMPROGRESS_DEFAULT, GO_STATE_READY)) m_caster->GetPhaseMask(), x, y, z, m_caster->GetOrientation()))
{ {
delete pGameObj; delete pGameObj;
return; return;
@ -8861,7 +8861,7 @@ void Spell::EffectTransmitted(SpellEffectIndex eff_idx)
GameObject* pGameObj = new GameObject; GameObject* pGameObj = new GameObject;
if(!pGameObj->Create(cMap->GenerateLocalLowGuid(HIGHGUID_GAMEOBJECT), name_id, cMap, if(!pGameObj->Create(cMap->GenerateLocalLowGuid(HIGHGUID_GAMEOBJECT), name_id, cMap,
m_caster->GetPhaseMask(), fx, fy, fz, m_caster->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, GO_ANIMPROGRESS_DEFAULT, GO_STATE_READY)) m_caster->GetPhaseMask(), fx, fy, fz, m_caster->GetOrientation()))
{ {
delete pGameObj; delete pGameObj;
return; return;

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "11805" #define REVISION_NR "11806"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__