General: Mark file-scope constexpr variables as inline

Allows the compiler to unify all usages of these constants down to a
single address if they're ODR used, rather than creating an individual
copy within each translation unit.

Unfortunately all file-scope variables don't have inline implied for
them by default (only for static class member variables).

Shrinks the size of the emitted binary a little bit.
This commit is contained in:
Lioncash 2020-04-19 03:16:34 -04:00
parent 6c46735ab1
commit 5520001117
5 changed files with 29 additions and 29 deletions

View File

@ -309,8 +309,8 @@ public:
return max[idx - 3];
}
};
constexpr CAABox skInvertedBox;
constexpr CAABox skNullBox(CVector3f{}, CVector3f{});
constexpr inline CAABox skInvertedBox;
constexpr inline CAABox skNullBox(CVector3f{}, CVector3f{});
[[nodiscard]] inline bool operator==(const CAABox& left, const CAABox& right) {
return (left.min == right.min && left.max == right.max);

View File

@ -310,18 +310,18 @@ constexpr CVector4f& CVector4f::operator=(const CColor& other) {
return *this;
}
constexpr CColor skRed(1.f, 0.f, 0.f, 1.f);
constexpr CColor skBlack(0.f, 0.f, 0.f, 1.f);
constexpr CColor skBlue(0.f, 0.f, 1.f, 1.f);
constexpr CColor skCyan(0.f, 1.f, 1.f, 1.f);
constexpr CColor skGreen(0.f, 1.f, 0.f, 1.f);
constexpr CColor skGrey(0.5f, 0.5f, 0.5f, 1.f);
constexpr CColor skMagenta(1.f, 0.f, 1.f, 1.f);
constexpr CColor skOrange(1.f, 0.43f, 0.f, 1.f);
constexpr CColor skPurple(0.63f, 0.f, 1.f, 1.f);
constexpr CColor skYellow(1.f, 1.f, 0.f, 1.f);
constexpr CColor skWhite(1.f, 1.f, 1.f, 1.f);
constexpr CColor skClear(0.f, 0.f, 0.f, 0.f);
constexpr inline CColor skRed(1.f, 0.f, 0.f, 1.f);
constexpr inline CColor skBlack(0.f, 0.f, 0.f, 1.f);
constexpr inline CColor skBlue(0.f, 0.f, 1.f, 1.f);
constexpr inline CColor skCyan(0.f, 1.f, 1.f, 1.f);
constexpr inline CColor skGreen(0.f, 1.f, 0.f, 1.f);
constexpr inline CColor skGrey(0.5f, 0.5f, 0.5f, 1.f);
constexpr inline CColor skMagenta(1.f, 0.f, 1.f, 1.f);
constexpr inline CColor skOrange(1.f, 0.43f, 0.f, 1.f);
constexpr inline CColor skPurple(0.63f, 0.f, 1.f, 1.f);
constexpr inline CColor skYellow(1.f, 1.f, 0.f, 1.f);
constexpr inline CColor skWhite(1.f, 1.f, 1.f, 1.f);
constexpr inline CColor skClear(0.f, 0.f, 0.f, 0.f);
[[nodiscard]] inline CColor operator+(float lhs, const CColor& rhs) {
return CColor(simd<float>(lhs) + rhs.mSimd).Clamp();

View File

@ -207,9 +207,9 @@ public:
[[nodiscard]] simd<float>::reference x() { return mSimd[0]; }
[[nodiscard]] simd<float>::reference y() { return mSimd[1]; }
};
constexpr CVector2f skOne2f(1.f);
constexpr CVector2f skNegOne2f(-1.f);
constexpr CVector2f skZero2f(0.f);
constexpr inline CVector2f skOne2f(1.f);
constexpr inline CVector2f skNegOne2f(-1.f);
constexpr inline CVector2f skZero2f(0.f);
[[nodiscard]] inline CVector2f operator+(float lhs, const CVector2f& rhs) { return zeus::simd<float>(lhs) + rhs.mSimd; }

View File

@ -79,7 +79,7 @@ public:
};
inline CVector3f::CVector3f(const CVector3d& vec) : mSimd(vec.mSimd) {}
constexpr CVector3d skZero3d(0.0);
constexpr inline CVector3d skZero3d(0.0);
[[nodiscard]] inline CVector3d operator+(double lhs, const CVector3d& rhs) {
return zeus::simd<double>(lhs) + rhs.mSimd;

View File

@ -209,17 +209,17 @@ public:
[[nodiscard]] static inline CVector3f degToRad(const CVector3f& deg);
};
constexpr CVector3f skOne3f(1.f);
constexpr CVector3f skNegOne3f(-1.f);
constexpr CVector3f skZero3f(0.f);
constexpr CVector3f skForward(0.f, 1.f, 0.f);
constexpr CVector3f skBack(0.f, -1.f, 0.f);
constexpr CVector3f skLeft(-1.f, 0.f, 0.f);
constexpr CVector3f skRight(1.f, 0.f, 0.f);
constexpr CVector3f skUp(0.f, 0.f, 1.f);
constexpr CVector3f skDown(0.f, 0.f, -1.f);
constexpr CVector3f skRadToDegVec(180.f / M_PIF);
constexpr CVector3f skDegToRadVec(M_PIF / 180.f);
constexpr inline CVector3f skOne3f(1.f);
constexpr inline CVector3f skNegOne3f(-1.f);
constexpr inline CVector3f skZero3f(0.f);
constexpr inline CVector3f skForward(0.f, 1.f, 0.f);
constexpr inline CVector3f skBack(0.f, -1.f, 0.f);
constexpr inline CVector3f skLeft(-1.f, 0.f, 0.f);
constexpr inline CVector3f skRight(1.f, 0.f, 0.f);
constexpr inline CVector3f skUp(0.f, 0.f, 1.f);
constexpr inline CVector3f skDown(0.f, 0.f, -1.f);
constexpr inline CVector3f skRadToDegVec(180.f / M_PIF);
constexpr inline CVector3f skDegToRadVec(M_PIF / 180.f);
[[nodiscard]] inline CVector3f operator+(float lhs, const CVector3f& rhs) { return zeus::simd<float>(lhs) + rhs.mSimd; }