2002-11-16 08:07:38 +00:00
|
|
|
#ifndef RAGEINPUT_H
|
|
|
|
|
#define RAGEINPUT_H
|
2001-11-04 19:34:28 +00:00
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
File: RageInput.h
|
|
|
|
|
|
2002-11-29 20:37:12 +00:00
|
|
|
Desc: Wrapper for SDL's input routines. Generates InputEvents.
|
2001-11-04 19:34:28 +00:00
|
|
|
|
2002-05-19 01:59:48 +00:00
|
|
|
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
2002-11-29 20:37:12 +00:00
|
|
|
Chris Danford
|
2001-11-04 19:34:28 +00:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-11-29 20:37:12 +00:00
|
|
|
struct _SDL_Joystick;
|
|
|
|
|
typedef struct _SDL_Joystick SDL_Joystick;
|
2001-11-21 03:21:00 +00:00
|
|
|
|
2002-11-29 20:37:12 +00:00
|
|
|
#include "SDL_keysym.h"
|
2001-12-28 10:15:59 +00:00
|
|
|
|
2002-11-29 20:37:12 +00:00
|
|
|
const int NUM_KEYBOARD_BUTTONS = SDLK_LAST;
|
2001-11-25 04:31:44 +00:00
|
|
|
const int NUM_JOYSTICKS = 4;
|
2002-11-29 20:37:12 +00:00
|
|
|
const int NUM_JOYSTICK_AXES = 4; // X, Y, Z, rudder
|
|
|
|
|
const int NUM_JOYSTICK_HATS = 1;
|
2002-08-20 22:51:12 +00:00
|
|
|
const int NUM_PUMPS = 2;
|
2002-08-20 23:25:27 +00:00
|
|
|
const int NUM_PUMP_PAD_BUTTONS = 11;
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-11-29 20:37:12 +00:00
|
|
|
const int NUM_DEVICE_BUTTONS = NUM_KEYBOARD_BUTTONS;
|
|
|
|
|
|
2001-11-25 10:49:31 +00:00
|
|
|
enum InputDevice {
|
|
|
|
|
DEVICE_KEYBOARD = 0,
|
2002-04-16 17:31:00 +00:00
|
|
|
DEVICE_JOY1,
|
|
|
|
|
DEVICE_JOY2,
|
|
|
|
|
DEVICE_JOY3,
|
|
|
|
|
DEVICE_JOY4,
|
2002-08-20 22:51:12 +00:00
|
|
|
DEVICE_PUMP1,
|
|
|
|
|
DEVICE_PUMP2,
|
2001-11-25 10:49:31 +00:00
|
|
|
NUM_INPUT_DEVICES, // leave this at the end
|
|
|
|
|
DEVICE_NONE // means this is NULL
|
|
|
|
|
};
|
|
|
|
|
|
2001-11-03 10:52:42 +00:00
|
|
|
// button byte codes for directional pad
|
2001-11-25 10:49:31 +00:00
|
|
|
enum JoystickButton {
|
2003-01-09 07:46:45 +00:00
|
|
|
JOY_LEFT = 0, JOY_RIGHT,
|
|
|
|
|
JOY_UP, JOY_DOWN,
|
2002-09-08 02:49:07 +00:00
|
|
|
JOY_Z_UP, JOY_Z_DOWN,
|
2002-09-08 06:13:47 +00:00
|
|
|
JOY_Z_ROT_UP, JOY_Z_ROT_DOWN,
|
2002-09-08 02:49:07 +00:00
|
|
|
JOY_HAT_LEFT, JOY_HAT_RIGHT, JOY_HAT_UP, JOY_HAT_DOWN,
|
2002-08-26 04:46:16 +00:00
|
|
|
JOY_1, JOY_2, JOY_3, JOY_4, JOY_5, JOY_6, JOY_7, JOY_8, JOY_9, JOY_10,
|
|
|
|
|
JOY_11, JOY_12, JOY_13, JOY_14, JOY_15, JOY_16, JOY_17, JOY_18, JOY_19, JOY_20,
|
|
|
|
|
JOY_21, JOY_22, JOY_23, JOY_24,
|
2001-11-25 10:49:31 +00:00
|
|
|
NUM_JOYSTICK_BUTTONS // leave this at the end
|
|
|
|
|
};
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
|
2001-11-25 10:49:31 +00:00
|
|
|
struct DeviceInput
|
2001-11-03 10:52:42 +00:00
|
|
|
{
|
|
|
|
|
public:
|
2001-11-25 10:49:31 +00:00
|
|
|
InputDevice device;
|
|
|
|
|
int button;
|
2001-11-25 04:31:44 +00:00
|
|
|
|
2001-11-25 10:49:31 +00:00
|
|
|
DeviceInput() { device=DEVICE_NONE; };
|
|
|
|
|
DeviceInput( InputDevice d, int b ) { device=d; button=b; };
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2001-12-19 01:50:57 +00:00
|
|
|
bool operator==( const DeviceInput &other )
|
|
|
|
|
{
|
|
|
|
|
return device == other.device && button == other.button;
|
|
|
|
|
};
|
|
|
|
|
|
2001-11-25 10:49:31 +00:00
|
|
|
CString GetDescription();
|
|
|
|
|
|
|
|
|
|
CString toString();
|
2002-03-30 20:00:13 +00:00
|
|
|
bool fromString( const CString &s );
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-07-31 19:40:40 +00:00
|
|
|
bool IsValid() const { return device != DEVICE_NONE; };
|
|
|
|
|
void MakeInvalid() { device = DEVICE_NONE; };
|
2002-08-20 22:51:12 +00:00
|
|
|
|
2002-08-23 20:18:29 +00:00
|
|
|
char ToChar() const;
|
|
|
|
|
|
2002-08-20 22:51:12 +00:00
|
|
|
static int NumButtons(InputDevice device);
|
2001-11-03 10:52:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RageInput
|
|
|
|
|
{
|
2002-11-29 20:37:12 +00:00
|
|
|
SDL_Joystick* m_pJoystick[NUM_JOYSTICKS];
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2003-02-15 06:44:53 +00:00
|
|
|
enum State { CURRENT = 0, LAST, NUM_STATES };
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2003-02-15 18:28:39 +00:00
|
|
|
struct state_t {
|
|
|
|
|
struct device_t {
|
|
|
|
|
bool button[NUM_DEVICE_BUTTONS];
|
|
|
|
|
} m_Devices[NUM_INPUT_DEVICES];
|
2003-02-15 06:44:53 +00:00
|
|
|
} state[NUM_STATES];
|
2002-08-20 22:51:12 +00:00
|
|
|
|
|
|
|
|
/* Structure for reading Pump pads: */
|
2003-02-15 06:00:33 +00:00
|
|
|
struct pump_t;
|
|
|
|
|
pump_t *m_Pumps;
|
2002-08-20 22:51:12 +00:00
|
|
|
|
2001-11-03 10:52:42 +00:00
|
|
|
public:
|
2002-11-29 20:37:12 +00:00
|
|
|
RageInput();
|
2001-11-03 10:52:42 +00:00
|
|
|
~RageInput();
|
|
|
|
|
|
2002-11-29 20:37:12 +00:00
|
|
|
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); }
|
2001-11-03 10:52:42 +00:00
|
|
|
};
|
|
|
|
|
|
2002-08-20 22:51:12 +00:00
|
|
|
namespace USB {
|
|
|
|
|
char *GetUSBDevicePath (int num);
|
2002-11-29 22:06:51 +00:00
|
|
|
HANDLE OpenUSB (int VID, int PID, int num);
|
2002-08-20 22:51:12 +00:00
|
|
|
};
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-05-19 01:59:48 +00:00
|
|
|
extern RageInput* INPUTMAN; // global and accessable from anywhere in our program
|
2002-11-11 04:53:31 +00:00
|
|
|
|
2002-11-16 08:07:38 +00:00
|
|
|
|
|
|
|
|
#endif
|