driver: Remove Suspend/ResumeAudio from UIContext

This commit is contained in:
Hajime Hoshi 2019-12-08 16:10:43 +09:00
parent 63fbffa9f6
commit 8e9f5b9535
5 changed files with 11 additions and 18 deletions

View File

@ -22,8 +22,6 @@ import (
type UIContext interface {
SetSize(width, height int, scale float64)
Update(afterFrameUpdate func()) error
SuspendAudio()
ResumeAudio()
}
// RegularTermination represents a regular termination.

View File

@ -33,6 +33,7 @@ import (
"github.com/hajimehoshi/ebiten/internal/devicescale"
"github.com/hajimehoshi/ebiten/internal/driver"
"github.com/hajimehoshi/ebiten/internal/glfw"
"github.com/hajimehoshi/ebiten/internal/hooks"
"github.com/hajimehoshi/ebiten/internal/thread"
)
@ -850,10 +851,10 @@ func (u *UserInterface) update(context driver.UIContext) error {
u.input.update(u.window, u.getScale()*u.glfwScale())
defer context.ResumeAudio()
defer hooks.ResumeAudio()
for !u.isRunnableInBackground() && u.window.GetAttrib(glfw.Focused) == 0 {
context.SuspendAudio()
hooks.SuspendAudio()
// Wait for an arbitrary period to avoid busy loop.
time.Sleep(time.Second / 60)
glfw.PollEvents()

View File

@ -26,6 +26,7 @@ import (
"github.com/hajimehoshi/ebiten/internal/devicescale"
"github.com/hajimehoshi/ebiten/internal/driver"
"github.com/hajimehoshi/ebiten/internal/hooks"
)
type UserInterface struct {
@ -204,10 +205,10 @@ func (u *UserInterface) suspended() bool {
func (u *UserInterface) update() error {
if u.suspended() {
u.context.SuspendAudio()
hooks.SuspendAudio()
return nil
}
u.context.ResumeAudio()
hooks.ResumeAudio()
u.input.UpdateGamepads()
u.updateSize()
@ -257,9 +258,9 @@ func (u *UserInterface) loop(context driver.UIContext) <-chan error {
defer t.Stop()
for range t.C {
if u.suspended() {
u.context.SuspendAudio()
hooks.SuspendAudio()
} else {
u.context.ResumeAudio()
hooks.ResumeAudio()
}
}
}()

View File

@ -34,6 +34,7 @@ import (
"github.com/hajimehoshi/ebiten/internal/devicescale"
"github.com/hajimehoshi/ebiten/internal/driver"
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/opengl"
"github.com/hajimehoshi/ebiten/internal/hooks"
"github.com/hajimehoshi/ebiten/internal/thread"
)
@ -276,11 +277,11 @@ func (u *UserInterface) update(context driver.UIContext) error {
select {
case <-renderCh:
case <-t.C:
context.SuspendAudio()
hooks.SuspendAudio()
<-renderCh
}
context.ResumeAudio()
hooks.ResumeAudio()
defer func() {
renderEndCh <- struct{}{}

View File

@ -131,11 +131,3 @@ func (c *uiContext) Update(afterFrameUpdate func()) error {
}
return nil
}
func (c *uiContext) SuspendAudio() {
hooks.SuspendAudio()
}
func (c *uiContext) ResumeAudio() {
hooks.ResumeAudio()
}