ui: Change RegularTermination to a value

This commit is contained in:
Hajime Hoshi 2018-02-04 00:22:38 +09:00
parent 1815eec806
commit e3023889ac
3 changed files with 10 additions and 8 deletions

View File

@ -14,15 +14,17 @@
package ui package ui
import (
"errors"
)
type GraphicsContext interface { type GraphicsContext interface {
SetSize(width, height int, scale float64) SetSize(width, height int, scale float64)
Update(afterFrameUpdate func()) error Update(afterFrameUpdate func()) error
Invalidate() Invalidate()
} }
type RegularTermination struct { // RegularTermination represents a regular termination.
} // Run can return this error, and if this error is received,
// the game loop should be terminated as soon as possible.
func (*RegularTermination) Error() string { var RegularTermination = errors.New("regular termination")
return "regular termination"
}

View File

@ -446,7 +446,7 @@ func (u *userInterface) update(g GraphicsContext) error {
return nil return nil
}) })
if shouldClose { if shouldClose {
return &RegularTermination{} return RegularTermination
} }
_ = u.runOnMainThread(func() error { _ = u.runOnMainThread(func() error {

2
run.go
View File

@ -80,7 +80,7 @@ var theGraphicsContext atomic.Value
func run(width, height int, scale float64, title string, g *graphicsContext) error { func run(width, height int, scale float64, title string, g *graphicsContext) error {
if err := ui.Run(width, height, scale, title, g); err != nil { if err := ui.Run(width, height, scale, title, g); err != nil {
if _, ok := err.(*ui.RegularTermination); ok { if err == ui.RegularTermination {
return nil return nil
} }
return err return err