Wrecked Games

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're just that awesome.

Author Topic: Accessing OIS from another thread stops shift from working  (Read 612 times)

AshMcConnell

  • Regular
  • *
  • Karma: +0/-0
  • Posts: 21
    • View Profile
    • Online Racing Championship
Accessing OIS from another thread stops shift from working
« on: January 05, 2011, 01:11:57 AM »

Hi Folks,

I have 1 main thread and a physics thread that executes for a frame then is joined with the main thread, sync is then done and we start a new frame.

On that physics thread I call the OIS capture methods for Mouse / Keyboard and Controllers.  I handle all the events on this thread and store them in a vector.  In the sync process I go through these events and call callbacks for keyboard and mouse handlers.

Originally I called the OIS capture events from the main thread, this worked as expected (there were issues at low FPS though, hence the move to the other thread). 

When I changed to the other thread, even when I didn't queue the events, shift wouldn't work (e.g. all letters in lower case & shift+1 displayed 1).

Any ideas what I could be doing wrong?
Thanks for your help
All the best,
Ash

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +1/-0
  • Posts: 2661
    • View Profile
    • http://www.wreckedgames.com
Re: Accessing OIS from another thread stops shift from working
« Reply #1 on: January 05, 2011, 08:43:24 PM »

OIS must be called from within the GUI thread for things to generally work correctly, especially with shift/localization handling.
Logged

AshMcConnell

  • Regular
  • *
  • Karma: +0/-0
  • Posts: 21
    • View Profile
    • Online Racing Championship
Re: Accessing OIS from another thread stops shift from working
« Reply #2 on: January 06, 2011, 12:37:50 AM »

Hi pjcast,

Any ideas why it needs to be on the same thread?  Perhaps I could do something to get round the problem?  I thought that queuing the events up on the physics thread then "replaying" them on the main thread (with the GUI) would be the same thing as receiving them "fresh" from the main thread?

Thanks for your help and an awesome lib!
All the best,
Ash

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +1/-0
  • Posts: 2661
    • View Profile
    • http://www.wreckedgames.com
Re: Accessing OIS from another thread stops shift from working
« Reply #3 on: January 06, 2011, 08:09:06 PM »

For the text translations, it involves the windows message loop... in a not quite so obvious way (but it is pretty much why you have to pass in a HWND) - and if you do not translate/dispatch your message loop, things act weird or do not work at all. The windows message loop is only safe for one thread to operate on... mainly, the thread that created it.

What low FPS problem are you running into that is making you want to move your input thread?
Logged

AshMcConnell

  • Regular
  • *
  • Karma: +0/-0
  • Posts: 21
    • View Profile
    • Online Racing Championship
Re: Accessing OIS from another thread stops shift from working
« Reply #4 on: January 07, 2011, 12:09:27 AM »

Hi pjcast,

Thanks for your reply, that makes sense.  The low FPS problem is that the tester was seeing visible lag on the steering wheel as he was turning quickly, to the extent that he was turning left and right quickly and it was getting out of sequence.

Previously in the main loop i'm updating OIS every x ms and after everything is done I render one frame.  As the framerate goes down the size of time taken to render a frame goes up,  I was hoping to put the input update on another thread so that it would be more smooth.  I'm not sure if that will fix the lagged input problem, but I thought it might help with smoothness.

I moved the joystick updates into the other thread and left the keyboard and mouse updates on the main thread and it appears to work without trouble.  I haven't got my tester to verify if it has made any impact on him yet.  I'd guess it might just affect smoothness rather than lag.

All the best,
Ash