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" ...

Get SFML Game Development By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.