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

Fix: 'Cache' top and bottom lines of textfile viewer to avoid overdraw. #9131

Merged
merged 2 commits into from Apr 29, 2021

Conversation

@PeterN
Copy link
Member

@PeterN PeterN commented Apr 28, 2021

Motivation / Problem

The text file viewer calculated the number of lines required to set the scrollbar, but did not retain this information, so this was recalculated on every draw operation. This includes overdrawing text outside the bounds of the current scroll position.

This is a considerable performance drag, although possibly only really noticeable with a debug build. For me a large file took over a second for each redraw.

Description

With this change the top and bottom lines for each line of text are remembered, and reflowing is avoided where possible. Text outside the current scroll bounds is not drawn.

Additionally the scroll interval is now based on text lines instead of pixel lines, which increases the text capacity depending on the font size.

Limitations

This most likely stomps all over #7786, however this is a more specific change and smaller in scope. What this does is also very similar to parts of that change.

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')
PeterN added 2 commits Apr 28, 2021
The text file viewer calculated the number of lines required to set the scrollbar, but did not retain this information, so this was recalculated on every draw operation. This includes overdrawing text outside the bounds of the current scroll position.

With this change the top and bottom lines for each line of text are remembered, and reflowing is avoided where possible. Text outside the current scroll bounds is not drawn.
Additionally the scroll interval is now based on text lines instead of pixel lines, which increases the text capacity depending on the font size.
Text files with more than 64k wrapped lines would exceed the scrollbar capacity and cause an assert. This is harder to reach now that the scrollbar counts lines instead of pixels.
@PeterN PeterN force-pushed the textfile-cache-reflow branch from e231434 to 0981ec6 Apr 28, 2021
@PeterN PeterN merged commit 0b460bf into OpenTTD:master Apr 29, 2021
12 checks passed
@PeterN PeterN deleted the textfile-cache-reflow branch Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants