Added low mem mode

This commit is contained in:
ineedbots 2021-05-19 20:13:18 -06:00
parent 1e5c65eafb
commit 215ea9c6c1
2 changed files with 40 additions and 3 deletions

View File

@ -23,6 +23,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();
thread hook_callbacks();

View File

@ -934,7 +934,10 @@ load_waypoints()
level.waypoints[i].childCount = level.waypoints[i].children.size;
}
if (!level.bots_lowmem)
{
level.waypointsKDTree = WaypointsToKDTree();
}
level.waypointsCamp = [];
level.waypointsTube = [];
@ -1492,6 +1495,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.
@ -1505,6 +1529,10 @@ AStarSearch(start, goal, team, greedy_path)
closed = [];//set for quick lookup
startwp = undefined;
if (level.bots_lowmem)
startwp = getNearestWaypoint(start);
else
startwp = level.waypointsKDTree KDTreeNearest(start);//balanced kdtree, for nns
if(!isDefined(startwp))
return [];
@ -1515,6 +1543,10 @@ AStarSearch(start, goal, team, greedy_path)
startwp = _startwp;
startwp = startwp.index;
goalwp = undefined;
if (level.bots_lowmem)
goalwp = getNearestWaypoint(goal);
else
goalwp = level.waypointsKDTree KDTreeNearest(goal);
if(!isDefined(goalwp))
return [];