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
import (
"errors"
)
type GraphicsContext interface {
SetSize(width, height int, scale float64)
Update(afterFrameUpdate func()) error
Invalidate()
}
type RegularTermination struct {
}
func (*RegularTermination) Error() string {
return "regular termination"
}
// 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.
var RegularTermination = errors.New("regular termination")

View File

@ -446,7 +446,7 @@ func (u *userInterface) update(g GraphicsContext) error {
return nil
})
if shouldClose {
return &RegularTermination{}
return RegularTermination
}
_ = 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 {
if err := ui.Run(width, height, scale, title, g); err != nil {
if _, ok := err.(*ui.RegularTermination); ok {
if err == ui.RegularTermination {
return nil
}
return err