(Apple) Start setting up the OSX code

This commit is contained in:
meancoot 2013-07-06 23:54:47 -04:00
parent f954ae2f64
commit 99ba3ccea3
8 changed files with 112 additions and 51 deletions

View File

@ -1308,7 +1308,7 @@
<bool key="NSWindowIsRestorable">YES</bool> <bool key="NSWindowIsRestorable">YES</bool>
</object> </object>
<object class="NSCustomObject" id="976324537"> <object class="NSCustomObject" id="976324537">
<string key="NSClassName">RAAppDelegate</string> <string key="NSClassName">RetroArch_OSX</string>
</object> </object>
<object class="NSCustomObject" id="755631768"> <object class="NSCustomObject" id="755631768">
<string key="NSClassName">NSFontManager</string> <string key="NSClassName">NSFontManager</string>
@ -4630,7 +4630,7 @@
</object> </object>
</object> </object>
<object class="IBPartialClassDescription"> <object class="IBPartialClassDescription">
<string key="className">RAAppDelegate</string> <string key="className">RetroArch_OSX</string>
<string key="superclassName">NSObject</string> <string key="superclassName">NSObject</string>
<dictionary class="NSMutableDictionary" key="actions"> <dictionary class="NSMutableDictionary" key="actions">
<string key="applicationShouldTerminate:">id</string> <string key="applicationShouldTerminate:">id</string>

View File

@ -13,28 +13,35 @@
* If not, see <http://www.gnu.org/licenses/>. * If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifdef IOS
#import "RetroArch_Apple.h" #import "RetroArch_Apple.h"
#import "views.h"
#include "rarch_wrapper.h" #include "rarch_wrapper.h"
#ifdef IOS
#include "../iOS/input/ios_input.h"
#endif
#include "general.h" #include "general.h"
#ifdef IOS
#import "views.h"
static const float ALMOST_INVISIBLE = .021f; static const float ALMOST_INVISIBLE = .021f;
static float g_screen_scale;
static int g_fast_forward_skips;
static bool g_is_syncing = true;
static RAGameView* g_instance; static RAGameView* g_instance;
static GLKView* g_view; static GLKView* g_view;
static EAGLContext* g_context; static EAGLContext* g_context;
static UIView* g_pause_view;; static UIView* g_pause_view;
static UIView* g_pause_indicator_view; static UIView* g_pause_indicator_view;
#elif defined(OSX)
static RAGameView* g_instance;
static NSOpenGLContext* g_context;
#define g_view g_instance // < RAGameView is a container on iOS; on OSX these are both the same object
#endif
static int g_fast_forward_skips;
static bool g_is_syncing = true;
static float g_screen_scale = 1.0f;
@implementation RAGameView @implementation RAGameView
+ (RAGameView*)get + (RAGameView*)get
{ {
@ -44,13 +51,38 @@ static UIView* g_pause_indicator_view;
return g_instance; return g_instance;
} }
#ifdef OSX
- (id)init
{
static const NSOpenGLPixelFormatAttribute attributes [] = {
NSOpenGLPFAWindow,
NSOpenGLPFADoubleBuffer, // double buffered
NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)16, // 16 bit depth buffer
(NSOpenGLPixelFormatAttribute)nil
};
self = [super initWithFrame:CGRectMake(0, 0, 100, 100) pixelFormat:[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]];
self.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
g_context = self.openGLContext;
[g_context makeCurrentContext];
return self;
}
- (void)display
{
[self.openGLContext flushBuffer];
}
#elif defined(IOS) // < iOS Pause menu and lifecycle
- (id)init - (id)init
{ {
self = [super init]; self = [super init];
g_screen_scale = [[UIScreen mainScreen] scale]; g_screen_scale = [[UIScreen mainScreen] scale];
#ifdef IOS
UINib* xib = [UINib nibWithNibName:@"PauseView" bundle:nil]; UINib* xib = [UINib nibWithNibName:@"PauseView" bundle:nil];
g_pause_view = [[xib instantiateWithOwner:[RetroArch_iOS get] options:nil] lastObject]; g_pause_view = [[xib instantiateWithOwner:[RetroArch_iOS get] options:nil] lastObject];
@ -62,13 +94,12 @@ static UIView* g_pause_indicator_view;
g_view.enableSetNeedsDisplay = NO; g_view.enableSetNeedsDisplay = NO;
[g_view addSubview:g_pause_view]; [g_view addSubview:g_pause_view];
[g_view addSubview:g_pause_indicator_view]; [g_view addSubview:g_pause_indicator_view];
#endif
self.view = g_view; self.view = g_view;
return self; return self;
} }
#ifdef IOS
// Pause Menus // Pause Menus
- (void)viewWillLayoutSubviews - (void)viewWillLayoutSubviews
{ {
@ -117,7 +148,6 @@ static UIView* g_pause_indicator_view;
completion:^(BOOL finished) { } completion:^(BOOL finished) { }
]; ];
} }
#endif
- (void)suspend - (void)suspend
{ {
@ -130,11 +160,14 @@ static UIView* g_pause_indicator_view;
g_view.context = g_context; g_view.context = g_context;
[EAGLContext setCurrentContext:g_context]; [EAGLContext setCurrentContext:g_context];
} }
#endif
@end @end
bool ios_init_game_view() // Realistically these functions don't create or destory the view; just the OpenGL context.
bool apple_init_game_view()
{ {
#ifdef IOS
dispatch_sync(dispatch_get_main_queue(), ^{ dispatch_sync(dispatch_get_main_queue(), ^{
// Make sure the view was created // Make sure the view was created
[RAGameView get]; [RAGameView get];
@ -150,12 +183,13 @@ bool ios_init_game_view()
}); });
[EAGLContext setCurrentContext:g_context]; [EAGLContext setCurrentContext:g_context];
#endif
return true; return true;
} }
void ios_destroy_game_view() void apple_destroy_game_view()
{ {
#ifdef IOS
dispatch_sync(dispatch_get_main_queue(), ^{ dispatch_sync(dispatch_get_main_queue(), ^{
// Clear the view, otherwise the last frame form this game will be displayed // Clear the view, otherwise the last frame form this game will be displayed
// briefly on the next game. // briefly on the next game.
@ -171,6 +205,7 @@ void ios_destroy_game_view()
}); });
[EAGLContext setCurrentContext:nil]; [EAGLContext setCurrentContext:nil];
#endif
} }
void apple_flip_game_view() void apple_flip_game_view()
@ -184,13 +219,18 @@ void apple_flip_game_view()
} }
} }
void ios_set_game_view_sync(unsigned interval) void apple_set_game_view_sync(unsigned interval)
{ {
#ifdef IOS // < No way to disable Vsync on iOS?
g_is_syncing = interval ? true : false; g_is_syncing = interval ? true : false;
g_fast_forward_skips = interval ? 0 : 3; g_fast_forward_skips = interval ? 0 : 3;
#elif defined(OSX)
GLint value = interval ? 0 : 1;
[g_view.openGLContext setValues:&value forParameter:NSOpenGLCPSwapInterval];
#endif
} }
void ios_get_game_view_size(unsigned *width, unsigned *height) void apple_get_game_view_size(unsigned *width, unsigned *height)
{ {
*width = g_view.bounds.size.width * g_screen_scale; *width = g_view.bounds.size.width * g_screen_scale;
*width = *width ? *width : 640; *width = *width ? *width : 640;
@ -201,11 +241,12 @@ void ios_get_game_view_size(unsigned *width, unsigned *height)
void apple_bind_game_view_fbo(void) void apple_bind_game_view_fbo(void)
{ {
#ifdef IOS
dispatch_sync(dispatch_get_main_queue(), ^{ dispatch_sync(dispatch_get_main_queue(), ^{
if (g_context) if (g_context)
[g_view bindDrawable]; [g_view bindDrawable];
}); });
#else
glBindFramebuffer(GL_FRAMEBUFFER, 0);
#endif
} }
#endif

View File

@ -29,6 +29,16 @@ void apple_run_core(RAModuleInfo* core, const char* file);
#ifdef IOS #ifdef IOS
// RAGameView.m
@interface RAGameView : UIViewController
+ (RAGameView*)get;
- (void)openPauseMenu;
- (void)closePauseMenu;
- (void)suspend;
- (void)resume;
@end
@interface RetroArch_iOS : UINavigationController<UIApplicationDelegate, UINavigationControllerDelegate, RetroArch_Platform> @interface RetroArch_iOS : UINavigationController<UIApplicationDelegate, UINavigationControllerDelegate, RetroArch_Platform>
+ (RetroArch_iOS*)get; + (RetroArch_iOS*)get;
@ -47,7 +57,18 @@ void apple_run_core(RAModuleInfo* core, const char* file);
#elif defined(OSX) #elif defined(OSX)
@interface RetroArch_OSX : NSObject<RetroArch_Platform> #import <AppKit/AppKit.h>
@interface RAGameView : NSOpenGLView
+ (RAGameView*)get;
- (void)display;
@end
@interface RetroArch_OSX : NSObject<RetroArch_Platform, NSApplicationDelegate>
+ (RetroArch_OSX*)get;
- (void)loadingCore:(RAModuleInfo*)core withFile:(const char*)file; - (void)loadingCore:(RAModuleInfo*)core withFile:(const char*)file;
- (void)unloadingCore:(RAModuleInfo*)core; - (void)unloadingCore:(RAModuleInfo*)core;

View File

@ -476,15 +476,24 @@ int main(int argc, char *argv[])
#ifdef OSX #ifdef OSX
@implementation RetroArch_OSX @implementation RetroArch_OSX
{
NSWindow IBOutlet *window;
}
+ (RetroArch_OSX*)get + (RetroArch_OSX*)get
{ {
return nil; return (RetroArch_OSX*)[[NSApplication sharedApplication] delegate];
} }
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{ {
apple_platform = self; apple_platform = self;
window.backgroundColor = [NSColor blackColor];
[window.contentView setAutoresizesSubviews:YES];
RAGameView.get.frame = [window.contentView bounds];
[window.contentView addSubview:RAGameView.get];
} }
#pragma mark RetroArch_Platform #pragma mark RetroArch_Platform

View File

@ -24,11 +24,11 @@ char* ios_get_rarch_system_directory();
void apple_rarch_exited (void* result); void apple_rarch_exited (void* result);
// These functions must only be called in gfx/context/ioseagl_ctx.c // These functions must only be called in gfx/context/ioseagl_ctx.c
bool ios_init_game_view(void); bool apple_init_game_view(void);
void ios_destroy_game_view(void); void apple_destroy_game_view(void);
void apple_flip_game_view(void); void apple_flip_game_view(void);
void ios_set_game_view_sync(unsigned interval); void apple_set_game_view_sync(unsigned interval);
void ios_get_game_view_size(unsigned *width, unsigned *height); void apple_get_game_view_size(unsigned *width, unsigned *height);
void apple_bind_game_view_fbo(void); void apple_bind_game_view_fbo(void);
void ios_add_log_message(const char* format, ...); void ios_add_log_message(const char* format, ...);

View File

@ -63,10 +63,6 @@
96355CD41788E6E00010DBFA = { 96355CD41788E6E00010DBFA = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
967894A81788F0E500D6CA69 /* AudioUnit.framework */,
967894A61788F0D900D6CA69 /* OpenGL.framework */,
967894A21788F0C200D6CA69 /* CoreAudio.framework */,
967894A31788F0C200D6CA69 /* CoreAudioKit.framework */,
96355CE81788E72A0010DBFA /* RetroArch */, 96355CE81788E72A0010DBFA /* RetroArch */,
96355CE11788E72A0010DBFA /* Frameworks */, 96355CE11788E72A0010DBFA /* Frameworks */,
96355CE01788E72A0010DBFA /* Products */, 96355CE01788E72A0010DBFA /* Products */,
@ -85,6 +81,10 @@
96355CE11788E72A0010DBFA /* Frameworks */ = { 96355CE11788E72A0010DBFA /* Frameworks */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
967894A81788F0E500D6CA69 /* AudioUnit.framework */,
967894A61788F0D900D6CA69 /* OpenGL.framework */,
967894A21788F0C200D6CA69 /* CoreAudio.framework */,
967894A31788F0C200D6CA69 /* CoreAudioKit.framework */,
96355CE51788E72A0010DBFA /* AppKit.framework */, 96355CE51788E72A0010DBFA /* AppKit.framework */,
96355CE61788E72A0010DBFA /* CoreData.framework */, 96355CE61788E72A0010DBFA /* CoreData.framework */,
96355CE71788E72A0010DBFA /* Foundation.framework */, 96355CE71788E72A0010DBFA /* Foundation.framework */,

View File

@ -18,16 +18,6 @@
#import "RAModuleInfo.h" #import "RAModuleInfo.h"
// RAGameView.m
@interface RAGameView : UIViewController
+ (RAGameView*)get;
- (void)openPauseMenu;
- (void)closePauseMenu;
- (void)suspend;
- (void)resume;
@end
// RALogView.m // RALogView.m
@interface RALogView : UITableViewController @interface RALogView : UITableViewController
@end @end

View File

@ -56,7 +56,7 @@ static void gfx_ctx_check_window(bool *quit,
*quit = false; *quit = false;
unsigned new_width, new_height; unsigned new_width, new_height;
ios_get_game_view_size(&new_width, &new_height); apple_get_game_view_size(&new_width, &new_height);
if (new_width != *width || new_height != *height) if (new_width != *width || new_height != *height)
{ {
*width = new_width; *width = new_width;
@ -87,15 +87,15 @@ static void gfx_ctx_input_driver(const input_driver_t **input, void **input_data
*input_data = NULL; *input_data = NULL;
} }
// The ios_* functions are implemented in ios/RetroArch/RAGameView.m // The apple_* functions are implemented in apple/RetroArch/RAGameView.m
const gfx_ctx_driver_t gfx_ctx_ios = { const gfx_ctx_driver_t gfx_ctx_ios = {
ios_init_game_view, apple_init_game_view,
ios_destroy_game_view, apple_destroy_game_view,
gfx_ctx_bind_api, gfx_ctx_bind_api,
ios_set_game_view_sync, apple_set_game_view_sync,
gfx_ctx_set_video_mode, gfx_ctx_set_video_mode,
ios_get_game_view_size, apple_get_game_view_size,
NULL, NULL,
gfx_ctx_update_window_title, gfx_ctx_update_window_title,
gfx_ctx_check_window, gfx_ctx_check_window,