mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
ebiten: refactoring: remove the global variable theGameForUI
This commit is contained in:
parent
82b9f7dc56
commit
0529fa955e
13
gameforui.go
13
gameforui.go
@ -16,7 +16,6 @@ package ebiten
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
)
|
||||
@ -25,16 +24,12 @@ type gameForUI struct {
|
||||
game Game
|
||||
offscreen *Image
|
||||
screen *Image
|
||||
|
||||
m sync.Mutex
|
||||
}
|
||||
|
||||
var theGameForUI = &gameForUI{}
|
||||
|
||||
func (c *gameForUI) set(game Game) {
|
||||
c.m.Lock()
|
||||
defer c.m.Unlock()
|
||||
c.game = game
|
||||
func newGameForUI(game Game) *gameForUI {
|
||||
return &gameForUI{
|
||||
game: game,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *gameForUI) Layout(outsideWidth, outsideHeight float64, deviceScaleFactor float64) (int, int) {
|
||||
|
4
run.go
4
run.go
@ -150,10 +150,10 @@ func RunGame(game Game) error {
|
||||
defer atomic.StoreInt32(&isRunGameEnded_, 1)
|
||||
|
||||
initializeWindowPositionIfNeeded(WindowSize())
|
||||
theGameForUI.set(&imageDumperGame{
|
||||
g := newGameForUI(&imageDumperGame{
|
||||
game: game,
|
||||
})
|
||||
if err := ui.Get().Run(theGameForUI); err != nil {
|
||||
if err := ui.Get().Run(g); err != nil {
|
||||
if err == ui.RegularTermination {
|
||||
return nil
|
||||
}
|
||||
|
@ -27,8 +27,7 @@ import (
|
||||
// Ebiten users should NOT call RunGameWithoutMainLoop.
|
||||
// Instead, functions in github.com/hajimehoshi/ebiten/v2/mobile package calls this.
|
||||
//
|
||||
// TODO: Remove this. In order to remove this, the uiContext should be in another package.
|
||||
// TODO: Remove this. In order to remove this, the gameForUI should be in another package.
|
||||
func RunGameWithoutMainLoop(game Game) {
|
||||
theGameForUI.set(game)
|
||||
ui.Get().RunWithoutMainLoop(theGameForUI)
|
||||
ui.Get().RunWithoutMainLoop(newGameForUI(game))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user