From 445df4ea85f46e564d659f7753367fea07572665 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 28 Dec 2005 19:02:50 +0000 Subject: [PATCH] Don't poll and acquire the same device in both the input thread and Update. --- .../arch/InputHandler/InputHandler_DirectInput.cpp | 14 ++++++++++---- .../arch/InputHandler/InputHandler_DirectInput.h | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/stepmania/src/arch/InputHandler/InputHandler_DirectInput.cpp b/stepmania/src/arch/InputHandler/InputHandler_DirectInput.cpp index 6eef5dd1ae..34b10de2f2 100644 --- a/stepmania/src/arch/InputHandler/InputHandler_DirectInput.cpp +++ b/stepmania/src/arch/InputHandler/InputHandler_DirectInput.cpp @@ -426,10 +426,13 @@ void InputHandler_DInput::UpdateBuffered(DIDevice &device, const RageTimer &tm) } -void InputHandler_DInput::PollAndAcquireDevices() +void InputHandler_DInput::PollAndAcquireDevices( bool bBuffered ) { for( unsigned i = 0; i < Devices.size(); ++i ) { + if( Devices[i].buffered != bBuffered ) + continue; + HRESULT hr = IDirectInputDevice2_Poll( Devices[i].Device ); if ( hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED ) { @@ -449,8 +452,11 @@ void InputHandler_DInput::Update() RageTimer zero; zero.SetZero(); - /* Handle polled devices. */ - PollAndAcquireDevices(); + /* Handle polled devices. Handle buffered, too, if there's no input thread to do it. */ + PollAndAcquireDevices( false ); + if( !m_Thread.IsCreated() ) + PollAndAcquireDevices( true ); + for( unsigned i = 0; i < Devices.size(); ++i ) { if( !Devices[i].buffered ) @@ -504,7 +510,7 @@ void InputHandler_DInput::InputThreadMain() if( BufferedDevices.size() ) { /* Update buffered devices. */ - PollAndAcquireDevices(); + PollAndAcquireDevices( true ); int ret = WaitForSingleObjectEx( Handle, 50, true ); if( ret == -1 ) diff --git a/stepmania/src/arch/InputHandler/InputHandler_DirectInput.h b/stepmania/src/arch/InputHandler/InputHandler_DirectInput.h index faa036260d..1331f2d506 100644 --- a/stepmania/src/arch/InputHandler/InputHandler_DirectInput.h +++ b/stepmania/src/arch/InputHandler/InputHandler_DirectInput.h @@ -22,7 +22,7 @@ private: void UpdatePolled( DIDevice &device, const RageTimer &tm ); void UpdateBuffered( DIDevice &device, const RageTimer &tm ); - void PollAndAcquireDevices(); + void PollAndAcquireDevices( bool bBuffered ); static int InputThread_Start( void *p ) { ((InputHandler_DInput *) p)->InputThreadMain(); return 0; } void InputThreadMain();