Re: Fw: Re: [AD] messy allegro 5.0 stuff

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


> You may also want to have a look at Lawrence's proposed API, which looks
> rather nice, although it's keyboard only.

I also read the related thread in the allegro.cc forum: no, Peter, you're
not the only one who loves callbacks :-)

Laurence wrote:
> Can somebody please give me an example of a nice, consistent program which
> uses callbacks and where another method just wouldn't do?

Firstly, is that really a valid argument ? Can it not be applied to the
notion of recursive functions as well for example: why to use recursive
functions since there is always a equivalent non recursive method to do the
job ?

Secondly, I have an example: emulators. In emulators, you need routines of
the lowest possible level to detect every event (key press, key release,
mouse button press, mouse button release, mouse move) and you need true
asynchronous input because you may want to accurately synchronize the
emulator with the emulated frame rate (50 Hz for instance), redrawing the
screen byte after byte in some cases, in order to be able to reproduce some
very special effects. You obviously don't want to poll between each byte.

Laurence wrote:
> As I said (somewhere), you really don't get any benefits being able to set
> a flag or two whenever a key is pressed: you still have to check for those
> flags in order to do something, so you might as well scan the keyboard
> whilst you're at it.

Callbacks are useful (not necessary, like recursive functions are not
necessary) when you want to do pure asynchronous event processing. Of course
you could set up your own thread, but why would you want to increase
again the system overhead ? Input processing is already done with threads on
most platforms by Allegro, why not simply allow to attach to these threads ?
Moreover, under DOS, callbacks are mandatory in this case.

I've been using Allegro since 3.0 to make emulators, first under DOS, now
under DOS,Windows and Linux. The input subsystem has always been running
asynchronously without a hitch (by the 3.0 time, I had to hook myself the
keyboard and mouse handlers), thus reproducing the real world scenario.

Allegro is a low-level library (Allegro Low-Level Game Routines), so why to
impose a model (polling) over another one (events/callbacks) ? I would
strongly argue for at least keeping Allegro agnostic on this topic, in the
same way Shawn argued to dismiss the proposal for the message-based method:
it is far easier to implement polling on top of events/callbacks than the
opposite.

To sum up a little, and to paraphrase a former British female Prime Minister
about a completely different topic: "I want my callbacks back !" ;-)

---
Eric Botcazou
ebotcazou@xxxxxxxxxx



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