#include #include #include #include int sleepNanos(long int ns) { struct timespec time; time.tv_sec = ns / 1000000000; time.tv_nsec = ns % 1000000000; return nanosleep(&time, NULL); } #define MAX_STEP_CLOCKS 20000 int runGame(VB *sim, GraphicsContext *gfx) { uint32_t clocks; SDL_Event event; gfxUpdateLeftEye(gfx, LEFT_EYE_DEFAULT); gfxUpdateRightEye(gfx, RIGHT_EYE_DEFAULT); while (1) { clocks = MAX_STEP_CLOCKS; vbEmulate(sim, &clocks); gfxRender(gfx); while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { return 0; } } sleepNanos((MAX_STEP_CLOCKS - clocks) * 50); } }