Re: [AD] user-defined events

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


On Fri, 2008-09-26 at 19:28 -0600, Thomas Fjellstrom wrote:
> >
> > > +typedef struct ALLEGRO_USER_EVENT
> > > +{
> > > +   _AL_EVENT_HEADER(struct ALLEGRO_EVENT_SOURCE);
> > > +   void *data1;
> > > +   void *data2;
> > > +   void *data3;
> > > +   void *data4;
> > > +} ALLEGRO_USER_EVENT;
> >
> > I know I said providing the user with one pointer would be fine, so I
> > can't reasonably complain when you give them 4, but I do think the
> > common case might be that you want one or two integers to pass
> > informmation along. Maybe we can have two of those as well?
> 
> Or clone some of the extra variables that the old GUI code passes along.
> 

No matter how many fields are added though, it never will be nice. How
well would using just a single void *data work instead?

It would be allocated whenever an event is emitted - but would it be
clear to users where to free it? For example, what if the event is never
received, or what if to event queues are receiving the events?

I think we should make sure the above works, if it does not right now.
It's the only way I can see this useful - if necessary, we might have to
provide a callback pointer with a "cleanup_user_event" method which is
passed the event when it goes out of servrice or something, so user code
can free the data poiner there. (But maybe that's already working..
didn't look too close yet and the example apparently just casts an int
to a pointer.)

In any case, a single "void *data" would be enough if the above works,
and then instead of the other 3 pointers I also think two integers might
be better to cover a few common default cases - but we could tell users
that the best practice is to allocate their own custom data structure if
they (ab-)use the events system too much.

-- 
Elias Pschernig <elias@xxxxxxxxxx>





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