diff --git a/src/audio/sfx_manager.cpp b/src/audio/sfx_manager.cpp index 7f3a9c92a..2dcf2c898 100644 --- a/src/audio/sfx_manager.cpp +++ b/src/audio/sfx_manager.cpp @@ -22,8 +22,8 @@ #include "audio/sfx_buffer.hpp" #include "config/user_config.hpp" #include "io/file_manager.hpp" -#include "modes/world.hpp" #include "race/race_manager.hpp" +#include "states_screens/state_manager.hpp" #include "utils/stk_process.hpp" #include "utils/profiler.hpp" #include "utils/string_utils.hpp" @@ -290,7 +290,7 @@ void SFXManager::queueCommand(SFXCommand *command) return; m_sfx_commands.lock(); - if(World::getWorld() && + if (StateManager::get()->getGameState() != GUIEngine::MENU && m_sfx_commands.getData().size() > 20*RaceManager::get()->getNumberOfKarts()+20 && RaceManager::get()->getMinorMode() != RaceManager::MINOR_MODE_CUTSCENE) { diff --git a/src/guiengine/abstract_state_manager.cpp b/src/guiengine/abstract_state_manager.cpp index 6a35a3186..4bf050e5e 100644 --- a/src/guiengine/abstract_state_manager.cpp +++ b/src/guiengine/abstract_state_manager.cpp @@ -37,7 +37,7 @@ static const char RACE_STATE_NAME[] = "race"; AbstractStateManager::AbstractStateManager() { - m_game_mode = MENU; + m_game_mode.store(MENU); } // AbstractStateManager #if 0 @@ -73,16 +73,16 @@ void AbstractStateManager::enterGameState() GameState AbstractStateManager::getGameState() { - return m_game_mode; + return m_game_mode.load(); } // getGameState // ---------------------------------------------------------------------------- void AbstractStateManager::setGameState(GameState state) { - if (m_game_mode == state) return; // no change + if (m_game_mode.load() == state) return; // no change - m_game_mode = state; + m_game_mode.store(state); onGameStateChange(state); } // setGameState @@ -98,7 +98,7 @@ void AbstractStateManager::setGameState(GameState state) void AbstractStateManager::pushMenu(Screen* screen) { // currently, only a single in-game menu is supported - assert(m_game_mode != INGAME_MENU); + assert(m_game_mode.load() != INGAME_MENU); // you need to close any dialog before calling this assert(!ModalDialog::isADialogActive()); @@ -111,11 +111,11 @@ void AbstractStateManager::pushMenu(Screen* screen) } // Send tear-down event to previous menu - if (m_menu_stack.size() > 0 && m_game_mode != GAME) + if (m_menu_stack.size() > 0 && m_game_mode.load() != GAME) getCurrentScreen()->tearDown(); m_menu_stack.emplace_back(screen->getName(), screen); - if (m_game_mode == GAME) + if (m_game_mode.load() == GAME) { setGameState(INGAME_MENU); } @@ -157,7 +157,7 @@ void AbstractStateManager::replaceTopMostScreen(Screen* screen, GUIEngine::GameS if (gameState == GUIEngine::CURRENT) gameState = getGameState(); - //assert(m_game_mode != GAME); + //assert(m_game_mode.load() != GAME); // you need to close any dialog before calling this assert(!ModalDialog::isADialogActive()); assert(!ScreenKeyboard::isActive()); @@ -191,7 +191,7 @@ void AbstractStateManager::replaceTopMostScreen(Screen* screen, GUIEngine::GameS void AbstractStateManager::reshowTopMostMenu() { - assert(m_game_mode != GAME); + assert(m_game_mode.load() != GAME); // you need to close any dialog before calling this assert(!ModalDialog::isADialogActive()); assert(!ScreenKeyboard::isActive()); @@ -217,7 +217,7 @@ void AbstractStateManager::reshowTopMostMenu() void AbstractStateManager::popMenu() { - assert(m_game_mode != GAME); + assert(m_game_mode.load() != GAME); if (m_menu_stack.empty()) return; @@ -272,7 +272,7 @@ void AbstractStateManager::resetAndGoToScreen(Screen* screen) Log::info("AbstractStateManager::resetAndGoToScreen", "Switching to screen %s", name.c_str()); - if (m_game_mode != GAME) getCurrentScreen()->tearDown(); + if (m_game_mode.load() != GAME) getCurrentScreen()->tearDown(); m_menu_stack.clear(); if (!screen->isLoaded()) screen->loadFromFile(); @@ -295,7 +295,7 @@ void AbstractStateManager::resetAndSetStack(Screen* screens[]) assert(!ModalDialog::isADialogActive()); assert(!ScreenKeyboard::isActive()); - if (m_game_mode != GAME && getCurrentScreen()) + if (m_game_mode.load() != GAME && getCurrentScreen()) getCurrentScreen()->tearDown(); m_menu_stack.clear(); diff --git a/src/guiengine/abstract_state_manager.hpp b/src/guiengine/abstract_state_manager.hpp index 9e2f105a8..2a18d2e61 100644 --- a/src/guiengine/abstract_state_manager.hpp +++ b/src/guiengine/abstract_state_manager.hpp @@ -19,6 +19,7 @@ #ifndef HEADER_ABSTRACT_STATE_MANAGER_HPP #define HEADER_ABSTRACT_STATE_MANAGER_HPP +#include #include #include #include "guiengine/engine.hpp" @@ -36,7 +37,7 @@ namespace GUIEngine /** * \ingroup guiengine */ - enum GameState + enum GameState : unsigned int { MENU, GAME, @@ -55,7 +56,7 @@ namespace GUIEngine /** * Whether we are in game mode */ - GameState m_game_mode; + std::atomic m_game_mode; /** * This stack will contain menu names (e.g. main.stkgui), @@ -137,7 +138,7 @@ namespace GUIEngine template void hardResetAndGoToScreen() { - if (m_game_mode != GAME) GUIEngine::getCurrentScreen()->tearDown(); + if (m_game_mode.load() != GAME) GUIEngine::getCurrentScreen()->tearDown(); GUIEngine::clearScreenCache();