From 35c9323de66b049cecac3f12474dca71272c3a95 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 30 Sep 2024 00:15:04 +0300 Subject: [PATCH] public: make vec3_origin and identity matrix inlined --- public/matrixlib.c | 15 --------------- public/xash3d_mathlib.c | 1 - public/xash3d_mathlib.h | 20 +++++++++++++++----- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/public/matrixlib.c b/public/matrixlib.c index fc471862..2926ce91 100644 --- a/public/matrixlib.c +++ b/public/matrixlib.c @@ -19,13 +19,6 @@ GNU General Public License for more details. #include "com_model.h" #include "xash3d_mathlib.h" -const matrix3x4 m_matrix3x4_identity = -{ -{ 1, 0, 0, 0 }, // PITCH [forward], org[0] -{ 0, 1, 0, 0 }, // YAW [right] , org[1] -{ 0, 0, 1, 0 }, // ROLL [up] , org[2] -}; - /* ======================================================================== @@ -225,14 +218,6 @@ void Matrix3x4_TransformAABB( const matrix3x4 world, const vec3_t mins, const ve VectorAdd( worldCenter, worldExtents, absmax ); } -const matrix4x4 m_matrix4x4_identity = -{ -{ 1, 0, 0, 0 }, // PITCH -{ 0, 1, 0, 0 }, // YAW -{ 0, 0, 1, 0 }, // ROLL -{ 0, 0, 0, 1 }, // ORIGIN -}; - /* ======================================================================== diff --git a/public/xash3d_mathlib.c b/public/xash3d_mathlib.c index ae7dfc3f..6a608887 100644 --- a/public/xash3d_mathlib.c +++ b/public/xash3d_mathlib.c @@ -25,7 +25,6 @@ GNU General Public License for more details. static const word hull_table[] = { 2, 4, 6, 8, 12, 16, 18, 24, 28, 32, 36, 40, 48, 54, 56, 60, 64, 72, 80, 112, 120, 128, 140, 176 }; -const vec3_t vec3_origin = { 0, 0, 0 }; const int boxpnt[6][4] = { { 0, 4, 6, 2 }, // +X diff --git a/public/xash3d_mathlib.h b/public/xash3d_mathlib.h index eec8adc5..afe02d9e 100644 --- a/public/xash3d_mathlib.h +++ b/public/xash3d_mathlib.h @@ -139,11 +139,21 @@ CONSTANTS GLOBALS =========================== */ -extern const vec3_t vec3_origin; -extern const int boxpnt[6][4]; -extern const matrix3x4 m_matrix3x4_identity; -extern const matrix4x4 m_matrix4x4_identity; -extern const float m_bytenormals[NUMVERTEXNORMALS][3]; +// a1ba: we never return pointers to these globals +// so help compiler optimize constants away +#define vec3_origin ((vec3_t){ 0.0f, 0.0f, 0.0f }) +#define m_matrix3x4_identity ((matrix3x4) { \ + { 1.0f, 0.0f, 0.0f, 0.0f }, \ + { 0.0f, 1.0f, 0.0f, 0.0f }, \ + { 0.0f, 0.0f, 1.0f, 0.0f }} ) +#define m_matrix4x4_identity ((matrix4x4) { \ + { 1.0f, 0.0f, 0.0f, 0.0f }, \ + { 0.0f, 1.0f, 0.0f, 0.0f }, \ + { 0.0f, 0.0f, 1.0f, 0.0f }, \ + { 0.0f, 0.0f, 0.0f, 1.0f }} ) + +extern const int boxpnt[6][4]; +extern const float m_bytenormals[NUMVERTEXNORMALS][3]; /*