Jump to content
  • Advertisement
Sign in to follow this  
soarsky

Where should I put DirectInput part?

This topic is 5059 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to deal with my main procedure and refresh the graphics per 33ms. For that, I should handle the input per 33ms. So I'm afraid I will lose a lot of input information. The following is pseudo. while (true) { GetInput(); //directinput GameMain(); //handle units and display ...... while ((GetTickCount()-startTime) < 33); ...... } Where should I put the DirectInput part?

Share this post


Link to post
Share on other sites
Advertisement
It's ok there. Just don't do a wait loop like that. Ever. Even a Sleep would be better.

Just at the position where you call the render stuff, put an "if" before. If enough time elapsed, call the rendering, otherwise only update input.

Why i said don't do a loop like that:

That loop as you wrote it would make the cpu loop and take all the processing power it can get to do nothing in that loop. A Sleep would be preferred, as it tells windows to give other processes a time slice to work on.

Share this post


Link to post
Share on other sites
while (true)
{
GetInput(); //directinput

if (GetTickCount()-startTime) > 33)
GameMain(); //handle units and display
else
sleep(10);
}

As Endurion said, moving the test up would be beneficial. You could change the sleep value. I don't know how accurate it will be. Also, if you are worried about losing input data, use keyboard buffering with DirectInput instead of keyboard state. It will tell you the keys that were pressed since the last time you called GetDeviceData().

Chris

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!