From ff17961584324c1da1ad67ab8873d39bb8c785b8 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 31 Aug 2015 21:47:55 +0200 Subject: [PATCH] Refactored CPauseManager --- data | 2 +- src/app/pausemanager.cpp | 80 +++++++++++---------- src/app/pausemanager.h | 38 +++++++--- src/common/settings.cpp | 2 + src/graphics/engine/engine.cpp | 2 +- src/graphics/engine/lightning.cpp | 2 + src/graphics/engine/particle.cpp | 2 + src/graphics/engine/pyro.cpp | 2 + src/level/robotmain.cpp | 100 ++++++++++++++------------- src/level/robotmain.h | 14 ++-- src/object/auto/auto.cpp | 2 + src/object/auto/autobase.cpp | 2 + src/object/auto/autoderrick.cpp | 2 + src/object/auto/autodestroyer.cpp | 2 + src/object/auto/autolabo.cpp | 2 + src/object/auto/autoportico.cpp | 2 + src/object/auto/autoresearch.cpp | 2 + src/object/auto/autovault.cpp | 2 + src/object/motion/motionhuman.cpp | 2 + src/object/motion/motiontoto.cpp | 2 + src/object/task/taskbuild.cpp | 2 + src/object/task/taskmanip.cpp | 2 + src/object/task/taskrecover.cpp | 2 + src/object/task/tasksearch.cpp | 2 + src/object/task/taskshield.cpp | 2 + src/object/task/tasktake.cpp | 2 + src/object/task/taskterraform.cpp | 2 + src/physics/physics.cpp | 2 + src/script/script.cpp | 25 ++----- src/script/script.h | 3 +- src/ui/displayinfo.cpp | 8 +-- src/ui/displayinfo.h | 6 +- src/ui/mainshort.cpp | 2 +- src/ui/screen/screen_io.cpp | 2 + src/ui/screen/screen_main_menu.cpp | 2 + src/ui/screen/screen_setup_sound.cpp | 2 + src/ui/studio.cpp | 39 +++++++---- src/ui/studio.h | 6 +- 38 files changed, 224 insertions(+), 151 deletions(-) diff --git a/data b/data index 11911a9a..eb4dc848 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 11911a9a4de2ec08dcefc291e80bde7ec1224e24 +Subproject commit eb4dc8489609c33a93b67bbc45939d5b5ee6d8ee diff --git a/src/app/pausemanager.cpp b/src/app/pausemanager.cpp index 21941393..88c12f06 100644 --- a/src/app/pausemanager.cpp +++ b/src/app/pausemanager.cpp @@ -25,62 +25,66 @@ #include "level/robotmain.h" +#include + template<> CPauseManager* CSingleton::m_instance = nullptr; CPauseManager::CPauseManager() -{ - m_sound = CApplication::GetInstancePointer()->GetSound(); - - m_pause = PAUSE_NONE; -} +{} CPauseManager::~CPauseManager() +{} + +ActivePause* CPauseManager::ActivatePause(PauseType type) { - m_sound = nullptr; + assert(type != PAUSE_NONE); + GetLogger()->Debug("Activated pause mode - %s\n", GetPauseName(type).c_str()); + auto pause = std::unique_ptr(new ActivePause(type)); // TODO: Can't use MakeUnique here because the constructor is private + ActivePause* ptr = pause.get(); + m_activePause.push_back(std::move(pause)); + UpdatePause(); + return ptr; } -void CPauseManager::SetPause(PauseType pause) +void CPauseManager::DeactivatePause(ActivePause* pause) { - if (pause != PAUSE_NONE) - { - if (m_pause != pause) - { - GetLogger()->Info("Game paused - %s\n", GetPauseName(pause).c_str()); - CRobotMain::GetInstancePointer()->StartPauseMusic(pause); - } + if (pause == nullptr) return; + GetLogger()->Debug("Deactivated pause mode - %s\n", GetPauseName(pause->type).c_str()); + m_activePause.erase(std::remove_if( + m_activePause.begin(), m_activePause.end(), + [&](const std::unique_ptr& x) { return x.get() == pause; }) + ); + UpdatePause(); +} - m_pause = pause; +void CPauseManager::FlushPause() +{ + m_activePause.clear(); +} + +bool CPauseManager::IsPause() +{ + return m_activePause.size() > 0; +} + +void CPauseManager::UpdatePause() +{ + PauseType type = PAUSE_NONE; + if (m_activePause.size() > 0) + type = m_activePause[m_activePause.size()-1]->type; + + if (type != PAUSE_NONE) + { + GetLogger()->Info("Game paused - %s\n", GetPauseName(type).c_str()); } else - ClearPause(); -} - -void CPauseManager::ClearPause() -{ - if(m_pause != PAUSE_NONE) { GetLogger()->Info("Game resumed\n"); - m_sound->StopPauseMusic(); } - m_pause = PAUSE_NONE; -} - -bool CPauseManager::GetPause() -{ - return m_pause != PAUSE_NONE; -} - -bool CPauseManager::GetPause(PauseType pause) -{ - return m_pause == pause; -} - -PauseType CPauseManager::GetPauseType() -{ - return m_pause; + CRobotMain::GetInstancePointer()->UpdatePause(type); } std::string CPauseManager::GetPauseName(PauseType pause) diff --git a/src/app/pausemanager.h b/src/app/pausemanager.h index e140ce84..54d0ef1b 100644 --- a/src/app/pausemanager.h +++ b/src/app/pausemanager.h @@ -25,9 +25,9 @@ #include "common/singleton.h" -#include "sound/sound.h" - #include +#include +#include enum PauseType @@ -44,23 +44,39 @@ enum PauseType PAUSE_CODE_BATTLE_LOCK }; +struct ActivePause +{ +private: + friend class CPauseManager; + + explicit ActivePause(PauseType type) + : type(type) + {} + + ActivePause(const ActivePause&) = delete; + ActivePause& operator=(const ActivePause&) = delete; + + PauseType type; +}; + class CPauseManager : public CSingleton { public: CPauseManager(); ~CPauseManager(); - void SetPause(PauseType pause); - void ClearPause(); - bool GetPause(); - bool GetPause(PauseType pause); - PauseType GetPauseType(); + ActivePause* ActivatePause(PauseType type); + void DeactivatePause(ActivePause* pause); + + void FlushPause(); + + bool IsPause(); private: - std::string GetPauseName(PauseType pause); + void UpdatePause(); + + static std::string GetPauseName(PauseType pause); private: - CSoundInterface* m_sound; - - PauseType m_pause; + std::vector> m_activePause; }; diff --git a/src/common/settings.cpp b/src/common/settings.cpp index e57aebd9..093ed6db 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -29,6 +29,8 @@ #include "level/robotmain.h" +#include "sound/sound.h" + template<> CSettings* CSingleton::m_instance = nullptr; CSettings::CSettings() diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index d141682d..3b6c131c 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -514,7 +514,7 @@ void CEngine::WriteScreenShotThread(std::unique_ptr data) bool CEngine::GetPause() { - return m_pause->GetPause(); + return m_pause->IsPause(); } void CEngine::SetShowStats(bool show) diff --git a/src/graphics/engine/lightning.cpp b/src/graphics/engine/lightning.cpp index 08b4c9ed..fdce7908 100644 --- a/src/graphics/engine/lightning.cpp +++ b/src/graphics/engine/lightning.cpp @@ -40,6 +40,8 @@ #include "object/interface/destroyable_object.h" #include "object/interface/transportable_object.h" +#include "sound/sound.h" + // Graphics module namespace namespace Gfx diff --git a/src/graphics/engine/particle.cpp b/src/graphics/engine/particle.cpp index 3f7f2be1..afd9f4d1 100644 --- a/src/graphics/engine/particle.cpp +++ b/src/graphics/engine/particle.cpp @@ -42,6 +42,8 @@ #include "object/subclass/shielder.h" +#include "sound/sound.h" + #include diff --git a/src/graphics/engine/pyro.cpp b/src/graphics/engine/pyro.cpp index 02b9c14b..68038902 100644 --- a/src/graphics/engine/pyro.cpp +++ b/src/graphics/engine/pyro.cpp @@ -39,6 +39,8 @@ #include "object/subclass/shielder.h" +#include "sound/sound.h" + // Graphics module namespace namespace Gfx diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 64b3cc0d..9cca897d 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -23,6 +23,7 @@ #include "app/app.h" #include "app/input.h" +#include "app/pausemanager.h" #include "common/config_file.h" #include "common/event.h" @@ -210,7 +211,6 @@ CRobotMain::CRobotMain() m_cheatRadar = false; m_fixScene = false; m_trainerPilot = false; - m_suspend = false; m_friendAim = false; m_resetCreate = false; m_shortCut = true; @@ -431,7 +431,7 @@ void CRobotMain::ChangePhase(Phase phase) m_resetCreate = false; m_infoObject = nullptr; - ChangePause(PAUSE_NONE); + m_pause->FlushPause(); FlushDisplayInfo(); m_engine->SetRankView(0); m_terrain->FlushRelief(); @@ -649,7 +649,8 @@ bool CRobotMain::ProcessEvent(Event &event) MainMovieType type = m_movie->GetStopType(); if (type == MM_SATCOMopen) { - ChangePause(PAUSE_NONE); + m_pause->DeactivatePause(m_satcomMoviePause); + m_satcomMoviePause = nullptr; SelectObject(m_infoObject, false); // hands over the command buttons m_map->ShowMap(m_mapShow); m_displayText->HideText(false); @@ -689,7 +690,7 @@ bool CRobotMain::ProcessEvent(Event &event) if (pe == nullptr) return false; pe->SetState(Ui::STATE_VISIBLE); m_interface->SetFocus(pe); - if (m_phase == PHASE_SIMUL) ChangePause(PAUSE_CHEAT); + if (m_phase == PHASE_SIMUL) m_cmdEditPause = m_pause->ActivatePause(PAUSE_CHEAT); m_cmdEdit = true; } return false; @@ -704,7 +705,11 @@ bool CRobotMain::ProcessEvent(Event &event) pe->GetText(cmd, 50); pe->SetText(""); pe->ClearState(Ui::STATE_VISIBLE); - if (m_phase == PHASE_SIMUL) ChangePause(PAUSE_NONE); + if (m_phase == PHASE_SIMUL) + { + m_pause->DeactivatePause(m_cmdEditPause); + m_cmdEditPause = nullptr; + } ExecuteCmd(cmd); m_cmdEdit = false; return false; @@ -817,11 +822,17 @@ bool CRobotMain::ProcessEvent(Event &event) } if (data->slot == INPUT_SLOT_PAUSE) { - if (!m_movieLock && !m_editLock && !m_cmdEdit && - m_camera->GetType() != Gfx::CAM_TYPE_VISIT && - !m_movie->IsExist()) + if (m_userPause == nullptr) { - ChangePause(m_pause->GetPause(PAUSE_USER) || m_pause->GetPause(PAUSE_CODE_BATTLE_LOCK) ? PAUSE_NONE : PAUSE_USER); + if (!m_pause->IsPause()) + { + m_userPause = m_pause->ActivatePause(PAUSE_USER); + } + } + else + { + m_pause->DeactivatePause(m_userPause); + m_userPause = nullptr; } } if (data->slot == INPUT_SLOT_CAMERA) @@ -1160,12 +1171,13 @@ void CRobotMain::ExecuteCmd(char *cmd) if (m_freePhoto) { m_camera->SetType(Gfx::CAM_TYPE_FREE); - ChangePause(PAUSE_PHOTO); + m_freePhotoPause = m_pause->ActivatePause(PAUSE_PHOTO); } else { m_camera->SetType(Gfx::CAM_TYPE_BACK); - ChangePause(PAUSE_NONE); + m_pause->DeactivatePause(m_freePhotoPause); + m_freePhotoPause = nullptr; } return; } @@ -1177,14 +1189,15 @@ void CRobotMain::ExecuteCmd(char *cmd) { m_camera->SetType(Gfx::CAM_TYPE_FREE); DeselectAll(); // removes the control buttons - ChangePause(PAUSE_PHOTO); + m_freePhotoPause = m_pause->ActivatePause(PAUSE_PHOTO); m_map->ShowMap(false); m_displayText->HideText(true); } else { m_camera->SetType(Gfx::CAM_TYPE_BACK); - ChangePause(PAUSE_NONE); + m_pause->DeactivatePause(m_freePhotoPause); + m_freePhotoPause = nullptr; m_map->ShowMap(m_mapShow); m_displayText->HideText(false); } @@ -1388,7 +1401,7 @@ void CRobotMain::StartDisplayInfo(int index, bool movie) { m_movieInfoIndex = index; m_movie->Start(MM_SATCOMopen, 2.5f); - ChangePause(PAUSE_SATCOMMOVIE); + m_satcomMoviePause = m_pause->ActivatePause(PAUSE_SATCOMMOVIE); m_infoObject = DeselectAll(); // removes the control buttons m_displayText->HideText(true); return; @@ -1398,7 +1411,8 @@ void CRobotMain::StartDisplayInfo(int index, bool movie) if (m_movie->IsExist()) { m_movie->Stop(); - ChangePause(PAUSE_NONE); + m_pause->DeactivatePause(m_satcomMoviePause); + m_satcomMoviePause = nullptr; SelectObject(m_infoObject, false); // hands over the command buttons m_displayText->HideText(false); } @@ -1483,8 +1497,7 @@ void CRobotMain::StartSuspend() { m_sound->MuteAll(true); ClearInterface(); - m_suspendInitPause = m_pause->GetPauseType(); - m_pause->SetPause(PAUSE_DIALOG); + m_suspend = m_pause->ActivatePause(PAUSE_DIALOG); m_engine->SetOverFront(false); // over flat behind CreateShortcuts(); @@ -1494,8 +1507,6 @@ void CRobotMain::StartSuspend() m_suspendInitCamera = m_camera->GetType(); m_camera->SetType(Gfx::CAM_TYPE_DIALOG); - - m_suspend = true; } //! End of dialogue during the game @@ -1503,7 +1514,8 @@ void CRobotMain::StopSuspend() { m_sound->MuteAll(false); ClearInterface(); - m_pause->SetPause(m_suspendInitPause); + m_pause->DeactivatePause(m_suspend); + m_suspend = nullptr; m_engine->SetOverFront(true); // over flat front CreateShortcuts(); @@ -1513,8 +1525,6 @@ void CRobotMain::StopSuspend() m_displayText->HideText(false); m_camera->SetType(m_suspendInitCamera); - - m_suspend = false; } @@ -1615,7 +1625,7 @@ void CRobotMain::StartDisplayVisit(EventType event) m_camera->StartVisit(m_displayText->GetVisitGoal(event), m_displayText->GetVisitDist(event)); m_displayText->SetVisit(event); - ChangePause(PAUSE_VISIT); + m_visitPause = m_pause->ActivatePause(PAUSE_VISIT); } //! Move the arrow to visit @@ -1668,7 +1678,8 @@ void CRobotMain::StopDisplayVisit() m_camera->StopVisit(); m_displayText->ClearVisit(); - ChangePause(PAUSE_NONE); + m_pause->DeactivatePause(m_visitPause); + m_visitPause = nullptr; if (m_visitObject != nullptr) { SelectObject(m_visitObject, false); // gives the command buttons @@ -2006,7 +2017,7 @@ void CRobotMain::HiliteObject(Math::Point pos) if (obj == nullptr) return; } - if (m_suspend) return; + if (m_suspend != nullptr) return; if (obj == nullptr) { @@ -2329,16 +2340,16 @@ bool CRobotMain::EventFrame(const Event &event) } m_time += event.rTime; - if (!m_movieLock && !m_pause->GetPause()) + if (!m_movieLock && !m_pause->IsPause()) { m_gameTime += event.rTime; m_gameTimeAbsolute += m_app->GetRealRelTime() / 1e9f; } - if (!m_movieLock && !m_pause->GetPause() && m_missionTimerStarted) + if (!m_movieLock && !m_pause->IsPause() && m_missionTimerStarted) m_missionTimer += event.rTime; - if (!m_pause->GetPause() && m_autosave && m_gameTimeAbsolute >= m_autosaveLast+(m_autosaveInterval*60) && m_phase == PHASE_SIMUL) + if (!m_pause->IsPause() && m_autosave && m_gameTimeAbsolute >= m_autosaveLast+(m_autosaveInterval*60) && m_phase == PHASE_SIMUL) { if (m_levelCategory == LevelCategory::Missions || m_levelCategory == LevelCategory::FreeGame || @@ -2460,7 +2471,7 @@ bool CRobotMain::EventFrame(const Event &event) } // Moves edition indicator. - if (m_editLock || m_pause->GetPause()) // edition in progress? + if (m_editLock || m_pause->IsPause()) // edition in progress? { Ui::CControl* pc = m_interface->SearchControl(EVENT_OBJECT_EDITLOCK); if (pc != nullptr) @@ -2567,12 +2578,12 @@ bool CRobotMain::EventFrame(const Event &event) { // NOTE: It's important to do this AFTER the first update event finished processing // because otherwise all robot parts are misplaced - ChangePause(PAUSE_CODE_BATTLE_LOCK); + m_userPause = m_pause->ActivatePause(PAUSE_CODE_BATTLE_LOCK); m_sound->MuteAll(false); // Allow sound m_codeBattleInit = true; // Will start on resume } - if (!m_codeBattleStarted && !m_pause->GetPause()) + if (!m_codeBattleStarted && m_userPause != nullptr) { m_codeBattleStarted = true; m_eventQueue->AddEvent(Event(EVENT_UPDINTERFACE)); @@ -5305,20 +5316,6 @@ void CRobotMain::UpdateChapterPassed() } -//! Changes on the pause mode -void CRobotMain::ChangePause(PauseType pause) -{ - if (pause != PAUSE_NONE) - m_pause->SetPause(pause); - else - m_pause->ClearPause(); - - m_sound->MuteAll(m_pause->GetPause()); - CreateShortcuts(); - if (m_pause->GetPause()) HiliteClear(); -} - - //! Changes game speed void CRobotMain::SetSpeed(float speed) { @@ -5484,11 +5481,18 @@ void CRobotMain::StartMusic() } } -//! Starts pause music -void CRobotMain::StartPauseMusic(PauseType pause) +void CRobotMain::UpdatePause(PauseType pause) { - switch(pause) + m_sound->MuteAll(pause != PAUSE_NONE); + CreateShortcuts(); + if (pause != PAUSE_NONE) HiliteClear(); + + switch (pause) { + case PAUSE_NONE: + m_sound->StopPauseMusic(); + break; + case PAUSE_EDITOR: if (m_editorTrack != "") m_sound->PlayPauseMusic(m_editorTrack, m_editorRepeat); diff --git a/src/level/robotmain.h b/src/level/robotmain.h index 02de6ea8..3fc003e3 100644 --- a/src/level/robotmain.h +++ b/src/level/robotmain.h @@ -89,6 +89,8 @@ class CAudioChangeCondition; class CPlayerProfile; class CSettings; class COldObject; +class CPauseManager; +struct ActivePause; namespace Gfx { @@ -185,8 +187,6 @@ public: void SetTracePrecision(float factor); float GetTracePrecision(); - void ChangePause(PauseType pause); - void SetSpeed(float speed); float GetSpeed(); @@ -256,7 +256,7 @@ public: void UpdateChapterPassed(); void StartMusic(); - void StartPauseMusic(PauseType pause); + void UpdatePause(PauseType pause); void ClearInterface(); void ChangeColor(); @@ -465,10 +465,13 @@ protected: CObject* m_selectObject = nullptr; Phase m_phase = PHASE_WELCOME1; + ActivePause* m_userPause = nullptr; int m_cameraRank = 0; Gfx::Color m_color; bool m_freePhoto = false; + ActivePause* m_freePhotoPause = nullptr; bool m_cmdEdit = false; + ActivePause* m_cmdEditPause = nullptr; bool m_selectInsect = false; bool m_showSoluce = false; bool m_showAll = false; @@ -500,8 +503,7 @@ protected: bool m_mapImage = false; char m_mapFilename[100] = {}; - bool m_suspend = false; - PauseType m_suspendInitPause = PAUSE_NONE; + ActivePause* m_suspend = nullptr; Gfx::CameraType m_suspendInitCamera = Gfx::CAM_TYPE_NULL; Math::Point m_tooltipPos; @@ -513,6 +515,7 @@ protected: int m_infoIndex = 0; int m_infoPos[SATCOM_MAX] = {}; int m_infoUsed = 0; + ActivePause* m_satcomMoviePause = nullptr; char m_title[100] = {}; char m_resume[500] = {}; @@ -543,6 +546,7 @@ protected: float m_visitParticle = 0.0f; Math::Vector m_visitPos; Math::Vector m_visitPosArrow; + ActivePause* m_visitPause = nullptr; std::vector> m_endTake; long m_endTakeResearch = 0; diff --git a/src/object/auto/auto.cpp b/src/object/auto/auto.cpp index 15544e52..29d7d240 100644 --- a/src/object/auto/auto.cpp +++ b/src/object/auto/auto.cpp @@ -36,6 +36,8 @@ #include "ui/controls/interface.h" #include "ui/controls/window.h" +#include "sound/sound.h" + // Object's constructor. diff --git a/src/object/auto/autobase.cpp b/src/object/auto/autobase.cpp index 6e5061dc..cb9e8510 100644 --- a/src/object/auto/autobase.cpp +++ b/src/object/auto/autobase.cpp @@ -41,6 +41,8 @@ #include "ui/controls/interface.h" #include "ui/controls/window.h" +#include "sound/sound.h" + const float BASE_LAND_TIME = 7.5f; // hard landing diff --git a/src/object/auto/autoderrick.cpp b/src/object/auto/autoderrick.cpp index ab4a22ef..bc1ced20 100644 --- a/src/object/auto/autoderrick.cpp +++ b/src/object/auto/autoderrick.cpp @@ -37,6 +37,8 @@ #include "ui/controls/interface.h" #include "ui/controls/window.h" +#include "sound/sound.h" + const float DERRICK_DELAY = 10.0f; // duration of the extraction diff --git a/src/object/auto/autodestroyer.cpp b/src/object/auto/autodestroyer.cpp index 66df64ee..24b8e162 100644 --- a/src/object/auto/autodestroyer.cpp +++ b/src/object/auto/autodestroyer.cpp @@ -37,6 +37,8 @@ #include "ui/controls/interface.h" #include "ui/controls/window.h" +#include "sound/sound.h" + #include diff --git a/src/object/auto/autolabo.cpp b/src/object/auto/autolabo.cpp index 65c12e4f..b8e69921 100644 --- a/src/object/auto/autolabo.cpp +++ b/src/object/auto/autolabo.cpp @@ -38,6 +38,8 @@ #include "ui/controls/interface.h" #include "ui/controls/window.h" +#include "sound/sound.h" + const float LABO_DELAY = 20.0f; // duration of the analysis diff --git a/src/object/auto/autoportico.cpp b/src/object/auto/autoportico.cpp index 981b7149..762533ca 100644 --- a/src/object/auto/autoportico.cpp +++ b/src/object/auto/autoportico.cpp @@ -26,6 +26,8 @@ #include "object/old_object.h" +#include "sound/sound.h" + const int PARAM_DEPOSE = 2; // run=2 -> deposits the spaceship diff --git a/src/object/auto/autoresearch.cpp b/src/object/auto/autoresearch.cpp index a3ac7420..cac63198 100644 --- a/src/object/auto/autoresearch.cpp +++ b/src/object/auto/autoresearch.cpp @@ -34,6 +34,8 @@ #include "object/interface/powered_object.h" +#include "sound/sound.h" + #include "ui/controls/gauge.h" #include "ui/controls/interface.h" #include "ui/controls/window.h" diff --git a/src/object/auto/autovault.cpp b/src/object/auto/autovault.cpp index 016b612e..0670dc48 100644 --- a/src/object/auto/autovault.cpp +++ b/src/object/auto/autovault.cpp @@ -34,6 +34,8 @@ #include "object/interface/transportable_object.h" +#include "sound/sound.h" + #include "ui/controls/interface.h" #include "ui/controls/window.h" diff --git a/src/object/motion/motionhuman.cpp b/src/object/motion/motionhuman.cpp index 3892d741..2b3b046e 100644 --- a/src/object/motion/motionhuman.cpp +++ b/src/object/motion/motionhuman.cpp @@ -37,6 +37,8 @@ #include "physics/physics.h" +#include "sound/sound.h" + #include diff --git a/src/object/motion/motiontoto.cpp b/src/object/motion/motiontoto.cpp index 7027cb0e..495eed10 100644 --- a/src/object/motion/motiontoto.cpp +++ b/src/object/motion/motiontoto.cpp @@ -32,6 +32,8 @@ #include "object/old_object.h" +#include "sound/sound.h" + #include diff --git a/src/object/task/taskbuild.cpp b/src/object/task/taskbuild.cpp index 4ff5855e..7f2ebce4 100644 --- a/src/object/task/taskbuild.cpp +++ b/src/object/task/taskbuild.cpp @@ -43,6 +43,8 @@ #include "physics/physics.h" +#include "sound/sound.h" + #include // Object's constructor. diff --git a/src/object/task/taskmanip.cpp b/src/object/task/taskmanip.cpp index 6256eba1..8093f14a 100644 --- a/src/object/task/taskmanip.cpp +++ b/src/object/task/taskmanip.cpp @@ -36,6 +36,8 @@ #include "physics/physics.h" +#include "sound/sound.h" + //?const float MARGIN_FRONT = 2.0f; //?const float MARGIN_BACK = 2.0f; diff --git a/src/object/task/taskrecover.cpp b/src/object/task/taskrecover.cpp index e0a51aa7..43ffcae9 100644 --- a/src/object/task/taskrecover.cpp +++ b/src/object/task/taskrecover.cpp @@ -35,6 +35,8 @@ #include "physics/physics.h" +#include "sound/sound.h" + const float ENERGY_RECOVER = 0.25f; // energy consumed by recovery const float RECOVER_DIST = 11.8f; diff --git a/src/object/task/tasksearch.cpp b/src/object/task/tasksearch.cpp index 53f67491..ac444c46 100644 --- a/src/object/task/tasksearch.cpp +++ b/src/object/task/tasksearch.cpp @@ -32,6 +32,8 @@ #include "physics/physics.h" +#include "sound/sound.h" + // Object's constructor. diff --git a/src/object/task/taskshield.cpp b/src/object/task/taskshield.cpp index 7ef80909..025b1978 100644 --- a/src/object/task/taskshield.cpp +++ b/src/object/task/taskshield.cpp @@ -38,6 +38,8 @@ #include "physics/physics.h" +#include "sound/sound.h" + #include const float ENERGY_TIME = 20.0f; // maximum duration if full battery diff --git a/src/object/task/tasktake.cpp b/src/object/task/tasktake.cpp index d1832853..2945ec6b 100644 --- a/src/object/task/tasktake.cpp +++ b/src/object/task/tasktake.cpp @@ -38,6 +38,8 @@ #include "physics/physics.h" +#include "sound/sound.h" + diff --git a/src/object/task/taskterraform.cpp b/src/object/task/taskterraform.cpp index 63317bc9..3b6e6ef3 100644 --- a/src/object/task/taskterraform.cpp +++ b/src/object/task/taskterraform.cpp @@ -39,6 +39,8 @@ #include "physics/physics.h" +#include "sound/sound.h" + const float ENERGY_TERRA = 0.40f; // energy consumed by blow const float ACTION_RADIUS = 400.0f; diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index f2267c92..a269eace 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -56,6 +56,8 @@ #include "object/task/task.h" +#include "sound/sound.h" + const float LANDING_SPEED = 3.0f; diff --git a/src/script/script.cpp b/src/script/script.cpp index e4926258..8d01412d 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -20,8 +20,6 @@ #include "script/script.h" -#include "app/pausemanager.h" - #include "common/restext.h" #include "common/stringutils.h" @@ -64,7 +62,6 @@ CScript::CScript(COldObject* object) m_terrain = m_main->GetTerrain(); m_water = m_engine->GetWater(); m_interface = m_main->GetInterface(); - m_pause = CPauseManager::GetInstancePointer(); m_ipf = CBOT_IPF; m_errMode = ERM_STOP; @@ -322,6 +319,11 @@ void CScript::SetStepMode(bool bStep) m_bStepMode = bStep; } +bool CScript::GetStepMode() +{ + return m_bStepMode; +} + // Runs the program from the beginning. @@ -379,13 +381,8 @@ bool CScript::Continue() GetError(s); m_main->GetDisplayText()->DisplayText(s.c_str(), m_object, 10.0f, Ui::TT_ERROR); } - m_pause->SetPause(PAUSE_EDITOR); // gives pause return true; } - if ( !m_bContinue ) - { - m_pause->SetPause(PAUSE_EDITOR); // gives pause - } } return false; @@ -427,10 +424,6 @@ bool CScript::Step() if ( !m_bRun ) return true; if ( !m_bStepMode ) return false; - // ??? m_engine->SetPause(false); - // TODO: m_app StepSimulation??? m_engine->StepSimulation(0.01f); // advance of 10ms - // ??? m_engine->SetPause(true); - if ( m_botProg->Run(this, 0) ) // step mode { m_botProg->GetError(m_error, m_cursor1, m_cursor2); @@ -454,14 +447,6 @@ bool CScript::Step() } return true; } - - if ( m_bContinue ) // instuction "move", "goto", etc. ? - { - if (m_pause->GetPauseType() == PAUSE_EDITOR) - { - m_pause->ClearPause(); // removes the pause - } - } return false; } diff --git a/src/script/script.h b/src/script/script.h index 9d0d7617..d57d2711 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -34,7 +34,6 @@ class COldObject; class CTaskExecutorObject; class CRobotMain; -class CPauseManager; class CScriptFunctions; namespace Ui @@ -70,6 +69,7 @@ public: void GetTitle(char* buffer); void SetStepMode(bool bStep); + bool GetStepMode(); bool Run(); bool Continue(); bool Step(); @@ -110,7 +110,6 @@ protected: CRobotMain* m_main = nullptr; Gfx::CTerrain* m_terrain = nullptr; Gfx::CWater* m_water = nullptr; - CPauseManager* m_pause = nullptr; int m_ipf = 0; // number of instructions/second int m_errMode = 0; // what to do in case of error diff --git a/src/ui/displayinfo.cpp b/src/ui/displayinfo.cpp index d6e45cbb..ed01cb4c 100644 --- a/src/ui/displayinfo.cpp +++ b/src/ui/displayinfo.cpp @@ -21,6 +21,7 @@ #include "ui/displayinfo.h" #include "app/app.h" +#include "app/pausemanager.h" #include "common/misc.h" #include "common/restext.h" @@ -79,7 +80,6 @@ CDisplayInfo::CDisplayInfo() m_lightSuppl = -1; m_toto = nullptr; m_bSoluce = false; - m_initPause = PAUSE_NONE; m_bEditLock = false; m_infoCamera = Gfx::CAM_TYPE_NULL; m_index = -1; @@ -363,8 +363,7 @@ void CDisplayInfo::StartDisplayInfo(std::string filename, int index, bool bSoluc m_main->SetEditLock(true, false); m_main->SetEditFull(false); - m_initPause = m_pause->GetPauseType(); - m_pause->SetPause(PAUSE_SATCOM); + m_satcomPause = m_pause->ActivatePause(PAUSE_SATCOM); m_infoCamera = m_camera->GetType(); m_camera->SetType(Gfx::CAM_TYPE_INFO); @@ -829,9 +828,10 @@ void CDisplayInfo::StopDisplayInfo() } else { - m_pause->SetPause(m_initPause); m_main->SetEditLock(false, false); } + m_pause->DeactivatePause(m_satcomPause); + m_satcomPause = nullptr; m_camera->SetType(m_infoCamera); m_engine->SetDrawWorld(true); // draws all on the interface diff --git a/src/ui/displayinfo.h b/src/ui/displayinfo.h index c41c4ad1..c269921d 100644 --- a/src/ui/displayinfo.h +++ b/src/ui/displayinfo.h @@ -19,8 +19,6 @@ #pragma once -#include "app/pausemanager.h" - #include "common/event.h" #include "graphics/engine/camera.h" @@ -30,6 +28,8 @@ class CRobotMain; class CObject; class CEventQueue; +class CPauseManager; +struct ActivePause; struct Event; @@ -92,7 +92,7 @@ protected: Math::Point m_infoFinalDim; int m_lightSuppl; bool m_bEditLock; - PauseType m_initPause; + ActivePause* m_satcomPause = nullptr; bool m_bSoluce; CObject* m_toto; }; diff --git a/src/ui/mainshort.cpp b/src/ui/mainshort.cpp index 6d11f2b4..e8c8a6b3 100644 --- a/src/ui/mainshort.cpp +++ b/src/ui/mainshort.cpp @@ -107,7 +107,7 @@ bool CMainShort::CreateShortcuts() m_engine->GetPause()) ) // hangs during edition? { m_interface->CreateShortcut(pos, dim, 128+6, EVENT_OBJECT_EDITLOCK); - if(!m_engine->GetPause() || CPauseManager::GetInstancePointer()->GetPauseType() == PAUSE_DIALOG) + if (!m_engine->GetPause()) return true; } if (m_main->GetFreePhoto() && m_main->GetSelect() == nullptr) diff --git a/src/ui/screen/screen_io.cpp b/src/ui/screen/screen_io.cpp index ae2703f3..f9c6b28d 100644 --- a/src/ui/screen/screen_io.cpp +++ b/src/ui/screen/screen_io.cpp @@ -27,6 +27,8 @@ #include "level/parser/parser.h" +#include "sound/sound.h" + #include "ui/screen/screen_level_list.h" #include "ui/controls/button.h" diff --git a/src/ui/screen/screen_main_menu.cpp b/src/ui/screen/screen_main_menu.cpp index dbbe6955..a730610b 100644 --- a/src/ui/screen/screen_main_menu.cpp +++ b/src/ui/screen/screen_main_menu.cpp @@ -25,6 +25,8 @@ #include "level/parser/parser.h" +#include "sound/sound.h" + #include "ui/controls/button.h" #include "ui/controls/group.h" #include "ui/controls/interface.h" diff --git a/src/ui/screen/screen_setup_sound.cpp b/src/ui/screen/screen_setup_sound.cpp index af8d86b9..d613b474 100644 --- a/src/ui/screen/screen_setup_sound.cpp +++ b/src/ui/screen/screen_setup_sound.cpp @@ -26,6 +26,8 @@ #include "graphics/engine/camera.h" +#include "sound/sound.h" + #include "ui/controls/button.h" #include "ui/controls/interface.h" #include "ui/controls/label.h" diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp index cc0b20b3..e4ec199d 100644 --- a/src/ui/studio.cpp +++ b/src/ui/studio.cpp @@ -23,6 +23,7 @@ #include "CBot/CBotDll.h" #include "app/app.h" +#include "app/pausemanager.h" #include "common/event.h" #include "common/logger.h" @@ -92,7 +93,6 @@ CStudio::CStudio() m_bRealTime = true; m_bRunning = false; m_fixInfoTextTime = 0.0f; - m_initPause = PAUSE_NONE; m_dialog = SD_NULL; m_editCamera = Gfx::CAM_TYPE_NULL; } @@ -352,6 +352,22 @@ bool CStudio::EventFrame(const Event &event) list = static_cast< CList* >(pw->SearchControl(EVENT_STUDIO_LIST)); if ( list == nullptr ) return false; + if (m_script->IsRunning() && (!m_script->GetStepMode() || m_script->IsContinue())) + { + if (m_editorPause != nullptr) + { + m_pause->DeactivatePause(m_editorPause); + m_editorPause = nullptr; + } + } + else + { + if (m_editorPause == nullptr) + { + m_editorPause = m_pause->ActivatePause(PAUSE_EDITOR); + } + } + if ( !m_script->IsRunning() && m_bRunning ) // stop? { m_bRunning = false; @@ -557,7 +573,6 @@ void CStudio::StartEditScript(CScript *script, std::string name, Program* progra m_main->SetEditLock(true, true); m_main->SetEditFull(false); - m_initPause = m_pause->GetPauseType(); m_main->SetSpeed(1.0f); m_editCamera = m_camera->GetType(); m_camera->SetType(Gfx::CAM_TYPE_EDIT); @@ -889,7 +904,8 @@ bool CStudio::StopEditScript(bool bCancel) m_interface->DeleteControl(EVENT_WINDOW3); - m_pause->SetPause(m_initPause); + m_pause->DeactivatePause(m_editorPause); + m_editorPause = nullptr; m_sound->MuteAll(false); m_main->SetEditLock(false, true); m_camera->SetType(m_editCamera); @@ -960,27 +976,22 @@ void CStudio::UpdateFlux() { if ( m_bRealTime ) // run? { - if(m_pause->GetPauseType() == PAUSE_EDITOR) - { - m_pause->ClearPause(); - m_sound->MuteAll(false); - } + m_pause->DeactivatePause(m_editorPause); + m_editorPause = nullptr; } else // step by step? { - if(!m_pause->GetPause()) + if (m_editorPause == nullptr) { - m_pause->SetPause(PAUSE_EDITOR); - m_sound->MuteAll(true); + m_editorPause = m_pause->ActivatePause(PAUSE_EDITOR); } } } else // stop? { - if(!m_pause->GetPause()) + if (m_editorPause == nullptr) { - m_pause->SetPause(PAUSE_EDITOR); - m_sound->MuteAll(true); + m_editorPause = m_pause->ActivatePause(PAUSE_EDITOR); } } } diff --git a/src/ui/studio.h b/src/ui/studio.h index e1059acc..3b2b2088 100644 --- a/src/ui/studio.h +++ b/src/ui/studio.h @@ -19,8 +19,6 @@ #pragma once -#include "app/pausemanager.h" - #include "common/event.h" #include "graphics/engine/camera.h" @@ -32,6 +30,8 @@ class CScript; class CSoundInterface; class CSettings; struct Program; +class CPauseManager; +struct ActivePause; namespace Ui { @@ -114,7 +114,7 @@ protected: float m_fixInfoTextTime; bool m_bRunning; bool m_bRealTime; - PauseType m_initPause; + ActivePause* m_editorPause = nullptr; std::string m_helpFilename; StudioDialog m_dialog;