mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
audio: Deprecate Update
This commit is contained in:
parent
dba7124e38
commit
0379e3c591
@ -43,6 +43,7 @@ import (
|
||||
|
||||
"github.com/hajimehoshi/oto"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/audiobinding"
|
||||
"github.com/hajimehoshi/ebiten/internal/clock"
|
||||
)
|
||||
|
||||
@ -180,7 +181,6 @@ func (p *players) hasSource(src ReadSeekCloser) bool {
|
||||
// }
|
||||
type Context struct {
|
||||
players *players
|
||||
errCh chan error
|
||||
initCh chan struct{}
|
||||
initedCh chan struct{}
|
||||
pingCount int
|
||||
@ -216,7 +216,6 @@ func NewContext(sampleRate int) (*Context, error) {
|
||||
}
|
||||
c := &Context{
|
||||
sampleRate: sampleRate,
|
||||
errCh: make(chan error, 1),
|
||||
}
|
||||
theContext = c
|
||||
c.players = &players{
|
||||
@ -266,7 +265,7 @@ func (c *Context) loop() {
|
||||
|
||||
p, err := oto.NewPlayer(c.sampleRate, channelNum, bytesPerSample, c.bufferSize())
|
||||
if err != nil {
|
||||
c.errCh <- err
|
||||
audiobinding.SetError(err)
|
||||
return
|
||||
}
|
||||
defer p.Close()
|
||||
@ -290,26 +289,21 @@ func (c *Context) loop() {
|
||||
c.writtenBytes += l
|
||||
buf := make([]uint8, l)
|
||||
if _, err := io.ReadFull(c.players, buf); err != nil {
|
||||
c.errCh <- err
|
||||
audiobinding.SetError(err)
|
||||
return
|
||||
}
|
||||
if _, err = p.Write(buf); err != nil {
|
||||
c.errCh <- err
|
||||
audiobinding.SetError(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update returns an error if some errors happen, or nil if there is no error.
|
||||
// Update is deprecated as of 1.6.0-alpha.
|
||||
//
|
||||
// As of 1.6.0-alpha, Update just returns the error if an error happens internally,
|
||||
// and do nothing related to updating the state.
|
||||
// Then, the audio is available without Update,
|
||||
// but it is recommended to call Update every frame to check errors.
|
||||
// As of 1.6.0-alpha, Update always returns nil and does nothing related to updating the state.
|
||||
// The internal audio error is returned at ebiten.Run instead.
|
||||
func (c *Context) Update() error {
|
||||
select {
|
||||
case err := <-c.errCh:
|
||||
return err
|
||||
default:
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
25
internal/audiobinding/error.go
Normal file
25
internal/audiobinding/error.go
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright 2017 The Ebiten Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package audiobinding
|
||||
|
||||
var ch = make(chan error, 1)
|
||||
|
||||
func Error() <-chan error {
|
||||
return ch
|
||||
}
|
||||
|
||||
func SetError(err error) {
|
||||
ch <- err
|
||||
}
|
10
run.go
10
run.go
@ -18,6 +18,7 @@ import (
|
||||
"image"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/audiobinding"
|
||||
"github.com/hajimehoshi/ebiten/internal/clock"
|
||||
"github.com/hajimehoshi/ebiten/internal/ui"
|
||||
)
|
||||
@ -79,6 +80,11 @@ func (u *updater) SetSize(width, height int, scale float64) {
|
||||
}
|
||||
|
||||
func (u *updater) Update(afterFrameUpdate func()) error {
|
||||
select {
|
||||
case err := <-audiobinding.Error():
|
||||
return err
|
||||
default:
|
||||
}
|
||||
n := clock.Update()
|
||||
if err := u.g.Update(n, afterFrameUpdate); err != nil {
|
||||
return err
|
||||
@ -108,8 +114,8 @@ func (u *updater) Invalidate() {
|
||||
//
|
||||
// The given scale is ignored on fullscreen mode.
|
||||
//
|
||||
// Run returns error when 1) OpenGL error happens, or 2) f returns error.
|
||||
// In the case of 2), Run returns the same error.
|
||||
// Run returns error when 1) OpenGL error happens, 2) audio error happens or 3) f returns error.
|
||||
// In the case of 3), Run returns the same error.
|
||||
//
|
||||
// The size unit is device-independent pixel.
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user