diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2019-11-25 03:00:55 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2019-11-25 03:00:55 +0000 |
| commit | 6699190149464be566b55e7726c04fb10010f788 (patch) | |
| tree | d63af48bbd827310f4dc991d5df389a3c9bf82d2 /NativeApp/src/Win32/WinMain.cpp | |
| parent | clang-formatted ImGuiImpl (diff) | |
| download | DiligentTools-6699190149464be566b55e7726c04fb10010f788.tar.gz DiligentTools-6699190149464be566b55e7726c04fb10010f788.zip | |
clang-formatted NativeApp
Diffstat (limited to 'NativeApp/src/Win32/WinMain.cpp')
| -rw-r--r-- | NativeApp/src/Win32/WinMain.cpp | 58 |
1 files changed, 30 insertions, 28 deletions
diff --git a/NativeApp/src/Win32/WinMain.cpp b/NativeApp/src/Win32/WinMain.cpp index 8f63460..63dd01c 100644 --- a/NativeApp/src/Win32/WinMain.cpp +++ b/NativeApp/src/Win32/WinMain.cpp @@ -38,10 +38,10 @@ LRESULT CALLBACK MessageProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int cmdShow) { #if defined(_DEBUG) || defined(DEBUG) - _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); + _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); #endif - g_pTheApp.reset( CreateApplication() ); + g_pTheApp.reset(CreateApplication()); const auto* cmdLine = GetCommandLineA(); g_pTheApp->ProcessCommandLine(cmdLine); @@ -49,40 +49,41 @@ int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int cmdShow) const auto* AppTitle = g_pTheApp->GetAppTitle(); #ifdef UNICODE - const auto* const WindowClassName = L"SampleApp"; + const auto* const WindowClassName = L"SampleApp"; #else - const auto* const WindowClassName = "SampleApp"; + const auto* const WindowClassName = "SampleApp"; #endif // Register our window class - WNDCLASSEX wcex = { sizeof(WNDCLASSEX), CS_HREDRAW|CS_VREDRAW, MessageProc, - 0L, 0L, instance, NULL, NULL, NULL, NULL, WindowClassName, NULL }; + WNDCLASSEX wcex = {sizeof(WNDCLASSEX), CS_HREDRAW | CS_VREDRAW, MessageProc, + 0L, 0L, instance, NULL, NULL, NULL, NULL, WindowClassName, NULL}; RegisterClassEx(&wcex); - int DesiredWidth = 0; + int DesiredWidth = 0; int DesiredHeight = 0; g_pTheApp->GetDesiredInitialWindowSize(DesiredWidth, DesiredHeight); // Create a window - LONG WindowWidth = DesiredWidth > 0 ? DesiredWidth : 1280; + LONG WindowWidth = DesiredWidth > 0 ? DesiredWidth : 1280; LONG WindowHeight = DesiredHeight > 0 ? DesiredHeight : 1024; - RECT rc = { 0, 0, WindowWidth, WindowHeight }; + RECT rc = {0, 0, WindowWidth, WindowHeight}; AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, FALSE); HWND wnd = CreateWindowA("SampleApp", AppTitle, - WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, - rc.right-rc.left, rc.bottom-rc.top, NULL, NULL, instance, NULL); + WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, + rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, instance, NULL); if (!wnd) { - MessageBoxA(NULL, "Cannot create window", "Error", MB_OK|MB_ICONERROR); + MessageBoxA(NULL, "Cannot create window", "Error", MB_OK | MB_ICONERROR); return 0; } ShowWindow(wnd, cmdShow); UpdateWindow(wnd); - + g_pTheApp->OnWindowCreated(wnd, WindowWidth, WindowHeight); AppTitle = g_pTheApp->GetAppTitle(); Diligent::Timer Timer; - auto PrevTime = Timer.GetElapsedTime(); + + auto PrevTime = Timer.GetElapsedTime(); double filteredFrameTime = 0.0; // Main message loop @@ -96,9 +97,10 @@ int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int cmdShow) } else { - auto CurrTime = Timer.GetElapsedTime(); + auto CurrTime = Timer.GetElapsedTime(); auto ElapsedTime = CurrTime - PrevTime; - PrevTime = CurrTime; + PrevTime = CurrTime; + g_pTheApp->Update(CurrTime, ElapsedTime); g_pTheApp->Render(); @@ -106,14 +108,14 @@ int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int cmdShow) g_pTheApp->Present(); double filterScale = 0.2; - filteredFrameTime = filteredFrameTime * (1.0 - filterScale) + filterScale * ElapsedTime; + filteredFrameTime = filteredFrameTime * (1.0 - filterScale) + filterScale * ElapsedTime; std::stringstream fpsCounterSS; fpsCounterSS << AppTitle << " - " << std::fixed << std::setprecision(1) << filteredFrameTime * 1000; fpsCounterSS << " ms (" << 1.0 / filteredFrameTime << " fps)"; SetWindowTextA(wnd, fpsCounterSS.str().c_str()); } } - + g_pTheApp.reset(); return (int)msg.wParam; @@ -122,24 +124,24 @@ int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int cmdShow) // Called every time the NativeNativeAppBase receives a message LRESULT CALLBACK MessageProc(HWND wnd, UINT message, WPARAM wParam, LPARAM lParam) { - if(g_pTheApp) + if (g_pTheApp) { auto res = g_pTheApp->HandleWin32Message(wnd, message, wParam, lParam); if (res != 0) return res; } - switch (message) + switch (message) { case WM_PAINT: - { - PAINTSTRUCT ps; - BeginPaint(wnd, &ps); - EndPaint(wnd, &ps); - return 0; - } + { + PAINTSTRUCT ps; + BeginPaint(wnd, &ps); + EndPaint(wnd, &ps); + return 0; + } case WM_SIZE: // Window size has been changed - if( g_pTheApp ) + if (g_pTheApp) { g_pTheApp->WindowResize(LOWORD(lParam), HIWORD(lParam)); } @@ -156,7 +158,7 @@ LRESULT CALLBACK MessageProc(HWND wnd, UINT message, WPARAM wParam, LPARAM lPara case WM_GETMINMAXINFO: { - LPMINMAXINFO lpMMI = (LPMINMAXINFO)lParam; + LPMINMAXINFO lpMMI = (LPMINMAXINFO)lParam; lpMMI->ptMinTrackSize.x = 320; lpMMI->ptMinTrackSize.y = 240; return 0; |
