mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
internal/hook: rename hooks -> hook
This commit is contained in:
parent
3d4dc239bc
commit
82f2319020
@ -42,7 +42,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/audio/internal/convert"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/hooks"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/hook"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -438,33 +438,33 @@ func (p *Player) SetBufferSize(bufferSize time.Duration) {
|
||||
p.p.SetBufferSize(bufferSize)
|
||||
}
|
||||
|
||||
type hook interface {
|
||||
type hooker interface {
|
||||
OnSuspendAudio(f func() error)
|
||||
OnResumeAudio(f func() error)
|
||||
AppendHookOnBeforeUpdate(f func() error)
|
||||
}
|
||||
|
||||
var hookForTesting hook
|
||||
var hookerForTesting hooker
|
||||
|
||||
func getHook() hook {
|
||||
if hookForTesting != nil {
|
||||
return hookForTesting
|
||||
func getHook() hooker {
|
||||
if hookerForTesting != nil {
|
||||
return hookerForTesting
|
||||
}
|
||||
return &hookImpl{}
|
||||
return &hookerImpl{}
|
||||
}
|
||||
|
||||
type hookImpl struct{}
|
||||
type hookerImpl struct{}
|
||||
|
||||
func (h *hookImpl) OnSuspendAudio(f func() error) {
|
||||
hooks.OnSuspendAudio(f)
|
||||
func (h *hookerImpl) OnSuspendAudio(f func() error) {
|
||||
hook.OnSuspendAudio(f)
|
||||
}
|
||||
|
||||
func (h *hookImpl) OnResumeAudio(f func() error) {
|
||||
hooks.OnResumeAudio(f)
|
||||
func (h *hookerImpl) OnResumeAudio(f func() error) {
|
||||
hook.OnResumeAudio(f)
|
||||
}
|
||||
|
||||
func (h *hookImpl) AppendHookOnBeforeUpdate(f func() error) {
|
||||
hooks.AppendHookOnBeforeUpdate(f)
|
||||
func (h *hookerImpl) AppendHookOnBeforeUpdate(f func() error) {
|
||||
hook.AppendHookOnBeforeUpdate(f)
|
||||
}
|
||||
|
||||
// Resample converts the sample rate of the given stream.
|
||||
|
@ -127,11 +127,11 @@ func (h *dummyHook) AppendHookOnBeforeUpdate(f func() error) {
|
||||
}
|
||||
|
||||
func init() {
|
||||
hookForTesting = &dummyHook{}
|
||||
hookerForTesting = &dummyHook{}
|
||||
}
|
||||
|
||||
func UpdateForTesting() error {
|
||||
for _, f := range hookForTesting.(*dummyHook).updates {
|
||||
for _, f := range hookerForTesting.(*dummyHook).updates {
|
||||
if err := f(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -59,7 +59,6 @@ func newPlayerFactory(sampleRate int) *playerFactory {
|
||||
if driverForTesting != nil {
|
||||
f.context = driverForTesting
|
||||
}
|
||||
// TODO: Consider the hooks.
|
||||
return f
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/hooks"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/hook"
|
||||
)
|
||||
|
||||
type pos struct {
|
||||
@ -80,7 +80,7 @@ var theInputState = &inputState{
|
||||
}
|
||||
|
||||
func init() {
|
||||
hooks.AppendHookOnBeforeUpdate(func() error {
|
||||
hook.AppendHookOnBeforeUpdate(func() error {
|
||||
theInputState.update()
|
||||
return nil
|
||||
})
|
||||
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package hooks
|
||||
package hook
|
||||
|
||||
import (
|
||||
"sync"
|
||||
@ -20,10 +20,10 @@ import (
|
||||
|
||||
var m sync.Mutex
|
||||
|
||||
var onBeforeUpdateHooks = []func() error{}
|
||||
var onBeforeUpdateHooks []func() error
|
||||
|
||||
// AppendHookOnBeforeUpdate appends a hook function that is run before the main update function
|
||||
// every frame.
|
||||
// every tick.
|
||||
func AppendHookOnBeforeUpdate(f func() error) {
|
||||
m.Lock()
|
||||
onBeforeUpdateHooks = append(onBeforeUpdateHooks, f)
|
@ -23,7 +23,7 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/clock"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/debug"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/hooks"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/hook"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/mipmap"
|
||||
)
|
||||
|
||||
@ -133,7 +133,7 @@ func (c *context) updateFrameImpl(graphicsDriver graphicsdriver.Graphics, update
|
||||
ui.readInputState(inputState)
|
||||
})
|
||||
|
||||
if err := hooks.RunBeforeUpdateHooks(); err != nil {
|
||||
if err := hook.RunBeforeUpdateHooks(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := c.game.Update(); err != nil {
|
||||
|
@ -31,7 +31,7 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/gamepad"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/glfw"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/hooks"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/hook"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/microsoftgdk"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/thread"
|
||||
)
|
||||
@ -1380,7 +1380,7 @@ func (u *userInterfaceImpl) update() (float64, float64, error) {
|
||||
return 0, 0, err
|
||||
}
|
||||
for visible != 0 && !u.isRunnableOnUnfocused() && focused == 0 && !shouldClose {
|
||||
if err := hooks.SuspendAudio(); err != nil {
|
||||
if err := hook.SuspendAudio(); err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
// Wait for an arbitrary period to avoid busy loop.
|
||||
@ -1389,7 +1389,7 @@ func (u *userInterfaceImpl) update() (float64, float64, error) {
|
||||
return 0, 0, err
|
||||
}
|
||||
}
|
||||
if err := hooks.ResumeAudio(); err != nil {
|
||||
if err := hook.ResumeAudio(); err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/gamepad"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/hooks"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/hook"
|
||||
)
|
||||
|
||||
type graphicsDriverCreatorImpl struct {
|
||||
@ -338,9 +338,9 @@ func (u *userInterfaceImpl) update() error {
|
||||
}
|
||||
|
||||
if u.suspended() {
|
||||
return hooks.SuspendAudio()
|
||||
return hook.SuspendAudio()
|
||||
}
|
||||
if err := hooks.ResumeAudio(); err != nil {
|
||||
if err := hook.ResumeAudio(); err != nil {
|
||||
return err
|
||||
}
|
||||
return u.updateImpl(false)
|
||||
@ -465,12 +465,12 @@ func (u *userInterfaceImpl) loop(game Game) <-chan error {
|
||||
select {
|
||||
case <-t.C:
|
||||
if u.suspended() {
|
||||
if err := hooks.SuspendAudio(); err != nil {
|
||||
if err := hook.SuspendAudio(); err != nil {
|
||||
errCh <- err
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if err := hooks.ResumeAudio(); err != nil {
|
||||
if err := hook.ResumeAudio(); err != nil {
|
||||
errCh <- err
|
||||
return
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/gamepad"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/hooks"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/hook"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/restorable"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/thread"
|
||||
)
|
||||
@ -231,9 +231,9 @@ func (u *userInterfaceImpl) SetForeground(foreground bool) error {
|
||||
atomic.StoreInt32(&u.foreground, v)
|
||||
|
||||
if foreground {
|
||||
return hooks.ResumeAudio()
|
||||
return hook.ResumeAudio()
|
||||
} else {
|
||||
return hooks.SuspendAudio()
|
||||
return hook.SuspendAudio()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ import (
|
||||
"golang.org/x/image/math/fixed"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/hooks"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/hook"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -38,7 +38,7 @@ func now() int64 {
|
||||
}
|
||||
|
||||
func init() {
|
||||
hooks.AppendHookOnBeforeUpdate(func() error {
|
||||
hook.AppendHookOnBeforeUpdate(func() error {
|
||||
monotonicClock++
|
||||
return nil
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user