mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||||
)
|
)
|
||||||
@ -25,16 +24,12 @@ type gameForUI struct {
|
|||||||
game Game
|
game Game
|
||||||
offscreen *Image
|
offscreen *Image
|
||||||
screen *Image
|
screen *Image
|
||||||
|
|
||||||
m sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var theGameForUI = &gameForUI{}
|
func newGameForUI(game Game) *gameForUI {
|
||||||
|
return &gameForUI{
|
||||||
func (c *gameForUI) set(game Game) {
|
game: game,
|
||||||
c.m.Lock()
|
}
|
||||||
defer c.m.Unlock()
|
|
||||||
c.game = game
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *gameForUI) Layout(outsideWidth, outsideHeight float64, deviceScaleFactor float64) (int, int) {
|
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)
|
defer atomic.StoreInt32(&isRunGameEnded_, 1)
|
||||||
|
|
||||||
initializeWindowPositionIfNeeded(WindowSize())
|
initializeWindowPositionIfNeeded(WindowSize())
|
||||||
theGameForUI.set(&imageDumperGame{
|
g := newGameForUI(&imageDumperGame{
|
||||||
game: game,
|
game: game,
|
||||||
})
|
})
|
||||||
if err := ui.Get().Run(theGameForUI); err != nil {
|
if err := ui.Get().Run(g); err != nil {
|
||||||
if err == ui.RegularTermination {
|
if err == ui.RegularTermination {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,7 @@ import (
|
|||||||
// Ebiten users should NOT call RunGameWithoutMainLoop.
|
// Ebiten users should NOT call RunGameWithoutMainLoop.
|
||||||
// Instead, functions in github.com/hajimehoshi/ebiten/v2/mobile package calls this.
|
// 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) {
|
func RunGameWithoutMainLoop(game Game) {
|
||||||
theGameForUI.set(game)
|
ui.Get().RunWithoutMainLoop(newGameForUI(game))
|
||||||
ui.Get().RunWithoutMainLoop(theGameForUI)
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user