shrooms-vb-native/game.c

28 lines
596 B
C

#include <game.h>
#include <SDL2/SDL.h>
#include <time.h>
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) {
uint32_t clocks;
SDL_Event event;
while (1) {
clocks = MAX_STEP_CLOCKS;
vbEmulate(sim, &clocks);
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
return 0;
}
}
sleepNanos((MAX_STEP_CLOCKS - clocks) * 50);
}
}