diff --git a/enginecustom/Systemclass.cpp b/enginecustom/Systemclass.cpp index 1975ca3..6345905 100644 --- a/enginecustom/Systemclass.cpp +++ b/enginecustom/Systemclass.cpp @@ -88,32 +88,52 @@ bool SystemClass::Initialize() void SystemClass::Shutdown() { + logger.Log("Shutting down system class", __FILE__, __LINE__); + + std::lock_guard guard(renderMutex); + + // Shutdown imgui + if (m_imguiManager) + { + logger.Log("Shutting down imgui manager", __FILE__, __LINE__); + + m_imguiManager->Shutdown(); + delete m_imguiManager; + m_imguiManager = 0; + + logger.Log("Imgui manager shut down", __FILE__, __LINE__); + } + // Release the application class object. if (m_Application) { + logger.Log("Shutting down application", __FILE__, __LINE__); + m_Application->Shutdown(); delete m_Application; m_Application = 0; + + logger.Log("Application shut down", __FILE__, __LINE__); } // Release the input object. if (m_Input) { + logger.Log("Shutting down input", __FILE__, __LINE__); + delete m_Input; m_Input = 0; + + logger.Log("Input shut down", __FILE__, __LINE__); } - // Shutdown imgui - if (m_imguiManager) - { - m_imguiManager->Shutdown(); - delete m_imguiManager; - m_imguiManager = 0; - } + // Shutdown the window. ShutdownWindows(); + logger.Log("System class shut down", __FILE__, __LINE__); + return; } @@ -134,14 +154,21 @@ void SystemClass::Run() // Handle the windows messages. if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { - TranslateMessage(&msg); - DispatchMessage(&msg); + if(msg.message == WM_QUIT) + { + done = true; + } + else + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } } // If windows signals to end the application then exit out. - if (msg.message == WM_QUIT) + if (m_Application != nullptr && m_Application->GetShouldQuit()) { - logger.Log("WM_QUIT message received", __FILE__, __LINE__); + logger.Log("Received quit signal from application", __FILE__, __LINE__); done = true; } else @@ -162,6 +189,8 @@ void SystemClass::Run() bool SystemClass::Frame() { + + std::lock_guard guard(renderMutex); bool result; // Do the input frame processing. @@ -172,6 +201,14 @@ bool SystemClass::Frame() return false; } + // Render ImGui + result = m_imguiManager->ImGuiWidgetRenderer(m_Application); + if (!result) + { + logger.Log("Failed to render ImGui widgets", __FILE__, __LINE__, Logger::LogLevel::Error); + return false; + } + // Do the frame processing for the application class object. result = m_Application->Frame(m_Input); if (!result) @@ -180,9 +217,6 @@ bool SystemClass::Frame() return false; } - // Render ImGui - m_imguiManager->ImGuiWidgetRenderer(m_Application); - return true; } @@ -267,6 +301,12 @@ LRESULT CALLBACK SystemClass::MessageHandler(HWND hwnd, UINT umsg, WPARAM wparam DragFinish(hDrop); return 0; } + case WM_CLOSE: + { + logger.Log("WM_CLOSE message received", __FILE__, __LINE__); + m_Application->SetShouldQuit(true); + return 0; + } // Any other messages send to the default message handler as our application won't make use of them. default: { @@ -365,6 +405,8 @@ void SystemClass::InitializeWindows(int& screenWidth, int& screenHeight) void SystemClass::ShutdownWindows() { + logger.Log("Shutting down windows", __FILE__, __LINE__); + logger.Log("Shutting down the windows", __FILE__, __LINE__); // Show the mouse cursor. ShowCursor(true); @@ -386,11 +428,6 @@ void SystemClass::ShutdownWindows() // Release the pointer to this class. ApplicationHandle = NULL; - //Releases COM references that ImGui was given on setup - ImGui_ImplDX11_Shutdown(); - ImGui_ImplWin32_Shutdown(); - ImGui::DestroyContext(); - return; } diff --git a/enginecustom/applicationclass.cpp b/enginecustom/applicationclass.cpp index 8058c58..9f91f90 100644 --- a/enginecustom/applicationclass.cpp +++ b/enginecustom/applicationclass.cpp @@ -1,6 +1,6 @@ #include "applicationclass.h" -ApplicationClass::ApplicationClass() +ApplicationClass::ApplicationClass() : m_ShouldQuit(false) { m_Direct3D = 0; m_Camera = 0; @@ -306,131 +306,191 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd) void ApplicationClass::Shutdown() { + logger.Log("Shutting down application class", __FILE__, __LINE__); + // Release the shader manager object. if (m_ShaderManager) { + logger.Log("Releasing the shader manager object", __FILE__, __LINE__); + m_ShaderManager->Shutdown(); delete m_ShaderManager; m_ShaderManager = 0; + + logger.Log("Shader manager object released", __FILE__, __LINE__); } // Release the frustum class object. if (m_Frustum) { + logger.Log("Releasing the frustum class object", __FILE__, __LINE__); + delete m_Frustum; m_Frustum = 0; + + logger.Log("Frustum class object released", __FILE__, __LINE__); } // Release the display plane object. if (m_DisplayPlane) { + logger.Log("Releasing the display plane object", __FILE__, __LINE__); + m_DisplayPlane->Shutdown(); delete m_DisplayPlane; m_DisplayPlane = 0; + + logger.Log("Display plane object released", __FILE__, __LINE__); } // Release the position object. if (m_Position) { + logger.Log("Releasing the position object", __FILE__, __LINE__); + delete m_Position; m_Position = 0; + + logger.Log("Position object released", __FILE__, __LINE__); } // Release the model list object. if (m_ModelList) { + logger.Log("Releasing the model list object", __FILE__, __LINE__); + m_ModelList->Shutdown(); delete m_ModelList; m_ModelList = 0; + + logger.Log("Model list object released", __FILE__, __LINE__); } // Release the text objects for the render count string. if (m_RenderCountString) { + logger.Log("Releasing the render count string object", __FILE__, __LINE__); + m_RenderCountString->Shutdown(); delete m_RenderCountString; m_RenderCountString = 0; + + logger.Log("Render count string object released", __FILE__, __LINE__); } // Release the text objects for the mouse strings. if (m_MouseStrings) { + logger.Log("Releasing the mouse strings", __FILE__, __LINE__); + m_MouseStrings[0].Shutdown(); m_MouseStrings[1].Shutdown(); m_MouseStrings[2].Shutdown(); delete[] m_MouseStrings; m_MouseStrings = 0; + + logger.Log("Mouse strings released", __FILE__, __LINE__); } // Release the text object for the fps string. if (m_FpsString) { + logger.Log("Releasing the fps string object", __FILE__, __LINE__); + m_FpsString->Shutdown(); delete m_FpsString; m_FpsString = 0; + + logger.Log("Fps string object released", __FILE__, __LINE__); } // Release the fps object. if (m_Fps) { + logger.Log("Releasing the fps object", __FILE__, __LINE__); + delete m_Fps; m_Fps = 0; + + logger.Log("Fps object released", __FILE__, __LINE__); } // Release the font object. if (m_Font) { + logger.Log("Releasing the font object", __FILE__, __LINE__); + m_Font->Shutdown(); delete m_Font; m_Font = 0; + + logger.Log("Font object released", __FILE__, __LINE__); } // Release the font shader object. if (m_FontShader) { + logger.Log("Releasing the font shader object", __FILE__, __LINE__); + m_FontShader->Shutdown(); delete m_FontShader; m_FontShader = 0; + + logger.Log("Font shader object released", __FILE__, __LINE__); } // Release the timer object. if (m_Timer) { + logger.Log("Releasing the timer object", __FILE__, __LINE__); + delete m_Timer; m_Timer = 0; + + logger.Log("Timer object released", __FILE__, __LINE__); } // Release the sprite object. if (m_Sprite) { + logger.Log("Releasing the sprite object", __FILE__, __LINE__); + m_Sprite->Shutdown(); delete m_Sprite; m_Sprite = 0; + + logger.Log("Sprite object released", __FILE__, __LINE__); } for (auto light : m_Lights) { + logger.Log("Releasing the light object", __FILE__, __LINE__); if (light) { delete light; light = 0; } + logger.Log("Light object released", __FILE__, __LINE__); } // Release the light object. if (m_Light) { + logger.Log("Releasing the light object", __FILE__, __LINE__); delete m_Light; m_Light = 0; + logger.Log("Light object released", __FILE__, __LINE__); } // Release the model object. if (m_Model) { + logger.Log("Releasing the model object", __FILE__, __LINE__); m_Model->Shutdown(); delete m_Model; m_Model = 0; + logger.Log("Model object released", __FILE__, __LINE__); } } @@ -460,7 +520,8 @@ bool ApplicationClass::Frame(InputClass* Input) // Check if the user pressed escape and wants to exit the application. if (Input->IsEscapePressed()) { - return false; + logger.Log("User pressed escape, exiting application", __FILE__, __LINE__); + m_ShouldQuit = true; } // Get the location of the mouse from the input object, diff --git a/enginecustom/applicationclass.h b/enginecustom/applicationclass.h index 306d30c..3fbc6e3 100644 --- a/enginecustom/applicationclass.h +++ b/enginecustom/applicationclass.h @@ -29,6 +29,7 @@ #include "rendertextureclass.h" #include "displayplaneclass.h" #include "reflectionshaderclass.h" +#include "systemclass.h" ///////////// @@ -75,14 +76,14 @@ public: XMVECTOR GetLightPosition(int index); XMVECTOR GetLightColor(int index); - void SetLightPosition(int index, XMVECTOR color); void SetLightColor(int index, XMVECTOR color); - void DeleteLight(int index); - std::vector GetLights() const { return m_Lights; }; + bool GetShouldQuit() const { return m_ShouldQuit; }; + void SetShouldQuit(bool shouldQuit) { m_ShouldQuit = shouldQuit; }; + private: bool Render(float, float, float, float, float); bool UpdateMouseStrings(int, int, bool); @@ -158,6 +159,12 @@ private : // ------------------- LOGGER ---------------------- // // ------------------------------------------------- // Logger logger; + + // ------------------------------------------------- // + // ------------------- OTHER ----------------------- // + // ------------------------------------------------- // + + bool m_ShouldQuit; }; #endif \ No newline at end of file diff --git a/enginecustom/imgui.ini b/enginecustom/imgui.ini index 19fa4df..e8c95e7 100644 --- a/enginecustom/imgui.ini +++ b/enginecustom/imgui.ini @@ -15,6 +15,6 @@ Pos=60,60 Size=342,82 [Window][Light] -Pos=95,296 +Pos=62,180 Size=345,230 diff --git a/enginecustom/imguiManager.cpp b/enginecustom/imguiManager.cpp index 276b6ea..406558d 100644 --- a/enginecustom/imguiManager.cpp +++ b/enginecustom/imguiManager.cpp @@ -201,7 +201,7 @@ void imguiManager::WidgetTerrainWindow(ApplicationClass* app) ImGui::End(); } -void imguiManager::ImGuiWidgetRenderer(ApplicationClass* app) +bool imguiManager::ImGuiWidgetRenderer(ApplicationClass* app) { // Start the Dear ImGui frame NewFrame(); @@ -255,6 +255,8 @@ void imguiManager::ImGuiWidgetRenderer(ApplicationClass* app) Render(); app->GetDirect3D()->m_swapChain->Present(0, NULL); + + return true; } void imguiManager::WidgetLightWindow(ApplicationClass* app) diff --git a/enginecustom/imguiManager.h b/enginecustom/imguiManager.h index 6d59fe0..166cd21 100644 --- a/enginecustom/imguiManager.h +++ b/enginecustom/imguiManager.h @@ -32,7 +32,7 @@ public: void WidgetTerrainWindow(ApplicationClass* app); void WidgetLightWindow(ApplicationClass* app); - void ImGuiWidgetRenderer(ApplicationClass* app); + bool ImGuiWidgetRenderer(ApplicationClass* app); private : bool showObjectWindow = false; diff --git a/enginecustom/systemclass.h b/enginecustom/systemclass.h index 8b62c64..12fb255 100644 --- a/enginecustom/systemclass.h +++ b/enginecustom/systemclass.h @@ -8,6 +8,7 @@ #include "inputclass.h" #include "applicationclass.h" #include "imguiManager.h" +#include #include "resources.h" class SystemClass @@ -42,6 +43,8 @@ private: int m_initialWindowHeight; bool m_isDirect3DInitialized; bool m_isResizing = false; + + std::mutex renderMutex; };