mirror of
https://github.com/EQEmu/Server.git
synced 2026-01-01 00:21:28 +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
|
||||
#include <functional>
|
||||
#include "../any.h"
|
||||
#include "event_loop.h"
|
||||
|
||||
namespace EQ {
|
||||
class BackgroundTask
|
||||
{
|
||||
public:
|
||||
typedef std::function<void(void)> BackgroundTaskFunction;
|
||||
typedef std::function<void(EQEmu::Any&)> 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;
|
||||
});
|
||||
|
||||
@ -776,7 +776,7 @@ public:
|
||||
void ChangeTributeSettings(TributeInfo_Struct *t);
|
||||
void SendTributeTimer();
|
||||
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); }
|
||||
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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();
|
||||
|
||||
107
zone/pathing.cpp
107
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<FindPerson_Point> &points) {
|
||||
if (points.size() < 2) {
|
||||
//empty length packet == not found.
|
||||
EQApplicationPacket outapp(OP_FindPersonReply, 0);
|
||||
QueuePacket(&outapp);
|
||||
void CullPoints(std::vector<FindPerson_Point> &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<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);
|
||||
}
|
||||
|
||||
void Client::SendPathPacket(const std::vector<FindPerson_Point> &points) {
|
||||
EQ::BackgroundTask task([](EQEmu::Any &data) {
|
||||
auto &points = EQEmu::any_cast<std::vector<FindPerson_Point>>(data);
|
||||
CullPoints(points);
|
||||
}, [this](EQEmu::Any &data) {
|
||||
auto &points = EQEmu::any_cast<std::vector<FindPerson_Point>>(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<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) {
|
||||
return MakeNewPositionAndSendUpdate(x, y, z, speed, checkZ);
|
||||
return MakeNewPositionAndSendUpdate(x, y, z, speed);
|
||||
}
|
||||
|
||||
void NPC::AssignWaypoints(int32 grid)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user