mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 03:02:49 +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 {
|
func newContext(screenWidth, screenHeight, screenScale int) *Context {
|
||||||
return &Context{
|
context := &Context{
|
||||||
screenWidth: screenWidth,
|
screenWidth: screenWidth,
|
||||||
screenHeight: screenHeight,
|
screenHeight: screenHeight,
|
||||||
screenScale: screenScale,
|
screenScale: screenScale,
|
||||||
ids: newIds(),
|
ids: newIds(),
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (context *Context) Init() {
|
|
||||||
C.glEnable(C.GL_TEXTURE_2D)
|
C.glEnable(C.GL_TEXTURE_2D)
|
||||||
C.glEnable(C.GL_BLEND)
|
C.glEnable(C.GL_BLEND)
|
||||||
|
|
||||||
@ -60,6 +58,8 @@ func (context *Context) Init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic("initializing the offscreen failed: " + err.Error())
|
panic("initializing the offscreen failed: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return context
|
||||||
}
|
}
|
||||||
|
|
||||||
func (context *Context) ToTexture(renderTargetId graphics.RenderTargetId) graphics.TextureId {
|
func (context *Context) ToTexture(renderTargetId graphics.RenderTargetId) graphics.TextureId {
|
||||||
|
@ -3,25 +3,17 @@ package opengl
|
|||||||
import (
|
import (
|
||||||
"github.com/hajimehoshi/go-ebiten/graphics"
|
"github.com/hajimehoshi/go-ebiten/graphics"
|
||||||
"github.com/hajimehoshi/go-ebiten/graphics/matrix"
|
"github.com/hajimehoshi/go-ebiten/graphics/matrix"
|
||||||
"runtime"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
screenScale int
|
|
||||||
context *Context
|
context *Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDevice(screenWidth, screenHeight, screenScale int) *Device {
|
func NewDevice(screenWidth, screenHeight, screenScale int) *Device {
|
||||||
graphicsContext := newContext(screenWidth, screenHeight, screenScale)
|
graphicsContext := newContext(screenWidth, screenHeight, screenScale)
|
||||||
device := &Device{
|
return &Device{
|
||||||
screenScale: screenScale,
|
|
||||||
context: graphicsContext,
|
context: graphicsContext,
|
||||||
}
|
}
|
||||||
return device
|
|
||||||
}
|
|
||||||
|
|
||||||
func (device *Device) Init() {
|
|
||||||
device.context.Init()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (device *Device) Update(draw func(graphics.Context)) {
|
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 {
|
func (device *Device) TextureFactory() graphics.TextureFactory {
|
||||||
return device.context
|
return device.context
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
|
||||||
runtime.LockOSThread()
|
|
||||||
}
|
|
||||||
|
@ -14,9 +14,14 @@ import (
|
|||||||
"github.com/hajimehoshi/go-ebiten/graphics/opengl"
|
"github.com/hajimehoshi/go-ebiten/graphics/opengl"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
"runtime"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
}
|
||||||
|
|
||||||
type GameContext struct {
|
type GameContext struct {
|
||||||
screenWidth int
|
screenWidth int
|
||||||
screenHeight int
|
screenHeight int
|
||||||
@ -90,6 +95,7 @@ func (ui *UI) gameMainLoop(game ebiten.Game) {
|
|||||||
|
|
||||||
func (ui *UI) Run(game ebiten.Game) {
|
func (ui *UI) Run(game ebiten.Game) {
|
||||||
go ui.gameMainLoop(game)
|
go ui.gameMainLoop(game)
|
||||||
|
runtime.LockOSThread()
|
||||||
|
|
||||||
cTitle := C.CString(ui.title)
|
cTitle := C.CString(ui.title)
|
||||||
defer C.free(unsafe.Pointer(cTitle))
|
defer C.free(unsafe.Pointer(cTitle))
|
||||||
@ -126,7 +132,6 @@ func ebiten_EbitenOpenGLView_Initialized() {
|
|||||||
currentUI.screenWidth,
|
currentUI.screenWidth,
|
||||||
currentUI.screenHeight,
|
currentUI.screenHeight,
|
||||||
currentUI.screenScale)
|
currentUI.screenScale)
|
||||||
currentUI.graphicsDevice.Init()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//export ebiten_EbitenOpenGLView_Updating
|
//export ebiten_EbitenOpenGLView_Updating
|
||||||
|
Loading…
Reference in New Issue
Block a user