uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 63108c178acb6a6c9ac949c55dee34e9b1b03ad5
parent b5fa665cdbd76122bf08f87655eed4da2b729ec5
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date:   Thu, 26 Jan 2023 10:56:14 -0800

Tighter run

Diffstat:
Msrc/uxnemu.c | 24++++++++----------------
1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -432,28 +432,20 @@ handle_events(Uxn *u) static int run(Uxn *u) { - Uint64 now = SDL_GetPerformanceCounter(), frame_end, frame_interval = SDL_GetPerformanceFrequency() / 60; - for(;;) { - /* .System/halt */ - if(u->dev[0x0f]) - return error("Run", "Ended."); - frame_end = now + frame_interval; + Uint64 now = SDL_GetPerformanceCounter(), frame_end = now, frame_interval = SDL_GetPerformanceFrequency() / 60; + for(;!u->dev[0x0f]; now = SDL_GetPerformanceCounter()) { exec_deadline = now + deadline_interval; if(!handle_events(u)) return 0; - uxn_eval(u, GETVEC(&u->dev[0x20])); + if (((Sint64)(frame_end - SDL_GetPerformanceCounter())) >= 0) { + frame_end = now + frame_interval; + uxn_eval(u, GETVEC(&u->dev[0x20])); + } if(uxn_screen.fg.changed || uxn_screen.bg.changed) redraw(); - now = SDL_GetPerformanceCounter(); - if(u->dev[0x20]) { - if(!BENCH && ((Sint64)(frame_end - now)) > 0) { - SDL_Delay((frame_end - now) / ms_interval); - now = frame_end; - } - } else - SDL_WaitEvent(NULL); + SDL_WaitEventTimeout(NULL, GETVEC(&u->dev[0x20]) ? (frame_end - SDL_GetPerformanceCounter()) / ms_interval : 0x100000); } - return error("SDL_WaitEvent", SDL_GetError()); + return error("Run", "Ended."); } int