From 3fbde68e4a3e22160ff2951abf8665d11268bdfa Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 18 Dec 2005 23:45:46 +0000 Subject: [PATCH] better encapsulation, reduce GameLoop.cpp depending on StepMania.cpp: move CheckForChangedInputDevicesAndRemap into InputMapper --- stepmania/src/InputMapper.cpp | 39 ++++++++++++++++++++++++++++++ stepmania/src/InputMapper.h | 1 + stepmania/src/StepMania.cpp | 45 +++-------------------------------- stepmania/src/StepMania.h | 1 - 4 files changed, 43 insertions(+), 43 deletions(-) diff --git a/stepmania/src/InputMapper.cpp b/stepmania/src/InputMapper.cpp index ec376e172c..69be4f421b 100644 --- a/stepmania/src/InputMapper.cpp +++ b/stepmania/src/InputMapper.cpp @@ -512,6 +512,45 @@ void InputMapper::SaveMappingsToDisk() ini.WriteFile( SpecialFiles::KEYMAPS_PATH ); } +bool InputMapper::CheckForChangedInputDevicesAndRemap( CString &sMessage ) +{ + // + // update last seen joysticks + // + vector vDevices; + vector vsDescriptions; + INPUTMAN->GetDevicesAndDescriptions( vDevices, vsDescriptions ); + CString sInputDevices = join( ",", vsDescriptions ); + + if( PREFSMAN->m_sLastSeenInputDevices.Get() == sInputDevices ) + return false; + + vector vsLastSeen; + split( PREFSMAN->m_sLastSeenInputDevices, ",", vsLastSeen ); + + vector vsConnects, vsDisconnects; + GetConnectsDisconnects( vsLastSeen, vsDescriptions, vsDisconnects, vsConnects ); + + sMessage.clear(); + if( !vsConnects.empty() ) + sMessage += "Connected: " + join( "\n", vsConnects ) + "\n"; + if( !vsDisconnects.empty() ) + sMessage += "Disconnected: " + join( "\n", vsDisconnects ) + "\n"; + + if( PREFSMAN->m_bAutoMapOnJoyChange ) + { + sMessage += "Remapping all joysticks."; + AutoMapJoysticksForCurrentGame(); + SaveMappingsToDisk(); + } + + LOG->Info( sMessage ); + + PREFSMAN->m_sLastSeenInputDevices.Set( sInputDevices ); + PREFSMAN->SavePrefsToDisk(); + + return true; +} void InputMapper::SetInputMap( const DeviceInput &DeviceI, const GameInput &GameI, int iSlotIndex ) { diff --git a/stepmania/src/InputMapper.h b/stepmania/src/InputMapper.h index fefe9bac77..0790c95e08 100644 --- a/stepmania/src/InputMapper.h +++ b/stepmania/src/InputMapper.h @@ -28,6 +28,7 @@ public: void AddDefaultMappingsForCurrentGameIfUnmapped(); void AutoMapJoysticksForCurrentGame(); + bool CheckForChangedInputDevicesAndRemap( CString &sMessageOut ); bool IsMapped( const DeviceInput &DeviceI ); bool IsMapped( const GameInput &GameI ); diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index 4e418da2a7..2d4927da28 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -292,47 +292,6 @@ void StepMania::ResetGame() PREFSMAN->SavePrefsToDisk(); } -void StepMania::CheckForChangedInputDevicesAndRemap() -{ - // - // update last seen joysticks - // - vector vDevices; - vector vsDescriptions; - INPUTMAN->GetDevicesAndDescriptions( vDevices, vsDescriptions ); - CString sInputDevices = join( ",", vsDescriptions ); - - if( PREFSMAN->m_sLastSeenInputDevices.Get() != sInputDevices ) - { - vector vsLastSeen; - split( PREFSMAN->m_sLastSeenInputDevices, ",", vsLastSeen ); - - vector vsConnects, vsDisconnects; - GetConnectsDisconnects( vsLastSeen, vsDescriptions, vsDisconnects, vsConnects ); - - CString sMessage; - - if( !vsConnects.empty() ) - sMessage += "Connected: " + join( "\n", vsConnects ) + "\n"; - if( !vsDisconnects.empty() ) - sMessage += "Disconnected: " + join( "\n", vsDisconnects ) + "\n"; - - if( PREFSMAN->m_bAutoMapOnJoyChange ) - { - sMessage += "Remapping all joysticks."; - INPUTMAPPER->AutoMapJoysticksForCurrentGame(); - INPUTMAPPER->SaveMappingsToDisk(); - } - - LOG->Info( sMessage ); - SCREENMAN->SystemMessage( sMessage ); - - PREFSMAN->m_sLastSeenInputDevices.Set( sInputDevices ); - } - - PREFSMAN->SavePrefsToDisk(); -} - static bool ChangeAppPri() { if( PREFSMAN->m_BoostAppPriority.Get() == PrefsManager::BOOST_NO ) @@ -1142,7 +1101,9 @@ int main(int argc, char* argv[]) SCREENMAN->SetNewScreen( CommonMetrics::INITIAL_SCREEN ); // Do this after ThemeChanged so that we can show a system message - StepMania::CheckForChangedInputDevicesAndRemap(); + CString sMessage; + if( INPUTMAPPER->CheckForChangedInputDevicesAndRemap(sMessage) ) + SCREENMAN->SystemMessage( sMessage ); CodeDetector::RefreshCacheItems(); diff --git a/stepmania/src/StepMania.h b/stepmania/src/StepMania.h index 07a28a9db0..25ab7572a0 100644 --- a/stepmania/src/StepMania.h +++ b/stepmania/src/StepMania.h @@ -16,7 +16,6 @@ namespace StepMania void ApplyGraphicOptions(); void NORETURN HandleException( CString error ); void ResetGame(); - void CheckForChangedInputDevicesAndRemap(); void ChangeCurrentGame( const Game* g ); void FocusChanged( bool bHasFocus ); bool AppHasFocus();