ebitenutil: Speed up to avoid copying by image.Rect

This commit is contained in:
Hajime Hoshi 2018-03-11 21:39:18 +09:00
parent ee7ef75b8b
commit 063153e41d
2 changed files with 6 additions and 2 deletions

View File

@ -270,7 +270,7 @@ func (c *Context) loop() {
c.pingCount--
c.m.Unlock()
const n = 4096
const n = 2048
if _, err := io.CopyN(p, c.players, n); err != nil {
c.err = err
return

View File

@ -63,6 +63,7 @@ func drawDebugText(rt *ebiten.Image, str string, ox, oy int, src *ebiten.Image)
x := 0
y := 0
w, _ := debugPrintTextImage.Size()
var r image.Rectangle
for _, c := range str {
const (
cw = assets.CharWidth
@ -76,7 +77,10 @@ func drawDebugText(rt *ebiten.Image, str string, ox, oy int, src *ebiten.Image)
n := w / cw
sx := (int(c) % n) * cw
sy := (int(c) / n) * ch
r := image.Rect(sx, sy, sx+cw, sy+ch)
r.Min.X = sx
r.Min.Y = sy
r.Max.X = sx + cw
r.Max.Y = sy + ch
op.SourceRect = &r
op.GeoM.Reset()
op.GeoM.Translate(float64(x), float64(y))