DirectInput, threads, and Irrlicht

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
ASchepis

DirectInput, threads, and Irrlicht

Post by ASchepis »

A while back i wrote a fast input library using direct input for a game engine i was working on. It has great support for keyboard, mouse, and joysticks so i want to use it with Irrlicht. I got this working correctly, but the problem is that the input is polled as part of the main game loop (i.e while device->run() loop). This means that the responsivity of my input depends on the # of frames per second i can push.

As you can imagine, testing this on a very slow machine caused dreadful input responsviity because i wasn't drawing more than 10 or 15 frames per second. Thus, i created a new thread to continuously poll the input and update the game data so it could then be represented in the frames later.

Doing this was fine, except it caused access violations (i think because i was accessing sceneNode positions while Irrlicht was attempting to do something with them). Does anyone know how i can resolve this issue? I would love to have fast, responsive input that isn't dependant on frames per second.
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post by thesmileman »

Yes, you will have to use a semaphore or a mutex(a simple semaphore) during the critical sections(places where exclusive access is important). If you are not familer with semaphores google them. There should be some good informaiton on the web about them.

I would normally give you more information but I am busy as hell.
ASchepis
Posts: 2
Joined: Fri Apr 02, 2004 10:11 pm
Location: Boston, MA

Post by ASchepis »

Thanks for the help, i actually got something working that seems not to crash it by moving the new thread into the class that is accessing it and having the threadfunc be a "friend" function. however, i did come across semaphores and, since you suggested it, plan to try it out.
Post Reply