Codechange: simplify string formatting for the viewport #11058
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
Passing
param_1
andparam_2
around through all kinds of functions to be able to draw something onto the viewport, instead of just resolving the string and drawing that when needed.Trying to go through the string drawing for signs when signs are set to be invisible.
Description
There is a function that loops through the signs and stations to see whether they are within the bounding box of the viewport, to add them to a collection of strings to draw on the viewport. When finally drawing it determines whether they should be drawn or not. Just move this check to just before looping through the signs and stations, thus preventing some calculations.
Instead of passing string parameters via
param_1
andparam_2
parameters, just set them viaSetDParam
and resolve the string when the determination is made that the string should be shown, and use that string to actually draw on the viewport. The allocation of the string doesn't impact the performance, because theStringID
variant of the function just doesGetString
anyway, and as such it saves copyingparam_1
andparam_2
around.Doing it this way will also make it immediately possible to pass more parameters if needed, or pass string parameters as it's not custom code anymore but the main string formatting code that is used.
Limitations
None that I can think of.
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.