shrooms-vb-native/game.c

34 lines
756 B
C
Raw Normal View History

#include <assets.h>
2024-10-15 04:24:13 +00:00
#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, GraphicsContext *gfx) {
2024-10-15 04:24:13 +00:00
uint32_t clocks;
SDL_Event event;
gfxUpdateLeftEye(gfx, LEFT_EYE_DEFAULT);
gfxUpdateRightEye(gfx, RIGHT_EYE_DEFAULT);
2024-10-15 04:24:13 +00:00
while (1) {
clocks = MAX_STEP_CLOCKS;
vbEmulate(sim, &clocks);
gfxRender(gfx);
2024-10-15 04:24:13 +00:00
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
return 0;
}
}
sleepNanos((MAX_STEP_CLOCKS - clocks) * 50);
}
}