diff options
| author | Shauren <shauren.trinity@gmail.com> | 2025-06-25 12:16:03 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2025-06-25 12:16:03 +0200 |
| commit | e284dc0a8025c5e4da65271914c88d9afac95667 (patch) | |
| tree | 225f9bd64fd7a6d37b2e3a5b02c7a088da998456 /src/server/game/Movement/Waypoints | |
| parent | 53f71a9838adf466783bde5240434961bf82f8ce (diff) | |
Core/Commands: Waypoint command fixes
* .wp add will now add data to waypoint_path table
* .wp reload will no longer crash the server
* Replace deprecated command handler arguments
Diffstat (limited to 'src/server/game/Movement/Waypoints')
| -rw-r--r-- | src/server/game/Movement/Waypoints/WaypointDefines.h | 17 | ||||
| -rw-r--r-- | src/server/game/Movement/Waypoints/WaypointManager.cpp | 59 | ||||
| -rw-r--r-- | src/server/game/Movement/Waypoints/WaypointManager.h | 7 |
3 files changed, 43 insertions, 40 deletions
diff --git a/src/server/game/Movement/Waypoints/WaypointDefines.h b/src/server/game/Movement/Waypoints/WaypointDefines.h index 68225a7e8b5..eb388481f71 100644 --- a/src/server/game/Movement/Waypoints/WaypointDefines.h +++ b/src/server/game/Movement/Waypoints/WaypointDefines.h @@ -51,15 +51,7 @@ struct WaypointNode { constexpr WaypointNode() : Id(0), X(0.f), Y(0.f), Z(0.f), MoveType(WaypointMoveType::Walk) { } constexpr WaypointNode(uint32 id, float x, float y, float z, Optional<float> orientation = { }, Optional<Milliseconds> delay = {}) - { - Id = id; - X = x; - Y = y; - Z = z; - Orientation = orientation; - Delay = delay; - MoveType = WaypointMoveType::Walk; - } + : Id(id), X(x), Y(y), Z(z), Orientation(orientation), Delay(delay), MoveType(WaypointMoveType::Walk) { } uint32 Id; float X; @@ -74,12 +66,7 @@ struct WaypointPath { WaypointPath() = default; WaypointPath(uint32 id, std::vector<WaypointNode>&& nodes, WaypointMoveType moveType = WaypointMoveType::Walk, WaypointPathFlags flags = WaypointPathFlags::None) - { - Id = id; - Nodes = std::move(nodes); - Flags = flags; - MoveType = moveType; - } + : Nodes(std::move(nodes)), Id(id), MoveType(moveType), Flags(flags) { } std::vector<WaypointNode> Nodes; std::vector<std::pair<std::size_t, std::size_t>> ContinuousSegments; diff --git a/src/server/game/Movement/Waypoints/WaypointManager.cpp b/src/server/game/Movement/Waypoints/WaypointManager.cpp index a1ccec0efcd..c1e8d4dde36 100644 --- a/src/server/game/Movement/Waypoints/WaypointManager.cpp +++ b/src/server/game/Movement/Waypoints/WaypointManager.cpp @@ -22,9 +22,13 @@ #include "MapUtils.h" #include "ObjectAccessor.h" #include "Optional.h" +#include "QueryResultStructured.h" #include "TemporarySummon.h" #include "Unit.h" +DEFINE_FIELD_ACCESSOR_CACHE(WaypointMgr::PathQueryResult, PreparedResultSet, (PathId)(MoveType)(Flags)(Velocity)); +DEFINE_FIELD_ACCESSOR_CACHE(WaypointMgr::PathNodeQueryResult, PreparedResultSet, (PathId)(NodeId)(PositionX)(PositionY)(PositionZ)(Orientation)(Delay)); + WaypointMgr::WaypointMgr() = default; WaypointMgr::~WaypointMgr() = default; @@ -41,8 +45,11 @@ void WaypointMgr::_LoadPaths() _pathStore.clear(); - // 0 1 2 3 - QueryResult result = WorldDatabase.Query("SELECT PathId, MoveType, Flags, Velocity FROM waypoint_path"); + WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_PATH); + stmt->setUInt32(0, 0); + stmt->setUInt32(1, 1); + + PreparedQueryResult result = WorldDatabase.Query(stmt); if (!result) { @@ -54,7 +61,7 @@ void WaypointMgr::_LoadPaths() do { - LoadPathFromDB(result->Fetch()); + LoadPathFromDB({ .Result = *result }); ++count; } while (result->NextRow()); @@ -64,8 +71,12 @@ void WaypointMgr::_LoadPaths() void WaypointMgr::_LoadPathNodes() { uint32 oldMSTime = getMSTime(); - // 0 1 2 3 4 5 6 - QueryResult result = WorldDatabase.Query("SELECT PathId, NodeId, PositionX, PositionY, PositionZ, Orientation, Delay FROM waypoint_path_node ORDER BY PathId, NodeId"); + + WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_PATH_NODE); + stmt->setUInt32(0, 0); + stmt->setUInt32(1, 1); + + PreparedQueryResult result = WorldDatabase.Query(stmt); if (!result) { @@ -77,7 +88,7 @@ void WaypointMgr::_LoadPathNodes() do { - LoadPathNodesFromDB(result->Fetch()); + LoadPathNodesFromDB({ .Result = *result }); ++count; } while (result->NextRow()); @@ -85,13 +96,13 @@ void WaypointMgr::_LoadPathNodes() TC_LOG_INFO("server.loading", ">> Loaded {} waypoint path nodes in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); } -void WaypointMgr::LoadPathFromDB(Field* fields) +void WaypointMgr::LoadPathFromDB(PathQueryResult const& fields) { - uint32 pathId = fields[0].GetUInt32(); + uint32 pathId = fields.PathId().GetUInt32(); WaypointPath& path = _pathStore[pathId]; - path.MoveType = WaypointMoveType(fields[1].GetUInt8()); + path.MoveType = WaypointMoveType(fields.MoveType().GetUInt8()); if (path.MoveType >= WaypointMoveType::Max) { TC_LOG_ERROR("sql.sql", "PathId {} in `waypoint_path` has invalid MoveType {}, ignoring", pathId, AsUnderlyingType(path.MoveType)); @@ -99,8 +110,8 @@ void WaypointMgr::LoadPathFromDB(Field* fields) } path.Id = pathId; - path.Flags = WaypointPathFlags(fields[2].GetUInt8()); - path.Velocity = fields[3].GetFloatOrNull(); + path.Flags = WaypointPathFlags(fields.Flags().GetUInt8()); + path.Velocity = fields.Velocity().GetFloatOrNull(); if (path.Velocity && *path.Velocity <= 0.0f) { @@ -111,9 +122,9 @@ void WaypointMgr::LoadPathFromDB(Field* fields) path.Nodes.clear(); } -void WaypointMgr::LoadPathNodesFromDB(Field* fields) +void WaypointMgr::LoadPathNodesFromDB(PathNodeQueryResult const& fields) { - uint32 pathId = fields[0].GetUInt32(); + uint32 pathId = fields.PathId().GetUInt32(); WaypointPath* path = Trinity::Containers::MapGetValuePtr(_pathStore, pathId); if (!path) @@ -122,19 +133,19 @@ void WaypointMgr::LoadPathNodesFromDB(Field* fields) return; } - float x = fields[2].GetFloat(); - float y = fields[3].GetFloat(); - float z = fields[4].GetFloat(); - Optional<float> o = fields[5].GetFloatOrNull(); + float x = fields.PositionX().GetFloat(); + float y = fields.PositionY().GetFloat(); + float z = fields.PositionZ().GetFloat(); + Optional<float> o = fields.Orientation().GetFloatOrNull(); Optional<Milliseconds> delay; - if (uint32 delayMs = fields[6].GetUInt32()) + if (uint32 delayMs = fields.Delay().GetUInt32()) delay.emplace(delayMs); Trinity::NormalizeMapCoord(x); Trinity::NormalizeMapCoord(y); - path->Nodes.emplace_back(fields[1].GetUInt32(), x, y, z, o, delay); + path->Nodes.emplace_back(fields.NodeId().GetUInt32(), x, y, z, o, delay); } void WaypointMgr::DoPostLoadingChecks() @@ -161,8 +172,9 @@ void WaypointMgr::ReloadPath(uint32 pathId) { // waypoint_path { - WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_PATH_BY_PATHID); + WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_PATH); stmt->setUInt32(0, pathId); + stmt->setUInt32(1, 0); PreparedQueryResult result = WorldDatabase.Query(stmt); @@ -174,14 +186,15 @@ void WaypointMgr::ReloadPath(uint32 pathId) do { - LoadPathFromDB(result->Fetch()); + LoadPathFromDB({ .Result = *result }); } while (result->NextRow()); } // waypoint_path_data { - WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_PATH_NODE_BY_PATHID); + WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_PATH_NODE); stmt->setUInt32(0, pathId); + stmt->setUInt32(1, 0); PreparedQueryResult result = WorldDatabase.Query(stmt); @@ -193,7 +206,7 @@ void WaypointMgr::ReloadPath(uint32 pathId) do { - LoadPathNodesFromDB(result->Fetch()); + LoadPathNodesFromDB({ .Result = *result }); } while (result->NextRow()); if (WaypointPath* path = Trinity::Containers::MapGetValuePtr(_pathStore, pathId)) diff --git a/src/server/game/Movement/Waypoints/WaypointManager.h b/src/server/game/Movement/Waypoints/WaypointManager.h index 31169de46a1..b7455507d5e 100644 --- a/src/server/game/Movement/Waypoints/WaypointManager.h +++ b/src/server/game/Movement/Waypoints/WaypointManager.h @@ -30,6 +30,9 @@ class Unit; class TC_GAME_API WaypointMgr { + struct PathQueryResult; + struct PathNodeQueryResult; + public: WaypointMgr(WaypointMgr const&) = delete; WaypointMgr(WaypointMgr&&) = delete; @@ -43,8 +46,8 @@ class TC_GAME_API WaypointMgr // Loads all paths from database, should only run on startup void LoadPaths(); - void LoadPathFromDB(Field* fields); - void LoadPathNodesFromDB(Field* fields); + void LoadPathFromDB(PathQueryResult const& fields); + void LoadPathNodesFromDB(PathNodeQueryResult const& fields); void DoPostLoadingChecks(); void VisualizePath(Unit* owner, WaypointPath const* path, Optional<uint32> displayId); |
