2024-10-16 04:25:31 +00:00
|
|
|
#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
|
|
|
|
|
2024-10-16 04:25:31 +00:00
|
|
|
int runGame(VB *sim, GraphicsContext *gfx) {
|
2024-10-15 04:24:13 +00:00
|
|
|
uint32_t clocks;
|
|
|
|
SDL_Event event;
|
|
|
|
|
2024-10-16 04:25:31 +00:00
|
|
|
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);
|
2024-10-16 04:25:31 +00:00
|
|
|
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);
|
|
|
|
}
|
2024-10-16 04:25:31 +00:00
|
|
|
}
|