Hi DR0ID,

thanks for your response, and for reviving this.

On Sat, Dec 22, 2018 at 10:34 AM DR0ID <dr...@bluewin.ch> wrote:

> This is a bit cumbersome to use (since I don't know why pygame.NUMEVENTS
> is limited to 32) but will work.
>

NUMEVENTS limited to 32 is because of a SDL1 limitation. We can't raise
that limit directly.

However, it is possible to change things underneath (inside the pygame
functions).
See https://github.com/pygame/pygame/issues/477#issuecomment-407551211

This is what the new API would look like:

ZOG_UP = pg.event.custom_type()ZOG_DOWN = pg.event.custom_type()
pg.event.post(pg.Event(ZOG_DOWN, msg='hello'))
for e in pg.event.get():
    if e.type == ZOG_UP:
        print('zog goes up!')


Now... what would happen underneath (inside the pygame functions) is that
on SDL1...

   - One custom type would be allocated from the 32 to pygame custom types.

CUSTOM_TYPE = pygame.USEREVENT


   - pygame.USEREVENT would be set to pygame.USEREVENT + 1 (so CUSTOM_TYPE
   is not used by other things).
   - When the python object is created, the SDL structure would use
   CUSTOM_TYPE. however event.type would be the custom type (eg. 'ZOG_UP').
   - pygame.event.post() would first translate this ZOG_UP to use
   CUSTOM_TYPE in the SDL structure.
   - pygame.event.get() and pygame.event.wait() would return an event with
   the type translated from the CUSTOM_TYPE (as used in the internal SDL
   structure) to the custom type (eg. e.type == ZOG_UP).


Does this all make sense?

These problems are solved by this:

   - no way to coordinate custom events between libraries.  Now
   pg.event.custom_type() would be used.
   - the number of custom events is too small. Now pygame would handle this
   translation at the C level.


But there is a strange thing: using mixer.music, mixer.Channel or
> pygame.time.set_timer() objects. They provide an set_endevent() method, but
> only can take an integer (which is almost useless with the NUMEVENTS
> limit). I would have expected to be able to set a custom event there too
> because that would solve it the same way as with normal events.
>
Yeah, it would be nice if these accepted events rather than event ids.

Can you please give some examples of how using these APIs would look taking
events?

Especially when using a timer you normally want many timers bound to
> different ids. If pygame would provide that built-in this would really be
> good (hmm, maybe there should be an additional module for this like for
> sprites).
>

Would you please be able to explain this some more?


cheers,

Reply via email to