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

#include "SmartScriptMgr.h"

Public Member Functions

 ~SmartWaypointMgr ()
 
void LoadFromDB ()
 
WPPathGetPath (uint32 id)
 

Static Public Member Functions

static SmartWaypointMgrinstance ()
 

Private Member Functions

 SmartWaypointMgr ()
 

Private Attributes

std::unordered_map< uint32, WPPath * > waypoint_map
 

Detailed Description

Constructor & Destructor Documentation

◆ SmartWaypointMgr()

SmartWaypointMgr::SmartWaypointMgr ( )
inlineprivate
1955{}

◆ ~SmartWaypointMgr()

SmartWaypointMgr::~SmartWaypointMgr ( )
112{
113 for (std::unordered_map<uint32, WPPath*>::iterator itr = waypoint_map.begin(); itr != waypoint_map.end(); ++itr)
114 {
115 for (WPPath::iterator pathItr = itr->second->begin(); pathItr != itr->second->end(); ++pathItr)
116 delete pathItr->second;
117
118 delete itr->second;
119 }
120}
std::unordered_map< uint32, WPPath * > waypoint_map
Definition: SmartScriptMgr.h:1971

References waypoint_map.

Member Function Documentation

◆ GetPath()

WPPath * SmartWaypointMgr::GetPath ( uint32  id)
inline
1964 {
1965 if (waypoint_map.find(id) != waypoint_map.end())
1966 return waypoint_map[id];
1967 else return 0;
1968 }

References waypoint_map.

◆ instance()

SmartWaypointMgr * SmartWaypointMgr::instance ( )
static
43{
45 return &instance;
46}
Definition: SmartScriptMgr.h:1954
static SmartWaypointMgr * instance()
Definition: SmartScriptMgr.cpp:42

References instance().

Referenced by instance().

◆ LoadFromDB()

void SmartWaypointMgr::LoadFromDB ( )
49{
50 uint32 oldMSTime = getMSTime();
51
52 for (std::unordered_map<uint32, WPPath*>::iterator itr = waypoint_map.begin(); itr != waypoint_map.end(); ++itr)
53 {
54 for (WPPath::iterator pathItr = itr->second->begin(); pathItr != itr->second->end(); ++pathItr)
55 delete pathItr->second;
56
57 delete itr->second;
58 }
59
60 waypoint_map.clear();
61
63 PreparedQueryResult result = WorldDatabase.Query(stmt);
64
65 if (!result)
66 {
67 LOG_WARN("server.loading", ">> Loaded 0 SmartAI Waypoint Paths. DB table `waypoints` is empty.");
68 LOG_INFO("server.loading", " ");
69 return;
70 }
71
72 uint32 count = 0;
73 uint32 total = 0;
74 uint32 last_entry = 0;
75 uint32 last_id = 1;
76
77 do
78 {
79 Field* fields = result->Fetch();
80 uint32 entry = fields[0].Get<uint32>();
81 uint32 id = fields[1].Get<uint32>();
82 float x = fields[2].Get<float>();
83 float y = fields[3].Get<float>();
84 float z = fields[4].Get<float>();
86 if (!fields[5].IsNull())
87 o = fields[5].Get<float>();
88 uint32 delay = fields[6].Get<uint32>();
89
90 if (last_entry != entry)
91 {
92 waypoint_map[entry] = new WPPath();
93 last_id = 1;
94 count++;
95 }
96
97 if (last_id != id)
98 LOG_ERROR("sql.sql", "SmartWaypointMgr::LoadFromDB: Path entry {}, unexpected point id {}, expected {}.", entry, id, last_id);
99
100 last_id++;
101 (*waypoint_map[entry])[id] = new WayPoint(id, x, y, z, o, delay);
102
103 last_entry = entry;
104 total++;
105 } while (result->NextRow());
106
107 LOG_INFO("server.loading", ">> Loaded {} SmartAI waypoint paths (total {} waypoints) in {} ms", count, total, GetMSTimeDiffToNow(oldMSTime));
108 LOG_INFO("server.loading", " ");
109}
std::uint32_t uint32
Definition: Define.h:108
#define LOG_INFO(filterType__,...)
Definition: Log.h:167
#define LOG_ERROR(filterType__,...)
Definition: Log.h:159
#define LOG_WARN(filterType__,...)
Definition: Log.h:163
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:24
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:131
uint32 getMSTime()
Definition: Timer.h:103
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: DatabaseEnvFwd.h:50
@ WORLD_SEL_SMARTAI_WP
Definition: WorldDatabase.h:36
std::unordered_map< uint32, WayPoint * > WPPath
Definition: SmartScriptMgr.h:1914
Definition: PreparedStatement.h:158
Class used to access individual fields of database query result.
Definition: Field.h:99
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:113
Definition: SmartScriptMgr.h:33

References Field::Get(), getMSTime(), GetMSTimeDiffToNow(), LOG_ERROR, LOG_INFO, LOG_WARN, waypoint_map, WORLD_SEL_SMARTAI_WP, and WorldDatabase.

Member Data Documentation

◆ waypoint_map

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