Reset mouse position inside a thread

Hey there gang,

Little experiment, I tried running the main game loop on a separate thread to see how that works as opposed to just calling it every frame from a controller on an empty or what have you. All my logic for listening to inputs and game events work fine, but this bit refuses to cooperate:

from bge.render import (getWindowWidth, getWindowHeight, setMousePosition)
def resetMousePos():
    setMousePosition(int(getWindowWidth()/2), int(getWindowHeight()/2))

Now I’m not convinced that threading in this case is good on performance – either that or I’m doing it wrong – but just out of curiosity I’d still like to know what’s going on. Anyone knows something about this?

i dont recenter each frame at all. i get the position offset between frames and recenter when the mouse gets near the screen edge.

Oh, I didn’t think it made a difference. Still need to check for mouse position plus evaluations, so leaving out a single function call seemed trivial. Is there a benefit I’m not seeing?

Anyhoo my concern is that the mouse doesn’t recenter at all. My first thoght was I should keep the thread purely python without any bge stuff in it, but since checking for keyboard inputs or mouse clicks/wheel works fine I thought maybe something else is going on.

Threading graphical things is usually a challenge because usually graphical functions require to be in the game loop to work. Try having a callback to the main thread to do stuff, or only use the thread to compute data.