diff options
| author | Riztazz <felianther15@gmail.com> | 2016-11-25 00:31:10 +0100 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2019-08-17 20:04:14 +0200 |
| commit | 2caec4f4d20b4c0f91abbcc60b756e00838c7bdd (patch) | |
| tree | 6dcc7dcdd3ed501a1ca87809fec05f7ccfb2a8bc /src/server/game/Movement | |
| parent | 7d60b9a289ee0942cf57b49626c0f3f9caeed331 (diff) | |
Revert "[3.3.5][master] Core/Movement: Smooth movement #13467 (#18020)"
This reverts commit 05fb27dae4e8af859e01e5b9e52b082cba217657.
(cherrypicked from a3c6880579f3326088ecbe5b8c08c4b75ed91a59)
Diffstat (limited to 'src/server/game/Movement')
| -rw-r--r-- | src/server/game/Movement/MotionMaster.cpp | 8 | ||||
| -rw-r--r-- | src/server/game/Movement/MotionMaster.h | 2 | ||||
| -rw-r--r--[-rwxr-xr-x] | src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp | 188 | ||||
| -rwxr-xr-x | src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.h | 27 | ||||
| -rw-r--r-- | src/server/game/Movement/Waypoints/WaypointManager.cpp | 70 | ||||
| -rw-r--r-- | src/server/game/Movement/Waypoints/WaypointManager.h | 29 |
6 files changed, 130 insertions, 194 deletions
diff --git a/src/server/game/Movement/MotionMaster.cpp b/src/server/game/Movement/MotionMaster.cpp index 4aa7f2246bf..df138316623 100644 --- a/src/server/game/Movement/MotionMaster.cpp +++ b/src/server/game/Movement/MotionMaster.cpp @@ -702,14 +702,6 @@ void MotionMaster::MovePath(uint32 path_id, bool repeatable) _owner->GetGUID().ToString().c_str(), path_id, repeatable ? "YES" : "NO"); } -void MotionMaster::MovePath(WaypointPath& path, bool repeatable) -{ - Mutate(new WaypointMovementGenerator<Creature>(path, repeatable), MOTION_SLOT_IDLE); - - TC_LOG_DEBUG("misc", "%s starts moving over path (repeatable: %s).", - _owner->GetGUID().ToString().c_str(), repeatable ? "YES" : "NO"); -} - void MotionMaster::MoveRotate(uint32 time, RotateDirection direction) { if (!time) diff --git a/src/server/game/Movement/MotionMaster.h b/src/server/game/Movement/MotionMaster.h index 9f56823feb3..5628b918402 100644 --- a/src/server/game/Movement/MotionMaster.h +++ b/src/server/game/Movement/MotionMaster.h @@ -32,7 +32,6 @@ class PathGenerator; struct Position; struct SplineChainLink; struct SplineChainResumeInfo; -struct WaypointPath; namespace G3D { @@ -181,7 +180,6 @@ class TC_GAME_API MotionMaster void MoveTaxiFlight(uint32 path, uint32 pathnode); void MoveDistract(uint32 time); void MovePath(uint32 path_id, bool repeatable); - void MovePath(WaypointPath& path, bool repeatable); void MoveRotate(uint32 time, RotateDirection direction); private: diff --git a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp index 9bb42da1e45..41f8020ba69 100755..100644 --- a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp @@ -25,18 +25,14 @@ #include "MoveSplineInit.h" #include "ObjectMgr.h" #include "Transport.h" -#include "WaypointManager.h" #include "World.h" void WaypointMovementGenerator<Creature>::LoadPath(Creature* creature) { - if (LoadedFromDB) - { - if (!path_id) - path_id = creature->GetWaypointPath(); + if (!path_id) + path_id = creature->GetWaypointPath(); - i_path = sWaypointMgr->GetPath(path_id); - } + i_path = sWaypointMgr->GetPath(path_id); if (!i_path) { @@ -45,95 +41,74 @@ void WaypointMovementGenerator<Creature>::LoadPath(Creature* creature) return; } - if (!Stopped()) - StartMoveNow(creature); + StartMoveNow(creature); } void WaypointMovementGenerator<Creature>::DoInitialize(Creature* creature) { LoadPath(creature); + creature->AddUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE); } void WaypointMovementGenerator<Creature>::DoFinalize(Creature* creature) { - creature->ClearUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE); + creature->ClearUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE); creature->SetWalk(false); } void WaypointMovementGenerator<Creature>::DoReset(Creature* creature) { - if (!Stopped()) - StartMoveNow(creature); + creature->AddUnitState(UNIT_STATE_ROAMING|UNIT_STATE_ROAMING_MOVE); + StartMoveNow(creature); } void WaypointMovementGenerator<Creature>::OnArrived(Creature* creature) { - if (!i_path || i_path->nodes.empty()) + if (!i_path || i_path->empty()) + return; + if (m_isArrivalDone) return; - WaypointNode const &waypoint = i_path->nodes.at(i_currentNode); - if (waypoint.delay) - { - creature->ClearUnitState(UNIT_STATE_ROAMING_MOVE); - Stop(waypoint.delay); - } + m_isArrivalDone = true; - if (waypoint.eventId && urand(0, 99) < waypoint.eventChance) + if (i_path->at(i_currentNode)->event_id && urand(0, 99) < i_path->at(i_currentNode)->event_chance) { - TC_LOG_DEBUG("maps.script", "Creature movement start script %u at point %u for %s.", waypoint.eventId, i_currentNode, creature->GetGUID().ToString().c_str()); + TC_LOG_DEBUG("maps.script", "Creature movement start script %u at point %u for %s.", i_path->at(i_currentNode)->event_id, i_currentNode, creature->GetGUID().ToString().c_str()); creature->ClearUnitState(UNIT_STATE_ROAMING_MOVE); - creature->GetMap()->ScriptsStart(sWaypointScripts, waypoint.eventId, creature, nullptr); + creature->GetMap()->ScriptsStart(sWaypointScripts, i_path->at(i_currentNode)->event_id, creature, NULL); } // Inform script MovementInform(creature); creature->UpdateWaypointID(i_currentNode); - creature->SetWalk(waypoint.moveType != WAYPOINT_MOVE_TYPE_RUN); -} - -void WaypointMovementGenerator<Creature>::FormationMove(Creature* creature) -{ - bool transportPath = creature->GetTransport() != nullptr; - - WaypointNode const &waypoint = i_path->nodes.at(i_currentNode); - - Movement::Location formationDest(waypoint.x, waypoint.y, waypoint.z, 0.0f); - - //! If creature is on transport, we assume waypoints set in DB are already transport offsets - if (transportPath) + if (i_path->at(i_currentNode)->delay) { - if (TransportBase* trans = creature->GetDirectTransport()) - trans->CalculatePassengerPosition(formationDest.x, formationDest.y, formationDest.z, &formationDest.orientation); + creature->ClearUnitState(UNIT_STATE_ROAMING_MOVE); + Stop(i_path->at(i_currentNode)->delay); } - - // Call for creature group update - if (creature->GetFormation() && creature->GetFormation()->getLeader() == creature) - creature->GetFormation()->LeaderMoveTo(formationDest.x, formationDest.y, formationDest.z); } bool WaypointMovementGenerator<Creature>::StartMove(Creature* creature) { - if (!creature || !creature->IsAlive()) + if (!i_path || i_path->empty()) return false; - if (!i_path || i_path->nodes.empty()) - return false; + if (Stopped()) + return true; if (Stopped()) return true; - bool transportPath = creature->GetTransport() != nullptr; + bool transportPath = creature->GetTransport() != NULL; - if (IsArrivalDone) + if (m_isArrivalDone) { - if ((i_currentNode == i_path->nodes.size() - 1) && !repeating) // If that's our last waypoint + if ((i_currentNode == i_path->size() - 1) && !repeating) // If that's our last waypoint { - WaypointNode const &waypoint = i_path->nodes.at(i_currentNode); - - float x = waypoint.x; - float y = waypoint.y; - float z = waypoint.z; + float x = i_path->at(i_currentNode)->x; + float y = i_path->at(i_currentNode)->y; + float z = i_path->at(i_currentNode)->z; float o = creature->GetOrientation(); if (!transportPath) @@ -151,45 +126,23 @@ bool WaypointMovementGenerator<Creature>::StartMove(Creature* creature) transportPath = false; // else if (vehicle) - this should never happen, vehicle offsets are const } + + creature->GetMotionMaster()->Initialize(); return false; } - i_currentNode = (i_currentNode + 1) % i_path->nodes.size(); + i_currentNode = (i_currentNode+1) % i_path->size(); } - float finalOrient = 0.0f; - uint8 finalMove = WAYPOINT_MOVE_TYPE_WALK; - - Movement::PointsArray pathing; - pathing.reserve((i_path->nodes.size() - i_currentNode) + 1); - - pathing.push_back(G3D::Vector3(creature->GetPositionX(), creature->GetPositionY(), creature->GetPositionZ())); - for (uint32 i = i_currentNode; i < i_path->nodes.size(); ++i) - { - WaypointNode const &waypoint = i_path->nodes.at(i); + WaypointData const* node = i_path->at(i_currentNode); - pathing.push_back(G3D::Vector3(waypoint.x, waypoint.y, waypoint.z)); - - finalOrient = waypoint.orientation; - finalMove = waypoint.moveType; - - if (waypoint.delay) - break; - } - - // if we have only 1 point, only current position, we shall return - if (pathing.size() < 2) - return false; - - IsArrivalDone = false; - i_recalculateSpeed = false; + m_isArrivalDone = false; creature->AddUnitState(UNIT_STATE_ROAMING_MOVE); + Movement::Location formationDest(node->x, node->y, node->z, 0.0f); Movement::MoveSplineInit init(creature); - Movement::Location formationDest(i_path->nodes.at(i_currentNode).x, i_path->nodes.at(i_currentNode).y, i_path->nodes.at(i_currentNode).z, 0.0f); - //! If creature is on transport, we assume waypoints set in DB are already transport offsets if (transportPath) { @@ -198,9 +151,15 @@ bool WaypointMovementGenerator<Creature>::StartMove(Creature* creature) trans->CalculatePassengerPosition(formationDest.x, formationDest.y, formationDest.z, &formationDest.orientation); } - init.MovebyPath(pathing, i_currentNode); + //! Do not use formationDest here, MoveTo requires transport offsets due to DisableTransportPathTransformations() call + //! but formationDest contains global coordinates + init.MoveTo(node->x, node->y, node->z); + + //! Accepts angles such as 0.00001 and -0.00001, 0 must be ignored, default value in waypoint table + if (node->orientation && node->delay) + init.SetFacing(node->orientation); - switch (finalMove) + switch (node->move_type) { case WAYPOINT_MOVE_TYPE_LAND: init.SetAnimation(Movement::ToGround); @@ -216,23 +175,20 @@ bool WaypointMovementGenerator<Creature>::StartMove(Creature* creature) break; } - if (finalOrient != 0.0f) - init.SetFacing(finalOrient); - init.Launch(); //Call for creature group update if (creature->GetFormation() && creature->GetFormation()->getLeader() == creature) + { + creature->SetWalk(node->move_type != WAYPOINT_MOVE_TYPE_RUN); creature->GetFormation()->LeaderMoveTo(formationDest.x, formationDest.y, formationDest.z); + } return true; } bool WaypointMovementGenerator<Creature>::DoUpdate(Creature* creature, uint32 diff) { - if (!creature || !creature->IsAlive()) - return false; - // Waypoint movement can be switched on/off // This is quite handy for escort quests and other stuff if (creature->HasUnitState(UNIT_STATE_NOT_MOVE)) @@ -240,15 +196,14 @@ bool WaypointMovementGenerator<Creature>::DoUpdate(Creature* creature, uint32 di creature->ClearUnitState(UNIT_STATE_ROAMING_MOVE); return true; } - // prevent a crash at empty waypoint path. - if (!i_path || i_path->nodes.empty()) + if (!i_path || i_path->empty()) return false; if (Stopped()) { if (CanMove(diff)) - return StartMoveNow(creature); + return StartMove(creature); } else { @@ -257,45 +212,15 @@ bool WaypointMovementGenerator<Creature>::DoUpdate(Creature* creature, uint32 di creature->SetHomePosition(creature->GetPosition()); if (creature->IsStopped()) - Stop(LoadedFromDB ? sWorld->getIntConfig(CONFIG_CREATURE_STOP_FOR_PLAYER) : 2 * HOUR * IN_MILLISECONDS); + Stop(sWorld->getIntConfig(CONFIG_CREATURE_STOP_FOR_PLAYER)); else if (creature->movespline->Finalized()) { OnArrived(creature); - - IsArrivalDone = true; - - if (!Stopped()) - { - if (creature->IsStopped()) - Stop(LoadedFromDB ? sWorld->getIntConfig(CONFIG_CREATURE_STOP_FOR_PLAYER) : 2 * HOUR * IN_MILLISECONDS); - else - return StartMove(creature); - } - } - else - { - // speed changed during path execution, calculate remaining path and launch it once more - if (i_recalculateSpeed) - { - i_recalculateSpeed = false; - - if (!Stopped()) - return StartMove(creature); - } - else - { - uint32 pointId = uint32(creature->movespline->currentPathIdx()); - if (pointId > i_currentNode) - { - OnArrived(creature); - i_currentNode = pointId; - FormationMove(creature); - } - } + return StartMove(creature); } } - return true; -} + return true; + } void WaypointMovementGenerator<Creature>::MovementInform(Creature* creature) { @@ -306,14 +231,11 @@ void WaypointMovementGenerator<Creature>::MovementInform(Creature* creature) bool WaypointMovementGenerator<Creature>::GetResetPos(Creature*, float& x, float& y, float& z) { // prevent a crash at empty waypoint path. - if (!i_path || i_path->nodes.empty()) + if (!i_path || i_path->empty()) return false; - WaypointNode const &waypoint = i_path->nodes.at(i_currentNode); - - x = waypoint.x; - y = waypoint.y; - z = waypoint.z; + const WaypointData* node = i_path->at(i_currentNode); + x = node->x; y = node->y; z = node->z; return true; } @@ -421,12 +343,12 @@ void FlightPathMovementGenerator::DoReset(Player* player) Movement::MoveSplineInit init(player); uint32 end = GetPathAtMapEnd(); - for (uint32 i = i_currentNode; i != end; ++i) + for (uint32 i = GetCurrentNode(); i != end; ++i) { G3D::Vector3 vertice(i_path[i]->Loc.X, i_path[i]->Loc.Y, i_path[i]->Loc.Z); init.Path().push_back(vertice); } - init.SetFirstPointId(i_currentNode); + init.SetFirstPointId(GetCurrentNode()); init.SetFly(); init.SetSmooth(); init.SetUncompressed(); diff --git a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.h b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.h index 7fcea212e9a..80422b15935 100755 --- a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.h +++ b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.h @@ -30,6 +30,7 @@ #include "DB2Stores.h" #include "Player.h" #include "Timer.h" +#include "WaypointManager.h" #define FLIGHT_TRAVEL_UPDATE 100 #define TIMEDIFF_NEXT_WP 250 @@ -57,16 +58,8 @@ class WaypointMovementGenerator<Creature> : public MovementGeneratorMedium< Crea { public: WaypointMovementGenerator(uint32 _path_id = 0, bool _repeating = true) - : i_nextMoveTime(0), IsArrivalDone(false), path_id(_path_id), repeating(_repeating), LoadedFromDB(true) { } - - WaypointMovementGenerator(WaypointPath& path, bool _repeating = true) - : i_nextMoveTime(0), IsArrivalDone(false), path_id(0), repeating(_repeating), LoadedFromDB(false) - { - i_path = &path; - } - - ~WaypointMovementGenerator() { i_path = nullptr; } - + : i_nextMoveTime(0), m_isArrivalDone(false), path_id(_path_id), repeating(_repeating) { } + ~WaypointMovementGenerator() { i_path = NULL; } void DoInitialize(Creature*); void DoFinalize(Creature*); void DoReset(Creature*); @@ -81,10 +74,6 @@ class WaypointMovementGenerator<Creature> : public MovementGeneratorMedium< Crea bool GetResetPos(Creature*, float& x, float& y, float& z); - TimeTrackerSmall & GetTrackerTimer() { return i_nextMoveTime; } - - void UnitSpeedChanged() { i_recalculateSpeed = true; } - private: void Stop(int32 time) { i_nextMoveTime.Reset(time);} @@ -99,21 +88,17 @@ class WaypointMovementGenerator<Creature> : public MovementGeneratorMedium< Crea void OnArrived(Creature*); bool StartMove(Creature*); - void FormationMove(Creature*); - bool StartMoveNow(Creature* creature) + void StartMoveNow(Creature* creature) { i_nextMoveTime.Reset(0); - return StartMove(creature); + StartMove(creature); } TimeTrackerSmall i_nextMoveTime; - bool i_recalculateSpeed; - - bool IsArrivalDone; + bool m_isArrivalDone; uint32 path_id; bool repeating; - bool LoadedFromDB; }; /** FlightPathMovementGenerator generates movement of the player for the paths diff --git a/src/server/game/Movement/Waypoints/WaypointManager.cpp b/src/server/game/Movement/Waypoints/WaypointManager.cpp index bf7eb0703ab..9ddf05fe85a 100644 --- a/src/server/game/Movement/Waypoints/WaypointManager.cpp +++ b/src/server/game/Movement/Waypoints/WaypointManager.cpp @@ -24,6 +24,19 @@ WaypointMgr::WaypointMgr() { } +WaypointMgr::~WaypointMgr() +{ + for (WaypointPathContainer::iterator itr = _waypointStore.begin(); itr != _waypointStore.end(); ++itr) + { + for (WaypointPath::const_iterator it = itr->second.begin(); it != itr->second.end(); ++it) + delete *it; + + itr->second.clear(); + } + + _waypointStore.clear(); +} + void WaypointMgr::Load() { uint32 oldMSTime = getMSTime(); @@ -42,6 +55,7 @@ void WaypointMgr::Load() do { Field* fields = result->Fetch(); + WaypointData* wp = new WaypointData(); uint32 pathId = fields[0].GetUInt32(); WaypointPath& path = _waypointStore[pathId]; @@ -54,25 +68,25 @@ void WaypointMgr::Load() Trinity::NormalizeMapCoord(x); Trinity::NormalizeMapCoord(y); - WaypointNode wp; - wp.id = fields[1].GetUInt32(); - wp.x = x; - wp.y = y; - wp.z = z; - wp.orientation = o; - wp.moveType = fields[6].GetUInt32(); + wp->id = fields[1].GetUInt32(); + wp->x = x; + wp->y = y; + wp->z = z; + wp->orientation = o; + wp->move_type = fields[6].GetUInt32(); - if (wp.moveType >= WAYPOINT_MOVE_TYPE_MAX) + if (wp->move_type >= WAYPOINT_MOVE_TYPE_MAX) { - TC_LOG_ERROR("sql.sql", "Waypoint %u in waypoint_data has invalid move_type, ignoring", wp.id); + TC_LOG_ERROR("sql.sql", "Waypoint %u in waypoint_data has invalid move_type, ignoring", wp->id); + delete wp; continue; } - wp.delay = fields[7].GetUInt32(); - wp.eventId = fields[8].GetUInt32(); - wp.eventChance = fields[9].GetInt16(); + wp->delay = fields[7].GetUInt32(); + wp->event_id = fields[8].GetUInt32(); + wp->event_chance = fields[9].GetInt16(); - path.nodes.push_back(std::move(wp)); + path.push_back(wp); ++count; } while (result->NextRow()); @@ -91,6 +105,9 @@ void WaypointMgr::ReloadPath(uint32 id) WaypointPathContainer::iterator itr = _waypointStore.find(id); if (itr != _waypointStore.end()) { + for (WaypointPath::const_iterator it = itr->second.begin(); it != itr->second.end(); ++it) + delete *it; + _waypointStore.erase(itr); } @@ -108,6 +125,7 @@ void WaypointMgr::ReloadPath(uint32 id) do { Field* fields = result->Fetch(); + WaypointData* wp = new WaypointData(); float x = fields[1].GetFloat(); float y = fields[2].GetFloat(); @@ -117,25 +135,25 @@ void WaypointMgr::ReloadPath(uint32 id) Trinity::NormalizeMapCoord(x); Trinity::NormalizeMapCoord(y); - WaypointNode wp; - wp.id = fields[0].GetUInt32(); - wp.x = x; - wp.y = y; - wp.z = z; - wp.orientation = o; - wp.moveType = fields[5].GetUInt32(); + wp->id = fields[0].GetUInt32(); + wp->x = x; + wp->y = y; + wp->z = z; + wp->orientation = o; + wp->move_type = fields[5].GetUInt32(); - if (wp.moveType >= WAYPOINT_MOVE_TYPE_MAX) + if (wp->move_type >= WAYPOINT_MOVE_TYPE_MAX) { - TC_LOG_ERROR("sql.sql", "Waypoint %u in waypoint_data has invalid move_type, ignoring", wp.id); + TC_LOG_ERROR("sql.sql", "Waypoint %u in waypoint_data has invalid move_type, ignoring", wp->id); + delete wp; continue; } - wp.delay = fields[6].GetUInt32(); - wp.eventId = fields[7].GetUInt32(); - wp.eventChance = fields[8].GetUInt8(); + wp->delay = fields[6].GetUInt32(); + wp->event_id = fields[7].GetUInt32(); + wp->event_chance = fields[8].GetUInt8(); - path.nodes.push_back(std::move(wp)); + path.push_back(wp); } while (result->NextRow()); diff --git a/src/server/game/Movement/Waypoints/WaypointManager.h b/src/server/game/Movement/Waypoints/WaypointManager.h index 33e7e650f9f..92867c9c692 100644 --- a/src/server/game/Movement/Waypoints/WaypointManager.h +++ b/src/server/game/Movement/Waypoints/WaypointManager.h @@ -20,9 +20,30 @@ #define TRINITY_WAYPOINTMANAGER_H #include "Define.h" -#include "WaypointDefines.h" +#include <vector> #include <unordered_map> +enum WaypointMoveType +{ + WAYPOINT_MOVE_TYPE_WALK, + WAYPOINT_MOVE_TYPE_RUN, + WAYPOINT_MOVE_TYPE_LAND, + WAYPOINT_MOVE_TYPE_TAKEOFF, + + WAYPOINT_MOVE_TYPE_MAX +}; + +struct WaypointData +{ + uint32 id; + float x, y, z, orientation; + uint32 delay; + uint32 event_id; + uint32 move_type; + uint8 event_chance; +}; + +typedef std::vector<WaypointData*> WaypointPath; typedef std::unordered_map<uint32, WaypointPath> WaypointPathContainer; class TC_GAME_API WaypointMgr @@ -43,14 +64,14 @@ class TC_GAME_API WaypointMgr if (itr != _waypointStore.end()) return &itr->second; - return nullptr; + return NULL; } private: WaypointMgr(); - ~WaypointMgr() { } + ~WaypointMgr(); - std::unordered_map<uint32, WaypointPath> _waypointStore; + WaypointPathContainer _waypointStore; }; #define sWaypointMgr WaypointMgr::instance() |
