Re: [AD] event source casts |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On 2009-08-04, Elias Pschernig <elias.pschernig@xxxxxxxxxx> wrote:
> On Tue, 2009-08-04 at 11:07 +1000, Peter Wang wrote:
> > On 2009-08-03, Elias Pschernig <elias.pschernig@xxxxxxxxxx> wrote:
> > > On Tue, 2009-08-04 at 00:20 +1000, Peter Wang wrote:
> > > >
> > > > A couple of comments.
> > > >
> > > > 1. al_register_event_source(queue,
> > > > al_get_keyboard_event_source(al_get_keyboard()));
> > > >
> > > > is a bit silly since al_get_keyboard() has no other use any more.
> > > > Same with al_get_mouse().
> > >
> > > As before with the cast.
> >
> > I was thinking we'd have:
> >
> > ALLEGRO_EVENT_SOURCE *al_get_keyboard_event_source(void);
> > ALLEGRO_EVENT_SOURCE *al_get_mouse_event_source(void);
>
> Makes sense. (Support for multiple mice could be a reason to re-publish
> ALLEGRO_MOUSE at some point I guess.)
I'll let you take care of it.
> > So I still would like to guarantee that
> >
> > display == al_get_display_event_source(display);
> >
> > and so on, as we had before ALLEGRO_STREAM and user event sources came
> > along.
> >
> > The idea that I had during one of the Hack Days was, I believe, to make
> > ALLEGRO_EVENT_SOURCE a structure with a publically known size but
> > private fields. Then users can derive their own event sources in the
> > same way as the core library without the extra indirection.
> >
> > struct MY_THING {
> > ALLEGRO_EVENT_SOURCE es;
> > int my_field;
> > ...
> > };
> >
> > I came across some minor problem when implementing it at that time, but
> > really I think there should be no problem so I'll give it another go.
> >
>
> Sounds good. In my case, it will look like this though:
>
> struct MY_THING {
> MY_OBJECT super;
> ALLEGRO_EVENT_SOURCE es;
> }
>
> So the assumption about the pointer values being the same still would
> not hold - it shouldn't matter at all though, but we simply can't
> enforce it for addons or even suggest to them that it's a good idea.
Ok, I've committed my change.
In your case you can still easily get from the event source pointer to a
MY_THING pointer by subtracting the offset of the es field ;) Could be
handy.
Peter
PS. r12345