Use SDL events for keyboard and joystick input. It's simpler.
It's also the "preferred" way of doing it, according to the SDL docs, so maybe it'll work better. This will reliably queue events, so we can handle coin events during loads. It'll queue events a little too reliably; we might want to flush some events when we load screens.
This commit is contained in:
@@ -10,17 +10,17 @@
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <math.h> // for fmod
|
||||
#include "InputFilter.h"
|
||||
#include "RageLog.h"
|
||||
#include "RageInput.h"
|
||||
#include "SDL_keyboard.h"
|
||||
|
||||
|
||||
InputFilter* INPUTFILTER = NULL; // global and accessable from anywhere in our program
|
||||
|
||||
InputFilter::InputFilter()
|
||||
{
|
||||
memset(m_BeingHeld, 0, sizeof(m_BeingHeld));
|
||||
|
||||
for( int i=0; i<NUM_INPUT_DEVICES; i++ )
|
||||
{
|
||||
for( int j=0; j<NUM_DEVICE_BUTTONS; j++ )
|
||||
@@ -28,28 +28,59 @@ InputFilter::InputFilter()
|
||||
}
|
||||
}
|
||||
|
||||
bool InputFilter::BeingPressed( DeviceInput di, bool Prev )
|
||||
void InputFilter::ButtonPressed( DeviceInput di, bool Down )
|
||||
{
|
||||
if(di.device == DEVICE_JOY1 || di.device == DEVICE_JOY2 || di.device == DEVICE_JOY3 || di.device == DEVICE_JOY4)
|
||||
switch( di.button ) {
|
||||
case JOY_Z_UP: case JOY_Z_DOWN:
|
||||
case JOY_Z_ROT_UP: case JOY_Z_ROT_DOWN:
|
||||
case JOY_HAT_LEFT: case JOY_HAT_RIGHT: case JOY_HAT_UP: case JOY_HAT_DOWN:
|
||||
/* For now, ignore these. */
|
||||
return false;
|
||||
}
|
||||
if(m_BeingHeld[di.device][di.button] == Down)
|
||||
return;
|
||||
|
||||
return INPUTMAN->BeingPressed(di, Prev);
|
||||
m_BeingHeld[di.device][di.button] = Down;
|
||||
m_fSecsHeld[di.device][di.button] = 0;
|
||||
|
||||
InputEventType iet = Down? IET_FIRST_PRESS:IET_RELEASE;
|
||||
queue.push_back( InputEvent(di,iet) );
|
||||
}
|
||||
|
||||
bool InputFilter::WasBeingPressed( DeviceInput di )
|
||||
void InputFilter::Update(float fDeltaTime)
|
||||
{
|
||||
return BeingPressed(di, true);
|
||||
INPUTMAN->Update( fDeltaTime );
|
||||
|
||||
for( int d=0; d<NUM_INPUT_DEVICES; d++ ) // foreach InputDevice
|
||||
{
|
||||
for( int b=0; b < NUM_DEVICE_BUTTONS; b++ ) // foreach button
|
||||
{
|
||||
if(!m_BeingHeld[d][b])
|
||||
continue;
|
||||
|
||||
const float fOldHoldTime = m_fSecsHeld[d][b];
|
||||
m_fSecsHeld[d][b] += fDeltaTime;
|
||||
const float fNewHoldTime = m_fSecsHeld[d][b];
|
||||
|
||||
float fTimeBetweenRepeats;
|
||||
InputEventType iet;
|
||||
if( fOldHoldTime > TIME_BEFORE_SLOW_REPEATS )
|
||||
{
|
||||
if( fOldHoldTime > TIME_BEFORE_FAST_REPEATS )
|
||||
{
|
||||
fTimeBetweenRepeats = TIME_BETWEEN_FAST_REPEATS;
|
||||
iet = IET_FAST_REPEAT;
|
||||
}
|
||||
else
|
||||
{
|
||||
fTimeBetweenRepeats = TIME_BETWEEN_SLOW_REPEATS;
|
||||
iet = IET_SLOW_REPEAT;
|
||||
}
|
||||
if( int(fOldHoldTime/fTimeBetweenRepeats) != int(fNewHoldTime/fTimeBetweenRepeats) )
|
||||
queue.push_back( InputEvent(InputDevice(d),b,iet) );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool InputFilter::IsBeingPressed( DeviceInput di )
|
||||
{
|
||||
return BeingPressed(di, false);
|
||||
return m_BeingHeld[di.device][di.button];
|
||||
}
|
||||
|
||||
float InputFilter::GetSecsHeld( DeviceInput di )
|
||||
@@ -57,56 +88,8 @@ float InputFilter::GetSecsHeld( DeviceInput di )
|
||||
return m_fSecsHeld[di.device][di.button];
|
||||
}
|
||||
|
||||
void InputFilter::GetInputEvents( InputEventArray &array, float fDeltaTime )
|
||||
void InputFilter::GetInputEvents( InputEventArray &array )
|
||||
{
|
||||
INPUTMAN->Update( fDeltaTime );
|
||||
|
||||
for( int d=0; d<NUM_INPUT_DEVICES; d++ ) // foreach InputDevice
|
||||
{
|
||||
int iNumButtonsToCheck = DeviceInput::NumButtons(InputDevice(d));
|
||||
|
||||
for( int b=0; b<iNumButtonsToCheck; b++ ) // foreach button
|
||||
{
|
||||
const DeviceInput di = DeviceInput(InputDevice(d),b);
|
||||
|
||||
if( WasBeingPressed(di) )
|
||||
{
|
||||
if( IsBeingPressed(di) )
|
||||
{
|
||||
const float fOldHoldTime = m_fSecsHeld[d][b];
|
||||
m_fSecsHeld[d][b] += fDeltaTime;
|
||||
const float fNewHoldTime = m_fSecsHeld[d][b];
|
||||
|
||||
float fTimeBetweenRepeats;
|
||||
InputEventType iet;
|
||||
if( fOldHoldTime > TIME_BEFORE_SLOW_REPEATS )
|
||||
{
|
||||
if( fOldHoldTime > TIME_BEFORE_FAST_REPEATS )
|
||||
{
|
||||
fTimeBetweenRepeats = TIME_BETWEEN_FAST_REPEATS;
|
||||
iet = IET_FAST_REPEAT;
|
||||
}
|
||||
else
|
||||
{
|
||||
fTimeBetweenRepeats = TIME_BETWEEN_SLOW_REPEATS;
|
||||
iet = IET_SLOW_REPEAT;
|
||||
}
|
||||
if( int(fOldHoldTime/fTimeBetweenRepeats) != int(fNewHoldTime/fTimeBetweenRepeats) )
|
||||
array.push_back( InputEvent(di,iet) );
|
||||
}
|
||||
}
|
||||
else { // !IsBeingPressed(di)
|
||||
m_fSecsHeld[d][b] = 0;
|
||||
array.push_back( InputEvent(di,IET_RELEASE) );
|
||||
}
|
||||
}
|
||||
else // !WasBeingPressed(di)
|
||||
{
|
||||
if( IsBeingPressed(di) )
|
||||
array.push_back( InputEvent(di,IET_FIRST_PRESS) );
|
||||
else // !IsBeingPressed(di)
|
||||
; // don't care
|
||||
}
|
||||
}
|
||||
}
|
||||
array = queue;
|
||||
queue.clear();
|
||||
}
|
||||
|
||||
@@ -24,12 +24,11 @@ const float TIME_BETWEEN_FAST_REPEATS = 0.125f;
|
||||
|
||||
enum InputEventType { IET_FIRST_PRESS, IET_SLOW_REPEAT, IET_FAST_REPEAT, IET_RELEASE };
|
||||
|
||||
class InputEvent : public DeviceInput
|
||||
struct InputEvent : public DeviceInput
|
||||
{
|
||||
public:
|
||||
InputEvent() { type=IET_FIRST_PRESS; };
|
||||
InputEvent( InputDevice d, int b, InputEventType t ) { device=d; button=b; type=t; };
|
||||
InputEvent( DeviceInput di, InputEventType t ) { device=di.device; button=di.button; type=t; };
|
||||
InputEvent( InputDevice d, int b, InputEventType t ): DeviceInput(d, b) { type=t; };
|
||||
InputEvent( DeviceInput di, InputEventType t ): DeviceInput(di) { type=t; };
|
||||
|
||||
InputEventType type;
|
||||
};
|
||||
@@ -38,17 +37,20 @@ typedef vector<InputEvent> InputEventArray;
|
||||
|
||||
class InputFilter
|
||||
{
|
||||
bool m_BeingHeld[NUM_INPUT_DEVICES][NUM_DEVICE_BUTTONS];
|
||||
float m_fSecsHeld[NUM_INPUT_DEVICES][NUM_DEVICE_BUTTONS];
|
||||
|
||||
InputEventArray queue;
|
||||
|
||||
public:
|
||||
void ButtonPressed( DeviceInput di, bool Down );
|
||||
InputFilter();
|
||||
void Update(float fDeltaTime);
|
||||
|
||||
bool BeingPressed( DeviceInput di, bool Prev = false);
|
||||
bool WasBeingPressed( DeviceInput di );
|
||||
bool IsBeingPressed( DeviceInput di );
|
||||
float GetSecsHeld( DeviceInput di );
|
||||
|
||||
void GetInputEvents( InputEventArray &array, float fDeltaTime );
|
||||
|
||||
float m_fSecsHeld[NUM_INPUT_DEVICES][NUM_DEVICE_BUTTONS];
|
||||
void GetInputEvents( InputEventArray &array );
|
||||
};
|
||||
|
||||
|
||||
|
||||
+58
-305
@@ -10,40 +10,14 @@
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// In-line Links
|
||||
//-----------------------------------------------------------------------------
|
||||
#pragma comment(lib, "ddk/setupapi.lib")
|
||||
#pragma comment(lib, "ddk/hid.lib")
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Includes
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "RageInput.h"
|
||||
#include "SDL.h"
|
||||
#include "SDL_keyboard.h"
|
||||
#include "RageUtil.h"
|
||||
#include "SDL_utils.h"
|
||||
#include "RageLog.h"
|
||||
#include "RageException.h"
|
||||
|
||||
#include "InputFilter.h"
|
||||
|
||||
RageInput* INPUTMAN = NULL; // globally accessable input device
|
||||
|
||||
struct RageInput::pump_t
|
||||
{
|
||||
HANDLE h;
|
||||
OVERLAPPED ov;
|
||||
long buf;
|
||||
bool pending;
|
||||
|
||||
pump_t();
|
||||
~pump_t();
|
||||
void Update();
|
||||
bool init(int devno);
|
||||
int GetPadEvent();
|
||||
|
||||
bool current_state[NUM_PUMP_PAD_BUTTONS];
|
||||
};
|
||||
|
||||
RageInput::RageInput()
|
||||
{
|
||||
@@ -51,9 +25,6 @@ RageInput::RageInput()
|
||||
|
||||
SDL_InitSubSystem( SDL_INIT_JOYSTICK );
|
||||
|
||||
// init state info
|
||||
memset( state, 0, sizeof(state) );
|
||||
|
||||
|
||||
//
|
||||
// Init keyboard
|
||||
@@ -68,310 +39,92 @@ RageInput::RageInput()
|
||||
//
|
||||
// Init joysticks
|
||||
//
|
||||
memset( m_pJoystick, 0, sizeof(m_pJoystick) );
|
||||
int iNumJoySticks = min( SDL_NumJoysticks(), NUM_JOYSTICKS );
|
||||
LOG->Info( "Found %d joysticks", iNumJoySticks );
|
||||
for( int i=0; i<iNumJoySticks; i++ )
|
||||
{
|
||||
m_pJoystick[i] = SDL_JoystickOpen( i );
|
||||
SDL_Joystick *pJoystick = SDL_JoystickOpen( i );
|
||||
LOG->Info( " %d: '%s' axes: %d, hats: %d, buttons: %d",
|
||||
i,
|
||||
SDL_JoystickName(i),
|
||||
SDL_JoystickNumAxes(m_pJoystick[i]),
|
||||
SDL_JoystickNumHats(m_pJoystick[i]),
|
||||
SDL_JoystickNumButtons(m_pJoystick[i]) );
|
||||
SDL_JoystickNumAxes(pJoystick),
|
||||
SDL_JoystickNumHats(pJoystick),
|
||||
SDL_JoystickNumButtons(pJoystick) );
|
||||
SDL_JoystickClose(pJoystick);
|
||||
}
|
||||
SDL_JoystickEventState( SDL_IGNORE );
|
||||
|
||||
SDL_JoystickEventState( SDL_ENABLE );
|
||||
|
||||
//
|
||||
// Init pumps
|
||||
// Init pump
|
||||
//
|
||||
m_Pumps = new pump_t[NUM_PUMPS];
|
||||
|
||||
for(int pumpNo = 0; pumpNo < NUM_PUMPS; ++pumpNo)
|
||||
{
|
||||
if(m_Pumps[pumpNo].init(pumpNo))
|
||||
LOG->Info("Found Pump pad %i", pumpNo);
|
||||
}
|
||||
m_Pump = new PumpPadDevice;
|
||||
}
|
||||
|
||||
RageInput::~RageInput()
|
||||
{
|
||||
//
|
||||
// De-init keyboard
|
||||
// De-init pump
|
||||
//
|
||||
|
||||
//
|
||||
// De-init joysticks
|
||||
//
|
||||
for( int i=0; i<NUM_JOYSTICKS; i++ )
|
||||
{
|
||||
if( m_pJoystick[i] )
|
||||
{
|
||||
SDL_JoystickClose(m_pJoystick[i]);
|
||||
m_pJoystick[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// De-init pumps
|
||||
//
|
||||
delete[] m_Pumps;
|
||||
|
||||
delete m_Pump;
|
||||
|
||||
SDL_QuitSubSystem( SDL_INIT_JOYSTICK );
|
||||
}
|
||||
|
||||
void RageInput::Update( float fDeltaTime )
|
||||
{
|
||||
//
|
||||
// Move last current state to old state
|
||||
//
|
||||
memcpy( &state[LAST], &state[CURRENT], sizeof(state[LAST]) );
|
||||
|
||||
|
||||
//
|
||||
// Update keyboard
|
||||
//
|
||||
SDL_PumpEvents();
|
||||
Uint8* keystate = SDL_GetKeyState(NULL);
|
||||
memcpy( state[CURRENT].m_Devices[DEVICE_KEYBOARD].button, keystate, NUM_KEYBOARD_BUTTONS );
|
||||
|
||||
//
|
||||
// Update Joystick
|
||||
//
|
||||
SDL_JoystickUpdate();
|
||||
|
||||
|
||||
for( int joy=0; joy<NUM_JOYSTICKS; joy++ ) // foreach joystick
|
||||
{
|
||||
state_t::device_t *dev = &state[CURRENT].m_Devices[DEVICE_JOY1+joy];
|
||||
memset( dev->button, 0, sizeof(dev->button) ); // clear current state
|
||||
SDL_Joystick* pJoy = m_pJoystick[joy];
|
||||
if( !pJoy )
|
||||
continue;
|
||||
|
||||
int iNumJoyAxes = min(NUM_JOYSTICK_AXES,SDL_JoystickNumAxes(pJoy));
|
||||
for( int axis=0; axis<iNumJoyAxes; axis++ )
|
||||
{
|
||||
Sint16 val = SDL_JoystickGetAxis(pJoy,axis);
|
||||
// LOG->Trace( "axis %d = %d", axis, val );
|
||||
if( val < -16000 )
|
||||
{
|
||||
JoystickButton b = (JoystickButton)(JOY_LEFT+2*axis);
|
||||
dev->button[b] = true;
|
||||
}
|
||||
else if( val > +16000 )
|
||||
{
|
||||
JoystickButton b = (JoystickButton)(JOY_RIGHT+2*axis);
|
||||
dev->button[b] = true;
|
||||
}
|
||||
}
|
||||
|
||||
int iNumJoyHats = min(NUM_JOYSTICK_HATS,SDL_JoystickNumHats(pJoy));
|
||||
for( int hat=0; hat<iNumJoyHats; hat++ )
|
||||
{
|
||||
Uint8 val = SDL_JoystickGetHat(pJoy,hat);
|
||||
dev->button[JOY_HAT_UP] = (val & SDL_HAT_UP) != 0;
|
||||
dev->button[JOY_HAT_RIGHT] = (val & SDL_HAT_RIGHT) != 0;
|
||||
dev->button[JOY_HAT_DOWN] = (val & SDL_HAT_DOWN) != 0;
|
||||
dev->button[JOY_HAT_LEFT] = (val & SDL_HAT_LEFT) != 0;
|
||||
}
|
||||
|
||||
int iNumJoyButtons = MIN(NUM_JOYSTICK_BUTTONS,SDL_JoystickNumButtons(pJoy));
|
||||
for( int button=0; button<iNumJoyButtons; button++ )
|
||||
{
|
||||
JoystickButton b = (JoystickButton)(JOY_1 + button);
|
||||
dev->button[b] = SDL_JoystickGetButton(pJoy,button) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Update Pump
|
||||
//
|
||||
for( int i=0; i<NUM_PUMPS; i++ )
|
||||
m_Pumps[i].Update();
|
||||
|
||||
memcpy(state[CURRENT].m_Devices[DEVICE_PUMP1].button, m_Pumps[0].current_state, sizeof(m_Pumps[0].current_state));
|
||||
memcpy(state[CURRENT].m_Devices[DEVICE_PUMP2].button, m_Pumps[1].current_state, sizeof(m_Pumps[0].current_state));
|
||||
m_Pump->Update();
|
||||
}
|
||||
|
||||
bool RageInput::BeingPressed( DeviceInput di, bool bPrevState )
|
||||
bool RageInput::FeedSDLEvent(const SDL_Event &event)
|
||||
{
|
||||
ASSERT(di.button < NUM_DEVICE_BUTTONS);
|
||||
ASSERT(di.device < NUM_INPUT_DEVICES);
|
||||
|
||||
State s = bPrevState? LAST:CURRENT;
|
||||
|
||||
return state[s].m_Devices[di.device].button[ di.button ];
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
#include "ddk/setupapi.h"
|
||||
/* Quiet header warning: */
|
||||
#pragma warning( push )
|
||||
#pragma warning (disable : 4201)
|
||||
#include "ddk/hidsdi.h"
|
||||
#pragma warning( pop )
|
||||
}
|
||||
|
||||
char *USB::GetUSBDevicePath (int num)
|
||||
{
|
||||
GUID guid;
|
||||
HidD_GetHidGuid(&guid);
|
||||
|
||||
HDEVINFO DeviceInfo = SetupDiGetClassDevs (&guid,
|
||||
NULL, NULL, (DIGCF_PRESENT | DIGCF_DEVICEINTERFACE));
|
||||
|
||||
SP_DEVICE_INTERFACE_DATA DeviceInterface;
|
||||
DeviceInterface.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
|
||||
|
||||
char *ret = NULL;
|
||||
PSP_INTERFACE_DEVICE_DETAIL_DATA DeviceDetail = NULL;
|
||||
|
||||
if (!SetupDiEnumDeviceInterfaces (DeviceInfo,
|
||||
NULL, &guid, num, &DeviceInterface))
|
||||
goto err;
|
||||
|
||||
unsigned long size;
|
||||
SetupDiGetDeviceInterfaceDetail (DeviceInfo, &DeviceInterface, NULL, 0, &size, 0);
|
||||
|
||||
DeviceDetail = (PSP_INTERFACE_DEVICE_DETAIL_DATA) malloc(size);
|
||||
DeviceDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
|
||||
|
||||
if (SetupDiGetDeviceInterfaceDetail (DeviceInfo, &DeviceInterface,
|
||||
DeviceDetail, size, &size, NULL))
|
||||
{
|
||||
ret = strdup(DeviceDetail->DevicePath);
|
||||
}
|
||||
|
||||
err:
|
||||
SetupDiDestroyDeviceInfoList (DeviceInfo);
|
||||
free (DeviceDetail);
|
||||
return ret;
|
||||
}
|
||||
|
||||
HANDLE USB::OpenUSB (int VID, int PID, int num)
|
||||
{
|
||||
DWORD index = 0;
|
||||
|
||||
char *path;
|
||||
HANDLE h = INVALID_HANDLE_VALUE;
|
||||
|
||||
while ((path = GetUSBDevicePath (index++)) != NULL)
|
||||
{
|
||||
if(h != INVALID_HANDLE_VALUE)
|
||||
CloseHandle (h);
|
||||
|
||||
h = CreateFile (path, GENERIC_READ,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
|
||||
|
||||
free(path);
|
||||
|
||||
if(h == INVALID_HANDLE_VALUE)
|
||||
continue;
|
||||
|
||||
HIDD_ATTRIBUTES attr;
|
||||
if (!HidD_GetAttributes (h, &attr))
|
||||
continue;
|
||||
|
||||
if ((VID != -1 && attr.VendorID != VID) &&
|
||||
(PID != -1 && attr.ProductID != PID))
|
||||
continue; /* This isn't it. */
|
||||
|
||||
/* The VID and PID match. */
|
||||
if(num-- == 0)
|
||||
return h;
|
||||
}
|
||||
if(h != INVALID_HANDLE_VALUE)
|
||||
CloseHandle (h);
|
||||
|
||||
return INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
RageInput::pump_t::pump_t()
|
||||
{
|
||||
ZeroMemory( &ov, sizeof(ov) );
|
||||
memset(current_state, 0, sizeof(current_state));
|
||||
pending=false;
|
||||
h = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
RageInput::pump_t::~pump_t()
|
||||
{
|
||||
if(h != INVALID_HANDLE_VALUE)
|
||||
CloseHandle(h);
|
||||
}
|
||||
|
||||
bool RageInput::pump_t::init(int devno)
|
||||
{
|
||||
const int pump_usb_vid = 0x0d2f, pump_usb_pid = 0x0001;
|
||||
h = USB::OpenUSB (pump_usb_vid, pump_usb_pid, devno);
|
||||
return h != INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
int RageInput::pump_t::GetPadEvent()
|
||||
{
|
||||
int ret;
|
||||
|
||||
if(!pending)
|
||||
{
|
||||
/* Request feedback from the device. */
|
||||
unsigned long r;
|
||||
ret = ReadFile(h, &buf, sizeof(buf), &r, &ov);
|
||||
pending=true;
|
||||
}
|
||||
|
||||
/* See if we have a response for our request (which we may
|
||||
* have made on a previous cal): */
|
||||
if(WaitForSingleObjectEx(h, 0, TRUE) == WAIT_TIMEOUT)
|
||||
return -1;
|
||||
|
||||
/* We do; get the result. It'll go into the original &buf
|
||||
* we supplied on the original call; that's why buf is a
|
||||
* member instead of a local. */
|
||||
unsigned long cnt;
|
||||
ret = GetOverlappedResult(h, &ov, &cnt, FALSE);
|
||||
pending=false;
|
||||
|
||||
if(ret == 0 && (GetLastError() == ERROR_IO_PENDING || GetLastError() == ERROR_IO_INCOMPLETE))
|
||||
return -1;
|
||||
|
||||
if(ret == 0) {
|
||||
LOG->Warn(werr_ssprintf(GetLastError(), "Error reading Pump pad"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
void RageInput::pump_t::Update()
|
||||
{
|
||||
if(h == INVALID_HANDLE_VALUE) return;
|
||||
|
||||
int ret = GetPadEvent();
|
||||
|
||||
if(ret == -1)
|
||||
return; /* no event */
|
||||
|
||||
/* Since we're checking for messages, and not polling,
|
||||
* only zero this out when we actually *have* a new
|
||||
* message. */
|
||||
|
||||
memset( ¤t_state, 0, sizeof(current_state) );
|
||||
|
||||
int bits[] = {
|
||||
/* P1 */ (1<<9), (1<<12), (1<<13), (1<<11), (1<<10),
|
||||
/* ESC */ (1<<16),
|
||||
/* P1 */ (1<<17), (1<<20), (1<<21), (1<<19), (1<<18),
|
||||
};
|
||||
|
||||
for (int butno = 0 ; butno < NUM_PUMP_PAD_BUTTONS ; butno++)
|
||||
switch(event.type)
|
||||
{
|
||||
if(!(ret & bits[butno]))
|
||||
current_state[butno] = true;
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
{
|
||||
DeviceInput di(DEVICE_KEYBOARD, event.key.keysym.sym);
|
||||
INPUTFILTER->ButtonPressed(di, event.key.state == SDL_PRESSED);
|
||||
return true;
|
||||
}
|
||||
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
case SDL_JOYBUTTONUP:
|
||||
{
|
||||
InputDevice i = InputDevice(DEVICE_JOY1 + event.jbutton.which);
|
||||
JoystickButton Button = JoystickButton(JOY_1 + event.jbutton.button);
|
||||
if(Button >= NUM_JOYSTICK_BUTTONS)
|
||||
{
|
||||
LOG->Warn("Ignored joystick event (button too high)");
|
||||
return true;
|
||||
}
|
||||
DeviceInput di(i, Button);
|
||||
INPUTFILTER->ButtonPressed(di, event.jbutton.state == SDL_PRESSED);
|
||||
return true;
|
||||
}
|
||||
|
||||
case SDL_JOYAXISMOTION:
|
||||
{
|
||||
InputDevice i = InputDevice(DEVICE_JOY1 + event.jaxis.which);
|
||||
JoystickButton neg = (JoystickButton)(JOY_LEFT+2*event.jaxis.axis);
|
||||
JoystickButton pos = (JoystickButton)(JOY_RIGHT+2*event.jaxis.axis);
|
||||
INPUTFILTER->ButtonPressed(DeviceInput(i, neg), event.jaxis.value < -16000);
|
||||
INPUTFILTER->ButtonPressed(DeviceInput(i, pos), event.jaxis.value > +16000);
|
||||
return true;
|
||||
}
|
||||
|
||||
case SDL_JOYHATMOTION:
|
||||
{
|
||||
InputDevice i = InputDevice(DEVICE_JOY1 + event.jhat.which);
|
||||
INPUTFILTER->ButtonPressed(DeviceInput(i, JOY_HAT_UP), !!(event.jhat.value & SDL_HAT_UP));
|
||||
INPUTFILTER->ButtonPressed(DeviceInput(i, JOY_HAT_DOWN), !!(event.jhat.value & JOY_HAT_DOWN));
|
||||
INPUTFILTER->ButtonPressed(DeviceInput(i, JOY_HAT_LEFT), !!(event.jhat.value & JOY_HAT_LEFT));
|
||||
INPUTFILTER->ButtonPressed(DeviceInput(i, JOY_HAT_RIGHT), !!(event.jhat.value & JOY_HAT_RIGHT));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,46 +5,25 @@
|
||||
File: RageInput.h
|
||||
|
||||
Desc: Wrapper for SDL's input routines. Generates InputEvents.
|
||||
|
||||
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
||||
Chris Danford
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "RageInputDevice.h"
|
||||
#include "SDL_utils.h"
|
||||
|
||||
struct _SDL_Joystick;
|
||||
typedef struct _SDL_Joystick SDL_Joystick;
|
||||
#include "arch/InputHandler/InputHandler_Win32_Pump.h"
|
||||
|
||||
class RageInput
|
||||
{
|
||||
SDL_Joystick* m_pJoystick[NUM_JOYSTICKS];
|
||||
|
||||
enum State { CURRENT = 0, LAST, NUM_STATES };
|
||||
|
||||
struct state_t {
|
||||
struct device_t {
|
||||
bool button[NUM_DEVICE_BUTTONS];
|
||||
} m_Devices[NUM_INPUT_DEVICES];
|
||||
} state[NUM_STATES];
|
||||
|
||||
/* Structure for reading Pump pads: */
|
||||
struct pump_t;
|
||||
pump_t *m_Pumps;
|
||||
PumpPadDevice *m_Pump;
|
||||
|
||||
public:
|
||||
RageInput();
|
||||
~RageInput();
|
||||
|
||||
void Update( float fDeltaTime );
|
||||
bool BeingPressed( DeviceInput di, bool bPrevState );
|
||||
bool IsBeingPressed( DeviceInput di ) { return BeingPressed(di, false); }
|
||||
bool WasBeingPressed( DeviceInput di ) { return BeingPressed(di, true); }
|
||||
};
|
||||
|
||||
namespace USB {
|
||||
char *GetUSBDevicePath (int num);
|
||||
HANDLE OpenUSB (int VID, int PID, int num);
|
||||
bool FeedSDLEvent(const SDL_Event &event);
|
||||
};
|
||||
|
||||
extern RageInput* INPUTMAN; // global and accessable from anywhere in our program
|
||||
@@ -52,7 +31,7 @@ extern RageInput* INPUTMAN; // global and accessable from anywhere in our prog
|
||||
|
||||
#endif
|
||||
/*
|
||||
* Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
||||
* Copyright (c) 2001-2003 by the person(s) listed below. All rights reserved.
|
||||
* Chris Danford
|
||||
* Glenn Maynard
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Define all of the input devices we know about.
|
||||
* Define all of the input devices we know about. This is the public
|
||||
* interface for describing input devices.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
+13
-13
@@ -420,8 +420,8 @@ bool HandleGlobalInputs( DeviceInput DeviceI, InputEventType type, GameInput Gam
|
||||
if(DeviceI == DeviceInput(DEVICE_KEYBOARD, SDLK_F4))
|
||||
{
|
||||
if(type != IET_FIRST_PRESS) return true;
|
||||
if( INPUTMAN->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_RALT)) ||
|
||||
INPUTMAN->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_LALT)) )
|
||||
if( INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_RALT)) ||
|
||||
INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_LALT)) )
|
||||
{
|
||||
// pressed Alt+F4
|
||||
SDL_Event *event;
|
||||
@@ -458,8 +458,8 @@ bool HandleGlobalInputs( DeviceInput DeviceI, InputEventType type, GameInput Gam
|
||||
|
||||
if(DeviceI == DeviceInput(DEVICE_KEYBOARD, SDLK_RETURN))
|
||||
{
|
||||
if( INPUTMAN->IsBeingPressed(DeviceInput(DEVICE_KEYBOARD, SDLK_RALT)) ||
|
||||
INPUTMAN->IsBeingPressed(DeviceInput(DEVICE_KEYBOARD, SDLK_LALT)) )
|
||||
if( INPUTFILTER->IsBeingPressed(DeviceInput(DEVICE_KEYBOARD, SDLK_RALT)) ||
|
||||
INPUTFILTER->IsBeingPressed(DeviceInput(DEVICE_KEYBOARD, SDLK_LALT)) )
|
||||
{
|
||||
if(type != IET_FIRST_PRESS) return true;
|
||||
/* alt-enter */
|
||||
@@ -474,9 +474,11 @@ bool HandleGlobalInputs( DeviceInput DeviceI, InputEventType type, GameInput Gam
|
||||
|
||||
static void HandleInputEvents(float fDeltaTime)
|
||||
{
|
||||
INPUTFILTER->Update( fDeltaTime );
|
||||
|
||||
static InputEventArray ieArray;
|
||||
ieArray.clear(); // empty the array
|
||||
INPUTFILTER->GetInputEvents( ieArray, fDeltaTime );
|
||||
INPUTFILTER->GetInputEvents( ieArray );
|
||||
for( unsigned i=0; i<ieArray.size(); i++ )
|
||||
{
|
||||
DeviceInput DeviceI = (DeviceInput)ieArray[i];
|
||||
@@ -503,11 +505,6 @@ static void HandleInputEvents(float fDeltaTime)
|
||||
if( HandleGlobalInputs(DeviceI, type, GameI, MenuI, StyleI ) )
|
||||
continue; // skip
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
SCREENMAN->Input( DeviceI, type, GameI, MenuI, StyleI );
|
||||
}
|
||||
}
|
||||
@@ -521,6 +518,9 @@ static void GameLoop()
|
||||
SDL_Event event;
|
||||
while(SDL_PollEvent(&event))
|
||||
{
|
||||
if(INPUTMAN->FeedSDLEvent(event))
|
||||
continue; /* it took care of it */
|
||||
|
||||
switch(event.type)
|
||||
{
|
||||
case SDL_QUIT:
|
||||
@@ -554,13 +554,13 @@ static void GameLoop()
|
||||
*/
|
||||
float fDeltaTime = timer.GetDeltaTime();
|
||||
|
||||
if( INPUTMAN->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_TAB) ) ) {
|
||||
if( INPUTMAN->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_BACKQUOTE) ) )
|
||||
if( INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_TAB) ) ) {
|
||||
if( INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_BACKQUOTE) ) )
|
||||
fDeltaTime = 0; /* both; stop time */
|
||||
else
|
||||
fDeltaTime *= 4;
|
||||
} else
|
||||
if( INPUTMAN->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_BACKQUOTE) ) )
|
||||
if( INPUTFILTER->IsBeingPressed( DeviceInput(DEVICE_KEYBOARD, SDLK_BACKQUOTE) ) )
|
||||
fDeltaTime /= 4;
|
||||
|
||||
TEXTUREMAN->Update( fDeltaTime );
|
||||
|
||||
@@ -60,7 +60,7 @@ IntDir=.\../Release6
|
||||
TargetDir=\temp\stepmania
|
||||
TargetName=StepMania
|
||||
SOURCE="$(InputPath)"
|
||||
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
|
||||
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
|
||||
PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi ia32.vdi
|
||||
# End Special Build Tool
|
||||
|
||||
@@ -95,7 +95,7 @@ IntDir=.\../Debug6
|
||||
TargetDir=\temp\stepmania
|
||||
TargetName=StepMania-debug
|
||||
SOURCE="$(InputPath)"
|
||||
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
|
||||
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
|
||||
PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi ia32.vdi
|
||||
# End Special Build Tool
|
||||
|
||||
@@ -688,6 +688,22 @@ SOURCE=.\arch\ArchHooks\ArchHooks_Win32.cpp
|
||||
SOURCE=.\arch\ArchHooks\ArchHooks_Win32.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "InputHandler"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\arch\InputHandler\InputHandler.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\arch\InputHandler\InputHandler_Win32_Pump.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\arch\InputHandler\InputHandler_Win32_Pump.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\arch\arch.cpp
|
||||
|
||||
@@ -808,6 +808,19 @@ cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
|
||||
RelativePath="arch\ArchHooks\ArchHooks_none.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="InputHandler"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath="arch\InputHandler\InputHandler.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="arch\InputHandler\InputHandler_Win32_Pump.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="arch\InputHandler\InputHandler_Win32_Pump.h">
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="system"
|
||||
|
||||
Reference in New Issue
Block a user