only wait for vsync if under frame budget
This commit is contained in:
parent
1143e46d20
commit
d8c96b82fa
4 changed files with 20 additions and 11 deletions
|
|
@ -192,18 +192,22 @@ void GFX_clearAll(void) {
|
||||||
memset(gfx.map, 0, gfx.map_size);
|
memset(gfx.map, 0, gfx.map_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int frame_start = 0;
|
||||||
|
void GFX_startFrame(void) {
|
||||||
|
frame_start = SDL_GetTicks();
|
||||||
|
}
|
||||||
void GFX_flip(SDL_Surface* screen) {
|
void GFX_flip(SDL_Surface* screen) {
|
||||||
|
static int ticks = 0;
|
||||||
|
ticks += 1;
|
||||||
#ifdef GFX_ENABLE_VSYNC
|
#ifdef GFX_ENABLE_VSYNC
|
||||||
|
#define FRAME_BUDGET 17 // 60fps
|
||||||
|
if (frame_start==0 || SDL_GetTicks()-frame_start<FRAME_BUDGET) { // only wait if we're under frame budget
|
||||||
int arg = 1;
|
int arg = 1;
|
||||||
ioctl(gfx.fb, OWLFB_WAITFORVSYNC, &arg); // TODO: this doesn't wait but it also doesn't error out like FBIO_WAITFORVSYNC...
|
ioctl(gfx.fb, OWLFB_WAITFORVSYNC, &arg);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef GFX_ENABLE_BUFFER
|
#ifdef GFX_ENABLE_BUFFER
|
||||||
// TODO: this would be moved to a thread
|
|
||||||
// I'm not clear on why that would be necessary
|
|
||||||
// if it's non-blocking and the pan will wait
|
|
||||||
// until the next vblank...
|
|
||||||
// what if the scaling was also moved to a thread?
|
|
||||||
gfx.vinfo.yoffset = gfx.buffer * SCREEN_HEIGHT;
|
gfx.vinfo.yoffset = gfx.buffer * SCREEN_HEIGHT;
|
||||||
ioctl(gfx.fb, FBIOPAN_DISPLAY, &gfx.vinfo);
|
ioctl(gfx.fb, FBIOPAN_DISPLAY, &gfx.vinfo);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ void LOG_note(int level, const char* fmt, ...);
|
||||||
SDL_Surface* GFX_init(void);
|
SDL_Surface* GFX_init(void);
|
||||||
void GFX_clear(SDL_Surface* screen);
|
void GFX_clear(SDL_Surface* screen);
|
||||||
void GFX_clearAll(void);
|
void GFX_clearAll(void);
|
||||||
|
void GFX_startFrame(void);
|
||||||
void GFX_flip(SDL_Surface* screen);
|
void GFX_flip(SDL_Surface* screen);
|
||||||
void GFX_quit(void);
|
void GFX_quit(void);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -926,6 +926,7 @@ int main(int argc , char* argv[]) {
|
||||||
|
|
||||||
sec_start = SDL_GetTicks();
|
sec_start = SDL_GetTicks();
|
||||||
while (1) {
|
while (1) {
|
||||||
|
GFX_startFrame();
|
||||||
if (PAD_justReleased(BTN_POWER)) break; // TODO: tmp
|
if (PAD_justReleased(BTN_POWER)) break; // TODO: tmp
|
||||||
core.run();
|
core.run();
|
||||||
cpu_ticks += 1;
|
cpu_ticks += 1;
|
||||||
|
|
|
||||||
|
|
@ -1262,6 +1262,7 @@ int main (int argc, char *argv[]) {
|
||||||
unsigned long cancel_start = SDL_GetTicks();
|
unsigned long cancel_start = SDL_GetTicks();
|
||||||
unsigned long power_start = 0;
|
unsigned long power_start = 0;
|
||||||
while (!quit) {
|
while (!quit) {
|
||||||
|
GFX_startFrame();
|
||||||
unsigned long frame_start = SDL_GetTicks();
|
unsigned long frame_start = SDL_GetTicks();
|
||||||
|
|
||||||
PAD_poll();
|
PAD_poll();
|
||||||
|
|
@ -1556,10 +1557,12 @@ int main (int argc, char *argv[]) {
|
||||||
GFX_flip(screen);
|
GFX_flip(screen);
|
||||||
dirty = 0;
|
dirty = 0;
|
||||||
}
|
}
|
||||||
// // slow down to 60fps
|
else {
|
||||||
// unsigned long frame_duration = SDL_GetTicks() - frame_start;
|
// slow down to 60fps
|
||||||
// #define TARGET_FRAME_DURATION 17
|
unsigned long frame_duration = SDL_GetTicks() - frame_start;
|
||||||
// if (frame_duration<TARGET_FRAME_DURATION) SDL_Delay(TARGET_FRAME_DURATION-frame_duration);
|
#define TARGET_FRAME_DURATION 17
|
||||||
|
if (frame_duration<TARGET_FRAME_DURATION) SDL_Delay(TARGET_FRAME_DURATION-frame_duration);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (version) SDL_FreeSurface(version);
|
if (version) SDL_FreeSurface(version);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue