From 18eb8a07ba39a8aad1c75521cee027b9c9c72e40 Mon Sep 17 00:00:00 2001 From: skal Date: Sun, 1 Feb 2026 00:58:20 +0100 Subject: clang-format --- src/util/asset_manager.cc | 12 ++--- src/util/asset_manager.h | 6 +-- src/util/math.h | 4 +- src/util/mini_math.h | 111 ++++++++++++++++++++++++++++------------------ 4 files changed, 80 insertions(+), 53 deletions(-) (limited to 'src/util') diff --git a/src/util/asset_manager.cc b/src/util/asset_manager.cc index de3934b..30295b9 100644 --- a/src/util/asset_manager.cc +++ b/src/util/asset_manager.cc @@ -9,19 +9,21 @@ extern const AssetRecord g_assets[]; extern const size_t g_assets_count; -const uint8_t *GetAsset(AssetId asset_id, size_t *out_size) { +const uint8_t* GetAsset(AssetId asset_id, size_t* out_size) { uint16_t index = (uint16_t)asset_id; if (index >= g_assets_count) { - if (out_size) *out_size = 0; + if (out_size) + *out_size = 0; return nullptr; } - const AssetRecord &record = g_assets[index]; - if (out_size) *out_size = record.size; + const AssetRecord& record = g_assets[index]; + if (out_size) + *out_size = record.size; return record.data; } -void DropAsset(AssetId asset_id, const uint8_t *asset) { +void DropAsset(AssetId asset_id, const uint8_t* asset) { (void)asset_id; (void)asset; // Implementation for lazy decompression will go here diff --git a/src/util/asset_manager.h b/src/util/asset_manager.h index 1b5e510..54d0144 100644 --- a/src/util/asset_manager.h +++ b/src/util/asset_manager.h @@ -10,10 +10,10 @@ enum class AssetId : uint16_t; struct AssetRecord { - const uint8_t *data; + const uint8_t* data; size_t size; }; // Generic interface -const uint8_t *GetAsset(AssetId asset_id, size_t *out_size = nullptr); -void DropAsset(AssetId asset_id, const uint8_t *asset); +const uint8_t* GetAsset(AssetId asset_id, size_t* out_size = nullptr); +void DropAsset(AssetId asset_id, const uint8_t* asset); diff --git a/src/util/math.h b/src/util/math.h index 8aa2c7a..f565b76 100644 --- a/src/util/math.h +++ b/src/util/math.h @@ -4,6 +4,6 @@ #pragma once -#ifndef M_PI +#if !defined(M_PI) #define M_PI 3.14159265358979323846 -#endif +#endif /* !defined(M_PI) */ diff --git a/src/util/mini_math.h b/src/util/mini_math.h index d3c9bc5..7314933 100644 --- a/src/util/mini_math.h +++ b/src/util/mini_math.h @@ -18,26 +18,33 @@ // T: Class Name (e.g., vec3) // N: Number of active components for math (e.g., 3) #define VEC_OPERATORS(T, N) \ - float &operator[](int i) { return v[i]; } \ - const float &operator[](int i) const { return v[i]; } \ - T &operator+=(const T &r) { \ - for (int i = 0; i < N; ++i) v[i] += r.v[i]; \ + float& operator[](int i) { \ + return v[i]; \ + } \ + const float& operator[](int i) const { \ + return v[i]; \ + } \ + T& operator+=(const T& r) { \ + for (int i = 0; i < N; ++i) \ + v[i] += r.v[i]; \ return *this; \ } \ - T &operator-=(const T &r) { \ - for (int i = 0; i < N; ++i) v[i] -= r.v[i]; \ + T& operator-=(const T& r) { \ + for (int i = 0; i < N; ++i) \ + v[i] -= r.v[i]; \ return *this; \ } \ - T &operator*=(float s) { \ - for (int i = 0; i < N; ++i) v[i] *= s; \ + T& operator*=(float s) { \ + for (int i = 0; i < N; ++i) \ + v[i] *= s; \ return *this; \ } \ - T operator+(const T &r) const { \ + T operator+(const T& r) const { \ T res(*this); \ res += r; \ return res; \ } \ - T operator-(const T &r) const { \ + T operator-(const T& r) const { \ T res(*this); \ res -= r; \ return res; \ @@ -49,24 +56,34 @@ } \ T operator-() const { \ T res; \ - for (int i = 0; i < N; ++i) res.v[i] = -v[i]; \ + for (int i = 0; i < N; ++i) \ + res.v[i] = -v[i]; \ return res; \ } \ - static float dot(const T &a, const T &b) { \ + static float dot(const T& a, const T& b) { \ float s = 0; \ - for (int i = 0; i < N; ++i) s += a.v[i] * b.v[i]; \ + for (int i = 0; i < N; ++i) \ + s += a.v[i] * b.v[i]; \ return s; \ } \ - float dot(const T &a) const { return dot(*this, a); } \ - float norm() const { return std::sqrt(dot(*this, *this)); } \ - float len() const { return norm(); } \ + float dot(const T& a) const { \ + return dot(*this, a); \ + } \ + float norm() const { \ + return std::sqrt(dot(*this, *this)); \ + } \ + float len() const { \ + return norm(); \ + } \ float inv_norm() const { \ float l2 = dot(*this, *this); \ return l2 > 0 ? 1.0f / std::sqrt(l2) : 0; \ } \ - T normalize() const { return (*this) * inv_norm(); } + T normalize() const { \ + return (*this) * inv_norm(); \ + } -#ifdef USE_VEC2 +#if defined(USE_VEC2) struct vec2 { union { struct { @@ -74,12 +91,13 @@ struct vec2 { }; float v[2]; }; - vec2(float x = 0, float y = 0) : x(x), y(y) {} + vec2(float x = 0, float y = 0) : x(x), y(y) { + } VEC_OPERATORS(vec2, 2) }; -#endif +#endif /* defined(USE_VEC2) */ -#ifdef USE_VEC3 +#if defined(USE_VEC3) struct vec3 { union { struct { @@ -88,7 +106,8 @@ struct vec3 { }; // _ is padding for 16-byte alignment float v[4]; // Size 4 to match alignment }; - vec3(float x = 0, float y = 0, float z = 0) : x(x), y(y), z(z), _(0) {} + vec3(float x = 0, float y = 0, float z = 0) : x(x), y(y), z(z), _(0) { + } VEC_OPERATORS(vec3, 3) // Operators only touch x,y,z (indices 0,1,2) static vec3 cross(vec3 a, vec3 b) { @@ -96,9 +115,9 @@ struct vec3 { a.x * b.y - a.y * b.x}; } }; -#endif +#endif /* defined(USE_VEC3) */ -#ifdef USE_VEC4 +#if defined(USE_VEC4) struct vec4 { union { struct { @@ -107,12 +126,13 @@ struct vec4 { float v[4]; }; vec4(float x = 0, float y = 0, float z = 0, float w = 0) - : x(x), y(y), z(z), w(w) {} + : x(x), y(y), z(z), w(w) { + } VEC_OPERATORS(vec4, 4) }; -#endif +#endif /* defined(USE_VEC4) */ -#ifdef USE_MAT4 +#if defined(USE_MAT4) struct mat4 { float m[16] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; // Identity (Column-Major) @@ -148,9 +168,9 @@ struct mat4 { return res; } }; -#endif +#endif /* defined(USE_MAT4) */ -#ifdef USE_QUAT +#if defined(USE_QUAT) struct quat { union { struct { @@ -159,10 +179,11 @@ struct quat { float v[4]; }; quat(float x = 0, float y = 0, float z = 0, float w = 1) - : x(x), y(y), z(z), w(w) {} + : x(x), y(y), z(z), w(w) { + } VEC_OPERATORS(quat, 4) - quat operator*(const quat &q) const { + quat operator*(const quat& q) const { return {w * q.x + x * q.w + y * q.z - z * q.y, w * q.y - x * q.z + y * q.w + z * q.x, w * q.z + x * q.y - y * q.x + z * q.w, @@ -177,7 +198,8 @@ struct quat { static quat from_to(vec3 a, vec3 b) { float d = vec3::dot(a, b); vec3 axis = vec3::cross(a, b); - if (d < -0.9999f) return {0, 1, 0, 0}; + if (d < -0.9999f) + return {0, 1, 0, 0}; float s = std::sqrt((1.0f + d) * 2.0f), inv_s = 1.0f / s; return {axis.x * inv_s, axis.y * inv_s, axis.z * inv_s, s * 0.5f}; } @@ -237,22 +259,25 @@ inline quat slerp(quat a, quat b, float t) { } if (d > 0.9995f) { // Linear fall-back quat r; - for (int i = 0; i < 4; ++i) r.v[i] = a.v[i] + (b.v[i] - a.v[i]) * t; + for (int i = 0; i < 4; ++i) + r.v[i] = a.v[i] + (b.v[i] - a.v[i]) * t; return r; } float th0 = std::acos(d), th = th0 * t, s0 = std::sin(th0), s1 = std::sin(th) / s0, s2 = std::sin(th0 - th) / s0; return a * s2 + b * s1; } -#endif +#endif /* defined(USE_QUAT) */ -template inline T lerp(const T &a, const T &b, float t) { +template inline T lerp(const T& a, const T& b, float t) { return a + (b - a) * t; } -#ifdef USE_EASING +#if defined(USE_EASING) namespace ease { -inline float out_cubic(float t) { return 1.0f - std::pow(1.0f - t, 3.0f); } +inline float out_cubic(float t) { + return 1.0f - std::pow(1.0f - t, 3.0f); +} inline float in_out_quad(float t) { return t < 0.5f ? 2.0f * t * t : 1.0f - std::pow(-2.0f * t + 2.0f, 2.0f) / 2.0f; @@ -260,13 +285,13 @@ inline float in_out_quad(float t) { inline float out_expo(float t) { return t == 1.0f ? 1.0f : 1.0f - std::pow(2.0f, -10.0f * t); } -} -#endif +} // namespace ease +#endif /* defined(USE_EASING) */ -#ifdef USE_SPRING +#if defined(USE_SPRING) namespace spring { template -void solve(T ¤t, T &velocity, const T &target, float smooth_time, +void solve(T& current, T& velocity, const T& target, float smooth_time, float dt) { float omega = 2.0f / smooth_time; float x = omega * dt; @@ -276,5 +301,5 @@ void solve(T ¤t, T &velocity, const T &target, float smooth_time, velocity = (velocity - temp * omega) * exp; current = target + (change + temp) * exp; } -} -#endif +} // namespace spring +#endif /* defined(USE_SPRING) */ -- cgit v1.2.3