mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-11 10:11:09 +00:00
Replace caller args in pathfinding code with requester (#88084)
## About The Pull Request Somewhat of a port of https://github.com/ParadiseSS13/Paradise/pull/26401, albeit re-done from scratch (with the power of find and replace) Caller is a protected/reserved var in 516. We use it a lot. It's used in more places than this, but I'm a perfectionist and can't think of better names for most of the other uses (mostly mob AI, holocall, and `InterceptClickOn` related), so I'm just doing pathfinding for now. ## Why It's Good For The Game Prep for compiling on 516 ## Changelog No user-facing changes - this is merely renaming vars.
This commit is contained in:
@@ -55,7 +55,7 @@
|
||||
|
||||
/datum/pathfind/jps
|
||||
/// The movable we are pathing
|
||||
var/atom/movable/caller
|
||||
var/atom/movable/requester
|
||||
/// The turf we're trying to path to (note that this won't track a moving target)
|
||||
var/turf/end
|
||||
/// The open list/stack we pop nodes out from (TODO: make this a normal list and macro-ize the heap operations to reduce proc overhead)
|
||||
@@ -72,9 +72,9 @@
|
||||
///Defines how we handle diagonal moves. See __DEFINES/path.dm
|
||||
var/diagonal_handling = DIAGONAL_REMOVE_CLUNKY
|
||||
|
||||
/datum/pathfind/jps/proc/setup(atom/movable/caller, list/access, max_distance, simulated_only, avoid, list/datum/callback/on_finish, atom/goal, mintargetdist, skip_first, diagonal_handling)
|
||||
src.caller = caller
|
||||
src.pass_info = new(caller, access)
|
||||
/datum/pathfind/jps/proc/setup(atom/movable/requester, list/access, max_distance, simulated_only, avoid, list/datum/callback/on_finish, atom/goal, mintargetdist, skip_first, diagonal_handling)
|
||||
src.requester = requester
|
||||
src.pass_info = new(requester, access)
|
||||
src.max_distance = max_distance
|
||||
src.simulated_only = simulated_only
|
||||
src.avoid = avoid
|
||||
@@ -88,12 +88,12 @@
|
||||
|
||||
/datum/pathfind/jps/Destroy(force)
|
||||
. = ..()
|
||||
caller = null
|
||||
requester = null
|
||||
end = null
|
||||
open = null
|
||||
|
||||
/datum/pathfind/jps/start()
|
||||
start = start || get_turf(caller)
|
||||
start = start || get_turf(requester)
|
||||
. = ..()
|
||||
if(!.)
|
||||
return .
|
||||
@@ -115,7 +115,7 @@
|
||||
. = ..()
|
||||
if(!.)
|
||||
return .
|
||||
if(QDELETED(caller))
|
||||
if(QDELETED(requester))
|
||||
return FALSE
|
||||
|
||||
while(!open.is_empty() && !path)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* It will yield until a path is returned, using magic
|
||||
*
|
||||
* Arguments:
|
||||
* * caller: The movable atom that's trying to find the path
|
||||
* * requester: The movable atom that's trying to find the path
|
||||
* * end: What we're trying to path to. It doesn't matter if this is a turf or some other atom, we're gonna just path to the turf it's on anyway
|
||||
* * max_distance: The maximum number of steps we can take in a given path to search (default: 30, 0 = infinite)
|
||||
* * mintargetdistance: Minimum distance to the target before path returns, could be used to get near a target, but not right to it - for an AI mob with a gun, for example.
|
||||
@@ -14,16 +14,16 @@
|
||||
* * skip_first: Whether or not to delete the first item in the path. This would be done because the first item is the starting tile, which can break movement for some creatures.
|
||||
* * diagonal_handling: defines how we handle diagonal moves. see __DEFINES/path.dm
|
||||
*/
|
||||
/proc/get_path_to(atom/movable/caller, atom/end, max_distance = 30, mintargetdist, access=list(), simulated_only = TRUE, turf/exclude, skip_first=TRUE, diagonal_handling=DIAGONAL_REMOVE_CLUNKY)
|
||||
/proc/get_path_to(atom/movable/requester, atom/end, max_distance = 30, mintargetdist, access=list(), simulated_only = TRUE, turf/exclude, skip_first=TRUE, diagonal_handling=DIAGONAL_REMOVE_CLUNKY)
|
||||
var/list/hand_around = list()
|
||||
// We're guaranteed that list will be the first list in pathfinding_finished's argset because of how callback handles the arguments list
|
||||
var/datum/callback/await = list(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(pathfinding_finished), hand_around))
|
||||
if(!SSpathfinder.pathfind(caller, end, max_distance, mintargetdist, access, simulated_only, exclude, skip_first, diagonal_handling, await))
|
||||
if(!SSpathfinder.pathfind(requester, end, max_distance, mintargetdist, access, simulated_only, exclude, skip_first, diagonal_handling, await))
|
||||
return list()
|
||||
|
||||
UNTIL(length(hand_around))
|
||||
var/list/return_val = hand_around[1]
|
||||
if(!islist(return_val) || (QDELETED(caller) || QDELETED(end))) // It's trash, just hand back empty to make it easy
|
||||
if(!islist(return_val) || (QDELETED(requester) || QDELETED(end))) // It's trash, just hand back empty to make it easy
|
||||
return list()
|
||||
return return_val
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
* It will yield until a path is returned, using magic
|
||||
*
|
||||
* Arguments:
|
||||
* * caller: The movable atom that's trying to find the path
|
||||
* * requester: The movable atom that's trying to find the path
|
||||
* * end: What we're trying to path to. It doesn't matter if this is a turf or some other atom, we're gonna just path to the turf it's on anyway
|
||||
* * max_distance: The maximum number of steps we can take in a given path to search (default: 30, 0 = infinite)
|
||||
* * mintargetdistance: Minimum distance to the target before path returns, could be used to get near a target, but not right to it - for an AI mob with a gun, for example.
|
||||
@@ -47,29 +47,29 @@
|
||||
* * exclude: If we want to avoid a specific turf, like if we're a mulebot who already got blocked by some turf
|
||||
* * skip_first: Whether or not to delete the first item in the path. This would be done because the first item is the starting tile, which can break movement for some creatures.
|
||||
*/
|
||||
/proc/get_swarm_path_to(atom/movable/caller, atom/end, max_distance = 30, mintargetdist, age = MAP_REUSE_INSTANT, access = list(), simulated_only = TRUE, turf/exclude, skip_first=TRUE)
|
||||
/proc/get_swarm_path_to(atom/movable/requester, atom/end, max_distance = 30, mintargetdist, age = MAP_REUSE_INSTANT, access = list(), simulated_only = TRUE, turf/exclude, skip_first=TRUE)
|
||||
var/list/hand_around = list()
|
||||
// We're guaranteed that list will be the first list in pathfinding_finished's argset because of how callback handles the arguments list
|
||||
var/datum/callback/await = list(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(pathfinding_finished), hand_around))
|
||||
if(!SSpathfinder.swarmed_pathfind(caller, end, max_distance, mintargetdist, age, access, simulated_only, exclude, skip_first, await))
|
||||
if(!SSpathfinder.swarmed_pathfind(requester, end, max_distance, mintargetdist, age, access, simulated_only, exclude, skip_first, await))
|
||||
return list()
|
||||
|
||||
UNTIL(length(hand_around))
|
||||
var/list/return_val = hand_around[1]
|
||||
if(!islist(return_val) || (QDELETED(caller) || QDELETED(end))) // It's trash, just hand back empty to make it easy
|
||||
if(!islist(return_val) || (QDELETED(requester) || QDELETED(end))) // It's trash, just hand back empty to make it easy
|
||||
return list()
|
||||
return return_val
|
||||
|
||||
/proc/get_sssp(atom/movable/caller, max_distance = 30, access = list(), simulated_only = TRUE, turf/exclude)
|
||||
/proc/get_sssp(atom/movable/requester, max_distance = 30, access = list(), simulated_only = TRUE, turf/exclude)
|
||||
var/list/hand_around = list()
|
||||
// We're guaranteed that list will be the first list in pathfinding_finished's argset because of how callback handles the arguments list
|
||||
var/datum/callback/await = list(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(pathfinding_finished), hand_around))
|
||||
if(!SSpathfinder.build_map(caller, get_turf(caller), max_distance, access, simulated_only, exclude, await))
|
||||
if(!SSpathfinder.build_map(requester, get_turf(requester), max_distance, access, simulated_only, exclude, await))
|
||||
return null
|
||||
|
||||
UNTIL(length(hand_around))
|
||||
var/datum/path_map/return_val = hand_around[1]
|
||||
if(!istype(return_val, /datum/path_map) || (QDELETED(caller))) // It's trash, just hand back null to make it easy
|
||||
if(!istype(return_val, /datum/path_map) || (QDELETED(requester))) // It's trash, just hand back null to make it easy
|
||||
return null
|
||||
return return_val
|
||||
|
||||
@@ -202,7 +202,7 @@
|
||||
return modified_path
|
||||
|
||||
/**
|
||||
* For seeing if we can actually move between 2 given turfs while accounting for our access and the caller's pass_flags
|
||||
* For seeing if we can actually move between 2 given turfs while accounting for our access and the requester's pass_flags
|
||||
*
|
||||
* Assumes destinantion turf is non-dense - check and shortcircuit in code invoking this proc to avoid overhead.
|
||||
* Makes some other assumptions, such as assuming that unless declared, non dense objects will not block movement.
|
||||
@@ -311,7 +311,7 @@
|
||||
/// Let's avoid this
|
||||
var/camera_type
|
||||
|
||||
/// Weakref to the caller used to generate this info
|
||||
/// Weakref to the requester used to generate this info
|
||||
/// Should not use this almost ever, it's for context and to allow for proc chains that
|
||||
/// Require a movable
|
||||
var/datum/weakref/caller_ref = null
|
||||
|
||||
@@ -201,8 +201,8 @@
|
||||
/// Our current position in the working queue
|
||||
var/working_index
|
||||
|
||||
/datum/pathfind/sssp/proc/setup(atom/movable/caller, list/access, turf/center, max_distance, simulated_only, turf/avoid, list/datum/callback/on_finish)
|
||||
src.pass_info = new(caller, access)
|
||||
/datum/pathfind/sssp/proc/setup(atom/movable/requester, list/access, turf/center, max_distance, simulated_only, turf/avoid, list/datum/callback/on_finish)
|
||||
src.pass_info = new(requester, access)
|
||||
src.start = center
|
||||
src.max_distance = max_distance
|
||||
src.simulated_only = simulated_only
|
||||
|
||||
@@ -61,9 +61,9 @@ SUBSYSTEM_DEF(pathfinder)
|
||||
currentmaps.len--
|
||||
|
||||
/// Initiates a pathfind. Returns true if we're good, FALSE if something's failed
|
||||
/datum/controller/subsystem/pathfinder/proc/pathfind(atom/movable/caller, atom/end, max_distance = 30, mintargetdist, access = list(), simulated_only = TRUE, turf/exclude, skip_first = TRUE, diagonal_handling = DIAGONAL_REMOVE_CLUNKY, list/datum/callback/on_finish)
|
||||
/datum/controller/subsystem/pathfinder/proc/pathfind(atom/movable/requester, atom/end, max_distance = 30, mintargetdist, access = list(), simulated_only = TRUE, turf/exclude, skip_first = TRUE, diagonal_handling = DIAGONAL_REMOVE_CLUNKY, list/datum/callback/on_finish)
|
||||
var/datum/pathfind/jps/path = new()
|
||||
path.setup(caller, access, max_distance, simulated_only, exclude, on_finish, end, mintargetdist, skip_first, diagonal_handling)
|
||||
path.setup(requester, access, max_distance, simulated_only, exclude, on_finish, end, mintargetdist, skip_first, diagonal_handling)
|
||||
if(path.start())
|
||||
active_pathing += path
|
||||
return TRUE
|
||||
@@ -71,21 +71,21 @@ SUBSYSTEM_DEF(pathfinder)
|
||||
|
||||
/// Initiates a swarmed pathfind. Returns TRUE if we're good, FALSE if something's failed
|
||||
/// If a valid pathmap exists for the TARGET turf we'll use that, otherwise we have to build a new one
|
||||
/datum/controller/subsystem/pathfinder/proc/swarmed_pathfind(atom/movable/caller, atom/end, max_distance = 30, mintargetdist = 0, age = MAP_REUSE_INSTANT, access = list(), simulated_only = TRUE, turf/exclude, skip_first = TRUE, list/datum/callback/on_finish)
|
||||
/datum/controller/subsystem/pathfinder/proc/swarmed_pathfind(atom/movable/requester, atom/end, max_distance = 30, mintargetdist = 0, age = MAP_REUSE_INSTANT, access = list(), simulated_only = TRUE, turf/exclude, skip_first = TRUE, list/datum/callback/on_finish)
|
||||
var/turf/target = get_turf(end)
|
||||
var/datum/can_pass_info/pass_info = new(caller, access)
|
||||
var/datum/can_pass_info/pass_info = new(requester, access)
|
||||
// If there's a map we can use already, use it
|
||||
var/datum/path_map/valid_map = get_valid_map(pass_info, target, simulated_only, exclude, age, include_building = TRUE)
|
||||
if(valid_map && valid_map.expand(max_distance))
|
||||
path_map_passalong(on_finish, get_turf(caller), mintargetdist, skip_first, valid_map)
|
||||
path_map_passalong(on_finish, get_turf(requester), mintargetdist, skip_first, valid_map)
|
||||
return TRUE
|
||||
|
||||
// Otherwise we're gonna make a new one, and turn it into a path for the callbacks passed into us
|
||||
var/list/datum/callback/pass_in = list()
|
||||
pass_in += CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(path_map_passalong), on_finish, get_turf(caller), mintargetdist, skip_first)
|
||||
pass_in += CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(path_map_passalong), on_finish, get_turf(requester), mintargetdist, skip_first)
|
||||
// And to allow subsequent calls to reuse the same map, we'll put a placeholder in the cache, and fill it up when the pathing finishes
|
||||
var/datum/path_map/empty = new()
|
||||
empty.pass_info = new(caller, access)
|
||||
empty.pass_info = new(requester, access)
|
||||
empty.start = target
|
||||
empty.pass_space = simulated_only
|
||||
empty.avoid = exclude
|
||||
@@ -133,9 +133,9 @@ SUBSYSTEM_DEF(pathfinder)
|
||||
source_to_maps[target] -= same_target
|
||||
|
||||
/// Initiates a SSSP run. Returns true if we're good, FALSE if something's failed
|
||||
/datum/controller/subsystem/pathfinder/proc/build_map(atom/movable/caller, turf/source, max_distance = 30, access = list(), simulated_only = TRUE, turf/exclude, list/datum/callback/on_finish)
|
||||
/datum/controller/subsystem/pathfinder/proc/build_map(atom/movable/requester, turf/source, max_distance = 30, access = list(), simulated_only = TRUE, turf/exclude, list/datum/callback/on_finish)
|
||||
var/datum/pathfind/sssp/path = new()
|
||||
path.setup(caller, access, source, max_distance, simulated_only, exclude, on_finish)
|
||||
path.setup(requester, access, source, max_distance, simulated_only, exclude, on_finish)
|
||||
if(path.start())
|
||||
active_pathing += path
|
||||
return TRUE
|
||||
@@ -160,7 +160,7 @@ SUBSYSTEM_DEF(pathfinder)
|
||||
/// Optionally takes a max age to accept (defaults to 0 seconds) and a minimum acceptable range
|
||||
/// If include_building is true and we can only find a building path, we'll use that instead. tho we will wait for it to finish first
|
||||
/datum/controller/subsystem/pathfinder/proc/get_valid_map(datum/can_pass_info/pass_info, turf/target, simulated_only = TRUE, turf/exclude, age = MAP_REUSE_INSTANT, min_range = -INFINITY, include_building = FALSE)
|
||||
// Walk all the maps that match our caller's turf OR our target's
|
||||
// Walk all the maps that match our requester's turf OR our target's
|
||||
// Then hold onto em. If their cache time is short we can reuse/expand them, if not we'll have to make a new one
|
||||
var/oldest_time = world.time - age
|
||||
/// Backup return value used if no finished pathmaps are found
|
||||
@@ -189,7 +189,7 @@ SUBSYSTEM_DEF(pathfinder)
|
||||
/// Takes a set of pathfind info, returns all valid pathmaps that would work
|
||||
/// Takes an optional minimum range arg
|
||||
/datum/controller/subsystem/pathfinder/proc/get_valid_maps(datum/can_pass_info/pass_info, turf/target, simulated_only = TRUE, turf/exclude, age = MAP_REUSE_INSTANT, min_range = -INFINITY, include_building = FALSE)
|
||||
// Walk all the maps that match our caller's turf OR our target's
|
||||
// Walk all the maps that match our requester's turf OR our target's
|
||||
// Then hold onto em. If their cache time is short we can reuse/expand them, if not we'll have to make a new one
|
||||
var/list/valid_maps = list()
|
||||
var/oldest_time = world.time - age
|
||||
|
||||
Reference in New Issue
Block a user