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:
2026-07-12 11:52:53 +02:00
parent c684a15fb9
commit 30eccf749d
155 changed files with 3333 additions and 6171 deletions

View File

@@ -12,20 +12,17 @@
#include <string>
#include <vector>
namespace coop
{
namespace coop {
struct WavData
{
struct WavData {
std::uint32_t sample_rate = 0;
std::uint32_t channels = 0;
std::uint32_t bits = 0;
std::uint32_t format_tag = 0; // 1 = PCM, 3 = IEEE float
std::uint32_t format_tag = 0; // 1 = PCM, 3 = IEEE float
std::vector<std::uint8_t> pcm; // interleaved frames
};
namespace detail
{
namespace detail {
inline void wav_put_u32(std::vector<std::uint8_t>& b, std::uint32_t v)
{
b.push_back(v & 0xFF);
@@ -75,12 +72,11 @@ inline bool wav_write(const std::wstring& path, const void* pcm, std::size_t byt
detail::wav_put_u32(hdr, static_cast<std::uint32_t>(bytes));
FILE* f = nullptr;
if (_wfopen_s(&f, path.c_str(), L"wb") != 0 || f == nullptr)
{
if (_wfopen_s(&f, path.c_str(), L"wb") != 0 || f == nullptr) {
return false;
}
const bool ok = std::fwrite(hdr.data(), 1, hdr.size(), f) == hdr.size() &&
(bytes == 0 || std::fwrite(pcm, 1, bytes, f) == bytes);
const bool ok = std::fwrite(hdr.data(), 1, hdr.size(), f) == hdr.size()
&& (bytes == 0 || std::fwrite(pcm, 1, bytes, f) == bytes);
std::fclose(f);
return ok;
}
@@ -89,44 +85,37 @@ inline bool wav_write(const std::wstring& path, const void* pcm, std::size_t byt
inline bool wav_read(const std::wstring& path, WavData& out)
{
FILE* f = nullptr;
if (_wfopen_s(&f, path.c_str(), L"rb") != 0 || f == nullptr)
{
if (_wfopen_s(&f, path.c_str(), L"rb") != 0 || f == nullptr) {
return false;
}
std::fseek(f, 0, SEEK_END);
const long size = std::ftell(f);
std::fseek(f, 0, SEEK_SET);
if (size < 44)
{
if (size < 44) {
std::fclose(f);
return false;
}
std::vector<std::uint8_t> all(static_cast<std::size_t>(size));
const bool read_ok = std::fread(all.data(), 1, all.size(), f) == all.size();
std::fclose(f);
if (!read_ok || std::memcmp(all.data(), "RIFF", 4) != 0 || std::memcmp(all.data() + 8, "WAVE", 4) != 0)
{
if (!read_ok || std::memcmp(all.data(), "RIFF", 4) != 0 || std::memcmp(all.data() + 8, "WAVE", 4) != 0) {
return false;
}
// Walk chunks for "fmt " and "data".
std::size_t pos = 12;
bool have_fmt = false, have_data = false;
while (pos + 8 <= all.size())
{
while (pos + 8 <= all.size()) {
const std::uint8_t* p = all.data() + pos;
const std::uint32_t chunk_size = detail::wav_get_u32(p + 4);
const std::size_t body = pos + 8;
if (std::memcmp(p, "fmt ", 4) == 0 && body + 16 <= all.size())
{
if (std::memcmp(p, "fmt ", 4) == 0 && body + 16 <= all.size()) {
out.format_tag = detail::wav_get_u16(all.data() + body + 0);
out.channels = detail::wav_get_u16(all.data() + body + 2);
out.sample_rate = detail::wav_get_u32(all.data() + body + 4);
out.bits = detail::wav_get_u16(all.data() + body + 14);
have_fmt = true;
}
else if (std::memcmp(p, "data", 4) == 0)
{
} else if (std::memcmp(p, "data", 4) == 0) {
const std::size_t avail = all.size() - body;
const std::size_t n = std::min<std::size_t>(chunk_size, avail);
out.pcm.assign(all.begin() + body, all.begin() + body + n);
@@ -136,8 +125,7 @@ inline bool wav_read(const std::wstring& path, WavData& out)
// wrap `pos` on a 32-bit size_t (x86) and spin the loop on garbage, and there's nothing valid
// past a chunk that claims more than the file holds anyway.
const std::size_t advance = static_cast<std::size_t>(chunk_size) + (chunk_size & 1);
if (advance > all.size() - body)
{
if (advance > all.size() - body) {
break;
}
pos = body + advance;