mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 12:08:58 +01:00
Add syncer
This commit is contained in:
parent
3190609f07
commit
97857715fa
@ -16,65 +16,70 @@ limitations under the License.
|
||||
|
||||
package ebiten
|
||||
|
||||
type syncer interface {
|
||||
Sync(f func())
|
||||
}
|
||||
|
||||
type syncGraphicsContext struct {
|
||||
ui *ui
|
||||
syncer syncer
|
||||
innerGraphicsContext GraphicsContext
|
||||
}
|
||||
|
||||
var _ GraphicsContext = new(syncGraphicsContext)
|
||||
|
||||
func (c *syncGraphicsContext) Clear() {
|
||||
c.ui.use(func() {
|
||||
c.ui.graphicsContext.Clear()
|
||||
c.syncer.Sync(func() {
|
||||
c.innerGraphicsContext.Clear()
|
||||
})
|
||||
}
|
||||
|
||||
func (c *syncGraphicsContext) Fill(r, g, b uint8) {
|
||||
c.ui.use(func() {
|
||||
c.ui.graphicsContext.Fill(r, g, b)
|
||||
c.syncer.Sync(func() {
|
||||
c.innerGraphicsContext.Fill(r, g, b)
|
||||
})
|
||||
}
|
||||
|
||||
func (c *syncGraphicsContext) Texture(id TextureID) (d Drawer) {
|
||||
c.ui.use(func() {
|
||||
c.syncer.Sync(func() {
|
||||
d = &drawer{
|
||||
ui: c.ui,
|
||||
innerDrawer: c.ui.graphicsContext.Texture(id),
|
||||
syncer: c.syncer,
|
||||
innerDrawer: c.innerGraphicsContext.Texture(id),
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (c *syncGraphicsContext) RenderTarget(id RenderTargetID) (d Drawer) {
|
||||
c.ui.use(func() {
|
||||
c.syncer.Sync(func() {
|
||||
d = &drawer{
|
||||
ui: c.ui,
|
||||
innerDrawer: c.ui.graphicsContext.RenderTarget(id),
|
||||
syncer: c.syncer,
|
||||
innerDrawer: c.innerGraphicsContext.RenderTarget(id),
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (c *syncGraphicsContext) PopRenderTarget() {
|
||||
c.ui.use(func() {
|
||||
c.ui.graphicsContext.PopRenderTarget()
|
||||
c.syncer.Sync(func() {
|
||||
c.innerGraphicsContext.PopRenderTarget()
|
||||
})
|
||||
}
|
||||
|
||||
func (c *syncGraphicsContext) PushRenderTarget(id RenderTargetID) {
|
||||
c.ui.use(func() {
|
||||
c.ui.graphicsContext.PushRenderTarget(id)
|
||||
c.syncer.Sync(func() {
|
||||
c.innerGraphicsContext.PushRenderTarget(id)
|
||||
})
|
||||
}
|
||||
|
||||
type drawer struct {
|
||||
ui *ui
|
||||
syncer syncer
|
||||
innerDrawer Drawer
|
||||
}
|
||||
|
||||
var _ Drawer = new(drawer)
|
||||
|
||||
func (d *drawer) Draw(parts []TexturePart, geo GeometryMatrix, color ColorMatrix) {
|
||||
d.ui.use(func() {
|
||||
d.syncer.Sync(func() {
|
||||
d.innerDrawer.Draw(parts, geo, color)
|
||||
})
|
||||
}
|
||||
|
9
ui.go
9
ui.go
@ -87,11 +87,18 @@ func (u *ui) drawGame(game Game) error {
|
||||
return u.draw(game)
|
||||
}
|
||||
|
||||
func (u *ui) Sync(f func()) {
|
||||
u.use(f)
|
||||
}
|
||||
|
||||
func (u *ui) draw(game Game) (err error) {
|
||||
u.use(func() {
|
||||
u.graphicsContext.preUpdate()
|
||||
})
|
||||
if err = game.Draw(&syncGraphicsContext{u}); err != nil {
|
||||
if err = game.Draw(&syncGraphicsContext{
|
||||
syncer: u,
|
||||
innerGraphicsContext: u.graphicsContext,
|
||||
}); err != nil {
|
||||
return
|
||||
}
|
||||
u.use(func() {
|
||||
|
Loading…
Reference in New Issue
Block a user