Re: [AD] New gfx api

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Peter Wang wrote:
I don't know how else to say it. You don't have to handle any queues if you don't want to. There is a key[]-like mechanism already -- you just can't access it without going through some synchronisation. Similarly for the mouse and joystick APIs.

Well, I guess I'll just have to wait and see the final implementaion then. I'm just getting more confused. Unless this is how you mean:

OS sends an event to Allegro (key pressed/released, mouse moved, etc). Allegro converts the OS event into an Allegro event. Allegro handles the event internally (updates the mouse position, key[]-mechanism, etc), then passes it to a user-installed event handler.

Is that close?

And how is the key[] array any different? It's still "polling" in that sense.

But with a key[] array, it's updated away from the main program/thread. So if I dereference the key array, wait a second, then dereference again it'll show the current keyboard state along with whatever changes happened within that second, not the last time you "took the snap shot".

Ok, so you don't like the one extra step.

Not that I have to do the one extra step, but the overhead associated with it I don't really care for.

If I have to continually refresh the keyboard state, it'll just bring more work into the main program. I'd prefer the main program not have to worry about refreshing the keyboard (or mouse or other device) state.. it should be done automatically.

I know key[] is convenient for many programs, but passing information between threads through global variables without any synchronisation is just a bad idea. I just couldn't think of a mechanism which is both thread-safe _and_ as convenient.

As long as the variable is volatile and not read in the main thread, I don't see anything wrong with updating it in a seperate thread. At worst, the old data is "ghosted" in the main thread for a few nano seconds (if that).

- Kitty Cat




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/