forked from ChaoticOnyx/OnyxBay
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tweak(astar): port tg version of AStar
- Loading branch information
Showing
31 changed files
with
1,518 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Define set that decides how an atom will be scanned for astar things | ||
/// If set, we make the assumption that CanAStarPass() will NEVER return FALSE unless density is true | ||
#define CANASTARPASS_DENSITY 0 | ||
/// If this is set, we bypass density checks and always call the proc | ||
#define CANASTARPASS_ALWAYS_PROC 1 | ||
|
||
/** | ||
* A helper macro to see if it's possible to step from the first turf into the second one, minding things like door access and directional windows. | ||
* If you really want to optimize things, optimize this, cuz this gets called a lot. | ||
* We do early next.density check despite it being already checked in LinkBlockedWithAccess for short-circuit performance | ||
*/ | ||
#define CAN_STEP(cur_turf, next, simulated_only, pass_info, avoid) (next && !next.density && !(simulated_only && SSpathfinder.space_type_cache[next.type]) && !cur_turf.LinkBlockedWithAccess(next, pass_info) && (next != avoid)) | ||
|
||
#define DIAGONAL_DO_NOTHING NONE | ||
#define DIAGONAL_REMOVE_ALL 1 | ||
#define DIAGONAL_REMOVE_CLUNKY 2 | ||
|
||
// Set of delays for path_map reuse | ||
// The longer you go, the higher the risk of invalid paths | ||
#define MAP_REUSE_INSTANT (0) | ||
#define MAP_REUSE_SNAPPY (0.5 SECONDS) | ||
#define MAP_REUSE_FAST (2 SECONDS) | ||
#define MAP_REUSE_SLOW (20 SECONDS) | ||
// Longest delay, so any maps older then this will be discarded from the subsystem cache | ||
#define MAP_REUSE_SLOWEST (60 SECONDS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
////////////////////// | ||
//datum/heap object | ||
////////////////////// | ||
|
||
/datum/heap | ||
var/list/L | ||
var/cmp | ||
|
||
/datum/heap/New(compare) | ||
L = new() | ||
cmp = compare | ||
|
||
/datum/heap/Destroy(force) | ||
for(var/i in L) // because this is before the list helpers are loaded | ||
qdel(i) | ||
L = null | ||
return ..() | ||
|
||
/datum/heap/proc/is_empty() | ||
return !length(L) | ||
|
||
//insert and place at its position a new node in the heap | ||
/datum/heap/proc/insert(A) | ||
|
||
L.Add(A) | ||
swim(length(L)) | ||
|
||
//removes and returns the first element of the heap | ||
//(i.e the max or the min dependant on the comparison function) | ||
/datum/heap/proc/pop() | ||
if(!length(L)) | ||
return 0 | ||
. = L[1] | ||
|
||
L[1] = L[length(L)] | ||
L.Cut(length(L)) | ||
if(length(L)) | ||
sink(1) | ||
|
||
//Get a node up to its right position in the heap | ||
/datum/heap/proc/swim(index) | ||
var/parent = round(index * 0.5) | ||
|
||
while(parent > 0 && (call(cmp)(L[index],L[parent]) > 0)) | ||
L.Swap(index,parent) | ||
index = parent | ||
parent = round(index * 0.5) | ||
|
||
//Get a node down to its right position in the heap | ||
/datum/heap/proc/sink(index) | ||
var/g_child = get_greater_child(index) | ||
|
||
while(g_child > 0 && (call(cmp)(L[index],L[g_child]) < 0)) | ||
L.Swap(index,g_child) | ||
index = g_child | ||
g_child = get_greater_child(index) | ||
|
||
//Returns the greater (relative to the comparison proc) of a node children | ||
//or 0 if there's no child | ||
/datum/heap/proc/get_greater_child(index) | ||
if(index * 2 > length(L)) | ||
return 0 | ||
|
||
if(index * 2 + 1 > length(L)) | ||
return index * 2 | ||
|
||
if(call(cmp)(L[index * 2],L[index * 2 + 1]) < 0) | ||
return index * 2 + 1 | ||
else | ||
return index * 2 | ||
|
||
//Replaces a given node so it verify the heap condition | ||
/datum/heap/proc/resort(A) | ||
var/index = L.Find(A) | ||
|
||
swim(index) | ||
sink(index) | ||
|
||
/datum/heap/proc/List() | ||
. = L.Copy() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.