[OLPC-Games] pygame.USEREVENT for events instead of top-level event-types
Mike C. Fletcher
mcfletch at vrplumber.com
Fri Feb 22 12:01:32 EST 2008
The following ticket:
http://dev.laptop.org/ticket/6550
describes a plan for fixing a minor problem we currently face with
OLPCGames, namely that the original design used individual top-level
Pygame events for each of the events we send. On some platforms we are
seeing the officially blessed user-definable event type range (between
USEREVENT (24) and NUMEVENTS (32)) exhausted and we still have more
event-types to add (I just added two more today for the file-read and
file-write events).
I'll be providing a flag that can be set to provide backward-compatible
events for a given activity. When the changes land (probably in 2.0)
you will need to use the flag to have your older code work as before
while you convert to the new event style.
The conversion will be fairly mechanical, replacing:
if event.type == olpcgames.SOMENAME
with
if event.type == pygame.USEREVENT and event.code == olpcgames.SOMENAME
or more likely, given that OLPCGames events tend to be processed together:
if event.type == pygame.USEREVENT:
if event.code == olpcgames.SOMENAME:
elif event.code == olpcgames.SOMEOTHERNAME:
We may, instead, define a single top-level event-type (e.g.
OLPCGAME_EVENT) and use that instead of USEREVENT.
I actually prefer the top-level event-type API, but at the moment it
looks like we are not going to be able to extend it to cover all the
events we will want to produce, and I'd rather have all of our events
use a consistent API. If people have a better suggestion to solve the
problem, please feel free to chime in (keeping in mind that while
reworking Pygame to add more space for events might be a long-term
solution, we aren't going to have a chance to update the Pygame on the
initial release laptops any time soon).
Have fun,
Mike
More information about the Games
mailing list