Browse Source

React to window closed by setting Engine to exiting state.
Eliminated circular dependency between Engine & Input.

Lasse Öörni 12 years ago
parent
commit
b1ce162af1
3 changed files with 18 additions and 12 deletions
  1. 9 1
      Engine/Engine/Engine.cpp
  2. 7 8
      Engine/Input/CMakeLists.txt
  3. 2 3
      Engine/Input/Input.cpp

+ 9 - 1
Engine/Engine/Engine.cpp

@@ -248,7 +248,15 @@ bool Engine::Initialize(const VariantMap& parameters)
 
 void Engine::RunFrame()
 {
-    assert(initialized_ && !exiting_);
+    assert(initialized_);
+    
+    // If graphics subsystem exists, but does not have a window open, assume we should exit
+    Graphics* graphics = GetSubsystem<Graphics>();
+    if (graphics && !graphics->IsInitialized())
+        exiting_ = true;
+    
+    if (exiting_)
+        return;
     
     // Note: there is a minimal performance cost to looking up subsystems (uses a hashmap); if they would be looked up several
     // times per frame it would be better to cache the pointers

+ 7 - 8
Engine/Input/CMakeLists.txt

@@ -8,12 +8,11 @@ set (SOURCE_FILES ${CPP_FILES} ${H_FILES})
 
 # Define dependency libs
 set (LIBS ../Container ../Core ../Graphics ../IO ../Math ../Resource ../Scene)
-set (INCLUDE_DIRS_ONLY ../Engine)
-set (LINK_LIBS_ONLY SDL)
-
-if (USE_OPENGL)
-    set (INCLUDE_DIRS_ONLY ${INCLUDE_DIRS_ONLY} ../../ThirdParty/GLEW)
-endif ()
-
-# Setup target
+set (LINK_LIBS_ONLY SDL)
+
+if (USE_OPENGL)
+    set (INCLUDE_DIRS_ONLY ${INCLUDE_DIRS_ONLY} ../../ThirdParty/GLEW)
+endif ()
+
+# Setup target
 setup_library ()

+ 2 - 3
Engine/Input/Input.cpp

@@ -31,7 +31,6 @@
 #include "ProcessUtils.h"
 #include "Profiler.h"
 #include "StringUtils.h"
-#include "Engine.h"
 
 #include <cstring>
 
@@ -196,7 +195,7 @@ void Input::SetMouseVisible(bool enable)
         if (initialized_)
         {
             // External windows can only support visible mouse cursor
-            if (graphics_ && graphics_->GetExternalWindow())
+            if (graphics_->GetExternalWindow())
             {
                 mouseVisible_ = true;
                 return;
@@ -794,7 +793,7 @@ void Input::HandleSDLEvent(void* sdlEvent)
             switch (evt.window.event)
             {
             case SDL_WINDOWEVENT_CLOSE:
-                GetSubsystem<Graphics>()->Close();
+                graphics_->Close();
                 break;
                 
             case SDL_WINDOWEVENT_MINIMIZED: