On OpenBSD I was unable to compile the original source since the timerfd
stuff is Linux only.
I suggest to just use usleep(16666) in the main loop.
After the modify I was able to compile and run the emulator.
crossbower (1):
src/uxn11.c: remove dependency on non-posix timerfd (just use usleep)
src/uxn11.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
--
2.34.2
From: crossbower <crossbower@gmail.com>
Signed-off-by: crossbower <crossbower@gmail.com>
---
src/uxn11.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/src/uxn11.c b/src/uxn11.c
index e68300f..c690882 100644
--- a/src/uxn11.c
+++ b/src/uxn11.c
@@ -3,7 +3,7 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysymdef.h>
-#include <sys/timerfd.h>
+//#include <sys/timerfd.h>
#include <unistd.h>
#include <poll.h>
@@ -223,8 +223,7 @@ main(int argc, char **argv)
Uxn u;
int i;
char expirations[8];
- struct pollfd fds[2];
- static const struct itimerspec screen_tspec = {{0, 16666666}, {0, 16666666}};
+ struct pollfd fds[1];
if(argc < 2)
return emu_error("Usage", "uxn11 game.rom args");
/* start sequence */
@@ -241,19 +240,15 @@ main(int argc, char **argv)
}
/* timer */
fds[0].fd = XConnectionNumber(display);
- fds[1].fd = timerfd_create(CLOCK_MONOTONIC, 0);
- timerfd_settime(fds[1].fd, 0, &screen_tspec, NULL);
- fds[0].events = fds[1].events = POLLIN;
+ fds[0].events = POLLIN;
/* main loop */
while(1) {
- if(poll(fds, 2, 1000) <= 0)
+ if(poll(fds, 1, 1000) <= 0)
continue;
while(XPending(display))
emu_event(&u);
- if(poll(&fds[1], 1, 0)) {
- read(fds[1].fd, expirations, 8); /* Indicate we handled the timer */
- uxn_eval(&u, GETVEC(&u.dev[0x20])); /* Call the vector once, even if the timer fired multiple times */
- }
+ usleep(16666); // <--- INSTEAD OF TIMERFD
+ uxn_eval(&u, GETVEC(&u.dev[0x20])); /* Call the vector once, even if the timer fired multiple times */
if(uxn_screen.fg.changed || uxn_screen.bg.changed)
emu_draw();
}
--
2.34.2
On Wed, May 25, 2022 at 19:04:13 +0000, ~crossbower wrote:
> On OpenBSD I was unable to compile the original source since the timerfd
> stuff is Linux only.
> I suggest to just use usleep(16666) in the main loop.
This fixes the compile error, but usleep(3) is still not portable, and
will not have totally regular frames, because your patch assumes no time
is used between each frame.
My patch (attached) uses only POSIX functions, and also has a more accurate
frame rate by pinging the parent process on each frame.
~phoebos