mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 10:42:42 +01:00
Refactoring
This commit is contained in:
parent
a6ebcbbda6
commit
5828feadd7
@ -45,6 +45,8 @@ type Texture interface {
|
|||||||
|
|
||||||
type TextureID int
|
type TextureID int
|
||||||
|
|
||||||
|
// The interface of a render target. This is essentially same as a texture, but
|
||||||
|
// it is assumed that the all alpha of a render target is maximum.
|
||||||
type RenderTarget interface {
|
type RenderTarget interface {
|
||||||
Texture() Texture
|
Texture() Texture
|
||||||
ID() RenderTargetID
|
ID() RenderTargetID
|
||||||
|
@ -17,14 +17,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type UI struct {
|
type UI struct {
|
||||||
game ebiten.Game
|
|
||||||
screenWidth int
|
screenWidth int
|
||||||
screenHeight int
|
screenHeight int
|
||||||
screenScale int
|
screenScale int
|
||||||
graphicsDevice *opengl.Device
|
graphicsDevice *opengl.Device
|
||||||
inited chan bool
|
initializing chan ebiten.Game
|
||||||
updating chan bool
|
initialized chan ebiten.Game
|
||||||
updated chan bool
|
updating chan ebiten.Game
|
||||||
|
updated chan ebiten.Game
|
||||||
input chan ebiten.InputState
|
input chan ebiten.InputState
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,16 +42,16 @@ func ebiten_EbitenOpenGLView_Initialized() {
|
|||||||
currentUI.screenScale)
|
currentUI.screenScale)
|
||||||
currentUI.graphicsDevice.Init()
|
currentUI.graphicsDevice.Init()
|
||||||
|
|
||||||
currentUI.game.Init(currentUI.graphicsDevice.TextureFactory())
|
game := <-currentUI.initializing
|
||||||
|
game.Init(currentUI.graphicsDevice.TextureFactory())
|
||||||
currentUI.inited <- true
|
currentUI.initialized <- game
|
||||||
}
|
}
|
||||||
|
|
||||||
//export ebiten_EbitenOpenGLView_Updating
|
//export ebiten_EbitenOpenGLView_Updating
|
||||||
func ebiten_EbitenOpenGLView_Updating() {
|
func ebiten_EbitenOpenGLView_Updating() {
|
||||||
<-currentUI.updating
|
game := <-currentUI.updating
|
||||||
currentUI.graphicsDevice.Update(currentUI.game.Draw)
|
currentUI.graphicsDevice.Update(game.Draw)
|
||||||
currentUI.updated <- true
|
currentUI.updated <- game
|
||||||
}
|
}
|
||||||
|
|
||||||
//export ebiten_EbitenOpenGLView_InputUpdated
|
//export ebiten_EbitenOpenGLView_InputUpdated
|
||||||
@ -79,17 +79,14 @@ func ebiten_EbitenOpenGLView_InputUpdated(inputType C.InputType, cx, cy C.int) {
|
|||||||
|
|
||||||
func Run(game ebiten.Game, screenWidth, screenHeight, screenScale int,
|
func Run(game ebiten.Game, screenWidth, screenHeight, screenScale int,
|
||||||
title string) {
|
title string) {
|
||||||
cTitle := C.CString(title)
|
|
||||||
defer C.free(unsafe.Pointer(cTitle))
|
|
||||||
|
|
||||||
currentUI = &UI{
|
currentUI = &UI{
|
||||||
game: game,
|
|
||||||
screenWidth: screenWidth,
|
screenWidth: screenWidth,
|
||||||
screenHeight: screenHeight,
|
screenHeight: screenHeight,
|
||||||
screenScale: screenScale,
|
screenScale: screenScale,
|
||||||
inited: make(chan bool),
|
initializing: make(chan ebiten.Game),
|
||||||
updating: make(chan bool),
|
initialized: make(chan ebiten.Game),
|
||||||
updated: make(chan bool),
|
updating: make(chan ebiten.Game),
|
||||||
|
updated: make(chan ebiten.Game),
|
||||||
input: make(chan ebiten.InputState),
|
input: make(chan ebiten.InputState),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,18 +99,21 @@ func Run(game ebiten.Game, screenWidth, screenHeight, screenScale int,
|
|||||||
screenHeight: screenHeight,
|
screenHeight: screenHeight,
|
||||||
inputState: ebiten.InputState{-1, -1},
|
inputState: ebiten.InputState{-1, -1},
|
||||||
}
|
}
|
||||||
<-currentUI.inited
|
currentUI.initializing <- game
|
||||||
|
game = <-currentUI.initialized
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case gameContext.inputState = <-currentUI.input:
|
case gameContext.inputState = <-currentUI.input:
|
||||||
case <-tick:
|
case <-tick:
|
||||||
game.Update(gameContext)
|
game.Update(gameContext)
|
||||||
case currentUI.updating <- true:
|
case currentUI.updating <- game:
|
||||||
<-currentUI.updated
|
game = <-currentUI.updated
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
cTitle := C.CString(title)
|
||||||
|
defer C.free(unsafe.Pointer(cTitle))
|
||||||
C.Run(C.size_t(screenWidth),
|
C.Run(C.size_t(screenWidth),
|
||||||
C.size_t(screenHeight),
|
C.size_t(screenHeight),
|
||||||
C.size_t(screenScale),
|
C.size_t(screenScale),
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
// -*- objc -*-
|
// -*- objc -*-
|
||||||
|
|
||||||
#import "ebiten_opengl_view.h"
|
|
||||||
#import "ebiten_window.h"
|
#import "ebiten_window.h"
|
||||||
|
|
||||||
|
#import "ebiten_opengl_view.h"
|
||||||
|
|
||||||
@implementation EbitenWindow
|
@implementation EbitenWindow
|
||||||
|
|
||||||
- (id)initWithSize:(NSSize)size {
|
- (id)initWithSize:(NSSize)size {
|
||||||
[NSApplication sharedApplication];
|
|
||||||
NSUInteger style = (NSTitledWindowMask | NSClosableWindowMask |
|
NSUInteger style = (NSTitledWindowMask | NSClosableWindowMask |
|
||||||
NSMiniaturizableWindowMask);
|
NSMiniaturizableWindowMask);
|
||||||
NSRect windowRect =
|
NSRect windowRect =
|
||||||
@ -27,6 +27,21 @@
|
|||||||
[self setReleasedWhenClosed:YES];
|
[self setReleasedWhenClosed:YES];
|
||||||
[self setDelegate:self];
|
[self setDelegate:self];
|
||||||
[self setDocumentEdited:YES];
|
[self setDocumentEdited:YES];
|
||||||
|
|
||||||
|
NSRect rect = NSMakeRect(0, 0, size.width, size.height);
|
||||||
|
NSOpenGLPixelFormatAttribute attributes[] = {
|
||||||
|
NSOpenGLPFAWindow,
|
||||||
|
NSOpenGLPFADoubleBuffer,
|
||||||
|
NSOpenGLPFAAccelerated,
|
||||||
|
NSOpenGLPFADepthSize, 32,
|
||||||
|
0,
|
||||||
|
};
|
||||||
|
NSOpenGLPixelFormat* format = [[NSOpenGLPixelFormat alloc]
|
||||||
|
initWithAttributes:attributes];
|
||||||
|
EbitenOpenGLView* glView =
|
||||||
|
[[EbitenOpenGLView alloc] initWithFrame:rect
|
||||||
|
pixelFormat:format];
|
||||||
|
[self setContentView:glView];
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,37 +3,13 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#import "ebiten_controller.h"
|
#import "ebiten_controller.h"
|
||||||
#import "ebiten_opengl_view.h"
|
|
||||||
#import "ebiten_window.h"
|
#import "ebiten_window.h"
|
||||||
|
|
||||||
static NSWindow* generateWindow(size_t width, size_t height, size_t scale, const char* title) {
|
|
||||||
EbitenWindow* window = [[EbitenWindow alloc]
|
|
||||||
initWithSize:NSMakeSize(width * scale, height * scale)];
|
|
||||||
assert(window != nil);
|
|
||||||
|
|
||||||
NSRect const rect = NSMakeRect(0, 0, width * scale, height * scale);
|
|
||||||
NSOpenGLPixelFormatAttribute const attributes[] = {
|
|
||||||
NSOpenGLPFAWindow,
|
|
||||||
NSOpenGLPFADoubleBuffer,
|
|
||||||
NSOpenGLPFAAccelerated,
|
|
||||||
NSOpenGLPFADepthSize, 32,
|
|
||||||
0,
|
|
||||||
};
|
|
||||||
NSOpenGLPixelFormat* format = [[NSOpenGLPixelFormat alloc]
|
|
||||||
initWithAttributes:attributes];
|
|
||||||
EbitenOpenGLView* glView =
|
|
||||||
[[EbitenOpenGLView alloc] initWithFrame:rect
|
|
||||||
pixelFormat:format];
|
|
||||||
[window setContentView:glView];
|
|
||||||
[window setTitle: [[NSString alloc] initWithUTF8String:title]];
|
|
||||||
//[window makeFirstResponder:glView];
|
|
||||||
|
|
||||||
return window;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Run(size_t width, size_t height, size_t scale, const char* title) {
|
void Run(size_t width, size_t height, size_t scale, const char* title) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
NSWindow* window = generateWindow(width, height, scale, title);
|
EbitenWindow* window = [[EbitenWindow alloc]
|
||||||
|
initWithSize:NSMakeSize(width * scale, height * scale)];
|
||||||
|
[window setTitle: [[NSString alloc] initWithUTF8String:title]];
|
||||||
EbitenController* controller = [[EbitenController alloc]
|
EbitenController* controller = [[EbitenController alloc]
|
||||||
initWithWindow:window];
|
initWithWindow:window];
|
||||||
NSApplication* app = [NSApplication sharedApplication];
|
NSApplication* app = [NSApplication sharedApplication];
|
||||||
|
Loading…
Reference in New Issue
Block a user