Remove Device.Drawing

This commit is contained in:
Hajime Hoshi 2013-10-06 18:22:45 +09:00
parent df84d26636
commit a35c74790c
2 changed files with 20 additions and 26 deletions

View File

@ -32,17 +32,15 @@ import (
)
type Device struct {
screenScale int
context *Context
drawing chan chan func(graphics.Context)
screenScale int
context *Context
}
func NewDevice(screenWidth, screenHeight, screenScale int) *Device {
graphicsContext := newContext(screenWidth, screenHeight, screenScale)
device := &Device{
screenScale: screenScale,
context: graphicsContext,
drawing: make(chan chan func(graphics.Context)),
screenScale: screenScale,
context: graphicsContext,
}
return device
}
@ -51,11 +49,7 @@ func (device *Device) Init() {
device.context.Init()
}
func (device *Device) Drawing() <-chan chan func(graphics.Context) {
return device.drawing
}
func (device *Device) Update() {
func (device *Device) Update(draw func(graphics.Context)) {
context := device.context
C.glEnable(C.GL_TEXTURE_2D)
C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MIN_FILTER, C.GL_NEAREST)
@ -63,10 +57,7 @@ func (device *Device) Update() {
context.SetOffscreen(context.Screen().ID())
context.Clear()
ch := make(chan func(graphics.Context))
device.drawing <- ch
drawable := <-ch
drawable(context)
draw(context)
context.flush()

View File

@ -58,13 +58,17 @@ type GlutUI struct {
screenScale int
glutInputting chan glutInputEvent
graphicsDevice *opengl.Device
updating chan func(graphics.Context)
updated chan bool
}
var currentUI *GlutUI
//export display
func display() {
currentUI.graphicsDevice.Update()
draw := <-currentUI.updating
currentUI.graphicsDevice.Update(draw)
currentUI.updated <- true
C.glutSwapBuffers()
}
@ -99,6 +103,8 @@ func new(screenWidth, screenHeight, screenScale int, title string) *GlutUI {
ui := &GlutUI{
glutInputting: make(chan glutInputEvent, 10),
graphicsDevice: graphicsDevice,
updating: make(chan func(graphics.Context)),
updated: make(chan bool),
}
cargs := []*C.char{}
@ -137,7 +143,6 @@ func Run(game ebiten.Game, screenScale int, title string) {
currentUI = ui
game.Init(ui.graphicsDevice.TextureFactory())
draw := ui.graphicsDevice.Drawing()
input := make(chan ebiten.InputState)
go func() {
@ -168,22 +173,20 @@ func Run(game ebiten.Game, screenScale int, title string) {
go func() {
frameTime := time.Duration(
int64(time.Second) / int64(game.Fps()))
update := time.Tick(frameTime)
tick := time.Tick(frameTime)
gameContext := &GameContext{
inputState: ebiten.InputState{-1, -1},
}
draw := func(context graphics.Context) {
game.Draw(context)
}
for {
select {
case gameContext.inputState = <-input:
case <-update:
case <-tick:
game.Update(gameContext)
case drawing := <-draw:
ch := make(chan interface{})
drawing <- func(context graphics.Context) {
game.Draw(context)
close(ch)
}
<-ch
case ui.updating <- draw:
<-ui.updated
}
if gameContext.terminated {
break