mirror of
https://github.com/EQEmu/Server.git
synced 2026-03-04 00:02:24 +00:00
Compile fixes and some debugging messages in find path code.
This commit is contained in:
parent
ffbee0ad1a
commit
563878f20e
@ -1,32 +1,35 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include "../any.h"
|
||||||
#include "event_loop.h"
|
#include "event_loop.h"
|
||||||
|
|
||||||
namespace EQ {
|
namespace EQ {
|
||||||
class BackgroundTask
|
class BackgroundTask
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef std::function<void(void)> BackgroundTaskFunction;
|
typedef std::function<void(EQEmu::Any&)> BackgroundTaskFunction;
|
||||||
struct BackgroundTaskBaton
|
struct BackgroundTaskBaton
|
||||||
{
|
{
|
||||||
BackgroundTaskFunction fn;
|
BackgroundTaskFunction fn;
|
||||||
BackgroundTaskFunction on_finish;
|
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;
|
uv_work_t *m_work = new uv_work_t;
|
||||||
memset(m_work, 0, sizeof(uv_work_t));
|
memset(m_work, 0, sizeof(uv_work_t));
|
||||||
BackgroundTaskBaton *baton = new BackgroundTaskBaton();
|
BackgroundTaskBaton *baton = new BackgroundTaskBaton();
|
||||||
baton->fn = fn;
|
baton->fn = fn;
|
||||||
baton->on_finish = on_finish;
|
baton->on_finish = on_finish;
|
||||||
|
baton->data = data;
|
||||||
|
|
||||||
m_work->data = baton;
|
m_work->data = baton;
|
||||||
uv_queue_work(EventLoop::Get().Handle(), m_work, [](uv_work_t* req) {
|
uv_queue_work(EventLoop::Get().Handle(), m_work, [](uv_work_t* req) {
|
||||||
BackgroundTaskBaton *baton = (BackgroundTaskBaton*)req->data;
|
BackgroundTaskBaton *baton = (BackgroundTaskBaton*)req->data;
|
||||||
baton->fn();
|
baton->fn(baton->data);
|
||||||
}, [](uv_work_t* req, int status) {
|
}, [](uv_work_t* req, int status) {
|
||||||
BackgroundTaskBaton *baton = (BackgroundTaskBaton*)req->data;
|
BackgroundTaskBaton *baton = (BackgroundTaskBaton*)req->data;
|
||||||
baton->on_finish();
|
baton->on_finish(baton->data);
|
||||||
delete baton;
|
delete baton;
|
||||||
delete req;
|
delete req;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -776,7 +776,7 @@ public:
|
|||||||
void ChangeTributeSettings(TributeInfo_Struct *t);
|
void ChangeTributeSettings(TributeInfo_Struct *t);
|
||||||
void SendTributeTimer();
|
void SendTributeTimer();
|
||||||
void ToggleTribute(bool enabled);
|
void ToggleTribute(bool enabled);
|
||||||
void SendPathPacket(std::vector<FindPerson_Point> &path);
|
void SendPathPacket(const std::vector<FindPerson_Point> &path);
|
||||||
|
|
||||||
inline PTimerList &GetPTimers() { return(p_timers); }
|
inline PTimerList &GetPTimers() { return(p_timers); }
|
||||||
|
|
||||||
|
|||||||
@ -5718,13 +5718,19 @@ void Client::Handle_OP_FindPersonRequest(const EQApplicationPacket *app)
|
|||||||
{
|
{
|
||||||
//fill in the path array...
|
//fill in the path array...
|
||||||
//
|
//
|
||||||
points.resize(2);
|
points.clear();
|
||||||
points[0].x = GetX();
|
FindPerson_Point a;
|
||||||
points[0].y = GetY();
|
FindPerson_Point b;
|
||||||
points[0].z = GetZ();
|
|
||||||
points[1].x = target->GetX();
|
a.x = GetX();
|
||||||
points[1].y = target->GetY();
|
a.y = GetY();
|
||||||
points[1].z = target->GetZ();
|
a.z = GetZ();
|
||||||
|
b.x = target->GetX();
|
||||||
|
b.y = target->GetY();
|
||||||
|
b.z = target->GetZ();
|
||||||
|
|
||||||
|
points.push_back(a);
|
||||||
|
points.push_back(b);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1536,7 +1536,7 @@ void NPC::AI_DoMovement() {
|
|||||||
float new_z = this->FindGroundZ(m_Position.x, m_Position.y, 5);
|
float new_z = this->FindGroundZ(m_Position.x, m_Position.y, 5);
|
||||||
new_z += (this->GetSize() / 1.55);
|
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
|
roambox_movingto_x = roambox_max_x + 1; // force update
|
||||||
pLastFightingDelayMoving = Timer::GetCurrentTime() + RandomTimer(roambox_min_delay, roambox_delay);
|
pLastFightingDelayMoving = Timer::GetCurrentTime() + RandomTimer(roambox_min_delay, roambox_delay);
|
||||||
|
|||||||
@ -542,8 +542,10 @@ int main(int argc, char** argv) {
|
|||||||
process_timer.Stop();
|
process_timer.Stop();
|
||||||
process_timer.Start(1000, true);
|
process_timer.Start(1000, true);
|
||||||
|
|
||||||
uint32 shutdown_timer = database.getZoneShutDownDelay(zone->GetZoneID(), zone->GetInstanceVersion());
|
if (zone) {
|
||||||
zone->StartShutdownTimer(shutdown_timer);
|
uint32 shutdown_timer = database.getZoneShutDownDelay(zone->GetZoneID(), zone->GetInstanceVersion());
|
||||||
|
zone->StartShutdownTimer(shutdown_timer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (!previous_loaded && current_loaded) {
|
else if (!previous_loaded && current_loaded) {
|
||||||
process_timer.Stop();
|
process_timer.Stop();
|
||||||
|
|||||||
107
zone/pathing.cpp
107
zone/pathing.cpp
@ -1,4 +1,5 @@
|
|||||||
#include "../common/global_define.h"
|
#include "../common/global_define.h"
|
||||||
|
#include "../common/event/background_task.h"
|
||||||
|
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "zone.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<FindPerson_Point> &points) {
|
void CullPoints(std::vector<FindPerson_Point> &points) {
|
||||||
if (points.size() < 2) {
|
if (!zone->HasMap()) {
|
||||||
//empty length packet == not found.
|
|
||||||
EQApplicationPacket outapp(OP_FindPersonReply, 0);
|
|
||||||
QueuePacket(&outapp);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (points.size() > 36) {
|
size_t i = 0;
|
||||||
EQApplicationPacket outapp(OP_FindPersonReply, 0);
|
for (; i < points.size(); ++i) {
|
||||||
QueuePacket(&outapp);
|
auto &p = points[i];
|
||||||
return;
|
|
||||||
|
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);
|
void Client::SendPathPacket(const std::vector<FindPerson_Point> &points) {
|
||||||
FindPersonResult_Struct* fpr = (FindPersonResult_Struct*)outapp->pBuffer;
|
EQ::BackgroundTask task([](EQEmu::Any &data) {
|
||||||
|
auto &points = EQEmu::any_cast<std::vector<FindPerson_Point>>(data);
|
||||||
std::vector<FindPerson_Point>::iterator cur, end;
|
CullPoints(points);
|
||||||
cur = points.begin();
|
}, [this](EQEmu::Any &data) {
|
||||||
end = points.end();
|
auto &points = EQEmu::any_cast<std::vector<FindPerson_Point>>(data);
|
||||||
unsigned int r;
|
|
||||||
for (r = 0; cur != end; ++cur, r++) {
|
if (points.size() < 2) {
|
||||||
fpr->path[r] = *cur;
|
if (Admin() > 10) {
|
||||||
|
Message(MT_System, "Too few points");
|
||||||
}
|
}
|
||||||
//put the last element into the destination field
|
|
||||||
--cur;
|
EQApplicationPacket outapp(OP_FindPersonReply, 0);
|
||||||
fpr->path[r] = *cur;
|
QueuePacket(&outapp);
|
||||||
fpr->dest = *cur;
|
return;
|
||||||
|
}
|
||||||
FastQueuePacket(&outapp);
|
|
||||||
|
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<FindPerson_Point>::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);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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) {
|
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)
|
void NPC::AssignWaypoints(int32 grid)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user