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

#include <SmartScriptMgr.h>

Public Member Functions

void LoadFromDB ()
 
WPPathGetPath (uint32 id)
 

Static Public Member Functions

static SmartWaypointMgrinstance ()
 

Private Member Functions

 SmartWaypointMgr ()
 
 ~SmartWaypointMgr ()
 

Private Attributes

std::unordered_map< uint32,
WPPath * > 
waypoint_map
 

Constructor & Destructor Documentation

SmartWaypointMgr::SmartWaypointMgr ( )
inlineprivate
1448 { }
SmartWaypointMgr::~SmartWaypointMgr ( )
private
98 {
99  for (std::unordered_map<uint32, WPPath*>::iterator itr = waypoint_map.begin(); itr != waypoint_map.end(); ++itr)
100  {
101  for (WPPath::iterator pathItr = itr->second->begin(); pathItr != itr->second->end(); ++pathItr)
102  delete pathItr->second;
103 
104  delete itr->second;
105  }
106 }
std::unordered_map< uint32, WPPath * > waypoint_map
Definition: SmartScriptMgr.h:1464

Member Function Documentation

WPPath* SmartWaypointMgr::GetPath ( uint32  id)
inline
1457  {
1458  if (waypoint_map.find(id) != waypoint_map.end())
1459  return waypoint_map[id];
1460  else return nullptr;
1461  }
std::unordered_map< uint32, WPPath * > waypoint_map
Definition: SmartScriptMgr.h:1464
SmartWaypointMgr * SmartWaypointMgr::instance ( )
static
32 {
34  return &instance;
35 }
Definition: SmartScriptMgr.h:1445
static SmartWaypointMgr * instance()
Definition: SmartScriptMgr.cpp:31
void SmartWaypointMgr::LoadFromDB ( )
38 {
39  uint32 oldMSTime = getMSTime();
40 
41  for (std::unordered_map<uint32, WPPath*>::iterator itr = waypoint_map.begin(); itr != waypoint_map.end(); ++itr)
42  {
43  for (WPPath::iterator pathItr = itr->second->begin(); pathItr != itr->second->end(); ++pathItr)
44  delete pathItr->second;
45 
46  delete itr->second;
47  }
48 
49  waypoint_map.clear();
50 
53 
54  if (!result)
55  {
56  TC_LOG_INFO("server.loading", ">> Loaded 0 SmartAI Waypoint Paths. DB table `waypoints` is empty.");
57 
58  return;
59  }
60 
61  uint32 count = 0;
62  uint32 total = 0;
63  uint32 last_entry = 0;
64  uint32 last_id = 1;
65 
66  do
67  {
68  Field* fields = result->Fetch();
69  uint32 entry = fields[0].GetUInt32();
70  uint32 id = fields[1].GetUInt32();
71  float x, y, z;
72  x = fields[2].GetFloat();
73  y = fields[3].GetFloat();
74  z = fields[4].GetFloat();
75 
76  if (last_entry != entry)
77  {
78  waypoint_map[entry] = new WPPath();
79  last_id = 1;
80  count++;
81  }
82 
83  if (last_id != id)
84  TC_LOG_ERROR("sql.sql", "SmartWaypointMgr::LoadFromDB: Path entry %u, unexpected point id %u, expected %u.", entry, id, last_id);
85 
86  last_id++;
87  (*waypoint_map[entry])[id] = new WayPoint(id, x, y, z);
88 
89  last_entry = entry;
90  total++;
91  }
92  while (result->NextRow());
93 
94  TC_LOG_INFO("server.loading", ">> Loaded %u SmartAI waypoint paths (total %u waypoints) in %u ms", count, total, GetMSTimeDiffToNow(oldMSTime));
95 }
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
float GetFloat() const
Definition: Field.h:222
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
Definition: WorldDatabase.h:37
Definition: PreparedStatement.h:74
Definition: SmartScriptMgr.h:31
std::unordered_map< uint32, WPPath * > waypoint_map
Definition: SmartScriptMgr.h:1464
G3D::int16 z
Definition: Vector3int16.h:46
uint32_t uint32
Definition: Define.h:150
G3D::int16 y
Definition: Vector2int16.h:38
std::unordered_map< uint32, WayPoint * > WPPath
Definition: SmartScriptMgr.h:1389
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
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
#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

+ Here is the call graph for this function:

Member Data Documentation

std::unordered_map<uint32, WPPath*> SmartWaypointMgr::waypoint_map
private

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