From 0e7c5a71415c57247ee2fa3e6fa412bc742a1ed3 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 1 Oct 2004 17:25:17 +0000 Subject: [PATCH] ascii optimization --- stepmania/src/Font.cpp | 16 ++++++++++++++++ stepmania/src/Font.h | 1 + 2 files changed, 17 insertions(+) diff --git a/stepmania/src/Font.cpp b/stepmania/src/Font.cpp index ec403e2f09..f016608264 100644 --- a/stepmania/src/Font.cpp +++ b/stepmania/src/Font.cpp @@ -270,6 +270,12 @@ void Font::MergeFont(Font &f) const glyph &Font::GetGlyph( wchar_t c ) const { + ASSERT(c >= 0 && c <= 0xFFFFFF); + + /* Fast path: */ + if( c < (int) ARRAYSIZE(m_iCharToGlyphCache) && m_iCharToGlyphCache[c] ) + return *m_iCharToGlyphCache[c]; + /* Try the regular character. */ map::const_iterator it = m_iCharToGlyph.find(c); @@ -842,6 +848,16 @@ void Font::Load(const CString &sFontOrTextureFilePath, CString sChars) LOG->Warn("Font %s has no characters", sFontOrTextureFilePath.c_str()); LoadStack.pop_back(); + + if( LoadStack.empty() ) + { + /* Cache ASCII glyphs. */ + ZERO( m_iCharToGlyphCache ); + map::iterator it; + for( it = m_iCharToGlyph.begin(); it != m_iCharToGlyph.end(); ++it ) + if( it->first < (int) ARRAYSIZE(m_iCharToGlyphCache) ) + m_iCharToGlyphCache[it->first] = it->second; + } } /* diff --git a/stepmania/src/Font.h b/stepmania/src/Font.h index 999cecbbcd..46e6b98628 100644 --- a/stepmania/src/Font.h +++ b/stepmania/src/Font.h @@ -144,6 +144,7 @@ private: /* Map from characters to glyphs. (Each glyph* is part of one of pages[].) */ map m_iCharToGlyph; + glyph *m_iCharToGlyphCache[128]; /* We keep this around only for reloading. */ CString Chars;