AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
WaypointMgr Class Reference

#include "WaypointMgr.h"

Public Member Functions

void ReloadPath (uint32 id)
 
void Load ()
 
WaypointPath const * GetPath (uint32 id) const
 

Static Public Member Functions

static WaypointMgrinstance ()
 

Private Member Functions

 WaypointMgr ()
 
 ~WaypointMgr ()
 

Private Attributes

WaypointPathContainer _waypointStore
 

Detailed Description

Constructor & Destructor Documentation

◆ WaypointMgr()

WaypointMgr::WaypointMgr ( )
private
25{
26}

◆ ~WaypointMgr()

WaypointMgr::~WaypointMgr ( )
private
29{
30 for (WaypointPathContainer::iterator itr = _waypointStore.begin(); itr != _waypointStore.end(); ++itr)
31 {
32 for (WaypointPath::const_iterator it = itr->second.begin(); it != itr->second.end(); ++it)
33 delete *it;
34
35 itr->second.clear();
36 }
37
38 _waypointStore.clear();
39}
WaypointPathContainer _waypointStore
Definition: WaypointMgr.h:75

References _waypointStore.

Member Function Documentation

◆ GetPath()

WaypointPath const * WaypointMgr::GetPath ( uint32  id) const
inline
63 {
64 WaypointPathContainer::const_iterator itr = _waypointStore.find(id);
65 if (itr != _waypointStore.end())
66 return &itr->second;
67
68 return nullptr;
69 }

References _waypointStore.

◆ instance()

WaypointMgr * WaypointMgr::instance ( )
static
42{
43 static WaypointMgr instance;
44 return &instance;
45}
Definition: WaypointMgr.h:51
static WaypointMgr * instance()
Definition: WaypointMgr.cpp:41

References instance().

Referenced by instance().

◆ Load()

void WaypointMgr::Load ( )
48{
49 uint32 oldMSTime = getMSTime();
50
51 // 0 1 2 3 4 5 6 7 8 9
52 QueryResult result = WorldDatabase.Query("SELECT id, point, position_x, position_y, position_z, orientation, move_type, delay, action, action_chance FROM waypoint_data ORDER BY id, point");
53
54 if (!result)
55 {
56 LOG_WARN("server.loading", ">> Loaded 0 waypoints. DB table `waypoint_data` is empty!");
57 LOG_INFO("server.loading", " ");
58 return;
59 }
60
61 uint32 count = 0;
62
63 do
64 {
65 Field* fields = result->Fetch();
66 WaypointData* wp = new WaypointData();
67
68 uint32 pathId = fields[0].Get<uint32>();
69 WaypointPath& path = _waypointStore[pathId];
70
71 float x = fields[2].Get<float>();
72 float y = fields[3].Get<float>();
73 float z = fields[4].Get<float>();
74 std::optional<float > o;
75 if (!fields[5].IsNull())
76 o = fields[5].Get<float>();
77
80
81 wp->id = fields[1].Get<uint32>();
82 wp->x = x;
83 wp->y = y;
84 wp->z = z;
85 wp->orientation = o;
86 wp->move_type = fields[6].Get<uint32>();
87
89 {
90 //LOG_ERROR("sql.sql", "Waypoint {} in waypoint_data has invalid move_type, ignoring", wp->id);
91 delete wp;
92 continue;
93 }
94
95 wp->delay = fields[7].Get<uint32>();
96 wp->event_id = fields[8].Get<uint32>();
97 wp->event_chance = fields[9].Get<int16>();
98
99 path.push_back(wp);
100 ++count;
101 } while (result->NextRow());
102
103 LOG_INFO("server.loading", ">> Loaded {} waypoints in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
104 LOG_INFO("server.loading", " ");
105}
#define LOG_INFO(filterType__,...)
Definition: Log.h:165
#define LOG_WARN(filterType__,...)
Definition: Log.h:161
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:131
uint32 getMSTime()
Definition: Timer.h:103
std::uint32_t uint32
Definition: Define.h:107
std::int16_t int16
Definition: Define.h:104
std::vector< WaypointData * > WaypointPath
Definition: WaypointMgr.h:47
@ WAYPOINT_MOVE_TYPE_MAX
Definition: WaypointMgr.h:33
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:27
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
void NormalizeMapCoord(float &c)
Definition: GridDefines.h:207
Class used to access individual fields of database query result.
Definition: Field.h:98
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:112
Definition: WaypointMgr.h:37
float z
Definition: WaypointMgr.h:39
uint32 event_id
Definition: WaypointMgr.h:42
float x
Definition: WaypointMgr.h:39
float y
Definition: WaypointMgr.h:39
std::optional< float > orientation
Definition: WaypointMgr.h:40
uint32 delay
Definition: WaypointMgr.h:41
uint8 event_chance
Definition: WaypointMgr.h:44
uint32 id
Definition: WaypointMgr.h:38
uint32 move_type
Definition: WaypointMgr.h:43

References _waypointStore, WaypointData::delay, WaypointData::event_chance, WaypointData::event_id, Field::Get(), getMSTime(), GetMSTimeDiffToNow(), WaypointData::id, LOG_INFO, LOG_WARN, WaypointData::move_type, Acore::NormalizeMapCoord(), WaypointData::orientation, WAYPOINT_MOVE_TYPE_MAX, WorldDatabase, WaypointData::x, WaypointData::y, and WaypointData::z.

◆ ReloadPath()

void WaypointMgr::ReloadPath ( uint32  id)
108{
109 WaypointPathContainer::iterator itr = _waypointStore.find(id);
110 if (itr != _waypointStore.end())
111 {
112 for (WaypointPath::const_iterator it = itr->second.begin(); it != itr->second.end(); ++it)
113 delete *it;
114
115 _waypointStore.erase(itr);
116 }
117
119
120 stmt->SetData(0, id);
121
122 PreparedQueryResult result = WorldDatabase.Query(stmt);
123
124 if (!result)
125 return;
126
127 WaypointPath& path = _waypointStore[id];
128
129 do
130 {
131 Field* fields = result->Fetch();
132 WaypointData* wp = new WaypointData();
133
134 float x = fields[1].Get<float>();
135 float y = fields[2].Get<float>();
136 float z = fields[3].Get<float>();
137 std::optional<float> o;
138 if (!fields[4].IsNull())
139 o = fields[4].Get<float>();
140
143
144 wp->id = fields[0].Get<uint32>();
145 wp->x = x;
146 wp->y = y;
147 wp->z = z;
148 wp->orientation = o;
149 wp->move_type = fields[5].Get<uint32>();
150
152 {
153 //LOG_ERROR("sql.sql", "Waypoint {} in waypoint_data has invalid move_type, ignoring", wp->id);
154 delete wp;
155 continue;
156 }
157
158 wp->delay = fields[6].Get<uint32>();
159 wp->event_id = fields[7].Get<uint32>();
160 wp->event_chance = fields[8].Get<uint8>();
161
162 path.push_back(wp);
163 } while (result->NextRow());
164}
std::uint8_t uint8
Definition: Define.h:109
@ WORLD_SEL_WAYPOINT_DATA_BY_ID
Definition: WorldDatabase.h:60
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: DatabaseEnvFwd.h:45
Definition: PreparedStatement.h:157
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition: PreparedStatement.h:77

References _waypointStore, WaypointData::delay, WaypointData::event_chance, WaypointData::event_id, Field::Get(), WaypointData::id, WaypointData::move_type, Acore::NormalizeMapCoord(), WaypointData::orientation, PreparedStatementBase::SetData(), WAYPOINT_MOVE_TYPE_MAX, WORLD_SEL_WAYPOINT_DATA_BY_ID, WorldDatabase, WaypointData::x, WaypointData::y, and WaypointData::z.

Member Data Documentation

◆ _waypointStore

WaypointPathContainer WaypointMgr::_waypointStore
private