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: simplify string formatting for the viewport #11058

Merged
merged 2 commits into from Jun 23, 2023

Conversation

rubidium42
Copy link
Contributor

Motivation / Problem

Passing param_1 and param_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 and param_2 parameters, just set them via SetDParam 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 the StringID variant of the function just does GetString anyway, and as such it saves copying param_1 and param_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.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR touches english.txt or translations? Check the guidelines
  • 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')

@rubidium42 rubidium42 merged commit 321f016 into OpenTTD:master Jun 23, 2023
18 checks passed
@rubidium42 rubidium42 deleted the viewport-string-improvements branch June 23, 2023 04:48
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

2 participants