WIP: Pathfinding Nr. 6: Add caching support

This commit is contained in:
TotallyNotElite 2018-08-17 14:23:51 +02:00
parent c1797dfdfa
commit 0e78958bcc

View File

@ -12,6 +12,7 @@ bool init = false;
bool pathfinding = true;
static settings::Bool enabled{ "misc.pathing", "true" };
// Todo fix
int FindInVector(int id)
{
@ -105,6 +106,9 @@ struct MAP : public micropather::Graph
}
};
std::unique_ptr<MAP> TF2MAP;
std::unique_ptr<micropather::MicroPather> pather;
void Init()
{
// TODO: Improve performance
@ -118,17 +122,23 @@ void Init()
lvldir.append("/.steam/steam/steamapps/common/Team Fortress 2/tf/");
lvldir.append(lvlname);
lvldir.append(".nav");
logging::Info(lvldir.c_str());
logging::Info(format("Pathing: Nav File location: ",lvldir).c_str());
areas.empty();
navfile = CNavFile(lvldir.c_str());
if (!navfile.m_isOK)
logging::Info("Invalid Nav File");
logging::Info("Pathing: Invalid Nav File");
else
{
areas.reserve(navfile.m_areas.size());
int size = navfile.m_areas.size();
logging::Info(format("Pathing: Number of areas to index:", size).c_str());
areas.reserve(size);
for (auto i : navfile.m_areas)
areas.push_back(i);
if (size > 7000)
size = 7000;
TF2MAP = std::make_unique<MAP>();
pather = std::make_unique<micropather::MicroPather>(TF2MAP.get(), size, 6, true);
}
pathfinding = true;
}
@ -166,12 +176,14 @@ std::vector<Vector> findPath(Vector loc, Vector dest)
if (id_loc == -1 || id_dest == -1)
return std::vector<Vector>(0);
micropather::MPVector<void *> pathNodes;
MAP TF2MAP;
micropather::MicroPather pather(&TF2MAP, areas.size(), 8, true);
//MAP TF2MAP;
//micropather::MicroPather pather(&TF2MAP, areas.size(), 8, true);
float cost;
int result = pather.Solve(static_cast<void *>(&areas.at(id_loc)),
int result = pather->Solve(static_cast<void *>(&areas.at(id_loc)),
static_cast<void *>(&areas.at(id_dest)),
&pathNodes, &cost);
if (result)
return std::vector<Vector>(0);
logging::Info(format(result).c_str());
std::vector<Vector> path;
for (int i = 0; i < pathNodes.size(); i++)
@ -206,7 +218,7 @@ void CreateMove()
return;
if (CE_BAD(LOCAL_E))
return;
if (!crumbs.empty() && g_pLocalPlayer->v_Origin.DistTo(crumbs.at(0)) < 40.0f)
if (!crumbs.empty() && g_pLocalPlayer->v_Origin.DistTo(crumbs.at(0)) < 20.0f)
{
crumbs.erase(crumbs.begin());
inactivity.update();