From 563878f20ea8653e32c4c33c9449f5ea3d4240e3 Mon Sep 17 00:00:00 2001 From: KimLS Date: Sat, 19 Aug 2017 12:49:06 -0700 Subject: [PATCH] Compile fixes and some debugging messages in find path code. --- common/event/background_task.h | 11 ++-- zone/client.h | 2 +- zone/client_packet.cpp | 20 +++--- zone/mob_ai.cpp | 2 +- zone/net.cpp | 6 +- zone/pathing.cpp | 107 ++++++++++++++++++++++++--------- zone/waypoints.cpp | 2 +- 7 files changed, 106 insertions(+), 44 deletions(-) diff --git a/common/event/background_task.h b/common/event/background_task.h index 8082abaf3..41fe4accb 100644 --- a/common/event/background_task.h +++ b/common/event/background_task.h @@ -1,32 +1,35 @@ #pragma once #include +#include "../any.h" #include "event_loop.h" namespace EQ { class BackgroundTask { public: - typedef std::function BackgroundTaskFunction; + typedef std::function BackgroundTaskFunction; struct BackgroundTaskBaton { BackgroundTaskFunction fn; BackgroundTaskFunction on_finish; + EQEmu::Any data; }; - BackgroundTask(BackgroundTaskFunction fn, BackgroundTaskFunction on_finish) { + BackgroundTask(BackgroundTaskFunction fn, BackgroundTaskFunction on_finish, EQEmu::Any data) { uv_work_t *m_work = new uv_work_t; memset(m_work, 0, sizeof(uv_work_t)); BackgroundTaskBaton *baton = new BackgroundTaskBaton(); baton->fn = fn; baton->on_finish = on_finish; + baton->data = data; m_work->data = baton; uv_queue_work(EventLoop::Get().Handle(), m_work, [](uv_work_t* req) { BackgroundTaskBaton *baton = (BackgroundTaskBaton*)req->data; - baton->fn(); + baton->fn(baton->data); }, [](uv_work_t* req, int status) { BackgroundTaskBaton *baton = (BackgroundTaskBaton*)req->data; - baton->on_finish(); + baton->on_finish(baton->data); delete baton; delete req; }); diff --git a/zone/client.h b/zone/client.h index dac409beb..a34bb8e72 100644 --- a/zone/client.h +++ b/zone/client.h @@ -776,7 +776,7 @@ public: void ChangeTributeSettings(TributeInfo_Struct *t); void SendTributeTimer(); void ToggleTribute(bool enabled); - void SendPathPacket(std::vector &path); + void SendPathPacket(const std::vector &path); inline PTimerList &GetPTimers() { return(p_timers); } diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 8537cada5..bb167c62f 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -5718,13 +5718,19 @@ void Client::Handle_OP_FindPersonRequest(const EQApplicationPacket *app) { //fill in the path array... // - points.resize(2); - points[0].x = GetX(); - points[0].y = GetY(); - points[0].z = GetZ(); - points[1].x = target->GetX(); - points[1].y = target->GetY(); - points[1].z = target->GetZ(); + points.clear(); + FindPerson_Point a; + FindPerson_Point b; + + a.x = GetX(); + a.y = GetY(); + a.z = GetZ(); + b.x = target->GetX(); + b.y = target->GetY(); + b.z = target->GetZ(); + + points.push_back(a); + points.push_back(b); } else { diff --git a/zone/mob_ai.cpp b/zone/mob_ai.cpp index bb36af028..b59146a12 100644 --- a/zone/mob_ai.cpp +++ b/zone/mob_ai.cpp @@ -1536,7 +1536,7 @@ void NPC::AI_DoMovement() { float new_z = this->FindGroundZ(m_Position.x, m_Position.y, 5); new_z += (this->GetSize() / 1.55); - if (!CalculateNewPosition2(roambox_movingto_x, roambox_movingto_y, new_z, walksp, true)) + if (!CalculateNewPosition(roambox_movingto_x, roambox_movingto_y, new_z, walksp, true)) { roambox_movingto_x = roambox_max_x + 1; // force update pLastFightingDelayMoving = Timer::GetCurrentTime() + RandomTimer(roambox_min_delay, roambox_delay); diff --git a/zone/net.cpp b/zone/net.cpp index eafdde807..582aa8116 100644 --- a/zone/net.cpp +++ b/zone/net.cpp @@ -542,8 +542,10 @@ int main(int argc, char** argv) { process_timer.Stop(); process_timer.Start(1000, true); - uint32 shutdown_timer = database.getZoneShutDownDelay(zone->GetZoneID(), zone->GetInstanceVersion()); - zone->StartShutdownTimer(shutdown_timer); + if (zone) { + uint32 shutdown_timer = database.getZoneShutDownDelay(zone->GetZoneID(), zone->GetInstanceVersion()); + zone->StartShutdownTimer(shutdown_timer); + } } else if (!previous_loaded && current_loaded) { process_timer.Stop(); diff --git a/zone/pathing.cpp b/zone/pathing.cpp index 826160905..62c80a5d5 100644 --- a/zone/pathing.cpp +++ b/zone/pathing.cpp @@ -1,4 +1,5 @@ #include "../common/global_define.h" +#include "../common/event/background_task.h" #include "client.h" #include "zone.h" @@ -163,36 +164,86 @@ glm::vec3 Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool &Wa } } -void Client::SendPathPacket(std::vector &points) { - if (points.size() < 2) { - //empty length packet == not found. - EQApplicationPacket outapp(OP_FindPersonReply, 0); - QueuePacket(&outapp); +void CullPoints(std::vector &points) { + if (!zone->HasMap()) { return; } - if (points.size() > 36) { - EQApplicationPacket outapp(OP_FindPersonReply, 0); - QueuePacket(&outapp); - return; + size_t i = 0; + for (; i < points.size(); ++i) { + auto &p = points[i]; + + for (;;) { + if (i + 2 >= points.size()) { + return; + } + + if (points.size() < 36) { + return; + } + + auto &p1 = points[i + 1]; + auto &p2 = points[i + 2]; + + if (zone->zonemap->CheckLoS(glm::vec3(p.x, p.y, p.z), glm::vec3(p2.x, p2.y, p2.z))) { + points.erase(points.begin() + i + 1); + Log(Logs::General, Logs::Status, "Culled find path point %u, connecting %u->%u instead.", i + 1, i, i + 2); + } + else { + break; + } + } } - - int len = sizeof(FindPersonResult_Struct) + (points.size() + 1) * sizeof(FindPerson_Point); - auto outapp = new EQApplicationPacket(OP_FindPersonReply, len); - FindPersonResult_Struct* fpr = (FindPersonResult_Struct*)outapp->pBuffer; - - std::vector::iterator cur, end; - cur = points.begin(); - end = points.end(); - unsigned int r; - for (r = 0; cur != end; ++cur, r++) { - fpr->path[r] = *cur; - - } - //put the last element into the destination field - --cur; - fpr->path[r] = *cur; - fpr->dest = *cur; - - FastQueuePacket(&outapp); +} + +void Client::SendPathPacket(const std::vector &points) { + EQ::BackgroundTask task([](EQEmu::Any &data) { + auto &points = EQEmu::any_cast>(data); + CullPoints(points); + }, [this](EQEmu::Any &data) { + auto &points = EQEmu::any_cast>(data); + + if (points.size() < 2) { + if (Admin() > 10) { + Message(MT_System, "Too few points"); + } + + EQApplicationPacket outapp(OP_FindPersonReply, 0); + QueuePacket(&outapp); + return; + } + + if (points.size() > 36) { + if (Admin() > 10) { + Message(MT_System, "Too many points %u", points.size()); + } + + EQApplicationPacket outapp(OP_FindPersonReply, 0); + QueuePacket(&outapp); + return; + } + + if (Admin() > 10) { + Message(MT_System, "Total points %u", points.size()); + } + + int len = sizeof(FindPersonResult_Struct) + (points.size() + 1) * sizeof(FindPerson_Point); + auto outapp = new EQApplicationPacket(OP_FindPersonReply, len); + FindPersonResult_Struct* fpr = (FindPersonResult_Struct*)outapp->pBuffer; + + std::vector::iterator cur, end; + cur = points.begin(); + end = points.end(); + unsigned int r; + for (r = 0; cur != end; ++cur, r++) { + fpr->path[r] = *cur; + + } + //put the last element into the destination field + --cur; + fpr->path[r] = *cur; + fpr->dest = *cur; + + FastQueuePacket(&outapp); + }, points); } diff --git a/zone/waypoints.cpp b/zone/waypoints.cpp index e6d9dee0a..527173287 100644 --- a/zone/waypoints.cpp +++ b/zone/waypoints.cpp @@ -627,7 +627,7 @@ bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, int speed) { } bool Mob::CalculateNewPosition(float x, float y, float z, int speed, bool checkZ, bool calcHeading) { - return MakeNewPositionAndSendUpdate(x, y, z, speed, checkZ); + return MakeNewPositionAndSendUpdate(x, y, z, speed); } void NPC::AssignWaypoints(int32 grid)