Shut down the input thread when resetting the window.
This commit is contained in:
@@ -95,7 +95,7 @@ InputHandler_DInput::InputHandler_DInput()
|
|||||||
unsigned i;
|
unsigned i;
|
||||||
for( i = 0; i < Devices.size(); ++i )
|
for( i = 0; i < Devices.size(); ++i )
|
||||||
{
|
{
|
||||||
if( OpenDevice( Devices[i] ) )
|
if( Devices[i].Open() )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Devices.erase( Devices.begin() + i );
|
Devices.erase( Devices.begin() + i );
|
||||||
@@ -115,30 +115,35 @@ InputHandler_DInput::InputHandler_DInput()
|
|||||||
Devices[i].buffered? "buffered": "unbuffered" );
|
Devices[i].buffered? "buffered": "unbuffered" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StartThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
void InputHandler_DInput::StartThread()
|
||||||
|
{
|
||||||
|
ASSERT( InputThreadPtr == NULL );
|
||||||
if( PREFSMAN->m_bThreadedInput )
|
if( PREFSMAN->m_bThreadedInput )
|
||||||
InputThreadPtr = SDL_CreateThread(InputThread_Start, this);
|
InputThreadPtr = SDL_CreateThread(InputThread_Start, this);
|
||||||
else
|
else
|
||||||
InputThreadPtr = NULL;
|
InputThreadPtr = NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InputHandler_DInput::ShutdownThread()
|
||||||
/* device.JoystickInst and device.dev must be filled in. Opens the device and
|
|
||||||
* fills in the remaining parameters. */
|
|
||||||
bool InputHandler_DInput::OpenDevice(DIDevice &device)
|
|
||||||
{
|
{
|
||||||
return device.Open();
|
if( InputThreadPtr == NULL )
|
||||||
}
|
return;
|
||||||
|
|
||||||
|
shutdown = true;
|
||||||
|
LOG->Trace("Shutting down DirectInput thread ...");
|
||||||
|
SDL_WaitThread(InputThreadPtr, NULL);
|
||||||
|
InputThreadPtr = NULL;
|
||||||
|
LOG->Trace("DirectInput thread shut down.");
|
||||||
|
shutdown = false;
|
||||||
|
}
|
||||||
|
|
||||||
InputHandler_DInput::~InputHandler_DInput()
|
InputHandler_DInput::~InputHandler_DInput()
|
||||||
{
|
{
|
||||||
if( InputThreadPtr )
|
ShutdownThread();
|
||||||
{
|
|
||||||
shutdown = true;
|
|
||||||
LOG->Trace("Shutting down DirectInput thread ...");
|
|
||||||
SDL_WaitThread(InputThreadPtr, NULL);
|
|
||||||
LOG->Trace("DirectInput thread shut down.");
|
|
||||||
}
|
|
||||||
|
|
||||||
for( unsigned i = 0; i < Devices.size(); ++i )
|
for( unsigned i = 0; i < Devices.size(); ++i )
|
||||||
Devices[i].Close();
|
Devices[i].Close();
|
||||||
@@ -151,6 +156,8 @@ InputHandler_DInput::~InputHandler_DInput()
|
|||||||
void InputHandler_DInput::WindowReset()
|
void InputHandler_DInput::WindowReset()
|
||||||
{
|
{
|
||||||
/* We need to reopen keyboards. */
|
/* We need to reopen keyboards. */
|
||||||
|
ShutdownThread();
|
||||||
|
|
||||||
for( unsigned i = 0; i < Devices.size(); ++i )
|
for( unsigned i = 0; i < Devices.size(); ++i )
|
||||||
{
|
{
|
||||||
if( Devices[i].type != Devices[i].KEYBOARD )
|
if( Devices[i].type != Devices[i].KEYBOARD )
|
||||||
@@ -166,6 +173,8 @@ void InputHandler_DInput::WindowReset()
|
|||||||
/* Reopening it should succeed. */
|
/* Reopening it should succeed. */
|
||||||
ASSERT( ret );
|
ASSERT( ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StartThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int TranslatePOV(DWORD value)
|
static int TranslatePOV(DWORD value)
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ class InputHandler_DInput: public InputHandler
|
|||||||
SDL_Thread *InputThreadPtr;
|
SDL_Thread *InputThreadPtr;
|
||||||
bool shutdown;
|
bool shutdown;
|
||||||
|
|
||||||
bool OpenDevice(DIDevice &joystick);
|
|
||||||
void UpdatePolled(DIDevice &device);
|
void UpdatePolled(DIDevice &device);
|
||||||
void UpdateBuffered(DIDevice &device, const RageTimer &tm);
|
void UpdateBuffered(DIDevice &device, const RageTimer &tm);
|
||||||
void PollAndAcquireDevices();
|
void PollAndAcquireDevices();
|
||||||
@@ -18,6 +17,9 @@ class InputHandler_DInput: public InputHandler
|
|||||||
static int InputThread_Start( void *p ) { ((InputHandler_DInput *) p)->InputThread(); return 0; }
|
static int InputThread_Start( void *p ) { ((InputHandler_DInput *) p)->InputThread(); return 0; }
|
||||||
void InputThread();
|
void InputThread();
|
||||||
|
|
||||||
|
void StartThread();
|
||||||
|
void ShutdownThread();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
InputHandler_DInput();
|
InputHandler_DInput();
|
||||||
~InputHandler_DInput();
|
~InputHandler_DInput();
|
||||||
|
|||||||
Reference in New Issue
Block a user