Apply clang-format across the whole tree
Run clang-format (the repo's .clang-format: LLVM base, 120 cols, tabs, Allman functions) over every source file so the tree is formatter-clean. Whitespace only -- no behavior change; full x64 + x86 suites pass. Also set SortIncludes: false in .clang-format. Windows include order is load-bearing (windows.h must precede tlhelp32.h / mmreg.h / xinput.h / dinput.h; winsock2.h must precede windows.h), and the default alphabetical sort reorders tlhelp32.h ahead of windows.h -- a build break. Leaving order alone keeps the manual, correct grouping.
This commit is contained in:
@@ -21,8 +21,7 @@
|
||||
#include "render_backend.hpp"
|
||||
#include "tone_source.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
std::atomic<bool> g_running{true};
|
||||
|
||||
// Diagnostic: on an access violation, log the faulting address and the caller (return address on the
|
||||
@@ -30,17 +29,15 @@ std::atomic<bool> g_running{true};
|
||||
// crash so the test still detects it.
|
||||
LONG WINAPI crash_logger(EXCEPTION_POINTERS* ep)
|
||||
{
|
||||
if (ep->ExceptionRecord->ExceptionCode != EXCEPTION_ACCESS_VIOLATION)
|
||||
{
|
||||
if (ep->ExceptionRecord->ExceptionCode != EXCEPTION_ACCESS_VIOLATION) {
|
||||
return EXCEPTION_CONTINUE_SEARCH;
|
||||
}
|
||||
auto mod = [](void* p, char* out, size_t n) -> unsigned long long {
|
||||
HMODULE m = nullptr;
|
||||
if (p != nullptr &&
|
||||
GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
||||
reinterpret_cast<LPCSTR>(p), &m) &&
|
||||
m != nullptr)
|
||||
{
|
||||
if (p != nullptr
|
||||
&& GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
||||
reinterpret_cast<LPCSTR>(p), &m)
|
||||
&& m != nullptr) {
|
||||
char path[MAX_PATH] = {};
|
||||
GetModuleFileNameA(m, path, MAX_PATH);
|
||||
const char* base = std::strrchr(path, '\\');
|
||||
@@ -62,8 +59,7 @@ LONG WINAPI crash_logger(EXCEPTION_POINTERS* ep)
|
||||
|
||||
LRESULT CALLBACK wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
|
||||
{
|
||||
if (msg == WM_DESTROY)
|
||||
{
|
||||
if (msg == WM_DESTROY) {
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
}
|
||||
@@ -73,23 +69,18 @@ LRESULT CALLBACK wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
|
||||
// Spawns the audio render loop on its own thread (WASAPI wants its own COM apartment).
|
||||
void audio_thread(coop::tone::ToneFormat want)
|
||||
{
|
||||
if (FAILED(CoInitializeEx(nullptr, COINIT_MULTITHREADED)))
|
||||
{
|
||||
if (FAILED(CoInitializeEx(nullptr, COINIT_MULTITHREADED))) {
|
||||
return;
|
||||
}
|
||||
coop::tone::ToneSource tone;
|
||||
if (tone.open(want, 440.0))
|
||||
{
|
||||
if (tone.open(want, 440.0)) {
|
||||
std::printf("MOCK_GAME audio: %u Hz %u ch %u-bit %s\n", tone.format().rate, tone.format().channels,
|
||||
tone.format().bits, tone.format().is_float ? "float" : "pcm");
|
||||
std::fflush(stdout);
|
||||
while (g_running.load(std::memory_order_relaxed))
|
||||
{
|
||||
while (g_running.load(std::memory_order_relaxed)) {
|
||||
tone.render_step(200);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
std::printf("MOCK_GAME audio: failed to open requested format\n");
|
||||
}
|
||||
tone.close();
|
||||
@@ -103,11 +94,11 @@ void audio_thread(coop::tone::ToneFormat want)
|
||||
void poll_input()
|
||||
{
|
||||
XINPUT_STATE xs{};
|
||||
(void)XInputGetState(0, &xs); // XInput hook (XInputGetState/Ex)
|
||||
(void)GetAsyncKeyState(VK_SPACE); // MKB hook (GetAsyncKeyState)
|
||||
(void)XInputGetState(0, &xs); // XInput hook (XInputGetState/Ex)
|
||||
(void)GetAsyncKeyState(VK_SPACE); // MKB hook (GetAsyncKeyState)
|
||||
BYTE kb[256] = {};
|
||||
(void)GetKeyboardState(kb); // MKB hook (GetKeyboardState)
|
||||
(void)GetForegroundWindow(); // focus hook (GetForegroundWindow)
|
||||
(void)GetKeyboardState(kb); // MKB hook (GetKeyboardState)
|
||||
(void)GetForegroundWindow(); // focus hook (GetForegroundWindow)
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -118,8 +109,7 @@ int main(int argc, char** argv)
|
||||
const double seconds = argc > 2 ? std::strtod(argv[2], nullptr) : 0.0;
|
||||
const bool want_audio = argc > 3;
|
||||
coop::tone::ToneFormat audio_fmt;
|
||||
if (want_audio)
|
||||
{
|
||||
if (want_audio) {
|
||||
audio_fmt.rate = static_cast<unsigned>(std::strtoul(argv[3], nullptr, 10));
|
||||
audio_fmt.channels = argc > 4 ? static_cast<unsigned>(std::strtoul(argv[4], nullptr, 10)) : 2;
|
||||
audio_fmt.bits = argc > 5 ? static_cast<unsigned>(std::strtoul(argv[5], nullptr, 10)) : 32;
|
||||
@@ -139,11 +129,9 @@ int main(int argc, char** argv)
|
||||
|
||||
RECT r = {0, 0, static_cast<LONG>(kW), static_cast<LONG>(kH)};
|
||||
AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW, FALSE);
|
||||
HWND hwnd = CreateWindowExW(0, wc.lpszClassName, L"CoopMockGame", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, r.right - r.left, r.bottom - r.top, nullptr,
|
||||
nullptr, inst, nullptr);
|
||||
if (hwnd == nullptr)
|
||||
{
|
||||
HWND hwnd = CreateWindowExW(0, wc.lpszClassName, L"CoopMockGame", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT,
|
||||
CW_USEDEFAULT, r.right - r.left, r.bottom - r.top, nullptr, nullptr, inst, nullptr);
|
||||
if (hwnd == nullptr) {
|
||||
std::printf("MOCK_GAME error: CreateWindow failed\n");
|
||||
return 1;
|
||||
}
|
||||
@@ -151,26 +139,23 @@ int main(int argc, char** argv)
|
||||
// Test hook (early-load): Vulkan caches its present pointer at init, so the capture hook must
|
||||
// be in place before vkCreateInstance. Under COOP_MOCK_VK_EARLY the mock loads vulkan-1.dll
|
||||
// now and waits, giving an already-injected hook time to hook vkGetInstanceProcAddr first.
|
||||
if (backend_name == "vk" && GetEnvironmentVariableW(L"COOP_MOCK_VK_EARLY", nullptr, 0) != 0)
|
||||
{
|
||||
if (backend_name == "vk" && GetEnvironmentVariableW(L"COOP_MOCK_VK_EARLY", nullptr, 0) != 0) {
|
||||
LoadLibraryW(L"vulkan-1.dll");
|
||||
Sleep(1500);
|
||||
}
|
||||
|
||||
auto backend = coop::mock::RenderBackend::create(backend_name);
|
||||
if (!backend || !backend->init(hwnd, kW, kH))
|
||||
{
|
||||
if (!backend || !backend->init(hwnd, kW, kH)) {
|
||||
std::printf("MOCK_GAME error: backend '%s' unavailable\n", backend_name.c_str());
|
||||
return 2;
|
||||
}
|
||||
|
||||
std::printf("MOCK_GAME pid=%lu backend=%s w=%u h=%u audio=%s\n", GetCurrentProcessId(), backend->name(),
|
||||
kW, kH, want_audio ? "yes" : "no");
|
||||
std::printf("MOCK_GAME pid=%lu backend=%s w=%u h=%u audio=%s\n", GetCurrentProcessId(), backend->name(), kW, kH,
|
||||
want_audio ? "yes" : "no");
|
||||
std::fflush(stdout);
|
||||
|
||||
std::thread audio;
|
||||
if (want_audio)
|
||||
{
|
||||
if (want_audio) {
|
||||
audio = std::thread(audio_thread, audio_fmt);
|
||||
}
|
||||
|
||||
@@ -178,20 +163,16 @@ int main(int argc, char** argv)
|
||||
std::uint32_t frame = 0;
|
||||
ULONGLONG fps_window_start = start; // window-title fps: frames in the last ~second
|
||||
std::uint32_t fps_window_frames = 0;
|
||||
for (;;)
|
||||
{
|
||||
for (;;) {
|
||||
MSG msg;
|
||||
while (PeekMessageW(&msg, nullptr, 0, 0, PM_REMOVE))
|
||||
{
|
||||
if (msg.message == WM_QUIT)
|
||||
{
|
||||
while (PeekMessageW(&msg, nullptr, 0, 0, PM_REMOVE)) {
|
||||
if (msg.message == WM_QUIT) {
|
||||
g_running.store(false, std::memory_order_relaxed);
|
||||
}
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessageW(&msg);
|
||||
}
|
||||
if (!g_running.load(std::memory_order_relaxed))
|
||||
{
|
||||
if (!g_running.load(std::memory_order_relaxed)) {
|
||||
break;
|
||||
}
|
||||
poll_input(); // drive the input/focus/MKB detours each frame, like a real game
|
||||
@@ -200,8 +181,7 @@ int main(int argc, char** argv)
|
||||
// Show the backend + a once-per-second-smoothed fps in the title bar.
|
||||
++fps_window_frames;
|
||||
const ULONGLONG now = GetTickCount64();
|
||||
if (now - fps_window_start >= 1000)
|
||||
{
|
||||
if (now - fps_window_start >= 1000) {
|
||||
const double fps = fps_window_frames * 1000.0 / static_cast<double>(now - fps_window_start);
|
||||
wchar_t title[128];
|
||||
swprintf(title, 128, L"CoopMockGame [%hs] - %.0f fps", backend->name(), fps);
|
||||
@@ -209,15 +189,13 @@ int main(int argc, char** argv)
|
||||
fps_window_start = now;
|
||||
fps_window_frames = 0;
|
||||
}
|
||||
if (seconds > 0.0 && (GetTickCount64() - start) >= static_cast<ULONGLONG>(seconds * 1000.0))
|
||||
{
|
||||
if (seconds > 0.0 && (GetTickCount64() - start) >= static_cast<ULONGLONG>(seconds * 1000.0)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_running.store(false, std::memory_order_relaxed);
|
||||
if (audio.joinable())
|
||||
{
|
||||
if (audio.joinable()) {
|
||||
audio.join();
|
||||
}
|
||||
std::printf("MOCK_GAME done: %u frames\n", frame);
|
||||
|
||||
Reference in New Issue
Block a user