[colobot] 252/390: CController - entry point into CRobotMain and CMainDialog
Didier Raboud
odyx at moszumanska.debian.org
Fri Jun 12 14:21:51 UTC 2015
This is an automated email from the git hooks/post-receive script.
odyx pushed a commit to branch upstream/latest
in repository colobot.
commit 986cf98aafcfc1522212fd51c666aa1b826bde7b
Author: krzys-h <krzys_h at interia.pl>
Date: Mon Dec 22 10:35:05 2014 +0100
CController - entry point into CRobotMain and CMainDialog
---
src/CMakeLists.txt | 1 +
src/app/app.cpp | 50 ++++++-------
src/app/app.h | 6 +-
src/app/controller.cpp | 88 +++++++++++++++++++++++
src/app/controller.h | 65 +++++++++++++++++
src/object/robotmain.cpp | 183 +++++++++++++++++++++++++++--------------------
src/object/robotmain.h | 13 ++--
src/ui/maindialog.cpp | 35 ++++++---
src/ui/maindialog.h | 2 +
9 files changed, 323 insertions(+), 120 deletions(-)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9e23493..a1e1c66 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -61,6 +61,7 @@ endif()
# Source files
set(BASE_SOURCES
app/app.cpp
+ app/controller.cpp
app/input.cpp
app/pausemanager.cpp
app/system.cpp
diff --git a/src/app/app.cpp b/src/app/app.cpp
index bdea2d7..d598c0e 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -21,6 +21,7 @@
#include "app/app.h"
+#include "app/controller.h"
#include "app/input.h"
#include "app/system.h"
@@ -108,16 +109,16 @@ CApplication::CApplication()
m_profile = new CProfile();
m_input = new CInput();
- m_engine = nullptr;
- m_device = nullptr;
- m_modelManager = nullptr;
- m_robotMain = nullptr;
- m_sound = nullptr;
+ m_engine = nullptr;
+ m_device = nullptr;
+ m_modelManager = nullptr;
+ m_controller = nullptr;
+ m_sound = nullptr;
- m_exitCode = 0;
- m_active = false;
- m_debugModes = 0;
- m_restart = false;
+ m_exitCode = 0;
+ m_active = false;
+ m_debugModes = 0;
+ m_restart = false;
m_windowTitle = "Colobot: Gold Edition";
@@ -588,14 +589,15 @@ bool CApplication::Create()
m_modelManager = new Gfx::CModelManager(m_engine);
// Create the robot application.
- m_robotMain = new CRobotMain(this, !defaultValues);
-
- if (defaultValues) m_robotMain->CreateIni();
-
- if (! m_runSceneName.empty())
- m_robotMain->LoadSceneOnStart(m_runSceneName, m_runSceneRank);
- else
- m_robotMain->ChangePhase(PHASE_WELCOME1);
+ m_controller = new CController(this, !defaultValues);
+
+ if (m_runSceneName.empty())
+ m_controller->StartApp();
+ else {
+ m_controller->GetRobotMain()->ChangePhase(PHASE_USER); // To load userlevel list - TODO: this is ugly
+ m_controller->GetRobotMain()->SetExitAfterMission(true);
+ m_controller->StartGame(m_runSceneName, m_runSceneRank/100, m_runSceneRank%100);
+ }
return true;
}
@@ -672,8 +674,8 @@ void CApplication::Destroy()
{
m_joystickEnabled = false;
- delete m_robotMain;
- m_robotMain = nullptr;
+ delete m_controller;
+ m_controller = nullptr;
delete m_sound;
m_sound = nullptr;
@@ -775,7 +777,7 @@ bool CApplication::ChangeVideoConfig(const Gfx::GLDeviceConfig &newConfig)
( static_cast<Gfx::CGLDevice*>(m_device) )->ConfigChanged(m_deviceConfig);
m_engine->ResetAfterDeviceChanged();
- m_robotMain->ResetAfterDeviceChanged();
+ m_controller->GetRobotMain()->ResetAfterDeviceChanged();
return true;
}
@@ -993,8 +995,8 @@ int CApplication::Run()
if (m_engine != nullptr)
passOn = m_engine->ProcessEvent(event);
- if (passOn && m_robotMain != nullptr)
- m_robotMain->ProcessEvent(event);
+ if (passOn && m_controller != nullptr)
+ m_controller->ProcessEvent(event);
}
StopPerformanceCounter(PCNT_EVENT_PROCESSING);
@@ -1003,14 +1005,14 @@ int CApplication::Run()
// Prepare and process step simulation event
event = CreateUpdateEvent();
- if (event.type != EVENT_NULL && m_robotMain != nullptr)
+ if (event.type != EVENT_NULL && m_controller != nullptr)
{
LogEvent(event);
m_sound->FrameMove(m_relTime);
StartPerformanceCounter(PCNT_UPDATE_GAME);
- m_robotMain->ProcessEvent(event);
+ m_controller->ProcessEvent(event);
StopPerformanceCounter(PCNT_UPDATE_GAME);
StartPerformanceCounter(PCNT_UPDATE_ENGINE);
diff --git a/src/app/app.h b/src/app/app.h
index a8ca340..818eaf4 100644
--- a/src/app/app.h
+++ b/src/app/app.h
@@ -40,7 +40,7 @@
class CInstanceManager;
class CEventQueue;
-class CRobotMain;
+class CController;
class CSoundInterface;
class CInput;
class CObjectManager;
@@ -373,8 +373,8 @@ protected:
Gfx::CModelManager* m_modelManager;
//! Sound subsystem
CSoundInterface* m_sound;
- //! Main class of the proper game engine
- CRobotMain* m_robotMain;
+ //! Game controller - game engine and UI
+ CController* m_controller;
//! Profile (INI) reader/writer
CProfile* m_profile;
//! Input manager
diff --git a/src/app/controller.cpp b/src/app/controller.cpp
new file mode 100644
index 0000000..b7eb670
--- /dev/null
+++ b/src/app/controller.cpp
@@ -0,0 +1,88 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
+ *
+ * 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://gnu.org/licenses
+ */
+
+#include "app/controller.h"
+
+
+#include "object/robotmain.h"
+
+#include "ui/maindialog.h"
+
+
+template<> CController* CSingleton<CController>::m_instance = nullptr;
+
+
+CController::CController(CApplication* app, bool loadProfile)
+{
+ m_app = app;
+ m_main = new CRobotMain(this);
+ m_dialog = new Ui::CMainDialog();
+
+ m_main->Create(loadProfile);
+ m_dialog->Create();
+ if (!loadProfile)
+ m_main->CreateIni();
+ else
+ m_main->LoadIni();
+}
+
+CController::~CController()
+{
+ delete m_dialog;
+ m_dialog = nullptr;
+
+ delete m_main;
+ m_main = nullptr;
+
+ m_app = nullptr;
+}
+
+CApplication* CController::GetApplication()
+{
+ return m_app;
+}
+
+CRobotMain* CController::GetRobotMain()
+{
+ return m_main;
+}
+
+Ui::CMainDialog* CController::GetMainDialog()
+{
+ return m_dialog;
+}
+
+void CController::StartApp()
+{
+ m_main->ChangePhase(PHASE_WELCOME1);
+}
+
+void CController::StartGame(std::string cat, int chap, int lvl)
+{
+ m_dialog->SetSceneName(cat.c_str());
+ m_dialog->SetSceneRank(chap*100+lvl);
+ m_main->ChangePhase(PHASE_LOADING);
+}
+
+void CController::ProcessEvent(Event& event)
+{
+ bool passOn = m_dialog->EventProcess(event);
+ if(passOn)
+ m_main->ProcessEvent(event);
+}
\ No newline at end of file
diff --git a/src/app/controller.h b/src/app/controller.h
new file mode 100644
index 0000000..8a84a5f
--- /dev/null
+++ b/src/app/controller.h
@@ -0,0 +1,65 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
+ *
+ * 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://gnu.org/licenses
+ */
+
+/**
+ * \file app/controller.h
+ * \brief CController class
+ */
+
+#pragma once
+
+#include "common/event.h"
+#include "common/singleton.h"
+
+class CApplication;
+class CRobotMain;
+namespace Ui {
+class CMainDialog;
+}
+
+/**
+ * \class CController
+ * \brief Entry point into CRobotMain and CMainDialog
+ */
+class CController : public CSingleton<CController>
+{
+public:
+ CController(CApplication* app, bool loadProfile = true);
+ ~CController();
+
+ //! Return CApplication instance
+ CApplication* GetApplication();
+ //! Return CRobotMain instance
+ CRobotMain* GetRobotMain();
+ //! Return CMainDialog instance
+ Ui::CMainDialog* GetMainDialog();
+
+ //! Event processing
+ void ProcessEvent(Event &event);
+
+ //! Start the application
+ void StartApp();
+ //! Starts the simulation, loading the given scene
+ void StartGame(std::string cat, int chap, int lvl);
+
+private:
+ CApplication* m_app;
+ CRobotMain* m_main;
+ Ui::CMainDialog* m_dialog;
+};
\ No newline at end of file
diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp
index 69ee3c7..caee647 100644
--- a/src/object/robotmain.cpp
+++ b/src/object/robotmain.cpp
@@ -23,6 +23,7 @@
#include "CBot/CBotDll.h"
#include "app/app.h"
+#include "app/controller.h"
#include "app/input.h"
#include "common/event.h"
@@ -120,35 +121,34 @@ float g_unit; // conversion factor
//! Constructor of robot application
-CRobotMain::CRobotMain(CApplication* app, bool loadProfile)
-{
- m_app = app;
-
- m_eventQueue = m_app->GetEventQueue();
- m_sound = m_app->GetSound();
-
- m_engine = Gfx::CEngine::GetInstancePointer();
- m_lightMan = m_engine->GetLightManager();
- m_particle = m_engine->GetParticle();
- m_water = m_engine->GetWater();
- m_cloud = m_engine->GetCloud();
- m_lightning = m_engine->GetLightning();
- m_planet = m_engine->GetPlanet();
- m_pause = CPauseManager::GetInstancePointer();
- m_input = CInput::GetInstancePointer();
-
- m_interface = new Ui::CInterface();
- m_terrain = new Gfx::CTerrain();
- m_camera = new Gfx::CCamera();
- m_displayText = new Ui::CDisplayText();
- m_movie = new CMainMovie();
- m_dialog = new Ui::CMainDialog();
- m_short = new Ui::CMainShort();
- m_map = new Ui::CMainMap();
+CRobotMain::CRobotMain(CController* controller)
+{
+ m_ctrl = controller;
+ m_app = nullptr;
+
+ m_eventQueue = nullptr;
+ m_sound = nullptr;
+
+ m_engine = nullptr;
+ m_lightMan = nullptr;
+ m_particle = nullptr;
+ m_water = nullptr;
+ m_cloud = nullptr;
+ m_lightning = nullptr;
+ m_planet = nullptr;
+ m_pause = nullptr;
+ m_input = nullptr;
+
+ m_interface = nullptr;
+ m_terrain = nullptr;
+ m_camera = nullptr;
+ m_displayText = nullptr;
+ m_movie = nullptr;
+ m_dialog = nullptr;
+ m_short = nullptr;
+ m_map = nullptr;
m_displayInfo = nullptr;
- m_engine->SetTerrain(m_terrain);
-
m_time = 0.0f;
m_gameTime = 0.0f;
@@ -199,10 +199,7 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile)
m_friendAim = false;
m_resetCreate = false;
m_shortCut = true;
-
- m_engine->SetMovieLock(m_movieLock);
-
- m_movie->Flush();
+
m_movieInfoIndex = -1;
m_tooltipPos = Math::Point(0.0f, 0.0f);
@@ -220,15 +217,67 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile)
m_autosaveSlots = 3;
m_autosaveLast = 0.0f;
- FlushDisplayInfo();
+ m_cameraPan = 0.0f;
+ m_cameraZoom = 0.0f;
+ g_id = 0;
+ g_build = 0;
+ g_researchDone = 0; // no research done
+ g_researchEnable = 0;
+ g_unit = UNIT;
+
+ m_gamerName = "";
+
+ for (int i = 0; i < MAXSHOWLIMIT; i++)
+ {
+ m_showLimit[i].used = false;
+ m_showLimit[i].total = 0;
+ m_showLimit[i].link = 0;
+ }
+}
+
+void CRobotMain::Create(bool loadProfile)
+{
+ m_app = m_ctrl->GetApplication();
+
+ m_eventQueue = m_app->GetEventQueue();
+ m_sound = m_app->GetSound();
+
+ m_engine = Gfx::CEngine::GetInstancePointer();
+ m_lightMan = m_engine->GetLightManager();
+ m_particle = m_engine->GetParticle();
+ m_water = m_engine->GetWater();
+ m_cloud = m_engine->GetCloud();
+ m_lightning = m_engine->GetLightning();
+ m_planet = m_engine->GetPlanet();
+ m_pause = CPauseManager::GetInstancePointer();
+ m_input = CInput::GetInstancePointer();
+
+ m_interface = new Ui::CInterface();
+ m_terrain = new Gfx::CTerrain();
+ m_camera = new Gfx::CCamera();
+ m_displayText = new Ui::CDisplayText();
+ m_movie = new CMainMovie();
+ m_dialog = m_ctrl->GetMainDialog();
+ m_short = new Ui::CMainShort();
+ m_map = new Ui::CMainMap();
+ m_displayInfo = nullptr;
+
+ m_engine->SetTerrain(m_terrain);
+
+ m_engine->SetMovieLock(m_movieLock);
+
+ m_movie->Flush();
+
+ FlushDisplayInfo();
+
m_fontSize = 19.0f;
m_windowPos = Math::Point(0.15f, 0.17f);
m_windowDim = Math::Point(0.70f, 0.66f);
-
+
float fValue;
int iValue;
-
+
if (loadProfile)
{
if (GetProfile().GetFloatProperty("Edit", "FontSize", fValue)) m_fontSize = fValue;
@@ -237,12 +286,12 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile)
if (GetProfile().GetFloatProperty("Edit", "WindowDimX", fValue)) m_windowDim.x = fValue;
if (GetProfile().GetFloatProperty("Edit", "WindowDimY", fValue)) m_windowDim.y = fValue;
}
-
+
m_IOPublic = false;
m_IODim = Math::Point(320.0f/640.0f, (121.0f+18.0f*8)/480.0f);
m_IOPos.x = (1.0f-m_IODim.x)/2.0f; // in the middle
m_IOPos.y = (1.0f-m_IODim.y)/2.0f;
-
+
if (loadProfile)
{
if (GetProfile().GetIntProperty ("Edit", "IOPublic", iValue)) m_IOPublic = iValue;
@@ -251,33 +300,15 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile)
if (GetProfile().GetFloatProperty("Edit", "IODimX", fValue)) m_IODim.x = fValue;
if (GetProfile().GetFloatProperty("Edit", "IODimY", fValue)) m_IODim.y = fValue;
}
-
+
m_short->FlushShortcuts();
InitEye();
-
+
m_engine->SetTracePrecision(1.0f);
-
- m_cameraPan = 0.0f;
- m_cameraZoom = 0.0f;
-
- g_id = 0;
- g_build = 0;
- g_researchDone = 0; // no research done
- g_researchEnable = 0;
- g_unit = UNIT;
-
- m_gamerName = "";
+
if (loadProfile) GetProfile().GetStringProperty("Gamer", "LastName", m_gamerName);
SetGlobalGamerName(m_gamerName);
ReadFreeParam();
- if (loadProfile) m_dialog->SetupRecall();
-
- for (int i = 0; i < MAXSHOWLIMIT; i++)
- {
- m_showLimit[i].used = false;
- m_showLimit[i].total = 0;
- m_showLimit[i].link = 0;
- }
CScriptFunctions::m_filesDir = CResourceManager::GetSaveLocation()+"/"+m_dialog->GetFilesDir(); //TODO: Refactor to PHYSFS while rewriting CBot engine
CScriptFunctions::Init();
@@ -304,18 +335,17 @@ CRobotMain::~CRobotMain()
delete m_movie;
m_movie = nullptr;
- delete m_dialog;
- m_dialog = nullptr;
-
delete m_short;
m_short = nullptr;
delete m_map;
m_map = nullptr;
-
+
+ m_dialog = nullptr;
m_input = nullptr;
m_pause = nullptr;
m_app = nullptr;
+ m_ctrl = nullptr;
}
Gfx::CCamera* CRobotMain::GetCamera()
@@ -338,16 +368,6 @@ Ui::CDisplayText* CRobotMain::GetDisplayText()
return m_displayText;
}
-void CRobotMain::LoadSceneOnStart(const std::string& name, int rank)
-{
- m_exitAfterMission = true;
- // TODO: fix this ugly dependency :(
- ChangePhase(PHASE_USER); // To load userlevel list
- m_dialog->SetSceneName(name.c_str());
- m_dialog->SetSceneRank(rank);
- ChangePhase(PHASE_LOADING);
-}
-
void CRobotMain::ResetAfterDeviceChanged()
{
if(m_phase == PHASE_SETUPds ||
@@ -382,6 +402,11 @@ void CRobotMain::CreateIni()
GetProfile().Save();
}
+void CRobotMain::LoadIni()
+{
+ m_dialog->SetupRecall();
+}
+
//! Changes phase
void CRobotMain::ChangePhase(Phase phase)
{
@@ -649,7 +674,6 @@ bool CRobotMain::ProcessEvent(Event &event)
}
}
- m_dialog->EventProcess(event);
m_displayText->EventProcess(event);
RemoteCamera(m_cameraPan, m_cameraZoom, event.rTime);
@@ -696,14 +720,10 @@ bool CRobotMain::ProcessEvent(Event &event)
if (event.type == EVENT_SPEED)
SetSpeed(1.0f);
- if (!m_dialog->EventProcess(event))
+ if (event.type == EVENT_MOUSE_MOVE)
{
- if (event.type == EVENT_MOUSE_MOVE)
- {
- m_lastMousePos = event.mousePos;
- HiliteObject(event.mousePos);
- }
- return false;
+ m_lastMousePos = event.mousePos;
+ HiliteObject(event.mousePos);
}
if (!m_displayText->EventProcess(event))
@@ -6186,4 +6206,9 @@ void CRobotMain::Autosave()
IOWriteScene(savegameFileName.c_str(), fileCBot.c_str(), const_cast<char*>((std::string("[AUTOSAVE] ")+timestr).c_str()));
m_dialog->MakeSaveScreenshot(dir + "/screen.png");
+}
+
+void CRobotMain::SetExitAfterMission(bool exit)
+{
+ m_exitAfterMission = exit;
}
\ No newline at end of file
diff --git a/src/object/robotmain.h b/src/object/robotmain.h
index f84f53e..9c4281c 100644
--- a/src/object/robotmain.h
+++ b/src/object/robotmain.h
@@ -74,6 +74,7 @@ enum Phase
};
+class CController;
class CEventQueue;
class CSoundInterface;
class CLevelParserLine;
@@ -170,18 +171,18 @@ const int SATCOM_MAX = 6;
class CRobotMain : public CSingleton<CRobotMain>
{
public:
- CRobotMain(CApplication* app, bool loadProfile);
+ CRobotMain(CController* controller);
virtual ~CRobotMain();
+
+ void Create(bool loadProfile = true);
Gfx::CCamera* GetCamera();
Gfx::CTerrain* GetTerrain();
Ui::CInterface* GetInterface();
Ui::CDisplayText* GetDisplayText();
- //! Caused the given mission to be loaded immediately after start
- void LoadSceneOnStart(const std::string& name, int rank);
-
void CreateIni();
+ void LoadIni();
void ResetAfterDeviceChanged();
@@ -350,6 +351,9 @@ public:
int GetAutosaveInterval();
void SetAutosaveSlots(int slots);
int GetAutosaveSlots();
+
+ //! Enable mode where completing mission closes the game
+ void SetExitAfterMission(bool exit);
protected:
bool EventFrame(const Event &event);
@@ -389,6 +393,7 @@ protected:
protected:
+ CController* m_ctrl;
CApplication* m_app;
CEventQueue* m_eventQueue;
CMainMovie* m_movie;
diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp
index 3240cfa..40bec52 100644
--- a/src/ui/maindialog.cpp
+++ b/src/ui/maindialog.cpp
@@ -116,15 +116,15 @@ static int perso_color[3*10*3] =
CMainDialog::CMainDialog()
{
- m_app = CApplication::GetInstancePointer();
- m_eventQueue = m_app->GetEventQueue();
- m_sound = m_app->GetSound();
- m_main = CRobotMain::GetInstancePointer();
- m_interface = m_main->GetInterface();
- m_camera = m_main->GetCamera();
- m_engine = Gfx::CEngine::GetInstancePointer();
- m_particle = m_engine->GetParticle();
- m_pause = CPauseManager::GetInstancePointer();
+ m_app = nullptr;
+ m_eventQueue = nullptr;
+ m_sound = nullptr;
+ m_main = nullptr;
+ m_interface = nullptr;
+ m_camera = nullptr;
+ m_engine = nullptr;
+ m_particle = nullptr;
+ m_pause = nullptr;
m_phase = PHASE_NAME;
m_phaseSetup = PHASE_SETUPg;
@@ -182,11 +182,26 @@ CMainDialog::CMainDialog()
m_publicDir = "program";
m_filesDir = "files";
- m_setupFull = m_app->GetVideoConfig().fullScreen;
+ m_setupFull = false;
m_bDialog = false;
}
+void CMainDialog::Create()
+{
+ m_app = CApplication::GetInstancePointer();
+ m_eventQueue = m_app->GetEventQueue();
+ m_sound = m_app->GetSound();
+ m_main = CRobotMain::GetInstancePointer();
+ m_interface = m_main->GetInterface();
+ m_camera = m_main->GetCamera();
+ m_engine = Gfx::CEngine::GetInstancePointer();
+ m_particle = m_engine->GetParticle();
+ m_pause = CPauseManager::GetInstancePointer();
+
+ m_setupFull = m_app->GetVideoConfig().fullScreen;
+}
+
// Destructor of robot application.
CMainDialog::~CMainDialog()
diff --git a/src/ui/maindialog.h b/src/ui/maindialog.h
index d0753df..9d69e59 100644
--- a/src/ui/maindialog.h
+++ b/src/ui/maindialog.h
@@ -72,6 +72,8 @@ class CMainDialog
public:
CMainDialog();
~CMainDialog();
+
+ void Create();
bool EventProcess(const Event &event);
void ChangePhase(Phase phase);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git
More information about the Pkg-games-commits
mailing list