Skip to content

Commit 9fda23b

Browse files
committed
Introduced basic FPS cap as view option
1 parent b8cd8ba commit 9fda23b

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

ui/xemu.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ static bool alt_grab;
106106
static bool ctrl_grab;
107107
static int gui_saved_grab;
108108
static int gui_fullscreen;
109+
static int fps_selection = 3;
110+
static float frame_deadline = (NANOSECONDS_PER_SECOND / 60);
109111
static int gui_grab_code = KMOD_LALT | KMOD_LCTRL;
110112
static SDL_Cursor *sdl_cursor_normal;
111113
static SDL_Cursor *sdl_cursor_hidden;
@@ -132,6 +134,26 @@ void xemu_toggle_fullscreen(void)
132134
toggle_full_screen(&sdl2_console[0]);
133135
}
134136

137+
int xemu_get_frame_rate_cap(void)
138+
{
139+
return fps_selection;
140+
}
141+
142+
void xemu_set_frame_rate_cap(int selection)
143+
{
144+
// FIXME: Remove redundent selection
145+
fps_selection = selection;
146+
147+
// No framerate cap
148+
if (!selection) {
149+
frame_deadline = 0;
150+
}
151+
152+
const int framerates[6] = { 60, 15, 30, 60, 120, 144 };
153+
int frame_rate = framerates[selection];
154+
frame_deadline = (float)NANOSECONDS_PER_SECOND / frame_rate;
155+
}
156+
135157
#define SDL2_REFRESH_INTERVAL_BUSY 16
136158
#define SDL2_MAX_IDLE_COUNT (2 * GUI_REFRESH_INTERVAL_DEFAULT \
137159
/ SDL2_REFRESH_INTERVAL_BUSY + 1)
@@ -1084,7 +1106,7 @@ void sdl2_gl_refresh(DisplayChangeListener *dcl)
10841106
* Throttle to make sure swaps happen at 60Hz
10851107
*/
10861108
static int64_t last_update = 0;
1087-
int64_t deadline = last_update + 16666666;
1109+
int64_t deadline = last_update + frame_deadline;
10881110

10891111
#ifdef DEBUG_XEMU_C
10901112
int64_t sleep_acc = 0;

ui/xui/menubar.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,17 @@ void ShowMainMenu()
194194
nv2a_set_surface_scale_factor(rendering_scale + 1);
195195
}
196196

197+
int max_fps = xemu_get_frame_rate_cap();
198+
if(ImGui::Combo("Frame Rate Cap", &max_fps,
199+
"none\0"
200+
"15fps\0"
201+
"30fps\0"
202+
"60fps\0"
203+
"120fps\0"
204+
"144fps\0")) {
205+
xemu_set_frame_rate_cap(max_fps);
206+
}
207+
197208
ImGui::Combo("Display Mode", &g_config.display.ui.fit,
198209
"Center\0Scale\0Stretch\0");
199210
ImGui::SameLine();

ui/xui/xemu-hud.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ extern "C" {
3333
// Implemented in xemu.c
3434
int xemu_is_fullscreen(void);
3535
void xemu_toggle_fullscreen(void);
36+
int xemu_get_frame_rate_cap(void);
37+
void xemu_set_frame_rate_cap(int selection);
3638
void xemu_eject_disc(Error **errp);
3739
void xemu_load_disc(const char *path, Error **errp);
3840

0 commit comments

Comments
 (0)