Refactoring

This commit is contained in:
Hajime Hoshi 2013-07-06 00:27:36 +09:00
parent 0c8ba5fef6
commit 1826db6f2e
2 changed files with 12 additions and 18 deletions

View File

@ -60,8 +60,5 @@ func main() {
} }
const screenScale = 2 const screenScale = 2
screenWidth := game.ScreenWidth() glut.Run(game, screenScale)
screenHeight := game.ScreenHeight()
ui := glut.New(screenWidth, screenHeight, screenScale)
ui.Run(game)
} }

View File

@ -55,8 +55,6 @@ type glutInputEvent struct {
} }
type GlutUI struct { type GlutUI struct {
screenWidth int
screenHeight int
screenScale int screenScale int
glutInputting chan glutInputEvent glutInputting chan glutInputEvent
updating chan chan func() updating chan chan func()
@ -98,11 +96,8 @@ func idle() {
C.glutPostRedisplay() C.glutPostRedisplay()
} }
func New(screenWidth, screenHeight, screenScale int) *GlutUI { func new(screenWidth, screenHeight, screenScale int) *GlutUI {
ui := &GlutUI{ ui := &GlutUI{
screenWidth: screenWidth,
screenHeight: screenHeight,
screenScale: screenScale,
glutInputting: make(chan glutInputEvent, 10), glutInputting: make(chan glutInputEvent, 10),
updating: make(chan chan func()), updating: make(chan chan func()),
} }
@ -130,24 +125,26 @@ func New(screenWidth, screenHeight, screenScale int) *GlutUI {
C.setGlutFuncs() C.setGlutFuncs()
currentUI = ui
return ui return ui
} }
func (ui *GlutUI) Run(game ebiten.Game) { func Run(game ebiten.Game, screenScale int) {
screenWidth := game.ScreenWidth()
screenHeight := game.ScreenHeight()
ui := new(screenWidth, screenHeight, screenScale)
currentUI = ui
graphicsDevice := opengl.NewDevice( graphicsDevice := opengl.NewDevice(
ui.screenWidth, ui.screenHeight, ui.screenScale, screenWidth, screenHeight, screenScale,
currentUI.updating) ui.updating)
game.Init(graphicsDevice.TextureFactory()) game.Init(graphicsDevice.TextureFactory())
draw := graphicsDevice.Drawing() draw := graphicsDevice.Drawing()
input := make(chan ebiten.InputState) input := make(chan ebiten.InputState)
go func() { go func() {
screenWidth := ui.screenWidth ch := ui.glutInputting
screenHeight := ui.screenHeight
screenScale := ui.screenScale
ch := currentUI.glutInputting
for { for {
event := <-ch event := <-ch
inputState := ebiten.InputState{-1, -1} inputState := ebiten.InputState{-1, -1}