Change: Reduce real sprite groups if possible. #9344
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.
Motivation / Problem
Many NewGRF features using Act 3/2/1 chains don't require loading/loaded stages (which are determined by the
RealSpriteGroup
), however by spec they are still created, and evaluated on every chain resolve.For features that do use loading/loaded stages, it is also fairly common for the same sprite or callback result to be returned.
Description
This change skips creating a RealSpriteGroup if there is only one result, or if all results are the same.
It also deduplicates the different ResolveReal() resolver function for resolvers which don't care about loading/loaded stages.
Limitations
The deduplication does not take account of the order of checking loading/loaded results which was previously inconsistent, therefore it's possible that if loading/loaded stages were supplied for a feature that does not expect it, a different result will now be used. But if this is the case then I think NewGRF is out-of-spec anyway.
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.