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

Codechange: differentiate in SettingDescBase implementations for different classes of settings #9288

Merged
merged 19 commits into from May 27, 2021

Conversation

rubidium42
Copy link
Contributor

@rubidium42 rubidium42 commented May 22, 2021

Motivation / Problem

String settings cannot be validated before they are getting set. To make this possible different implementations of OnChange with different types are needed. This is the first step into getting to a place where that distinction can be made, and proper validations can be performed on settings.

Description

Split the SettingDescBase into a number of distinct sub classes with their own implementations of some common functionality.
Put the setting arrays into initializer_lists, so iterating over them can be done more easily.
Replaced the custom string decoding for the one-to-many lookups by actually using a vector of the allowed values and comparing against that.

These change will be followed by rubidium42/OpenTTD@setting-classes...rubidium42:setting-prechange-check to make the pre checks an actual reality, but I'm trying to limit the PRs in size so they will be separate.

Limitations

None as far as I know.

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 affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

src/settings_internal.h Outdated Show resolved Hide resolved
@glx22
Copy link
Contributor

glx22 commented May 22, 2021

Oh and there's a nice regression failure, probably incorrect parsing of the settings chunk.

@rubidium42
Copy link
Contributor Author

Oh and there's a nice regression failure, probably incorrect parsing of the settings chunk.

Today I learned the default save game is so old it does not even contain the PATS chunk, but yeah I broke save game compatibility somewhere somehow. Though the first push was mostly to get a feeling whether the other compilers would accept the code, as I have been battling with that mostly for the last week.

@rubidium42 rubidium42 force-pushed the setting-classes branch 5 times, most recently from ebbd2b5 to 07eed85 Compare May 23, 2021 17:55
@rubidium42 rubidium42 marked this pull request as ready for review May 23, 2021 18:22
@rubidium42 rubidium42 force-pushed the setting-classes branch 2 times, most recently from ec2fb22 to cbaa8f1 Compare May 24, 2021 13:36
src/settings_internal.h Outdated Show resolved Hide resolved
src/settings_internal.h Outdated Show resolved Hide resolved
Copy link
Member

@TrueBrain TrueBrain left a comment

Choose a reason for hiding this comment

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

This PR is rather difficult to review. I am not blaming you or anything, as I think it is needed and awesome work. I also have no suggestions how to make reviewing easier .. just mentioning that I gave up half-way through, as I was going blind :D Sorry .. I did my best :)

src/settings.cpp Show resolved Hide resolved
src/settings_internal.h Outdated Show resolved Hide resolved
src/settings.cpp Show resolved Hide resolved
src/settings.cpp Outdated Show resolved Hide resolved
src/settings.cpp Outdated Show resolved Hide resolved
src/settings.cpp Outdated Show resolved Hide resolved
src/settings.cpp Outdated Show resolved Hide resolved
src/settings.cpp Show resolved Hide resolved
Copy link
Member

@TrueBrain TrueBrain left a comment

Choose a reason for hiding this comment

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

Made it through \o/ I think .. :)

src/settings.cpp Show resolved Hide resolved
src/settings.cpp Outdated Show resolved Hide resolved
src/settings_internal.h Outdated Show resolved Hide resolved
src/settings_internal.h Outdated Show resolved Hide resolved
src/settings_internal.h Show resolved Hide resolved
@rubidium42 rubidium42 force-pushed the setting-classes branch 2 times, most recently from 7e47f55 to 3b2030e Compare May 27, 2021 15:36
src/settings.cpp Outdated Show resolved Hide resolved
src/settings.cpp Show resolved Hide resolved
The comments for SettingDescType; it is a byte, so not 4 bytes and since it is not a flag there are about 250 other possibilities left instead of 9.
SettingGuiFlag is uint16 so has 2 bytes allocated.
SettingDescGlobVarList and related comments imply that global vars cannot be used elsewhere, but they are used for settings just fine. Even then the type is not used anywhere else but the definition of the table.
Not using vectors as those require copying from the initializer list and that
makes unique_ptrs to the actual SettingDesc objects later impossible.
Copy link
Member

@TrueBrain TrueBrain left a comment

Choose a reason for hiding this comment

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

Pretty sure I still don't understand halve of this, but code-wise I couldn't find anything else to bitch about :P So YOLO!

(I also tested it locally, and it seems to do what it suggests, and doesn't trigger address sanitizer of GCC)

@rubidium42 rubidium42 merged commit 8372c67 into OpenTTD:master May 27, 2021
@rubidium42 rubidium42 deleted the setting-classes branch May 27, 2021 16:49
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