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()
{
int count = 0;
LinkedListIterator<ZonePoint *> 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);

View File

@ -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.");
}

View File

@ -108,10 +108,7 @@ void command_showzonepoints(Client *c, const Seperator *sep)
found_zone_points++;
}
LinkedListIterator<ZonePoint *> 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++;
}

View File

@ -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<ZonePoint*> 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<ZonePoint*> 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<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->virtual_zone_point_list.clear();
@ -2036,7 +2026,7 @@ bool ZoneDatabase::LoadStaticZonePoints(LinkedList<ZonePoint *> *zone_point_list
continue;
}
zone_point_list->Insert(zp);
zone_point_list.push_back(std::unique_ptr<ZonePoint>(zp));
zone->numzonepoints++;
}

View File

@ -184,7 +184,7 @@ public:
IPathfinder *pathing;
LinkedList<NPC_Emote_Struct *> NPCEmoteList;
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;
Map *zonemap;

View File

@ -452,7 +452,7 @@ public:
int &ruleset,
char **map_filename);
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);
uint8 GetUseCFGSafeCoords();
int getZoneShutDownDelay(uint32 zoneID, uint32 version);