easystarjs icon indicating copy to clipboard operation
easystarjs copied to clipboard

Adds option to 'find nearest' when target tile is unacceptable

Open Jiminibob opened this issue 3 years ago • 6 comments

Not sure if this is the most elegant approach, but is my attempt at 'Moving within range of target'

https://github.com/prettymuchbryce/easystarjs/issues/75

Jiminibob avatar Aug 27 '21 15:08 Jiminibob

Not sure if this is the most elegant approach, but is my attempt at 'Moving within range of target'

#75

you legend, i was literally just about to write this... testing now

aJamDonut avatar Aug 30 '21 01:08 aJamDonut

Sadly I find several performance issues with the solution, due to the fact it essentially loops over the entire node list multiple times during its calculation. It would be better if this could calculate the check during the first calculate and return early or something similar.

image

This sort fuction and the following loop are causing the issue.

`instance.storeList.sort(function(a, b){ if( a.simpleDistanceToTarget === b.simpleDistanceToTarget) return 0; return a.simpleDistanceToTarget < b.simpleDistanceToTarget ? -1 :1 }) // loop through and find best result var closestDist = instance.storeList[0].simpleDistanceToTarget; var targetNode, targetCost; for(var i = 0; i < instance.storeList.length; i++){

                    if(instance.storeList[i].simpleDistanceToTarget > closestDist ) break;

                    if(!targetNode || targetCost > instance.storeList[i].costSoFar){
                        targetNode = instance.storeList[i];
                        targetCost = instance.storeList[i].costSoFar;
                    }
                }

`

aJamDonut avatar Aug 30 '21 02:08 aJamDonut

yah, that's not pretty :/

Updated to check 'nearest' during the main look up and cache it ( kills a few of those loops ). See if that feels better

Jiminibob avatar Aug 30 '21 10:08 Jiminibob

@Jiminibob Great stuff! Sadly the execution still takes about 500ms. Have you been able to make progress on the performance?

nithiz avatar Nov 15 '21 20:11 nithiz

sorry for the old response, i wrote it later down the line and forgot about this.

commit here, if anyone wants it i might make a pr

https://github.com/aJamDonut/CustomStar/commit/ae4e8fdb7e23bd39049a06df1092da55ee4ce3ad

aJamDonut avatar Dec 20 '23 03:12 aJamDonut

it's been in use for a while now no issues

aJamDonut avatar Dec 20 '23 03:12 aJamDonut