From ac941c18a3d6227a9d6d79138407d1c39de69978 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 9 Jul 2014 12:56:29 +0200 Subject: [PATCH] (Apple) Move location/camera code into separate files --- apple/common/RAGameView.m | 172 +--------------------------- apple/common/apple_camera_ios.c.inl | 80 +++++++++++++ apple/common/apple_location.c.inl | 82 +++++++++++++ 3 files changed, 167 insertions(+), 167 deletions(-) create mode 100644 apple/common/apple_camera_ios.c.inl create mode 100644 apple/common/apple_location.c.inl diff --git a/apple/common/RAGameView.m b/apple/common/RAGameView.m index 22261911b0..5947c3e205 100644 --- a/apple/common/RAGameView.m +++ b/apple/common/RAGameView.m @@ -558,10 +558,10 @@ bool apple_gfx_ctx_set_video_mode(void *data, unsigned width, unsigned height, b void apple_gfx_ctx_get_video_size(void *data, unsigned* width, unsigned* height) { - RAScreen *screen; - CGRect size; + RAScreen *screen = (RAScreen*)get_chosen_screen(); + CGRect size = screen.bounds; + (void)data; - screen = (RAScreen*)get_chosen_screen(); if (g_initialized) { @@ -572,8 +572,6 @@ void apple_gfx_ctx_get_video_size(void *data, unsigned* width, unsigned* height) size = g_view.bounds; #endif } - else - size = screen.bounds; *width = CGRectGetWidth(size) * screen.scale; *height = CGRectGetHeight(size) * screen.scale; @@ -637,171 +635,11 @@ void apple_bind_game_view_fbo(void) } #ifdef HAVE_CAMERA -typedef struct ios_camera -{ - void *empty; -} ioscamera_t; - -static void *ios_camera_init(const char *device, uint64_t caps, unsigned width, unsigned height) -{ - ioscamera_t *ioscamera; - - if ((caps & (1ULL << RETRO_CAMERA_BUFFER_OPENGL_TEXTURE)) == 0) - { - RARCH_ERR("ioscamera returns OpenGL texture.\n"); - return NULL; - } - - ioscamera = (ioscamera_t*)calloc(1, sizeof(ioscamera_t)); - if (!ioscamera) - return NULL; - - [[RAGameView get] onCameraInit]; - - return ioscamera; -} - -static void ios_camera_free(void *data) -{ - ioscamera_t *ioscamera = (ioscamera_t*)data; - - [[RAGameView get] onCameraFree]; - - if (ioscamera) - free(ioscamera); - ioscamera = NULL; -} - -static bool ios_camera_start(void *data) -{ - (void)data; - - [[RAGameView get] onCameraStart]; - - return true; -} - -static void ios_camera_stop(void *data) -{ - [[RAGameView get] onCameraStop]; -} - -static bool ios_camera_poll(void *data, retro_camera_frame_raw_framebuffer_t frame_raw_cb, - retro_camera_frame_opengl_texture_t frame_gl_cb) -{ - - (void)data; - (void)frame_raw_cb; - - if (frame_gl_cb && newFrame) - { - // FIXME: Identity for now. Use proper texture matrix as returned by iOS Camera (if at all?). - static const float affine[] = { - 1.0f, 0.0f, 0.0f, - 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 1.0f - }; - - frame_gl_cb(outputTexture, GL_TEXTURE_2D, affine); - newFrame = false; - } - - return true; -} - -const camera_driver_t camera_ios = { - ios_camera_init, - ios_camera_free, - ios_camera_start, - ios_camera_stop, - ios_camera_poll, - "ios", -}; +#include "apple_camera_ios.c.inl" #endif #endif #ifdef HAVE_LOCATION -typedef struct apple_location -{ - void *empty; -} applelocation_t; - -static void *apple_location_init(void) -{ - applelocation_t *applelocation = (applelocation_t*)calloc(1, sizeof(applelocation_t)); - if (!applelocation) - return NULL; - - [[RAGameView get] onLocationInit]; - - return applelocation; -} - -static void apple_location_set_interval(void *data, unsigned interval_update_ms, unsigned interval_distance) -{ - (void)data; - - locationManager.distanceFilter = interval_distance ? interval_distance : kCLDistanceFilterNone; -} - -static void apple_location_free(void *data) -{ - applelocation_t *applelocation = (applelocation_t*)data; - - /* TODO - free location manager? */ - - if (applelocation) - free(applelocation); - applelocation = NULL; -} - -static bool apple_location_start(void *data) -{ - (void)data; - - [locationManager startUpdatingLocation]; - return true; -} - -static void apple_location_stop(void *data) -{ - (void)data; - - [locationManager stopUpdatingLocation]; -} - -static bool apple_location_get_position(void *data, double *lat, double *lon, double *horiz_accuracy, - double *vert_accuracy) -{ - (void)data; - - bool ret = [[RAGameView get] onLocationHasChanged]; - - if (!ret) - goto fail; - - *lat = currentLatitude; - *lon = currentLongitude; - *horiz_accuracy = currentHorizontalAccuracy; - *vert_accuracy = currentVerticalAccuracy; - return true; - -fail: - *lat = 0.0; - *lon = 0.0; - *horiz_accuracy = 0.0; - *vert_accuracy = 0.0; - return false; -} - -const location_driver_t location_apple = { - apple_location_init, - apple_location_free, - apple_location_start, - apple_location_stop, - apple_location_get_position, - apple_location_set_interval, - "apple", -}; +#include "apple_location.c.inl" #endif diff --git a/apple/common/apple_camera_ios.c.inl b/apple/common/apple_camera_ios.c.inl new file mode 100644 index 0000000000..8d68bc2c9f --- /dev/null +++ b/apple/common/apple_camera_ios.c.inl @@ -0,0 +1,80 @@ +typedef struct ios_camera +{ + void *empty; +} ioscamera_t; + +static void *ios_camera_init(const char *device, uint64_t caps, unsigned width, unsigned height) +{ + ioscamera_t *ioscamera; + + if ((caps & (1ULL << RETRO_CAMERA_BUFFER_OPENGL_TEXTURE)) == 0) + { + RARCH_ERR("ioscamera returns OpenGL texture.\n"); + return NULL; + } + + ioscamera = (ioscamera_t*)calloc(1, sizeof(ioscamera_t)); + if (!ioscamera) + return NULL; + + [[RAGameView get] onCameraInit]; + + return ioscamera; +} + +static void ios_camera_free(void *data) +{ + ioscamera_t *ioscamera = (ioscamera_t*)data; + + [[RAGameView get] onCameraFree]; + + if (ioscamera) + free(ioscamera); + ioscamera = NULL; +} + +static bool ios_camera_start(void *data) +{ + (void)data; + + [[RAGameView get] onCameraStart]; + + return true; +} + +static void ios_camera_stop(void *data) +{ + [[RAGameView get] onCameraStop]; +} + +static bool ios_camera_poll(void *data, retro_camera_frame_raw_framebuffer_t frame_raw_cb, + retro_camera_frame_opengl_texture_t frame_gl_cb) +{ + + (void)data; + (void)frame_raw_cb; + + if (frame_gl_cb && newFrame) + { + // FIXME: Identity for now. Use proper texture matrix as returned by iOS Camera (if at all?). + static const float affine[] = { + 1.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 1.0f + }; + + frame_gl_cb(outputTexture, GL_TEXTURE_2D, affine); + newFrame = false; + } + + return true; +} + +const camera_driver_t camera_ios = { + ios_camera_init, + ios_camera_free, + ios_camera_start, + ios_camera_stop, + ios_camera_poll, + "ios", +}; diff --git a/apple/common/apple_location.c.inl b/apple/common/apple_location.c.inl new file mode 100644 index 0000000000..88988177b1 --- /dev/null +++ b/apple/common/apple_location.c.inl @@ -0,0 +1,82 @@ +typedef struct apple_location +{ + void *empty; +} applelocation_t; + +static void *apple_location_init(void) +{ + applelocation_t *applelocation = (applelocation_t*)calloc(1, sizeof(applelocation_t)); + if (!applelocation) + return NULL; + + [[RAGameView get] onLocationInit]; + + return applelocation; +} + +static void apple_location_set_interval(void *data, unsigned interval_update_ms, unsigned interval_distance) +{ + (void)data; + + locationManager.distanceFilter = interval_distance ? interval_distance : kCLDistanceFilterNone; +} + +static void apple_location_free(void *data) +{ + applelocation_t *applelocation = (applelocation_t*)data; + + /* TODO - free location manager? */ + + if (applelocation) + free(applelocation); + applelocation = NULL; +} + +static bool apple_location_start(void *data) +{ + (void)data; + + [locationManager startUpdatingLocation]; + return true; +} + +static void apple_location_stop(void *data) +{ + (void)data; + + [locationManager stopUpdatingLocation]; +} + +static bool apple_location_get_position(void *data, double *lat, double *lon, double *horiz_accuracy, + double *vert_accuracy) +{ + (void)data; + + bool ret = [[RAGameView get] onLocationHasChanged]; + + if (!ret) + goto fail; + + *lat = currentLatitude; + *lon = currentLongitude; + *horiz_accuracy = currentHorizontalAccuracy; + *vert_accuracy = currentVerticalAccuracy; + return true; + +fail: + *lat = 0.0; + *lon = 0.0; + *horiz_accuracy = 0.0; + *vert_accuracy = 0.0; + return false; +} + +const location_driver_t location_apple = { + apple_location_init, + apple_location_free, + apple_location_start, + apple_location_stop, + apple_location_get_position, + apple_location_set_interval, + "apple", +};