mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
text: Integrate emptyGlyphs and glyphImageCache to reduce runtine.mapaccess2
This commit is contained in:
parent
fdad70ca46
commit
c8454bdfed
13
text/text.go
13
text/text.go
@ -85,21 +85,13 @@ type glyphImageCacheEntry struct {
|
||||
|
||||
var (
|
||||
glyphImageCache = map[font.Face]map[rune]*glyphImageCacheEntry{}
|
||||
emptyGlyphs = map[font.Face]map[rune]struct{}{}
|
||||
)
|
||||
|
||||
func getGlyphImage(face font.Face, r rune) *ebiten.Image {
|
||||
if _, ok := emptyGlyphs[face]; !ok {
|
||||
emptyGlyphs[face] = map[rune]struct{}{}
|
||||
}
|
||||
if _, ok := glyphImageCache[face]; !ok {
|
||||
glyphImageCache[face] = map[rune]*glyphImageCacheEntry{}
|
||||
}
|
||||
|
||||
if _, ok := emptyGlyphs[face][r]; ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
if e, ok := glyphImageCache[face][r]; ok {
|
||||
e.atime = now()
|
||||
return e.image
|
||||
@ -108,7 +100,10 @@ func getGlyphImage(face font.Face, r rune) *ebiten.Image {
|
||||
b := getGlyphBounds(face, r)
|
||||
w, h := (b.Max.X - b.Min.X).Ceil(), (b.Max.Y - b.Min.Y).Ceil()
|
||||
if w == 0 || h == 0 {
|
||||
emptyGlyphs[face][r] = struct{}{}
|
||||
glyphImageCache[face][r] = &glyphImageCacheEntry{
|
||||
image: nil,
|
||||
atime: now(),
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user