CPauseManager

dev-ui
krzys-h 2013-12-31 12:58:45 +01:00
parent 3536f1c7cc
commit 4a237f5925
15 changed files with 239 additions and 85 deletions

View File

@ -65,6 +65,7 @@ app/main.cpp
app/system.cpp
app/${SYSTEM_CPP_MODULE}
app/system_other.cpp
app/pausemanager.cpp
common/event.cpp
common/image.cpp
common/iman.cpp

83
src/app/pausemanager.cpp Normal file
View File

@ -0,0 +1,83 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
#include "app/pausemanager.h"
#include "common/logger.h"
template<> CPauseManager* CSingleton<CPauseManager>::m_instance = nullptr;
CPauseManager::CPauseManager()
{
m_pause = PAUSE_NONE;
}
CPauseManager::~CPauseManager()
{
}
void CPauseManager::SetPause(PauseType pause)
{
if(pause != PAUSE_NONE) {
if(m_pause != pause)
CLogger::GetInstancePointer()->Info("Game paused - %s\n", GetPauseName(pause).c_str());
m_pause = pause;
} else
ClearPause();
}
void CPauseManager::ClearPause()
{
if(m_pause != PAUSE_NONE)
CLogger::GetInstancePointer()->Info("Game resumed\n");
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;
}
std::string CPauseManager::GetPauseName(PauseType pause)
{
switch(pause)
{
case PAUSE_NONE: return "None";
case PAUSE_USER: return "User";
case PAUSE_SATCOM: return "SatCom";
case PAUSE_DIALOG: return "Dialog";
case PAUSE_EDITOR: return "CBot editor";
case PAUSE_VISIT: return "Visit";
case PAUSE_CHEAT: return "Cheat console";
case PAUSE_PHOTO: return "Photo mode";
default: assert(false); // Should never happen
}
}

57
src/app/pausemanager.h Normal file
View File

@ -0,0 +1,57 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
/**
* \file app/pausemanager.h
* \brief Management of pause modes
*/
#pragma once
#include "common/singleton.h"
#include <string>
enum PauseType {
PAUSE_NONE = 0,
PAUSE_USER,
PAUSE_SATCOM,
PAUSE_DIALOG,
PAUSE_EDITOR,
PAUSE_VISIT,
PAUSE_CHEAT,
PAUSE_PHOTO
};
class CPauseManager : public CSingleton<CPauseManager>
{
public:
CPauseManager();
~CPauseManager();
void SetPause(PauseType pause);
void ClearPause();
bool GetPause();
bool GetPause(PauseType pause);
PauseType GetPauseType();
private:
std::string GetPauseName(PauseType pause);
PauseType m_pause;
};

View File

@ -63,6 +63,7 @@ CEngine::CEngine(CApplication *app)
m_planet = nullptr;
m_sound = nullptr;
m_terrain = nullptr;
m_pause = nullptr;
m_showStats = false;
@ -80,7 +81,6 @@ CEngine::CEngine(CApplication *app)
m_fogStart[1] = 0.75f;
m_waterAddColor = Color(0.0f, 0.0f, 0.0f, 0.0f);
m_pause = false;
m_render = true;
m_movieLock = false;
m_shadowVisible = true;
@ -179,6 +179,7 @@ CEngine::~CEngine()
m_lightning = nullptr;
m_planet = nullptr;
m_terrain = nullptr;
m_pause = nullptr;
GetSystemUtils()->DestroyTimeStamp(m_lastFrameTime);
m_lastFrameTime = nullptr;
@ -252,6 +253,7 @@ bool CEngine::Create()
m_cloud = new CCloud(this);
m_lightning = new CLightning(this);
m_planet = new CPlanet(this);
m_pause = new CPauseManager();
m_lightMan->SetDevice(m_device);
m_particle->SetDevice(m_device);
@ -422,18 +424,13 @@ void CEngine::FrameUpdate()
bool CEngine::WriteScreenShot(const std::string& fileName, int width, int height)
{
// TODO write screenshot: not very important for now
GetLogger()->Trace("CEngine::WriteSceenShot(): stub!\n");
GetLogger()->Debug("CEngine::WriteSceenShot(): stub!\n");
return true;
}
void CEngine::SetPause(bool pause)
{
m_pause = pause;
}
bool CEngine::GetPause()
{
return m_pause;
return m_pause->GetPause();
}
void CEngine::SetMovieLock(bool lock)

View File

@ -24,6 +24,7 @@
#include "app/system.h"
#include "app/pausemanager.h"
#include "common/event.h"
#include "common/singleton.h"
@ -734,11 +735,8 @@ public:
bool WriteScreenShot(const std::string& fileName, int width, int height);
//@{
//! Management of game pause mode
void SetPause(bool pause);
//! Get pause mode
TEST_VIRTUAL bool GetPause();
//@}
//@{
//! Management of lock for the duration of movie sequence
@ -1288,6 +1286,7 @@ protected:
CLightning* m_lightning;
CPlanet* m_planet;
CTerrain* m_terrain;
CPauseManager* m_pause;
//! Last encountered error
std::string m_error;
@ -1300,9 +1299,6 @@ protected:
//! Whether to show stats (FPS, etc)
bool m_showStats;
std::string m_fpsText;
//! Pause mode
bool m_pause;
//! Rendering enabled?
bool m_render;
//! Lock for duration of movie?

View File

@ -618,6 +618,7 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile)
m_cloud = m_engine->GetCloud();
m_lightning = m_engine->GetLightning();
m_planet = m_engine->GetPlanet();
m_pause = CPauseManager::GetInstancePointer();
m_interface = new Ui::CInterface();
m_terrain = new Gfx::CTerrain();
@ -663,7 +664,6 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile)
m_satComLock = false;
m_editLock = false;
m_editFull = false;
m_pause = false;
m_hilite = false;
m_freePhoto = false;
m_showPos = false;
@ -1110,7 +1110,7 @@ void CRobotMain::ChangePhase(Phase phase)
m_resetCreate = false;
m_engine->SetMovieLock(m_movieLock);
ChangePause(false);
ChangePause(PAUSE_NONE);
FlushDisplayInfo();
m_engine->SetRankView(0);
m_terrain->FlushRelief();
@ -1387,7 +1387,7 @@ bool CRobotMain::ProcessEvent(Event &event)
MainMovieType type = m_movie->GetStopType();
if (type == MM_SATCOMopen)
{
ChangePause(false);
ChangePause(PAUSE_NONE);
SelectObject(m_infoObject, false); // hands over the command buttons
m_map->ShowMap(m_mapShow);
m_displayText->HideText(false);
@ -1419,7 +1419,7 @@ bool CRobotMain::ProcessEvent(Event &event)
if (pe == nullptr) return false;
pe->SetState(Ui::STATE_VISIBLE);
pe->SetFocus(true);
if (m_phase == PHASE_SIMUL) ChangePause(true);
if (m_phase == PHASE_SIMUL) ChangePause(PAUSE_CHEAT);
m_cmdEdit = true;
return false;
}
@ -1432,7 +1432,7 @@ bool CRobotMain::ProcessEvent(Event &event)
pe->GetText(cmd, 50);
pe->SetText("");
pe->ClearState(Ui::STATE_VISIBLE);
if (m_phase == PHASE_SIMUL) ChangePause(false);
if (m_phase == PHASE_SIMUL) ChangePause(PAUSE_NONE);
ExecuteCmd(cmd);
m_cmdEdit = false;
return false;
@ -1562,7 +1562,7 @@ bool CRobotMain::ProcessEvent(Event &event)
m_camera->GetType() != Gfx::CAM_TYPE_VISIT &&
!m_movie->IsExist())
{
ChangePause(!m_engine->GetPause());
ChangePause(m_pause->GetPause(PAUSE_USER) ? PAUSE_NONE : PAUSE_USER);
}
}
if (event.key.key == GetInputBinding(INPUT_SLOT_CAMERA).primary ||
@ -1891,12 +1891,12 @@ void CRobotMain::ExecuteCmd(char *cmd)
if (m_freePhoto)
{
m_camera->SetType(Gfx::CAM_TYPE_FREE);
ChangePause(true);
ChangePause(PAUSE_PHOTO);
}
else
{
m_camera->SetType(Gfx::CAM_TYPE_BACK);
ChangePause(false);
ChangePause(PAUSE_NONE);
}
return;
}
@ -1907,7 +1907,7 @@ void CRobotMain::ExecuteCmd(char *cmd)
if (m_freePhoto)
{
m_camera->SetType(Gfx::CAM_TYPE_FREE);
ChangePause(true);
ChangePause(PAUSE_PHOTO);
DeselectAll(); // removes the control buttons
m_map->ShowMap(false);
m_displayText->HideText(true);
@ -1915,7 +1915,7 @@ void CRobotMain::ExecuteCmd(char *cmd)
else
{
m_camera->SetType(Gfx::CAM_TYPE_BACK);
ChangePause(false);
ChangePause(PAUSE_NONE);
m_map->ShowMap(m_mapShow);
m_displayText->HideText(false);
}
@ -2174,7 +2174,7 @@ void CRobotMain::StartDisplayInfo(int index, bool movie)
{
m_movieInfoIndex = index;
m_movie->Start(MM_SATCOMopen, 2.5f);
ChangePause(true);
ChangePause(PAUSE_SATCOM);
m_infoObject = DeselectAll(); // removes the control buttons
m_displayText->HideText(true);
return;
@ -2184,7 +2184,7 @@ void CRobotMain::StartDisplayInfo(int index, bool movie)
if (m_movie->IsExist())
{
m_movie->Stop();
ChangePause(false);
ChangePause(PAUSE_NONE);
SelectObject(m_infoObject, false); // hands over the command buttons
m_displayText->HideText(false);
}
@ -2476,7 +2476,7 @@ void CRobotMain::StartDisplayVisit(EventType event)
m_camera->StartVisit(m_displayText->GetVisitGoal(event),
m_displayText->GetVisitDist(event));
m_displayText->SetVisit(event);
ChangePause(true);
ChangePause(PAUSE_VISIT);
}
//! Move the arrow to visit
@ -2530,7 +2530,7 @@ void CRobotMain::StopDisplayVisit()
m_camera->StopVisit();
m_displayText->ClearVisit();
ChangePause(false);
ChangePause(PAUSE_NONE);
if (m_visitObject != 0)
{
SelectObject(m_visitObject, false); // gives the command buttons
@ -2628,7 +2628,7 @@ bool CRobotMain::SelectObject(CObject* obj, bool displayError)
if (m_camera->GetType() == Gfx::CAM_TYPE_VISIT)
StopDisplayVisit();
if (m_movieLock || m_editLock || m_pause) return false;
if (m_movieLock || m_editLock || m_pause->GetPause()) return false;
if (m_movie->IsExist()) return false;
if (obj == nullptr || !IsSelectable(obj)) return false;
@ -3530,7 +3530,7 @@ bool CRobotMain::EventFrame(const Event &event)
}
// Moves edition indicator.
if (m_editLock || m_pause) // edition in progress?
if (m_editLock || m_pause->GetPause()) // edition in progress?
{
Ui::CControl* pc = m_interface->SearchControl(EVENT_OBJECT_EDITLOCK);
if (pc != nullptr)
@ -7022,14 +7022,16 @@ float CRobotMain::GetPersoAngle()
//! Changes on the pause mode
void CRobotMain::ChangePause(bool pause)
void CRobotMain::ChangePause(PauseType pause)
{
m_pause = pause;
m_engine->SetPause(m_pause);
if(pause != PAUSE_NONE)
m_pause->SetPause(pause);
else
m_pause->ClearPause();
m_sound->MuteAll(m_pause);
m_sound->MuteAll(m_pause->GetPause());
CreateShortcuts();
if (m_pause) HiliteClear();
if (m_pause->GetPause()) HiliteClear();
}

View File

@ -30,6 +30,8 @@
#include "object/object.h"
#include "object/mainmovie.h"
#include "app/pausemanager.h"
#include <stdio.h>
enum Phase
@ -253,7 +255,7 @@ public:
void SetTracePrecision(float factor);
float GetTracePrecision();
void ChangePause(bool pause);
void ChangePause(PauseType pause);
void SetSpeed(float speed);
float GetSpeed();
@ -440,6 +442,7 @@ protected:
Ui::CDisplayText* m_displayText;
Ui::CDisplayInfo* m_displayInfo;
CSoundInterface* m_sound;
CPauseManager* m_pause;
//! Bindings for user inputs
InputBinding m_inputBindings[INPUT_SLOT_MAX];
@ -495,7 +498,6 @@ protected:
bool m_satComLock; // call of SatCom is possible?
bool m_editLock; // edition in progress?
bool m_editFull; // edition in full screen?
bool m_pause; // simulation paused
bool m_hilite;
bool m_trainerPilot; // remote trainer?
bool m_suspend;

View File

@ -3423,6 +3423,7 @@ CScript::CScript(CObject* object, CTaskManager** secondaryTask)
m_secondaryTask = secondaryTask;
m_interface = m_main->GetInterface();
m_pause = CPauseManager::GetInstancePointer();
m_ipf = CBOT_IPF;
m_errMode = ERM_STOP;
@ -3821,12 +3822,12 @@ bool CScript::Continue(const Event &event)
GetError(s);
m_main->GetDisplayText()->DisplayText(s.c_str(), m_object, 10.0f, Ui::TT_ERROR);
}
m_engine->SetPause(true); // gives pause
m_pause->SetPause(PAUSE_EDITOR); // gives pause
return true;
}
if ( !m_bContinue )
{
m_engine->SetPause(true); // gives pause
m_pause->SetPause(PAUSE_EDITOR); // gives pause
}
}
@ -3869,9 +3870,9 @@ bool CScript::Step(const Event &event)
if ( !m_bRun ) return true;
if ( !m_bStepMode ) return false;
m_engine->SetPause(false);
// ??? m_engine->SetPause(false);
// TODO: m_app StepSimulation??? m_engine->StepSimulation(0.01f); // advance of 10ms
m_engine->SetPause(true);
// ??? m_engine->SetPause(true);
m_event = event;
@ -3901,7 +3902,7 @@ bool CScript::Step(const Event &event)
if ( m_bContinue ) // instuction "move", "goto", etc. ?
{
m_engine->SetPause(false); // removes the pause
m_pause->ClearPause(); // removes the pause
}
return false;
}

View File

@ -24,6 +24,8 @@
#include "common/event.h"
#include "app/pausemanager.h"
#include "CBot/CBotDll.h"
#include <stdio.h>
@ -217,6 +219,7 @@ protected:
CTaskManager* m_primaryTask;
CTaskManager** m_secondaryTask;
CObject* m_object;
CPauseManager* m_pause;
int m_ipf; // number of instructions/second
int m_errMode; // what to do in case of error

View File

@ -59,6 +59,7 @@ CDisplayInfo::CDisplayInfo()
m_main = CRobotMain::GetInstancePointer();
m_interface = m_main->GetInterface();
m_camera = m_main->GetCamera();
m_pause = CPauseManager::GetInstancePointer();
m_bInfoMaximized = true;
m_bInfoMinimized = false;
@ -330,13 +331,13 @@ void CDisplayInfo::HyperUpdate()
void CDisplayInfo::StartDisplayInfo(std::string filename, int index, bool bSoluce)
{
Gfx::Light light;
Gfx::Light light;
Math::Point pos, dim;
Ui::CWindow* pw;
Ui::CEdit* edit;
Ui::CButton* button;
Ui::CSlider* slider;
CMotionToto* toto;
CMotionToto* toto;
m_index = index;
m_bSoluce = bSoluce;
@ -355,8 +356,8 @@ void CDisplayInfo::StartDisplayInfo(std::string filename, int index, bool bSoluc
m_main->SetEditLock(true, false);
m_main->SetEditFull(false);
m_bInitPause = m_engine->GetPause();
m_engine->SetPause(true);
m_bInitPause = m_pause->GetPauseType();
m_pause->SetPause(PAUSE_SATCOM);
m_infoCamera = m_camera->GetType();
m_camera->SetType(Gfx::CAM_TYPE_INFO);
@ -839,7 +840,7 @@ void CDisplayInfo::StopDisplayInfo()
}
else
{
if ( !m_bInitPause ) m_engine->SetPause(false);
m_pause->SetPause(m_bInitPause);
m_main->SetEditLock(false, false);
}
m_camera->SetType(m_infoCamera);

View File

@ -25,6 +25,8 @@
#include "graphics/engine/camera.h"
#include "app/pausemanager.h"
class CRobotMain;
class CObject;
class CEventQueue;
@ -67,13 +69,14 @@ protected:
void CreateObjectsFile();
protected:
Gfx::CEngine* m_engine;
CEventQueue* m_event;
CRobotMain* m_main;
Gfx::CCamera* m_camera;
CInterface* m_interface;
Gfx::CParticle* m_particle;
Gfx::CLightManager* m_light;
Gfx::CEngine* m_engine;
CEventQueue* m_event;
CRobotMain* m_main;
Gfx::CCamera* m_camera;
CInterface* m_interface;
Gfx::CParticle* m_particle;
Gfx::CLightManager* m_light;
CPauseManager* m_pause;
bool m_bInfoMaximized;
bool m_bInfoMinimized;
@ -88,7 +91,7 @@ protected:
Math::Point m_infoFinalDim;
int m_lightSuppl;
bool m_bEditLock;
bool m_bInitPause;
PauseType m_bInitPause;
bool m_bSoluce;
CObject* m_toto;
};

View File

@ -120,6 +120,7 @@ CMainDialog::CMainDialog()
m_camera = m_main->GetCamera();
m_engine = Gfx::CEngine::GetInstancePointer();
m_particle = m_engine->GetParticle();
m_pause = CPauseManager::GetInstancePointer();
m_phase = PHASE_NAME;
m_phaseSetup = PHASE_SETUPg;
@ -6401,8 +6402,8 @@ void CMainDialog::StartSuspend()
{
m_sound->MuteAll(true);
m_main->ClearInterface();
m_bInitPause = m_engine->GetPause();
m_engine->SetPause(true);
m_bInitPause = m_pause->GetPauseType();
m_pause->SetPause(PAUSE_DIALOG);
m_engine->SetOverFront(false); // over flat behind
m_main->CreateShortcuts();
m_main->StartSuspend();
@ -6416,7 +6417,7 @@ void CMainDialog::StopSuspend()
{
m_sound->MuteAll(false);
m_main->ClearInterface();
if ( !m_bInitPause ) m_engine->SetPause(false);
m_pause->SetPause(m_bInitPause);
m_engine->SetOverFront(true); // over flat front
m_main->CreateShortcuts();
m_main->StopSuspend();

View File

@ -23,6 +23,8 @@
#include "object/robotmain.h"
#include "app/pausemanager.h"
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
@ -186,6 +188,7 @@ protected:
Gfx::CParticle* m_particle;
Gfx::CCamera* m_camera;
CSoundInterface* m_sound;
CPauseManager* m_pause;
Phase m_phase; // copy of CRobotMain
Phase m_phaseSetup; // tab selected
@ -242,26 +245,26 @@ protected:
bool m_bCameraInvertY; // for CCamera
bool m_bEffect; // for CCamera
Math::Point m_glintMouse;
float m_glintTime;
Math::Point m_glintMouse;
float m_glintTime;
int m_loadingCounter;
int m_loadingCounter;
bool m_bDialog; // this dialogue?
bool m_bDialogFire; // setting on fire?
bool m_bDialogDelete;
Math::Point m_dialogPos;
Math::Point m_dialogDim;
float m_dialogParti;
float m_dialogTime;
bool m_bInitPause;
bool m_bDialog; // this dialogue?
bool m_bDialogFire; // setting on fire?
bool m_bDialogDelete;
Math::Point m_dialogPos;
Math::Point m_dialogDim;
float m_dialogParti;
float m_dialogTime;
PauseType m_bInitPause;
Gfx::CameraType m_initCamera;
int m_partiPhase[10];
float m_partiTime[10];
Math::Point m_partiPos[10];
int m_partiPhase[10];
float m_partiTime[10];
Math::Point m_partiPos[10];
SceneInfo m_sceneInfo[MAXSCENE];
SceneInfo m_sceneInfo[MAXSCENE];
std::vector<fs::path> m_saveList;
};

View File

@ -71,6 +71,7 @@ CStudio::CStudio()
m_main = CRobotMain::GetInstancePointer();
m_interface = m_main->GetInterface();
m_camera = m_main->GetCamera();
m_pause = CPauseManager::GetInstancePointer();
m_bEditMaximized = false;
m_bEditMinimized = false;
@ -563,7 +564,7 @@ void CStudio::StartEditScript(CScript *script, std::string name, int rank)
m_main->SetEditLock(true, true);
m_main->SetEditFull(false);
m_bInitPause = m_engine->GetPause();
m_bInitPause = m_pause->GetPauseType();
m_main->SetSpeed(1.0f);
m_editCamera = m_camera->GetType();
m_camera->SetType(Gfx::CAM_TYPE_EDIT);
@ -882,7 +883,7 @@ bool CStudio::StopEditScript(bool bCancel)
button->SetState(STATE_VISIBLE);
}
if ( !m_bInitPause ) m_engine->SetPause(false);
m_pause->SetPause(m_bInitPause);
m_sound->MuteAll(false);
m_main->SetEditLock(false, true);
m_camera->SetType(m_editCamera);
@ -954,22 +955,22 @@ void CStudio::UpdateFlux()
#if 1
if ( m_bRealTime ) // run?
{
m_engine->SetPause(false);
m_pause->ClearPause();
m_sound->MuteAll(false);
}
else // step by step?
{
m_engine->SetPause(true);
m_pause->SetPause(PAUSE_EDITOR);
m_sound->MuteAll(true);
}
#else
m_engine->SetPause(false);
m_pause->ClearPause();
m_sound->MuteAll(false);
#endif
}
else // stop?
{
m_engine->SetPause(true);
m_pause->SetPause(PAUSE_EDITOR);
m_sound->MuteAll(true);
}
}

View File

@ -22,6 +22,8 @@
#include "graphics/engine/camera.h"
#include "app/pausemanager.h"
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
@ -96,6 +98,7 @@ protected:
CSoundInterface* m_sound;
CInterface* m_interface;
CApplication* m_app;
CPauseManager* m_pause;
int m_rank;
CScript* m_script;
@ -109,11 +112,11 @@ protected:
Math::Point m_editFinalPos;
Math::Point m_editFinalDim;
float m_time;
float m_fixInfoTextTime;
bool m_bRunning;
bool m_bRealTime;
bool m_bInitPause;
float m_time;
float m_fixInfoTextTime;
bool m_bRunning;
bool m_bRealTime;
PauseType m_bInitPause;
std::string m_helpFilename;
StudioDialog m_dialog;