mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 02:42:02 +01:00
buffered: Refactoring: Use defer
defer's performance will be much better as of Go 1.14. https://tip.golang.org/doc/go1.14#runtime
This commit is contained in:
parent
74cb080c6f
commit
4159c500bd
@ -45,7 +45,10 @@ func EndFrame() error {
|
|||||||
|
|
||||||
func NewImage(width, height int, volatile bool) *Image {
|
func NewImage(width, height int, volatile bool) *Image {
|
||||||
i := &Image{}
|
i := &Image{}
|
||||||
|
|
||||||
delayedCommandsM.Lock()
|
delayedCommandsM.Lock()
|
||||||
|
defer delayedCommandsM.Unlock()
|
||||||
|
|
||||||
if needsToDelayCommands {
|
if needsToDelayCommands {
|
||||||
delayedCommands = append(delayedCommands, func() error {
|
delayedCommands = append(delayedCommands, func() error {
|
||||||
i.img = mipmap.New(width, height, volatile)
|
i.img = mipmap.New(width, height, volatile)
|
||||||
@ -53,10 +56,8 @@ func NewImage(width, height int, volatile bool) *Image {
|
|||||||
i.height = height
|
i.height = height
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
delayedCommandsM.Unlock()
|
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
delayedCommandsM.Unlock()
|
|
||||||
|
|
||||||
i.img = mipmap.New(width, height, volatile)
|
i.img = mipmap.New(width, height, volatile)
|
||||||
i.width = width
|
i.width = width
|
||||||
@ -66,7 +67,10 @@ func NewImage(width, height int, volatile bool) *Image {
|
|||||||
|
|
||||||
func NewScreenFramebufferImage(width, height int) *Image {
|
func NewScreenFramebufferImage(width, height int) *Image {
|
||||||
i := &Image{}
|
i := &Image{}
|
||||||
|
|
||||||
delayedCommandsM.Lock()
|
delayedCommandsM.Lock()
|
||||||
|
defer delayedCommandsM.Unlock()
|
||||||
|
|
||||||
if needsToDelayCommands {
|
if needsToDelayCommands {
|
||||||
delayedCommands = append(delayedCommands, func() error {
|
delayedCommands = append(delayedCommands, func() error {
|
||||||
i.img = mipmap.NewScreenFramebufferMipmap(width, height)
|
i.img = mipmap.NewScreenFramebufferMipmap(width, height)
|
||||||
@ -74,10 +78,9 @@ func NewScreenFramebufferImage(width, height int) *Image {
|
|||||||
i.height = height
|
i.height = height
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
delayedCommandsM.Unlock()
|
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
delayedCommandsM.Unlock()
|
|
||||||
|
|
||||||
i.img = mipmap.NewScreenFramebufferMipmap(width, height)
|
i.img = mipmap.NewScreenFramebufferMipmap(width, height)
|
||||||
i.width = width
|
i.width = width
|
||||||
@ -104,15 +107,15 @@ func (i *Image) resolvePendingPixels(keepPendingPixels bool) {
|
|||||||
|
|
||||||
func (i *Image) MarkDisposed() {
|
func (i *Image) MarkDisposed() {
|
||||||
delayedCommandsM.Lock()
|
delayedCommandsM.Lock()
|
||||||
|
defer delayedCommandsM.Unlock()
|
||||||
|
|
||||||
if needsToDelayCommands {
|
if needsToDelayCommands {
|
||||||
delayedCommands = append(delayedCommands, func() error {
|
delayedCommands = append(delayedCommands, func() error {
|
||||||
i.img.MarkDisposed()
|
i.img.MarkDisposed()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
delayedCommandsM.Unlock()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
delayedCommandsM.Unlock()
|
|
||||||
|
|
||||||
i.invalidatePendingPixels()
|
i.invalidatePendingPixels()
|
||||||
}
|
}
|
||||||
@ -130,14 +133,13 @@ func (i *Image) At(x, y int) (r, g, b, a byte, err error) {
|
|||||||
|
|
||||||
func (i *Image) Set(x, y int, r, g, b, a byte) error {
|
func (i *Image) Set(x, y int, r, g, b, a byte) error {
|
||||||
delayedCommandsM.Lock()
|
delayedCommandsM.Lock()
|
||||||
|
defer delayedCommandsM.Unlock()
|
||||||
if needsToDelayCommands {
|
if needsToDelayCommands {
|
||||||
delayedCommands = append(delayedCommands, func() error {
|
delayedCommands = append(delayedCommands, func() error {
|
||||||
return i.set(x, y, r, g, b, a)
|
return i.set(x, y, r, g, b, a)
|
||||||
})
|
})
|
||||||
delayedCommandsM.Unlock()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
delayedCommandsM.Unlock()
|
|
||||||
|
|
||||||
return i.set(x, y, r, g, b, a)
|
return i.set(x, y, r, g, b, a)
|
||||||
}
|
}
|
||||||
@ -181,15 +183,15 @@ func (i *Image) Dump(name string, blackbg bool) error {
|
|||||||
|
|
||||||
func (i *Image) Fill(clr color.RGBA) {
|
func (i *Image) Fill(clr color.RGBA) {
|
||||||
delayedCommandsM.Lock()
|
delayedCommandsM.Lock()
|
||||||
|
defer delayedCommandsM.Unlock()
|
||||||
|
|
||||||
if needsToDelayCommands {
|
if needsToDelayCommands {
|
||||||
delayedCommands = append(delayedCommands, func() error {
|
delayedCommands = append(delayedCommands, func() error {
|
||||||
i.img.Fill(clr)
|
i.img.Fill(clr)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
delayedCommandsM.Unlock()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
delayedCommandsM.Unlock()
|
|
||||||
|
|
||||||
i.invalidatePendingPixels()
|
i.invalidatePendingPixels()
|
||||||
i.img.Fill(clr)
|
i.img.Fill(clr)
|
||||||
@ -197,6 +199,8 @@ func (i *Image) Fill(clr color.RGBA) {
|
|||||||
|
|
||||||
func (i *Image) ReplacePixels(pix []byte) {
|
func (i *Image) ReplacePixels(pix []byte) {
|
||||||
delayedCommandsM.Lock()
|
delayedCommandsM.Lock()
|
||||||
|
defer delayedCommandsM.Unlock()
|
||||||
|
|
||||||
if needsToDelayCommands {
|
if needsToDelayCommands {
|
||||||
delayedCommands = append(delayedCommands, func() error {
|
delayedCommands = append(delayedCommands, func() error {
|
||||||
copied := make([]byte, len(pix))
|
copied := make([]byte, len(pix))
|
||||||
@ -204,10 +208,8 @@ func (i *Image) ReplacePixels(pix []byte) {
|
|||||||
i.img.ReplacePixels(copied)
|
i.img.ReplacePixels(copied)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
delayedCommandsM.Unlock()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
delayedCommandsM.Unlock()
|
|
||||||
|
|
||||||
i.invalidatePendingPixels()
|
i.invalidatePendingPixels()
|
||||||
i.img.ReplacePixels(pix)
|
i.img.ReplacePixels(pix)
|
||||||
@ -228,15 +230,15 @@ func (i *Image) DrawImage(src *Image, bounds image.Rectangle, a, b, c, d, tx, ty
|
|||||||
}
|
}
|
||||||
|
|
||||||
delayedCommandsM.Lock()
|
delayedCommandsM.Lock()
|
||||||
|
defer delayedCommandsM.Unlock()
|
||||||
|
|
||||||
if needsToDelayCommands {
|
if needsToDelayCommands {
|
||||||
delayedCommands = append(delayedCommands, func() error {
|
delayedCommands = append(delayedCommands, func() error {
|
||||||
i.drawImage(src, bounds, g, colorm, mode, filter)
|
i.drawImage(src, bounds, g, colorm, mode, filter)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
delayedCommandsM.Unlock()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
delayedCommandsM.Unlock()
|
|
||||||
|
|
||||||
i.drawImage(src, bounds, g, colorm, mode, filter)
|
i.drawImage(src, bounds, g, colorm, mode, filter)
|
||||||
}
|
}
|
||||||
@ -253,15 +255,15 @@ func (i *Image) DrawTriangles(src *Image, vertices []float32, indices []uint16,
|
|||||||
}
|
}
|
||||||
|
|
||||||
delayedCommandsM.Lock()
|
delayedCommandsM.Lock()
|
||||||
|
defer delayedCommandsM.Unlock()
|
||||||
|
|
||||||
if needsToDelayCommands {
|
if needsToDelayCommands {
|
||||||
delayedCommands = append(delayedCommands, func() error {
|
delayedCommands = append(delayedCommands, func() error {
|
||||||
i.drawTriangles(src, vertices, indices, colorm, mode, filter, address)
|
i.drawTriangles(src, vertices, indices, colorm, mode, filter, address)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
delayedCommandsM.Unlock()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
delayedCommandsM.Unlock()
|
|
||||||
i.drawTriangles(src, vertices, indices, colorm, mode, filter, address)
|
i.drawTriangles(src, vertices, indices, colorm, mode, filter, address)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user