mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 03:02:49 +01:00
text: Refactoring
This commit is contained in:
parent
5ec05ed79d
commit
ec6821b1e1
@ -81,7 +81,7 @@ var (
|
|||||||
emptyGlyphs = map[font.Face]map[rune]struct{}{}
|
emptyGlyphs = map[font.Face]map[rune]struct{}{}
|
||||||
)
|
)
|
||||||
|
|
||||||
func getGlyphImages(face font.Face, runes []rune, cacheLimit int) []*ebiten.Image {
|
func getGlyphImages(face font.Face, runes []rune) []*ebiten.Image {
|
||||||
if _, ok := emptyGlyphs[face]; !ok {
|
if _, ok := emptyGlyphs[face]; !ok {
|
||||||
emptyGlyphs[face] = map[rune]struct{}{}
|
emptyGlyphs[face] = map[rune]struct{}{}
|
||||||
}
|
}
|
||||||
@ -183,9 +183,8 @@ func Draw(dst *ebiten.Image, text string, face font.Face, x, y int, clr color.Co
|
|||||||
|
|
||||||
faceHeight := face.Metrics().Height
|
faceHeight := face.Metrics().Height
|
||||||
|
|
||||||
const cacheLimit = 512 // This is an arbitrary number.
|
|
||||||
runes := []rune(text)
|
runes := []rune(text)
|
||||||
glyphImgs := getGlyphImages(face, runes, cacheLimit)
|
glyphImgs := getGlyphImages(face, runes)
|
||||||
colorm := colormcache.ColorToColorM(clr)
|
colorm := colormcache.ColorToColorM(clr)
|
||||||
|
|
||||||
for i, r := range runes {
|
for i, r := range runes {
|
||||||
@ -205,6 +204,9 @@ func Draw(dst *ebiten.Image, text string, face font.Face, x, y int, clr color.Co
|
|||||||
prevR = r
|
prevR = r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cacheLimit = 512
|
||||||
|
|
||||||
|
// Clean up the cache.
|
||||||
for len(glyphImageCache[face]) > cacheLimit {
|
for len(glyphImageCache[face]) > cacheLimit {
|
||||||
oldest := int64(math.MaxInt64)
|
oldest := int64(math.MaxInt64)
|
||||||
oldestKey := rune(-1)
|
oldestKey := rune(-1)
|
||||||
|
Loading…
Reference in New Issue
Block a user