Font handling

The Death Dawn font handler is a thin wrapper around the gnarlplot font handling library. It maintains a hash map of gnarlplot font definitions, where each definition contains the name of the font, the gnarlplot font definition, and a copy of the font data as a set of gnarlplot sprites. It also maintains an ID to font name/size/colour lookup table, which allows the gameconfig script to specify which fonts, sizes and colours are used by each part of the engine, in much finer detail than simply replacing font sprite files.

Font requests

There are three ways for the game code to request a font:

  1. Using a file name, font size (0 for default), and font colour. This is deprecated, in favour of using font IDs
  2. Using a font ID. This is the preferred method.
  3. Using a font ID, but with a custom size/colour. This is for use by code that must recolour the text itself, e.g. for generic mission text.

Requests by ID will be translated into a file name, font size, and font colour triplet by an array lookup. This filename is then searched through a hashmap of loaded fonts; if an entry is found, a request is sent to gnarlplot for a handle to that font in the appropriate size and colour. The gp_font font handle that is returned is now owned by the game code, and thus must be freed when no longer needed. Generally, the font handles should be freed at the end of each per-frame usage.

Resetting the font system

Resetting the font system will free all font definitions contained in the hash map; however it is unable to free the gp_font font handles, so for the code to work correctly it is important for the game code to have freed the font handles manually. If gnarlplot has any fonts still registered as 'in use', then future font requests may return the wrong fonts (but it shouldn't crash).

Resetting will also cause the font ID -> name/size/colour lookup table to be reset. The default font will be set to the font "main", in default size, and white colour. All other entries will be left blank; but these will be redirected to the default entry should a request come through before they are defined.

Memory usage

Since a copy of the original font data is kept in memory, memory usage for a font which is only requested once will be twice as high as needed. However caching the original font data in memory is important, as otherwise the game would pause whenever a new size or colour is requested, while the font data is loaded from disc.

Potential fonts

AteUp?(+BlueVelvet?)Chunk? (Outline == bad)
Game fontSource font320x256480x352640x480
DefaultBois? (Although texture like that might work?) Buckingham? Erie? Fixed????
ScoreAteUp? Lintsec? Terminator? Chunk? Biting? Master? (Outline == bad) Fixed????
MultiAteUp? Lintsec? Terminator? Chunk? Biting? Master? (Outline == bad) Fixed????
HealthAteUp? Lintsec? Terminator? Chunk? Biting? Master? (Outline == bad) Fixed????
LivesAteUp? Lintsec? Terminator? Chunk? Biting? Master? (Outline == bad) Fixed????
ArmourAteUp? Lintsec? Terminator? Chunk? Biting? Master? (Outline == bad) Fixed????
WeaponAteUp? Lintsec? Terminator? Chunk? Biting? Master? (Outline == bad) Fixed????
TitleAteUp? Argentum? (few chars) Beyond Control? (Outline == bad) Eight? Master? (Outline == bad) Eras? Fixed????
TextBois? (Although texture like that might work?) Buckingham? Erie? Fixed????
PagerAcorn? Chunk? (Outline == bad) Digitol? (few chars) DotMatrix????
Location ???
CarEight? Optima????
PickupNeuro? (Outline == bad) Optima???
RadioBois? (Although texture like that might work?) Chunk? (Outline == bad) Optima???
ClockTerminator? Biting? (Outline == bad) Optima???

TODO:
MUST-CODE: QUICK: Add more fonts, improve existing ones (lowercase), etc. Use some free ones? http://www.dafont.com/bitmap.php
DOCS: UNKNOWN: Make it store font handles instead of/in addition to definitions? Would allow it to force-free all handles, but would cause trouble if force-free occured while the handle was in use
CODE: MED: Support for compressed/raw fonts? Would save some time during loading as it wouldn't have to be converted from Paint first, would provide more cross-platform-ness, etc.
CODE: QUICK: Update fonts_load() to only load the fonts whose names are listed in the font definition array. Will reduce memory requirements, etc. (although really it should have no effect, for if a font isn't used, why is it in the game folder?)
MUST-CODE: MED: Update pager code to take into account variable-width fonts
MUST-CODE: MED: Fix missing/incorrect characters in fonts (% in Fixed, etc.)
???
Profit!