Refactor away rarch_main_set_idle

This commit is contained in:
twinaphex 2015-09-26 13:20:15 +02:00
parent 5ad2987449
commit e3e1a5a35c
4 changed files with 33 additions and 19 deletions

View File

@ -359,9 +359,11 @@ static void engine_handle_cmd(void)
if (!system->shutdown) if (!system->shutdown)
{ {
bool boolean = true;
RARCH_LOG("Pausing RetroArch.\n"); RARCH_LOG("Pausing RetroArch.\n");
rarch_main_set_pause(true); rarch_main_set_pause(true);
rarch_main_set_idle(true);
rarch_main_ctl(RARCH_MAIN_CTL_SET_IDLE, &boolean);
} }
break; break;
@ -390,16 +392,20 @@ static void engine_handle_cmd(void)
break; break;
case APP_CMD_GAINED_FOCUS: case APP_CMD_GAINED_FOCUS:
rarch_main_set_pause(false); {
rarch_main_set_idle(false); bool boolean = false;
if ((android_app->sensor_state_mask rarch_main_set_pause(false);
& (UINT64_C(1) << RETRO_SENSOR_ACCELEROMETER_ENABLE)) rarch_main_ctl(RARCH_MAIN_CTL_SET_IDLE, &boolean);
&& android_app->accelerometerSensor == NULL
&& driver->input_data) if ((android_app->sensor_state_mask
android_input_set_sensor_state(driver->input_data, 0, & (UINT64_C(1) << RETRO_SENSOR_ACCELEROMETER_ENABLE))
RETRO_SENSOR_ACCELEROMETER_ENABLE, && android_app->accelerometerSensor == NULL
android_app->accelerometer_event_rate); && driver->input_data)
android_input_set_sensor_state(driver->input_data, 0,
RETRO_SENSOR_ACCELEROMETER_ENABLE,
android_app->accelerometer_event_rate);
}
break; break;
case APP_CMD_LOST_FOCUS: case APP_CMD_LOST_FOCUS:
/* Avoid draining battery while app is not being used. */ /* Avoid draining battery while app is not being used. */

View File

@ -881,11 +881,6 @@ void rarch_main_set_max_frames(unsigned val)
main_max_frames = val; main_max_frames = val;
} }
void rarch_main_set_idle(unsigned enable)
{
main_is_idle = enable;
}
bool rarch_main_ctl(enum rarch_main_ctl_state state, void *data) bool rarch_main_ctl(enum rarch_main_ctl_state state, void *data)
{ {
switch (state) switch (state)
@ -898,6 +893,14 @@ bool rarch_main_ctl(enum rarch_main_ctl_state state, void *data)
*ptr = main_is_idle; *ptr = main_is_idle;
} }
return true; return true;
case RARCH_MAIN_CTL_SET_IDLE:
{
bool *ptr = (bool*)data;
if (!ptr)
return false;
main_is_idle = *ptr;
}
return true;
case RARCH_MAIN_CTL_IS_SLOWMOTION: case RARCH_MAIN_CTL_IS_SLOWMOTION:
{ {
bool *ptr = (bool*)data; bool *ptr = (bool*)data;

View File

@ -36,6 +36,7 @@ extern "C" {
enum rarch_main_ctl_state enum rarch_main_ctl_state
{ {
RARCH_MAIN_CTL_IS_IDLE = 0, RARCH_MAIN_CTL_IS_IDLE = 0,
RARCH_MAIN_CTL_SET_IDLE,
RARCH_MAIN_CTL_IS_SLOWMOTION, RARCH_MAIN_CTL_IS_SLOWMOTION,
RARCH_MAIN_CTL_SET_SLOWMOTION, RARCH_MAIN_CTL_SET_SLOWMOTION,
RARCH_MAIN_CTL_IS_PAUSED, RARCH_MAIN_CTL_IS_PAUSED,
@ -342,8 +343,6 @@ void rarch_main_set_frame_limit_last_time(void);
void rarch_main_set_max_frames(unsigned val); void rarch_main_set_max_frames(unsigned val);
void rarch_main_set_idle(unsigned enable);
void rarch_main_state_free(void); void rarch_main_state_free(void);
void rarch_main_global_free(void); void rarch_main_global_free(void);

View File

@ -45,16 +45,22 @@ void apple_rarch_exited(void);
static void rarch_enable_ui(void) static void rarch_enable_ui(void)
{ {
bool boolean = true;
ui_companion_set_foreground(true); ui_companion_set_foreground(true);
rarch_main_set_pause(true); rarch_main_set_pause(true);
rarch_main_set_idle(true);
rarch_main_ctl(RARCH_MAIN_CTL_SET_IDLE, &boolean);
} }
static void rarch_disable_ui(void) static void rarch_disable_ui(void)
{ {
bool boolean = false;
ui_companion_set_foreground(false); ui_companion_set_foreground(false);
rarch_main_set_pause(false); rarch_main_set_pause(false);
rarch_main_set_idle(false);
rarch_main_ctl(RARCH_MAIN_CTL_SET_IDLE, &boolean);
} }
static void rarch_draw_observer(CFRunLoopObserverRef observer, static void rarch_draw_observer(CFRunLoopObserverRef observer,