Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
WaypointManager.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#include "DatabaseEnv.h"
7#include "GridDefines.h"
8#include "Log.h"
9#include "MapManager.h"
10#include "WaypointManager.h"
11
13
15{
16 for (WaypointPathContainer::iterator itr = _waypointStore.begin(); itr != _waypointStore.end(); ++itr)
17 {
18 for (WaypointPath::const_iterator it = itr->second.begin(); it != itr->second.end(); ++it)
19 delete* it;
20
21 itr->second.clear();
22 }
23
24 _waypointStore.clear();
25}
26
28{
29 uint32 oldMSTime = getMSTime();
30
31 // 0 1 2 3 4 5 6 7 8 9
32 QueryResult result = WorldDatabase.Query("SELECT id, point, position_x, position_y, position_z, orientation, move_flag, delay, action, action_chance FROM waypoint_data ORDER BY id, point");
33
34 if (!result)
35 {
36 SF_LOG_ERROR("server.loading", ">> Loaded 0 waypoints. DB table `waypoint_data` is empty!");
37 return;
38 }
39
40 uint32 count = 0;
41
42 do
43 {
44 Field* fields = result->Fetch();
45 WaypointData* wp = new WaypointData();
46
47 uint32 pathId = fields[0].GetUInt32();
48 WaypointPath& path = _waypointStore[pathId];
49
50 float x = fields[2].GetFloat();
51 float y = fields[3].GetFloat();
52 float z = fields[4].GetFloat();
53 float o = fields[5].GetFloat();
54
57
58 wp->id = fields[1].GetUInt32();
59 wp->x = x;
60 wp->y = y;
61 wp->z = z;
62 wp->orientation = o;
63 wp->run = fields[6].GetBool();
64 wp->delay = fields[7].GetUInt32();
65 wp->event_id = fields[8].GetUInt32();
66 wp->event_chance = fields[9].GetInt16();
67
68 path.push_back(wp);
69 ++count;
70 } while (result->NextRow());
71
72 SF_LOG_INFO("server.loading", ">> Loaded %u waypoints in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
73}
74
76{
77 WaypointPathContainer::iterator itr = _waypointStore.find(id);
78 if (itr != _waypointStore.end())
79 {
80 for (WaypointPath::const_iterator it = itr->second.begin(); it != itr->second.end(); ++it)
81 delete* it;
82
83 _waypointStore.erase(itr);
84 }
85
87
88 stmt->setUInt32(0, id);
89
90 PreparedQueryResult result = WorldDatabase.Query(stmt);
91
92 if (!result)
93 return;
94
95 WaypointPath& path = _waypointStore[id];
96
97 do
98 {
99 Field* fields = result->Fetch();
100 WaypointData* wp = new WaypointData();
101
102 float x = fields[1].GetFloat();
103 float y = fields[2].GetFloat();
104 float z = fields[3].GetFloat();
105 float o = fields[4].GetFloat();
106
109
110 wp->id = fields[0].GetUInt32();
111 wp->x = x;
112 wp->y = y;
113 wp->z = z;
114 wp->orientation = o;
115 wp->run = fields[5].GetBool();
116 wp->delay = fields[6].GetUInt32();
117 wp->event_id = fields[7].GetUInt32();
118 wp->event_chance = fields[8].GetUInt8();
119
120 path.push_back(wp);
121 } while (result->NextRow());
122}
std::uint32_t uint32
Definition Define.h:77
#define SF_LOG_ERROR(filterType__,...)
Definition Log.h:143
#define SF_LOG_INFO(filterType__,...)
Definition Log.h:137
Skyfire::AutoPtr< PreparedResultSet, Skyfire::Mutex > PreparedQueryResult
Definition QueryResult.h:94
Skyfire::AutoPtr< ResultSet, Skyfire::Mutex > QueryResult
Definition QueryResult.h:48
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition Timer.h:22
uint32 getMSTime()
Definition Timer.h:12
std::vector< WaypointData * > WaypointPath
@ WORLD_SEL_WAYPOINT_DATA_BY_ID
Definition Field.h:16
uint8 GetUInt8() const
Definition Field.h:26
int16 GetInt16() const
Definition Field.h:87
float GetFloat() const
Definition Field.h:177
bool GetBool() const
Definition Field.h:21
uint32 GetUInt32() const
Definition Field.h:105
void setUInt32(const uint8 index, const uint32 value)
void ReloadPath(uint32 id)
WaypointPathContainer _waypointStore
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition Main.cpp:40
void NormalizeMapCoord(float &c)