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: Scale sprite font size once. #9158

Merged
merged 2 commits into from May 1, 2021

Conversation

PeterN
Copy link
Member

@PeterN PeterN commented May 1, 2021

Motivation / Problem

Calling GetHeight() on a sprite font calls ScaleFontTrad() every time. This cascades back to all GetCharacterHeight(FS_xxx) and all FONT_HEIGHT_xxx calls.
Scaling is not expensive, but it does not change either -- the cache is reset if the zoom level is changed. This call is also a virtual method call.

Description

The change sets the scaled font height once on init instead of every call to GetHeight(). This also avoids the need for GetHeight() to be a virtual method call.

Also included slightly randomly is a clean up to remove a direct access to the _default_font_height array in the FreeTypeFontCache.

Limitations

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 May 1, 2021 09:23
This makes this part of font size setup in FreeTypeFontCache consist with OSX and Windows variants.
…ll to GetHeight().

Scaling is not expensive, but it does not change either, and this avoids the need for a virtual method call. This cascades back to all GetCharacterHeight(FS_xxx) and FONT_HEIGHT_xxx calls.
Copy link
Member

@LordAro LordAro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

@PeterN PeterN merged commit 9c6c0a0 into OpenTTD:master May 1, 2021
@PeterN PeterN deleted the default-font-size branch May 1, 2021 09:41
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