0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-24 06:45:11 +00:00

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 fi
echo "Assembling.." echo "Assembling.."
./bin/assembler projects/software/left.usm bin/boot.rom ./bin/assembler projects/software/noodle.usm bin/boot.rom
echo "Running.." echo "Running.."
if [ "${2}" = '--cli' ]; if [ "${2}" = '--cli' ];

View file

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