Cache font heights in a static fixed array.

This is to avoid significant per-call overhead to get font heights,
as this is performed very frequently.
This commit is contained in:
Jonathan G Rennison
2016-01-01 21:47:34 +00:00
parent b51dd34fe4
commit 5aad0b51a3
3 changed files with 18 additions and 13 deletions

View File

@@ -158,7 +158,17 @@ byte GetCharacterWidth(FontSize size, uint32 key);
byte GetDigitWidth(FontSize size = FS_NORMAL);
void GetBroadestDigit(uint *front, uint *next, FontSize size = FS_NORMAL);
int GetCharacterHeight(FontSize size);
extern int font_height_cache[FS_END];
/**
* Get height of a character for a given font size.
* @param size Font size to get height of
* @return Height of characters in the given font (pixels)
*/
inline int GetCharacterHeight(FontSize size)
{
return font_height_cache[size];
}
/** Height of characters in the small (#FS_SMALL) font. */
#define FONT_HEIGHT_SMALL (GetCharacterHeight(FS_SMALL))