From 722941a6464ceb3c566c8b431be8727aa50e44d8 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sat, 16 Oct 2004 15:04:10 +0000 Subject: [PATCH] add monkey scripting input driver for longevity testing --- stepmania/src/Makefile.am | 3 +- stepmania/src/PrefsManager.cpp | 9 +- stepmania/src/PrefsManager.h | 1 + stepmania/src/RageInput.cpp | 4 +- stepmania/src/RageInput.h | 2 +- stepmania/src/ScreenAttract.cpp | 2 +- stepmania/src/StepMania.cpp | 2 +- stepmania/src/StepMania.dsp | 12 ++- stepmania/src/StepMania.vcproj | 6 ++ .../InputHandler_MonkeyKeyboard.cpp | 100 ++++++++++++++++++ .../InputHandler_MonkeyKeyboard.h | 46 ++++++++ stepmania/src/arch/arch.cpp | 45 +++++--- stepmania/src/arch/arch.h | 10 +- stepmania/src/arch/arch_default.h | 1 + 14 files changed, 216 insertions(+), 27 deletions(-) create mode 100644 stepmania/src/arch/InputHandler/InputHandler_MonkeyKeyboard.cpp create mode 100644 stepmania/src/arch/InputHandler/InputHandler_MonkeyKeyboard.h diff --git a/stepmania/src/Makefile.am b/stepmania/src/Makefile.am index ddbf1603e5..8686f08be9 100644 --- a/stepmania/src/Makefile.am +++ b/stepmania/src/Makefile.am @@ -106,7 +106,8 @@ endif ArchHooks = arch/ArchHooks/ArchHooks.cpp arch/ArchHooks/ArchHooks.h -InputHandler = arch/InputHandler/InputHandler.cpp arch/InputHandler/InputHandler.h +InputHandler = arch/InputHandler/InputHandler.cpp arch/InputHandler/InputHandler.h \ + arch/InputHandler/InputHandler_MonkeyKeyboard.cpp arch/InputHandler/InputHandler_MonkeyKeyboard.h MovieTexture = arch/MovieTexture/MovieTexture.cpp arch/MovieTexture/MovieTexture.h \ arch/MovieTexture/MovieTexture_Null.cpp arch/MovieTexture/MovieTexture_Null.h diff --git a/stepmania/src/PrefsManager.cpp b/stepmania/src/PrefsManager.cpp index ffd8d5c9e3..4ce3f616c3 100644 --- a/stepmania/src/PrefsManager.cpp +++ b/stepmania/src/PrefsManager.cpp @@ -271,6 +271,8 @@ void PrefsManager::Init() m_fSoundVolume = DEFAULT_SOUND_VOLUME; m_iSoundResampleQuality = RageSoundReader_Resample::RESAMP_NORMAL; + m_sInputDrivers = DEFAULT_INPUT_DRIVER_LIST; + m_sMovieDrivers = DEFAULT_MOVIE_DRIVER_LIST; // StepMania.cpp sets these on first run: @@ -467,6 +469,7 @@ void PrefsManager::ReadPrefsFromFile( CString sIni ) ini.GetValue( "Options", "SoundDrivers", m_sSoundDrivers ); ini.GetValue( "Options", "SoundWriteAhead", m_iSoundWriteAhead ); ini.GetValue( "Options", "SoundDevice", m_iSoundDevice ); + ini.GetValue( "Options", "InputDrivers", m_sInputDrivers ); ini.GetValue( "Options", "MovieDrivers", m_sMovieDrivers ); ini.GetValue( "Options", "EasterEggs", m_bEasterEggs ); ini.GetValue( "Options", "MarvelousTiming", (int&)m_iMarvelousTiming ); @@ -809,10 +812,12 @@ void PrefsManager::SaveGlobalPrefsToDisk() const ini.SetValue ( "Options", "SoundDrivers", m_sSoundDrivers ); if(m_fSoundVolume != DEFAULT_SOUND_VOLUME) ini.SetValue( "Options", "SoundVolume", m_fSoundVolume ); - if(m_sLightsDriver != DEFAULT_LIGHTS_DRIVER) - ini.SetValue( "Options", "LightsDriver", m_sLightsDriver ); + if(m_sInputDrivers != DEFAULT_INPUT_DRIVER_LIST) + ini.SetValue ( "Options", "InputDrivers", m_sInputDrivers ); if(m_sMovieDrivers != DEFAULT_MOVIE_DRIVER_LIST) ini.SetValue ( "Options", "MovieDrivers", m_sMovieDrivers ); + if(m_sLightsDriver != DEFAULT_LIGHTS_DRIVER) + ini.SetValue( "Options", "LightsDriver", m_sLightsDriver ); ini.SetValue( "Options", "AdditionalSongFolders", m_sAdditionalSongFolders); ini.SetValue( "Options", "AdditionalFolders", m_sAdditionalFolders); diff --git a/stepmania/src/PrefsManager.h b/stepmania/src/PrefsManager.h index b97f10fc0a..cbdf785719 100644 --- a/stepmania/src/PrefsManager.h +++ b/stepmania/src/PrefsManager.h @@ -251,6 +251,7 @@ public: CString m_iSoundDevice; float m_fSoundVolume; int m_iSoundResampleQuality; + CString m_sInputDrivers; CString m_sMovieDrivers; CString m_sLightsDriver; CString m_sLightsStepsDifficulty; diff --git a/stepmania/src/RageInput.cpp b/stepmania/src/RageInput.cpp index 053553f195..6dc600669c 100644 --- a/stepmania/src/RageInput.cpp +++ b/stepmania/src/RageInput.cpp @@ -7,12 +7,12 @@ RageInput* INPUTMAN = NULL; // globally accessable input device -RageInput::RageInput() +RageInput::RageInput( CString drivers ) { LOG->Trace( "RageInput::RageInput()" ); /* Init optional devices. */ - MakeInputHandlers(Devices); + MakeInputHandlers(drivers,Devices); /* If no input devices are loaded, the user won't be able to input anything. * That should never happen. */ diff --git a/stepmania/src/RageInput.h b/stepmania/src/RageInput.h index d02e7b406b..a3f29639dd 100644 --- a/stepmania/src/RageInput.h +++ b/stepmania/src/RageInput.h @@ -11,7 +11,7 @@ class RageInput vector Devices; public: - RageInput(); + RageInput( CString drivers ); ~RageInput(); void Update( float fDeltaTime ); diff --git a/stepmania/src/ScreenAttract.cpp b/stepmania/src/ScreenAttract.cpp index fc42f7af43..d6bf2591b7 100644 --- a/stepmania/src/ScreenAttract.cpp +++ b/stepmania/src/ScreenAttract.cpp @@ -99,7 +99,7 @@ void ScreenAttract::AttractInput( const DeviceInput& DeviceI, const InputEventTy if( MenuI.button != MENU_BUTTON_COIN ) SCREENMAN->PlayCoinSound(); SCREENMAN->SendMessageToTopScreen( SM_StopMusic ); - usleep( (int)(JOIN_PAUSE_SECONDS*1000000) ); // do a little pause, like the arcade does + usleep( (int)(JOIN_PAUSE_SECONDS*1000*1000) ); // do a little pause, like the arcade does LOG->Trace("ScreenAttract::AttractInput: go to ScreenTitleMenu" ); SCREENMAN->SetNewScreen( "ScreenTitleMenu" ); break; diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index 4bf0959dda..42a5848fbb 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -1093,7 +1093,7 @@ int main(int argc, char* argv[]) /* This initializes objects that change the SDL event mask, and has other * dependencies on the SDL video subsystem, so it must be initialized after DISPLAY. */ - INPUTMAN = new RageInput; + INPUTMAN = new RageInput( PREFSMAN->m_sInputDrivers ); // These things depend on the TextureManager, so do them after! FONT = new FontManager; diff --git a/stepmania/src/StepMania.dsp b/stepmania/src/StepMania.dsp index 671aa5848b..87d7339021 100644 --- a/stepmania/src/StepMania.dsp +++ b/stepmania/src/StepMania.dsp @@ -62,7 +62,7 @@ IntDir=.\../Debug6 TargetDir=\temp\stepmania\Program TargetName=StepMania-debug SOURCE="$(InputPath)" -PreLink_Cmds=archutils\Win32\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ +PreLink_Cmds=archutils\Win32\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ PostBuild_Cmds=archutils\Win32\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi # End Special Build Tool @@ -99,7 +99,7 @@ IntDir=.\../Release6 TargetDir=\temp\stepmania\Program TargetName=StepMania SOURCE="$(InputPath)" -PreLink_Cmds=archutils\Win32\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ +PreLink_Cmds=archutils\Win32\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ PostBuild_Cmds=archutils\Win32\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi # End Special Build Tool @@ -1218,6 +1218,14 @@ SOURCE=.\arch\InputHandler\InputHandler_DirectInputHelper.h # End Source File # Begin Source File +SOURCE=.\arch\InputHandler\InputHandler_MonkeyKeyboard.cpp +# End Source File +# Begin Source File + +SOURCE=.\arch\InputHandler\InputHandler_MonkeyKeyboard.h +# End Source File +# Begin Source File + SOURCE=.\arch\InputHandler\InputHandler_Win32_Para.cpp # End Source File # Begin Source File diff --git a/stepmania/src/StepMania.vcproj b/stepmania/src/StepMania.vcproj index 3df06bd27b..d30541e9b8 100644 --- a/stepmania/src/StepMania.vcproj +++ b/stepmania/src/StepMania.vcproj @@ -1069,6 +1069,12 @@ cl /Zl /nologo /c verstub.cpp /Fo"$(IntDir)"\ + + + + diff --git a/stepmania/src/arch/InputHandler/InputHandler_MonkeyKeyboard.cpp b/stepmania/src/arch/InputHandler/InputHandler_MonkeyKeyboard.cpp new file mode 100644 index 0000000000..6771ae2aca --- /dev/null +++ b/stepmania/src/arch/InputHandler/InputHandler_MonkeyKeyboard.cpp @@ -0,0 +1,100 @@ +#include "global.h" +#include "InputHandler_MonkeyKeyboard.h" +#include "RageUtil.h" + + +InputHandler_MonkeyKeyboard::InputHandler_MonkeyKeyboard() : + m_diLast(DEVICE_KEYBOARD,KEY_SPACE) +{ +} + +InputHandler_MonkeyKeyboard::~InputHandler_MonkeyKeyboard() +{ +} + +void InputHandler_MonkeyKeyboard::GetDevicesAndDescriptions(vector& vDevicesOut, vector& vDescriptionsOut) +{ + vDevicesOut.push_back( InputDevice(DEVICE_KEYBOARD) ); + vDescriptionsOut.push_back( "MonkeyKeyboard" ); +} + +static const int g_keys[] = +{ + // Some of the default keys for the dance game type + KEY_LEFT, // DANCE_BUTTON_LEFT, + KEY_RIGHT, // DANCE_BUTTON_RIGHT, + KEY_UP, // DANCE_BUTTON_UP, + KEY_DOWN, // DANCE_BUTTON_DOWN, + KEY_ENTER, // DANCE_BUTTON_START, + KEY_ENTER, // DANCE_BUTTON_START, + KEY_ENTER, // DANCE_BUTTON_START, + KEY_DEL, // DANCE_BUTTON_MENULEFT + KEY_PGDN, // DANCE_BUTTON_MENURIGHT + KEY_HOME, // DANCE_BUTTON_MENUUP + KEY_END, // DANCE_BUTTON_MENUDOWN + KEY_F1, // DANCE_BUTTON_COIN + KEY_F1, // DANCE_BUTTON_COIN + KEY_KP_C4, // DANCE_BUTTON_LEFT, + KEY_KP_C6, // DANCE_BUTTON_RIGHT, + KEY_KP_C8, // DANCE_BUTTON_UP, + KEY_KP_C2, // DANCE_BUTTON_DOWN, + KEY_KP_C7, // DANCE_BUTTON_UPLEFT, + KEY_KP_C9, // DANCE_BUTTON_UPRIGHT, + KEY_KP_ENTER, // DANCE_BUTTON_START, + KEY_KP_ENTER, // DANCE_BUTTON_START, + KEY_KP_ENTER, // DANCE_BUTTON_START, + KEY_KP_SLASH, // DANCE_BUTTON_MENULEFT + KEY_KP_ASTERISK, // DANCE_BUTTON_MENURIGHT + KEY_KP_HYPHEN, // DANCE_BUTTON_MENUUP + KEY_KP_PLUS, // DANCE_BUTTON_MENUDOWN +}; + +int GetRandomKeyboadKey() +{ + int index = rand()%ARRAYSIZE(g_keys); + return g_keys[index]; +} + + +void InputHandler_MonkeyKeyboard::Update(float fDeltaTime) +{ + float fSecsAgo = m_timerPressButton.Ago(); + + if( fSecsAgo > 0.5 ) + { + // End the previous key + ButtonPressed(m_diLast, false); + + // Choose a new key and send it. + m_diLast = DeviceInput(DEVICE_KEYBOARD,GetRandomKeyboadKey()); + ButtonPressed(m_diLast, true); + + m_timerPressButton.Touch(); + } +} + +/* + * (c) 2002-2004 Chris Danford + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons to + * whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF + * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS + * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + diff --git a/stepmania/src/arch/InputHandler/InputHandler_MonkeyKeyboard.h b/stepmania/src/arch/InputHandler/InputHandler_MonkeyKeyboard.h new file mode 100644 index 0000000000..44f62666e6 --- /dev/null +++ b/stepmania/src/arch/InputHandler/InputHandler_MonkeyKeyboard.h @@ -0,0 +1,46 @@ +#ifndef INPUT_HANDLER_MONKEY_SCRIPT +#define INPUT_HANDLER_MONKEY_SCRIPT 1 + +#include "InputHandler.h" +#include "RageTimer.h" +#include "RageInputDevice.h" + +class InputHandler_MonkeyKeyboard: public InputHandler +{ + RageTimer m_timerPressButton; + DeviceInput m_diLast; // Last input that we sent + +public: + void Update(float fDeltaTime); + InputHandler_MonkeyKeyboard(); + ~InputHandler_MonkeyKeyboard(); + void GetDevicesAndDescriptions(vector& vDevicesOut, vector& vDescriptionsOut); +}; + +#endif + +/* + * (c) 2002-2004 Glenn Maynard + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons to + * whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF + * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS + * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + diff --git a/stepmania/src/arch/arch.cpp b/stepmania/src/arch/arch.cpp index afc6eb94ae..f34b2d27d8 100644 --- a/stepmania/src/arch/arch.cpp +++ b/stepmania/src/arch/arch.cpp @@ -65,19 +65,32 @@ LoadingWindow *MakeLoadingWindow() LowLevelWindow *MakeLowLevelWindow() { return new ARCH_LOW_LEVEL_WINDOW; } #endif -void MakeInputHandlers(vector &Add) +void MakeInputHandlers(CString drivers, vector &Add) { + CStringArray DriversToTry; + split(drivers, ",", DriversToTry, true); + + ASSERT( DriversToTry.size() != 0 ); + + CString Driver; + RageSoundDriver *ret = NULL; + + for(unsigned i = 0; ret == NULL && i < DriversToTry.size(); ++i) + { #if defined(_WINDOWS) - Add.push_back(new InputHandler_DInput); - Add.push_back(new InputHandler_Win32_Pump); -// Add.push_back(new InputHandler_Win32_Para); + if(!DriversToTry[i].CompareNoCase("DirectInput")) Add.push_back(new InputHandler_DInput); + if(!DriversToTry[i].CompareNoCase("Pump")) Add.push_back(new InputHandler_Win32_Pump); + // if(!DriversToTry[i].CompareNoCase("Para")) Add.push_back(new InputHandler_Win32_Para); #elif defined(_XBOX) - Add.push_back(new InputHandler_Xbox); + if(!DriversToTry[i].CompareNoCase("Xbox")) Add.push_back(new InputHandler_Xbox); #endif #if defined(SUPPORT_SDL_INPUT) - Add.push_back(new InputHandler_SDL); + if(!DriversToTry[i].CompareNoCase("SDL")) Add.push_back(new InputHandler_SDL); #endif + + if(!DriversToTry[i].CompareNoCase("MonkeyKeyboard"))Add.push_back(new InputHandler_MonkeyKeyboard); + } } RageSoundDriver *MakeRageSoundDriver(CString drivers) @@ -97,27 +110,27 @@ RageSoundDriver *MakeRageSoundDriver(CString drivers) LOG->Trace("Initializing driver: %s", DriversToTry[i].c_str()); #ifdef _WINDOWS - if(!DriversToTry[i].CompareNoCase("DirectSound")) ret = new RageSound_DSound; - if(!DriversToTry[i].CompareNoCase("DirectSound-sw")) ret = new RageSound_DSound_Software; - if(!DriversToTry[i].CompareNoCase("WaveOut")) ret = new RageSound_WaveOut; + if(!DriversToTry[i].CompareNoCase("DirectSound")) ret = new RageSound_DSound; + if(!DriversToTry[i].CompareNoCase("DirectSound-sw")) ret = new RageSound_DSound_Software; + if(!DriversToTry[i].CompareNoCase("WaveOut")) ret = new RageSound_WaveOut; #endif #ifdef _XBOX - if(!DriversToTry[i].CompareNoCase("DirectSound")) ret = new RageSound_DSound; + if(!DriversToTry[i].CompareNoCase("DirectSound")) ret = new RageSound_DSound; #endif #ifdef HAVE_ALSA - if(!DriversToTry[i].CompareNoCase("ALSA")) ret = new RageSound_ALSA9; - if(!DriversToTry[i].CompareNoCase("ALSA-sw")) ret = new RageSound_ALSA9_Software; + if(!DriversToTry[i].CompareNoCase("ALSA")) ret = new RageSound_ALSA9; + if(!DriversToTry[i].CompareNoCase("ALSA-sw")) ret = new RageSound_ALSA9_Software; #endif #ifdef HAVE_OSS - if(!DriversToTry[i].CompareNoCase("OSS")) ret = new RageSound_OSS; + if(!DriversToTry[i].CompareNoCase("OSS")) ret = new RageSound_OSS; #endif #ifdef RAGE_SOUND_CA - if(!DriversToTry[i].CompareNoCase("CoreAudio")) ret = new RageSound_CA; + if(!DriversToTry[i].CompareNoCase("CoreAudio")) ret = new RageSound_CA; #endif #ifdef RAGE_SOUND_QT1 - if(!DriversToTry[i].CompareNoCase("QT1")) ret = new RageSound_QT1; + if(!DriversToTry[i].CompareNoCase("QT1")) ret = new RageSound_QT1; #endif - if(!DriversToTry[i].CompareNoCase("Null")) ret = new RageSound_Null; + if(!DriversToTry[i].CompareNoCase("Null")) ret = new RageSound_Null; if( !ret ) LOG->Warn("Unknown sound driver name: %s", DriversToTry[i].c_str()); } catch(const RageException &e) { diff --git a/stepmania/src/arch/arch.h b/stepmania/src/arch/arch.h index 4b3a82a1fb..abbf13be04 100644 --- a/stepmania/src/arch/arch.h +++ b/stepmania/src/arch/arch.h @@ -13,7 +13,7 @@ class MemoryCardDriver; LoadingWindow *MakeLoadingWindow(); LowLevelWindow *MakeLowLevelWindow(); -void MakeInputHandlers(vector &Add); +void MakeInputHandlers(CString drivers,vector &Add); RageSoundDriver *MakeRageSoundDriver(CString drivers); /* These definitions are in here, instead of in arch_*.h, because they @@ -34,6 +34,14 @@ RageSoundDriver *MakeRageSoundDriver(CString drivers); #define DEFAULT_SOUND_DRIVER_LIST "Null" #endif +#if defined(_WINDOWS) + #define DEFAULT_INPUT_DRIVER_LIST "DirectInput,Pump" +#elif defined(_XBOX) + #define DEFAULT_INPUT_DRIVER_LIST "Xbox" +#else + #define DEFAULT_INPUT_DRIVER_LIST "SDL" +#endif + #define DEFAULT_MOVIE_DRIVER_LIST "FFMpeg,Null" /* Choose your renderers. */ diff --git a/stepmania/src/arch/arch_default.h b/stepmania/src/arch/arch_default.h index 62999cbdf3..7238921308 100644 --- a/stepmania/src/arch/arch_default.h +++ b/stepmania/src/arch/arch_default.h @@ -26,6 +26,7 @@ * header. */ #define SUPPORT_SDL_INPUT #include "InputHandler/InputHandler_SDL.h" +#include "InputHandler/InputHandler_MonkeyKeyboard.h" /* Load default fallback drivers; some of these may be overridden by arch-specific * drivers. These are all singleton drivers--we never use more than one. */