ebitenutil: Cache sub images for debug print

This commit is contained in:
Hajime Hoshi 2019-11-24 20:30:54 +09:00
parent 21ba42325c
commit a449045ae2

View File

@ -22,7 +22,8 @@ import (
) )
var ( var (
debugPrintTextImage *ebiten.Image debugPrintTextImage *ebiten.Image
debugPrintTextSubImages = map[rune]*ebiten.Image{}
) )
func init() { func init() {
@ -66,13 +67,18 @@ func drawDebugText(rt *ebiten.Image, str string, ox, oy int, shadow bool) {
y += ch y += ch
continue continue
} }
n := w / cw s, ok := debugPrintTextSubImages[c]
sx := (int(c) % n) * cw if !ok {
sy := (int(c) / n) * ch n := w / cw
sx := (int(c) % n) * cw
sy := (int(c) / n) * ch
s = debugPrintTextImage.SubImage(image.Rect(sx, sy, sx+cw, sy+ch)).(*ebiten.Image)
debugPrintTextSubImages[c] = s
}
op.GeoM.Reset() op.GeoM.Reset()
op.GeoM.Translate(float64(x), float64(y)) op.GeoM.Translate(float64(x), float64(y))
op.GeoM.Translate(float64(ox+1), float64(oy)) op.GeoM.Translate(float64(ox+1), float64(oy))
_ = rt.DrawImage(debugPrintTextImage.SubImage(image.Rect(sx, sy, sx+cw, sy+ch)).(*ebiten.Image), op) _ = rt.DrawImage(s, op)
x += cw x += cw
} }
} }