Skip to main content
GameDev.net gamedev.net
🔒 Locked

poll/Acquire question

Started by carbon14 Aug 10, 2002 at 5:44 PM 4 replies 450+ views
Original Post
carbon14
carbon14
hi after i set up the joystick: do i need to do the following durin every frame? ddrval= g_pJoyStick->Poll(); g_pJoyStick->GetDeviceState(sizeof(stick), &stick); ddrval= g_pJoyStick->Acquire(); thanks
lonnie
lonnie
No - Just Acquire one Time, then call GetDeviceState every time you need.
I don''t know what Poll really does, in my app it had no effect!
SDyer
SDyer
I just implemented the joystick in my program. I used the SDK''s DirectInput Joystick sample to start with. The Poll method they implement never actually calls a "Poll" method on the joystick device itself - I don''t think there is a Poll method for that device (I think Poll is only for the mouse).

Here''s my Poll method, taken pretty much right from that sample:


HRESULT CJoystick:oll()
{
// If device not initialized, just return false
if(!m_bInitialized)
{
return E_FAIL;
}

// Attempt to get state of Joystick
HRESULT r = 0;

r = g_pJoystickDev->GetDeviceState(sizeof(DIJOYSTATE2), &m_JoystickData);
if(FAILED(r))
{
// If failed due to device not being acquired, reqcquire it.
// Otherwise, some other error so just return false.
if(r == DIERR_INPUTLOST)
{
// Attempt to acquire the device
r = g_pJoystickDev->Acquire();

// If succeeded, get device state. Otherwise, just return false
if(SUCCEEDED(r))
{
g_pJoystickDev->GetDeviceState(sizeof(DIJOYSTATE2), &m_JoystickData);
}
else
{
GWriteToLog("IsKeyDown FALSE - get state failed twice");
return E_FAIL;
}
}
else
{
GWriteToLog("CJoystick:oll - get state failed first time, not due to input lost");
return E_FAIL;
}
}

return S_OK;
}

It just makes sure the device is properly configured and acquired, then gets the data from it.
SDyer
SDyer
How funny - it replaced the characters ": P" in my reply with a smiley. Cute.
Marsc
Marsc
quote:
Original post by lonnie
No - Just Acquire one Time, then call GetDeviceState every time you need.
I don''t know what Poll really does, in my app it had no effect!


Be aware about this... It had no effect in your app, that is runing in your computer, but could have effect in your app if you run in another computer with another joystick.

Most joysticks dont need to be polled because they do an interruption when the users acts on it, but is not this ways this in all cases.
Poll method of course polls the Joy, and then you can get its state.
Is o good policy to use Poll method before GetDeviceState.




JoeyBlow2
JoeyBlow2
The SDK says if you Poll and the device does not need a Poll, the function does nothing... They suggest you Poll all the time, in case there is someone with an old device (analog joystick for example, digitals dont need a Poll)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.