Integrating our code
In order to prevent sounds or music from playing at inappropriate times, our state manager must notify the sound manager of any state changes:
void StateManager::SwitchTo(const StateType& l_type){ ... m_shared->m_soundManager->ChangeState(l_type); ... }
Since the sound manager also cares about states being removed, let's tell it when that happens:
void StateManager::RemoveState(const StateType& l_type){ for (auto itr = m_states.begin(); itr != m_states.end(); ++itr) { if (itr->first == l_type){ ... m_shared->m_soundManager->RemoveState(l_type); return; } } }
The only thing we have left to do now is actually integrating everything we worked on into the rest of our code base, starting with SharedContext.h
:
... #include "AudioManager.h" #include "SoundManager.h" ... struct SharedContext{ SharedContext(): ... m_audioManager(nullptr), m_soundManager(nullptr),...