mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
audio: Refactoring: Remove dependency on clock package
This commit is contained in:
parent
28c96d256a
commit
a6b3f761f8
@ -42,7 +42,6 @@ import (
|
||||
|
||||
"github.com/hajimehoshi/oto"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/clock"
|
||||
"github.com/hajimehoshi/ebiten/internal/hooks"
|
||||
"github.com/hajimehoshi/ebiten/internal/web"
|
||||
)
|
||||
@ -67,20 +66,6 @@ var (
|
||||
theContextLock sync.Mutex
|
||||
)
|
||||
|
||||
func init() {
|
||||
hooks.AppendHookOnBeforeUpdate(func() error {
|
||||
var err error
|
||||
theContextLock.Lock()
|
||||
if theContext != nil {
|
||||
theContext.m.Lock()
|
||||
err = theContext.err
|
||||
theContext.m.Unlock()
|
||||
}
|
||||
theContextLock.Unlock()
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
// NewContext creates a new audio context with the given sample rate.
|
||||
//
|
||||
// The sample rate is also used for decoding MP3 with audio/mp3 package
|
||||
@ -128,8 +113,6 @@ func newDriver(sampleRate int) (io.WriteCloser, error) {
|
||||
}
|
||||
|
||||
func (c *Context) loop() {
|
||||
initCh := make(chan struct{})
|
||||
|
||||
suspendCh := make(chan struct{}, 1)
|
||||
resumeCh := make(chan struct{}, 1)
|
||||
hooks.OnSuspendAudio(func() {
|
||||
@ -138,8 +121,23 @@ func (c *Context) loop() {
|
||||
hooks.OnResumeAudio(func() {
|
||||
resumeCh <- struct{}{}
|
||||
})
|
||||
clock.OnStart(func() {
|
||||
close(initCh)
|
||||
|
||||
initCh := make(chan struct{})
|
||||
var once sync.Once
|
||||
hooks.AppendHookOnBeforeUpdate(func() error {
|
||||
once.Do(func() {
|
||||
close(initCh)
|
||||
})
|
||||
|
||||
var err error
|
||||
theContextLock.Lock()
|
||||
if theContext != nil {
|
||||
theContext.m.Lock()
|
||||
err = theContext.err
|
||||
theContext.m.Unlock()
|
||||
}
|
||||
theContextLock.Unlock()
|
||||
return err
|
||||
})
|
||||
|
||||
// Initialize oto.Player lazily to enable calling NewContext in an 'init' function.
|
||||
|
@ -30,9 +30,6 @@ var (
|
||||
fpsCount = 0
|
||||
tpsCount = 0
|
||||
|
||||
onStartCalled bool
|
||||
onStart func()
|
||||
|
||||
m sync.Mutex
|
||||
)
|
||||
|
||||
@ -50,12 +47,6 @@ func CurrentTPS() float64 {
|
||||
return v
|
||||
}
|
||||
|
||||
func OnStart(f func()) {
|
||||
m.Lock()
|
||||
onStart = f
|
||||
m.Unlock()
|
||||
}
|
||||
|
||||
func calcCountFromTPS(tps int64, now int64) int {
|
||||
if tps == 0 {
|
||||
return 0
|
||||
@ -132,13 +123,6 @@ func Update(tps int) int {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
if !onStartCalled {
|
||||
if onStart != nil {
|
||||
onStart()
|
||||
onStartCalled = true
|
||||
}
|
||||
}
|
||||
|
||||
n := now()
|
||||
c := 0
|
||||
if tps == UncappedTPS {
|
||||
|
Loading…
Reference in New Issue
Block a user