driver: Move ui.RegularTermination to driver

This commit is contained in:
Hajime Hoshi 2019-04-07 10:54:05 +09:00
parent 1b8d4abfdb
commit 6b8516c7a5
4 changed files with 12 additions and 26 deletions

View File

@ -14,7 +14,16 @@
package driver package driver
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
} }
// 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

@ -1,24 +0,0 @@
// Copyright 2015 Hajime Hoshi
//
// 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 ui
import (
"errors"
)
// 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

@ -745,7 +745,7 @@ func (u *userInterface) update(g driver.GraphicsContext) error {
return nil return nil
}) })
if shouldClose { if shouldClose {
return RegularTermination return driver.RegularTermination
} }
_ = mainthread.Run(func() error { _ = mainthread.Run(func() error {

3
run.go
View File

@ -19,6 +19,7 @@ import (
"sync/atomic" "sync/atomic"
"github.com/hajimehoshi/ebiten/internal/clock" "github.com/hajimehoshi/ebiten/internal/clock"
"github.com/hajimehoshi/ebiten/internal/driver"
"github.com/hajimehoshi/ebiten/internal/input" "github.com/hajimehoshi/ebiten/internal/input"
"github.com/hajimehoshi/ebiten/internal/ui" "github.com/hajimehoshi/ebiten/internal/ui"
"github.com/hajimehoshi/ebiten/internal/web" "github.com/hajimehoshi/ebiten/internal/web"
@ -98,7 +99,7 @@ func run(width, height int, scale float64, title string, g *graphicsContext, mai
defer atomic.StoreInt32(&isRunning, 0) defer atomic.StoreInt32(&isRunning, 0)
} }
if err := ui.Run(width, height, scale, title, g, mainloop, graphicsDriver(), input.Get()); err != nil { if err := ui.Run(width, height, scale, title, g, mainloop, graphicsDriver(), input.Get()); err != nil {
if err == ui.RegularTermination { if err == driver.RegularTermination {
return nil return nil
} }
return err return err