aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Movement/Waypoints
diff options
context:
space:
mode:
authorccrs <ccrs@users.noreply.github.com>2017-08-12 01:40:25 +0200
committerGitHub <noreply@github.com>2017-08-12 01:40:25 +0200
commit7fff83d67526efff63867d41b9e036a19a9287b3 (patch)
tree0462cb16ac0099318ab9ce07dc6cc099e141375e /src/server/game/Movement/Waypoints
parent00329fe9a505c437af0b7591d8321bf3b77ad7fb (diff)
Core/Movement: waypoint movement (#20121)
Following the work done in #19361 this is the cleanup and improvement of the related logic of waypoint management. Ref 28050f3 #18020 (taking the good parts and ignoring the incomplete work)
Diffstat (limited to 'src/server/game/Movement/Waypoints')
-rw-r--r--src/server/game/Movement/Waypoints/WaypointDefines.h71
-rw-r--r--src/server/game/Movement/Waypoints/WaypointManager.cpp99
-rw-r--r--src/server/game/Movement/Waypoints/WaypointManager.h38
3 files changed, 117 insertions, 91 deletions
diff --git a/src/server/game/Movement/Waypoints/WaypointDefines.h b/src/server/game/Movement/Waypoints/WaypointDefines.h
new file mode 100644
index 00000000000..dbb7a15fa5c
--- /dev/null
+++ b/src/server/game/Movement/Waypoints/WaypointDefines.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TRINITY_WAYPOINTDEFINES_H
+#define TRINITY_WAYPOINTDEFINES_H
+
+#include "Define.h"
+#include <vector>
+
+enum WaypointMoveType
+{
+ WAYPOINT_MOVE_TYPE_WALK,
+ WAYPOINT_MOVE_TYPE_RUN,
+ WAYPOINT_MOVE_TYPE_LAND,
+ WAYPOINT_MOVE_TYPE_TAKEOFF,
+
+ WAYPOINT_MOVE_TYPE_MAX
+};
+
+struct WaypointNode
+{
+ WaypointNode() : id(0), x(0.f), y(0.f), z(0.f), orientation(0.f), delay(0), eventId(0), moveType(WAYPOINT_MOVE_TYPE_RUN), eventChance(0) { }
+ WaypointNode(uint32 _id, float _x, float _y, float _z, float _orientation = 0.f, uint32 _delay = 0)
+ {
+ id = _id;
+ x = _x;
+ y = _y;
+ z = _z;
+ orientation = _orientation;
+ delay = _delay;
+ eventId = 0;
+ moveType = WAYPOINT_MOVE_TYPE_WALK;
+ eventChance = 100;
+ }
+
+ uint32 id;
+ float x, y, z, orientation;
+ uint32 delay;
+ uint32 eventId;
+ uint32 moveType;
+ uint8 eventChance;
+};
+
+struct WaypointPath
+{
+ WaypointPath() : id(0) { }
+ WaypointPath(uint32 _id, std::vector<WaypointNode>&& _nodes)
+ {
+ id = _id;
+ nodes = _nodes;
+ }
+
+ std::vector<WaypointNode> nodes;
+ uint32 id;
+};
+
+#endif
diff --git a/src/server/game/Movement/Waypoints/WaypointManager.cpp b/src/server/game/Movement/Waypoints/WaypointManager.cpp
index 76c6228d302..3112459245f 100644
--- a/src/server/game/Movement/Waypoints/WaypointManager.cpp
+++ b/src/server/game/Movement/Waypoints/WaypointManager.cpp
@@ -16,27 +16,12 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "WaypointManager.h"
#include "DatabaseEnv.h"
#include "GridDefines.h"
-#include "WaypointManager.h"
#include "MapManager.h"
#include "Log.h"
-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();
@@ -55,11 +40,7 @@ void WaypointMgr::Load()
do
{
Field* fields = result->Fetch();
- WaypointData* wp = new WaypointData();
-
uint32 pathId = fields[0].GetUInt32();
- WaypointPath& path = _waypointStore[pathId];
-
float x = fields[2].GetFloat();
float y = fields[3].GetFloat();
float z = fields[4].GetFloat();
@@ -68,25 +49,27 @@ void WaypointMgr::Load()
Trinity::NormalizeMapCoord(x);
Trinity::NormalizeMapCoord(y);
- wp->id = fields[1].GetUInt32();
- wp->x = x;
- wp->y = y;
- wp->z = z;
- wp->orientation = o;
- wp->move_type = fields[6].GetUInt32();
+ WaypointNode waypoint;
+ waypoint.id = fields[1].GetUInt32();
+ waypoint.x = x;
+ waypoint.y = y;
+ waypoint.z = z;
+ waypoint.orientation = o;
+ waypoint.moveType = fields[6].GetUInt32();
- if (wp->move_type >= WAYPOINT_MOVE_TYPE_MAX)
+ if (waypoint.moveType >= WAYPOINT_MOVE_TYPE_MAX)
{
- TC_LOG_ERROR("sql.sql", "Waypoint %u in waypoint_data has invalid move_type, ignoring", wp->id);
- delete wp;
+ TC_LOG_ERROR("sql.sql", "Waypoint %u in waypoint_data has invalid move_type, ignoring", waypoint.id);
continue;
}
- wp->delay = fields[7].GetUInt32();
- wp->event_id = fields[8].GetUInt32();
- wp->event_chance = fields[9].GetInt16();
+ waypoint.delay = fields[7].GetUInt32();
+ waypoint.eventId = fields[8].GetUInt32();
+ waypoint.eventChance = fields[9].GetInt16();
- path.push_back(wp);
+ WaypointPath& path = _waypointStore[pathId];
+ path.id = pathId;
+ path.nodes.push_back(std::move(waypoint));
++count;
}
while (result->NextRow());
@@ -102,14 +85,9 @@ WaypointMgr* WaypointMgr::instance()
void WaypointMgr::ReloadPath(uint32 id)
{
- WaypointPathContainer::iterator itr = _waypointStore.find(id);
+ auto 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);
- }
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_DATA_BY_ID);
@@ -120,13 +98,10 @@ void WaypointMgr::ReloadPath(uint32 id)
if (!result)
return;
- WaypointPath& path = _waypointStore[id];
-
+ std::vector<WaypointNode> values;
do
{
Field* fields = result->Fetch();
- WaypointData* wp = new WaypointData();
-
float x = fields[1].GetFloat();
float y = fields[2].GetFloat();
float z = fields[3].GetFloat();
@@ -135,26 +110,36 @@ void WaypointMgr::ReloadPath(uint32 id)
Trinity::NormalizeMapCoord(x);
Trinity::NormalizeMapCoord(y);
- wp->id = fields[0].GetUInt32();
- wp->x = x;
- wp->y = y;
- wp->z = z;
- wp->orientation = o;
- wp->move_type = fields[5].GetUInt32();
+ WaypointNode waypoint;
+ waypoint.id = fields[0].GetUInt32();
+ waypoint.x = x;
+ waypoint.y = y;
+ waypoint.z = z;
+ waypoint.orientation = o;
+ waypoint.moveType = fields[5].GetUInt32();
- if (wp->move_type >= WAYPOINT_MOVE_TYPE_MAX)
+ if (waypoint.moveType >= WAYPOINT_MOVE_TYPE_MAX)
{
- TC_LOG_ERROR("sql.sql", "Waypoint %u in waypoint_data has invalid move_type, ignoring", wp->id);
- delete wp;
+ TC_LOG_ERROR("sql.sql", "Waypoint %u in waypoint_data has invalid move_type, ignoring", waypoint.id);
continue;
}
- wp->delay = fields[6].GetUInt32();
- wp->event_id = fields[7].GetUInt32();
- wp->event_chance = fields[8].GetUInt8();
-
- path.push_back(wp);
+ waypoint.delay = fields[6].GetUInt32();
+ waypoint.eventId = fields[7].GetUInt32();
+ waypoint.eventChance = fields[8].GetUInt8();
+ values.push_back(std::move(waypoint));
}
while (result->NextRow());
+
+ _waypointStore[id] = WaypointPath(id, std::move(values));
+}
+
+WaypointPath const* WaypointMgr::GetPath(uint32 id) const
+{
+ auto itr = _waypointStore.find(id);
+ if (itr != _waypointStore.end())
+ return &itr->second;
+
+ return nullptr;
}
diff --git a/src/server/game/Movement/Waypoints/WaypointManager.h b/src/server/game/Movement/Waypoints/WaypointManager.h
index f62805594ef..769e45432e7 100644
--- a/src/server/game/Movement/Waypoints/WaypointManager.h
+++ b/src/server/game/Movement/Waypoints/WaypointManager.h
@@ -20,32 +20,10 @@
#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
{
public:
@@ -58,20 +36,12 @@ class TC_GAME_API WaypointMgr
void Load();
// Returns the path from a given id
- WaypointPath const* GetPath(uint32 id) const
- {
- WaypointPathContainer::const_iterator itr = _waypointStore.find(id);
- if (itr != _waypointStore.end())
- return &itr->second;
-
- return nullptr;
- }
+ WaypointPath const* GetPath(uint32 id) const;
private:
- WaypointMgr();
- ~WaypointMgr();
+ WaypointMgr() { }
- WaypointPathContainer _waypointStore;
+ std::unordered_map<uint32, WaypointPath> _waypointStore;
};
#define sWaypointMgr WaypointMgr::instance()