mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
ui: Reduce methods in UserInterface
This commit is contained in:
parent
93a994f1d6
commit
571d67f967
@ -109,15 +109,12 @@ func Run(g GraphicsContext, width, height int, scale float64, title string, fps
|
||||
currentRunContext.startRunning()
|
||||
defer currentRunContext.endRunning()
|
||||
|
||||
if err := ui.CurrentUI().Start(width, height, scale, title); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
n := now()
|
||||
currentRunContext.lastUpdated = n
|
||||
currentRunContext.lastFPSUpdated = n
|
||||
|
||||
if err := ui.CurrentUI().AnimationFrameLoop(&loopGraphicsContext{currentRunContext, g}); err != nil {
|
||||
lg := &loopGraphicsContext{currentRunContext, g}
|
||||
if err := ui.CurrentUI().Run(width, height, scale, title, lg); err != nil {
|
||||
if _, ok := err.(*ui.RegularTermination); ok {
|
||||
return nil
|
||||
}
|
||||
|
@ -20,8 +20,7 @@ type GraphicsContext interface {
|
||||
}
|
||||
|
||||
type UserInterface interface {
|
||||
Start(width, height int, scale float64, title string) error
|
||||
AnimationFrameLoop(g GraphicsContext) error
|
||||
Run(width, height int, scale float64, title string, g GraphicsContext) error
|
||||
ScreenScale() float64
|
||||
SetScreenSize(width, height int) (bool, error)
|
||||
SetScreenScale(scale float64) (bool, error)
|
||||
|
@ -147,7 +147,7 @@ func (u *userInterface) ScreenScale() float64 {
|
||||
return s
|
||||
}
|
||||
|
||||
func (u *userInterface) Start(width, height int, scale float64, title string) error {
|
||||
func (u *userInterface) Run(width, height int, scale float64, title string, g GraphicsContext) error {
|
||||
// GLContext must be created before setting the screen size, which requires
|
||||
// swapping buffers.
|
||||
var err error
|
||||
@ -176,7 +176,7 @@ func (u *userInterface) Start(width, height int, scale float64, title string) er
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return u.loop(g)
|
||||
}
|
||||
|
||||
func (u *userInterface) glfwSize() (int, int) {
|
||||
@ -241,7 +241,7 @@ func (u *userInterface) update(g GraphicsContext) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *userInterface) AnimationFrameLoop(g GraphicsContext) error {
|
||||
func (u *userInterface) loop(g GraphicsContext) error {
|
||||
defer func() {
|
||||
_ = u.runOnMainThread(func() error {
|
||||
glfw.Terminate()
|
||||
|
@ -87,7 +87,7 @@ func (u *userInterface) update(g GraphicsContext) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *userInterface) AnimationFrameLoop(g GraphicsContext) error {
|
||||
func (u *userInterface) loop(g GraphicsContext) error {
|
||||
ch := make(chan error)
|
||||
var f func()
|
||||
f = func() {
|
||||
@ -262,7 +262,7 @@ func Main(ch <-chan error) error {
|
||||
return <-ch
|
||||
}
|
||||
|
||||
func (u *userInterface) Start(width, height int, scale float64, title string) error {
|
||||
func (u *userInterface) Run(width, height int, scale float64, title string, g GraphicsContext) error {
|
||||
doc := js.Global.Get("document")
|
||||
doc.Set("title", title)
|
||||
u.setScreenSize(width, height, scale)
|
||||
@ -272,7 +272,7 @@ func (u *userInterface) Start(width, height int, scale float64, title string) er
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return u.loop(g)
|
||||
}
|
||||
|
||||
func (u *userInterface) size() (width, height int) {
|
||||
|
@ -64,7 +64,7 @@ func CurrentUI() UserInterface {
|
||||
return currentUI
|
||||
}
|
||||
|
||||
func (u *userInterface) Start(width, height int, scale float64, title string) error {
|
||||
func (u *userInterface) Run(width, height int, scale float64, title string, g GraphicsContext) error {
|
||||
u.width = width
|
||||
u.height = height
|
||||
u.scale = scale
|
||||
@ -74,10 +74,6 @@ func (u *userInterface) Start(width, height int, scale float64, title string) er
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *userInterface) AnimationFrameLoop(g GraphicsContext) error {
|
||||
for {
|
||||
if err := u.update(g); err != nil {
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user