[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

@ -1395,8 +1395,8 @@ bool BattleGround::AddObject(uint32 type, uint32 entry, float x, float y, float
// and when loading it (in go::LoadFromDB()), a new guid would be assigned to the object, and a new object would be created
// so we must create it specific for this instance
GameObject * go = new GameObject;
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))
if (!go->Create(GetBgMap()->GenerateLocalLowGuid(HIGHGUID_GAMEOBJECT),entry, GetBgMap(),
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.outError("Cannot create gameobject template %u! BattleGround not created!", entry);

View file

@ -58,7 +58,7 @@ GameObject::GameObject() : WorldObject(),
m_spellId = 0;
m_cooldownTime = 0;
m_rotation = 0;
m_packedRotation = 0;
}
GameObject::~GameObject()
@ -97,7 +97,7 @@ void GameObject::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);
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);
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;
}
@ -129,7 +129,7 @@ bool GameObject::Create(uint32 guidlow, uint32 name_id, Map *map, uint32 phaseMa
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
// TODO: store these values in DB
SetTransportPathRotation(0, 0, 0, 1.f);
@ -517,10 +517,10 @@ void GameObject::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
data.posY = GetPositionY();
data.posZ = GetPositionZ();
data.orientation = GetOrientation();
data.rotation0 = m_quatX;
data.rotation1 = m_quatY;
data.rotation2 = m_quatZ;
data.rotation3 = m_quatW;
data.rotation.x = m_worldRotation.x;
data.rotation.y = m_worldRotation.y;
data.rotation.z = m_worldRotation.z;
data.rotation.w = m_worldRotation.w;
data.spawntimesecs = m_spawnedByDefault ? (int32)m_respawnDelayTime : -(int32)m_respawnDelayTime;
data.animprogress = GetGoAnimProgress();
data.go_state = GetGoState();
@ -538,10 +538,10 @@ void GameObject::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
<< GetPositionY() << ", "
<< GetPositionZ() << ", "
<< GetOrientation() << ", "
<< m_quatX << ", "
<< m_quatY << ", "
<< m_quatZ << ", "
<< m_quatW << ", "
<< m_worldRotation.x << ", "
<< m_worldRotation.y << ", "
<< m_worldRotation.z << ", "
<< m_worldRotation.w << ", "
<< m_respawnDelayTime << ", "
<< uint32(GetGoAnimProgress()) << ", "
<< uint32(GetGoState()) << ")";
@ -570,15 +570,10 @@ bool GameObject::LoadFromDB(uint32 guid, Map *map)
float z = data->posZ;
float ang = data->orientation;
float rotation0 = data->rotation0;
float rotation1 = data->rotation1;
float rotation2 = data->rotation2;
float rotation3 = data->rotation3;
uint8 animprogress = data->animprogress;
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;
if (!GetGOInfo()->GetDespawnPossibility() && !GetGOInfo()->IsDespawnAtAction() && data->spawntimesecs >= 0)
@ -827,7 +822,7 @@ void GameObject::SummonLinkedTrapIfAny()
GameObject* linkedGO = new GameObject;
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;
return;
@ -1674,17 +1669,17 @@ struct QuaternionCompressed
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:
if (qz == 0 && qw == 0)
quat = Quat::fromAxisAngleRotation(G3D::Vector3::unitZ(), GetOrientation());
if (qz == 0.f && qw == 0.f)
rotation = Quat::fromAxisAngleRotation(G3D::Vector3::unitZ(), GetOrientation());
quat.unitize();
m_rotation = QuaternionCompressed(quat).m_raw;
m_quatX = quat.x;
m_quatY = quat.y;
m_quatZ = quat.z;
m_quatW = quat.w;
rotation.unitize();
m_packedRotation = QuaternionCompressed(rotation).m_raw;
m_worldRotation.x = rotation.x;
m_worldRotation.y = rotation.y;
m_worldRotation.z = rotation.z;
m_worldRotation.w = rotation.w;
}
void GameObject::SetTransportPathRotation(float qx, float qy, float qz, float qw)

View file

@ -549,6 +549,16 @@ enum GOState
#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`
struct GameObjectData
{
@ -559,10 +569,7 @@ struct GameObjectData
float posY;
float posZ;
float orientation;
float rotation0;
float rotation1;
float rotation2;
float rotation3;
QuaternionData rotation;
int32 spawntimesecs;
uint32 animprogress;
GOState go_state;
@ -598,7 +605,8 @@ class MANGOS_DLL_SPEC GameObject : public WorldObject
void AddToWorld();
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;
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 SetWorldRotation(float qx, float qy, float qz, float qw);
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
const char* GetNameForLocaleIdx(int32 locale_idx) const;
@ -746,8 +754,8 @@ class MANGOS_DLL_SPEC GameObject : public WorldObject
GameObjectInfo const* m_goInfo;
GameObjectDisplayInfoEntry const* m_displayInfo;
int64 m_rotation;
float m_quatX, m_quatY, m_quatZ, m_quatW;
int64 m_packedRotation;
QuaternionData m_worldRotation;
private:
void SwitchDoorOrButton(bool activate, bool alternative = false);

View file

@ -1091,7 +1091,7 @@ bool ChatHandler::HandleGameObjectAddCommand(char* args)
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;
return false;

View file

@ -407,7 +407,7 @@ void Object::BuildMovementUpdate(ByteBuffer * data, uint16 updateFlags) const
// 0x200
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.posZ = fields[ 5].GetFloat();
data.orientation = fields[ 6].GetFloat();
data.rotation0 = fields[ 7].GetFloat();
data.rotation1 = fields[ 8].GetFloat();
data.rotation2 = fields[ 9].GetFloat();
data.rotation3 = fields[10].GetFloat();
data.rotation.x = fields[ 7].GetFloat();
data.rotation.y = fields[ 8].GetFloat();
data.rotation.z = fields[ 9].GetFloat();
data.rotation.w = fields[10].GetFloat();
data.spawntimesecs = fields[11].GetInt32();
MapEntry const* mapEntry = sMapStore.LookupEntry(data.mapid);
@ -1513,27 +1513,27 @@ void ObjectMgr::LoadGameobjects()
int16 GuidPoolId = fields[17].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;
}
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;
}
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;
}
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;
}

View file

@ -4318,7 +4318,7 @@ void Aura::HandleAuraModStun(bool apply, bool Real)
{
GameObject* pObj = new GameObject;
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->SetSpellId(GetId());

View file

@ -1006,7 +1006,7 @@ void Spell::EffectDummy(SpellEffectIndex eff_idx)
if (!pGameObj->Create(map->GenerateLocalLowGuid(HIGHGUID_GAMEOBJECT), 177704,
map, m_caster->GetPhaseMask(),
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;
return;
@ -1061,7 +1061,7 @@ void Spell::EffectDummy(SpellEffectIndex eff_idx)
// create before death for get proper coordinates
if (!pGameObj->Create(map->GenerateLocalLowGuid(HIGHGUID_GAMEOBJECT), 179644, map, m_caster->GetPhaseMask(),
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;
return;
@ -6164,7 +6164,7 @@ void Spell::EffectSummonObjectWild(SpellEffectIndex eff_idx)
Map *map = target->GetMap();
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;
return;
@ -7889,7 +7889,7 @@ void Spell::EffectDuel(SpellEffectIndex eff_idx)
m_caster->GetPositionX()+(unitTarget->GetPositionX()-m_caster->GetPositionX())/2 ,
m_caster->GetPositionY()+(unitTarget->GetPositionY()-m_caster->GetPositionY())/2 ,
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;
return;
@ -8254,7 +8254,7 @@ void Spell::EffectSummonObject(SpellEffectIndex eff_idx)
Map *map = m_caster->GetMap();
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;
return;
@ -8861,7 +8861,7 @@ void Spell::EffectTransmitted(SpellEffectIndex eff_idx)
GameObject* pGameObj = new GameObject;
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;
return;

View file

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