[A5] user event type constant 1024
axilmar

I read in the docs that the minimum user event type value is 1024. Shouldn't this value be a constant?

Thomas Fjellstrom

Not really, the idea is that you're supposed to use ALLEGRO_GET_EVENT_TYPE to create an event id. It supposedly should keep down on collisions.

Trent Gamblin

That, and you can add to it: AL_GET_EVENT_TYPE(...) + 1 etc for other events. Instead of trying to create a unique 4 letter word for each event.

axilmar

Thanks. Are 4 characters enough, I wonder? perhaps the event type should be 8 characters to minimize collisions?

Trent Gamblin

4 characters (they can be any number 0-255) gives you about 2-4 billion event types :P.

X-G

Well, given that they are characters one's mind tends to gravitate towards printable characters (as in the example!), of which there are only about 60 that are likely to be used (some 12 million combinations). Among those, though, certain combinations are much more likely to collide than others.

Trent Gamblin

Possibly, but what can you do about it? 8 characters is excessive IMO. If you use 5 addons that use events, that's 5 (or should be) "strings". If addons use their name for their event type (Super Fantastic Physics Library uses SFPL) then it's not really likely you'll get collisions... but not impossible. Not much you can do about it.

X-G

You can generate IDs dynamically on program startup, and not take any arguments at all. It hardly matters exactly what the identifier is anyway, does it?

Elias
X-G said:

You can generate IDs dynamically on program startup, and not take any arguments at all. It hardly matters exactly what the identifier is anyway, does it?

Would be very easy to do of course - I think the only argument against it was that you can't use switch/case any longer. Personally I would prefer dynamic ids as well though, even if there is no danger of collision in practice. E.g. if two GUI addons use event ids of (AL_GET_EVENT_TYPE('A', 'G', 'U', 'I') + n) with (n in 0..1000) then you likely would still never use both addons at the same time.

However, it just would feel much cleaner to prevent collisions in the first place.

SiegeLord

Just have an official system to request id blocks. We could call it AANA.

X-G

Coincidentally, given that ALLEGRO_GET_EVENT_TYPE is (I assume) meant to be opaque, how exactly are you supposed to ensure that the resulting ID is not within Allegro's reserved range?

Trent Gamblin

I was asking about this constant before (1024 are reserved by allegro) but for different reasons. Maybe it would be good after all though.

Peter Wang

People should just be more creative with their base event id (not restricted to printable characters, btw).

Ron Novy

SiegeLord, why AANA?

Matthew Leverton
Ron Novy

Ahh... Now it makes sense.

Thread #606364. Printed from Allegro.cc