mirror of
https://github.com/libretro/RetroArch
synced 2025-03-29 13:20:30 +00:00
(Apple) Start setting up the OSX code
This commit is contained in:
parent
f954ae2f64
commit
99ba3ccea3
@ -1308,7 +1308,7 @@
|
||||
<bool key="NSWindowIsRestorable">YES</bool>
|
||||
</object>
|
||||
<object class="NSCustomObject" id="976324537">
|
||||
<string key="NSClassName">RAAppDelegate</string>
|
||||
<string key="NSClassName">RetroArch_OSX</string>
|
||||
</object>
|
||||
<object class="NSCustomObject" id="755631768">
|
||||
<string key="NSClassName">NSFontManager</string>
|
||||
@ -4630,7 +4630,7 @@
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">RAAppDelegate</string>
|
||||
<string key="className">RetroArch_OSX</string>
|
||||
<string key="superclassName">NSObject</string>
|
||||
<dictionary class="NSMutableDictionary" key="actions">
|
||||
<string key="applicationShouldTerminate:">id</string>
|
||||
|
@ -13,28 +13,35 @@
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef IOS
|
||||
|
||||
#import "RetroArch_Apple.h"
|
||||
#import "views.h"
|
||||
#include "rarch_wrapper.h"
|
||||
|
||||
#ifdef IOS
|
||||
#include "../iOS/input/ios_input.h"
|
||||
#endif
|
||||
|
||||
#include "general.h"
|
||||
|
||||
#ifdef IOS
|
||||
|
||||
#import "views.h"
|
||||
|
||||
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 GLKView* g_view;
|
||||
static EAGLContext* g_context;
|
||||
static UIView* g_pause_view;;
|
||||
static UIView* g_pause_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
|
||||
+ (RAGameView*)get
|
||||
{
|
||||
@ -44,13 +51,38 @@ static UIView* g_pause_indicator_view;
|
||||
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
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
g_screen_scale = [[UIScreen mainScreen] scale];
|
||||
|
||||
#ifdef IOS
|
||||
UINib* xib = [UINib nibWithNibName:@"PauseView" bundle:nil];
|
||||
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 addSubview:g_pause_view];
|
||||
[g_view addSubview:g_pause_indicator_view];
|
||||
#endif
|
||||
|
||||
self.view = g_view;
|
||||
return self;
|
||||
}
|
||||
|
||||
#ifdef IOS
|
||||
|
||||
// Pause Menus
|
||||
- (void)viewWillLayoutSubviews
|
||||
{
|
||||
@ -117,7 +148,6 @@ static UIView* g_pause_indicator_view;
|
||||
completion:^(BOOL finished) { }
|
||||
];
|
||||
}
|
||||
#endif
|
||||
|
||||
- (void)suspend
|
||||
{
|
||||
@ -130,11 +160,14 @@ static UIView* g_pause_indicator_view;
|
||||
g_view.context = g_context;
|
||||
[EAGLContext setCurrentContext:g_context];
|
||||
}
|
||||
#endif
|
||||
|
||||
@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(), ^{
|
||||
// Make sure the view was created
|
||||
[RAGameView get];
|
||||
@ -150,12 +183,13 @@ bool ios_init_game_view()
|
||||
});
|
||||
|
||||
[EAGLContext setCurrentContext:g_context];
|
||||
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
void ios_destroy_game_view()
|
||||
void apple_destroy_game_view()
|
||||
{
|
||||
#ifdef IOS
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
// Clear the view, otherwise the last frame form this game will be displayed
|
||||
// briefly on the next game.
|
||||
@ -171,6 +205,7 @@ void ios_destroy_game_view()
|
||||
});
|
||||
|
||||
[EAGLContext setCurrentContext:nil];
|
||||
#endif
|
||||
}
|
||||
|
||||
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_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 = *width ? *width : 640;
|
||||
@ -201,11 +241,12 @@ void ios_get_game_view_size(unsigned *width, unsigned *height)
|
||||
|
||||
void apple_bind_game_view_fbo(void)
|
||||
{
|
||||
#ifdef IOS
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
if (g_context)
|
||||
[g_view bindDrawable];
|
||||
});
|
||||
#else
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#endif
|
@ -29,6 +29,16 @@ void apple_run_core(RAModuleInfo* core, const char* file);
|
||||
|
||||
#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>
|
||||
|
||||
+ (RetroArch_iOS*)get;
|
||||
@ -47,7 +57,18 @@ void apple_run_core(RAModuleInfo* core, const char* file);
|
||||
|
||||
#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)unloadingCore:(RAModuleInfo*)core;
|
||||
|
@ -476,15 +476,24 @@ int main(int argc, char *argv[])
|
||||
#ifdef OSX
|
||||
|
||||
@implementation RetroArch_OSX
|
||||
{
|
||||
NSWindow IBOutlet *window;
|
||||
}
|
||||
|
||||
+ (RetroArch_OSX*)get
|
||||
{
|
||||
return nil;
|
||||
return (RetroArch_OSX*)[[NSApplication sharedApplication] delegate];
|
||||
}
|
||||
|
||||
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
|
||||
{
|
||||
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
|
||||
|
@ -24,11 +24,11 @@ char* ios_get_rarch_system_directory();
|
||||
void apple_rarch_exited (void* result);
|
||||
|
||||
// These functions must only be called in gfx/context/ioseagl_ctx.c
|
||||
bool ios_init_game_view(void);
|
||||
void ios_destroy_game_view(void);
|
||||
bool apple_init_game_view(void);
|
||||
void apple_destroy_game_view(void);
|
||||
void apple_flip_game_view(void);
|
||||
void ios_set_game_view_sync(unsigned interval);
|
||||
void ios_get_game_view_size(unsigned *width, unsigned *height);
|
||||
void apple_set_game_view_sync(unsigned interval);
|
||||
void apple_get_game_view_size(unsigned *width, unsigned *height);
|
||||
void apple_bind_game_view_fbo(void);
|
||||
|
||||
void ios_add_log_message(const char* format, ...);
|
||||
|
@ -63,10 +63,6 @@
|
||||
96355CD41788E6E00010DBFA = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
967894A81788F0E500D6CA69 /* AudioUnit.framework */,
|
||||
967894A61788F0D900D6CA69 /* OpenGL.framework */,
|
||||
967894A21788F0C200D6CA69 /* CoreAudio.framework */,
|
||||
967894A31788F0C200D6CA69 /* CoreAudioKit.framework */,
|
||||
96355CE81788E72A0010DBFA /* RetroArch */,
|
||||
96355CE11788E72A0010DBFA /* Frameworks */,
|
||||
96355CE01788E72A0010DBFA /* Products */,
|
||||
@ -85,6 +81,10 @@
|
||||
96355CE11788E72A0010DBFA /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
967894A81788F0E500D6CA69 /* AudioUnit.framework */,
|
||||
967894A61788F0D900D6CA69 /* OpenGL.framework */,
|
||||
967894A21788F0C200D6CA69 /* CoreAudio.framework */,
|
||||
967894A31788F0C200D6CA69 /* CoreAudioKit.framework */,
|
||||
96355CE51788E72A0010DBFA /* AppKit.framework */,
|
||||
96355CE61788E72A0010DBFA /* CoreData.framework */,
|
||||
96355CE71788E72A0010DBFA /* Foundation.framework */,
|
||||
|
@ -18,16 +18,6 @@
|
||||
|
||||
#import "RAModuleInfo.h"
|
||||
|
||||
// RAGameView.m
|
||||
@interface RAGameView : UIViewController
|
||||
+ (RAGameView*)get;
|
||||
- (void)openPauseMenu;
|
||||
- (void)closePauseMenu;
|
||||
|
||||
- (void)suspend;
|
||||
- (void)resume;
|
||||
@end
|
||||
|
||||
// RALogView.m
|
||||
@interface RALogView : UITableViewController
|
||||
@end
|
||||
|
@ -56,7 +56,7 @@ static void gfx_ctx_check_window(bool *quit,
|
||||
*quit = false;
|
||||
|
||||
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)
|
||||
{
|
||||
*width = new_width;
|
||||
@ -87,15 +87,15 @@ static void gfx_ctx_input_driver(const input_driver_t **input, void **input_data
|
||||
*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 = {
|
||||
ios_init_game_view,
|
||||
ios_destroy_game_view,
|
||||
apple_init_game_view,
|
||||
apple_destroy_game_view,
|
||||
gfx_ctx_bind_api,
|
||||
ios_set_game_view_sync,
|
||||
apple_set_game_view_sync,
|
||||
gfx_ctx_set_video_mode,
|
||||
ios_get_game_view_size,
|
||||
apple_get_game_view_size,
|
||||
NULL,
|
||||
gfx_ctx_update_window_title,
|
||||
gfx_ctx_check_window,
|
||||
|
Loading…
x
Reference in New Issue
Block a user