Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Faff_Master

DirectInput: How do make my game more responsive?

This topic is 6940 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

Hi, I''m just putting the finishing touches to a Tetris clone written in C++ and uses DirectX 7.0. I''m using DirectInput to get a snapshot of the keybard state every frame. The controls are fairly responsive but if you tap a key quickly it won''t respond. Where about should I read the keyboard? Should be in the main game loop, in the message handler, I don''t know. Originally I was using the message handler to process keypresses. It handled quick keypresses but it was no good in 2 player mode. Any help would be appreciated? Regards, Faff_Master...

Share this post


Link to post
Share on other sites
Advertisement
If you just read the keyboard state unbuffered, you are going to run into this problem no matter when you read the keyboard. Reading the state, of course, just tells you what the state is at that one moment in time when you actually call GetDeviceState (I assume that''s how you''re doing it?)

In most cases, you should use buffered data. Look into IDirectInputDevice7::GetDeviceData instead of IDirectInputDevice7::GetDeviceState. You''ll also have to set the buffer size first using IDirectInputDevice7::SetProperty. Look into the DX7 help files for exact usage information.

Share this post


Link to post
Share on other sites
Yeah, I''m currently reading the keyboard in immediate mode. Buffered mode is the general feed back I have been getting. Should the buffer be any particular size? How do I avoid processing multiple keypresses when I just want to process one keypress?

Share this post


Link to post
Share on other sites
I'm not sure what your basic input processing strategy is, so I'm not sure exactly how large your buffer should be. I suggest you integrate some buffered-read code into your input handling system and then play around with the buffer size. Of course, keep in mind that depending upon how the timing of your game works and how often it reads and flushes the buffered data... other users of your software may buffer overflow before you do when using the same buffer-size, so its better to go with a slightly larger buffer than would be needed in most circumstances.

Also take a look at the structure documentation for DIDEVICEOBJECTDATA (which are what you get back from GetDeviceData). Each entry has a sequence number and a time stamp, either of which could be used to determine which buffered data should be processed or not based on some rules you have decided upon. Again... I'm not sure exactly how you want your input to work, but you could use this information to determine that the user has pressed KEY1 after KEY2, and thus the press on KEY2 should be ignored because its obsolete for whatever reason.




Edited by - gmcbay on 4/21/00 5:27:36 PM

Share this post


Link to post
Share on other sites
Thanks,

I''m now reading the keyboard in buffered mode and setting bytes in my keyboard state array to pressed. The game is now much more responsive, even to really short keypresses.

I''ve used a buffer size of 32. However, it is possible for a player to mash down a load keys and the other player loses control.

I''m happy with it now so I''m just going to leave it!!!

Cheers,

Faff_Master...

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!