From 762368d75fee3acab0472470f8e9a7e32de5e3c6 Mon Sep 17 00:00:00 2001 From: 8dcc <8dcc.git@gmail.com> Date: Sat, 29 Jul 2023 17:34:18 +0200 Subject: [PATCH] Optimize some vector functions, replace vec_copy with macro --- src/include/util.h | 6 +++++- src/util.c | 22 ++++++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/include/util.h b/src/include/util.h index 02d2070..56b851f 100644 --- a/src/include/util.h +++ b/src/include/util.h @@ -22,6 +22,11 @@ typedef struct { #define gl_drawline_points(p0, p1, w, col) \ gl_drawline(p0[0], p0[1], p1[0], p1[1], w, col); +#define vec_copy(dst, src) \ + dst.x = src.x; \ + dst.y = src.y; \ + dst.z = src.z; + /*----------------------------------------------------------------------------*/ cl_entity_t* get_player(int ent_idx); @@ -31,7 +36,6 @@ bool is_friend(cl_entity_t* ent); char* get_name(int ent_idx); game_id get_cur_game(void); vec3_t vec3(float x, float y, float z); -void vec_copy(vec3_t* dst, const vec3_t* src); vec3_t vec_add(vec3_t a, vec3_t b); vec3_t vec_sub(vec3_t a, vec3_t b); bool vec_is_zero(vec3_t v); diff --git a/src/util.c b/src/util.c index 0a53680..0cfa17c 100644 --- a/src/util.c +++ b/src/util.c @@ -100,18 +100,24 @@ vec3_t vec3(float x, float y, float z) { return ret; } -void vec_copy(vec3_t* dst, const vec3_t* src) { - dst->x = src->x; - dst->y = src->y; - dst->z = src->z; -} - vec3_t vec_add(vec3_t a, vec3_t b) { - return vec3(a.x + b.x, a.y + b.y, a.z + b.z); + vec3_t ret; + + ret.x = a.x + b.x; + ret.y = a.y + b.y; + ret.z = a.z + b.z; + + return ret; } vec3_t vec_sub(vec3_t a, vec3_t b) { - return vec3(a.x - b.x, a.y - b.y, a.z - b.z); + vec3_t ret; + + ret.x = a.x - b.x; + ret.y = a.y - b.y; + ret.z = a.z - b.z; + + return ret; } bool vec_is_zero(vec3_t v) {