O'Reilly logo

SFML Game Development By Example by Raimondas Pupius

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required