Optimize some vector functions, replace vec_copy with macro

This commit is contained in:
8dcc 2023-07-29 17:34:18 +02:00
parent 67f4c5ed88
commit 762368d75f
2 changed files with 19 additions and 9 deletions

View File

@ -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);

View File

@ -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) {