From 3df2ffebd102e1b451ae9c88619459f88c2ae98c Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 5 Nov 2023 00:49:53 +0900 Subject: [PATCH] internal/ui: refactoring: integrate Run except for mobiles --- internal/ui/run.go | 8 ++++++++ internal/ui/ui_glfw.go | 7 ------- internal/ui/ui_js.go | 4 ---- internal/ui/ui_nintendosdk.go | 7 ------- internal/ui/ui_playstation5.go | 7 ------- 5 files changed, 8 insertions(+), 25 deletions(-) diff --git a/internal/ui/run.go b/internal/ui/run.go index ebcbd76f3..03946076f 100644 --- a/internal/ui/run.go +++ b/internal/ui/run.go @@ -18,6 +18,7 @@ package ui import ( stdcontext "context" + "runtime" "golang.org/x/sync/errgroup" @@ -25,6 +26,13 @@ import ( "github.com/hajimehoshi/ebiten/v2/internal/thread" ) +func (u *UserInterface) Run(game Game, options *RunOptions) error { + if options.SingleThread || buildTagSingleThread || runtime.GOOS == "js" { + return u.runSingleThread(game, options) + } + return u.runMultiThread(game, options) +} + func (u *UserInterface) runMultiThread(game Game, options *RunOptions) error { u.mainThread = thread.NewOSThread() u.renderThread = thread.NewOSThread() diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index 13bf5135f..8907a6b48 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -120,13 +120,6 @@ func init() { runtime.LockOSThread() } -func (u *UserInterface) Run(game Game, options *RunOptions) error { - if options.SingleThread || buildTagSingleThread { - return u.runSingleThread(game, options) - } - return u.runMultiThread(game, options) -} - func (u *UserInterface) init() error { u.userInterfaceImpl = userInterfaceImpl{ runnableOnUnfocused: true, diff --git a/internal/ui/ui_js.go b/internal/ui/ui_js.go index 205e1979b..b2d70f41d 100644 --- a/internal/ui/ui_js.go +++ b/internal/ui/ui_js.go @@ -740,10 +740,6 @@ func (u *UserInterface) forceUpdateOnMinimumFPSMode() { }() } -func (u *UserInterface) Run(game Game, options *RunOptions) error { - return u.runSingleThread(game, options) -} - func (u *UserInterface) initOnMainThread(options *RunOptions) error { if !options.InitUnfocused && window.Truthy() { // Do not focus the canvas when the current document is in an iframe. diff --git a/internal/ui/ui_nintendosdk.go b/internal/ui/ui_nintendosdk.go index 237b451d6..29d871cda 100644 --- a/internal/ui/ui_nintendosdk.go +++ b/internal/ui/ui_nintendosdk.go @@ -75,13 +75,6 @@ func (u *UserInterface) init() error { return nil } -func (u *UserInterface) Run(game Game, options *RunOptions) error { - if options.SingleThread || buildTagSingleThread { - return u.runSingleThread(game, options) - } - return u.runMultiThread(game, options) -} - func (u *UserInterface) initOnMainThread(options *RunOptions) error { g, lib, err := newGraphicsDriver(&graphicsDriverCreatorImpl{}, options.GraphicsLibrary) if err != nil { diff --git a/internal/ui/ui_playstation5.go b/internal/ui/ui_playstation5.go index a45714c3a..b6e5af155 100644 --- a/internal/ui/ui_playstation5.go +++ b/internal/ui/ui_playstation5.go @@ -69,13 +69,6 @@ func (u *UserInterface) init() error { return nil } -func (u *UserInterface) Run(game Game, options *RunOptions) error { - if options.SingleThread || buildTagSingleThread { - return u.runSingleThread(game, options) - } - return u.runMultiThread(game, options) -} - func (u *UserInterface) initOnMainThread(options *RunOptions) error { g, lib, err := newGraphicsDriver(&graphicsDriverCreatorImpl{}, options.GraphicsLibrary) if err != nil {