[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Wii Remote support -- first patch



Dave LeCompte (really) wrote:
René Dudfield <renesd@xxxxxxxxx> suggested:

For pygame integration posting events into the event queue would be a
good idea ( pygame.event.post ). Maybe run in another thread, or
polled at the required frequency with pygame.time.set_timer ?

I'd suggest not creating another thread if we don't absolutely need to.
Does anyone know how the mouse works in Pygame? how is it polled?
I'd think the wiimote should be done in a similar manner.

Depending on what mode you have the wiimote in, it either reports a result whenever a button is pressed/released (buttons-only mode)
or it reports continuously (when in accel+buttons, or accel+buttons+IR).
so button-only mode is more similar to how mouse reporting happens in Pygame (only when the state changes.)
Would it be possible to query the result of the overlapped IO as part of
the pygame.event.pump / pygame.event.get calls?
Yes, I believe so.
The game is going to be
calling those already.

Some reasons why that might not work:

- I recall reading in the code that some of the accelerometer calculations
work best if the device is polled with inconsistent frequency. I don't
know how big a problem that is in practice.
We'll see, I guess. It makes sense that a consistent frequency would be ideal, but from what I can tell,
the Wii remote issues reports only when it wants to, and the read will just block if it has nothing to report.
(well, unless you tell it not to block, but my point is that the wii mote doesn't just constantly stream data)
Does this mean that it would work the other way, and cache output until you read it in? I'm not sure.
The bluetooth adapter driver code could do that for you (I doubt the wii mote would cache output)


so couldn't you theoretically read all outputs that occurred since your last frame every time you get a chance to read?
I bet the wiimote reports at a consistent frequency either way, when in accelerometer mode.
- The bluetooth library code might want to be called more frequently than
once per (graphics) frame.
I don't know why it would care... my code has nothing to do with bluetooth. As far as it's concerned, the Wiimotes could be USB HID devices.

I haven't dug around very much inside the code, so I don't know how it looks in there, but it seems like the pygame.event.pump code is already doing periodic input work,
Are you assuming that the user calls pump, or does pygame have some internal thread that consistently calls pump?
or does pygame.event.get call pump as well?
how does all that jazz work?
-Luke