TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
WaypointMgr Class Reference

#include <WaypointManager.h>

Public Member Functions

void ReloadPath (uint32 id)
 
void Load ()
 
WaypointPath constGetPath (uint32 id) const
 

Static Public Member Functions

static WaypointMgrinstance ()
 

Private Member Functions

 WaypointMgr ()
 
 ~WaypointMgr ()
 

Private Attributes

WaypointPathContainer _waypointStore
 

Constructor & Destructor Documentation

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

Member Function Documentation

WaypointPath const* WaypointMgr::GetPath ( uint32  id) const
inline
60  {
61  WaypointPathContainer::const_iterator itr = _waypointStore.find(id);
62  if (itr != _waypointStore.end())
63  return &itr->second;
64 
65  return NULL;
66  }
arena_t NULL
Definition: jemalloc_internal.h:624
WaypointPathContainer _waypointStore
Definition: WaypointManager.h:72
WaypointMgr * WaypointMgr::instance ( )
static
98 {
99  static WaypointMgr instance;
100  return &instance;
101 }
Definition: WaypointManager.h:47
static WaypointMgr * instance()
Definition: WaypointManager.cpp:97
void WaypointMgr::Load ( )
41 {
42  uint32 oldMSTime = getMSTime();
43 
44  // 0 1 2 3 4 5 6 7 8 9
45  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");
46 
47  if (!result)
48  {
49  TC_LOG_ERROR("server.loading", ">> Loaded 0 waypoints. DB table `waypoint_data` is empty!");
50  return;
51  }
52 
53  uint32 count = 0;
54 
55  do
56  {
57  Field* fields = result->Fetch();
58  WaypointData* wp = new WaypointData();
59 
60  uint32 pathId = fields[0].GetUInt32();
61  WaypointPath& path = _waypointStore[pathId];
62 
63  float x = fields[2].GetFloat();
64  float y = fields[3].GetFloat();
65  float z = fields[4].GetFloat();
66  float o = fields[5].GetFloat();
67 
70 
71  wp->id = fields[1].GetUInt32();
72  wp->x = x;
73  wp->y = y;
74  wp->z = z;
75  wp->orientation = o;
76  wp->move_type = fields[6].GetUInt32();
77 
79  {
80  TC_LOG_ERROR("sql.sql", "Waypoint %u in waypoint_data has invalid move_type, ignoring", wp->id);
81  delete wp;
82  continue;
83  }
84 
85  wp->delay = fields[7].GetUInt32();
86  wp->event_id = fields[8].GetUInt32();
87  wp->event_chance = fields[9].GetInt16();
88 
89  path.push_back(wp);
90  ++count;
91  }
92  while (result->NextRow());
93 
94  TC_LOG_INFO("server.loading", ">> Loaded %u waypoints in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
95 }
uint32 event_id
Definition: WaypointManager.h:39
float x
Definition: WaypointManager.h:37
uint32 id
Definition: WaypointManager.h:36
float GetFloat() const
Definition: Field.h:222
float z
Definition: WaypointManager.h:37
Class used to access individual fields of database query result.
Definition: Field.h:56
uint32 getMSTime()
Definition: Timer.h:24
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
std::vector< WaypointData * > WaypointPath
Definition: WaypointManager.h:44
float orientation
Definition: WaypointManager.h:37
float y
Definition: WaypointManager.h:37
G3D::int16 z
Definition: Vector3int16.h:46
uint8 event_chance
Definition: WaypointManager.h:41
uint32_t uint32
Definition: Define.h:150
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
G3D::int16 y
Definition: Vector2int16.h:38
void NormalizeMapCoord(float &c)
Definition: GridDefines.h:210
int16 GetInt16() const
Definition: Field.h:127
uint32 move_type
Definition: WaypointManager.h:40
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:42
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
uint32 GetUInt32() const
Definition: Field.h:146
uint32 delay
Definition: WaypointManager.h:38
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:201
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
G3D::int16 x
Definition: Vector2int16.h:37
WaypointPathContainer _waypointStore
Definition: WaypointManager.h:72
Definition: WaypointManager.h:31
Definition: WaypointManager.h:34

+ Here is the call graph for this function:

void WaypointMgr::ReloadPath ( uint32  id)
104 {
105  WaypointPathContainer::iterator itr = _waypointStore.find(id);
106  if (itr != _waypointStore.end())
107  {
108  for (WaypointPath::const_iterator it = itr->second.begin(); it != itr->second.end(); ++it)
109  delete *it;
110 
111  _waypointStore.erase(itr);
112  }
113 
115 
116  stmt->setUInt32(0, id);
117 
118  PreparedQueryResult result = WorldDatabase.Query(stmt);
119 
120  if (!result)
121  return;
122 
123  WaypointPath& path = _waypointStore[id];
124 
125  do
126  {
127  Field* fields = result->Fetch();
128  WaypointData* wp = new WaypointData();
129 
130  float x = fields[1].GetFloat();
131  float y = fields[2].GetFloat();
132  float z = fields[3].GetFloat();
133  float o = fields[4].GetFloat();
134 
137 
138  wp->id = fields[0].GetUInt32();
139  wp->x = x;
140  wp->y = y;
141  wp->z = z;
142  wp->orientation = o;
143  wp->move_type = fields[5].GetUInt32();
144 
146  {
147  TC_LOG_ERROR("sql.sql", "Waypoint %u in waypoint_data has invalid move_type, ignoring", wp->id);
148  delete wp;
149  continue;
150  }
151 
152  wp->delay = fields[6].GetUInt32();
153  wp->event_id = fields[7].GetUInt32();
154  wp->event_chance = fields[8].GetUInt8();
155 
156  path.push_back(wp);
157 
158  }
159  while (result->NextRow());
160 }
uint32 event_id
Definition: WaypointManager.h:39
float x
Definition: WaypointManager.h:37
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
uint32 id
Definition: WaypointManager.h:36
float GetFloat() const
Definition: Field.h:222
float z
Definition: WaypointManager.h:37
Class used to access individual fields of database query result.
Definition: Field.h:56
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
std::vector< WaypointData * > WaypointPath
Definition: WaypointManager.h:44
float orientation
Definition: WaypointManager.h:37
Definition: PreparedStatement.h:74
float y
Definition: WaypointManager.h:37
uint8 GetUInt8() const
Definition: Field.h:70
Definition: WorldDatabase.h:61
G3D::int16 z
Definition: Vector3int16.h:46
uint8 event_chance
Definition: WaypointManager.h:41
G3D::int16 y
Definition: Vector2int16.h:38
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
void NormalizeMapCoord(float &c)
Definition: GridDefines.h:210
uint32 move_type
Definition: WaypointManager.h:40
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
uint32 GetUInt32() const
Definition: Field.h:146
uint32 delay
Definition: WaypointManager.h:38
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
G3D::int16 x
Definition: Vector2int16.h:37
WaypointPathContainer _waypointStore
Definition: WaypointManager.h:72
Definition: WaypointManager.h:31
Definition: WaypointManager.h:34

+ Here is the call graph for this function:

Member Data Documentation

WaypointPathContainer WaypointMgr::_waypointStore
private

The documentation for this class was generated from the following files: