mirror of
https://github.com/libretro/RetroArch
synced 2025-04-02 16:20:39 +00:00
(Location) Reimplement some parts of the location interface - get_latitude
and get_longitude are gone now in place of get_position. Basically, from C land we basically do a poll-style queries, but on the implementation side (ie. Android/iOS/OSX) - they all use callback-based location updates. So we simply check in the poll function (get_position) whether position has changed, and if so, update the pointer values and return true - if not, set them to 0 and return false.
This commit is contained in:
parent
855cb54def
commit
f0aa0f99fd
@ -32,7 +32,11 @@ LocationListener
|
|||||||
// Define an object that holds accuracy and frequency parameters
|
// Define an object that holds accuracy and frequency parameters
|
||||||
LocationRequest mLocationRequest = null;
|
LocationRequest mLocationRequest = null;
|
||||||
boolean mUpdatesRequested = false;
|
boolean mUpdatesRequested = false;
|
||||||
|
boolean locationChanged = false;
|
||||||
boolean location_service_running = false;
|
boolean location_service_running = false;
|
||||||
|
double current_latitude = 0.0;
|
||||||
|
double current_longitude = 0.0;
|
||||||
|
double current_accuracy = 0.0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Called by Location Services when the request to connect the
|
* Called by Location Services when the request to connect the
|
||||||
@ -126,7 +130,7 @@ LocationListener
|
|||||||
/**
|
/**
|
||||||
* Initializing methods for location based functionality.
|
* Initializing methods for location based functionality.
|
||||||
*/
|
*/
|
||||||
public void onLocationInit(int update_interval_in_ms, int distance_interval)
|
public void onLocationInit()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Create a new location client, using the enclosing class to
|
* Create a new location client, using the enclosing class to
|
||||||
@ -141,7 +145,7 @@ LocationListener
|
|||||||
if (mLocationRequest == null)
|
if (mLocationRequest == null)
|
||||||
mLocationRequest = LocationRequest.create();
|
mLocationRequest = LocationRequest.create();
|
||||||
|
|
||||||
onLocationSetInterval(update_interval_in_ms, distance_interval);
|
onLocationSetInterval(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -209,11 +213,35 @@ LocationListener
|
|||||||
{
|
{
|
||||||
return mCurrentLocation.getLongitude();
|
return mCurrentLocation.getLongitude();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Gets the accuracy of the current location in meters.
|
||||||
|
*
|
||||||
|
* @return the accuracy of the current position.
|
||||||
|
*/
|
||||||
|
public float onLocationGetAccuracy()
|
||||||
|
{
|
||||||
|
return mCurrentLocation.getAccuracy();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tells us whether the location listener callback has
|
||||||
|
* updated the current location since the last time
|
||||||
|
* we polled.
|
||||||
|
*/
|
||||||
|
public boolean onLocationHasChanged()
|
||||||
|
{
|
||||||
|
boolean ret = locationChanged;
|
||||||
|
if (ret)
|
||||||
|
locationChanged = false;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
// Define the callback method that receives location updates
|
// Define the callback method that receives location updates
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChanged(Location location)
|
public void onLocationChanged(Location location)
|
||||||
{
|
{
|
||||||
|
locationChanged = true;
|
||||||
mCurrentLocation = location;
|
mCurrentLocation = location;
|
||||||
|
|
||||||
// Report to the UI that the location was updated
|
// Report to the UI that the location was updated
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <CoreLocation/CoreLocation.h>
|
#include <CoreLocation/CoreLocation.h>
|
||||||
|
|
||||||
static CLLocationManager *locationManager;
|
static CLLocationManager *locationManager;
|
||||||
|
static bool locationChanged;
|
||||||
static CLLocationDegrees currentLatitude;
|
static CLLocationDegrees currentLatitude;
|
||||||
static CLLocationDegrees currentLongitude;
|
static CLLocationDegrees currentLongitude;
|
||||||
|
|
||||||
@ -314,7 +315,7 @@ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
- (void)onLocationSetInterval:(int)interval_update_ms interval_update_distance:(int)interval_distance
|
- (void)onLocationSetInterval:(unsigned)interval_update_ms interval_update_distance:(unsigned)interval_distance
|
||||||
{
|
{
|
||||||
(void)interval_update_ms;
|
(void)interval_update_ms;
|
||||||
|
|
||||||
@ -325,7 +326,7 @@ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
|
|||||||
locationManager.distanceFilter = interval_distance;
|
locationManager.distanceFilter = interval_distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)onLocationInit:(int)interval_update_ms interval_update_distance:(int)interval_distance
|
- (void)onLocationInit
|
||||||
{
|
{
|
||||||
// Create the location manager if this object does not
|
// Create the location manager if this object does not
|
||||||
// already have one.
|
// already have one.
|
||||||
@ -335,7 +336,7 @@ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
|
|||||||
locationManager.delegate = self;
|
locationManager.delegate = self;
|
||||||
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
|
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
|
||||||
|
|
||||||
[[RAGameView get] onLocationSetInterval:interval_update_ms interval_update_distance:interval_distance];
|
[[RAGameView get] onLocationSetInterval:0 interval_update_distance:0];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)onLocationStart
|
- (void)onLocationStart
|
||||||
@ -363,8 +364,23 @@ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
|
|||||||
return currentLongitude;
|
return currentLongitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (double)onLocationGetAccuracy
|
||||||
|
{
|
||||||
|
/* TODO/FIXME - implement */
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (bool)onLocationHasChanged
|
||||||
|
{
|
||||||
|
bool ret = locationChanged;
|
||||||
|
if (ret)
|
||||||
|
locationChanged = false;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
|
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
|
||||||
{
|
{
|
||||||
|
locationChanged = true;
|
||||||
currentLatitude = newLocation.coordinate.latitude;
|
currentLatitude = newLocation.coordinate.latitude;
|
||||||
currentLongitude = newLocation.coordinate.longitude;
|
currentLongitude = newLocation.coordinate.longitude;
|
||||||
RARCH_LOG("didUpdateToLocation - latitude %f, longitude %f\n", (float)currentLatitude, (float)currentLongitude);
|
RARCH_LOG("didUpdateToLocation - latitude %f, longitude %f\n", (float)currentLatitude, (float)currentLongitude);
|
||||||
@ -372,7 +388,7 @@ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
|
|||||||
|
|
||||||
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
|
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
|
||||||
{
|
{
|
||||||
|
locationChanged = true;
|
||||||
currentLatitude = [[locations objectAtIndex:([locations count]-1)] coordinate].latitude;
|
currentLatitude = [[locations objectAtIndex:([locations count]-1)] coordinate].latitude;
|
||||||
currentLongitude = [[locations objectAtIndex:([locations count]-1)] coordinate].longitude;
|
currentLongitude = [[locations objectAtIndex:([locations count]-1)] coordinate].longitude;
|
||||||
RARCH_LOG("didUpdateLocations - latitude %f, longitude %f\n", (float)currentLatitude, (float)currentLongitude);
|
RARCH_LOG("didUpdateLocations - latitude %f, longitude %f\n", (float)currentLatitude, (float)currentLongitude);
|
||||||
@ -711,7 +727,7 @@ static void *apple_location_init(int interval_update_ms, int interval_distance)
|
|||||||
return applelocation;
|
return applelocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void apple_location_set_interval(void *data, int interval_update_ms, int interval_distance)
|
static void apple_location_set_interval(void *data, unsigned interval_update_ms, unsigned interval_distance)
|
||||||
{
|
{
|
||||||
(void)data;
|
(void)data;
|
||||||
|
|
||||||
@ -745,18 +761,25 @@ static void apple_location_stop(void *data)
|
|||||||
[[RAGameView get] onLocationStop];
|
[[RAGameView get] onLocationStop];
|
||||||
}
|
}
|
||||||
|
|
||||||
static double apple_location_get_latitude(void *data)
|
static bool apple_location_get_position(void *data, double *lat, double *lon, double *accuracy)
|
||||||
{
|
{
|
||||||
(void)data;
|
(void)data;
|
||||||
|
|
||||||
return [[RAGameView get] onLocationGetLatitude];
|
|
||||||
}
|
|
||||||
|
|
||||||
static double apple_location_get_longitude(void *data)
|
bool ret = [[RAGameView get] onLocationHasChanged];
|
||||||
{
|
|
||||||
(void)data;
|
if (!ret)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
return [[RAGameView get] onLocationGetLongitude];
|
*lat = [[RAGameView get] onLocationGetLatitude];
|
||||||
|
*lon = [[RAGameView get] onLocationGetLongitude];
|
||||||
|
*accuracy = [[RAGameView get] onLocationGetAccuracy];
|
||||||
|
return true;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
*lat = 0.0;
|
||||||
|
*lon = 0.0;
|
||||||
|
*accuracy = 0.0;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const location_driver_t location_apple = {
|
const location_driver_t location_apple = {
|
||||||
@ -764,8 +787,7 @@ const location_driver_t location_apple = {
|
|||||||
apple_location_free,
|
apple_location_free,
|
||||||
apple_location_start,
|
apple_location_start,
|
||||||
apple_location_stop,
|
apple_location_stop,
|
||||||
apple_location_get_longitude,
|
apple_location_get_position,
|
||||||
apple_location_get_latitude,
|
|
||||||
apple_location_set_interval,
|
apple_location_set_interval,
|
||||||
"apple",
|
"apple",
|
||||||
};
|
};
|
||||||
|
17
driver.c
17
driver.c
@ -648,20 +648,15 @@ void driver_location_set_interval(unsigned interval_msecs, unsigned interval_dis
|
|||||||
driver.location->set_interval(driver.location_data, interval_msecs, interval_distance);
|
driver.location->set_interval(driver.location_data, interval_msecs, interval_distance);
|
||||||
}
|
}
|
||||||
|
|
||||||
double driver_location_get_latitude(void)
|
bool driver_location_get_position(double *lat, double *lon, double *accuracy)
|
||||||
{
|
{
|
||||||
if (driver.location && driver.location_data)
|
if (driver.location && driver.location_data)
|
||||||
return driver.location->get_latitude(driver.location_data);
|
return driver.location->get_position(driver.location_data, lat, lon, accuracy);
|
||||||
else
|
|
||||||
return 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
double driver_location_get_longitude(void)
|
*lat = 0.0;
|
||||||
{
|
*lon = 0.0;
|
||||||
if (driver.location && driver.location_data)
|
*accuracy = 0.0;
|
||||||
return driver.location->get_longitude(driver.location_data);
|
return false;
|
||||||
else
|
|
||||||
return 0.0;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
6
driver.h
6
driver.h
@ -375,8 +375,7 @@ typedef struct location_driver
|
|||||||
bool (*start)(void *data);
|
bool (*start)(void *data);
|
||||||
void (*stop)(void *data);
|
void (*stop)(void *data);
|
||||||
|
|
||||||
double (*get_longitude)(void *data);
|
bool (*get_position)(void *data, double *lat, double *lon, double *accuracy);
|
||||||
double (*get_latitude)(void *data);
|
|
||||||
void (*set_interval)(void *data, unsigned interval_msecs, unsigned interval_distance);
|
void (*set_interval)(void *data, unsigned interval_msecs, unsigned interval_distance);
|
||||||
const char *ident;
|
const char *ident;
|
||||||
} location_driver_t;
|
} location_driver_t;
|
||||||
@ -604,8 +603,7 @@ void driver_camera_poll(void);
|
|||||||
#ifdef HAVE_LOCATION
|
#ifdef HAVE_LOCATION
|
||||||
bool driver_location_start(void);
|
bool driver_location_start(void);
|
||||||
void driver_location_stop(void);
|
void driver_location_stop(void);
|
||||||
double driver_location_get_latitude(void);
|
bool driver_location_get_position(double *lat, double *lon, double *accuracy);
|
||||||
double driver_location_get_longitude(void);
|
|
||||||
void driver_location_set_interval(unsigned interval_msecs, unsigned interval_distance);
|
void driver_location_set_interval(unsigned interval_msecs, unsigned interval_distance);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -849,8 +849,7 @@ bool rarch_environment_cb(unsigned cmd, void *data)
|
|||||||
struct retro_location_callback *cb = (struct retro_location_callback*)data;
|
struct retro_location_callback *cb = (struct retro_location_callback*)data;
|
||||||
cb->start = driver_location_start;
|
cb->start = driver_location_start;
|
||||||
cb->stop = driver_location_stop;
|
cb->stop = driver_location_stop;
|
||||||
cb->get_latitude = driver_location_get_latitude;
|
cb->get_position = driver_location_get_position;
|
||||||
cb->get_longitude = driver_location_get_longitude;
|
|
||||||
cb->set_interval = driver_location_set_interval;
|
cb->set_interval = driver_location_set_interval;
|
||||||
g_extern.system.location_callback = *cb;
|
g_extern.system.location_callback = *cb;
|
||||||
g_extern.location_active = true;
|
g_extern.location_active = true;
|
||||||
|
11
libretro.h
11
libretro.h
@ -764,18 +764,15 @@ typedef bool (*retro_location_start_t)(void);
|
|||||||
// location.
|
// location.
|
||||||
typedef void (*retro_location_stop_t)(void);
|
typedef void (*retro_location_stop_t)(void);
|
||||||
|
|
||||||
// Get the latitude of the current location.
|
// Get the position of the current location. Will set parameters to 0 if no new
|
||||||
typedef double (*retro_location_get_latitude_t)(void);
|
// location update has happened since the last time.
|
||||||
|
typedef bool (*retro_location_get_position_t)(double *lat, double *lon, double *accuracy);
|
||||||
// Get the longitude of the current location.
|
|
||||||
typedef double (*retro_location_get_longitude_t)(void);
|
|
||||||
|
|
||||||
struct retro_location_callback
|
struct retro_location_callback
|
||||||
{
|
{
|
||||||
retro_location_start_t start;
|
retro_location_start_t start;
|
||||||
retro_location_stop_t stop;
|
retro_location_stop_t stop;
|
||||||
retro_location_get_latitude_t get_latitude;
|
retro_location_get_position_t get_position;
|
||||||
retro_location_get_longitude_t get_longitude;
|
|
||||||
retro_location_set_interval_t set_interval;
|
retro_location_set_interval_t set_interval;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -26,6 +26,8 @@ typedef struct android_location
|
|||||||
jmethodID onLocationSetInterval;
|
jmethodID onLocationSetInterval;
|
||||||
jmethodID onLocationGetLongitude;
|
jmethodID onLocationGetLongitude;
|
||||||
jmethodID onLocationGetLatitude;
|
jmethodID onLocationGetLatitude;
|
||||||
|
jmethodID onLocationGetAccuracy;
|
||||||
|
jmethodID onLocationHasChanged;
|
||||||
} androidlocation_t;
|
} androidlocation_t;
|
||||||
|
|
||||||
static void *android_location_init(void)
|
static void *android_location_init(void)
|
||||||
@ -46,7 +48,7 @@ static void *android_location_init(void)
|
|||||||
if (class == NULL)
|
if (class == NULL)
|
||||||
goto dealloc;
|
goto dealloc;
|
||||||
|
|
||||||
GET_METHOD_ID(env, androidlocation->onLocationInit, class, "onLocationInit", "(II)V");
|
GET_METHOD_ID(env, androidlocation->onLocationInit, class, "onLocationInit", "()V");
|
||||||
if (!androidlocation->onLocationInit)
|
if (!androidlocation->onLocationInit)
|
||||||
goto dealloc;
|
goto dealloc;
|
||||||
|
|
||||||
@ -70,14 +72,21 @@ static void *android_location_init(void)
|
|||||||
if (!androidlocation->onLocationGetLongitude)
|
if (!androidlocation->onLocationGetLongitude)
|
||||||
goto dealloc;
|
goto dealloc;
|
||||||
|
|
||||||
|
GET_METHOD_ID(env, androidlocation->onLocationGetAccuracy, class, "onLocationGetAccuracy", "()F");
|
||||||
|
if (!androidlocation->onLocationGetAccuracy)
|
||||||
|
goto dealloc;
|
||||||
|
|
||||||
GET_METHOD_ID(env, androidlocation->onLocationGetLongitude, class, "onLocationSetInterval", "(II)V");
|
GET_METHOD_ID(env, androidlocation->onLocationGetLongitude, class, "onLocationSetInterval", "(II)V");
|
||||||
if (!androidlocation->onLocationSetInterval)
|
if (!androidlocation->onLocationSetInterval)
|
||||||
goto dealloc;
|
goto dealloc;
|
||||||
|
|
||||||
|
GET_METHOD_ID(env, androidlocation->onLocationHasChanged, class, "onLocationHasChanged", "()Z");
|
||||||
|
if (!androidlocation->onLocationHasChanged)
|
||||||
|
goto dealloc;
|
||||||
|
|
||||||
CALL_VOID_METHOD(env, android_app->activity->clazz, androidlocation->onLocationInit);
|
CALL_VOID_METHOD(env, android_app->activity->clazz, androidlocation->onLocationInit);
|
||||||
|
|
||||||
return androidlocation;
|
return androidlocation;
|
||||||
|
|
||||||
dealloc:
|
dealloc:
|
||||||
free(androidlocation);
|
free(androidlocation);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -120,30 +129,40 @@ static void android_location_stop(void *data)
|
|||||||
CALL_VOID_METHOD(env, android_app->activity->clazz, androidlocation->onLocationStop);
|
CALL_VOID_METHOD(env, android_app->activity->clazz, androidlocation->onLocationStop);
|
||||||
}
|
}
|
||||||
|
|
||||||
static double android_location_get_latitude(void *data)
|
static bool android_location_get_position(void *data, double *latitude, double *longitude, double *accuracy)
|
||||||
{
|
{
|
||||||
struct android_app *android_app = (struct android_app*)g_android;
|
struct android_app *android_app = (struct android_app*)g_android;
|
||||||
androidlocation_t *androidlocation = (androidlocation_t*)data;
|
androidlocation_t *androidlocation = (androidlocation_t*)data;
|
||||||
JNIEnv *env = jni_thread_getenv();
|
JNIEnv *env = jni_thread_getenv();
|
||||||
if (!env)
|
if (!env)
|
||||||
return 0.0;
|
goto fail;
|
||||||
|
|
||||||
jdouble latitude;
|
jdouble lat, lon, accuhurtz;
|
||||||
CALL_BOOLEAN_METHOD(env, latitude, android_app->activity->clazz, androidlocation->onLocationGetLatitude);
|
jboolean newLocation;
|
||||||
return latitude;
|
|
||||||
}
|
|
||||||
|
|
||||||
static double android_location_get_longitude(void *data)
|
CALL_BOOLEAN_METHOD(env, newLocation, android_app->activity->clazz, androidlocation->onLocationHasChanged);
|
||||||
{
|
|
||||||
struct android_app *android_app = (struct android_app*)g_android;
|
|
||||||
androidlocation_t *androidlocation = (androidlocation_t*)data;
|
|
||||||
JNIEnv *env = jni_thread_getenv();
|
|
||||||
if (!env)
|
|
||||||
return 0.0;
|
|
||||||
|
|
||||||
jdouble longitude;
|
if (!newLocation)
|
||||||
CALL_BOOLEAN_METHOD(env, longitude, android_app->activity->clazz, androidlocation->onLocationGetLongitude);
|
goto fail;
|
||||||
return longitude;
|
|
||||||
|
CALL_DOUBLE_METHOD(env, lat, android_app->activity->clazz, androidlocation->onLocationGetLatitude);
|
||||||
|
CALL_DOUBLE_METHOD(env, lon, android_app->activity->clazz, androidlocation->onLocationGetLongitude);
|
||||||
|
CALL_DOUBLE_METHOD(env, accuhurtz, android_app->activity->clazz, androidlocation->onLocationGetAccuracy);
|
||||||
|
|
||||||
|
if (lat != 0.0)
|
||||||
|
*latitude = lat;
|
||||||
|
if (lon != 0.0)
|
||||||
|
*longitude = lon;
|
||||||
|
if (accuhurtz != 0.0)
|
||||||
|
*accuracy = accuhurtz;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
*latitude = 0.0;
|
||||||
|
*longitude = 0.0;
|
||||||
|
*accuracy = 0.0;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void android_location_set_interval(void *data, unsigned interval_ms, unsigned interval_distance)
|
static void android_location_set_interval(void *data, unsigned interval_ms, unsigned interval_distance)
|
||||||
@ -154,7 +173,7 @@ static void android_location_set_interval(void *data, unsigned interval_ms, unsi
|
|||||||
if (!env)
|
if (!env)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CALL_VOID_METHOD_PARAM(env, android_app->activity->clazz, androidlocation->onLocationSetInterval, interval_ms, interval_distance);
|
CALL_VOID_METHOD_PARAM(env, android_app->activity->clazz, androidlocation->onLocationSetInterval, (int)interval_ms, (int)interval_distance);
|
||||||
}
|
}
|
||||||
|
|
||||||
const location_driver_t location_android = {
|
const location_driver_t location_android = {
|
||||||
@ -162,8 +181,7 @@ const location_driver_t location_android = {
|
|||||||
android_location_free,
|
android_location_free,
|
||||||
android_location_start,
|
android_location_start,
|
||||||
android_location_stop,
|
android_location_stop,
|
||||||
android_location_get_longitude,
|
android_location_get_position,
|
||||||
android_location_get_latitude,
|
|
||||||
android_location_set_interval,
|
android_location_set_interval,
|
||||||
"android",
|
"android",
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user