Author Topic: Font performance  (Read 3512 times)

0 Members and 1 Guest are viewing this topic.

Offline 40wattstudio

  • Newbie
  • Posts: 82
    • View Profile
    • 40wattstudio
Font performance
« 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?

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Font performance
« Reply #1 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
Programming isn't difficult, only it's  consuming time and coffee

FellippeHeitor

  • Guest
Re: Font performance
« Reply #2 on: March 25, 2020, 08:16:14 pm »
Make sure you're not loading the fonts inside a loop.

Offline 40wattstudio

  • Newbie
  • Posts: 82
    • View Profile
    • 40wattstudio
Re: Font performance
« Reply #3 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.

Offline 40wattstudio

  • Newbie
  • Posts: 82
    • View Profile
    • 40wattstudio
Re: Font performance
« Reply #4 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?

Offline 40wattstudio

  • Newbie
  • Posts: 82
    • View Profile
    • 40wattstudio
Re: Font performance
« Reply #5 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!

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: Font performance
« Reply #6 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.
In order to understand recursion, one must first understand recursion.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Font performance
« Reply #7 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.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!