From 93632078c56cf84d4256b63fae03f9265816990b Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 15 Feb 2003 18:49:18 +0000 Subject: [PATCH] split InputDevice into a separate file (so RageInput.h can be edited without recompiling everything) --- stepmania/src/RageInput.cpp | 153 --------------------------- stepmania/src/RageInput.h | 72 ++----------- stepmania/src/RageInputDevice.cpp | 166 ++++++++++++++++++++++++++++++ stepmania/src/RageInputDevice.h | 72 +++++++++++++ stepmania/src/Screen.h | 2 +- stepmania/src/StepMania.dsp | 10 +- stepmania/src/StepMania.vcproj | 6 ++ 7 files changed, 261 insertions(+), 220 deletions(-) create mode 100644 stepmania/src/RageInputDevice.cpp create mode 100644 stepmania/src/RageInputDevice.h diff --git a/stepmania/src/RageInput.cpp b/stepmania/src/RageInput.cpp index d64c8448ba..810df38f1b 100644 --- a/stepmania/src/RageInput.cpp +++ b/stepmania/src/RageInput.cpp @@ -29,11 +29,6 @@ RageInput* INPUTMAN = NULL; // globally accessable input device -static const char *PumpButtonNames[] = { - "UL", "UR", "MID", "DL", "DR", "Esc", - "P2 UL", "P2 UR", "P2 MID", "P2 DL", "P2 DR" -}; - struct RageInput::pump_t { HANDLE h; @@ -50,154 +45,6 @@ struct RageInput::pump_t bool current_state[NUM_PUMP_PAD_BUTTONS]; }; -int DeviceInput::NumButtons(InputDevice device) -{ - switch( device ) - { - case DEVICE_KEYBOARD: - return NUM_KEYBOARD_BUTTONS; - case DEVICE_JOY1: - case DEVICE_JOY2: - case DEVICE_JOY3: - case DEVICE_JOY4: - return NUM_JOYSTICK_BUTTONS; - case DEVICE_PUMP1: - case DEVICE_PUMP2: - return NUM_PUMP_PAD_BUTTONS; - default: - ASSERT(0); // invalid device - } - return -1; /* quiet compiler */ -} - -CString DeviceInput::GetDescription() -{ - CString sReturn; - - switch( device ) - { - case DEVICE_NONE: // blank - ASSERT( false ); // called GetDescription on a blank DeviceInput! - break; - - case DEVICE_JOY1: // joystick - case DEVICE_JOY2: - case DEVICE_JOY3: - case DEVICE_JOY4: - sReturn = ssprintf("Joy%d ", device - DEVICE_JOY1 + 1 ); - - switch( button ) - { - case JOY_LEFT: sReturn += "Left"; break; - case JOY_RIGHT: sReturn += "Right"; break; - case JOY_UP: sReturn += "Up"; break; - case JOY_DOWN: sReturn += "Down"; break; - case JOY_Z_UP: sReturn += "Z-Up"; break; - case JOY_Z_DOWN: sReturn += "Z-Down"; break; - case JOY_Z_ROT_UP: sReturn += "ZR-Up"; break; - case JOY_Z_ROT_DOWN:sReturn += "ZR-Down"; break; - case JOY_HAT_LEFT: sReturn += "H-Left"; break; - case JOY_HAT_RIGHT: sReturn += "H-Right"; break; - case JOY_HAT_UP: sReturn += "H-Up"; break; - case JOY_HAT_DOWN: sReturn += "H-Down"; break; - case JOY_1: sReturn += "1"; break; - case JOY_2: sReturn += "2"; break; - case JOY_3: sReturn += "3"; break; - case JOY_4: sReturn += "4"; break; - case JOY_5: sReturn += "5"; break; - case JOY_6: sReturn += "6"; break; - case JOY_7: sReturn += "7"; break; - case JOY_8: sReturn += "8"; break; - case JOY_9: sReturn += "9"; break; - case JOY_10: sReturn += "10"; break; - case JOY_11: sReturn += "11"; break; - case JOY_12: sReturn += "12"; break; - case JOY_13: sReturn += "13"; break; - case JOY_14: sReturn += "14"; break; - case JOY_15: sReturn += "15"; break; - case JOY_16: sReturn += "16"; break; - case JOY_17: sReturn += "17"; break; - case JOY_18: sReturn += "18"; break; - case JOY_19: sReturn += "19"; break; - case JOY_20: sReturn += "20"; break; - case JOY_21: sReturn += "21"; break; - case JOY_22: sReturn += "22"; break; - case JOY_23: sReturn += "23"; break; - case JOY_24: sReturn += "24"; break; - } - - break; - - case DEVICE_PUMP1: - case DEVICE_PUMP2: - /* There is almost always only one Pump device, even if there are - * two pads, so only enumerate the second and higher. */ - if(device == DEVICE_PUMP1) - sReturn = ssprintf("PIU "); - else - sReturn = ssprintf("PIU#%d ", device - DEVICE_PUMP1 + 1 ); - - if(button < NUM_PUMP_PAD_BUTTONS) - sReturn += PumpButtonNames[button]; - else - /* This can happen if the INI is corrupt and has an invalid - * button number. Crashing with an assertion failure because - * we got something unexpected is no good. */ - sReturn += "???"; - - break; - - case DEVICE_KEYBOARD: // keyboard - sReturn = ssprintf("Key %s", SDL_GetKeyName((SDLKey)button) ); - break; - default: - ASSERT(0); // what device is this? - } - - return sReturn; -} - -CString DeviceInput::toString() -{ - if( device == DEVICE_NONE ) - return ""; - else - return ssprintf("%d-%d", device, button ); -} - -bool DeviceInput::fromString( const CString &s ) -{ - CStringArray a; - split( s, "-", a); - - if( a.size() != 2 ) { - device = DEVICE_NONE; - return false; - } - - device = (InputDevice)atoi( a[0] ); - button = atoi( a[1] ); - return true; -} - - -char DeviceInput::ToChar() const -{ - switch( device ) - { - case DEVICE_KEYBOARD: - if( button < 128 ) - return (char) button; - /* XXX: SDLK_WORLD_* are for international keyboards; we can handle those, - * now, by mapping it to Unicode. However, I can't find any documentation - * on those keysyms. */ - return '\0'; - default: - return '\0'; - } -} - - RageInput::RageInput() { LOG->Trace( "RageInput::RageInput()" ); diff --git a/stepmania/src/RageInput.h b/stepmania/src/RageInput.h index b1aff7c304..c8e4f430c1 100644 --- a/stepmania/src/RageInput.h +++ b/stepmania/src/RageInput.h @@ -11,74 +11,11 @@ ----------------------------------------------------------------------------- */ +#include "RageInputDevice.h" + struct _SDL_Joystick; typedef struct _SDL_Joystick SDL_Joystick; -#include "SDL_keysym.h" - -const int NUM_KEYBOARD_BUTTONS = SDLK_LAST; -const int NUM_JOYSTICKS = 4; -const int NUM_JOYSTICK_AXES = 4; // X, Y, Z, rudder -const int NUM_JOYSTICK_HATS = 1; -const int NUM_PUMPS = 2; -const int NUM_PUMP_PAD_BUTTONS = 11; - -const int NUM_DEVICE_BUTTONS = NUM_KEYBOARD_BUTTONS; - -enum InputDevice { - DEVICE_KEYBOARD = 0, - DEVICE_JOY1, - DEVICE_JOY2, - DEVICE_JOY3, - DEVICE_JOY4, - DEVICE_PUMP1, - DEVICE_PUMP2, - NUM_INPUT_DEVICES, // leave this at the end - DEVICE_NONE // means this is NULL -}; - -// button byte codes for directional pad -enum JoystickButton { - JOY_LEFT = 0, JOY_RIGHT, - JOY_UP, JOY_DOWN, - JOY_Z_UP, JOY_Z_DOWN, - JOY_Z_ROT_UP, JOY_Z_ROT_DOWN, - JOY_HAT_LEFT, JOY_HAT_RIGHT, JOY_HAT_UP, JOY_HAT_DOWN, - 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, - NUM_JOYSTICK_BUTTONS // leave this at the end -}; - - -struct DeviceInput -{ -public: - InputDevice device; - int button; - - DeviceInput() { device=DEVICE_NONE; }; - DeviceInput( InputDevice d, int b ) { device=d; button=b; }; - - bool operator==( const DeviceInput &other ) - { - return device == other.device && button == other.button; - }; - - CString GetDescription(); - - CString toString(); - bool fromString( const CString &s ); - - bool IsValid() const { return device != DEVICE_NONE; }; - void MakeInvalid() { device = DEVICE_NONE; }; - - char ToChar() const; - - static int NumButtons(InputDevice device); -}; - - class RageInput { SDL_Joystick* m_pJoystick[NUM_JOYSTICKS]; @@ -114,3 +51,8 @@ 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. + * Chris Danford + * Glenn Maynard + */ diff --git a/stepmania/src/RageInputDevice.cpp b/stepmania/src/RageInputDevice.cpp new file mode 100644 index 0000000000..9d5dc96347 --- /dev/null +++ b/stepmania/src/RageInputDevice.cpp @@ -0,0 +1,166 @@ +/* + * Define all of the input devices we know about. + */ + +#include "stdafx.h" +#include "RageInputDevice.h" +#include "RageUtil.h" + +#include "SDL_keyboard.h" + +static const char *PumpButtonNames[] = { + "UL", "UR", "MID", "DL", "DR", "Esc", + "P2 UL", "P2 UR", "P2 MID", "P2 DL", "P2 DR" +}; + +int DeviceInput::NumButtons(InputDevice device) +{ + switch( device ) + { + case DEVICE_KEYBOARD: + return NUM_KEYBOARD_BUTTONS; + case DEVICE_JOY1: + case DEVICE_JOY2: + case DEVICE_JOY3: + case DEVICE_JOY4: + return NUM_JOYSTICK_BUTTONS; + case DEVICE_PUMP1: + case DEVICE_PUMP2: + return NUM_PUMP_PAD_BUTTONS; + default: + ASSERT(0); // invalid device + } + return -1; /* quiet compiler */ +} + +CString DeviceInput::GetDescription() +{ + CString sReturn; + + switch( device ) + { + case DEVICE_NONE: // blank + ASSERT( false ); // called GetDescription on a blank DeviceInput! + break; + + case DEVICE_JOY1: // joystick + case DEVICE_JOY2: + case DEVICE_JOY3: + case DEVICE_JOY4: + sReturn = ssprintf("Joy%d ", device - DEVICE_JOY1 + 1 ); + + switch( button ) + { + case JOY_LEFT: sReturn += "Left"; break; + case JOY_RIGHT: sReturn += "Right"; break; + case JOY_UP: sReturn += "Up"; break; + case JOY_DOWN: sReturn += "Down"; break; + case JOY_Z_UP: sReturn += "Z-Up"; break; + case JOY_Z_DOWN: sReturn += "Z-Down"; break; + case JOY_Z_ROT_UP: sReturn += "ZR-Up"; break; + case JOY_Z_ROT_DOWN:sReturn += "ZR-Down"; break; + case JOY_HAT_LEFT: sReturn += "H-Left"; break; + case JOY_HAT_RIGHT: sReturn += "H-Right"; break; + case JOY_HAT_UP: sReturn += "H-Up"; break; + case JOY_HAT_DOWN: sReturn += "H-Down"; break; + case JOY_1: sReturn += "1"; break; + case JOY_2: sReturn += "2"; break; + case JOY_3: sReturn += "3"; break; + case JOY_4: sReturn += "4"; break; + case JOY_5: sReturn += "5"; break; + case JOY_6: sReturn += "6"; break; + case JOY_7: sReturn += "7"; break; + case JOY_8: sReturn += "8"; break; + case JOY_9: sReturn += "9"; break; + case JOY_10: sReturn += "10"; break; + case JOY_11: sReturn += "11"; break; + case JOY_12: sReturn += "12"; break; + case JOY_13: sReturn += "13"; break; + case JOY_14: sReturn += "14"; break; + case JOY_15: sReturn += "15"; break; + case JOY_16: sReturn += "16"; break; + case JOY_17: sReturn += "17"; break; + case JOY_18: sReturn += "18"; break; + case JOY_19: sReturn += "19"; break; + case JOY_20: sReturn += "20"; break; + case JOY_21: sReturn += "21"; break; + case JOY_22: sReturn += "22"; break; + case JOY_23: sReturn += "23"; break; + case JOY_24: sReturn += "24"; break; + } + + break; + + case DEVICE_PUMP1: + case DEVICE_PUMP2: + /* There is almost always only one Pump device, even if there are + * two pads, so only enumerate the second and higher. */ + if(device == DEVICE_PUMP1) + sReturn = ssprintf("PIU "); + else + sReturn = ssprintf("PIU#%d ", device - DEVICE_PUMP1 + 1 ); + + if(button < NUM_PUMP_PAD_BUTTONS) + sReturn += PumpButtonNames[button]; + else + /* This can happen if the INI is corrupt and has an invalid + * button number. Crashing with an assertion failure because + * we got something unexpected is no good. */ + sReturn += "???"; + + break; + + case DEVICE_KEYBOARD: // keyboard + sReturn = ssprintf("Key %s", SDL_GetKeyName((SDLKey)button) ); + break; + default: + ASSERT(0); // what device is this? + } + + return sReturn; +} + +CString DeviceInput::toString() +{ + if( device == DEVICE_NONE ) + return ""; + else + return ssprintf("%d-%d", device, button ); +} + +bool DeviceInput::fromString( const CString &s ) +{ + CStringArray a; + split( s, "-", a); + + if( a.size() != 2 ) { + device = DEVICE_NONE; + return false; + } + + device = (InputDevice)atoi( a[0] ); + button = atoi( a[1] ); + return true; +} + + +char DeviceInput::ToChar() const +{ + switch( device ) + { + case DEVICE_KEYBOARD: + if( button < 128 ) + return (char) button; + /* XXX: SDLK_WORLD_* are for international keyboards; we can handle those, + * now, by mapping it to Unicode. However, I can't find any documentation + * on those keysyms. */ + return '\0'; + default: + return '\0'; + } +} + +/* + * Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved. + * Chris Danford + */ diff --git a/stepmania/src/RageInputDevice.h b/stepmania/src/RageInputDevice.h new file mode 100644 index 0000000000..45fa909cd3 --- /dev/null +++ b/stepmania/src/RageInputDevice.h @@ -0,0 +1,72 @@ +#ifndef RAGEINPUTDEVICE_H +#define RAGEINPUTDEVICE_H 1 + +#include "SDL_keysym.h" + +const int NUM_KEYBOARD_BUTTONS = SDLK_LAST; +const int NUM_JOYSTICKS = 4; +const int NUM_JOYSTICK_AXES = 4; // X, Y, Z, rudder +const int NUM_JOYSTICK_HATS = 1; +const int NUM_PUMPS = 2; +const int NUM_PUMP_PAD_BUTTONS = 11; + +const int NUM_DEVICE_BUTTONS = NUM_KEYBOARD_BUTTONS; + +enum InputDevice { + DEVICE_KEYBOARD = 0, + DEVICE_JOY1, + DEVICE_JOY2, + DEVICE_JOY3, + DEVICE_JOY4, + DEVICE_PUMP1, + DEVICE_PUMP2, + NUM_INPUT_DEVICES, // leave this at the end + DEVICE_NONE // means this is NULL +}; + +// button byte codes for directional pad +enum JoystickButton { + JOY_LEFT = 0, JOY_RIGHT, + JOY_UP, JOY_DOWN, + JOY_Z_UP, JOY_Z_DOWN, + JOY_Z_ROT_UP, JOY_Z_ROT_DOWN, + JOY_HAT_LEFT, JOY_HAT_RIGHT, JOY_HAT_UP, JOY_HAT_DOWN, + 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, + NUM_JOYSTICK_BUTTONS // leave this at the end +}; + + +struct DeviceInput +{ +public: + InputDevice device; + int button; + + DeviceInput() { device=DEVICE_NONE; }; + DeviceInput( InputDevice d, int b ) { device=d; button=b; }; + + bool operator==( const DeviceInput &other ) + { + return device == other.device && button == other.button; + }; + + CString GetDescription(); + + CString toString(); + bool fromString( const CString &s ); + + bool IsValid() const { return device != DEVICE_NONE; }; + void MakeInvalid() { device = DEVICE_NONE; }; + + char ToChar() const; + + static int NumButtons(InputDevice device); +}; + +#endif +/* + * Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved. + * Chris Danford + */ diff --git a/stepmania/src/Screen.h b/stepmania/src/Screen.h index 71b23384fd..91cfaf93ec 100644 --- a/stepmania/src/Screen.h +++ b/stepmania/src/Screen.h @@ -11,7 +11,7 @@ ----------------------------------------------------------------------------- */ -#include "RageInput.h" +#include "RageInputDevice.h" #include "ActorFrame.h" #include "ScreenMessage.h" #include "InputFilter.h" diff --git a/stepmania/src/StepMania.dsp b/stepmania/src/StepMania.dsp index 516b82f37b..59a02e93e4 100644 --- a/stepmania/src/StepMania.dsp +++ b/stepmania/src/StepMania.dsp @@ -195,7 +195,15 @@ SOURCE=.\RageInput.cpp # End Source File # Begin Source File -SOURCE=.\RageInput.h +SOURCE=.\RageInput.cpp +# End Source File +# Begin Source File + +SOURCE=.\RageInputDevice.cpp +# End Source File +# Begin Source File + +SOURCE=.\RageInputDevice.h # End Source File # Begin Source File diff --git a/stepmania/src/StepMania.vcproj b/stepmania/src/StepMania.vcproj index 89592b2c98..4320f0fc1d 100644 --- a/stepmania/src/StepMania.vcproj +++ b/stepmania/src/StepMania.vcproj @@ -1313,6 +1313,12 @@ cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ + + + +