[colobot] 09/145: Refactor some references to CRobotMain from CEngine

Didier Raboud odyx at moszumanska.debian.org
Mon Jul 11 12:56:12 UTC 2016


This is an automated email from the git hooks/post-receive script.

odyx pushed a commit to branch debian/master
in repository colobot.

commit 6585ee9ae8ef7fedb3cf7fdd3d83c933be703dff
Author: krzys-h <krzys_h at interia.pl>
Date:   Sat Mar 26 18:55:39 2016 +0100

    Refactor some references to CRobotMain from CEngine
---
 src/app/app.cpp                |  2 +-
 src/common/event.cpp           |  2 ++
 src/common/event.h             |  4 ++++
 src/graphics/engine/engine.cpp |  9 ++++++---
 src/graphics/engine/engine.h   |  8 +++++---
 src/level/robotmain.cpp        | 41 +++++++++++++++++------------------------
 src/level/robotmain.h          |  3 ---
 7 files changed, 35 insertions(+), 34 deletions(-)

diff --git a/src/app/app.cpp b/src/app/app.cpp
index 5e91af9..fbf6018 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -822,7 +822,7 @@ bool CApplication::ChangeVideoConfig(const Gfx::DeviceConfig &newConfig)
 
     m_device->ConfigChanged(m_deviceConfig);
 
-    m_engine->ResetAfterVideoConfigChanged();
+    m_eventQueue->AddEvent(Event(EVENT_RESOLUTION_CHANGED));
 
     return true;
 }
diff --git a/src/common/event.cpp b/src/common/event.cpp
index ccd7fe8..49b5218 100644
--- a/src/common/event.cpp
+++ b/src/common/event.cpp
@@ -68,6 +68,8 @@ void InitializeEventTypeTexts()
 
 
     EVENT_TYPE_TEXT[EVENT_UPDINTERFACE]      = "EVENT_UPDINTERFACE";
+    EVENT_TYPE_TEXT[EVENT_RESOLUTION_CHANGED]= "EVENT_RESOLUTION_CHANGED";
+    EVENT_TYPE_TEXT[EVENT_RELOAD_TEXTURES]   = "EVENT_RELOAD_TEXTURES";
     EVENT_TYPE_TEXT[EVENT_WIN]               = "EVENT_WIN";
     EVENT_TYPE_TEXT[EVENT_LOST]              = "EVENT_LOST";
 
diff --git a/src/common/event.h b/src/common/event.h
index 50fb0c9..b4eb79f 100644
--- a/src/common/event.h
+++ b/src/common/event.h
@@ -95,6 +95,10 @@ enum EventType
     //! Event sent on user quit request
     EVENT_QUIT              = 20,
     EVENT_UPDINTERFACE      = 21,
+    //! Event sent on resolution change
+    EVENT_RESOLUTION_CHANGED = 22,
+    //! Event sent when textures have to be reloaded
+    EVENT_RELOAD_TEXTURES   = 23,
     EVENT_WIN               = 30,
     EVENT_LOST              = 31,
 
diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp
index a66f806..afc8a17 100644
--- a/src/graphics/engine/engine.cpp
+++ b/src/graphics/engine/engine.cpp
@@ -359,8 +359,6 @@ void CEngine::ResetAfterVideoConfigChanged()
     m_size = m_app->GetVideoConfig().size;
     m_mouseSize = Math::Point(0.04f, 0.04f * (static_cast<float>(m_size.x) / static_cast<float>(m_size.y)));
 
-    CRobotMain::GetInstancePointer()->ResetAfterVideoConfigChanged(); //TODO: Remove cross-reference to CRobotMain
-
     // Update the camera projection matrix for new aspect ratio
     SetFocus(m_focus);
 
@@ -373,13 +371,18 @@ void CEngine::ReloadAllTextures()
     FlushTextureCache();
     m_text->FlushCache();
 
-    CRobotMain::GetInstancePointer()->ReloadAllTextures(); //TODO: Remove cross-reference to CRobotMain
+    m_app->GetEventQueue()->AddEvent(Event(EVENT_RELOAD_TEXTURES));
     UpdateGroundSpotTextures();
     LoadAllTextures();
 }
 
 bool CEngine::ProcessEvent(const Event &event)
 {
+    if (event.type == EVENT_RESOLUTION_CHANGED)
+    {
+        ResetAfterVideoConfigChanged();
+    }
+
     if (event.type == EVENT_KEY_DOWN)
     {
         auto data = event.GetData<KeyEventData>();
diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h
index 5fc65a2..bda5f78 100644
--- a/src/graphics/engine/engine.h
+++ b/src/graphics/engine/engine.h
@@ -655,9 +655,6 @@ public:
     //! Frees all resources before exit
     void            Destroy();
 
-    //! Resets some states and flushes textures after device was changed (e.g. resoulution changed)
-    void            ResetAfterVideoConfigChanged();
-
 
     //! Called once per frame, the call is the entry point for rendering
     void            Render();
@@ -1188,6 +1185,10 @@ public:
     void            AddDisplayCrashSpheres(const std::vector<Math::Sphere>& crashSpheres);
 
 protected:
+    //! Resets some states and flushes textures after device was changed (e.g. resoulution changed)
+    /** Instead of calling this directly, send EVENT_RESOLUTION_CHANGED event **/
+    void            ResetAfterVideoConfigChanged();
+
     //! Prepares the interface for 3D scene
     void        Draw3DScene();
     //! Renders shadow map
@@ -1281,6 +1282,7 @@ protected:
     static void WriteScreenShotThread(std::unique_ptr<WriteScreenShotData> data);
 
     //! Reloads all textures
+    /** This additionally sends EVENT_RELOAD_TEXTURES to reload all textures not maintained by CEngine **/
     void ReloadAllTextures();
 
 protected:
diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp
index 514d218..9a841e6 100644
--- a/src/level/robotmain.cpp
+++ b/src/level/robotmain.cpp
@@ -303,30 +303,6 @@ CPauseManager* CRobotMain::GetPauseManager()
     return m_pause.get();
 }
 
-void CRobotMain::ResetAfterVideoConfigChanged()
-{
-    // Recreate the interface (needed if the aspect ratio changes)
-    // TODO: This can sometimes cause unwanted side effects, like hidden windows reappearing. To be fixed during CEGUI refactoring.
-    m_eventQueue->AddEvent(Event(EVENT_UPDINTERFACE));
-    CreateShortcuts();
-}
-
-void CRobotMain::ReloadAllTextures()
-{
-    if (m_phase == PHASE_SETUPds ||
-       m_phase == PHASE_SETUPgs ||
-       m_phase == PHASE_SETUPps ||
-       m_phase == PHASE_SETUPcs ||
-       m_phase == PHASE_SETUPss ||
-       m_phase == PHASE_SIMUL ||
-       m_phase == PHASE_WIN ||
-       m_phase == PHASE_LOST)
-    {
-        ChangeColor();
-        UpdateMap();
-    }
-}
-
 std::string PhaseToString(Phase phase)
 {
     if (phase == PHASE_WELCOME1) return "PHASE_WELCOME1";
@@ -693,6 +669,23 @@ bool CRobotMain::ProcessEvent(Event &event)
         return EventFrame(event);
     }
 
+    if (event.type == EVENT_RELOAD_TEXTURES)
+    {
+        if (IsPhaseWithWorld(m_phase))
+        {
+            ChangeColor();
+            UpdateMap();
+        }
+    }
+
+    if (event.type == EVENT_RESOLUTION_CHANGED)
+    {
+        // Recreate the interface (needed if the aspect ratio changes)
+        // TODO: This can sometimes cause unwanted side effects, like hidden windows reappearing. To be fixed during CEGUI refactoring.
+        m_eventQueue->AddEvent(Event(EVENT_UPDINTERFACE));
+        CreateShortcuts();
+    }
+
     if (event.type == EVENT_FOCUS_LOST)
     {
         GetLogger()->Trace("Window unfocused\n");
diff --git a/src/level/robotmain.h b/src/level/robotmain.h
index 991c97c..dd40988 100644
--- a/src/level/robotmain.h
+++ b/src/level/robotmain.h
@@ -161,9 +161,6 @@ public:
     Ui::CDisplayText* GetDisplayText();
     CPauseManager* GetPauseManager();
 
-    void        ResetAfterVideoConfigChanged();
-    void        ReloadAllTextures();
-
     void        ChangePhase(Phase phase);
     bool        ProcessEvent(Event &event);
     Phase       GetPhase();

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