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")) if (!getDvarInt("bots_main"))
return; 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 load_waypoints();
cac_init_patch(); cac_init_patch();
thread hook_callbacks(); thread hook_callbacks();

View File

@ -1237,7 +1237,10 @@ load_waypoints()
level.waypoints[i].childCount = level.waypoints[i].children.size; level.waypoints[i].childCount = level.waypoints[i].children.size;
} }
if (!level.bots_lowmem)
{
level.waypointsKDTree = WaypointsToKDTree(); level.waypointsKDTree = WaypointsToKDTree();
}
level.waypointsCamp = []; level.waypointsCamp = [];
level.waypointsTube = []; level.waypointsTube = [];
@ -1822,6 +1825,27 @@ GetNearestWaypointWithSight(pos)
return candidate; 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. 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. 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,6 +1859,10 @@ AStarSearch(start, goal, team, greedy_path)
closed = [];//set for quick lookup closed = [];//set for quick lookup
startwp = undefined;
if (level.bots_lowmem)
startwp = getNearestWaypoint(start);
else
startwp = level.waypointsKDTree KDTreeNearest(start);//balanced kdtree, for nns startwp = level.waypointsKDTree KDTreeNearest(start);//balanced kdtree, for nns
if(!isDefined(startwp)) if(!isDefined(startwp))
return []; return [];
@ -1845,6 +1873,10 @@ AStarSearch(start, goal, team, greedy_path)
startwp = _startwp; startwp = _startwp;
startwp = startwp.index; startwp = startwp.index;
goalwp = undefined;
if (level.bots_lowmem)
goalwp = getNearestWaypoint(goal);
else
goalwp = level.waypointsKDTree KDTreeNearest(goal); goalwp = level.waypointsKDTree KDTreeNearest(goal);
if(!isDefined(goalwp)) if(!isDefined(goalwp))
return []; return [];