~rabbits/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
3 3

[PATCH uxn11 0/1] Remove dependency on non-posix timerfd for *BSD and non-Linux systems

Details
Message ID
<165350545316.23834.16423803443025824096-0@git.sr.ht>
DKIM signature
missing
Download raw message
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

[PATCH uxn11 1/1] [PATCH uxn] src/uxn11.c: remove dependency on non-posix timerfd (just use usleep)

Details
Message ID
<165350545316.23834.16423803443025824096-1@git.sr.ht>
In-Reply-To
<165350545316.23834.16423803443025824096-0@git.sr.ht> (view parent)
DKIM signature
missing
Download raw message
Patch: +6 -11
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

[uxn/patches/.build.yml] build failed

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CK92S8P27Q40.2MDYLQAX92EUT@cirno>
In-Reply-To
<165350545316.23834.16423803443025824096-1@git.sr.ht> (view parent)
DKIM signature
missing
Download raw message
uxn/patches/.build.yml: FAILED in 55s

[Remove dependency on non-posix timerfd for *BSD and non-Linux systems][0] from [~crossbower][1]

[0]: https://lists.sr.ht/~rabbits/public-inbox/patches/32512
[1]: crossbower@tuta.io

✗ #766629 FAILED uxn/patches/.build.yml https://builds.sr.ht/~rabbits/job/766629
Details
Message ID
<20220531180758.tanfj52dlvk6nnhf@t480>
In-Reply-To
<165350545316.23834.16423803443025824096-0@git.sr.ht> (view parent)
DKIM signature
pass
Download raw message
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
Reply to thread Export thread (mbox)