mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-24 18:02:02 +01:00
Refactoring
This commit is contained in:
parent
f72076641a
commit
2bc4d6bf14
@ -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 {
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user