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$.,")\ |
Comments
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
Likes: Apollo14
https://deluxepixel.com