GameScope: Refactor GSARR indexing #1028
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR refactors how we parse and index GSARR in
GameScopeGui
. Previously we were hardcoding each index, and this was brittle. When we added a new element, everything had to get shifted down by one. This PR uses a "relative positioning" system, where everything indexed relative to the index of the heading above it. We calculate heading positions using a hardcoded number of elements per section.If we want to add a new element to, say, the HDR section, we can do it much more simply now. All we have to do is bump
GSHDROPTSLEN
by1
, and then add the element in. To position the element we can calculate its index based on its number in the section (i.e. if it's the 5th section, then it'll beGSFILTERINGHEADING + 5
). If a new element is inserted into the middle of a section, we only need to re-organise the indexes in that section and not the whole list. Instead of changing all 60+ lines for how we parse the GameScope variables out ofGSARR
, we only need to change a few lines. At worst if something went at the top of the section, we would only need to update the indexes for the variables in that section (as well as the variable tracking the length of the section, since this is used to position the other headings).It is much easier to format things this way, and having the variable tracking the length of each section is also a good way for us to check our work and make sure each section is the correct and expected length.
In testing, this seems to work with existing and fresh GameScope configurations. Everything is parsed correctly from existing configs, even complex ones like
GAMESCOPE_ARGS="-w 1920 -h 1080 -W 3840 -H 2160 -r 144 -f --force-grab-cursor -s 7 -F fsr -S stretch -m 3 --fsr-sharpness 8 -C 5 --rt --"
. I will do more testing though and if this works fine, I will bump the version and merge.