threaded Pump input
This commit is contained in:
@@ -1,29 +1,44 @@
|
|||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "InputHandler_Win32_Pump.h"
|
#include "InputHandler_Win32_Pump.h"
|
||||||
|
|
||||||
|
#include "PrefsManager.h"
|
||||||
#include "RageLog.h"
|
#include "RageLog.h"
|
||||||
#include "RageInputDevice.h"
|
#include "RageInputDevice.h"
|
||||||
#include "archutils/Win32/USB.h"
|
#include "archutils/Win32/USB.h"
|
||||||
|
|
||||||
InputHandler_Win32_Pump::InputHandler_Win32_Pump()
|
InputHandler_Win32_Pump::InputHandler_Win32_Pump()
|
||||||
{
|
{
|
||||||
|
shutdown = false;
|
||||||
const int pump_usb_vid = 0x0d2f, pump_usb_pid = 0x0001;
|
const int pump_usb_vid = 0x0d2f, pump_usb_pid = 0x0001;
|
||||||
|
|
||||||
dev = new USBDevice[NUM_PUMPS];
|
dev = new USBDevice[NUM_PUMPS];
|
||||||
|
|
||||||
for(int i = 0; i < NUM_PUMPS; ++i)
|
for(int i = 0; i < NUM_PUMPS; ++i)
|
||||||
{
|
{
|
||||||
if(dev[i].Open(pump_usb_vid, pump_usb_pid, i))
|
if(dev[i].Open(pump_usb_vid, pump_usb_pid, sizeof(long), i))
|
||||||
LOG->Info("Found Pump pad %i", i);
|
LOG->Info("Found Pump pad %i", i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( PREFSMAN->m_bThreadedInput )
|
||||||
|
InputThreadPtr = SDL_CreateThread(InputThread_Start, this);
|
||||||
|
else
|
||||||
|
InputThreadPtr = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
InputHandler_Win32_Pump::~InputHandler_Win32_Pump()
|
InputHandler_Win32_Pump::~InputHandler_Win32_Pump()
|
||||||
{
|
{
|
||||||
|
if( InputThreadPtr )
|
||||||
|
{
|
||||||
|
shutdown = true;
|
||||||
|
LOG->Trace("Shutting down Pump thread ...");
|
||||||
|
SDL_WaitThread(InputThreadPtr, NULL);
|
||||||
|
LOG->Trace("Pump thread shut down.");
|
||||||
|
}
|
||||||
|
|
||||||
delete[] dev;
|
delete[] dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputHandler_Win32_Pump::Update(float fDeltaTime)
|
void InputHandler_Win32_Pump::HandleInput( int devno, int event )
|
||||||
{
|
{
|
||||||
static const int bits[NUM_PUMP_PAD_BUTTONS] = {
|
static const int bits[NUM_PUMP_PAD_BUTTONS] = {
|
||||||
/* P1 */ (1<<9), (1<<12), (1<<13), (1<<11), (1<<10),
|
/* P1 */ (1<<9), (1<<12), (1<<13), (1<<11), (1<<10),
|
||||||
@@ -31,20 +46,18 @@ void InputHandler_Win32_Pump::Update(float fDeltaTime)
|
|||||||
/* P1 */ (1<<17), (1<<20), (1<<21), (1<<19), (1<<18),
|
/* P1 */ (1<<17), (1<<20), (1<<21), (1<<19), (1<<18),
|
||||||
};
|
};
|
||||||
|
|
||||||
for(int i = 0; i < NUM_PUMPS; ++i)
|
InputDevice id = InputDevice(DEVICE_PUMP1 + devno);
|
||||||
{
|
|
||||||
int ret = dev[i].GetPadEvent();
|
|
||||||
|
|
||||||
if(ret == -1)
|
|
||||||
continue; /* no event */
|
|
||||||
|
|
||||||
InputDevice id = InputDevice(DEVICE_PUMP1 + i);
|
|
||||||
|
|
||||||
for (int butno = 0 ; butno < NUM_PUMP_PAD_BUTTONS ; butno++)
|
for (int butno = 0 ; butno < NUM_PUMP_PAD_BUTTONS ; butno++)
|
||||||
ButtonPressed(DeviceInput(id, butno), !(ret & bits[butno]));
|
{
|
||||||
}
|
DeviceInput dev(id, butno);
|
||||||
|
|
||||||
InputHandler::Update( fDeltaTime );
|
/* If we're in a thread, our timestamp is accurate. */
|
||||||
|
if( InputThreadPtr )
|
||||||
|
dev.ts.Touch();
|
||||||
|
|
||||||
|
ButtonPressed(dev, !(event & bits[butno]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputHandler_Win32_Pump::GetDevicesAndDescriptions(vector<InputDevice>& vDevicesOut, vector<CString>& vDescriptionsOut)
|
void InputHandler_Win32_Pump::GetDevicesAndDescriptions(vector<InputDevice>& vDevicesOut, vector<CString>& vDescriptionsOut)
|
||||||
@@ -59,6 +72,52 @@ void InputHandler_Win32_Pump::GetDevicesAndDescriptions(vector<InputDevice>& vDe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int InputHandler_Win32_Pump::InputThread_Start( void *p )
|
||||||
|
{
|
||||||
|
((InputHandler_Win32_Pump *) p)->InputThread();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void InputHandler_Win32_Pump::InputThread()
|
||||||
|
{
|
||||||
|
vector<WindowsFileIO *> sources;
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < NUM_PUMPS; ++i)
|
||||||
|
{
|
||||||
|
if( dev[i].io.IsOpen() )
|
||||||
|
sources.push_back( &dev[i].io );
|
||||||
|
}
|
||||||
|
|
||||||
|
while(!shutdown)
|
||||||
|
{
|
||||||
|
int actual = 0, val = 0;
|
||||||
|
int ret = WindowsFileIO::read_several(sources, &val, actual, 0.100f);
|
||||||
|
|
||||||
|
if(ret <= 0)
|
||||||
|
continue; /* no event */
|
||||||
|
|
||||||
|
HandleInput( actual, val );
|
||||||
|
InputHandler::UpdateTimer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void InputHandler_Win32_Pump::Update(float fDeltaTime)
|
||||||
|
{
|
||||||
|
if( InputThreadPtr == NULL )
|
||||||
|
{
|
||||||
|
for(int i = 0; i < NUM_PUMPS; ++i)
|
||||||
|
{
|
||||||
|
int ret = dev[i].GetPadEvent();
|
||||||
|
|
||||||
|
if(ret == -1)
|
||||||
|
continue; /* no event */
|
||||||
|
|
||||||
|
HandleInput( i, ret );
|
||||||
|
}
|
||||||
|
InputHandler::UpdateTimer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
Copyright (c) 2002-2003 by the person(s) listed below. All rights reserved.
|
Copyright (c) 2002-2003 by the person(s) listed below. All rights reserved.
|
||||||
|
|||||||
@@ -2,11 +2,19 @@
|
|||||||
#define INPUT_HANDLER_WIN32_PUMP_H 1
|
#define INPUT_HANDLER_WIN32_PUMP_H 1
|
||||||
|
|
||||||
#include "InputHandler.h"
|
#include "InputHandler.h"
|
||||||
|
#include "SDL_Thread.h"
|
||||||
|
|
||||||
class USBDevice;
|
class USBDevice;
|
||||||
class InputHandler_Win32_Pump: public InputHandler
|
class InputHandler_Win32_Pump: public InputHandler
|
||||||
{
|
{
|
||||||
USBDevice *dev;
|
USBDevice *dev;
|
||||||
|
SDL_Thread *InputThreadPtr;
|
||||||
|
bool shutdown;
|
||||||
|
|
||||||
|
static int InputThread_Start( void *p );
|
||||||
|
void InputThread();
|
||||||
|
void HandleInput( int devno, int event );
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void Update(float fDeltaTime);
|
void Update(float fDeltaTime);
|
||||||
|
|||||||
Reference in New Issue
Block a user