Browse Source

Apply formatting to headers

Kajetan Johannes Hammerle 1 month ago
parent
commit
790d196efe

+ 1 - 0
include/core/BitArray.h

@@ -8,6 +8,7 @@ typedef struct {
     u64 bits : 8;
     u64* data;
 } BitArray;
+
 static_assert(sizeof(BitArray) == 16, "invalid bit array size");
 
 void initBitArray(BitArray* a, size_t length, size_t bits);

+ 1 - 0
include/core/Box.h

@@ -8,6 +8,7 @@ typedef union {
         Vector3 min;
         Vector3 max;
     };
+
     Vector3 v[2];
 } Box;
 

+ 1 - 1
include/core/Buffer.h

@@ -12,7 +12,7 @@ typedef struct {
 void initBuffer(Buffer* b);
 void destroyBuffer(Buffer* b);
 void addSizedBufferData(Buffer* b, const void* data, size_t size);
-#define addTypedBufferData(buffer, type, ...)                                  \
+#define addTypedBufferData(buffer, type, ...)                      \
     addSizedBufferData(buffer, &(type){__VA_ARGS__}, sizeof(type))
 void clearBuffer(Buffer* b);
 

+ 1 - 1
include/core/Check.h

@@ -2,7 +2,7 @@
 #define CORE_CHECK_H
 
 #if defined(__GNUC__)
-#define check_format(format_index, arg_start_index)                            \
+#define check_format(format_index, arg_start_index)                \
     __attribute__((format(printf, format_index, arg_start_index)))
 #else
 #error "please add a 'check_format' option"

+ 80 - 80
include/core/Components.h

@@ -44,86 +44,86 @@ typedef size_t Entity;
     T* getComponentsStart##N(Components##N* c);                                \
     T* getComponentsEnd##N(Components##N* c);
 
-#define COMPONENTS_SOURCE(T, N)                                                \
-    void initComponents##N(Components##N* c) {                                 \
-        initHashMapSize(&c->entityToIndex);                                    \
-        initListSize(&c->indexToEntity);                                       \
-        initList##N(&c->components);                                           \
-    }                                                                          \
-                                                                               \
-    void destroyComponents##N(Components##N* c) {                              \
-        destroyHashMapSize(&c->entityToIndex);                                 \
-        destroyListSize(&c->indexToEntity);                                    \
-        destroyList##N(&c->components);                                        \
-    }                                                                          \
-                                                                               \
-    T* getOrAddComponent##N(Components##N* c, Entity e) {                      \
-        void* component = searchComponent##N(c, e);                            \
-        if(component != nullptr) {                                             \
-            return component;                                                  \
-        }                                                                      \
-        size_t index = c->components.length;                                   \
-        *putHashMapKeySize(&c->entityToIndex, e) = index;                      \
-        addListDataSize(&c->indexToEntity, e);                                 \
-        return addEmptyListData##N(&c->components);                            \
-    }                                                                          \
-                                                                               \
-    T* searchComponent##N(Components##N* c, Entity e) {                        \
-        size_t* index = searchHashMapKeySize(&c->entityToIndex, e);            \
-        if(index == nullptr) {                                                 \
-            return nullptr;                                                    \
-        }                                                                      \
-        return getListIndex##N(&c->components, *index);                        \
-    }                                                                          \
-                                                                               \
-    bool removeComponent##N(Components##N* c, Entity e) {                      \
-        size_t* indexP = searchHashMapKeySize(&c->entityToIndex, e);           \
-        if(indexP == nullptr) {                                                \
-            return false;                                                      \
-        }                                                                      \
-        size_t lastIndex = c->components.length - 1;                           \
-        size_t index = *indexP;                                                \
-        removeHashMapKeySize(&c->entityToIndex, e);                            \
-        removeListIndexBySwap##N(&c->components, index);                       \
-        if(index == lastIndex) {                                               \
-            removeListIndexBySwapSize(&c->indexToEntity, index);               \
-            return true;                                                       \
-        }                                                                      \
-        Entity other = *getListIndexSize(&c->indexToEntity, lastIndex);        \
-        removeListIndexBySwapSize(&c->indexToEntity, index);                   \
-        *putHashMapKeySize(&c->entityToIndex, other) = index;                  \
-        return true;                                                           \
-    }                                                                          \
-                                                                               \
-    void initComponentIterator##N(ComponentIterator##N* ci,                    \
-                                  Components##N* c) {                          \
-        ci->indexToEntity = getListStartSize(&c->indexToEntity);               \
-        ci->indexToEntityEnd = getListEndSize(&c->indexToEntity);              \
-        ci->component = getListStart##N(&c->components);                       \
-        ci->componentEnd = getListEnd##N(&c->components);                      \
-        ci->node = (ComponentNode##N){0};                                      \
-    }                                                                          \
-                                                                               \
-    bool hasNextComponentNode##N(ComponentIterator##N* ci) {                   \
-        return ci->indexToEntity != ci->indexToEntityEnd;                      \
-    }                                                                          \
-                                                                               \
-    ComponentNode##N* nextComponentNode##N(ComponentIterator##N* ci) {         \
-        ci->node.component = ci->component;                                    \
-        ci->node.entity = *ci->indexToEntity;                                  \
-        ci->indexToEntity++;                                                   \
-        ci->component++;                                                       \
-        return &ci->node;                                                      \
-    }                                                                          \
-                                                                               \
-    T* getComponentsStart##N(Components##N* c) {                               \
-        return getListStart##N(&c->components);                                \
-    }                                                                          \
-                                                                               \
-    T* getComponentsEnd##N(Components##N* c) {                                 \
-        return getListEnd##N(&c->components);                                  \
-    }                                                                          \
-    LIST_SOURCE(size_t, Size)                                                  \
+#define COMPONENTS_SOURCE(T, N)                                         \
+    void initComponents##N(Components##N* c) {                          \
+        initHashMapSize(&c->entityToIndex);                             \
+        initListSize(&c->indexToEntity);                                \
+        initList##N(&c->components);                                    \
+    }                                                                   \
+                                                                        \
+    void destroyComponents##N(Components##N* c) {                       \
+        destroyHashMapSize(&c->entityToIndex);                          \
+        destroyListSize(&c->indexToEntity);                             \
+        destroyList##N(&c->components);                                 \
+    }                                                                   \
+                                                                        \
+    T* getOrAddComponent##N(Components##N* c, Entity e) {               \
+        void* component = searchComponent##N(c, e);                     \
+        if(component != nullptr) {                                      \
+            return component;                                           \
+        }                                                               \
+        size_t index = c->components.length;                            \
+        *putHashMapKeySize(&c->entityToIndex, e) = index;               \
+        addListDataSize(&c->indexToEntity, e);                          \
+        return addEmptyListData##N(&c->components);                     \
+    }                                                                   \
+                                                                        \
+    T* searchComponent##N(Components##N* c, Entity e) {                 \
+        size_t* index = searchHashMapKeySize(&c->entityToIndex, e);     \
+        if(index == nullptr) {                                          \
+            return nullptr;                                             \
+        }                                                               \
+        return getListIndex##N(&c->components, *index);                 \
+    }                                                                   \
+                                                                        \
+    bool removeComponent##N(Components##N* c, Entity e) {               \
+        size_t* indexP = searchHashMapKeySize(&c->entityToIndex, e);    \
+        if(indexP == nullptr) {                                         \
+            return false;                                               \
+        }                                                               \
+        size_t lastIndex = c->components.length - 1;                    \
+        size_t index = *indexP;                                         \
+        removeHashMapKeySize(&c->entityToIndex, e);                     \
+        removeListIndexBySwap##N(&c->components, index);                \
+        if(index == lastIndex) {                                        \
+            removeListIndexBySwapSize(&c->indexToEntity, index);        \
+            return true;                                                \
+        }                                                               \
+        Entity other = *getListIndexSize(&c->indexToEntity, lastIndex); \
+        removeListIndexBySwapSize(&c->indexToEntity, index);            \
+        *putHashMapKeySize(&c->entityToIndex, other) = index;           \
+        return true;                                                    \
+    }                                                                   \
+                                                                        \
+    void initComponentIterator##N(                                      \
+        ComponentIterator##N* ci, Components##N* c) {                   \
+        ci->indexToEntity = getListStartSize(&c->indexToEntity);        \
+        ci->indexToEntityEnd = getListEndSize(&c->indexToEntity);       \
+        ci->component = getListStart##N(&c->components);                \
+        ci->componentEnd = getListEnd##N(&c->components);               \
+        ci->node = (ComponentNode##N){0};                               \
+    }                                                                   \
+                                                                        \
+    bool hasNextComponentNode##N(ComponentIterator##N* ci) {            \
+        return ci->indexToEntity != ci->indexToEntityEnd;               \
+    }                                                                   \
+                                                                        \
+    ComponentNode##N* nextComponentNode##N(ComponentIterator##N* ci) {  \
+        ci->node.component = ci->component;                             \
+        ci->node.entity = *ci->indexToEntity;                           \
+        ci->indexToEntity++;                                            \
+        ci->component++;                                                \
+        return &ci->node;                                               \
+    }                                                                   \
+                                                                        \
+    T* getComponentsStart##N(Components##N* c) {                        \
+        return getListStart##N(&c->components);                         \
+    }                                                                   \
+                                                                        \
+    T* getComponentsEnd##N(Components##N* c) {                          \
+        return getListEnd##N(&c->components);                           \
+    }                                                                   \
+    LIST_SOURCE(size_t, Size)                                           \
     HASHMAP_SOURCE(size_t, size_t, Size)
 
 #endif

+ 3 - 3
include/core/Frustum.h

@@ -14,9 +14,9 @@ typedef struct {
 
 void initFrustum(Frustum* f, float fieldOfView, float nearClip, float farClip);
 const Matrix* updateProjection(Frustum* f, const IntVector2* size);
-void updateFrustumPlanes(Frustum* f, const Vector3* pos, const Vector3* right,
-                         const Vector3* up, const Vector3* front,
-                         const IntVector2* size);
+void updateFrustumPlanes(
+    Frustum* f, const Vector3* pos, const Vector3* right, const Vector3* up,
+    const Vector3* front, const IntVector2* size);
 bool isInsideFrustum(const Frustum* f, const Vector3* pos);
 bool isInsideFrustumRadius(const Frustum* f, const Vector3* pos, float radius);
 

+ 75 - 65
include/core/Generic.h

@@ -7,33 +7,36 @@
 #define GENERIC_PAIR(type, name) type: name, const type : name
 // clang-format on
 
-#define GENERIC_FLOAT_VECTOR(a, name)                                          \
-    _Generic((a),                                                              \
-        GENERIC_PAIR(Vector2*, name##V2),                                      \
-        GENERIC_PAIR(Vector3*, name##V3),                                      \
+#define GENERIC_FLOAT_VECTOR(a, name)     \
+    _Generic(                             \
+        (a),                              \
+        GENERIC_PAIR(Vector2*, name##V2), \
+        GENERIC_PAIR(Vector3*, name##V3), \
         GENERIC_PAIR(Vector4*, name##V4))
 
-#define GENERIC_VECTOR(a, name)                                                \
-    _Generic((a),                                                              \
-        GENERIC_PAIR(Vector2*, name##V2),                                      \
-        GENERIC_PAIR(Vector3*, name##V3),                                      \
-        GENERIC_PAIR(Vector4*, name##V4),                                      \
-        GENERIC_PAIR(IntVector2*, name##IV2),                                  \
-        GENERIC_PAIR(IntVector3*, name##IV3),                                  \
+#define GENERIC_VECTOR(a, name)               \
+    _Generic(                                 \
+        (a),                                  \
+        GENERIC_PAIR(Vector2*, name##V2),     \
+        GENERIC_PAIR(Vector3*, name##V3),     \
+        GENERIC_PAIR(Vector4*, name##V4),     \
+        GENERIC_PAIR(IntVector2*, name##IV2), \
+        GENERIC_PAIR(IntVector3*, name##IV3), \
         GENERIC_PAIR(IntVector4*, name##IV4))
 
-#define ZERO_VECTOR(a)                                                         \
-    _Generic((a),                                                              \
-        GENERIC_PAIR(Matrix*, &(Vector3){0}),                                  \
-        GENERIC_PAIR(Vector2*, &(Vector2){0}),                                 \
-        GENERIC_PAIR(Vector3*, &(Vector3){0}),                                 \
-        GENERIC_PAIR(Vector4*, &(Vector4){0}),                                 \
-        GENERIC_PAIR(IntVector2*, &(IntVector2){0}),                           \
-        GENERIC_PAIR(IntVector3*, &(IntVector3){0}),                           \
+#define ZERO_VECTOR(a)                               \
+    _Generic(                                        \
+        (a),                                         \
+        GENERIC_PAIR(Matrix*, &(Vector3){0}),        \
+        GENERIC_PAIR(Vector2*, &(Vector2){0}),       \
+        GENERIC_PAIR(Vector3*, &(Vector3){0}),       \
+        GENERIC_PAIR(Vector4*, &(Vector4){0}),       \
+        GENERIC_PAIR(IntVector2*, &(IntVector2){0}), \
+        GENERIC_PAIR(IntVector3*, &(IntVector3){0}), \
         GENERIC_PAIR(IntVector4*, &(IntVector4){0}))
 
-#define GENERIC_FACTOR(b, type, base, factor)                                  \
-    type:                                                                      \
+#define GENERIC_FACTOR(b, type, base, factor)                \
+    type:                                                    \
     _Generic((b), GENERIC_PAIR(type, base), default: factor)
 
 #define SELECT_OP(_1, _2, _3, name, ...) name
@@ -48,51 +51,57 @@
 #define sub2(a, b) sub3(ZERO_VECTOR(a), a, b)
 #define sub(...) SELECT_OP(__VA_ARGS__, sub3, sub2, 0)(__VA_ARGS__)
 
-#define mulSet(a, b)                                                           \
-    _Generic((a),                                                              \
-        Matrix *: mulSetMatrix,                                                \
-        Quaternion *: mulSetQ,                                                 \
-        GENERIC_FACTOR(b, Vector2*, mulSetV2, mulSetV2F),                      \
-        GENERIC_FACTOR(b, Vector3*, mulSetV3, mulSetV3F),                      \
-        GENERIC_FACTOR(b, Vector4*, mulSetV4, mulSetV4F),                      \
-        GENERIC_FACTOR(b, IntVector2*, mulSetIV2, mulSetIV2F),                 \
-        GENERIC_FACTOR(b, IntVector3*, mulSetIV3, mulSetIV3F),                 \
+#define mulSet(a, b)                                                 \
+    _Generic(                                                        \
+        (a),                                                         \
+        Matrix *: mulSetMatrix,                                      \
+        Quaternion *: mulSetQ,                                       \
+        GENERIC_FACTOR(b, Vector2*, mulSetV2, mulSetV2F),            \
+        GENERIC_FACTOR(b, Vector3*, mulSetV3, mulSetV3F),            \
+        GENERIC_FACTOR(b, Vector4*, mulSetV4, mulSetV4F),            \
+        GENERIC_FACTOR(b, IntVector2*, mulSetIV2, mulSetIV2F),       \
+        GENERIC_FACTOR(b, IntVector3*, mulSetIV3, mulSetIV3F),       \
         GENERIC_FACTOR(b, IntVector4*, mulSetIV4, mulSetIV4F))(a, b)
 
-#define mul3(a, b, c)                                                          \
-    _Generic((a),                                                              \
-        Matrix *: mulMatrix,                                                   \
-        Quaternion *: mulQ,                                                    \
-        GENERIC_FACTOR(c, Vector2*, mulV2, mulV2F),                            \
-        Vector3 *: _Generic((c),                                               \
-                 Vector3 *: _Generic((b),                                      \
-                          GENERIC_PAIR(Quaternion*, mulQV3),                   \
-                          GENERIC_PAIR(Matrix*, mulMatrixV3),                  \
-                          default: mulV3),                                     \
-                 default: mulV3F),                                             \
-        GENERIC_FACTOR(c, Vector4*, mulV4, mulV4F),                            \
-        GENERIC_FACTOR(c, IntVector2*, mulIV2, mulIV2F),                       \
-        GENERIC_FACTOR(c, IntVector3*, mulIV3, mulIV3F),                       \
+#define mul3(a, b, c)                                             \
+    _Generic(                                                     \
+        (a),                                                      \
+        Matrix *: mulMatrix,                                      \
+        Quaternion *: mulQ,                                       \
+        GENERIC_FACTOR(c, Vector2*, mulV2, mulV2F),               \
+        Vector3 *: _Generic(                                      \
+                     (c),                                         \
+                Vector3 *: _Generic(                              \
+                             (b),                                 \
+                        GENERIC_PAIR(Quaternion*, mulQV3),        \
+                        GENERIC_PAIR(Matrix*, mulMatrixV3),       \
+                        default: mulV3),                          \
+                default: mulV3F),                                 \
+        GENERIC_FACTOR(c, Vector4*, mulV4, mulV4F),               \
+        GENERIC_FACTOR(c, IntVector2*, mulIV2, mulIV2F),          \
+        GENERIC_FACTOR(c, IntVector3*, mulIV3, mulIV3F),          \
         GENERIC_FACTOR(c, IntVector4*, mulIV4, mulIV4F))(a, b, c)
 #define mul2(a, b) mul3(ZERO_VECTOR(a), a, b)
 #define mul(...) SELECT_OP(__VA_ARGS__, mul3, mul2, 0)(__VA_ARGS__)
 
-#define divSet(a, b)                                                           \
-    _Generic((a),                                                              \
-        GENERIC_FACTOR(b, Vector2*, divSetV2, divSetV2F),                      \
-        GENERIC_FACTOR(b, Vector3*, divSetV3, divSetV3F),                      \
-        GENERIC_FACTOR(b, Vector4*, divSetV4, divSetV4F),                      \
-        GENERIC_FACTOR(b, IntVector2*, divSetIV2, divSetIV2F),                 \
-        GENERIC_FACTOR(b, IntVector3*, divSetIV3, divSetIV3F),                 \
+#define divSet(a, b)                                                 \
+    _Generic(                                                        \
+        (a),                                                         \
+        GENERIC_FACTOR(b, Vector2*, divSetV2, divSetV2F),            \
+        GENERIC_FACTOR(b, Vector3*, divSetV3, divSetV3F),            \
+        GENERIC_FACTOR(b, Vector4*, divSetV4, divSetV4F),            \
+        GENERIC_FACTOR(b, IntVector2*, divSetIV2, divSetIV2F),       \
+        GENERIC_FACTOR(b, IntVector3*, divSetIV3, divSetIV3F),       \
         GENERIC_FACTOR(b, IntVector4*, divSetIV4, divSetIV4F))(a, b)
 
-#define div3(a, b, c)                                                          \
-    _Generic((a),                                                              \
-        GENERIC_FACTOR(c, Vector2*, divV2, divV2F),                            \
-        GENERIC_FACTOR(c, Vector3*, divV3, divV3F),                            \
-        GENERIC_FACTOR(c, Vector4*, divV4, divV4F),                            \
-        GENERIC_FACTOR(c, IntVector2*, divIV2, divIV2F),                       \
-        GENERIC_FACTOR(c, IntVector3*, divIV3, divIV3F),                       \
+#define div3(a, b, c)                                             \
+    _Generic(                                                     \
+        (a),                                                      \
+        GENERIC_FACTOR(c, Vector2*, divV2, divV2F),               \
+        GENERIC_FACTOR(c, Vector3*, divV3, divV3F),               \
+        GENERIC_FACTOR(c, Vector4*, divV4, divV4F),               \
+        GENERIC_FACTOR(c, IntVector2*, divIV2, divIV2F),          \
+        GENERIC_FACTOR(c, IntVector3*, divIV3, divIV3F),          \
         GENERIC_FACTOR(c, IntVector4*, divIV4, divIV4F))(a, b, c)
 #define div2(a, b) div3(ZERO_VECTOR(a), a, b)
 #define div(...) SELECT_OP(__VA_ARGS__, div3, div2, 0)(__VA_ARGS__)
@@ -112,13 +121,14 @@
 #define cross2(a, b) cross(&(Vector3){0}, a, b)
 #define cross(...) SELECT_OP(__VA_ARGS__, cross3, cross2, 0)(__VA_ARGS__)
 
-#define convert(a, b)                                                          \
-    _Generic((a),                                                              \
-        Vector2 *: convertIV2,                                                 \
-        Vector3 *: convertIV3,                                                 \
-        Vector4 *: convertIV4,                                                 \
-        IntVector2 *: convertV2,                                               \
-        IntVector3 *: convertV3,                                               \
+#define convert(a, b)                  \
+    _Generic(                          \
+        (a),                           \
+        Vector2 *: convertIV2,         \
+        Vector3 *: convertIV3,         \
+        Vector4 *: convertIV4,         \
+        IntVector2 *: convertV2,       \
+        IntVector3 *: convertV3,       \
         IntVector4 *: convertV4)(a, b)
 
 #endif

+ 12 - 12
include/core/HashMap.h

@@ -48,13 +48,13 @@ size_t roundUp2(size_t n);
     void initHashMapIterator##N(HashMapIterator##N* mi, const HashMap##N* m);  \
     bool hasNextHashMapNode##N(HashMapIterator##N* mi);                        \
     HashMapNode##N* nextHashMapNode##N(HashMapIterator##N* mi);                \
-    typedef size_t (*ToStringKey##N)(K const* const data, char* buffer,        \
-                                     size_t n);                                \
-    typedef size_t (*ToStringValue##N)(V const* const data, char* buffer,      \
-                                       size_t n);                              \
-    size_t toStringHashMap##N(const HashMap##N* m, char* buffer, size_t n,     \
-                              ToStringKey##N keyString,                        \
-                              ToStringValue##N valueString);
+    typedef size_t (*ToStringKey##N)(                                          \
+        K const* const data, char* buffer, size_t n);                          \
+    typedef size_t (*ToStringValue##N)(                                        \
+        V const* const data, char* buffer, size_t n);                          \
+    size_t toStringHashMap##N(                                                 \
+        const HashMap##N* m, char* buffer, size_t n, ToStringKey##N keyString, \
+        ToStringValue##N valueString);
 
 #define HASHMAP_SOURCE(K, V, N)                                                \
     static size_t searchSlot##N(HashMap##N* m, K key) {                        \
@@ -64,7 +64,7 @@ size_t roundUp2(size_t n);
             if(isInvalidKey##N(key)) {                                         \
                 return m->capacity - 1;                                        \
             }                                                                  \
-            size_t baseHash = hash##N(key) * 514685581u;                       \
+            size_t baseHash = hash##N(key) * 514'685'581u;                     \
             size_t end = m->capacity - 2;                                      \
             /* rehash on bad clustering */                                     \
             for(size_t i = 0; i <= 5; i++) {                                   \
@@ -140,7 +140,7 @@ size_t roundUp2(size_t n);
                 size_t i = m->capacity - 1;                                    \
                 return isInvalidKey##N(m->keys[i]) ? m->values + i : nullptr;  \
             }                                                                  \
-            size_t baseHash = hash##N(key) * 514685581u;                       \
+            size_t baseHash = hash##N(key) * 514'685'581u;                     \
             size_t end = m->capacity - 2;                                      \
             for(size_t i = 0; i <= end; i++) {                                 \
                 size_t hash = (baseHash + i) & end;                            \
@@ -212,9 +212,9 @@ size_t roundUp2(size_t n);
         return &mi->node;                                                      \
     }                                                                          \
                                                                                \
-    size_t toStringHashMap##N(const HashMap##N* m, char* buffer, size_t n,     \
-                              ToStringKey##N keyString,                        \
-                              ToStringValue##N valueString) {                  \
+    size_t toStringHashMap##N(                                                 \
+        const HashMap##N* m, char* buffer, size_t n, ToStringKey##N keyString, \
+        ToStringValue##N valueString) {                                        \
         size_t w = 0;                                                          \
         stringAdd(&w, &buffer, &n, toString(buffer, n, "["));                  \
         bool notFirst = false;                                                 \

+ 118 - 118
include/core/List.h

@@ -7,125 +7,125 @@
 #include "core/Types.h"
 #include "core/Utility.h"
 
-#define LIST(T, N)                                                             \
-    struct ListT##N {                                                          \
-        size_t length;                                                         \
-        size_t capacity;                                                       \
-        T* data;                                                               \
-    };                                                                         \
-    typedef struct ListT##N List##N;                                           \
-                                                                               \
-    void initList##N(List##N* l);                                              \
-    void destroyList##N(List##N* l);                                           \
-    void reserveListEntries##N(List##N* l, size_t n);                          \
-    void addListData##N(List##N* l, T data);                                   \
-    void addLastListData##N(List##N* l);                                       \
-    T* addEmptyListData##N(List##N* l);                                        \
-    T* getListIndex##N(const List##N* l, size_t index);                        \
-    T* getListLast##N(const List##N* l);                                       \
-    void clearList##N(List##N* l);                                             \
-    void removeListIndexBySwap##N(List##N* l, size_t index);                   \
-    void removeListIndex##N(List##N* l, size_t index);                         \
-    void removeListLast##N(List##N* l);                                        \
-    T* getListStart##N(const List##N* l);                                      \
-    T* getListEnd##N(const List##N* l);                                        \
-    typedef size_t (*ToString##N)(const T* data, char* buffer, size_t n);      \
-    size_t toStringList##N(const List##N* l, char* buffer, size_t n,           \
-                           ToString##N c);
+#define LIST(T, N)                                                        \
+    struct ListT##N {                                                     \
+        size_t length;                                                    \
+        size_t capacity;                                                  \
+        T* data;                                                          \
+    };                                                                    \
+    typedef struct ListT##N List##N;                                      \
+                                                                          \
+    void initList##N(List##N* l);                                         \
+    void destroyList##N(List##N* l);                                      \
+    void reserveListEntries##N(List##N* l, size_t n);                     \
+    void addListData##N(List##N* l, T data);                              \
+    void addLastListData##N(List##N* l);                                  \
+    T* addEmptyListData##N(List##N* l);                                   \
+    T* getListIndex##N(const List##N* l, size_t index);                   \
+    T* getListLast##N(const List##N* l);                                  \
+    void clearList##N(List##N* l);                                        \
+    void removeListIndexBySwap##N(List##N* l, size_t index);              \
+    void removeListIndex##N(List##N* l, size_t index);                    \
+    void removeListLast##N(List##N* l);                                   \
+    T* getListStart##N(const List##N* l);                                 \
+    T* getListEnd##N(const List##N* l);                                   \
+    typedef size_t (*ToString##N)(const T* data, char* buffer, size_t n); \
+    size_t toStringList##N(                                               \
+        const List##N* l, char* buffer, size_t n, ToString##N c);
 
-#define LIST_SOURCE(T, N)                                                      \
-    void initList##N(List##N* l) {                                             \
-        *l = (List##N){0, 0, nullptr};                                         \
-    }                                                                          \
-                                                                               \
-    void destroyList##N(List##N* l) {                                          \
-        coreFree(l->data);                                                     \
-        *l = (List##N){0};                                                     \
-    }                                                                          \
-                                                                               \
-    void reserveListEntries##N(List##N* l, size_t n) {                         \
-        if(n > l->capacity) {                                                  \
-            l->capacity = n;                                                   \
-            l->data = coreReallocate(l->data, sizeof(T) * n);                  \
-        }                                                                      \
-    }                                                                          \
-                                                                               \
-    void addListData##N(List##N* l, T data) {                                  \
-        *addEmptyListData##N(l) = data;                                        \
-    }                                                                          \
-                                                                               \
-    void addLastListData##N(List##N* l) {                                      \
-        addListData##N(l, *getListLast##N(l));                                 \
-    }                                                                          \
-                                                                               \
-    T* addEmptyListData##N(List##N* l) {                                       \
-        if(l->length >= l->capacity) {                                         \
-            reserveListEntries##N(l, l->capacity +                             \
-                                         maxSize(4lu, l->capacity / 4));       \
-        }                                                                      \
-        return l->data + l->length++;                                          \
-    }                                                                          \
-                                                                               \
-    T* getListIndex##N(const List##N* l, size_t index) {                       \
-        assert(index < l->length);                                             \
-        return l->data + index;                                                \
-    }                                                                          \
-                                                                               \
-    T* getListLast##N(const List##N* l) {                                      \
-        return getListIndex##N(l, l->length - 1);                              \
-    }                                                                          \
-                                                                               \
-    void clearList##N(List##N* l) {                                            \
-        l->length = 0;                                                         \
-    }                                                                          \
-                                                                               \
-    void removeListIndexBySwap##N(List##N* l, size_t index) {                  \
-        assert(index < l->length);                                             \
-        size_t length = l->length - 1;                                         \
-        if(index != length) {                                                  \
-            l->data[index] = l->data[length];                                  \
-        }                                                                      \
-        l->length = length;                                                    \
-    }                                                                          \
-                                                                               \
-    void removeListIndex##N(List##N* l, size_t index) {                        \
-        assert(index < l->length);                                             \
-        l->length--;                                                           \
-        T* p = l->data + index;                                                \
-        T* end = getListEnd##N(l);                                             \
-        while(p != end) {                                                      \
-            *p = *(p + 1);                                                     \
-            p++;                                                               \
-        }                                                                      \
-    }                                                                          \
-                                                                               \
-    void removeListLast##N(List##N* l) {                                       \
-        removeListIndexBySwap##N(l, l->length - 1);                            \
-    }                                                                          \
-                                                                               \
-    T* getListStart##N(const List##N* l) {                                     \
-        return l->data;                                                        \
-    }                                                                          \
-                                                                               \
-    T* getListEnd##N(const List##N* l) {                                       \
-        return l->data + l->length;                                            \
-    }                                                                          \
-                                                                               \
-    size_t toStringList##N(const List##N* l, char* buffer, size_t n,           \
-                           ToString##N c) {                                    \
-        size_t w = 0;                                                          \
-        stringAdd(&w, &buffer, &n, toString(buffer, n, "["));                  \
-        T* end = getListEnd##N(l);                                             \
-        T* p = getListStart##N(l);                                             \
-        while(p != end) {                                                      \
-            stringAdd(&w, &buffer, &n, c(p, buffer, n));                       \
-            p++;                                                               \
-            if(p != end) {                                                     \
-                stringAdd(&w, &buffer, &n, toString(buffer, n, ", "));         \
-            }                                                                  \
-        }                                                                      \
-        stringAdd(&w, &buffer, &n, toString(buffer, n, "]"));                  \
-        return w;                                                              \
+#define LIST_SOURCE(T, N)                                              \
+    void initList##N(List##N* l) {                                     \
+        *l = (List##N){0, 0, nullptr};                                 \
+    }                                                                  \
+                                                                       \
+    void destroyList##N(List##N* l) {                                  \
+        coreFree(l->data);                                             \
+        *l = (List##N){0};                                             \
+    }                                                                  \
+                                                                       \
+    void reserveListEntries##N(List##N* l, size_t n) {                 \
+        if(n > l->capacity) {                                          \
+            l->capacity = n;                                           \
+            l->data = coreReallocate(l->data, sizeof(T) * n);          \
+        }                                                              \
+    }                                                                  \
+                                                                       \
+    void addListData##N(List##N* l, T data) {                          \
+        *addEmptyListData##N(l) = data;                                \
+    }                                                                  \
+                                                                       \
+    void addLastListData##N(List##N* l) {                              \
+        addListData##N(l, *getListLast##N(l));                         \
+    }                                                                  \
+                                                                       \
+    T* addEmptyListData##N(List##N* l) {                               \
+        if(l->length >= l->capacity) {                                 \
+            reserveListEntries##N(                                     \
+                l, l->capacity + maxSize(4lu, l->capacity / 4));       \
+        }                                                              \
+        return l->data + l->length++;                                  \
+    }                                                                  \
+                                                                       \
+    T* getListIndex##N(const List##N* l, size_t index) {               \
+        assert(index < l->length);                                     \
+        return l->data + index;                                        \
+    }                                                                  \
+                                                                       \
+    T* getListLast##N(const List##N* l) {                              \
+        return getListIndex##N(l, l->length - 1);                      \
+    }                                                                  \
+                                                                       \
+    void clearList##N(List##N* l) {                                    \
+        l->length = 0;                                                 \
+    }                                                                  \
+                                                                       \
+    void removeListIndexBySwap##N(List##N* l, size_t index) {          \
+        assert(index < l->length);                                     \
+        size_t length = l->length - 1;                                 \
+        if(index != length) {                                          \
+            l->data[index] = l->data[length];                          \
+        }                                                              \
+        l->length = length;                                            \
+    }                                                                  \
+                                                                       \
+    void removeListIndex##N(List##N* l, size_t index) {                \
+        assert(index < l->length);                                     \
+        l->length--;                                                   \
+        T* p = l->data + index;                                        \
+        T* end = getListEnd##N(l);                                     \
+        while(p != end) {                                              \
+            *p = *(p + 1);                                             \
+            p++;                                                       \
+        }                                                              \
+    }                                                                  \
+                                                                       \
+    void removeListLast##N(List##N* l) {                               \
+        removeListIndexBySwap##N(l, l->length - 1);                    \
+    }                                                                  \
+                                                                       \
+    T* getListStart##N(const List##N* l) {                             \
+        return l->data;                                                \
+    }                                                                  \
+                                                                       \
+    T* getListEnd##N(const List##N* l) {                               \
+        return l->data + l->length;                                    \
+    }                                                                  \
+                                                                       \
+    size_t toStringList##N(                                            \
+        const List##N* l, char* buffer, size_t n, ToString##N c) {     \
+        size_t w = 0;                                                  \
+        stringAdd(&w, &buffer, &n, toString(buffer, n, "["));          \
+        T* end = getListEnd##N(l);                                     \
+        T* p = getListStart##N(l);                                     \
+        while(p != end) {                                              \
+            stringAdd(&w, &buffer, &n, c(p, buffer, n));               \
+            p++;                                                       \
+            if(p != end) {                                             \
+                stringAdd(&w, &buffer, &n, toString(buffer, n, ", ")); \
+            }                                                          \
+        }                                                              \
+        stringAdd(&w, &buffer, &n, toString(buffer, n, "]"));          \
+        return w;                                                      \
     }
 
 #endif

+ 17 - 14
include/core/Logger.h

@@ -28,38 +28,41 @@ extern LogLevel logLevel;
 
 const char* getShortFileName(const char* s);
 
-check_format(6, 7) void printLog(LogLevel l, const char* file, int line,
-                                 const char* prefix, const char* tag,
-                                 const char* format, ...);
+check_format(6, 7) void printLog(
+    LogLevel l, const char* file, int line, const char* prefix, const char* tag,
+    const char* format, ...);
 
 #if defined(LOG_LEVEL) && LOG_LEVEL >= 1
-#define LOG_ERROR(...)                                                         \
-    printLog(LOG_ERROR, __FILE__, __LINE__, TERMINAL_BRIGHT_RED, "[ERROR] ",   \
-             __VA_ARGS__)
+#define LOG_ERROR(...)                                                  \
+    printLog(                                                           \
+        LOG_ERROR, __FILE__, __LINE__, TERMINAL_BRIGHT_RED, "[ERROR] ", \
+        __VA_ARGS__)
 #else
 #define LOG_ERROR(...)
 #endif
 
 #if defined(LOG_LEVEL) && LOG_LEVEL >= 2
 #define LOG_WARNING(...)                                                       \
-    printLog(LOG_WARNING, __FILE__, __LINE__, TERMINAL_BRIGHT_YELLOW,          \
-             "[WARNING] ", __VA_ARGS__)
+    printLog(                                                                  \
+        LOG_WARNING, __FILE__, __LINE__, TERMINAL_BRIGHT_YELLOW, "[WARNING] ", \
+        __VA_ARGS__)
 #else
 #define LOG_WARNING(...)
 #endif
 
 #if defined(LOG_LEVEL) && LOG_LEVEL >= 3
-#define LOG_INFO(...)                                                          \
-    printLog(LOG_INFO, __FILE__, __LINE__, TERMINAL_BOLD, "[INFO] ",           \
-             __VA_ARGS__)
+#define LOG_INFO(...)                                                        \
+    printLog(                                                                \
+        LOG_INFO, __FILE__, __LINE__, TERMINAL_BOLD, "[INFO] ", __VA_ARGS__)
 #else
 #define LOG_INFO(...)
 #endif
 
 #if defined(LOG_LEVEL) && LOG_LEVEL >= 4
-#define LOG_DEBUG(...)                                                         \
-    printLog(LOG_DEBUG, __FILE__, __LINE__,                                    \
-             TERMINAL_BOLD TERMINAL_BRIGHT_BLACK, "[DEBUG] ", __VA_ARGS__)
+#define LOG_DEBUG(...)                                                      \
+    printLog(                                                               \
+        LOG_DEBUG, __FILE__, __LINE__, TERMINAL_BOLD TERMINAL_BRIGHT_BLACK, \
+        "[DEBUG] ", __VA_ARGS__)
 #else
 #define LOG_DEBUG(...)
 #endif

+ 1 - 1
include/core/Matrix.h

@@ -9,7 +9,7 @@ typedef struct {
 } Matrix;
 
 #define ZERO_MATRIX ((Matrix){0})
-#define UNIT_MATRIX                                                            \
+#define UNIT_MATRIX \
     ((Matrix){{{{1, 0, 0, 0}}, {{0, 1, 0, 0}}, {{0, 0, 1, 0}}, {{0, 0, 0, 1}}}})
 
 Matrix* transposeMatrix(Matrix* m);

+ 2 - 2
include/core/Quaternion.h

@@ -10,8 +10,8 @@ typedef struct {
 #define UNIT_QUATERNION ((Quaternion){{{0.0f, 0.0f, 0.0f, 1.0f}}})
 
 Quaternion* axisAngleQ(Quaternion* q, const Vector3* axis, float angle);
-Quaternion* lerpQ(Quaternion* q, const Quaternion* a, float f,
-                  const Quaternion* b);
+Quaternion* lerpQ(
+    Quaternion* q, const Quaternion* a, float f, const Quaternion* b);
 Quaternion* mulSetQ(Quaternion* q, const Quaternion* other);
 Quaternion* mulQ(Quaternion* q, const Quaternion* a, const Quaternion* b);
 Vector3* mulQV3(Vector3* r, const Quaternion* q, const Vector3* v);

+ 72 - 72
include/core/Queue.h

@@ -7,79 +7,79 @@
 #include "core/Types.h"
 #include "core/Utility.h"
 
-#define QUEUE(T, N)                                                            \
-    typedef struct {                                                           \
-        size_t writeIndex;                                                     \
-        size_t readIndex;                                                      \
-        size_t length;                                                         \
-        size_t capacity;                                                       \
-        T* data;                                                               \
-    } Queue##N;                                                                \
-                                                                               \
-    void initQueue##N(Queue##N* r, size_t capacity);                           \
-    void destroyQueue##N(Queue##N* r);                                         \
-    void pushQueueData##N(Queue##N* r, T data);                                \
-    T* getQueueIndex##N(const Queue##N* r, size_t index);                      \
-    void clearQueue##N(Queue##N* r);                                           \
-    void popQueueData##N(Queue##N* r);                                         \
-    typedef size_t (*ToString##N)(const T* data, char* buffer, size_t n);      \
-    size_t toStringQueue##N(const Queue##N* r, char* buffer, size_t n,         \
-                            ToString##N c);
+#define QUEUE(T, N)                                                       \
+    typedef struct {                                                      \
+        size_t writeIndex;                                                \
+        size_t readIndex;                                                 \
+        size_t length;                                                    \
+        size_t capacity;                                                  \
+        T* data;                                                          \
+    } Queue##N;                                                           \
+                                                                          \
+    void initQueue##N(Queue##N* r, size_t capacity);                      \
+    void destroyQueue##N(Queue##N* r);                                    \
+    void pushQueueData##N(Queue##N* r, T data);                           \
+    T* getQueueIndex##N(const Queue##N* r, size_t index);                 \
+    void clearQueue##N(Queue##N* r);                                      \
+    void popQueueData##N(Queue##N* r);                                    \
+    typedef size_t (*ToString##N)(const T* data, char* buffer, size_t n); \
+    size_t toStringQueue##N(                                              \
+        const Queue##N* r, char* buffer, size_t n, ToString##N c);
 
-#define QUEUE_SOURCE(T, N)                                                     \
-    void initQueue##N(Queue##N* r, size_t capacity) {                          \
-        *r = ((Queue##N){0, 0, 0, capacity, nullptr});                         \
-    }                                                                          \
-                                                                               \
-    void destroyQueue##N(Queue##N* r) {                                        \
-        coreFree(r->data);                                                     \
-        *r = (Queue##N){0};                                                    \
-    }                                                                          \
-                                                                               \
-    void pushQueueData##N(Queue##N* r, T data) {                               \
-        if(r->length >= r->capacity) {                                         \
-            return;                                                            \
-        } else if(r->data == nullptr) {                                        \
-            r->data = coreAllocate(r->capacity * sizeof(T));                   \
-        }                                                                      \
-        r->data[r->writeIndex] = data;                                         \
-        r->writeIndex = (r->writeIndex + 1) % r->capacity;                     \
-        r->length++;                                                           \
-    }                                                                          \
-                                                                               \
-    T* getQueueIndex##N(const Queue##N* r, size_t index) {                     \
-        return r->data + ((index + r->readIndex) % r->capacity);               \
-    }                                                                          \
-                                                                               \
-    void clearQueue##N(Queue##N* r) {                                          \
-        r->writeIndex = 0;                                                     \
-        r->readIndex = 0;                                                      \
-        r->length = 0;                                                         \
-    }                                                                          \
-                                                                               \
-    void popQueueData##N(Queue##N* r) {                                        \
-        assert(r->length > 0);                                                 \
-        r->length--;                                                           \
-        r->readIndex = (r->readIndex + 1) % r->capacity;                       \
-    }                                                                          \
-                                                                               \
-    size_t toStringQueue##N(const Queue##N* r, char* buffer, size_t n,         \
-                            ToString##N c) {                                   \
-        size_t w = 0;                                                          \
-        stringAdd(&w, &buffer, &n, toString(buffer, n, "["));                  \
-        size_t end = r->length;                                                \
-        if(end > 0) {                                                          \
-            end--;                                                             \
-            for(size_t i = 0; i < end; i++) {                                  \
-                stringAdd(&w, &buffer, &n,                                     \
-                          c(getQueueIndex##N(r, i), buffer, n));               \
-                stringAdd(&w, &buffer, &n, toString(buffer, n, ", "));         \
-            }                                                                  \
-            stringAdd(&w, &buffer, &n,                                         \
-                      c(getQueueIndex##N(r, end), buffer, n));                 \
-        }                                                                      \
-        stringAdd(&w, &buffer, &n, toString(buffer, n, "]"));                  \
-        return w;                                                              \
+#define QUEUE_SOURCE(T, N)                                                  \
+    void initQueue##N(Queue##N* r, size_t capacity) {                       \
+        *r = ((Queue##N){0, 0, 0, capacity, nullptr});                      \
+    }                                                                       \
+                                                                            \
+    void destroyQueue##N(Queue##N* r) {                                     \
+        coreFree(r->data);                                                  \
+        *r = (Queue##N){0};                                                 \
+    }                                                                       \
+                                                                            \
+    void pushQueueData##N(Queue##N* r, T data) {                            \
+        if(r->length >= r->capacity) {                                      \
+            return;                                                         \
+        } else if(r->data == nullptr) {                                     \
+            r->data = coreAllocate(r->capacity * sizeof(T));                \
+        }                                                                   \
+        r->data[r->writeIndex] = data;                                      \
+        r->writeIndex = (r->writeIndex + 1) % r->capacity;                  \
+        r->length++;                                                        \
+    }                                                                       \
+                                                                            \
+    T* getQueueIndex##N(const Queue##N* r, size_t index) {                  \
+        return r->data + ((index + r->readIndex) % r->capacity);            \
+    }                                                                       \
+                                                                            \
+    void clearQueue##N(Queue##N* r) {                                       \
+        r->writeIndex = 0;                                                  \
+        r->readIndex = 0;                                                   \
+        r->length = 0;                                                      \
+    }                                                                       \
+                                                                            \
+    void popQueueData##N(Queue##N* r) {                                     \
+        assert(r->length > 0);                                              \
+        r->length--;                                                        \
+        r->readIndex = (r->readIndex + 1) % r->capacity;                    \
+    }                                                                       \
+                                                                            \
+    size_t toStringQueue##N(                                                \
+        const Queue##N* r, char* buffer, size_t n, ToString##N c) {         \
+        size_t w = 0;                                                       \
+        stringAdd(&w, &buffer, &n, toString(buffer, n, "["));               \
+        size_t end = r->length;                                             \
+        if(end > 0) {                                                       \
+            end--;                                                          \
+            for(size_t i = 0; i < end; i++) {                               \
+                stringAdd(                                                  \
+                    &w, &buffer, &n, c(getQueueIndex##N(r, i), buffer, n)); \
+                stringAdd(&w, &buffer, &n, toString(buffer, n, ", "));      \
+            }                                                               \
+            stringAdd(                                                      \
+                &w, &buffer, &n, c(getQueueIndex##N(r, end), buffer, n));   \
+        }                                                                   \
+        stringAdd(&w, &buffer, &n, toString(buffer, n, "]"));               \
+        return w;                                                           \
     }
 
 #endif

+ 11 - 11
include/core/Test.h

@@ -6,7 +6,7 @@
 void finalizeTests(void);
 
 #define TEST_ARGS const char *file, int line
-#define TEST_FUNCTION(name, type)                                              \
+#define TEST_FUNCTION(name, type)                        \
     bool test##name(TEST_ARGS, type wanted, type actual)
 
 TEST_FUNCTION(Int, int);
@@ -21,10 +21,10 @@ bool testFloat(TEST_ARGS, float wanted, float actual, float error);
 bool testNull(TEST_ARGS, const void* p);
 bool testNotNull(TEST_ARGS, const void* p);
 
-#define TEST(wanted, actual, name)                                             \
+#define TEST(wanted, actual, name)                 \
     test##name(__FILE__, __LINE__, wanted, actual)
 
-#define TEST_FLOAT(wanted, actual, error)                                      \
+#define TEST_FLOAT(wanted, actual, error)                \
     testFloat(__FILE__, __LINE__, wanted, actual, error)
 
 #define TEST_BOOL(wanted, actual) TEST(wanted, actual, Bool)
@@ -39,23 +39,23 @@ bool testNotNull(TEST_ARGS, const void* p);
 #define TEST_NOT_NULL(actual) testNotNull(__FILE__, __LINE__, actual)
 
 bool testVectorN(TEST_ARGS, const float* wanted, const float* actual, size_t n);
-#define TEST_VN(wanted, actual, n)                                             \
+#define TEST_VN(wanted, actual, n)                                     \
     testVectorN(__FILE__, __LINE__, (wanted)->data, (actual)->data, n)
-#define TEST_V2(wanted, actual)                                                \
+#define TEST_V2(wanted, actual)                        \
     TEST_VN((Vector2*)(wanted), (Vector2*)(actual), 2)
-#define TEST_V3(wanted, actual)                                                \
+#define TEST_V3(wanted, actual)                        \
     TEST_VN((Vector3*)(wanted), (Vector3*)(actual), 3)
-#define TEST_V4(wanted, actual)                                                \
+#define TEST_V4(wanted, actual)                        \
     TEST_VN((Vector4*)(wanted), (Vector4*)(actual), 4)
 
 bool testIntVectorN(TEST_ARGS, const int* wanted, const int* actual, size_t n);
-#define TEST_IVN(wanted, actual, n)                                            \
+#define TEST_IVN(wanted, actual, n)                                       \
     testIntVectorN(__FILE__, __LINE__, (wanted)->data, (actual)->data, n)
-#define TEST_IV2(wanted, actual)                                               \
+#define TEST_IV2(wanted, actual)                              \
     TEST_IVN((IntVector2*)(wanted), (IntVector2*)(actual), 2)
-#define TEST_IV3(wanted, actual)                                               \
+#define TEST_IV3(wanted, actual)                              \
     TEST_IVN((IntVector3*)(wanted), (IntVector3*)(actual), 3)
-#define TEST_IV4(wanted, actual)                                               \
+#define TEST_IV4(wanted, actual)                              \
     TEST_IVN((IntVector4*)(wanted), (IntVector4*)(actual), 4)
 
 #endif

+ 20 - 20
include/core/Utility.h

@@ -48,29 +48,29 @@ void coreFree(void* p);
 bool sleepNanos(i64 nanos);
 i64 getNanos(void);
 
-#define swap(a, b)                                                             \
-    do {                                                                       \
-        auto aPointer = (a);                                                   \
-        auto bPointer = (b);                                                   \
-        auto tmp = *aPointer;                                                  \
-        *aPointer = *bPointer;                                                 \
-        *bPointer = tmp;                                                       \
+#define swap(a, b)             \
+    do {                       \
+        auto aPointer = (a);   \
+        auto bPointer = (b);   \
+        auto tmp = *aPointer;  \
+        *aPointer = *bPointer; \
+        *bPointer = tmp;       \
     } while(0)
 
 #define BUBBLE_SORT(type, Type) void bubbleSort##Type(type* data, size_t n);
-#define BUBBLE_SORT_SOURCE(type, Type, greaterThan)                            \
-    void bubbleSort##Type(type* data, size_t n) {                              \
-        bool swapped = true;                                                   \
-        while(swapped && n > 0) {                                              \
-            swapped = false;                                                   \
-            n--;                                                               \
-            for(size_t i = 0; i < n; i++) {                                    \
-                if(greaterThan(data[i], data[i + 1])) {                        \
-                    swap(data + i, data + i + 1);                              \
-                    swapped = true;                                            \
-                }                                                              \
-            }                                                                  \
-        }                                                                      \
+#define BUBBLE_SORT_SOURCE(type, Type, greaterThan)     \
+    void bubbleSort##Type(type* data, size_t n) {       \
+        bool swapped = true;                            \
+        while(swapped && n > 0) {                       \
+            swapped = false;                            \
+            n--;                                        \
+            for(size_t i = 0; i < n; i++) {             \
+                if(greaterThan(data[i], data[i + 1])) { \
+                    swap(data + i, data + i + 1);       \
+                    swapped = true;                     \
+                }                                       \
+            }                                           \
+        }                                               \
     }
 
 #endif