QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: 40wattstudio on March 25, 2020, 07:34:33 pm

Title: Font performance
Post by: 40wattstudio on March 25, 2020, 07:34:33 pm
Started experimenting with fonts and the various statements (_FONTLOAD, _FONT, etc). Needless to say I was utterly shocked at how much the main game loop bogs down after trying to display the font.
I switched to monospace per the Wiki and that helped a lot.

Is there anything else that can be done to use fancy fonts without killing performance too much?
Title: Re: Font performance
Post by: TempodiBasic on March 25, 2020, 08:14:04 pm
Hi  40wattstudio

I have got no so much of the issue...
can you post an example code?

Thanks
Title: Re: Font performance
Post by: FellippeHeitor on March 25, 2020, 08:16:14 pm
Make sure you're not loading the fonts inside a loop.
Title: Re: Font performance
Post by: 40wattstudio on March 25, 2020, 08:19:49 pm
Code: QB64: [Select]
  1.     fontstyle = "monospace"
  2.     gamefont = _LOADFONT("\fonts\Demo_Fonts\latticedemo.otf", 16, fontstyle)
  3.     . . .
  4.  
  5.      DO ' main game loop
  6.  
  7.     LOCATE 1, 1
  8.     IF gamefont THEN _FONT gamefont
  9.     PRINT "HEALTH: "; player.HEALTH
  10.  
  11.     LOOP
  12.  

If I run the above without loading any fonts, just the default PRINT text, the game runs absolutely fine. But if I load in that custom font, especially without monospace, the game slows down.
Title: Re: Font performance
Post by: 40wattstudio on March 25, 2020, 08:21:37 pm
Make sure you're not loading the fonts inside a loop.

I got this part . . .

Code: QB64: [Select]
  1.     fontstyle = "monospace"
  2.     gamefont = _LOADFONT("path\fonts\Demo_Fonts\latticedemo.otf", 16, fontstyle)
  3.  

. . . outside the main game loop. Would just loading _FONT inside a loop cause it to slow down?
Title: Re: Font performance
Post by: 40wattstudio on March 25, 2020, 11:55:54 pm
I tried two more fonts (one .otf and one .ttf) and performance was fine with both of those. The only difference is that those two fonts were free and the original font was a demo with a small watermark.
Still baffling how a 62kb .otf file can slow down a game. Anyways, I found a different font that works better so I'm going to stick with that.
Thanks for the feedback!
Title: Re: Font performance
Post by: TerryRitchie on March 26, 2020, 12:12:08 am
You are using the _FONT statement over and over again in a loop. Only need to use _FONT once outside your loop. There are no performance issues with any of the font commands as I use them all the time.
Title: Re: Font performance
Post by: SMcNeill on March 26, 2020, 12:25:30 am
Try:

    IF gamefont THEN
        IF_FONT <> gamefont THEN _FONT gamefont
    END IF


Only change the font if it's not the current one loaded and ready for use.