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

Load campaign data only once #1710

Merged
merged 8 commits into from
Nov 11, 2024

Conversation

Flamefire
Copy link
Member

This fixes #1705 but is a larger rework to make campaign handling easier and more flexible.

The reason for the bug was that the campaign file is loaded repeatedly, especially in the draw call to determine whether to draw the image.

So load data for all campaigns when opening the capaign selection window.
We don't rescan the folders while the window is open so there is no need to load the lua files multiple times.

If we pass the parsed campaign to the mission selection screen we can also get rid of the invisible column for the filepath.
Finally we can load all resources (images) in one go.
The 2 mission selection classes share some code and essentially the same functionality and the difference in naming doesn't make it clear which is which.
Especially problematic is the reliance on the "mission map" in the campaign description which may lead to an empty screen if
dskCampaignMissionMapSelection is instantiated in absence of that.
So just merge them so the campaign selection doesn't need to decide which one to use and the screen can use the representation that is available, i.e. either a map to select an area or the list as a fallback. The result looks exactly the same.

I noticed that we can rather use std::optional in 2 places for improved semantics. When modifying the test I noticed that the whole project gets recompiled instead of only libGamedata (I moved the test to the corresponding test suite) which was due to some superflous dependencies in CMake.

@Flamefire Flamefire requested a review from Flow86 October 21, 2024 12:18
@Flamefire Flamefire force-pushed the fix-campaign-load-dsk branch 4 times, most recently from a2b2f01 to bbf6420 Compare October 23, 2024 15:56
doc/AddingCustomCampaign.md Outdated Show resolved Hide resolved
The test doesn't contain on s25Main so we can reduce the amount of
compilation required.
Also move the campaign test out of the s25Main tests.
Now the image is either a non-empty string or `nullopt`
Load data for all campaigns when opening the capaign selection window.
We don't rescan the folders while the window is open so there is no need
to load the lua files multiple times.
Especially the draw code for the map image loads the current campaign
on every draw call to determine what is to be drawn. This also spams the
log with messages such as missing languages.

If we pass the parsed campaign to the mission selection screen we can
also get rid of the invisible column for the filepath.
Finally we can load all ressources (images) in one go.

Fixes Return-To-The-Roots#1705
Avoid use of sentinel values in presence of C++17 `std::optional`.
Makes it more obvious what is returned.

Also rename from `getCurrentSelection` for consistency with e.g.
`ctrlList` and similar and `setSelection`.
The classes share some code and essentially the same functionality.
Especially problematic is the reliance on the "mission map" in the
campagin description which may lead to an empty screen if
`dskCampaignMissionMapSelection` is instantiated in absence of that.

Additionally the difference in naming doesn't make it clear which is which.
Allow to easily identify the expected type for `GetCtrl` calls.
The mission selection map starts with nothing selected so the "Start"
button does nothing on click.
Disable it until something gets selected for better UX.
@Flow86 Flow86 enabled auto-merge (rebase) November 11, 2024 06:21
@Flow86 Flow86 disabled auto-merge November 11, 2024 06:21
@Flow86 Flow86 merged commit aa11dc5 into Return-To-The-Roots:master Nov 11, 2024
21 checks passed
@Flamefire Flamefire deleted the fix-campaign-load-dsk branch November 11, 2024 10:25
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.

Console infinite loop with specific languages in campaign menu.
2 participants