Here's what I suggest. Create a Font Manager, which will load and free all fonts for you.
Make a function so you can do something like this:
Code: Select all
FontManager->GetFont("name.ttf", size);
And this function should load the font in that size if it's not already loaded. You could also implement reference counting, so then every time the font is called, a +1 goes to the ref, and everytime something is done using it, a -1 to the ref count.
In this way, when the count hits 0, you actually free the resource.
So let's say there's a standard game font you use for conversation boxes or such... I'll say it's Times New Roman size 12 for sake of example. So since you'll use this font throughout the game, you'll want it to always be in mem so you don't have to wait, so in your game initialization you do:
Code: Select all
FontManager->LoadFont("Times New Roman.ttf", 12);
and in your quit stuff:
Code: Select all
FontManager->ReleaseFont("Times New Roman.ttf", 12);
This way the reference count is at least 1 while the game is running.
I'm not too sure of what you'd store it in, because you essentially have 2 values that can be unique (font and size). I think multimap would work well though. Just have the key as a string, so then you can access all the sizes of that font you have loaded...
Actually, though, I think you can do a map of maps (essentially a 2d map?) So you could do something like: Fonts[font][size] To get your specific font...
Well that's all the thoughts I have on the matter...