lv2 / pugl

A minimal portable API for embeddable GUIs
https://gitlab.com/lv2/pugl/
ISC License
174 stars 34 forks source link

Added basic template for timer support, and windows implementation #29

Closed marc-weber1 closed 4 years ago

marc-weber1 commented 4 years ago

After this commit, timers are working, documented and tested on windows/cmake/c++.

!! WARNING !! This may cause the mac or linux version to fail to compile, but it will likely be a small and fixable error.

Timers are also not yet implemented on mac or linux, since I haven't been able to test either one yet. I may be able to add linux timers myself, but I will need external help for mac timers.

drobilla commented 4 years ago

Great, thanks.

I'm keen on having finally added tests to pugl recently, and this seems like an easy one, so I'll try to write one and implement it for the other platforms based on that.

Would probably be good to use in a demo too though. Maybe one of them can rotate the cube or whatever every second or so when not running continuously...

drobilla commented 4 years ago

This is way harder on both MacOS and especially X11.

It might be easier if pugl allocates the ID instead, but even then things don't quite line up...

marc-weber1 commented 4 years ago

Would it be easier if the function template looked more like:

PuglTimer registerTimer(PuglView view, double rate)

I could fix up the windows version to do that, if it helps

drobilla commented 4 years ago

Don't bother, it's going to need to be massaged along with the implementations, but thanks.

A pugl-allocated uintptr_t ID will probably work for MacOS. X11 has an xsync extension, but it doesn't allow associating any extra data with timers, and does not send events to windows at all, so... still no idea what to do there.

I imagine that reworking the event loop functions is going to have to happen for this.

drobilla commented 4 years ago

I ended up doing this from scratch but after a few misadventures it turned out basically the same in the end anyway: a54361853bdfa08437c2858e603ce6202fb341b2

It wasn't too much of a nuisance to do the ID thing like the Windows API, since both X11 and MacOS (annoyingly) required storing a record of all the timers anyway.

It reliably gets about 2ms precision on X11 and MacOS (really more like the ideal 1, but these things are never perfect), but only 10ms on Windows which is the minimum period there. There's some other "multimedia timers" API there that can apparently do better, but it's a whole different thing that doesn't work in the usual way and I don't care enough to bother.

We'll see how common functioning XSync extension support actually is, I have no idea...