mirror of
https://github.com/libretro/RetroArch
synced 2025-01-30 12:32:52 +00:00
(Apple) Move location/camera code into separate files
This commit is contained in:
parent
c1cdf78fc8
commit
ac941c18a3
@ -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
|
||||
|
80
apple/common/apple_camera_ios.c.inl
Normal file
80
apple/common/apple_camera_ios.c.inl
Normal file
@ -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",
|
||||
};
|
82
apple/common/apple_location.c.inl
Normal file
82
apple/common/apple_location.c.inl
Normal file
@ -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",
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user