try to accurate software vsync

This commit is contained in:
Carlos Aragones 2021-04-28 11:07:25 +02:00
parent cc79a85e3d
commit f9aa6acb7a
4 changed files with 48 additions and 44 deletions

View File

@ -321,18 +321,8 @@ mfb_wait_sync(struct mfb_window *window) {
double current; double current;
uint32_t millis = 1; uint32_t millis = 1;
while(1) { while(1) {
event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES];
if (event) {
[NSApp sendEvent:event];
}
if(window_data->close) {
destroy_window_data(window_data);
return false;
}
current = mfb_timer_now(window_data_osx->timer); current = mfb_timer_now(window_data_osx->timer);
if (current >= g_time_for_frame) { if (current >= g_time_for_frame * 0.96) {
mfb_timer_reset(window_data_osx->timer); mfb_timer_reset(window_data_osx->timer);
return true; return true;
} }
@ -342,6 +332,18 @@ mfb_wait_sync(struct mfb_window *window) {
usleep(millis * 1000); usleep(millis * 1000);
//sched_yield(); //sched_yield();
if(millis == 1) {
event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES];
if (event) {
[NSApp sendEvent:event];
if(window_data->close) {
destroy_window_data(window_data);
return false;
}
}
}
} }
} }

View File

@ -817,17 +817,8 @@ mfb_wait_sync(struct mfb_window *window) {
double current; double current;
uint32_t millis = 1; uint32_t millis = 1;
while(1) { while(1) {
if (wl_display_dispatch_pending(window_data_way->display) == -1) {
return false;
}
if(window_data->close) {
destroy_window_data(window_data);
return false;
}
current = mfb_timer_now(window_data_way->timer); current = mfb_timer_now(window_data_way->timer);
if (current >= g_time_for_frame) { if (current >= g_time_for_frame * 0.96) {
mfb_timer_reset(window_data_way->timer); mfb_timer_reset(window_data_way->timer);
return true; return true;
} }
@ -837,6 +828,17 @@ mfb_wait_sync(struct mfb_window *window) {
usleep(millis * 1000); usleep(millis * 1000);
//sched_yield(); //sched_yield();
if(millis == 1) {
if (wl_display_dispatch_pending(window_data_way->display) == -1) {
return false;
}
if(window_data->close) {
destroy_window_data(window_data);
return false;
}
}
} }
return true; return true;

View File

@ -666,18 +666,8 @@ mfb_wait_sync(struct mfb_window *window) {
double current; double current;
uint32_t millis = 1; uint32_t millis = 1;
while (1) { while (1) {
if(PeekMessage(&msg, window_data_win->window, 0, 0, PM_REMOVE)) { current = mfb_timer_now(window_data_win->timer);
TranslateMessage(&msg); if (current >= g_time_for_frame * 0.96) {
DispatchMessage(&msg);
}
if (window_data->close) {
destroy_window_data(window_data);
return false;
}
current = mfb_timer_now(window_data_win->timer);;
if (current >= g_time_for_frame) {
mfb_timer_reset(window_data_win->timer); mfb_timer_reset(window_data_win->timer);
return true; return true;
} }
@ -686,6 +676,16 @@ mfb_wait_sync(struct mfb_window *window) {
} }
Sleep(millis); Sleep(millis);
if(millis == 1 && PeekMessage(&msg, window_data_win->window, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
if (window_data->close) {
destroy_window_data(window_data);
return false;
}
}
} }
return true; return true;

View File

@ -452,18 +452,8 @@ mfb_wait_sync(struct mfb_window *window) {
double current; double current;
uint32_t millis = 1; uint32_t millis = 1;
while(1) { while(1) {
if(XEventsQueued(window_data_x11->display, QueuedAlready) > 0) {
XNextEvent(window_data_x11->display, &event);
processEvent(window_data, &event);
}
if(window_data->close) {
destroy_window_data(window_data);
return false;
}
current = mfb_timer_now(window_data_x11->timer); current = mfb_timer_now(window_data_x11->timer);
if (current >= g_time_for_frame) { if (current >= g_time_for_frame * 0.96) {
mfb_timer_reset(window_data_x11->timer); mfb_timer_reset(window_data_x11->timer);
return true; return true;
} }
@ -473,6 +463,16 @@ mfb_wait_sync(struct mfb_window *window) {
usleep(millis * 1000); usleep(millis * 1000);
//sched_yield(); //sched_yield();
if(millis == 1 && XEventsQueued(window_data_x11->display, QueuedAlready) > 0) {
XNextEvent(window_data_x11->display, &event);
processEvent(window_data, &event);
if(window_data->close) {
destroy_window_data(window_data);
return false;
}
}
} }
return true; return true;