Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Jiminibob
Copy link

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

#75

@aJamDonut
Copy link

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
Copy link

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;
                    }
                }

`

@Jiminibob
Copy link
Author

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

@nithiz
Copy link

nithiz commented Nov 15, 2021

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

@aJamDonut
Copy link

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

aJamDonut/CustomStar@ae4e8fd

@aJamDonut
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants