I have a bunch of questions about performance. How "expensive" are the following commands?
sqrt
updatesector
cansee
setarray
setvarvar (specifically pulling data from an array)
I'm trying to improve performance on my A* pathfinding, and I'm trying to identify which operations are very "expensive" that I should avoid or limit my usage of. I am calling these potentially thousands of times for every enemy on a given frame. There's not frequently frame drops and I am doing what I can to limit the frequency for these calls, but I'm curious which of these are the most heavy on CPU.
I am using "sqrt" for a simple Euclidian distance calculation, as dist / ldist takes actors and not X/Y positions:
defstate astardist
{
setvarvar ASTARDELTAX ASTARPOSX
subvarvar ASTARDELTAX NODEPOSX
abs ASTARDELTAX
setvarvar ASTARDELTAY ASTARPOSY
subvarvar ASTARDELTAY NODEPOSY
abs ASTARDELTAY
mulvarvar ASTARDELTAX ASTARDELTAX
mulvarvar ASTARDELTAY ASTARDELTAY
addvarvar ASTARDELTAX ASTARDELTAY
sqrt ASTARDELTAX ASTARDIST
}
ends
Is there a cheaper method of getting the distance between 2 arbitrary points in space?
I'm using "updatesector" in conjunction with "cansee" to validate if 2 points in space are valid (IE not in the void):
// Ignore any point we don't have line of sight to
getactor[THISACTOR].sectnum ASTARSECT
updatesector ASTARPOSX ASTARPOSY ASTARSECT
getsector[ASTARSECT].floorz ASTARPOSZ
subvar ASTARPOSZ 6144
getactor[THISACTOR].sectnum NODESECT
updatesector NODEPOSX NODEPOSY NODESECT
getsector[NODESECT].floorz NODEPOSZ
subvar NODEPOSZ 6144
cansee ASTARPOSX ASTARPOSY ASTARPOSZ ASTARSECT NODEPOSX NODEPOSY NODEPOSZ NODESECT ASTARCANSEE
I need to validate line-of-sight between 2 points, is there a less expensive method than this?
I don't have concise examples of using "setarray" and "setvarvar" for pulling values from an array, but suffice it to say that 2 separate arrays have their values checked and/or set potentially thousands of times during each loop. I know that this sucks, and I try to use a reference to the array value (rather than comparing it directly, IE ifvarvarl VAR ARRAY[INDEX]), but I am not sure I can improve things further. How much of a CPU hit could this be causing?