Sign in to follow this  

Buffered joystick input always empty

This topic is 3483 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 am trying to change my input from immidiate to buffered. I have setuped everything according to docs, but number of read items is always 0. In my init joystick routine I have this code to set buffer size:
    // Set BUFFERSIZE.
    DIPROPDWORD dipbs;

    dipbs.diph.dwSize       = sizeof( dipdw ); 
    dipbs.diph.dwHeaderSize = sizeof( dipdw.diph ); 
    dipbs.diph.dwObj        = 0;
    dipbs.diph.dwHow        = DIPH_DEVICE;
    dipbs.dwData            = BUFFERSIZE; // Arbitary buffer size
    joystick->SetProperty( DIPROP_BUFFERSIZE, &dipbs.diph );
and then when I read input I have this code:
void buffered_joystick()
{
	int status;
	DWORD buffsize = BUFFERSIZE;
	DIDEVICEOBJECTDATA buffer[BUFFERSIZE];

	for(int i=0; i < num_joysticks; i++){
		pads[i]->Poll();
		status = pads[i]->GetDeviceData(sizeof(DIDEVICEOBJECTDATA), buffer, &buffsize,0);
		if(status == DI_BUFFEROVERFLOW)
			puts("overflow");
		if(status == DI_OK){
			puts("read ok");
			if(buffsize != 0)
				printf("number of items: %l\n",buffsize);
			for(int j = 0; j < buffsize; j++){
				// do something here ....
			}
		}
}
(this is just very simplified version to illustrate my problem). Now I do get DI_OK status all the time, but buffsize is always set to 0, which means 0 events are read. I have no problems when reading with GetDeviceState. What can be problem with buffered read?

Share this post


Link to post
Share on other sites
shiiiiit,

so lame misstake, buffer size variable has to be reset per device in for-loop :-)

DWORD buffsize = BUFFERSIZE; <-- had to be in for loop before call to GetDeviceData; I can't believe I was so blind ...

It works awesome, and it solves problem of multiple keypresses, if you remember my previous post about polling gamepad :-).

Share this post


Link to post
Share on other sites

This topic is 3483 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this