mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-23 09:22:01 +01:00
audio: Refactoring
This commit is contained in:
parent
ba75592807
commit
3216d50460
@ -200,15 +200,13 @@ func NewContext(sampleRate int) (*Context, error) {
|
|||||||
c := &Context{
|
c := &Context{
|
||||||
sampleRate: sampleRate,
|
sampleRate: sampleRate,
|
||||||
errCh: make(chan error, 1),
|
errCh: make(chan error, 1),
|
||||||
initCh: make(chan struct{}),
|
|
||||||
initedCh: make(chan struct{}),
|
|
||||||
}
|
}
|
||||||
theContext = c
|
theContext = c
|
||||||
c.players = &players{
|
c.players = &players{
|
||||||
players: map[*Player]struct{}{},
|
players: map[*Player]struct{}{},
|
||||||
}
|
}
|
||||||
|
|
||||||
go c.loop(c.initCh)
|
go c.loop()
|
||||||
|
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
@ -232,7 +230,13 @@ func (c *Context) ping() {
|
|||||||
c.m.Unlock()
|
c.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) loop(initCh <-chan struct{}) {
|
func (c *Context) loop() {
|
||||||
|
c.initCh = make(chan struct{})
|
||||||
|
c.initedCh = make(chan struct{})
|
||||||
|
|
||||||
|
// Copy the channel since c.initCh can be set as nil after clock.RegisterPing.
|
||||||
|
initCh := c.initCh
|
||||||
|
|
||||||
clock.RegisterPing(c.ping)
|
clock.RegisterPing(c.ping)
|
||||||
|
|
||||||
// Initialize oto.Player lazily to enable calling NewContext in an 'init' function.
|
// Initialize oto.Player lazily to enable calling NewContext in an 'init' function.
|
||||||
|
Loading…
Reference in New Issue
Block a user