From 2bc4d6bf14a9f7f3902100e3991f6835cb5ad3f6 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 21 Nov 2013 00:05:57 +0900 Subject: [PATCH] Refactoring --- graphics/opengl/context.go | 6 +++--- graphics/opengl/device.go | 14 +------------- ui/cocoa/cocoa.go | 7 ++++++- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/graphics/opengl/context.go b/graphics/opengl/context.go index 7f3c1c513..2321338d0 100644 --- a/graphics/opengl/context.go +++ b/graphics/opengl/context.go @@ -29,15 +29,13 @@ type Context struct { } func newContext(screenWidth, screenHeight, screenScale int) *Context { - return &Context{ + context := &Context{ screenWidth: screenWidth, screenHeight: screenHeight, screenScale: screenScale, ids: newIds(), } -} -func (context *Context) Init() { C.glEnable(C.GL_TEXTURE_2D) C.glEnable(C.GL_BLEND) @@ -60,6 +58,8 @@ func (context *Context) Init() { if err != nil { panic("initializing the offscreen failed: " + err.Error()) } + + return context } func (context *Context) ToTexture(renderTargetId graphics.RenderTargetId) graphics.TextureId { diff --git a/graphics/opengl/device.go b/graphics/opengl/device.go index 55af25295..0380001ac 100644 --- a/graphics/opengl/device.go +++ b/graphics/opengl/device.go @@ -3,25 +3,17 @@ package opengl import ( "github.com/hajimehoshi/go-ebiten/graphics" "github.com/hajimehoshi/go-ebiten/graphics/matrix" - "runtime" ) type Device struct { - screenScale int context *Context } func NewDevice(screenWidth, screenHeight, screenScale int) *Device { graphicsContext := newContext(screenWidth, screenHeight, screenScale) - device := &Device{ - screenScale: screenScale, + return &Device{ context: graphicsContext, } - return device -} - -func (device *Device) Init() { - device.context.Init() } func (device *Device) Update(draw func(graphics.Context)) { @@ -46,7 +38,3 @@ func (device *Device) Update(draw func(graphics.Context)) { func (device *Device) TextureFactory() graphics.TextureFactory { return device.context } - -func init() { - runtime.LockOSThread() -} diff --git a/ui/cocoa/cocoa.go b/ui/cocoa/cocoa.go index 7dc8a79f4..db94c92aa 100644 --- a/ui/cocoa/cocoa.go +++ b/ui/cocoa/cocoa.go @@ -14,9 +14,14 @@ import ( "github.com/hajimehoshi/go-ebiten/graphics/opengl" "sync" "time" + "runtime" "unsafe" ) +func init() { + runtime.LockOSThread() +} + type GameContext struct { screenWidth int screenHeight int @@ -90,6 +95,7 @@ func (ui *UI) gameMainLoop(game ebiten.Game) { func (ui *UI) Run(game ebiten.Game) { go ui.gameMainLoop(game) + runtime.LockOSThread() cTitle := C.CString(ui.title) defer C.free(unsafe.Pointer(cTitle)) @@ -126,7 +132,6 @@ func ebiten_EbitenOpenGLView_Initialized() { currentUI.screenWidth, currentUI.screenHeight, currentUI.screenScale) - currentUI.graphicsDevice.Init() } //export ebiten_EbitenOpenGLView_Updating