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

Allow pre-rendering character sets in DynamicFont to avoid stalls during gameplay #2021

Closed
Calinou opened this issue Dec 25, 2020 · 4 comments
Milestone

Comments

@Calinou
Copy link
Member

Calinou commented Dec 25, 2020

Describe the project you are working on

The Godot editor 🙂

Describe the problem or limitation you are having in your project

DynamicFont can introduce stalls during gameplay when new characters are used, since they need to be rendered on the fly. These stalls are mainly noticeable on mobile/web platforms due to their slow CPUs.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Allow pre-rendering character sets in a DynamicFont to avoid stalls during gameplay. This moves the rendering cost to happen before anything in the game has started, which is arguably less annoying than stalls during gameplay.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Add a "Prerender Character Set" enum property to DynamicFont with the following values:

  • Disabled
  • Numbers + Symbols (0-9 + common symbols: + - * / : ; ,)
  • ASCII (includes the above numbers and symbols, sufficient for English)
  • Latin-1 (includes characters required for English, French, German, Spanish, …)
  • Some way to specify a custom character set? It's not exactly reasonable to prerender the whole Unicode character set due to its size.

Wider character sets allow for better language support at the cost of longer prerendering times and higher memory usage.

The old BitmapFont importer in Godot 2.1 also offered similar functionality to restrict character sets (including a way to reference a text file that contained the characters you wanted to render).

A question that remains is: Should we enable prerendering by default? I'd argue we should use ASCII prerendering by default (since it's very likely to help against jank in almost all situations), but there may be reasons not to do so.

If this enhancement will not be used often, can it be worked around with a few lines of script?

Thanks to godotengine/godot#40491 (cc @RandomShaper), it can be worked around decently, but I'd still argue this should be a built-in feature to ensure a jank-free experience out of the box.

Is there a reason why this should be core and not an add-on in the asset library?

See above.

@jonbonazza
Copy link

Would it be better to instead have a new resource type that is a serialized prerendered character set?

@Calinou
Copy link
Member Author

Calinou commented Dec 27, 2020

Would it be better to instead have a new resource type that is a serialized prerendered character set?

I'm not sure about that, as it makes it quite harder for users to reason about DynamicFont usage. If you have to swap the resource to use a prerendered DynamicFont, it's not quite as transparent and easy to use as merely toggling a property.

The prerendering should happen when the font is first used. It's not a problem if it happens while the game is running, but it must be done "all at once" as early as possible, rather than rendering new characters as they appear on screen.

@Calinou

This comment has been minimized.

@Calinou Calinou closed this as completed Mar 30, 2021
@Calinou Calinou added this to the 4.0 milestone Mar 30, 2021
@Calinou Calinou reopened this Apr 7, 2021
@Calinou Calinou removed the topic:core label Jul 1, 2021
@bruvzg
Copy link
Member

bruvzg commented Aug 27, 2021

Implemented in godotengine/godot#51908

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants