Convert zone points from old style linked list to std

This commit is contained in:
KimLS 2022-02-14 00:53:56 -08:00
parent 1d4438ae1f
commit 296d48993e
6 changed files with 26 additions and 52 deletions

View File

@ -6178,16 +6178,10 @@ void Client::MarkSingleCompassLoc(float in_x, float in_y, float in_z, uint8 coun
void Client::SendZonePoints() void Client::SendZonePoints()
{ {
int count = 0; int count = 0;
LinkedListIterator<ZonePoint *> iterator(zone->zone_point_list); for (auto& data : zone->zone_point_list) {
iterator.Reset();
while (iterator.MoreElements()) {
ZonePoint *data = iterator.GetData();
if (ClientVersionBit() & data->client_version_mask) { if (ClientVersionBit() & data->client_version_mask) {
count++; count++;
} }
iterator.Advance();
} }
uint32 zpsize = sizeof(ZonePoints) + ((count + 1) * sizeof(ZonePoint_Entry)); uint32 zpsize = sizeof(ZonePoints) + ((count + 1) * sizeof(ZonePoint_Entry));
@ -6196,11 +6190,7 @@ void Client::SendZonePoints()
zp->count = count; zp->count = count;
int i = 0; int i = 0;
iterator.Reset(); for (auto& data : zone->zone_point_list) {
while(iterator.MoreElements())
{
ZonePoint* data = iterator.GetData();
LogZonePoints( LogZonePoints(
"Sending zone point to client [{}] mask [{}] x [{}] y [{}] z [{}] number [{}]", "Sending zone point to client [{}] mask [{}] x [{}] y [{}] z [{}] number [{}]",
GetCleanName(), GetCleanName(),
@ -6222,7 +6212,6 @@ void Client::SendZonePoints()
zp->zpe[i].zoneinstance = data->target_zone_instance; zp->zpe[i].zoneinstance = data->target_zone_instance;
i++; i++;
} }
iterator.Advance();
} }
FastQueuePacket(&outapp); FastQueuePacket(&outapp);

View File

@ -2,7 +2,7 @@
void command_reloadzps(Client *c, const Seperator *sep) void command_reloadzps(Client *c, const Seperator *sep)
{ {
content_db.LoadStaticZonePoints(&zone->zone_point_list, zone->GetShortName(), zone->GetInstanceVersion()); content_db.LoadStaticZonePoints(zone->zone_point_list, zone->GetShortName(), zone->GetInstanceVersion());
c->Message(Chat::White, "Reloading server zone_points."); c->Message(Chat::White, "Reloading server zone_points.");
} }

View File

@ -108,10 +108,7 @@ void command_showzonepoints(Client *c, const Seperator *sep)
found_zone_points++; found_zone_points++;
} }
LinkedListIterator<ZonePoint *> iterator(zone->zone_point_list); for (auto& zone_point : zone->zone_point_list) {
iterator.Reset();
while (iterator.MoreElements()) {
ZonePoint *zone_point = iterator.GetData();
std::string zone_long_name = ZoneLongName(zone_point->target_zone_id); std::string zone_long_name = ZoneLongName(zone_point->target_zone_id);
std::string node_name = fmt::format("ZonePoint To [{}]", zone_long_name); std::string node_name = fmt::format("ZonePoint To [{}]", zone_long_name);
@ -142,8 +139,6 @@ void command_showzonepoints(Client *c, const Seperator *sep)
).c_str() ).c_str()
); );
iterator.Advance();
found_zone_points++; found_zone_points++;
} }

View File

@ -1061,7 +1061,7 @@ Zone::~Zone() {
safe_delete_array(long_name); safe_delete_array(long_name);
safe_delete(Weather_Timer); safe_delete(Weather_Timer);
NPCEmoteList.Clear(); NPCEmoteList.Clear();
zone_point_list.Clear(); zone_point_list.clear();
entity_list.Clear(); entity_list.Clear();
ClearBlockedSpells(); ClearBlockedSpells();
@ -1103,7 +1103,7 @@ bool Zone::Init(bool iStaticZone) {
} }
LogInfo("Loading static zone points"); LogInfo("Loading static zone points");
if (!content_db.LoadStaticZonePoints(&zone_point_list, short_name, GetInstanceVersion())) { if (!content_db.LoadStaticZonePoints(zone_point_list, short_name, GetInstanceVersion())) {
LogError("Loading static zone points failed"); LogError("Loading static zone points failed");
return false; return false;
} }
@ -1213,8 +1213,8 @@ void Zone::ReloadStaticData() {
LogInfo("Reloading Zone Static Data"); LogInfo("Reloading Zone Static Data");
LogInfo("Reloading static zone points"); LogInfo("Reloading static zone points");
zone_point_list.Clear(); zone_point_list.clear();
if (!content_db.LoadStaticZonePoints(&zone_point_list, GetShortName(), GetInstanceVersion())) { if (!content_db.LoadStaticZonePoints(zone_point_list, GetShortName(), GetInstanceVersion())) {
LogError("Loading static zone points failed"); LogError("Loading static zone points failed");
} }
@ -1884,17 +1884,12 @@ void Zone::SetTime(uint8 hour, uint8 minute, bool update_world /*= true*/)
} }
ZonePoint* Zone::GetClosestZonePoint(const glm::vec3& location, uint32 to, Client* client, float max_distance) { ZonePoint* Zone::GetClosestZonePoint(const glm::vec3& location, uint32 to, Client* client, float max_distance) {
LinkedListIterator<ZonePoint*> iterator(zone_point_list);
ZonePoint* closest_zp = nullptr; ZonePoint* closest_zp = nullptr;
float closest_dist = FLT_MAX; float closest_dist = FLT_MAX;
float max_distance2 = max_distance * max_distance; float max_distance2 = max_distance * max_distance;
iterator.Reset(); for (auto& zp : zone_point_list) {
while(iterator.MoreElements())
{
ZonePoint* zp = iterator.GetData();
uint32 mask_test = client->ClientVersionBit(); uint32 mask_test = client->ClientVersionBit();
if (!(zp->client_version_mask & mask_test)) { if (!(zp->client_version_mask & mask_test)) {
iterator.Advance();
continue; continue;
} }
@ -1906,11 +1901,10 @@ ZonePoint* Zone::GetClosestZonePoint(const glm::vec3& location, uint32 to, Clien
if (dist < closest_dist) if (dist < closest_dist)
{ {
closest_zp = zp; closest_zp = zp.get();
closest_dist = dist; closest_dist = dist;
} }
} }
iterator.Advance();
} }
// if we have a water map and it says we're in a zoneline, lets assume it's just a really big zone line // if we have a water map and it says we're in a zoneline, lets assume it's just a really big zone line
@ -1942,19 +1936,15 @@ ZonePoint* Zone::GetClosestZonePoint(const glm::vec3& location, const char* to_n
} }
ZonePoint* Zone::GetClosestZonePointWithoutZone(float x, float y, float z, Client* client, float max_distance) { ZonePoint* Zone::GetClosestZonePointWithoutZone(float x, float y, float z, Client* client, float max_distance) {
LinkedListIterator<ZonePoint*> iterator(zone_point_list);
ZonePoint* closest_zp = nullptr; ZonePoint* closest_zp = nullptr;
float closest_dist = FLT_MAX; float closest_dist = FLT_MAX;
float max_distance2 = max_distance*max_distance; float max_distance2 = max_distance*max_distance;
iterator.Reset();
while(iterator.MoreElements()) for (auto& zp : zone_point_list) {
{
ZonePoint* zp = iterator.GetData();
uint32 mask_test = client->ClientVersionBit(); uint32 mask_test = client->ClientVersionBit();
if(!(zp->client_version_mask & mask_test)) if (!(zp->client_version_mask & mask_test))
{ {
iterator.Advance();
continue; continue;
} }
@ -1965,23 +1955,23 @@ ZonePoint* Zone::GetClosestZonePointWithoutZone(float x, float y, float z, Clien
if(zp->y == 999999 || zp->y == -999999) if(zp->y == 999999 || zp->y == -999999)
delta_y = 0; delta_y = 0;
float dist = delta_x*delta_x+delta_y*delta_y;///*+(zp->z-z)*(zp->z-z)*/; float dist = delta_x*delta_x+delta_y*delta_y;
if (dist < closest_dist) if (dist < closest_dist)
{ {
closest_zp = zp; closest_zp = zp.get();
closest_dist = dist; closest_dist = dist;
} }
iterator.Advance();
} }
if(closest_dist > max_distance2) if(closest_dist > max_distance2)
closest_zp = nullptr; closest_zp = nullptr;
return closest_zp; return closest_zp;
} }
bool ZoneDatabase::LoadStaticZonePoints(LinkedList<ZonePoint *> *zone_point_list, const char *zonename, uint32 version) bool ZoneDatabase::LoadStaticZonePoints(std::list<std::unique_ptr<ZonePoint>> &zone_point_list, const char *zonename, uint32 version)
{ {
zone_point_list->Clear(); zone_point_list.clear();
zone->numzonepoints = 0; zone->numzonepoints = 0;
zone->virtual_zone_point_list.clear(); zone->virtual_zone_point_list.clear();
@ -2036,7 +2026,7 @@ bool ZoneDatabase::LoadStaticZonePoints(LinkedList<ZonePoint *> *zone_point_list
continue; continue;
} }
zone_point_list->Insert(zp); zone_point_list.push_back(std::unique_ptr<ZonePoint>(zp));
zone->numzonepoints++; zone->numzonepoints++;
} }

View File

@ -184,7 +184,7 @@ public:
IPathfinder *pathing; IPathfinder *pathing;
LinkedList<NPC_Emote_Struct *> NPCEmoteList; LinkedList<NPC_Emote_Struct *> NPCEmoteList;
LinkedList<Spawn2 *> spawn2_list; LinkedList<Spawn2 *> spawn2_list;
LinkedList<ZonePoint *> zone_point_list; std::list<std::unique_ptr<ZonePoint>> zone_point_list;
std::vector<ZonePointsRepository::ZonePoints> virtual_zone_point_list; std::vector<ZonePointsRepository::ZonePoints> virtual_zone_point_list;
Map *zonemap; Map *zonemap;

View File

@ -452,7 +452,7 @@ public:
int &ruleset, int &ruleset,
char **map_filename); char **map_filename);
bool SaveZoneCFG(uint32 zoneid, uint16 instance_version, NewZone_Struct* zd); bool SaveZoneCFG(uint32 zoneid, uint16 instance_version, NewZone_Struct* zd);
bool LoadStaticZonePoints(LinkedList<ZonePoint*>* zone_point_list,const char* zonename, uint32 version); bool LoadStaticZonePoints(std::list<std::unique_ptr<ZonePoint>> &zone_point_list,const char* zonename, uint32 version);
bool UpdateZoneSafeCoords(const char* zonename, const glm::vec3& location); bool UpdateZoneSafeCoords(const char* zonename, const glm::vec3& location);
uint8 GetUseCFGSafeCoords(); uint8 GetUseCFGSafeCoords();
int getZoneShutDownDelay(uint32 zoneID, uint32 version); int getZoneShutDownDelay(uint32 zoneID, uint32 version);