Threading for WiiMote information

Heya,

We are some students working on a python/panda3D game.
We thought it would be awesomez to use the wiimote as inpute device.

After a while we finally found a way to read out the wii data. But we are stuck if we try to combine it with the game.

So, we think the best option will be threading.
In that case, we will need 2 threads: 1 for the reading of wiidata, and 1 for the game.

The only line that’s needed for reading WiiData is pretty much the following: messages = wiimote.get_mesg()

If I try to put this in a while loop, but the game keeps freezing because it gets stuck in the loop.

So how do we fix a while loop, that runs next to the game?

Thanks in advance

Forgot to add: we work with python.

if you use python, please post on the regular scripting issue board (not the c++ section).

have you tried to set up a task which calls your getmessage() each frame?
http://www.panda3d.org/manual/index.php/Tasks

mtk_group fellas, have you already rummaged through these forums what others made before? I found this project quite interesting, maybe you’ll find there something of your interest as well.

Threading in Python with Panda is a bit problematic. Assuming the get_mesg() call isn’t likely to block for many milliseconds at a time, you can use threading, but you have to (a) use the direct.stdpy.threading module instead of Python’s threading module, and (b) call Thread.considerYield() within your while loop to allow other threads to run.

However, if it is true that get_mesg() isn’t likely to block for a long time, then Thomas’ suggestion is better: just use a task, instead of threading. It’s just better.

On the other hand, if get_mesg() might block for a long time, you have a problem. Neither Panda (in its default configuration) nor Python (in any configuration) support true multiprocessing, so your blocking call may block all of your Python threads. You’d have to wrap this call within a C++ block that either spawned and completely managed the thread itself, or that at least managed the Python GIL while the get_mesg() call was made.

David

yet another possibility is to set up 2 python applications communicating with each other using sockets. i successfully used that technique while doing facetracking in combination with panda. both python apps are handled independently by the OS. it’s a bit of a dirty heck but worked for me.