Always handle unbuffered devices in the main thread.
This commit is contained in:
@@ -78,18 +78,6 @@ InputHandler_DInput::InputHandler_DInput()
|
|||||||
shutdown = false;
|
shutdown = false;
|
||||||
g_NumJoysticks = 0;
|
g_NumJoysticks = 0;
|
||||||
|
|
||||||
/* If we have any polled devices, we need to check it constantly. In WinNT,
|
|
||||||
* we have the scheduling resolution to do this. In Win9x, we don't, so always
|
|
||||||
* handle those devices uring Update(). */
|
|
||||||
{
|
|
||||||
OSVERSIONINFO ovi;
|
|
||||||
ovi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
|
||||||
GetVersionEx(&ovi);
|
|
||||||
PolledDevicesInMainThread = (ovi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS);
|
|
||||||
if( PolledDevicesInMainThread )
|
|
||||||
LOG->Info( "Polled devices are not threaded");
|
|
||||||
}
|
|
||||||
|
|
||||||
AppInstance inst;
|
AppInstance inst;
|
||||||
HRESULT hr = DirectInputCreate(/* SDL_Instance */inst.Get(), DIRECTINPUT_VERSION, &dinput, NULL);
|
HRESULT hr = DirectInputCreate(/* SDL_Instance */inst.Get(), DIRECTINPUT_VERSION, &dinput, NULL);
|
||||||
if ( hr != DI_OK )
|
if ( hr != DI_OK )
|
||||||
@@ -433,23 +421,17 @@ void InputHandler_DInput::Update(float fDeltaTime)
|
|||||||
RageTimer zero;
|
RageTimer zero;
|
||||||
zero.SetZero();
|
zero.SetZero();
|
||||||
|
|
||||||
if( InputThreadPtr == NULL )
|
/* Handle polled devices. */
|
||||||
|
PollAndAcquireDevices();
|
||||||
|
for( unsigned i = 0; i < Devices.size(); ++i )
|
||||||
{
|
{
|
||||||
/* We don't have an input thread, so handle buffered devices. */
|
if( !Devices[i].buffered )
|
||||||
PollAndAcquireDevices();
|
UpdatePolled( Devices[i], zero );
|
||||||
for( unsigned i = 0; i < Devices.size(); ++i )
|
else if( InputThreadPtr == NULL )
|
||||||
if( Devices[i].buffered )
|
{
|
||||||
UpdateBuffered( Devices[i], zero );
|
/* If we have an input thread, it'll handle buffered devices. */
|
||||||
}
|
UpdateBuffered( Devices[i], zero );
|
||||||
|
}
|
||||||
if( InputThreadPtr == NULL || PolledDevicesInMainThread )
|
|
||||||
{
|
|
||||||
/* We don't have an input thread, or polled devices are not being handled
|
|
||||||
* in the thread, so handle polled devices. */
|
|
||||||
PollAndAcquireDevices();
|
|
||||||
for( unsigned i = 0; i < Devices.size(); ++i )
|
|
||||||
if( !Devices[i].buffered )
|
|
||||||
UpdatePolled( Devices[i], zero );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
InputHandler::UpdateTimer();
|
InputHandler::UpdateTimer();
|
||||||
@@ -483,14 +465,6 @@ void InputHandler_DInput::InputThread()
|
|||||||
IDirectInputDevice2_Acquire(Devices[i].Device);
|
IDirectInputDevice2_Acquire(Devices[i].Device);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we have any polled devices, we need a fast loop. */
|
|
||||||
int Delay = (UnbufferedDevices.size() && !PolledDevicesInMainThread)? 2:50;
|
|
||||||
LOG->Info( "DirectInput thread is running at %ims", Delay );
|
|
||||||
|
|
||||||
RageTimer LoopPerformanceTimer;
|
|
||||||
int Counts[6];
|
|
||||||
memset(Counts, 0, sizeof(Counts));
|
|
||||||
RageTimer ThreadTimer;
|
|
||||||
while(!shutdown)
|
while(!shutdown)
|
||||||
{
|
{
|
||||||
VDCHECKPOINT;
|
VDCHECKPOINT;
|
||||||
@@ -499,7 +473,7 @@ void InputHandler_DInput::InputThread()
|
|||||||
/* Update buffered devices. */
|
/* Update buffered devices. */
|
||||||
PollAndAcquireDevices();
|
PollAndAcquireDevices();
|
||||||
|
|
||||||
int ret = WaitForSingleObjectEx( Handle, Delay, true );
|
int ret = WaitForSingleObjectEx( Handle, 50, true );
|
||||||
if( ret == -1 )
|
if( ret == -1 )
|
||||||
{
|
{
|
||||||
LOG->Trace( werr_ssprintf(GetLastError(), "WaitForSingleObjectEx failed") );
|
LOG->Trace( werr_ssprintf(GetLastError(), "WaitForSingleObjectEx failed") );
|
||||||
@@ -515,28 +489,10 @@ void InputHandler_DInput::InputThread()
|
|||||||
}
|
}
|
||||||
VDCHECKPOINT;
|
VDCHECKPOINT;
|
||||||
|
|
||||||
/* Check polled devices, unless we're not handling them in the thread. */
|
|
||||||
if( UnbufferedDevices.size() && !PolledDevicesInMainThread )
|
|
||||||
{
|
|
||||||
PollAndAcquireDevices();
|
|
||||||
for( i = 0; i < UnbufferedDevices.size(); ++i )
|
|
||||||
UpdatePolled( *UnbufferedDevices[i], ThreadTimer.Half() );
|
|
||||||
}
|
|
||||||
|
|
||||||
ThreadTimer.Touch();
|
|
||||||
|
|
||||||
/* If we have no buffered devices, we didn't delay at WaitForMultipleObjectsEx. */
|
/* If we have no buffered devices, we didn't delay at WaitForMultipleObjectsEx. */
|
||||||
if( BufferedDevices.size() == 0 )
|
if( BufferedDevices.size() == 0 )
|
||||||
SDL_Delay( Delay );
|
SDL_Delay( 50 );
|
||||||
VDCHECKPOINT;
|
VDCHECKPOINT;
|
||||||
|
|
||||||
float time = LoopPerformanceTimer.GetDeltaTime();
|
|
||||||
if(time < 0.002f) ++Counts[0];
|
|
||||||
else if(time < 0.005f) ++Counts[1];
|
|
||||||
else if(time < 0.010f) ++Counts[2];
|
|
||||||
else if(time < 0.025f) ++Counts[3];
|
|
||||||
else if(time < 0.050f) ++Counts[4];
|
|
||||||
else ++Counts[5];
|
|
||||||
}
|
}
|
||||||
VDCHECKPOINT;
|
VDCHECKPOINT;
|
||||||
|
|
||||||
@@ -550,11 +506,6 @@ void InputHandler_DInput::InputThread()
|
|||||||
}
|
}
|
||||||
|
|
||||||
CloseHandle(Handle);
|
CloseHandle(Handle);
|
||||||
|
|
||||||
/* If we're running in "slow loop" mode--that is, all devices are buffered--it's
|
|
||||||
* normal for most loops to take 50ms. */
|
|
||||||
LOG->Info("DirectInput thread performance: %i %i %i %i %i %i",
|
|
||||||
Counts[0], Counts[1], Counts[2], Counts[3], Counts[4], Counts[5]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputHandler_DInput::GetDevicesAndDescriptions(vector<InputDevice>& vDevicesOut, vector<CString>& vDescriptionsOut)
|
void InputHandler_DInput::GetDevicesAndDescriptions(vector<InputDevice>& vDevicesOut, vector<CString>& vDescriptionsOut)
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ class InputHandler_DInput: public InputHandler
|
|||||||
{
|
{
|
||||||
SDL_Thread *InputThreadPtr;
|
SDL_Thread *InputThreadPtr;
|
||||||
bool shutdown;
|
bool shutdown;
|
||||||
bool PolledDevicesInMainThread;
|
|
||||||
|
|
||||||
void UpdatePolled(DIDevice &device, const RageTimer &tm);
|
void UpdatePolled(DIDevice &device, const RageTimer &tm);
|
||||||
void UpdateBuffered(DIDevice &device, const RageTimer &tm);
|
void UpdateBuffered(DIDevice &device, const RageTimer &tm);
|
||||||
|
|||||||
Reference in New Issue
Block a user