Brief ? on Direct Input
With immediate data I get the current state of all the keys AT the time of the call.
But with buffered data what exactly is happening? Say every frame I get the data. Is that ALL of the data that has been entered over the last frame? So if I press down ALT+SHIFT+E+R then the data would contain press messages for all 4 of those? Then I release all 4 and that data would be sent as well?
I think I understand how it works but not exactly sure I am correct. Based on this, as long as the user isn''t fast enough (or my app slow enough) to press a key up and down multiple times a frame then I will get all the keypresses correct?
Also, the buffer size. How large should it be? Do I need it large enough to hold one state for every possible key? Or just large enough to hold the maximum amount of input the game would allow (ALT+CTRL+SHIFT+LETTER) or whatever.
Finally, for mouse movement, how is this buffered? It''s polled once per frame so if it''s moving then the buffered data will show mouse_move_on_axis? Or is the movement accumulated in some different manner?
Thanks for any clarification,
Webby
Could someone look at this and see if there is a problem?
Everything prefixed with m_ is a private member of the class
wrapping this input.
In the above switch statement case DIMOFS_X: will always trigger
its MessageBox 16 times a frame every frame (16 is the size of my data buffer).
However, I comment it out and the program runs fine except that no mouse clicks seem to be gettign registered. Neither of the other two message boxes are firing...
Thanks for taking a look,
Webby
Everything prefixed with m_ is a private member of the class
wrapping this input.
lpdi->CreateDevice(GUID_SysMouse, &m_mouse, NULL);m_mouse->SetDataFormat(&c_dfDIMouse2);m_mouse->SetCooperativeLevel(g_cApp.GethWnd(), DISCL_BACKGROUND |DISCL_NONEXCLUSIVE);m_mouse->Acquire();GetMouseMappingFromFile(); // the headerm_dipdw.diph.dwSize = sizeof(DIPROPDWORD);m_dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);m_dipdw.diph.dwObj = 0;m_dipdw.diph.dwHow = DIPH_DEVICE;// the datam_dipdw.dwData = 16;m_mouse->SetProperty(DIPROP_BUFFERSIZE, &m_dipdw.diph);
void cInputManager::ReadMouseBuffered(){HRESULT hr;m_dwElements = 16;if(!m_mouse){ //We don''t have a mouse object return;}// query DirectInput for newest mouse data hr = m_mouse->GetDeviceData(sizeof(m_od[0]), m_od, &m_dwElements, 0); if (FAILED(hr)) { while (hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED) { // device lost... reacquire hr = m_mouse->Acquire(); } } //If some mouse input has occurredif (m_dwElements != 0) { /* View the element to see what occurred */ for(int i=0; i<16; i++) { switch (m_od[i].dwOfs) { // Mouse horizontal motion case DIMOFS_X: m_relPosition.x = m_od[i].dwData; m_absPosition.x += m_od[i].dwData; char text[20]; _itoa(m_absPosition.x, text, 10); //MessageBox(g_cApp.GethWnd(), "MOUSE", text, MB_OK); break; // Mouse vertical motion case DIMOFS_Y: m_relPosition.y = m_od[i].dwData; m_absPosition.y += m_od[i].dwData; break; // Mouse distance motion case DIMOFS_Z: m_relPosition.z = m_od[i].dwData; m_absPosition.z += m_od[i].dwData; break; // DIMOFS_BUTTON0: Right button pressed case DIMOFS_BUTTON0: m_iLeftButton = m_od[i].dwData; MessageBox(g_cApp.GethWnd(),"MOUSE", "RIGHT_CLICK",MB_OK); break; // DIMOFS_BUTTON1: Left button pressed case DIMOFS_BUTTON1: m_iRightButton = m_od[i].dwData; break; // DIMOFS_BUTTON2: Middle button case DIMOFS_BUTTON2: m_iMiddleButton = m_od[i].dwData; break; case DIMOFS_BUTTON3: case DIMOFS_BUTTON4: case DIMOFS_BUTTON5: case DIMOFS_BUTTON6: case DIMOFS_BUTTON7: MessageBox(g_cApp.GethWnd(), "SOME BUTTON", "SOME BUTTON", MB_OK); break; } }}}
In the above switch statement case DIMOFS_X: will always trigger
its MessageBox 16 times a frame every frame (16 is the size of my data buffer).
However, I comment it out and the program runs fine except that no mouse clicks seem to be gettign registered. Neither of the other two message boxes are firing...
Thanks for taking a look,
Webby
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement