Clamp at 60fps

This commit is contained in:
neauoire 2021-04-04 11:47:13 -07:00
parent 98da3cbe31
commit 3ca4fb6b42
2 changed files with 28 additions and 24 deletions

View File

@ -28,7 +28,7 @@ else
fi
echo "Assembling.."
./bin/assembler projects/software/left.usm bin/boot.rom
./bin/assembler projects/software/noodle.usm bin/boot.rom
echo "Running.."
if [ "${2}" = '--cli' ];

View File

@ -564,19 +564,10 @@ ppnil(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
#pragma mark - Generics
int
start(Uxn *u)
void
runevents(Uxn *u)
{
int ticknext = 0;
evaluxn(u, PAGE_VECTORS);
if(screen.reqdraw)
redraw(pixels, u);
while(1) {
int tick = SDL_GetTicks();
SDL_Event event;
if(tick < ticknext)
SDL_Delay(ticknext - tick);
ticknext = tick + (1000 / FPS);
while(SDL_PollEvent(&event) != 0) {
switch(event.type) {
case SDL_QUIT: quit(); break;
@ -592,9 +583,22 @@ start(Uxn *u)
break;
}
}
}
int
start(Uxn *u)
{
evaluxn(u, PAGE_VECTORS);
redraw(pixels, u);
while(1) {
float elapsed;
double start = SDL_GetPerformanceCounter();
runevents(u);
evaluxn(u, PAGE_VECTORS + 0x08);
if(screen.reqdraw)
redraw(pixels, u);
elapsed = (SDL_GetPerformanceCounter() - start) / (double)SDL_GetPerformanceFrequency() * 1000.0f;
SDL_Delay(floor(16.666f - elapsed));
}
}