|
| 1 | +#include <afxwin.h> |
| 2 | + |
1 | 3 | #define ENABLE_SMOKE |
2 | 4 |
|
3 | 5 | using namespace nbl; |
@@ -36,45 +38,86 @@ class Smoke final : public system::IApplicationFramework |
36 | 38 | return false; |
37 | 39 | } |
38 | 40 |
|
39 | | - exportGpuProfiles(); |
| 41 | + if (!AfxWinInit(GetModuleHandle(nullptr), nullptr, GetCommandLineA(), 0)) |
| 42 | + { |
| 43 | + std::cerr << "[ERROR]: Could not init AFX, terminating!\n"; |
| 44 | + return false; |
| 45 | + } |
| 46 | + |
| 47 | + try { |
| 48 | + createAfxDummyWindow(320, 240, nullptr, _T("Dummy 1")); |
| 49 | + exportGpuProfiles(); |
| 50 | + createAfxDummyWindow(320, 240, nullptr, _T("Dummy 2")); |
| 51 | + } |
| 52 | + catch (const std::exception& e) { |
| 53 | + std::cerr << "[ERROR]: " << e.what() << '\n'; |
| 54 | + return false; |
| 55 | + } |
| 56 | + catch (...) { |
| 57 | + std::cerr << "[ERROR]: Unknown exception!\n"; |
| 58 | + return false; |
| 59 | + } |
40 | 60 |
|
41 | 61 | return true; |
42 | 62 | } |
43 | 63 |
|
44 | 64 | void workLoopBody() override {} |
45 | 65 | bool keepRunning() override { return false; } |
46 | 66 |
|
| 67 | + bool onAppTerminated() override |
| 68 | + { |
| 69 | + AfxWinTerm(); |
| 70 | + return true; |
| 71 | + } |
| 72 | + |
47 | 73 | private: |
48 | 74 | static void exportGpuProfiles() |
49 | 75 | { |
50 | | - std::string arg2 = "-o"; |
51 | | - std::string buf; |
52 | | - std::string arg1; |
53 | | - std::string arg3; |
| 76 | + std::string buf, arg1, arg2 = "-o", arg3; |
54 | 77 |
|
55 | 78 | for (size_t i = 0;; i++) |
56 | 79 | { |
57 | | - auto stringifiedIndex = std::to_string(i); |
58 | | - arg1 = "--json=" + stringifiedIndex; |
59 | | - arg3 = "device_" + stringifiedIndex + ".json"; |
60 | | - std::array<const char*, 3> args = { arg1.data(), arg2.data(), arg3.data() }; |
| 80 | + auto six = std::to_string(i); |
| 81 | + arg1 = "--json=" + six; |
| 82 | + arg3 = "device_" + six + ".json"; |
61 | 83 |
|
| 84 | + auto args = std::to_array<const char*>({ arg1.data(), arg2.data(), arg3.data()}); |
62 | 85 | int code = nbl::video::vulkaninfo(args); |
63 | 86 |
|
64 | 87 | if (code != 0) |
65 | 88 | break; |
66 | 89 |
|
67 | | - // print out file content |
68 | 90 | std::ifstream input(arg3); |
69 | 91 |
|
70 | 92 | while (std::getline(input, buf)) |
71 | | - { |
72 | 93 | std::cout << buf << "\n"; |
73 | | - } |
74 | 94 |
|
75 | 95 | std::cout << "\n\n"; |
76 | 96 | } |
77 | 97 | } |
| 98 | + |
| 99 | + static bool createAfxDummyWindow(int w, int h, HWND parent, LPCTSTR windowName) |
| 100 | + { |
| 101 | + CWnd wnd; |
| 102 | + LPCTSTR cls = AfxRegisterWndClass(0, ::LoadCursor(nullptr, IDC_ARROW)); |
| 103 | + if (!cls) return false; |
| 104 | + |
| 105 | + if (!wnd.CreateEx(0, cls, windowName, WS_POPUP | WS_VISIBLE, 0, 0, w, h, parent, nullptr)) |
| 106 | + return false; |
| 107 | + |
| 108 | + MSG msg {}; |
| 109 | + const ULONGLONG end = GetTickCount64() + 1000; |
| 110 | + while (GetTickCount64() < end) { |
| 111 | + while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) { |
| 112 | + TranslateMessage(&msg); |
| 113 | + DispatchMessage(&msg); |
| 114 | + } |
| 115 | + Sleep(1); |
| 116 | + } |
| 117 | + |
| 118 | + wnd.DestroyWindow(); |
| 119 | + return true; |
| 120 | + } |
78 | 121 | }; |
79 | 122 |
|
80 | 123 | NBL_MAIN_FUNC(Smoke) |
|
0 commit comments