From 296d48993ecd29ddb3d7d9efd78d7dffe141b799 Mon Sep 17 00:00:00 2001 From: KimLS Date: Mon, 14 Feb 2022 00:53:56 -0800 Subject: [PATCH] Convert zone points from old style linked list to std --- zone/client.cpp | 15 ++------- zone/gm_commands/reloadzps.cpp | 2 +- zone/gm_commands/showzonepoints.cpp | 7 +--- zone/zone.cpp | 50 ++++++++++++----------------- zone/zone.h | 2 +- zone/zonedb.h | 2 +- 6 files changed, 26 insertions(+), 52 deletions(-) diff --git a/zone/client.cpp b/zone/client.cpp index 2857f86db..605505bd3 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -6178,16 +6178,10 @@ void Client::MarkSingleCompassLoc(float in_x, float in_y, float in_z, uint8 coun void Client::SendZonePoints() { int count = 0; - LinkedListIterator iterator(zone->zone_point_list); - iterator.Reset(); - while (iterator.MoreElements()) { - ZonePoint *data = iterator.GetData(); - + for (auto& data : zone->zone_point_list) { if (ClientVersionBit() & data->client_version_mask) { count++; } - - iterator.Advance(); } uint32 zpsize = sizeof(ZonePoints) + ((count + 1) * sizeof(ZonePoint_Entry)); @@ -6196,11 +6190,7 @@ void Client::SendZonePoints() zp->count = count; int i = 0; - iterator.Reset(); - while(iterator.MoreElements()) - { - ZonePoint* data = iterator.GetData(); - + for (auto& data : zone->zone_point_list) { LogZonePoints( "Sending zone point to client [{}] mask [{}] x [{}] y [{}] z [{}] number [{}]", GetCleanName(), @@ -6222,7 +6212,6 @@ void Client::SendZonePoints() zp->zpe[i].zoneinstance = data->target_zone_instance; i++; } - iterator.Advance(); } FastQueuePacket(&outapp); diff --git a/zone/gm_commands/reloadzps.cpp b/zone/gm_commands/reloadzps.cpp index 353499d88..653dad152 100755 --- a/zone/gm_commands/reloadzps.cpp +++ b/zone/gm_commands/reloadzps.cpp @@ -2,7 +2,7 @@ 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."); } diff --git a/zone/gm_commands/showzonepoints.cpp b/zone/gm_commands/showzonepoints.cpp index d1e8c2428..7eae3e2b9 100755 --- a/zone/gm_commands/showzonepoints.cpp +++ b/zone/gm_commands/showzonepoints.cpp @@ -108,10 +108,7 @@ void command_showzonepoints(Client *c, const Seperator *sep) found_zone_points++; } - LinkedListIterator iterator(zone->zone_point_list); - iterator.Reset(); - while (iterator.MoreElements()) { - ZonePoint *zone_point = iterator.GetData(); + for (auto& zone_point : zone->zone_point_list) { std::string zone_long_name = ZoneLongName(zone_point->target_zone_id); 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() ); - iterator.Advance(); - found_zone_points++; } diff --git a/zone/zone.cpp b/zone/zone.cpp index 2dffad339..c2229a5bb 100755 --- a/zone/zone.cpp +++ b/zone/zone.cpp @@ -1061,7 +1061,7 @@ Zone::~Zone() { safe_delete_array(long_name); safe_delete(Weather_Timer); NPCEmoteList.Clear(); - zone_point_list.Clear(); + zone_point_list.clear(); entity_list.Clear(); ClearBlockedSpells(); @@ -1103,7 +1103,7 @@ bool Zone::Init(bool iStaticZone) { } 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"); return false; } @@ -1213,8 +1213,8 @@ void Zone::ReloadStaticData() { LogInfo("Reloading Zone Static Data"); LogInfo("Reloading static zone points"); - zone_point_list.Clear(); - if (!content_db.LoadStaticZonePoints(&zone_point_list, GetShortName(), GetInstanceVersion())) { + zone_point_list.clear(); + if (!content_db.LoadStaticZonePoints(zone_point_list, GetShortName(), GetInstanceVersion())) { LogError("Loading static zone points failed"); } @@ -1884,33 +1884,27 @@ 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) { - LinkedListIterator iterator(zone_point_list); ZonePoint* closest_zp = nullptr; float closest_dist = FLT_MAX; float max_distance2 = max_distance * max_distance; - iterator.Reset(); - while(iterator.MoreElements()) - { - ZonePoint* zp = iterator.GetData(); + for (auto& zp : zone_point_list) { uint32 mask_test = client->ClientVersionBit(); if (!(zp->client_version_mask & mask_test)) { - iterator.Advance(); continue; } - + if (zp->target_zone_id == to) { - auto dist = Distance(glm::vec2(zp->x, zp->y), glm::vec2(location)); + auto dist = Distance(glm::vec2(zp->x, zp->y), glm::vec2(location)); if ((zp->x == 999999 || zp->x == -999999) && (zp->y == 999999 || zp->y == -999999)) dist = 0; - + if (dist < closest_dist) { - closest_zp = zp; + closest_zp = zp.get(); 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 @@ -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) { - LinkedListIterator iterator(zone_point_list); ZonePoint* closest_zp = nullptr; float closest_dist = FLT_MAX; float max_distance2 = max_distance*max_distance; - iterator.Reset(); - while(iterator.MoreElements()) - { - ZonePoint* zp = iterator.GetData(); + + for (auto& zp : zone_point_list) { uint32 mask_test = client->ClientVersionBit(); - if(!(zp->client_version_mask & mask_test)) + if (!(zp->client_version_mask & mask_test)) { - iterator.Advance(); continue; } @@ -1964,24 +1954,24 @@ ZonePoint* Zone::GetClosestZonePointWithoutZone(float x, float y, float z, Clien delta_x = 0; if(zp->y == 999999 || zp->y == -999999) 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) { - closest_zp = zp; + closest_zp = zp.get(); closest_dist = dist; } - iterator.Advance(); } + if(closest_dist > max_distance2) closest_zp = nullptr; - + return closest_zp; } -bool ZoneDatabase::LoadStaticZonePoints(LinkedList *zone_point_list, const char *zonename, uint32 version) +bool ZoneDatabase::LoadStaticZonePoints(std::list> &zone_point_list, const char *zonename, uint32 version) { - zone_point_list->Clear(); + zone_point_list.clear(); zone->numzonepoints = 0; zone->virtual_zone_point_list.clear(); @@ -2036,7 +2026,7 @@ bool ZoneDatabase::LoadStaticZonePoints(LinkedList *zone_point_list continue; } - zone_point_list->Insert(zp); + zone_point_list.push_back(std::unique_ptr(zp)); zone->numzonepoints++; } diff --git a/zone/zone.h b/zone/zone.h index 23262778d..4aa1c46ec 100755 --- a/zone/zone.h +++ b/zone/zone.h @@ -184,7 +184,7 @@ public: IPathfinder *pathing; LinkedList NPCEmoteList; LinkedList spawn2_list; - LinkedList zone_point_list; + std::list> zone_point_list; std::vector virtual_zone_point_list; Map *zonemap; diff --git a/zone/zonedb.h b/zone/zonedb.h index e12a0ed19..2f925fadf 100644 --- a/zone/zonedb.h +++ b/zone/zonedb.h @@ -452,7 +452,7 @@ public: int &ruleset, char **map_filename); bool SaveZoneCFG(uint32 zoneid, uint16 instance_version, NewZone_Struct* zd); - bool LoadStaticZonePoints(LinkedList* zone_point_list,const char* zonename, uint32 version); + bool LoadStaticZonePoints(std::list> &zone_point_list,const char* zonename, uint32 version); bool UpdateZoneSafeCoords(const char* zonename, const glm::vec3& location); uint8 GetUseCFGSafeCoords(); int getZoneShutDownDelay(uint32 zoneID, uint32 version);