Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::Font incomplete loading  (Read 3370 times)

0 Members and 1 Guest are viewing this topic.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
sf::Font incomplete loading
« on: October 06, 2012, 01:37:25 pm »
According to the documentation, sf::Font is not loaded completely in loadFromMemory() and loadFromStream(), I remember you saying that glyphs are loaded on demand. I think the same applies to loadFromFile(), so I would state in the doc that SFML requires read access to the file throughout the font's lifetime.

Furthermore, wouldn't it be more consistent with respect to sf::Music, if the functions were called open...() instead of load...()? Like this, the semantics are directly visible.
« Last Edit: October 06, 2012, 01:39:47 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::Font incomplete loading
« Reply #1 on: October 06, 2012, 06:33:01 pm »
Quote
According to the documentation, sf::Font is not loaded completely in loadFromMemory() and loadFromStream(), I remember you saying that glyphs are loaded on demand. I think the same applies to loadFromFile(), so I would state in the doc that SFML requires read access to the file throughout the font's lifetime.
I can't imagine a situation where the font file is moved or removed while the program is running :P
But it's already written in the tutorial, don't worry.

Quote
Furthermore, wouldn't it be more consistent with respect to sf::Music, if the functions were called open...() instead of load...()? Like this, the semantics are directly visible.
I think it's different: sf::Music uses its source continuously due to its streamed nature, which is clearly and publicly stated by its base class. sf::Font uses its source continuously because I have no choice, it's an implementation issue. But if it was technically possible, I would rather load the entire font at once.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: sf::Font incomplete loading
« Reply #2 on: October 06, 2012, 10:30:38 pm »
I can't imagine a situation where the font file is moved or removed while the program is running :P
An open file handle prevents these operations anyway. However, the font may be on an external storage device which is plugged out.

Quote
sf::Font uses its source continuously because I have no choice, it's an implementation issue. But if it was technically possible, I would rather load the entire font at once.
Ah, I thought it were only an optimization in the sense of "don't load before you need".

I see why it may be inefficient, but not technically impossible: Can't you copy the whole data to a buffer of which the lifetime is managed by the font?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::Font incomplete loading
« Reply #3 on: October 06, 2012, 11:27:44 pm »
Quote
Can't you copy the whole data to a buffer of which the lifetime is managed by the font?
Font files can take many MB.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: sf::Font incomplete loading
« Reply #4 on: October 07, 2012, 11:03:29 am »
Font files can take many MB.
Okay, so I misunderstood you.

Your decision to load data on demand however is not a pure implementation detail, since it has an effect to the API: The origin must remain valid during font usage. So if you are already sure that you won't ever change the implementation towards a complete preload, "openFromXY" might be more appropriate as it expresses there are still things to be done after the invocation.

But I see it's a bit a border case, also because sf::Font can be shared like the other resources (unlike sf::Music). Hm... Other opinions? :-\
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::Font incomplete loading
« Reply #5 on: October 07, 2012, 11:43:07 am »
Quote
So if you are already sure that you won't ever change the implementation towards a complete preload
I'm not. In SFML 1.6, glyphs were preloaded (but limited to a given character set), it changed in SFML 2.0.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: sf::Font incomplete loading
« Reply #6 on: October 07, 2012, 12:07:20 pm »
Okay, then it looks like loadFromXY() makes sense, as you can still change the implementation in SFML 2.x without breaking code (the only thing that may happen are unnecessary copies).

Thanks for the explanations! :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: