mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-04 23:14:28 +01:00
Stop using [NSApp run]
This commit is contained in:
parent
2bc4d6bf14
commit
170ed689fa
@ -9,9 +9,7 @@ import (
|
|||||||
"github.com/hajimehoshi/go-ebiten/example/game/rotating"
|
"github.com/hajimehoshi/go-ebiten/example/game/rotating"
|
||||||
"github.com/hajimehoshi/go-ebiten/example/game/sprites"
|
"github.com/hajimehoshi/go-ebiten/example/game/sprites"
|
||||||
"github.com/hajimehoshi/go-ebiten/example/game/testpattern"
|
"github.com/hajimehoshi/go-ebiten/example/game/testpattern"
|
||||||
"github.com/hajimehoshi/go-ebiten/ui"
|
|
||||||
"github.com/hajimehoshi/go-ebiten/ui/cocoa"
|
"github.com/hajimehoshi/go-ebiten/ui/cocoa"
|
||||||
// "github.com/hajimehoshi/go-ebiten/ui/glut"
|
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
@ -23,10 +21,6 @@ func main() {
|
|||||||
if 2 <= len(os.Args) {
|
if 2 <= len(os.Args) {
|
||||||
gameName = os.Args[1]
|
gameName = os.Args[1]
|
||||||
}
|
}
|
||||||
uiName := "cocoa"
|
|
||||||
if 3 <= len(os.Args) {
|
|
||||||
uiName = os.Args[2]
|
|
||||||
}
|
|
||||||
|
|
||||||
var game ebiten.Game
|
var game ebiten.Game
|
||||||
switch gameName {
|
switch gameName {
|
||||||
@ -52,12 +46,11 @@ func main() {
|
|||||||
const screenHeight = 240
|
const screenHeight = 240
|
||||||
const screenScale = 2
|
const screenScale = 2
|
||||||
const title = "Ebiten Demo"
|
const title = "Ebiten Demo"
|
||||||
var u ui.UI
|
ui := cocoa.New(screenWidth, screenHeight, screenScale, title)
|
||||||
switch uiName {
|
ui.Start(game)
|
||||||
default:
|
ui.InitTextures(game)
|
||||||
fallthrough
|
for {
|
||||||
case "cocoa":
|
ui.WaitEvents()
|
||||||
u = cocoa.New(screenWidth, screenHeight, screenScale, title)
|
ui.Draw(game.Draw)
|
||||||
}
|
}
|
||||||
u.Run(game)
|
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
context *Context
|
context *Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDevice(screenWidth, screenHeight, screenScale int) *Device {
|
func NewDevice(screenWidth, screenHeight, screenScale int) *Device {
|
||||||
graphicsContext := newContext(screenWidth, screenHeight, screenScale)
|
context := newContext(screenWidth, screenHeight, screenScale)
|
||||||
return &Device{
|
return &Device{
|
||||||
context: graphicsContext,
|
context: context,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,20 +1,24 @@
|
|||||||
package cocoa
|
package cocoa
|
||||||
|
|
||||||
// #cgo CFLAGS: -x objective-c -fobjc-arc
|
// #cgo CFLAGS: -x objective-c
|
||||||
// #cgo LDFLAGS: -framework Cocoa -framework OpenGL -framework QuartzCore
|
// #cgo LDFLAGS: -framework Cocoa -framework OpenGL -framework QuartzCore
|
||||||
//
|
//
|
||||||
// #include <stdlib.h>
|
// #include <stdlib.h>
|
||||||
// #include "input.h"
|
// #include "input.h"
|
||||||
//
|
//
|
||||||
// void Run(size_t width, size_t height, size_t scale, const char* title);
|
// void Start(size_t width, size_t height, size_t scale, const char* title);
|
||||||
|
// void WaitEvents(void);
|
||||||
|
// void BeginDrawing(void);
|
||||||
|
// void EndDrawing(void);
|
||||||
//
|
//
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
"github.com/hajimehoshi/go-ebiten"
|
"github.com/hajimehoshi/go-ebiten"
|
||||||
|
"github.com/hajimehoshi/go-ebiten/graphics"
|
||||||
"github.com/hajimehoshi/go-ebiten/graphics/opengl"
|
"github.com/hajimehoshi/go-ebiten/graphics/opengl"
|
||||||
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"runtime"
|
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -41,16 +45,16 @@ func (context *GameContext) InputState() ebiten.InputState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type UI struct {
|
type UI struct {
|
||||||
screenWidth int
|
screenWidth int
|
||||||
screenHeight int
|
screenHeight int
|
||||||
screenScale int
|
screenScale int
|
||||||
title string
|
title string
|
||||||
updating chan ebiten.Game
|
updating chan struct{}
|
||||||
updated chan ebiten.Game
|
updated chan struct{}
|
||||||
input chan ebiten.InputState
|
input chan ebiten.InputState
|
||||||
graphicsDevice *opengl.Device
|
graphicsDevice *opengl.Device
|
||||||
funcsExecutedOnMainThread []func() // TODO: map?
|
lock sync.Mutex
|
||||||
lock sync.Mutex
|
gameContext *GameContext
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentUI *UI
|
var currentUI *UI
|
||||||
@ -60,14 +64,18 @@ func New(screenWidth, screenHeight, screenScale int, title string) *UI {
|
|||||||
panic("UI can't be duplicated.")
|
panic("UI can't be duplicated.")
|
||||||
}
|
}
|
||||||
ui := &UI{
|
ui := &UI{
|
||||||
screenWidth: screenWidth,
|
screenWidth: screenWidth,
|
||||||
screenHeight: screenHeight,
|
screenHeight: screenHeight,
|
||||||
screenScale: screenScale,
|
screenScale: screenScale,
|
||||||
title: title,
|
title: title,
|
||||||
updating: make(chan ebiten.Game),
|
updating: make(chan struct{}),
|
||||||
updated: make(chan ebiten.Game),
|
updated: make(chan struct{}),
|
||||||
input: make(chan ebiten.InputState),
|
input: make(chan ebiten.InputState),
|
||||||
funcsExecutedOnMainThread: []func(){},
|
gameContext: &GameContext{
|
||||||
|
screenWidth: screenWidth,
|
||||||
|
screenHeight: screenHeight,
|
||||||
|
inputState: ebiten.InputState{-1, -1},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
currentUI = ui
|
currentUI = ui
|
||||||
return ui
|
return ui
|
||||||
@ -76,50 +84,45 @@ func New(screenWidth, screenHeight, screenScale int, title string) *UI {
|
|||||||
func (ui *UI) gameMainLoop(game ebiten.Game) {
|
func (ui *UI) gameMainLoop(game ebiten.Game) {
|
||||||
frameTime := time.Duration(int64(time.Second) / int64(ebiten.FPS))
|
frameTime := time.Duration(int64(time.Second) / int64(ebiten.FPS))
|
||||||
tick := time.Tick(frameTime)
|
tick := time.Tick(frameTime)
|
||||||
gameContext := &GameContext{
|
|
||||||
screenWidth: ui.screenWidth,
|
|
||||||
screenHeight: ui.screenHeight,
|
|
||||||
inputState: ebiten.InputState{-1, -1},
|
|
||||||
}
|
|
||||||
ui.InitializeGame(game)
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case gameContext.inputState = <-ui.input:
|
case ui.gameContext.inputState = <-ui.input:
|
||||||
case <-tick:
|
case <-tick:
|
||||||
game.Update(gameContext)
|
game.Update(ui.gameContext)
|
||||||
case ui.updating <- game:
|
case ui.updating <- struct{}{}:
|
||||||
game = <-ui.updated
|
//ui.DrawGame(game)
|
||||||
|
<-ui.updated
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *UI) Run(game ebiten.Game) {
|
func (ui *UI) Start(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))
|
||||||
|
|
||||||
C.Run(C.size_t(ui.screenWidth),
|
C.Start(C.size_t(ui.screenWidth),
|
||||||
C.size_t(ui.screenHeight),
|
C.size_t(ui.screenHeight),
|
||||||
C.size_t(ui.screenScale),
|
C.size_t(ui.screenScale),
|
||||||
cTitle)
|
cTitle)
|
||||||
|
C.WaitEvents()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *UI) InitializeGame(game ebiten.Game) {
|
func (ui *UI) WaitEvents() {
|
||||||
ui.lock.Lock()
|
C.WaitEvents()
|
||||||
defer ui.lock.Unlock()
|
|
||||||
ui.funcsExecutedOnMainThread = append(ui.funcsExecutedOnMainThread, func() {
|
|
||||||
game.InitTextures(ui.graphicsDevice.TextureFactory())
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *UI) DrawGame(game ebiten.Game) {
|
func (ui *UI) InitTextures(game ebiten.Game) {
|
||||||
ui.lock.Lock()
|
C.BeginDrawing()
|
||||||
defer ui.lock.Unlock()
|
game.InitTextures(ui.graphicsDevice.TextureFactory())
|
||||||
ui.funcsExecutedOnMainThread = append(ui.funcsExecutedOnMainThread, func() {
|
C.EndDrawing()
|
||||||
ui.graphicsDevice.Update(game.Draw)
|
}
|
||||||
})
|
|
||||||
|
func (ui *UI) Draw(f func(graphics.Context)) {
|
||||||
|
C.BeginDrawing()
|
||||||
|
ui.graphicsDevice.Update(f)
|
||||||
|
C.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
//export ebiten_EbitenOpenGLView_Initialized
|
//export ebiten_EbitenOpenGLView_Initialized
|
||||||
@ -127,7 +130,6 @@ func ebiten_EbitenOpenGLView_Initialized() {
|
|||||||
if currentUI.graphicsDevice != nil {
|
if currentUI.graphicsDevice != nil {
|
||||||
panic("The graphics device is already initialized")
|
panic("The graphics device is already initialized")
|
||||||
}
|
}
|
||||||
|
|
||||||
currentUI.graphicsDevice = opengl.NewDevice(
|
currentUI.graphicsDevice = opengl.NewDevice(
|
||||||
currentUI.screenWidth,
|
currentUI.screenWidth,
|
||||||
currentUI.screenHeight,
|
currentUI.screenHeight,
|
||||||
@ -136,16 +138,6 @@ func ebiten_EbitenOpenGLView_Initialized() {
|
|||||||
|
|
||||||
//export ebiten_EbitenOpenGLView_Updating
|
//export ebiten_EbitenOpenGLView_Updating
|
||||||
func ebiten_EbitenOpenGLView_Updating() {
|
func ebiten_EbitenOpenGLView_Updating() {
|
||||||
currentUI.lock.Lock()
|
|
||||||
defer currentUI.lock.Unlock()
|
|
||||||
for _, f := range currentUI.funcsExecutedOnMainThread {
|
|
||||||
f()
|
|
||||||
}
|
|
||||||
currentUI.funcsExecutedOnMainThread = currentUI.funcsExecutedOnMainThread[0:0]
|
|
||||||
|
|
||||||
game := <-currentUI.updating
|
|
||||||
currentUI.graphicsDevice.Update(game.Draw)
|
|
||||||
currentUI.updated <- game
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//export ebiten_EbitenOpenGLView_InputUpdated
|
//export ebiten_EbitenOpenGLView_InputUpdated
|
||||||
|
@ -13,7 +13,7 @@ void ebiten_EbitenOpenGLView_InputUpdated(InputType inputType, int x, int y);
|
|||||||
|
|
||||||
// TODO: Use NSViewController?
|
// TODO: Use NSViewController?
|
||||||
|
|
||||||
static CVReturn
|
/*static CVReturn
|
||||||
EbitenDisplayLinkCallback(CVDisplayLinkRef displayLink,
|
EbitenDisplayLinkCallback(CVDisplayLinkRef displayLink,
|
||||||
CVTimeStamp const* now,
|
CVTimeStamp const* now,
|
||||||
CVTimeStamp const* outputTime,
|
CVTimeStamp const* outputTime,
|
||||||
@ -28,19 +28,26 @@ EbitenDisplayLinkCallback(CVDisplayLinkRef displayLink,
|
|||||||
EbitenOpenGLView* view = (__bridge EbitenOpenGLView*)displayLinkContext;
|
EbitenOpenGLView* view = (__bridge EbitenOpenGLView*)displayLinkContext;
|
||||||
return [view getFrameForTime:outputTime];
|
return [view getFrameForTime:outputTime];
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@implementation EbitenOpenGLView {
|
@implementation EbitenOpenGLView {
|
||||||
@private
|
/*@private
|
||||||
CVDisplayLinkRef displayLink_;
|
CVDisplayLinkRef displayLink_;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
/*- (void)dealloc {
|
||||||
CVDisplayLinkRelease(self->displayLink_);
|
CVDisplayLinkRelease(self->displayLink_);
|
||||||
// Do not call [super dealloc] because of ARC.
|
#if !__has_feature(objc_arc)
|
||||||
}
|
[super dealloc];
|
||||||
|
#endif
|
||||||
|
}*/
|
||||||
|
|
||||||
- (void)prepareOpenGL {
|
/*- (void)prepareOpenGL {
|
||||||
|
[super prepareOpenGL];
|
||||||
|
ebiten_EbitenOpenGLView_Initialized();
|
||||||
|
}*/
|
||||||
|
|
||||||
|
/*- (void)prepareOpenGL {
|
||||||
[super prepareOpenGL];
|
[super prepareOpenGL];
|
||||||
NSOpenGLContext* openGLContext = [self openGLContext];
|
NSOpenGLContext* openGLContext = [self openGLContext];
|
||||||
assert(openGLContext != nil);
|
assert(openGLContext != nil);
|
||||||
@ -60,9 +67,9 @@ EbitenDisplayLinkCallback(CVDisplayLinkRef displayLink,
|
|||||||
CVDisplayLinkStart(self->displayLink_);
|
CVDisplayLinkStart(self->displayLink_);
|
||||||
|
|
||||||
ebiten_EbitenOpenGLView_Initialized();
|
ebiten_EbitenOpenGLView_Initialized();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
- (CVReturn)getFrameForTime:(CVTimeStamp const*)outputTime {
|
/*- (CVReturn)getFrameForTime:(CVTimeStamp const*)outputTime {
|
||||||
(void)outputTime;
|
(void)outputTime;
|
||||||
NSOpenGLContext* context = [self openGLContext];
|
NSOpenGLContext* context = [self openGLContext];
|
||||||
assert(context != nil);
|
assert(context != nil);
|
||||||
@ -74,7 +81,7 @@ EbitenDisplayLinkCallback(CVDisplayLinkRef displayLink,
|
|||||||
CGLUnlockContext((CGLContextObj)[context CGLContextObj]);
|
CGLUnlockContext((CGLContextObj)[context CGLContextObj]);
|
||||||
}
|
}
|
||||||
return kCVReturnSuccess;
|
return kCVReturnSuccess;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
- (BOOL)isFlipped {
|
- (BOOL)isFlipped {
|
||||||
return YES;
|
return YES;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
@interface EbitenOpenGLView : NSOpenGLView
|
@interface EbitenOpenGLView : NSOpenGLView
|
||||||
|
|
||||||
- (CVReturn)getFrameForTime:(CVTimeStamp const*)outputTime;
|
//- (CVReturn)getFrameForTime:(CVTimeStamp const*)outputTime;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -2,9 +2,16 @@
|
|||||||
|
|
||||||
#import "ebiten_window.h"
|
#import "ebiten_window.h"
|
||||||
|
|
||||||
|
#include <OpenGL/gl.h>
|
||||||
|
|
||||||
#import "ebiten_opengl_view.h"
|
#import "ebiten_opengl_view.h"
|
||||||
|
|
||||||
|
void ebiten_EbitenOpenGLView_Initialized(void);
|
||||||
|
|
||||||
@implementation EbitenWindow
|
@implementation EbitenWindow
|
||||||
|
{
|
||||||
|
NSOpenGLContext* glContext_;
|
||||||
|
}
|
||||||
|
|
||||||
- (id)initWithSize:(NSSize)size {
|
- (id)initWithSize:(NSSize)size {
|
||||||
NSUInteger style = (NSTitledWindowMask | NSClosableWindowMask |
|
NSUInteger style = (NSTitledWindowMask | NSClosableWindowMask |
|
||||||
@ -31,6 +38,20 @@
|
|||||||
[self setDocumentEdited:YES];
|
[self setDocumentEdited:YES];
|
||||||
|
|
||||||
NSRect rect = NSMakeRect(0, 0, size.width, size.height);
|
NSRect rect = NSMakeRect(0, 0, size.width, size.height);
|
||||||
|
NSView* contentView = [[NSView alloc] initWithFrame:rect];
|
||||||
|
[self setContentView:contentView];
|
||||||
|
|
||||||
|
return self;
|
||||||
|
|
||||||
|
/*EbitenOpenGLView* contentView =
|
||||||
|
[[EbitenOpenGLView alloc] initWithFrame:rect
|
||||||
|
pixelFormat:format];*/
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSOpenGLContext*)glContext {
|
||||||
|
if (self->glContext_ != nil)
|
||||||
|
return self->glContext_;
|
||||||
|
|
||||||
NSOpenGLPixelFormatAttribute attributes[] = {
|
NSOpenGLPixelFormatAttribute attributes[] = {
|
||||||
NSOpenGLPFAWindow,
|
NSOpenGLPFAWindow,
|
||||||
NSOpenGLPFADoubleBuffer,
|
NSOpenGLPFADoubleBuffer,
|
||||||
@ -40,11 +61,15 @@
|
|||||||
};
|
};
|
||||||
NSOpenGLPixelFormat* format = [[NSOpenGLPixelFormat alloc]
|
NSOpenGLPixelFormat* format = [[NSOpenGLPixelFormat alloc]
|
||||||
initWithAttributes:attributes];
|
initWithAttributes:attributes];
|
||||||
EbitenOpenGLView* glView =
|
self->glContext_ = [[NSOpenGLContext alloc] initWithFormat:format
|
||||||
[[EbitenOpenGLView alloc] initWithFrame:rect
|
shareContext:nil];
|
||||||
pixelFormat:format];
|
[self->glContext_ setView:[self contentView]];
|
||||||
[self setContentView:glView];
|
[self->glContext_ makeCurrentContext];
|
||||||
return self;
|
ebiten_EbitenOpenGLView_Initialized();
|
||||||
|
|
||||||
|
[format release];
|
||||||
|
|
||||||
|
return self->glContext_;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)windowShouldClose:(id)sender {
|
- (BOOL)windowShouldClose:(id)sender {
|
||||||
@ -60,6 +85,7 @@
|
|||||||
modalDelegate:self
|
modalDelegate:self
|
||||||
didEndSelector:selector
|
didEndSelector:selector
|
||||||
contextInfo:nil];
|
contextInfo:nil];
|
||||||
|
[alert release];
|
||||||
}
|
}
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
@ -74,5 +100,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
- (void)beginDrawing {
|
||||||
|
[[self glContext] makeCurrentContext];
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)endDrawing {
|
||||||
|
[[self glContext] flushBuffer];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
returnCode:(NSInteger)returnCode
|
returnCode:(NSInteger)returnCode
|
||||||
contextInfo:(void*)contextInfo;
|
contextInfo:(void*)contextInfo;
|
||||||
- (BOOL)windowShouldClose:(id)sender;
|
- (BOOL)windowShouldClose:(id)sender;
|
||||||
|
- (void)beginDrawing;
|
||||||
|
- (void)endDrawing;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
45
ui/cocoa/mainloop.c
Normal file
45
ui/cocoa/mainloop.c
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
// -*- objc -*-
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#import "ebiten_controller.h"
|
||||||
|
#import "ebiten_window.h"
|
||||||
|
|
||||||
|
static EbitenWindow* currentWindow = 0;
|
||||||
|
|
||||||
|
void Start(size_t width, size_t height, size_t scale, const char* title) {
|
||||||
|
NSSize size = NSMakeSize(width * scale, height * scale);
|
||||||
|
EbitenWindow* window = [[EbitenWindow alloc]
|
||||||
|
initWithSize:size];
|
||||||
|
[window setTitle: [[NSString alloc] initWithUTF8String:title]];
|
||||||
|
EbitenController* controller = [[EbitenController alloc]
|
||||||
|
initWithWindow:window];
|
||||||
|
NSApplication* app = [NSApplication sharedApplication];
|
||||||
|
[app setActivationPolicy:NSApplicationActivationPolicyRegular];
|
||||||
|
[app setDelegate:controller];
|
||||||
|
[app finishLaunching];
|
||||||
|
[app activateIgnoringOtherApps:YES];
|
||||||
|
|
||||||
|
currentWindow = window;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WaitEvents(void) {
|
||||||
|
for (;;) {
|
||||||
|
NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask
|
||||||
|
untilDate:[NSDate distantPast]
|
||||||
|
inMode:NSDefaultRunLoopMode
|
||||||
|
dequeue:YES];
|
||||||
|
if (event == nil) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
[NSApp sendEvent:event];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BeginDrawing(void) {
|
||||||
|
[currentWindow beginDrawing];
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndDrawing(void) {
|
||||||
|
[currentWindow endDrawing];
|
||||||
|
}
|
@ -1,23 +0,0 @@
|
|||||||
// -*- objc -*-
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#import "ebiten_controller.h"
|
|
||||||
#import "ebiten_window.h"
|
|
||||||
|
|
||||||
void Run(size_t width, size_t height, size_t scale, const char* title) {
|
|
||||||
@autoreleasepool {
|
|
||||||
NSSize size = NSMakeSize(width * scale, height * scale);
|
|
||||||
EbitenWindow* window = [[EbitenWindow alloc]
|
|
||||||
initWithSize:size];
|
|
||||||
[window setTitle: [[NSString alloc] initWithUTF8String:title]];
|
|
||||||
EbitenController* controller = [[EbitenController alloc]
|
|
||||||
initWithWindow:window];
|
|
||||||
NSApplication* app = [NSApplication sharedApplication];
|
|
||||||
[app setActivationPolicy:NSApplicationActivationPolicyRegular];
|
|
||||||
[app setDelegate:controller];
|
|
||||||
[app finishLaunching];
|
|
||||||
[app activateIgnoringOtherApps:YES];
|
|
||||||
[app run];
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user