From 4d182f85a4188ad421b0fd5784f231861e403791 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Wed, 28 May 2003 02:35:05 +0000 Subject: [PATCH] add automatic mapping of joysticks --- stepmania/NEWS | 3 + stepmania/Themes/default/metrics.ini | 1 + stepmania/src/InputMapper.cpp | 109 ++++++++++++++++++ stepmania/src/InputMapper.h | 1 + stepmania/src/PrefsManager.cpp | 3 + stepmania/src/PrefsManager.h | 1 + stepmania/src/RageInput.cpp | 5 + stepmania/src/RageInput.h | 1 + stepmania/src/ScreenInputOptions.cpp | 6 +- stepmania/src/StepMania.cpp | 4 +- stepmania/src/StepMania.dsp | 10 +- stepmania/src/StepMania.vcproj | 12 +- .../src/arch/InputHandler/InputHandler.h | 2 + .../arch/InputHandler/InputHandler_SDL.cpp | 16 +++ .../src/arch/InputHandler/InputHandler_SDL.h | 1 + .../InputHandler/InputHandler_Win32_Pump.cpp | 12 ++ .../InputHandler/InputHandler_Win32_Pump.h | 1 + stepmania/src/archutils/Win32/USB.cpp | 5 + stepmania/src/archutils/Win32/USB.h | 1 + 19 files changed, 183 insertions(+), 11 deletions(-) diff --git a/stepmania/NEWS b/stepmania/NEWS index e36ef26b95..a012bedd4b 100644 --- a/stepmania/NEWS +++ b/stepmania/NEWS @@ -48,6 +48,9 @@ NEW FEATURE: New parameters for background changes: rate, fade old, loop, rewind. CHANGE: Background playback speed scaled by song rate, so movies stay in sync (although syncing isn't very accurate at some song rates). +NEW FEATURE: Automatic mapping of joysticks. +NEW FEATURE: Automatically adujst graphic detail on first run. +NEW FEATURE: #DISPLAYBPM tag for SM and DWI files. ----------------------- Version 3.01 --------------------------- CHANGE: Simplified NoteSkin tap graphic format. Old NoteSkins will need to diff --git a/stepmania/Themes/default/metrics.ini b/stepmania/Themes/default/metrics.ini index 70a0956470..afa782df23 100644 --- a/stepmania/Themes/default/metrics.ini +++ b/stepmania/Themes/default/metrics.ini @@ -1787,6 +1787,7 @@ AttackDurationSeconds=0 [ScreenInputOptions] HelpText=&UP; &DOWN; to change line &LEFT; &RIGHT; to select between options::START to accept changes BACK to discard changes +AutoMapJoysticks=&oq;ON&cq; will cause StepMania automatically create::mappings for the joysticks attached to your computer::at the time the program starts. This will::override any manually defined mappings. IgnoreJoyAxes=&oq;ON&cq; will cause StepMania to ignore all input from::joystick directional pads. This is useful for the DirectPad Pro driver::and some brands of USB convertors. MenuButtons=The default setting allows the dance pad's panels to navigate::the menus. Changing this to &oq;dedicated only&cq; will restrict::menu navigation to only the Menu* set of buttons. Be sure to map::the Menu* set of buttons before setting this to &oq;dedicated&cq;! AutoPlay=This option is useful for those who would like to play::without using a pad. However, you will not be able to set::high scores or earn extra stages while this options is ON. diff --git a/stepmania/src/InputMapper.cpp b/stepmania/src/InputMapper.cpp index 93f6de92d7..ec8505568e 100644 --- a/stepmania/src/InputMapper.cpp +++ b/stepmania/src/InputMapper.cpp @@ -17,6 +17,8 @@ #include "RageLog.h" #include "InputFilter.h" #include "RageUtil.h" +#include "PrefsManager.h" +#include "RageInput.h" InputMapper* INPUTMAPPER = NULL; // global and accessable from anywhere in our program @@ -63,6 +65,113 @@ void InputMapper::AddDefaultMappingsForCurrentGameIfUnmapped() } } +struct AutoJoyMapping +{ + Game game; + char sDeviceDescription[64]; + bool bIgnoreAxes; + int numMappings; + struct { + int deviceButton; + GameButton gb; + } mapping[32]; +}; +const AutoJoyMapping g_AutoJoyMappings[] = +{ + { + GAME_DANCE, + "GIC USB Joystick", + false, + 4, + { + { JOY_16, DANCE_BUTTON_LEFT }, + { JOY_14, DANCE_BUTTON_RIGHT }, + { JOY_13, DANCE_BUTTON_UP }, + { JOY_15, DANCE_BUTTON_DOWN }, + } + }, + { + GAME_DANCE, + "4 axis 16 button joystick", // likely a PC Magic Box + false, + 4, + { + { JOY_16, DANCE_BUTTON_LEFT }, + { JOY_14, DANCE_BUTTON_RIGHT }, + { JOY_13, DANCE_BUTTON_UP }, + { JOY_15, DANCE_BUTTON_DOWN }, + } + }, + { + GAME_DANCE, + "GamePad Pro USB ", // yes, there is a space at the end + false, + 12, + { + { JOY_LEFT, DANCE_BUTTON_LEFT }, + { JOY_RIGHT, DANCE_BUTTON_RIGHT }, + { JOY_UP, DANCE_BUTTON_UP }, + { JOY_DOWN, DANCE_BUTTON_DOWN }, + { JOY_1, DANCE_BUTTON_LEFT }, + { JOY_3, DANCE_BUTTON_RIGHT }, + { JOY_4, DANCE_BUTTON_UP }, + { JOY_2, DANCE_BUTTON_DOWN }, + { JOY_5, DANCE_BUTTON_UPLEFT }, + { JOY_6, DANCE_BUTTON_UPRIGHT }, + { JOY_9, DANCE_BUTTON_BACK }, + { JOY_10, DANCE_BUTTON_START }, + } + }, +}; +const int NUM_AUTO_JOY_MAPPINGS = sizeof(g_AutoJoyMappings) / sizeof(g_AutoJoyMappings[0]); + +void InputMapper::AutoMapJoysticksForCurrentGame() +{ + vector vDevices; + vector vDescriptions; + PREFSMAN->m_bIgnoreJoyAxes = false; + INPUTMAN->GetDevicesAndDescriptions(vDevices,vDescriptions); + for( unsigned i=0; im_bIgnoreJoyAxes |= mapping.bIgnoreAxes; + + GameController gc = GAME_CONTROLLER_INVALID; + switch( device ) + { + case DEVICE_JOY1: + case DEVICE_JOY3: + case DEVICE_PUMP1: + gc = GAME_CONTROLLER_1; + break; + case DEVICE_JOY2: + case DEVICE_JOY4: + case DEVICE_PUMP2: + gc = GAME_CONTROLLER_2; + break; + } + if( gc == GAME_CONTROLLER_INVALID ) + continue; + + for( unsigned k=0; kUpdate(fDeltaTime); } +void RageInput::GetDevicesAndDescriptions(vector& vDevicesOut, vector& vDescriptionsOut) +{ + for(unsigned i = 0; i < Devices.size(); ++i) + Devices[i]->GetDevicesAndDescriptions( vDevicesOut, vDescriptionsOut ); +} diff --git a/stepmania/src/RageInput.h b/stepmania/src/RageInput.h index c46b7fa150..9e013bb8f8 100644 --- a/stepmania/src/RageInput.h +++ b/stepmania/src/RageInput.h @@ -21,6 +21,7 @@ public: ~RageInput(); void Update( float fDeltaTime ); + void GetDevicesAndDescriptions(vector& vDevicesOut, vector& vDescriptionsOut); }; extern RageInput* INPUTMAN; // global and accessable from anywhere in our program diff --git a/stepmania/src/ScreenInputOptions.cpp b/stepmania/src/ScreenInputOptions.cpp index bec802b30f..f55d87da12 100644 --- a/stepmania/src/ScreenInputOptions.cpp +++ b/stepmania/src/ScreenInputOptions.cpp @@ -24,7 +24,8 @@ enum { - IO_IGNORE_AXES = 0, + IO_AUTO_MAP_JOYSTICKS = 0, + IO_IGNORE_AXES, IO_DEDICATED_MENU_BUTTONS, IO_AUTOPLAY, IO_DELAYED_ESCAPE, @@ -36,6 +37,7 @@ enum { /* Hmm. Ignore JoyAxes and Back Delayed probably belong in "key/joy config", * preferably alongside button configuration. */ OptionRow g_InputOptionsLines[NUM_INPUT_OPTIONS_LINES] = { + OptionRow( "Auto Map\nJoysticks", "OFF","ON (recommended)" ), OptionRow( "Ignore\nJoy Axes", "OFF","ON (for NTPad or DirectPad)" ), OptionRow( "Menu\nButtons", "USE GAMEPLAY BUTTONS","ONLY DEDICATED BUTTONS" ), OptionRow( "AutoPlay", "OFF","ON" ), @@ -61,6 +63,7 @@ ScreenInputOptions::ScreenInputOptions() : void ScreenInputOptions::ImportOptions() { + m_iSelectedOption[0][IO_AUTO_MAP_JOYSTICKS] = PREFSMAN->m_bAutoMapJoysticks ? 1:0; m_iSelectedOption[0][IO_IGNORE_AXES] = PREFSMAN->m_bIgnoreJoyAxes ? 1:0; m_iSelectedOption[0][IO_DEDICATED_MENU_BUTTONS] = PREFSMAN->m_bOnlyDedicatedMenuButtons ? 1:0; m_iSelectedOption[0][IO_AUTOPLAY] = PREFSMAN->m_bAutoPlay; @@ -74,6 +77,7 @@ void ScreenInputOptions::ImportOptions() void ScreenInputOptions::ExportOptions() { + PREFSMAN->m_bAutoMapJoysticks = m_iSelectedOption[0][IO_AUTO_MAP_JOYSTICKS] == 1; PREFSMAN->m_bIgnoreJoyAxes = m_iSelectedOption[0][IO_IGNORE_AXES] == 1; PREFSMAN->m_bOnlyDedicatedMenuButtons= m_iSelectedOption[0][IO_DEDICATED_MENU_BUTTONS] == 1; PREFSMAN->m_bDelayedEscape = m_iSelectedOption[0][IO_DELAYED_ESCAPE] == 1; diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index 7ea1afd661..b0bfb29bec 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -153,6 +153,9 @@ void ResetGame() else SCREENMAN->SetNewScreen( THEME->GetMetric("Common","InitialScreen") ); PREFSMAN->m_bFirstRun = false; + + if( PREFSMAN->m_bAutoMapJoysticks ) + INPUTMAPPER->AutoMapJoysticksForCurrentGame(); } static void GameLoop(); @@ -402,7 +405,6 @@ int main(int argc, char* argv[]) SONGINDEX = new SongCacheIndex; /* depends on SONGINDEX: */ SONGMAN = new SongManager( loading_window ); // this takes a long time to load - delete loading_window; // destroy this before init'ing Display PREFSMAN->ReadGlobalPrefsFromDisk( true ); diff --git a/stepmania/src/StepMania.dsp b/stepmania/src/StepMania.dsp index d8934cf739..878e375e34 100644 --- a/stepmania/src/StepMania.dsp +++ b/stepmania/src/StepMania.dsp @@ -64,7 +64,7 @@ IntDir=.\../Debug6 TargetDir=\stepmania\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 @@ -104,7 +104,7 @@ IntDir=.\StepMania___Xbox_Debug___VC6 TargetDir=.\StepMania___Xbox_Debug___VC6 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 @@ -144,7 +144,7 @@ IntDir=.\../Release6 TargetDir=\stepmania\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 @@ -336,6 +336,10 @@ SOURCE=.\RageInput.cpp # End Source File # Begin Source File +SOURCE=.\RageInput.h +# End Source File +# Begin Source File + SOURCE=.\RageInputDevice.cpp !IF "$(CFG)" == "StepMania - Win32 Debug" diff --git a/stepmania/src/StepMania.vcproj b/stepmania/src/StepMania.vcproj index ea668bf05e..af81ffb363 100644 --- a/stepmania/src/StepMania.vcproj +++ b/stepmania/src/StepMania.vcproj @@ -31,9 +31,9 @@ RuntimeLibrary="2" UsePrecompiledHeader="2" PrecompiledHeaderFile="$(IntDir)/StepMania.pch" - AssemblerListingLocation=".\../Debug_OGL/" - ObjectFile=".\../Debug_OGL/" - ProgramDataBaseFileName=".\../Debug_OGL/" + AssemblerListingLocation=".\../Debug/" + ObjectFile=".\../Debug/" + ProgramDataBaseFileName=".\../Debug/" BrowseInformation="0" WarningLevel="4" SuppressStartupBanner="TRUE" @@ -110,9 +110,9 @@ cl /Zl /nologo /c verstub.cpp /Fo"$(IntDir)"\ UsePrecompiledHeader="2" PrecompiledHeaderThrough="global.h" PrecompiledHeaderFile="$(IntDir)/StepMania.pch" - AssemblerListingLocation=".\../Release_OGL/" - ObjectFile=".\../Release_OGL/" - ProgramDataBaseFileName=".\../Release_OGL/" + AssemblerListingLocation=".\../Release/" + ObjectFile=".\../Release/" + ProgramDataBaseFileName=".\../Release/" BrowseInformation="1" WarningLevel="4" SuppressStartupBanner="TRUE" diff --git a/stepmania/src/arch/InputHandler/InputHandler.h b/stepmania/src/arch/InputHandler/InputHandler.h index 49da6cc527..4b32ebefa8 100644 --- a/stepmania/src/arch/InputHandler/InputHandler.h +++ b/stepmania/src/arch/InputHandler/InputHandler.h @@ -22,12 +22,14 @@ * input for the same device; we have no method to allocate device numbers. * We don't need this now; I'll write it if it becomes needed.) */ +#include "RageInputDevice.h" // for InputDevice class InputHandler { public: virtual void Update(float fDeltaTime) { } virtual ~InputHandler() { } + virtual void GetDevicesAndDescriptions(vector& vDevicesOut, vector& vDescriptionsOut) = 0; }; #endif diff --git a/stepmania/src/arch/InputHandler/InputHandler_SDL.cpp b/stepmania/src/arch/InputHandler/InputHandler_SDL.cpp index d52dc71f41..cf9ceef959 100644 --- a/stepmania/src/arch/InputHandler/InputHandler_SDL.cpp +++ b/stepmania/src/arch/InputHandler/InputHandler_SDL.cpp @@ -132,6 +132,22 @@ void InputHandler_SDL::Update(float fDeltaTime) } } + +void InputHandler_SDL::GetDevicesAndDescriptions(vector& vDevicesOut, vector& vDescriptionsOut) +{ + vDevicesOut.push_back( DEVICE_KEYBOARD ); + vDescriptionsOut.push_back( "Keyboard" ); + + for( int i=0; i& vDevicesOut, vector& vDescriptionsOut); }; diff --git a/stepmania/src/arch/InputHandler/InputHandler_Win32_Pump.cpp b/stepmania/src/arch/InputHandler/InputHandler_Win32_Pump.cpp index 4a6aee25d5..b5d3836289 100644 --- a/stepmania/src/arch/InputHandler/InputHandler_Win32_Pump.cpp +++ b/stepmania/src/arch/InputHandler/InputHandler_Win32_Pump.cpp @@ -46,6 +46,18 @@ void InputHandler_Win32_Pump::Update(float fDeltaTime) } } +void InputHandler_Win32_Pump::GetDevicesAndDescriptions(vector& vDevicesOut, vector& vDescriptionsOut) +{ + for(int i = 0; i < NUM_PUMPS; ++i) + { + if( dev[i].IsOpen() ) + { + vDevicesOut.push_back( InputDevice(DEVICE_PUMP1+i) ); + vDescriptionsOut.push_back( "Pump USB" ); + } + } +} + /* ----------------------------------------------------------------------------- Copyright (c) 2002-2003 by the person(s) listed below. All rights reserved. diff --git a/stepmania/src/arch/InputHandler/InputHandler_Win32_Pump.h b/stepmania/src/arch/InputHandler/InputHandler_Win32_Pump.h index 6bfbcadf15..84888f517e 100644 --- a/stepmania/src/arch/InputHandler/InputHandler_Win32_Pump.h +++ b/stepmania/src/arch/InputHandler/InputHandler_Win32_Pump.h @@ -12,6 +12,7 @@ public: void Update(float fDeltaTime); InputHandler_Win32_Pump(); ~InputHandler_Win32_Pump(); + void GetDevicesAndDescriptions(vector& vDevicesOut, vector& vDescriptionsOut); }; #endif diff --git a/stepmania/src/archutils/Win32/USB.cpp b/stepmania/src/archutils/Win32/USB.cpp index 678ef111b1..890f1aecad 100644 --- a/stepmania/src/archutils/Win32/USB.cpp +++ b/stepmania/src/archutils/Win32/USB.cpp @@ -108,6 +108,11 @@ bool USBDevice::Open(int VID, int PID, int num) return h != INVALID_HANDLE_VALUE; } +bool USBDevice::IsOpen() +{ + return h != INVALID_HANDLE_VALUE; +} + int USBDevice::GetPadEvent() { if(h == INVALID_HANDLE_VALUE) diff --git a/stepmania/src/archutils/Win32/USB.h b/stepmania/src/archutils/Win32/USB.h index e58d95507f..5f14e15511 100644 --- a/stepmania/src/archutils/Win32/USB.h +++ b/stepmania/src/archutils/Win32/USB.h @@ -8,6 +8,7 @@ public: ~USBDevice(); int GetPadEvent(); bool Open(int VID, int PID, int num); + bool IsOpen(); private: HANDLE h;