Add pausing when window loses focus :p
This commit is contained in:
parent
3033fb6791
commit
93202f191c
|
@ -156,7 +156,8 @@ static const unsigned rewind_buffer_size = 20 << 20; // 20MiB
|
||||||
// How many frames to rewind at a time.
|
// How many frames to rewind at a time.
|
||||||
static const unsigned rewind_granularity = 1;
|
static const unsigned rewind_granularity = 1;
|
||||||
|
|
||||||
|
// Pause gameplay when gameplay loses focus.
|
||||||
|
static const bool pause_nonactive = true;
|
||||||
|
|
||||||
|
|
||||||
////////////////////
|
////////////////////
|
||||||
|
|
1
driver.h
1
driver.h
|
@ -110,6 +110,7 @@ typedef struct video_driver
|
||||||
void (*set_nonblock_state)(void* data, bool toggle); // Should we care about syncing to vblank? Fast forwarding.
|
void (*set_nonblock_state)(void* data, bool toggle); // Should we care about syncing to vblank? Fast forwarding.
|
||||||
// Is the window still active?
|
// Is the window still active?
|
||||||
bool (*alive)(void *data);
|
bool (*alive)(void *data);
|
||||||
|
bool (*focus)(void *data); // Does the window have focus?
|
||||||
void (*free)(void* data);
|
void (*free)(void* data);
|
||||||
const char *ident;
|
const char *ident;
|
||||||
} video_driver_t;
|
} video_driver_t;
|
||||||
|
|
|
@ -90,6 +90,8 @@ struct settings
|
||||||
bool rewind_enable;
|
bool rewind_enable;
|
||||||
unsigned rewind_buffer_size;
|
unsigned rewind_buffer_size;
|
||||||
unsigned rewind_granularity;
|
unsigned rewind_granularity;
|
||||||
|
|
||||||
|
bool pause_nonactive;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ssnes_game_type
|
enum ssnes_game_type
|
||||||
|
|
7
gfx/gl.c
7
gfx/gl.c
|
@ -553,11 +553,18 @@ static bool gl_alive(void *data)
|
||||||
return !gl->quitting;
|
return !gl->quitting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool gl_focus(void *data)
|
||||||
|
{
|
||||||
|
(void)data;
|
||||||
|
return (SDL_GetAppState() & (SDL_APPINPUTFOCUS | SDL_APPACTIVE)) == (SDL_APPINPUTFOCUS | SDL_APPACTIVE);
|
||||||
|
}
|
||||||
|
|
||||||
const video_driver_t video_gl = {
|
const video_driver_t video_gl = {
|
||||||
.init = gl_init,
|
.init = gl_init,
|
||||||
.frame = gl_frame,
|
.frame = gl_frame,
|
||||||
.alive = gl_alive,
|
.alive = gl_alive,
|
||||||
.set_nonblock_state = gl_set_nonblock_state,
|
.set_nonblock_state = gl_set_nonblock_state,
|
||||||
|
.focus = gl_focus,
|
||||||
.free = gl_free,
|
.free = gl_free,
|
||||||
.ident = "gl"
|
.ident = "gl"
|
||||||
};
|
};
|
||||||
|
|
|
@ -322,7 +322,7 @@ static void sdl_input_poll(void *data)
|
||||||
*sdl->should_resize = true;
|
*sdl->should_resize = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,6 +127,7 @@ static void set_defaults(void)
|
||||||
g_settings.rewind_enable = rewind_enable;
|
g_settings.rewind_enable = rewind_enable;
|
||||||
g_settings.rewind_buffer_size = rewind_buffer_size;
|
g_settings.rewind_buffer_size = rewind_buffer_size;
|
||||||
g_settings.rewind_granularity = rewind_granularity;
|
g_settings.rewind_granularity = rewind_granularity;
|
||||||
|
g_settings.pause_nonactive = pause_nonactive;
|
||||||
|
|
||||||
assert(sizeof(g_settings.input.binds[0]) >= sizeof(snes_keybinds_1));
|
assert(sizeof(g_settings.input.binds[0]) >= sizeof(snes_keybinds_1));
|
||||||
assert(sizeof(g_settings.input.binds[1]) >= sizeof(snes_keybinds_2));
|
assert(sizeof(g_settings.input.binds[1]) >= sizeof(snes_keybinds_2));
|
||||||
|
@ -320,6 +321,8 @@ static void parse_config_file(void)
|
||||||
|
|
||||||
CONFIG_GET_INT(rewind_granularity, "rewind_granularity");
|
CONFIG_GET_INT(rewind_granularity, "rewind_granularity");
|
||||||
|
|
||||||
|
CONFIG_GET_BOOL(pause_nonactive, "pause_nonactive");
|
||||||
|
|
||||||
read_keybinds(conf);
|
read_keybinds(conf);
|
||||||
|
|
||||||
config_file_free(conf);
|
config_file_free(conf);
|
||||||
|
|
24
ssnes.c
24
ssnes.c
|
@ -943,7 +943,14 @@ static void check_pause(void)
|
||||||
{
|
{
|
||||||
static bool old_state = false;
|
static bool old_state = false;
|
||||||
bool new_state = driver.input->key_pressed(driver.input_data, SSNES_PAUSE_TOGGLE);
|
bool new_state = driver.input->key_pressed(driver.input_data, SSNES_PAUSE_TOGGLE);
|
||||||
if (new_state && !old_state)
|
|
||||||
|
static bool old_focus = true;
|
||||||
|
bool focus = true;
|
||||||
|
|
||||||
|
if (g_settings.pause_nonactive)
|
||||||
|
focus = driver.video->focus(driver.video_data);
|
||||||
|
|
||||||
|
if (focus && new_state && !old_state)
|
||||||
{
|
{
|
||||||
g_extern.is_paused = !g_extern.is_paused;
|
g_extern.is_paused = !g_extern.is_paused;
|
||||||
|
|
||||||
|
@ -960,7 +967,22 @@ static void check_pause(void)
|
||||||
driver.audio->start(driver.audio_data);
|
driver.audio->start(driver.audio_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (focus && !old_focus)
|
||||||
|
{
|
||||||
|
SSNES_LOG("Unpaused!\n");
|
||||||
|
g_extern.is_paused = false;
|
||||||
|
if (driver.audio_data)
|
||||||
|
driver.audio->start(driver.audio_data);
|
||||||
|
}
|
||||||
|
else if (!focus && old_focus)
|
||||||
|
{
|
||||||
|
SSNES_LOG("Paused!\n");
|
||||||
|
g_extern.is_paused = true;
|
||||||
|
if (driver.audio_data)
|
||||||
|
driver.audio->stop(driver.audio_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
old_focus = focus;
|
||||||
old_state = new_state;
|
old_state = new_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue