mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 02:42:02 +01:00
driver: Remove Suspend/ResumeAudio from UIContext
This commit is contained in:
parent
63fbffa9f6
commit
8e9f5b9535
@ -22,8 +22,6 @@ import (
|
|||||||
type UIContext interface {
|
type UIContext interface {
|
||||||
SetSize(width, height int, scale float64)
|
SetSize(width, height int, scale float64)
|
||||||
Update(afterFrameUpdate func()) error
|
Update(afterFrameUpdate func()) error
|
||||||
SuspendAudio()
|
|
||||||
ResumeAudio()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegularTermination represents a regular termination.
|
// RegularTermination represents a regular termination.
|
||||||
|
@ -33,6 +33,7 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/internal/devicescale"
|
"github.com/hajimehoshi/ebiten/internal/devicescale"
|
||||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||||
"github.com/hajimehoshi/ebiten/internal/glfw"
|
"github.com/hajimehoshi/ebiten/internal/glfw"
|
||||||
|
"github.com/hajimehoshi/ebiten/internal/hooks"
|
||||||
"github.com/hajimehoshi/ebiten/internal/thread"
|
"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())
|
u.input.update(u.window, u.getScale()*u.glfwScale())
|
||||||
|
|
||||||
defer context.ResumeAudio()
|
defer hooks.ResumeAudio()
|
||||||
|
|
||||||
for !u.isRunnableInBackground() && u.window.GetAttrib(glfw.Focused) == 0 {
|
for !u.isRunnableInBackground() && u.window.GetAttrib(glfw.Focused) == 0 {
|
||||||
context.SuspendAudio()
|
hooks.SuspendAudio()
|
||||||
// Wait for an arbitrary period to avoid busy loop.
|
// Wait for an arbitrary period to avoid busy loop.
|
||||||
time.Sleep(time.Second / 60)
|
time.Sleep(time.Second / 60)
|
||||||
glfw.PollEvents()
|
glfw.PollEvents()
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/devicescale"
|
"github.com/hajimehoshi/ebiten/internal/devicescale"
|
||||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||||
|
"github.com/hajimehoshi/ebiten/internal/hooks"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserInterface struct {
|
type UserInterface struct {
|
||||||
@ -204,10 +205,10 @@ func (u *UserInterface) suspended() bool {
|
|||||||
|
|
||||||
func (u *UserInterface) update() error {
|
func (u *UserInterface) update() error {
|
||||||
if u.suspended() {
|
if u.suspended() {
|
||||||
u.context.SuspendAudio()
|
hooks.SuspendAudio()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
u.context.ResumeAudio()
|
hooks.ResumeAudio()
|
||||||
|
|
||||||
u.input.UpdateGamepads()
|
u.input.UpdateGamepads()
|
||||||
u.updateSize()
|
u.updateSize()
|
||||||
@ -257,9 +258,9 @@ func (u *UserInterface) loop(context driver.UIContext) <-chan error {
|
|||||||
defer t.Stop()
|
defer t.Stop()
|
||||||
for range t.C {
|
for range t.C {
|
||||||
if u.suspended() {
|
if u.suspended() {
|
||||||
u.context.SuspendAudio()
|
hooks.SuspendAudio()
|
||||||
} else {
|
} else {
|
||||||
u.context.ResumeAudio()
|
hooks.ResumeAudio()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -34,6 +34,7 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/internal/devicescale"
|
"github.com/hajimehoshi/ebiten/internal/devicescale"
|
||||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/opengl"
|
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/opengl"
|
||||||
|
"github.com/hajimehoshi/ebiten/internal/hooks"
|
||||||
"github.com/hajimehoshi/ebiten/internal/thread"
|
"github.com/hajimehoshi/ebiten/internal/thread"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -276,11 +277,11 @@ func (u *UserInterface) update(context driver.UIContext) error {
|
|||||||
select {
|
select {
|
||||||
case <-renderCh:
|
case <-renderCh:
|
||||||
case <-t.C:
|
case <-t.C:
|
||||||
context.SuspendAudio()
|
hooks.SuspendAudio()
|
||||||
<-renderCh
|
<-renderCh
|
||||||
}
|
}
|
||||||
|
|
||||||
context.ResumeAudio()
|
hooks.ResumeAudio()
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
renderEndCh <- struct{}{}
|
renderEndCh <- struct{}{}
|
||||||
|
@ -131,11 +131,3 @@ func (c *uiContext) Update(afterFrameUpdate func()) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *uiContext) SuspendAudio() {
|
|
||||||
hooks.SuspendAudio()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *uiContext) ResumeAudio() {
|
|
||||||
hooks.ResumeAudio()
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user