From c68e39d074641a9a8da67916acdc89347038b2fa Mon Sep 17 00:00:00 2001 From: Ovahlord Date: Sat, 5 Oct 2019 03:46:31 +0200 Subject: [PATCH] Core/Transports: solved all remaining visual issues for transports --- .../game/Entities/GameObject/GameObject.cpp | 2 +- src/server/game/Entities/Object/Object.cpp | 6 +-- .../game/Entities/Transport/Transport.cpp | 48 +++++++++++-------- .../game/Entities/Transport/Transport.h | 9 ++-- 4 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp index 6c50d97f9bb..bb15025c5fc 100644 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -2442,7 +2442,7 @@ void GameObject::BuildValuesUpdate(uint8 updateType, ByteBuffer* data, Player* t Transport const* transport = ToTransport(); if (uint32 transportPeriod = transport->GetTransportPeriod()) { - float timer = float(transport->GetPathProgress() % transportPeriod); + float timer = float(transport->GetTimer() % transportPeriod); pathProgress = int16(timer / float(transportPeriod) * 65535.0f); } break; diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index 9f94b9c1e2b..75f75f317c8 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -643,10 +643,8 @@ void Object::BuildMovementUpdate(ByteBuffer* data, uint16 flags) const { if (GameObject const* go = ToGameObject()) { - if (MapTransport const* transport = go->ToMapTransport()) - *data << uint32(transport->GetPathProgress()); - else if (Transport const* transport = go->ToTransport()) - *data << uint32(getMSTime() + transport->GetCurrentTransportTime()); + if (Transport const* transport = go->ToTransport()) + *data << uint32(transport->GetTimer()); else *data << uint32(getMSTime()); } diff --git a/src/server/game/Entities/Transport/Transport.cpp b/src/server/game/Entities/Transport/Transport.cpp index 0ba8949a0d8..30ae4ad45fb 100644 --- a/src/server/game/Entities/Transport/Transport.cpp +++ b/src/server/game/Entities/Transport/Transport.cpp @@ -67,7 +67,7 @@ void Transport::AddPassenger(WorldObject* passenger) { passenger->SetTransport(this); passenger->m_movementInfo.transport.guid = GetGUID(); - passenger->m_movementInfo.transport.time = GetPathProgress(); + passenger->m_movementInfo.transport.time = GetTimer(); TC_LOG_DEBUG("entities.transport", "Object %s boarded transport %s.", passenger->GetName().c_str(), GetName().c_str()); if (Unit* unit = passenger->ToUnit()) @@ -214,7 +214,19 @@ bool Transport::Create(ObjectGuid::LowType guidlow, uint32 entry, Map* map, uint else SetGoState(GO_STATE_TRANSPORT_ACTIVE); - SetPathProgress(0); + if (_isDynamicTransport) + { + SetPeriod(m_goValue.Transport.AnimationInfo->TotalTime); + m_goValue.Transport.PathProgress = getMSTime(); + if (m_goValue.Transport.AnimationInfo) + m_goValue.Transport.PathProgress -= m_goValue.Transport.PathProgress % GetTransportPeriod(); // align to period + } + else + { + SetPeriod(getMSTime() + stopTimer); + m_goValue.Transport.PathProgress = getMSTime() + stopTimer; + } + SetDestinationStopFrameTime(stopTimer); SetCurrentTransportTime(stopTimer); @@ -291,6 +303,7 @@ void Transport::Update(uint32 diff) if (IsDynamicTransport()) { + m_goValue.Transport.PathProgress += diff; SetCurrentTransportTime(GetCurrentTransportTime() + diff); if (GetCurrentTransportTime() >= GetTransportPeriod()) SetCurrentTransportTime(GetCurrentTransportTime() % GetTransportPeriod()); @@ -358,9 +371,9 @@ void Transport::Update(uint32 diff) SetCurrentTransportTime(currentTime); } } + m_goValue.Transport.PathProgress = getMSTime() + GetCurrentTransportTime(); } - SetPathProgress(getMSTime() + GetCurrentTransportTime()); RelocateToProgress(GetCurrentTransportTime()); } @@ -474,15 +487,6 @@ void Transport::UpdatePassengerPositions(PassengerSet& passengers) } } -uint32 Transport::GetTransportPeriod() const -{ - ASSERT(m_goInfo->type == GAMEOBJECT_TYPE_TRANSPORT); - if (m_goValue.Transport.AnimationInfo) - return m_goValue.Transport.AnimationInfo->TotalTime; - - return 0; -} - void Transport::SetTransportState(GOState state, uint32 stopFrame /*= 0*/) { // Do not change the transport state before reaching the last selected destination @@ -497,9 +501,10 @@ void Transport::SetTransportState(GOState state, uint32 stopFrame /*= 0*/) if (state == GO_STATE_TRANSPORT_ACTIVE) { if (GetGoState() >= GO_STATE_TRANSPORT_STOPPED) + { stopTimer = m_goValue.Transport.StopFrames->at(GetGoState() - GO_STATE_TRANSPORT_STOPPED); - - SetUInt32Value(GAMEOBJECT_LEVEL, getMSTime() + stopTimer); + SetPeriod(stopTimer); + } } else { @@ -514,15 +519,16 @@ void Transport::SetTransportState(GOState state, uint32 stopFrame /*= 0*/) // forward movement. target frame time - current frame time if (GetCurrentTransportTime() < stopTimer) - SetUInt32Value(GAMEOBJECT_LEVEL, getMSTime() + stopTimer - GetCurrentTransportTime()); + SetPeriod(getMSTime() + stopTimer - GetCurrentTransportTime()); else if (backwardsTimer) - SetUInt32Value(GAMEOBJECT_LEVEL, getMSTime() + backwardsTimer); + SetPeriod(getMSTime() + backwardsTimer); else - SetUInt32Value(GAMEOBJECT_LEVEL, getMSTime() + GetCurrentTransportTime() - stopTimer); + SetPeriod(getMSTime() + GetCurrentTransportTime() - stopTimer); state = GOState(GO_STATE_TRANSPORT_STOPPED + stopFrame); } + SetDestinationStopFrameTime(stopTimer); SetLastStopFrameTime(GetCurrentTransportTime()); if (GetCurrentTransportTime() > backwardsTimer) @@ -563,7 +569,7 @@ bool MapTransport::CreateMapTransport(ObjectGuid::LowType guidlow, uint32 entry, _triggeredArrivalEvent = false; _triggeredDepartureEvent = false; - SetPathProgress(0); + m_goValue.Transport.PathProgress = 0; SetPeriod(tInfo->pathTime); SetGoState(!m_goInfo->moTransport.canBeStopped ? GO_STATE_READY : GO_STATE_ACTIVE); SetLocalRotation(0.0f, 0.0f, 0.0f, 1.0f); @@ -765,7 +771,7 @@ Creature* MapTransport::CreateNPCPassenger(ObjectGuid::LowType guid, CreatureDat creature->SetTransport(this); creature->m_movementInfo.transport.guid = GetGUID(); - creature->m_movementInfo.transport.time = GetPathProgress(); + creature->m_movementInfo.transport.time = GetTimer(); creature->m_movementInfo.transport.pos.Relocate(x, y, z, o); CalculatePassengerPosition(x, y, z, &o); creature->Relocate(x, y, z, o); @@ -824,7 +830,7 @@ GameObject* MapTransport::CreateGOPassenger(ObjectGuid::LowType guid, GameObject go->SetTransport(this); go->m_movementInfo.transport.guid = GetGUID(); - go->m_movementInfo.transport.time = GetPathProgress(); + go->m_movementInfo.transport.time = GetTimer(); go->m_movementInfo.transport.pos.Relocate(x, y, z, o); CalculatePassengerPosition(x, y, z, &o); go->Relocate(x, y, z, o); @@ -939,7 +945,7 @@ TempSummon* MapTransport::SummonPassenger(uint32 entry, Position const& pos, Tem summon->SetTransport(this); summon->m_movementInfo.transport.guid = GetGUID(); summon->m_movementInfo.transport.pos.Relocate(pos); - summon->m_movementInfo.transport.time = GetPathProgress(); + summon->m_movementInfo.transport.time = GetTimer(); summon->Relocate(x, y, z, o); summon->SetHomePosition(x, y, z, o); summon->SetTransportHomePosition(pos); diff --git a/src/server/game/Entities/Transport/Transport.h b/src/server/game/Entities/Transport/Transport.h index 076eedadcf4..97a74faa581 100644 --- a/src/server/game/Entities/Transport/Transport.h +++ b/src/server/game/Entities/Transport/Transport.h @@ -58,10 +58,10 @@ class TC_GAME_API Transport : public GameObject, public TransportBase bool IsDynamicTransport() const { return _isDynamicTransport; } - uint32 GetPathProgress() const { return GetGOValue()->Transport.PathProgress; } - void SetPathProgress(uint32 val) { m_goValue.Transport.PathProgress = val; } + uint32 GetTransportPeriod() const { return GetUInt32Value(GAMEOBJECT_LEVEL); } + void SetPeriod(uint32 period) { SetUInt32Value(GAMEOBJECT_LEVEL, period); } + uint32 GetTimer() const { return GetGOValue()->Transport.PathProgress; } - virtual uint32 GetTransportPeriod() const; void SetTransportState(GOState state, uint32 stopFrame = 0); void RelocateToProgress(uint32 progress); @@ -131,9 +131,6 @@ class TC_GAME_API MapTransport : public Transport */ TempSummon* SummonPassenger(uint32 entry, Position const& pos, TempSummonType summonType, SummonPropertiesEntry const* properties = nullptr, uint32 duration = 0, Unit* summoner = nullptr, uint32 spellId = 0, uint32 vehId = 0); - uint32 GetTransportPeriod() const override { return GetUInt32Value(GAMEOBJECT_LEVEL); } - void SetPeriod(uint32 period) { SetUInt32Value(GAMEOBJECT_LEVEL, period); } - KeyFrameVec const& GetKeyFrames() const { return _transportInfo->keyFrames; } void UpdatePosition(float x, float y, float z, float o);