(RARCH_CONSOLE) Refactor timer code

This commit is contained in:
twinaphex 2013-01-08 00:35:49 +01:00
parent 1c39f6f630
commit fe62828fb1
9 changed files with 24 additions and 36 deletions

View File

@ -1179,7 +1179,7 @@ bool rmenu_iterate(void)
XInputGetState(0, &state);
if (IS_TIMER_EXPIRED(0))
if (!(g_extern.frame_count < g_extern.delay_timer))
{
bool rmenu_enable = !((state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB)
&& (state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) && (g_extern.main_is_init));
@ -1226,12 +1226,10 @@ bool rmenu_iterate(void)
return true;
deinit:
// set a timer delay so that we don't instantly switch back to the menu when
// press and holding L3 + R3 in the emulation loop (lasts for 30 frame ticks)
if(!(g_extern.lifecycle_state & (1ULL << RARCH_FRAMEADVANCE)))
{
// set a timer delay so that we don't instantly switch back to the menu when
// press and holding L3 + R3 in the emulation loop (lasts for 30 frame ticks)
SET_TIMER_EXPIRATION(0, 30);
}
g_extern.delay_timer = g_extern.frame_count + 30;
g_extern.console.rmenu.state.ingame_menu.enable = false;
g_extern.draw_menu = false;

View File

@ -17,10 +17,6 @@
#ifndef RARCH_CONSOLE_VIDEO_H__
#define RARCH_CONSOLE_VIDEO_H__
#define IS_TIMER_NOT_EXPIRED(index) (g_extern.frame_count < g_extern.console.general_timers[(index)].expire_frame)
#define IS_TIMER_EXPIRED(index) (!(IS_TIMER_NOT_EXPIRED(index)))
#define SET_TIMER_EXPIRATION(index, value) (g_extern.console.general_timers[(index)].expire_frame = g_extern.frame_count + (value))
#define MIN_SCALING_FACTOR (1.0f)
#if defined(__CELLOS_LV2__)

View File

@ -2322,10 +2322,10 @@ void rmenu_input_poll(void *data, void *state)
if(!first_held)
{
first_held = true;
SET_TIMER_EXPIRATION(1, 7);
g_extern.delay_timer = g_extern.frame_count + 7;
}
if(IS_TIMER_EXPIRED(1))
if(!(g_extern.frame_count < g_extern.delay_timer))
{
first_held = false;
rstate->input = input_state; //second input frame set as current frame
@ -2344,7 +2344,7 @@ void rmenu_input_process(void *data, void *state)
(void)data;
rmenu_state_t *rstate = (rmenu_state_t*)state;
if (IS_TIMER_EXPIRED(0))
if (!(g_extern.frame_count < g_extern.delay_timer))
{
bool rmenu_enable = (((rstate->old_state & (1ULL << RMENU_DEVICE_NAV_L3)) && (rstate->old_state & (1ULL << RMENU_DEVICE_NAV_R3)) && g_extern.main_is_init));
@ -2503,12 +2503,10 @@ bool rmenu_iterate(void)
return true;
deinit:
// set a timer delay so that we don't instantly switch back to the menu when
// press and holding L3 + R3 in the emulation loop (lasts for 30 frame ticks)
if (!(g_extern.lifecycle_state & (1ULL << RARCH_FRAMEADVANCE)))
{
// set a timer delay so that we don't instantly switch back to the menu when
// press and holding L3 + R3 in the emulation loop (lasts for 30 frame ticks)
SET_TIMER_EXPIRATION(0, 30);
}
g_extern.delay_timer = g_extern.frame_count + 30;
if(g_extern.console.rmenu.state.ingame_menu.enable)
menu_stack_pop();

View File

@ -298,10 +298,10 @@ static bool rmenu_iterate(void)
if(!first_held)
{
first_held = true;
SET_TIMER_EXPIRATION(1, (initial_held) ? 15 : 7);
g_extern.delay_timer = g_extern.frame_count + (initial_held ? 15 : 7);
}
if(IS_TIMER_EXPIRED(1))
if (!(g_extern.frame_count < g_extern.delay_timer))
{
first_held = false;
trigger_state = input_state; //second input frame set as current frame
@ -341,7 +341,7 @@ static bool rmenu_iterate(void)
old_input_state = input_state;
if(IS_TIMER_EXPIRED(0))
if (!(g_extern.frame_count < g_extern.delay_timer))
{
bool rmenu_enable = ((trigger_state & (1ULL << GX_DEVICE_NAV_MENU)) && g_extern.main_is_init);
bool quit_key_pressed = (trigger_state & (1ULL << GX_DEVICE_NAV_QUIT));
@ -364,12 +364,11 @@ static bool rmenu_iterate(void)
return true;
deinit:
// set a timer delay so that we don't instantly switch back to the menu when
// press and holding QUIT in the emulation loop (lasts for 30 frame ticks)
if (!(g_extern.lifecycle_state & (1ULL << RARCH_FRAMEADVANCE)))
{
// set a timer delay so that we don't instantly switch back to the menu when
// press and holding QUIT in the emulation loop (lasts for 30 frame ticks)
SET_TIMER_EXPIRATION(0, 30);
}
g_extern.delay_timer = g_extern.frame_count + 30;
g_extern.draw_menu = false;
g_extern.console.rmenu.state.ingame_menu.enable = false;

View File

@ -238,11 +238,6 @@ typedef struct rarch_boolean_state
unsigned value;
} rarch_boolean_state_t;
typedef struct rarch_frame_count
{
unsigned expire_frame;
} rarch_frame_count_t;
typedef struct rarch_resolution
{
unsigned idx;
@ -459,6 +454,7 @@ struct global
} frame_cache;
unsigned frame_count;
unsigned delay_timer;
char title_buf[64];
struct
@ -475,7 +471,6 @@ struct global
struct
{
bool block_config_read;
rarch_frame_count_t general_timers[2];
struct
{

View File

@ -449,7 +449,7 @@ static void gx_input_poll(void *data)
g_quit = false;
}
if (IS_TIMER_EXPIRED(0))
if (!(g_extern.frame_count < g_extern.delay_timer))
{
if (*pad_p1 & GX_QUIT_KEY)
*lifecycle_state |= (1ULL << RARCH_QUIT_KEY);

View File

@ -206,7 +206,8 @@ static void ps3_input_poll(void *data)
*lifecycle_state |= (1ULL << RARCH_STATE_SLOT_MINUS);
if ((*state_p1 & (1ULL << RARCH_ANALOG_RIGHT_Y_DPAD_UP)) && !(*state_p1 & (1ULL << RETRO_DEVICE_ID_JOYPAD_R2)))
*lifecycle_state |= (1ULL << RARCH_REWIND);
if(IS_TIMER_EXPIRED(0))
if (!(g_extern.frame_count < g_extern.delay_timer))
{
if((*state_p1 & (1ULL << RETRO_DEVICE_ID_JOYPAD_L3)) && (*state_p1 & (1ULL << RETRO_DEVICE_ID_JOYPAD_R3)))
{

View File

@ -2789,7 +2789,7 @@ bool rarch_main_iterate(void)
if (rmenu_enable || (g_extern.console.rmenu.state.ingame_menu.enable && !rmenu_enable))
{
g_extern.console.rmenu.mode = MODE_MENU;
SET_TIMER_EXPIRATION(0, 30);
g_extern.delay_timer = g_extern.frame_count + 30;
}
#endif
return false;

View File

@ -222,7 +222,8 @@ static void xdk_input_poll(void *data)
*lifecycle_state |= (1ULL << RARCH_STATE_SLOT_MINUS);
if ((*state_p1 & (1ULL << RARCH_ANALOG_RIGHT_Y_DPAD_UP)) && !(*state_p1 & (1ULL << RETRO_DEVICE_ID_JOYPAD_R2)))
*lifecycle_state |= (1ULL << RARCH_REWIND);
if(IS_TIMER_EXPIRED(0))
if (!(g_extern.frame_count < g_extern.delay_timer))
{
if((*state_p1 & (1ULL << RETRO_DEVICE_ID_JOYPAD_L3)) && (*state_p1 & (1ULL << RETRO_DEVICE_ID_JOYPAD_R3)))
{