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

Fix #10452: Limit river generation max_search_nodes #11544

Merged

Conversation

SamuXarick
Copy link
Contributor

@SamuXarick SamuXarick commented Dec 5, 2023

Prevent long stalls during river generation by capping the maximum search nodes to be the same as that defined in NPF.

Motivation / Problem

See #10452 (comment)

Terraforming occurs during river generation which causes issues for the pathfinding. If the tile the pathfinder is working with is no longer flat, a long stall occurs due to the pathfinding doing an exhaustive search around that tile, trying to connect a river path to it and ultimately failing in the end, leaving a river disconnected somewhere along the way from the spring to the sea.

The stall can last up to 3-5 minutes until all paths are tried.
https://github.com/OpenTTD/OpenTTD/assets/43006711/cbb18259-51cc-4f18-9b4e-3248334f4f11

Description

This PR fixes the stall, by preventing the pathfinder from initializing max_search_nodes as 0 (= infinite). Since AyStar is used, I created a constant with the default value equal to that of both NPF and YAPF and have it referred.

Limitations

This does not fix the river becoming disconnected due to terraforming.

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR touches english.txt or translations? Check the guidelines
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, game_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

Copy link
Member

@2TallTyler 2TallTyler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable.

I don't think it makes sense for players to be able to change this limit, so it could be hardcoded to 10,000 (the default for both NPF and YAPF).

src/landscape.cpp Outdated Show resolved Hide resolved
src/pathfinder/npf/aystar.h Outdated Show resolved Hide resolved
src/pathfinder/npf/aystar.cpp Outdated Show resolved Hide resolved
@SamuXarick SamuXarick force-pushed the limit-river-generation-max_search_nodes branch from e7b23a3 to b64f295 Compare December 16, 2023 23:07
…initializing

Add a constant with the default value of 10000 and have the pathfinding settings refer to it.

Add a preventative method to AyStar when it's initializing, to limit the number of max_search_nodes if left unattended.
@SamuXarick SamuXarick force-pushed the limit-river-generation-max_search_nodes branch from b64f295 to ee32c2a Compare December 16, 2023 23:20
@glx22 glx22 merged commit c05ffb2 into OpenTTD:master Dec 17, 2023
20 checks passed
@SamuXarick SamuXarick deleted the limit-river-generation-max_search_nodes branch March 8, 2024 14:11
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

4 participants