Added low mem mode

This commit is contained in:
ineedbots 2021-05-19 20:09:50 -06:00
parent 91044ff842
commit 9c1f4552c2
2 changed files with 40 additions and 3 deletions

View File

@ -16,6 +16,11 @@ init()
if (!getDvarInt("bots_main"))
return;
if(getDvar("bots_main_lowmem") == "")
setDvar("bots_main_lowmem", false);//lower memory usage mode, more cpu
level.bots_lowmem = getDvarInt("bots_main_lowmem");
thread load_waypoints();
cac_init_patch();
thread hook_callbacks();

View File

@ -1237,7 +1237,10 @@ load_waypoints()
level.waypoints[i].childCount = level.waypoints[i].children.size;
}
level.waypointsKDTree = WaypointsToKDTree();
if (!level.bots_lowmem)
{
level.waypointsKDTree = WaypointsToKDTree();
}
level.waypointsCamp = [];
level.waypointsTube = [];
@ -1822,6 +1825,27 @@ GetNearestWaypointWithSight(pos)
return candidate;
}
/*
Will linearly search for the nearest waypoint
*/
GetNearestWaypoint(pos)
{
candidate = undefined;
dist = 2147483647;
for(i = 0; i < level.waypointCount; i++)
{
curdis = DistanceSquared(level.waypoints[i].origin, pos);
if(curdis > dist)
continue;
dist = curdis;
candidate = level.waypoints[i];
}
return candidate;
}
/*
Modified Pezbot astar search.
This makes use of sets for quick look up and a heap for a priority queue instead of simple lists which require to linearly search for elements everytime.
@ -1835,7 +1859,11 @@ AStarSearch(start, goal, team, greedy_path)
closed = [];//set for quick lookup
startwp = level.waypointsKDTree KDTreeNearest(start);//balanced kdtree, for nns
startwp = undefined;
if (level.bots_lowmem)
startwp = getNearestWaypoint(start);
else
startwp = level.waypointsKDTree KDTreeNearest(start);//balanced kdtree, for nns
if(!isDefined(startwp))
return [];
_startwp = undefined;
@ -1845,7 +1873,11 @@ AStarSearch(start, goal, team, greedy_path)
startwp = _startwp;
startwp = startwp.index;
goalwp = level.waypointsKDTree KDTreeNearest(goal);
goalwp = undefined;
if (level.bots_lowmem)
goalwp = getNearestWaypoint(goal);
else
goalwp = level.waypointsKDTree KDTreeNearest(goal);
if(!isDefined(goalwp))
return [];
_goalwp = undefined;