mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Scale sprite font height once on init instead of every call to GetHeight().
Scaling is not expensive, but it does not change either, and this avoids the need for a virtual method call. This cascades back to all GetCharacterHeight(FS_xxx) and FONT_HEIGHT_xxx calls.pull/9165/head
parent
ce55cd0ce7
commit
9c6c0a0966
|
@ -87,7 +87,6 @@ public:
|
||||||
virtual void ClearFontCache();
|
virtual void ClearFontCache();
|
||||||
virtual const Sprite *GetGlyph(GlyphID key);
|
virtual const Sprite *GetGlyph(GlyphID key);
|
||||||
virtual uint GetGlyphWidth(GlyphID key);
|
virtual uint GetGlyphWidth(GlyphID key);
|
||||||
virtual int GetHeight() const;
|
|
||||||
virtual bool GetDrawGlyphShadow();
|
virtual bool GetDrawGlyphShadow();
|
||||||
virtual GlyphID MapCharToGlyph(WChar key) { assert(IsPrintable(key)); return SPRITE_GLYPH | key; }
|
virtual GlyphID MapCharToGlyph(WChar key) { assert(IsPrintable(key)); return SPRITE_GLYPH | key; }
|
||||||
virtual const void *GetFontTable(uint32 tag, size_t &length) { length = 0; return nullptr; }
|
virtual const void *GetFontTable(uint32 tag, size_t &length) { length = 0; return nullptr; }
|
||||||
|
@ -102,6 +101,7 @@ public:
|
||||||
SpriteFontCache::SpriteFontCache(FontSize fs) : FontCache(fs), glyph_to_spriteid_map(nullptr)
|
SpriteFontCache::SpriteFontCache(FontSize fs) : FontCache(fs), glyph_to_spriteid_map(nullptr)
|
||||||
{
|
{
|
||||||
this->InitializeUnicodeGlyphMap();
|
this->InitializeUnicodeGlyphMap();
|
||||||
|
this->height = ScaleFontTrad(this->GetDefaultFontHeight(this->fs));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -177,6 +177,7 @@ void SpriteFontCache::ClearGlyphToSpriteMap()
|
||||||
void SpriteFontCache::ClearFontCache()
|
void SpriteFontCache::ClearFontCache()
|
||||||
{
|
{
|
||||||
Layouter::ResetFontCache(this->fs);
|
Layouter::ResetFontCache(this->fs);
|
||||||
|
this->height = ScaleFontTrad(this->GetDefaultFontHeight(this->fs));
|
||||||
}
|
}
|
||||||
|
|
||||||
const Sprite *SpriteFontCache::GetGlyph(GlyphID key)
|
const Sprite *SpriteFontCache::GetGlyph(GlyphID key)
|
||||||
|
@ -193,11 +194,6 @@ uint SpriteFontCache::GetGlyphWidth(GlyphID key)
|
||||||
return SpriteExists(sprite) ? GetSprite(sprite, ST_FONT)->width + ScaleFontTrad(this->fs != FS_NORMAL ? 1 : 0) : 0;
|
return SpriteExists(sprite) ? GetSprite(sprite, ST_FONT)->width + ScaleFontTrad(this->fs != FS_NORMAL ? 1 : 0) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SpriteFontCache::GetHeight() const
|
|
||||||
{
|
|
||||||
return ScaleFontTrad(this->height);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SpriteFontCache::GetDrawGlyphShadow()
|
bool SpriteFontCache::GetDrawGlyphShadow()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -45,7 +45,7 @@ public:
|
||||||
* Get the height of the font.
|
* Get the height of the font.
|
||||||
* @return The height of the font.
|
* @return The height of the font.
|
||||||
*/
|
*/
|
||||||
virtual int GetHeight() const { return this->height; }
|
inline int GetHeight() const { return this->height; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the ascender value of the font.
|
* Get the ascender value of the font.
|
||||||
|
|
Loading…
Reference in New Issue