Open Jiminibob opened 3 years ago
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
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.
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;
}
}
`
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 Great stuff! Sadly the execution still takes about 500ms. Have you been able to make progress on the performance?
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
it's been in use for a while now no issues
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