From c1ec50e1661648d7d12c8049e4ec74f142d60915 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Fri, 29 Oct 2021 17:20:30 +0900 Subject: [PATCH] caching is back to the hashset as we don't iterate over them --- .../terrarumsansbitmap/gdx/GameFontBase.kt | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/net/torvald/terrarumsansbitmap/gdx/GameFontBase.kt b/src/net/torvald/terrarumsansbitmap/gdx/GameFontBase.kt index 8be6588..edfb523 100755 --- a/src/net/torvald/terrarumsansbitmap/gdx/GameFontBase.kt +++ b/src/net/torvald/terrarumsansbitmap/gdx/GameFontBase.kt @@ -119,7 +119,7 @@ class GameFontBase( //private val textCache = HashMap() - private data class TextCacheObj(var age: Int, val hash: Long, val glyphLayout: ShittyGlyphLayout?): Comparable { + private data class TextCacheObj(val hash: Long, val glyphLayout: ShittyGlyphLayout?): Comparable { // var disposed = false; private set fun dispose() { @@ -132,14 +132,13 @@ class GameFontBase( } } private var textCacheCap = 0 - - private val textCache = TreeMap() + private val textCache = HashMap(textCacheSize * 2) /** * Insertion sorts the last element fo the textCache */ private fun addToCache(text: CodepointSequence, linotype: Texture, width: Int) { - val cacheObj = TextCacheObj(0, text.getHash(), ShittyGlyphLayout(text, linotype, width)) + val cacheObj = TextCacheObj(text.getHash(), ShittyGlyphLayout(text, linotype, width)) if (textCacheCap < textCacheSize) { textCache[cacheObj.hash] = cacheObj @@ -155,19 +154,7 @@ class GameFontBase( } private fun getCache(hash: Long): TextCacheObj? { - val cache = textCache[hash] - - if (cache == null) - return null -// else if (cache.disposed) { -// textCache.remove(hash) -// return null -// } - else { - // decrement age count (see: addToCache(CodepointSequence, Pixmap, Int)) - if (cache.age > 0) cache.age -= 1 - return cache - } + return textCache[hash] }