From 50d28f9a4649a652e40f73b6909f486aa88445ed Mon Sep 17 00:00:00 2001 From: fuzun Date: Sat, 31 Aug 2019 03:35:17 +0300 Subject: [PATCH] StrobeAPI Integration --- main.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index 324d00c..87294e8 100644 --- a/main.cpp +++ b/main.cpp @@ -1,17 +1,43 @@ #include #include #include + +#include "strobe-api/strobe/strobe-core.h" + using namespace std::chrono; const char g_szClassName[] = "desktopBFIwindowClass"; bool quitProgram = false; -bool frameVisible = false; +bool frameVisible; + +StrobeAPI* strobe = nullptr; +char* strobeInfo = (char*)malloc(sizeof(char) * 4096); +bool debugMode = false; +int frameSnapshot = 0; // Window event handling LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { + case WM_PAINT: + { + PAINTSTRUCT ps; + HDC hdc = BeginPaint(hwnd, &ps); + if (strobe && debugMode && strobeInfo && strobe->frameCount(StrobeAPI::TotalFrame) - frameSnapshot >= 10) + { + RECT rec; + SetRect(&rec, 10, 10, 500, 600); + HBRUSH brush = CreateSolidBrush(RGB(255, 255, 255)); + FillRect(hdc, &rec, brush); + snprintf(strobeInfo, sizeof(char) * 4096, "%s", strobe->getDebugInformation()); + DrawText(hdc, strobeInfo, strlen(strobeInfo), &rec, DT_TOP | DT_LEFT); + frameSnapshot = strobe->frameCount(StrobeAPI::TotalFrame); + } + EndPaint(hwnd, &ps); + ReleaseDC(hwnd, hdc); + break; + } case WM_CLOSE: quitProgram = true; DestroyWindow(hwnd); @@ -78,6 +104,23 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); + LPWSTR* szArglist; + int argCount; + szArglist = CommandLineToArgvW(GetCommandLineW(), &argCount); + if (argCount == 4) + { + int sMode = _wtoi(szArglist[1]); + int pSInterval = _wtoi(szArglist[2]); + debugMode = _wtoi(szArglist[3]); + + strobe = new StrobeCore(sMode, pSInterval); + } + else + { + strobe = new StrobeCore(); + } + + // Setting up to do V-sync. Guidance came from: // https://www.vsynctester.com/firefoxisbroken.html // https://gist.github.com/anonymous/4397e4909c524c939bee#file-gistfile1-txt-L3 @@ -110,10 +153,16 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, do { high_resolution_clock::time_point pollTime = high_resolution_clock::now() + microseconds(100); while (pollTime < high_resolution_clock::now()) - {} + { + } result = D3DKMTGetScanLine(&gsl); } while (gsl.InVerticalBlank == TRUE); - frameVisible = !frameVisible; + + if (strobe) + frameVisible = strobe->strobe(); + else + frameVisible = true; + // Window transparency: 0 is invisible, 255 is opaque SetLayeredWindowAttributes(hwnd, 0, frameVisible * 255, LWA_ALPHA); RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE); @@ -124,5 +173,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, } } + delete strobeInfo; + delete strobe; + return Msg.wParam; -} \ No newline at end of file +}