diff options
author | Lizzy Fleckenstein <lizzy@vlhl.dev> | 2024-06-23 20:07:44 +0200 |
---|---|---|
committer | Lizzy Fleckenstein <lizzy@vlhl.dev> | 2024-06-23 20:07:44 +0200 |
commit | 3be565f4e8ee1610aae5b0945185b4012f026c87 (patch) | |
tree | e24cb1320ea236c90bb3c81a1398677c1c9c8177 /include/vec.h | |
parent | bf3c2eb3509076251b16ded45f8ceb4be60ae98b (diff) |
implement movement
Signed-off-by: Lizzy Fleckenstein <lizzy@vlhl.dev>
Diffstat (limited to 'include/vec.h')
-rw-r--r-- | include/vec.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/include/vec.h b/include/vec.h index ce1b921..d2d9e31 100644 --- a/include/vec.h +++ b/include/vec.h @@ -9,7 +9,7 @@ #include <stdbool.h> #include "ser.h" -#define VECFN static __attribute__((unused)) +#define VECFN [[maybe_unused]] static #define MIN(X, Y) ((X) < (Y) ? (X) : (Y)) #define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) @@ -22,12 +22,16 @@ typedef struct { S x; S y; } V; \ typedef struct { V pos; uvec2 size; } B; \ VECFN V V##_add(V a, V b) { return (V) { a.x+b.x, a.y+b.y }; } \ VECFN V V##_sub(V a, V b) { return (V) { a.x-b.x, a.y-b.y }; } \ +VECFN V V##_mul(V v, S s) { return (V) { v.x*s, v.y*s }; } \ +VECFN V V##_div(V v, S s) { return (V) { v.x/s, v.y/s }; } \ VECFN uvec2 V##_chksub(V a, V b) { return (uvec2) { CHKSUB(a.x, b.x), CHKSUB(a.y, b.y) }; } \ VECFN V V##_min(V a, V b) { return (V) { MIN(a.x, b.x), MIN(a.y, b.y) }; } \ VECFN V V##_max(V a, V b) { return (V) { MAX(a.x, b.x), MAX(a.y, b.y) }; } \ VECFN bool V##_eq(V a, V b) { return a.x == b.x && a.y == b.y; } \ VECFN bool V##_le(V a, V b) { return a.x <= b.x && a.y <= b.y; } \ VECFN bool V##_lt(V a, V b) { return a.x < b.x && a.y < b.y; } \ +VECFN V V##_zero() { return (V) { 0, 0 }; } \ +VECFN bool V##_iszero(V v) { return V##_eq(v, V##_zero()); } \ VECFN void ser_##V(strbuf *w, V v) { ser_##SER(w, v.x); ser_##SER(w, v.y); } \ VECFN bool deser_##V(str *r, V *v) { return deser_##SER(r, &v->x) && deser_##SER(r, &v->y); } \ VECFN void ser_##B(strbuf *w, B b) { ser_##V(w, b.pos); ser_uvec2(w, b.size); } \ |