Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
TTFont pre-caching doesn't work? — Gideros Forum

TTFont pre-caching doesn't work?

Apollo14Apollo14 Member
edited September 2019 in Bugs and issues
Hi guys!
Two questions on TTFonts pefomance:
1) Why TTFont pre-caching doesn't work?
SEGOE_BOLD_30 =TTFont.new("gui/fonts/segoe-ui-bold.ttf",30,"")
First time I show textfield using this font, it lags like nothing was pre-cached at all.
Isn't it supposed to pre-cache symbols when we leave blank ""?

If I specify symbols, it doesn't lag:
SEGOE_BOLD_30 =TTFont.new("gui/fonts/segoe-ui-bold.ttf",30,"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz0123456789$.,")

2) I've seen in rogue-like tutorial TTFont declarations using Macro constants.
I thought it would be faster, but it's actually slower. Why does it lag?
--regular "non-optimized" declaration (actually works faster):
SEGOE_BOLD_30 =TTFont.new("gui/fonts/segoe-ui-bold.ttf",30,"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz0123456789$.,")
SEGOE_BOLD_36 =TTFont.new("gui/fonts/segoe-ui-bold.ttf",36,"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz0123456789$.,")
SEGOE_BOLD_150 =TTFont.new("gui/fonts/segoe-ui-bold.ttf",150,"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz0123456789$.,")
--"optimized" version (I thought it's faster, but it's actually slower):
SEGOE_BOLD_30 @ \TTFont.new("gui/fonts/segoe-ui-bold.ttf",30,"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz0123456789$.,")\
SEGOE_BOLD_36 @ \TTFont.new("gui/fonts/segoe-ui-bold.ttf",36,"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz0123456789$.,")\
SEGOE_BOLD_150 @ \TTFont.new("gui/fonts/segoe-ui-bold.ttf",150,"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz0123456789$.,")\
> Newcomers roadmap: from where to start learning Gideros
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)


  • hgy29hgy29 Maintainer
    Accepted Answer
    Hi @Apollo14,

    1) If you specify an empty string for pre-caching, Gideros cache symbols on-the-fly, when they are first needed. First text will lag, but subsequent will be fast. This mode was meant to benefit from caching even if you don't know which symbols will be needed beforehand. So the behaviour you see is normal.

    2) Don't use macros this way! macros acts as if the content they evaluate to was substitued in each macro usage. In your case, you are re-creating the TTFont objects each time you want to use them if you use macro. Better cache them in a variable once and for all.

    Likes: Apollo14, antix

    +1 -1 (+2 / -0 )Share on Facebook
  • SinisterSoftSinisterSoft Maintainer
    Accepted Answer
    The empty string method is cache on the fly is great for when you use multiple fonts for different languages - it makes Gideros better (and much simpler for the programmer) than any other system I know of for that kind of thing.

    Likes: Apollo14

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.