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

Slow path-finding code #10229

Open
1 task done
nickshanks opened this issue Jun 18, 2024 · 3 comments
Open
1 task done

Slow path-finding code #10229

nickshanks opened this issue Jun 18, 2024 · 3 comments
Labels
bug Something in the game is not behaving as intended unconfirmed More information is needed to be sure this report is true

Comments

@nickshanks
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

The path-finding code is very slow. I think it is iterating through every StellarObject in every system once per ship for every ship in the fleet, 60 times a second.
This is most noticable when your escort fleet is 'trapped' on the other side of a Jump Drive gap without a Jump Drive.

Steps to Reproduce

  1. Load provided game
  2. Leave planet

press 'h' to prevent pathing and get your CPU back.

Expected Behavior

CPU usage would be 10%, not 450%

Screenshots

No response

Link to save file

Nicholas Shanks~250% CPU.txt
Nicholas Shanks~350% CPU.txt
Nicholas Shanks~450% when jumping.txt
Nicholas Shanks~also 250% CPU.txt

Operating System

MacOS X

Game Source

Built from source

Game Version

nickhanks/endless-sky/tree/master with unpushed changes

Additional Information

Commenting out code to find the cause, I traced it here:

AI::Step() {
	if(parent->GetSystem() != it->GetSystem())
		MoveEscort(*it, command);
}

AI::MoveEscort() {
	SelectRoute(ship, parent.GetSystem());
}

AI::SelectRoute() {
	const DistanceMap route();
}

DistanceMap::DistanceMap(const Ship &, const System *, const PlayerInfo *) {
	while(!edges.empty()) {...}
}

Now I am no mathmetician and I don't understand Graph Theory, so I am not best placed to solve this, but I believe we don't need to re-route every escort 60 times a second. An already-found path should suffice until the graph of known systems changes, or the Orders change, or the player or escort moves to a new system (is that the same as 'graph changes'?)
I think caching whether a system has a wormhole would be helpful too.

@nickshanks nickshanks added bug Something in the game is not behaving as intended unconfirmed More information is needed to be sure this report is true labels Jun 18, 2024
@TheGiraffe3
Copy link
Contributor

TheGiraffe3 commented Jun 18, 2024

#9587. Not exactly the same, but pretty close.

@eebop
Copy link
Contributor

eebop commented Jun 18, 2024

I've got a planned fix and will pr it sometime soon - a major improvement via caching (I am away from my computer for the next couple days)

@tibetiroka
Copy link
Member

Related: #6940

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something in the game is not behaving as intended unconfirmed More information is needed to be sure this report is true
Projects
None yet
Development

No branches or pull requests

4 participants