From 48fafe66bb5b205d2d9e068348c9232501672786 Mon Sep 17 00:00:00 2001 From: Uristqwerty Date: Tue, 19 Mar 2013 08:59:39 -0400 Subject: [PATCH] Pathing optimization + Added Distance_cardinal proc. Should result in slightly more CPU-efficient pathing when used with CardinalTurfsWithAccess, or other adjacent turf procs that do not return diagonals. + Changed calls to AStar that used CardinalTurfsWithAccess to use Distance_cardinal instead of Distance Overall effect: A bit less CPU used during pathing, if a bot has to path around corners. If a bot doesn't have to path around corners, it should be about as fast as before. --- code/game/machinery/bots/cleanbot.dm | 2 +- code/game/machinery/bots/ed209bot.dm | 2 +- code/game/machinery/bots/medbot.dm | 2 +- code/game/machinery/bots/mulebot.dm | 2 +- code/game/machinery/bots/secbot.dm | 2 +- code/game/turfs/turf.dm | 7 +++++++ 6 files changed, 12 insertions(+), 5 deletions(-) diff --git a/code/game/machinery/bots/cleanbot.dm b/code/game/machinery/bots/cleanbot.dm index ad64713c8df..f1995865c6e 100644 --- a/code/game/machinery/bots/cleanbot.dm +++ b/code/game/machinery/bots/cleanbot.dm @@ -224,7 +224,7 @@ text("[src.oddbutton ? "Yes" : "No" if (!next_dest_loc) next_dest_loc = closest_loc if (next_dest_loc) - src.patrol_path = AStar(src.loc, next_dest_loc, /turf/proc/CardinalTurfsWithAccess, /turf/proc/Distance, 0, 120, id=botcard, exclude=null) + src.patrol_path = AStar(src.loc, next_dest_loc, /turf/proc/CardinalTurfsWithAccess, /turf/proc/Distance_cardinal, 0, 120, id=botcard, exclude=null) if(!patrol_path) patrol_path = list() else diff --git a/code/game/machinery/bots/ed209bot.dm b/code/game/machinery/bots/ed209bot.dm index a07da54e0c1..c8ccb1c924b 100644 --- a/code/game/machinery/bots/ed209bot.dm +++ b/code/game/machinery/bots/ed209bot.dm @@ -614,7 +614,7 @@ Auto Patrol: []"}, // calculates a path to the current destination // given an optional turf to avoid /obj/machinery/bot/ed209/proc/calc_path(var/turf/avoid = null) - src.path = AStar(src.loc, patrol_target, /turf/proc/CardinalTurfsWithAccess, /turf/proc/Distance, 0, 120, id=botcard, exclude=avoid) + src.path = AStar(src.loc, patrol_target, /turf/proc/CardinalTurfsWithAccess, /turf/proc/Distance_cardinal, 0, 120, id=botcard, exclude=avoid) if(!src.path) src.path = list() diff --git a/code/game/machinery/bots/medbot.dm b/code/game/machinery/bots/medbot.dm index 807d8cb57d8..e91a2b42bde 100644 --- a/code/game/machinery/bots/medbot.dm +++ b/code/game/machinery/bots/medbot.dm @@ -299,7 +299,7 @@ if(src.patient && src.path.len == 0 && (get_dist(src,src.patient) > 1)) spawn(0) - src.path = AStar(src.loc, get_turf(src.patient), /turf/proc/CardinalTurfsWithAccess, /turf/proc/Distance, 0, 30,id=botcard) + src.path = AStar(src.loc, get_turf(src.patient), /turf/proc/CardinalTurfsWithAccess, /turf/proc/Distance_cardinal, 0, 30,id=botcard) if(!src.path) src.path = list() if(src.path.len == 0) diff --git a/code/game/machinery/bots/mulebot.dm b/code/game/machinery/bots/mulebot.dm index b28be073d3e..8f56a805db5 100644 --- a/code/game/machinery/bots/mulebot.dm +++ b/code/game/machinery/bots/mulebot.dm @@ -646,7 +646,7 @@ var/global/mulebot_count = 0 // calculates a path to the current destination // given an optional turf to avoid /obj/machinery/bot/mulebot/proc/calc_path(var/turf/avoid = null) - src.path = AStar(src.loc, src.target, /turf/proc/CardinalTurfsWithAccess, /turf/proc/Distance, 0, 250, id=botcard, exclude=avoid) + src.path = AStar(src.loc, src.target, /turf/proc/CardinalTurfsWithAccess, /turf/proc/Distance_cardinal, 0, 250, id=botcard, exclude=avoid) if(!src.path) src.path = list() diff --git a/code/game/machinery/bots/secbot.dm b/code/game/machinery/bots/secbot.dm index 4dcc2d60601..23a0a245c88 100644 --- a/code/game/machinery/bots/secbot.dm +++ b/code/game/machinery/bots/secbot.dm @@ -552,7 +552,7 @@ Auto Patrol: []"}, // calculates a path to the current destination // given an optional turf to avoid /obj/machinery/bot/secbot/proc/calc_path(var/turf/avoid = null) - src.path = AStar(src.loc, patrol_target, /turf/proc/CardinalTurfsWithAccess, /turf/proc/Distance, 0, 120, id=botcard, exclude=avoid) + src.path = AStar(src.loc, patrol_target, /turf/proc/CardinalTurfsWithAccess, /turf/proc/Distance_cardinal, 0, 120, id=botcard, exclude=avoid) if(!src.path) src.path = list() diff --git a/code/game/turfs/turf.dm b/code/game/turfs/turf.dm index 5eff3e3bc1c..870278d08ae 100644 --- a/code/game/turfs/turf.dm +++ b/code/game/turfs/turf.dm @@ -293,6 +293,13 @@ return cost else return get_dist(src,t) + +// This Distance proc assumes that only cardinal movement is +// possible. It results in more efficient (CPU-wise) pathing +// for bots and anything else that only moves in cardinal dirs. +/turf/proc/Distance_cardinal(turf/t) + return abs(src.x - t.x) + abs(src.y - t.y) + /turf/proc/AdjacentTurfsSpace() var/L[] = new() for(var/turf/t in oview(src,1))