diff --git a/Client/Audio/Audio.hpp b/Client/Audio/Audio.hpp index fb7b21a..8a5cb54 100644 --- a/Client/Audio/Audio.hpp +++ b/Client/Audio/Audio.hpp @@ -19,4 +19,5 @@ namespace Audio { int Initialize(); + void Shutdown(); } \ No newline at end of file diff --git a/Client/Audio/Startup.cpp b/Client/Audio/Startup.cpp index f1a7471..8693f18 100644 --- a/Client/Audio/Startup.cpp +++ b/Client/Audio/Startup.cpp @@ -24,8 +24,6 @@ HANDLE Thread; IXAudio2 *pXAudio2 = NULL; IXAudio2MasteringVoice *MasterVoice = NULL; -void Shutdown(); - int Initialize(){ HRESULT result; diff --git a/Client/Client.cpp b/Client/Client.cpp index 488c055..104cff4 100644 --- a/Client/Client.cpp +++ b/Client/Client.cpp @@ -74,13 +74,13 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) return ERROR_INIT | ERROR_INIT_LOGIC | ERROR_LOGIC_CREATE_SCENE; } - LARGE_INTEGER PreviousTime; - QueryPerformanceCounter(&PreviousTime); - ShowWindow(Window::hWnd, SW_SHOW); SetForegroundWindow(Window::hWnd); SetFocus(Window::hWnd); + LARGE_INTEGER PreviousTime; + QueryPerformanceCounter(&PreviousTime); + while(true){ MSG msg; while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){ @@ -102,18 +102,15 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) PreviousTime.QuadPart = CurrentTime.QuadPart; QueryPerformanceCounter(&CurrentTime); - unsigned SleepDuration = (unsigned) - ((System::FramePeriod - (float)(CurrentTime.QuadPart-PreviousTime.QuadPart)/System::ClockFreq.QuadPart) * 1000); - if(SleepDuration > 1) Sleep(SleepDuration); - } - - MSG msg; - while(GetMessage(&msg, NULL, 0, 0)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); + float SleepDuration = + (System::FramePeriod - (float)(CurrentTime.QuadPart-PreviousTime.QuadPart)/System::ClockFreq.QuadPart) * 1000; + if(SleepDuration > 1) Sleep((unsigned) SleepDuration); } + ShowWindow(Window::hWnd, SW_HIDE); + Audio::Shutdown(); + Graphics::Shutdown(); + Shutdown(); return 0; } diff --git a/Client/Graphics/Graphics.hpp b/Client/Graphics/Graphics.hpp index e4dc9ca..af47f24 100644 --- a/Client/Graphics/Graphics.hpp +++ b/Client/Graphics/Graphics.hpp @@ -21,6 +21,7 @@ //Graphics/Startup.cpp namespace Graphics { int Initialize(); + void Shutdown(); extern HDC hDC; extern HGLRC hRC; diff --git a/Client/Graphics/Startup.cpp b/Client/Graphics/Startup.cpp index ecdf434..90cd57e 100644 --- a/Client/Graphics/Startup.cpp +++ b/Client/Graphics/Startup.cpp @@ -23,8 +23,6 @@ HANDLE Thread; HDC hDC; HGLRC hRC; -void Shutdown(); - int Initialize(){ hDC = GetDC(Window::hWnd); if(hDC == NULL){ diff --git a/Client/MessageHandler.cpp b/Client/MessageHandler.cpp index 4898f04..d28d0cd 100644 --- a/Client/MessageHandler.cpp +++ b/Client/MessageHandler.cpp @@ -44,6 +44,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) return 0; case WM_CLOSE: + System::UserInput.CloseWindow = true; PostQuitMessage(0); return 0; diff --git a/Client/Scene/Scene.hpp b/Client/Scene/Scene.hpp index f956e53..4dfb78f 100644 --- a/Client/Scene/Scene.hpp +++ b/Client/Scene/Scene.hpp @@ -51,8 +51,9 @@ class LoginScreen : public Scene { int Run(float){ if(System::UserInput.CloseWindow){ System::Shutdown = true; + return 0; } - return 0; + return 1; } public: diff --git a/Client/System/System.cpp b/Client/System/System.cpp index 6a5a88b..072ebfa 100644 --- a/Client/System/System.cpp +++ b/Client/System/System.cpp @@ -27,6 +27,8 @@ namespace System { UserInput_t UserInput; int Initialize(){ + memset(&UserInput, 0, sizeof(UserInput)); + QueryPerformanceFrequency(&ClockFreq); DEVMODE dm;