mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 03:02:49 +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 (
|
var (
|
||||||
glyphImageCache = map[font.Face]map[rune]*glyphImageCacheEntry{}
|
glyphImageCache = map[font.Face]map[rune]*glyphImageCacheEntry{}
|
||||||
emptyGlyphs = map[font.Face]map[rune]struct{}{}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func getGlyphImage(face font.Face, r rune) *ebiten.Image {
|
func getGlyphImage(face font.Face, r rune) *ebiten.Image {
|
||||||
if _, ok := emptyGlyphs[face]; !ok {
|
|
||||||
emptyGlyphs[face] = map[rune]struct{}{}
|
|
||||||
}
|
|
||||||
if _, ok := glyphImageCache[face]; !ok {
|
if _, ok := glyphImageCache[face]; !ok {
|
||||||
glyphImageCache[face] = map[rune]*glyphImageCacheEntry{}
|
glyphImageCache[face] = map[rune]*glyphImageCacheEntry{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := emptyGlyphs[face][r]; ok {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if e, ok := glyphImageCache[face][r]; ok {
|
if e, ok := glyphImageCache[face][r]; ok {
|
||||||
e.atime = now()
|
e.atime = now()
|
||||||
return e.image
|
return e.image
|
||||||
@ -108,7 +100,10 @@ func getGlyphImage(face font.Face, r rune) *ebiten.Image {
|
|||||||
b := getGlyphBounds(face, r)
|
b := getGlyphBounds(face, r)
|
||||||
w, h := (b.Max.X - b.Min.X).Ceil(), (b.Max.Y - b.Min.Y).Ceil()
|
w, h := (b.Max.X - b.Min.X).Ceil(), (b.Max.Y - b.Min.Y).Ceil()
|
||||||
if w == 0 || h == 0 {
|
if w == 0 || h == 0 {
|
||||||
emptyGlyphs[face][r] = struct{}{}
|
glyphImageCache[face][r] = &glyphImageCacheEntry{
|
||||||
|
image: nil,
|
||||||
|
atime: now(),
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user