internal/hooks: Rename Update -> BeforeUpdate

This commit is contained in:
Hajime Hoshi 2018-03-15 02:50:10 +09:00
parent e085f511ec
commit 1b0e71765f
4 changed files with 9 additions and 9 deletions

View File

@ -166,7 +166,7 @@ var (
) )
func init() { func init() {
hooks.AppendHookOnUpdate(func() error { hooks.AppendHookOnBeforeUpdate(func() error {
var err error var err error
theContextLock.Lock() theContextLock.Lock()
if theContext != nil { if theContext != nil {

View File

@ -88,7 +88,7 @@ func (c *graphicsContext) Update(afterFrameUpdate func()) error {
c.offscreen.fill(0, 0, 0, 0) c.offscreen.fill(0, 0, 0, 0)
setRunningSlowly(i < updateCount-1) setRunningSlowly(i < updateCount-1)
if err := hooks.Run(); err != nil { if err := hooks.RunBeforeUpdateHooks(); err != nil {
return err return err
} }
if err := c.f(c.offscreen); err != nil { if err := c.f(c.offscreen); err != nil {

View File

@ -54,7 +54,7 @@ var theInputState = &inputState{
} }
func init() { func init() {
hooks.AppendHookOnUpdate(func() error { hooks.AppendHookOnBeforeUpdate(func() error {
theInputState.update() theInputState.update()
return nil return nil
}) })

View File

@ -14,16 +14,16 @@
package hooks package hooks
var onUpdateHooks = []func() error{} var onBeforeUpdateHooks = []func() error{}
// AppendHookOnUpdate appends a hook function that is run before the main update function // AppendHookOnBeforeUpdate appends a hook function that is run before the main update function
// every frame. // every frame.
func AppendHookOnUpdate(f func() error) { func AppendHookOnBeforeUpdate(f func() error) {
onUpdateHooks = append(onUpdateHooks, f) onBeforeUpdateHooks = append(onBeforeUpdateHooks, f)
} }
func Run() error { func RunBeforeUpdateHooks() error {
for _, f := range onUpdateHooks { for _, f := range onBeforeUpdateHooks {
if err := f(); err != nil { if err := f(); err != nil {
return err return err
} }