Skip to content

Commit e0447c3

Browse files
committed
Revised comments and variable names. Removed unused fps variable and update method
1 parent 32173c3 commit e0447c3

File tree

1 file changed

+9
-26
lines changed

1 file changed

+9
-26
lines changed

ui/xemu.c

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static bool alt_grab;
106106
static bool ctrl_grab;
107107
static int gui_saved_grab;
108108
static int gui_fullscreen;
109-
static float frame_deadline = (NANOSECONDS_PER_SECOND / 60);
109+
static float min_frame_duration = (NANOSECONDS_PER_SECOND / 60);
110110
static int gui_grab_code = KMOD_LALT | KMOD_LCTRL;
111111
static SDL_Cursor *sdl_cursor_normal;
112112
static SDL_Cursor *sdl_cursor_hidden;
@@ -140,7 +140,7 @@ void xemu_update_frame_rate_cap(void)
140140

141141
// No framerate cap
142142
if (!selection) {
143-
frame_deadline = 0;
143+
min_frame_duration = 0;
144144
return;
145145
}
146146

@@ -156,7 +156,7 @@ void xemu_update_frame_rate_cap(void)
156156

157157
// Calculate the minimum time allowed between frames based on
158158
// the desired frame rate
159-
frame_deadline = (float)NANOSECONDS_PER_SECOND / frame_rate;
159+
min_frame_duration = (float)NANOSECONDS_PER_SECOND / frame_rate;
160160
}
161161

162162
#define SDL2_REFRESH_INTERVAL_BUSY 16
@@ -1031,29 +1031,13 @@ void sdl2_gl_switch(DisplayChangeListener *dcl,
10311031
}
10321032
}
10331033

1034-
float fps = 1.0;
1035-
1036-
static void update_fps(void)
1037-
{
1038-
static int64_t last_update = 0;
1039-
const float r = 0.5;//0.1;
1040-
static float avg = 1.0;
1041-
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
1042-
float ms = ((float)(now-last_update)/1000000.0);
1043-
last_update = now;
1044-
if (fabs(avg-ms) > 0.25*avg) avg = ms;
1045-
else avg = avg*(1.0-r)+ms*r;
1046-
fps = 1000.0/avg;
1047-
}
1048-
10491034
void sdl2_gl_refresh(DisplayChangeListener *dcl)
10501035
{
10511036
struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
10521037
assert(scon->opengl);
10531038
bool flip_required = false;
10541039

10551040
SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
1056-
update_fps();
10571041

10581042
/* XXX: Note that this bypasses the usual VGA path in order to quickly
10591043
* get the surface. This is simple and fast, at the cost of accuracy.
@@ -1108,10 +1092,10 @@ void sdl2_gl_refresh(DisplayChangeListener *dcl)
11081092
qemu_mutex_unlock_main_loop();
11091093

11101094
/*
1111-
* Throttle to make sure swaps happen at 60Hz
1095+
* Throttle to make sure swaps happen at the desired frame rate cap
11121096
*/
1113-
static int64_t last_update = 0;
1114-
int64_t deadline = last_update + frame_deadline;
1097+
static int64_t last_frame_update = 0;
1098+
int64_t frame_expiration = last_frame_update + min_frame_duration;
11151099

11161100
#ifdef DEBUG_XEMU_C
11171101
int64_t sleep_acc = 0;
@@ -1126,8 +1110,8 @@ void sdl2_gl_refresh(DisplayChangeListener *dcl)
11261110

11271111
while (1) {
11281112
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
1129-
int64_t time_remaining = deadline - now;
1130-
if (now < deadline) {
1113+
int64_t time_remaining = frame_expiration - now;
1114+
if (now < frame_expiration) {
11311115
if (time_remaining > sleep_threshold) {
11321116
// Try to sleep until the until reaching the sleep threshold.
11331117
sleep_ns(time_remaining - sleep_threshold);
@@ -1144,11 +1128,10 @@ void sdl2_gl_refresh(DisplayChangeListener *dcl)
11441128
}
11451129
} else {
11461130
DPRINTF("zzZz %g %ld\n", (double)sleep_acc/1000000.0, spin_acc);
1147-
last_update = now;
1131+
last_frame_update = now;
11481132
break;
11491133
}
11501134
}
1151-
11521135
}
11531136

11541137
void sdl2_gl_redraw(struct sdl2_console *scon)

0 commit comments

Comments
 (0)