From 117c4e688649c50fd8b4d42c8f0ee065a71d43e5 Mon Sep 17 00:00:00 2001 From: smilediver Date: Sat, 14 Sep 2024 03:52:46 +0300 Subject: [PATCH] Math: remove and replace GP_ASSERT with AX_ASSERT (#2143) --- core/base/Macros.h | 2 -- core/math/Mat4.cpp | 66 ++++++++++++++++++++-------------------- core/math/Mat4.h | 6 ++-- core/math/MathUtil.cpp | 4 +-- core/math/Quaternion.cpp | 18 +++++------ core/math/Quaternion.h | 4 +-- core/math/Vec2.cpp | 10 +++--- core/math/Vec2.h | 2 +- core/math/Vec3.cpp | 12 ++++---- core/math/Vec3.h | 2 +- core/math/Vec4.cpp | 10 +++--- core/math/Vec4.h | 2 +- 12 files changed, 68 insertions(+), 70 deletions(-) diff --git a/core/base/Macros.h b/core/base/Macros.h index 9c68ff029880..3b2e90463f24 100644 --- a/core/base/Macros.h +++ b/core/base/Macros.h @@ -59,8 +59,6 @@ extern bool AX_DLL ax_assert_script_compatible(const char* msg); # define AXASSERT(cond, msg) # endif -# define GP_ASSERT(cond) AXASSERT(cond, "") - // FIXME:: Backward compatible # define CCAssert AXASSERT #endif // AXASSERT diff --git a/core/math/Mat4.cpp b/core/math/Mat4.cpp index cefebca68d5d..72ab74acc1eb 100644 --- a/core/math/Mat4.cpp +++ b/core/math/Mat4.cpp @@ -54,7 +54,7 @@ void Mat4::createLookAt(float eyePositionX, float upZ, Mat4* dst) { - GP_ASSERT(dst); + AX_ASSERT(dst); Vec3 eye(eyePositionX, eyePositionY, eyePositionZ); Vec3 target(targetPositionX, targetPositionY, targetPositionZ); @@ -96,8 +96,8 @@ void Mat4::createLookAt(float eyePositionX, void Mat4::createPerspective(float fieldOfView, float aspectRatio, float zNearPlane, float zFarPlane, Mat4* dst) { - GP_ASSERT(dst); - GP_ASSERT(zFarPlane != zNearPlane); + AX_ASSERT(dst); + AX_ASSERT(zFarPlane != zNearPlane); float f_n = 1.0f / (zFarPlane - zNearPlane); float theta = MATH_DEG_TO_RAD(fieldOfView) * 0.5f; @@ -108,12 +108,12 @@ void Mat4::createPerspective(float fieldOfView, float aspectRatio, float zNearPl return; } float divisor = std::tan(theta); - GP_ASSERT(divisor); + AX_ASSERT(divisor); float factor = 1.0f / divisor; memset(dst->m, 0, sizeof(dst->m)); - GP_ASSERT(aspectRatio); + AX_ASSERT(aspectRatio); dst->m[0] = (1.0f / aspectRatio) * factor; dst->m[5] = factor; dst->m[10] = (-(zFarPlane + zNearPlane)) * f_n; @@ -142,10 +142,10 @@ void Mat4::createOrthographicOffCenter(float left, float zFarPlane, Mat4* dst) { - GP_ASSERT(dst); - GP_ASSERT(right != left); - GP_ASSERT(top != bottom); - GP_ASSERT(zFarPlane != zNearPlane); + AX_ASSERT(dst); + AX_ASSERT(right != left); + AX_ASSERT(top != bottom); + AX_ASSERT(zFarPlane != zNearPlane); memset(dst->m, 0, sizeof(dst->m)); dst->m[0] = 2 / (right - left); @@ -237,7 +237,7 @@ void Mat4::createBillboardHelper(const Vec3& objectPosition, void Mat4::createScale(const Vec3& scale, Mat4* dst) { - GP_ASSERT(dst); + AX_ASSERT(dst); dst->setIdentity(); @@ -248,7 +248,7 @@ void Mat4::createScale(const Vec3& scale, Mat4* dst) void Mat4::createScale(float xScale, float yScale, float zScale, Mat4* dst) { - GP_ASSERT(dst); + AX_ASSERT(dst); dst->setIdentity(); @@ -259,7 +259,7 @@ void Mat4::createScale(float xScale, float yScale, float zScale, Mat4* dst) void Mat4::createRotation(const Quaternion& q, Mat4* dst) { - GP_ASSERT(dst); + AX_ASSERT(dst); float x2 = q.x + q.x; float y2 = q.y + q.y; @@ -298,7 +298,7 @@ void Mat4::createRotation(const Quaternion& q, Mat4* dst) void Mat4::createRotation(const Vec3& axis, float angle, Mat4* dst) { - GP_ASSERT(dst); + AX_ASSERT(dst); float x = axis.x; float y = axis.y; @@ -357,7 +357,7 @@ void Mat4::createRotation(const Vec3& axis, float angle, Mat4* dst) void Mat4::createRotationX(float angle, Mat4* dst) { - GP_ASSERT(dst); + AX_ASSERT(dst); dst->setIdentity(); @@ -372,7 +372,7 @@ void Mat4::createRotationX(float angle, Mat4* dst) void Mat4::createRotationY(float angle, Mat4* dst) { - GP_ASSERT(dst); + AX_ASSERT(dst); dst->setIdentity(); @@ -387,7 +387,7 @@ void Mat4::createRotationY(float angle, Mat4* dst) void Mat4::createRotationZ(float angle, Mat4* dst) { - GP_ASSERT(dst); + AX_ASSERT(dst); dst->setIdentity(); @@ -402,7 +402,7 @@ void Mat4::createRotationZ(float angle, Mat4* dst) void Mat4::createTranslation(const Vec3& translation, Mat4* dst) { - GP_ASSERT(dst); + AX_ASSERT(dst); dst->setIdentity(); @@ -413,7 +413,7 @@ void Mat4::createTranslation(const Vec3& translation, Mat4* dst) void Mat4::createTranslation(float xTranslation, float yTranslation, float zTranslation, Mat4* dst) { - GP_ASSERT(dst); + AX_ASSERT(dst); dst->setIdentity(); @@ -429,7 +429,7 @@ void Mat4::add(float scalar) void Mat4::add(float scalar, Mat4* dst) { - GP_ASSERT(dst); + AX_ASSERT(dst); MathUtil::addMatrix(m, scalar, dst->m); } @@ -440,7 +440,7 @@ void Mat4::add(const Mat4& mat) void Mat4::add(const Mat4& m1, const Mat4& m2, Mat4* dst) { - GP_ASSERT(dst); + AX_ASSERT(dst); MathUtil::addMatrix(m1.m, m2.m, dst->m); } @@ -588,7 +588,7 @@ void Mat4::getTranslation(Vec3* translation) const void Mat4::getUpVector(Vec3* dst) const { - GP_ASSERT(dst); + AX_ASSERT(dst); dst->x = m[4]; dst->y = m[5]; @@ -597,7 +597,7 @@ void Mat4::getUpVector(Vec3* dst) const void Mat4::getDownVector(Vec3* dst) const { - GP_ASSERT(dst); + AX_ASSERT(dst); dst->x = -m[4]; dst->y = -m[5]; @@ -606,7 +606,7 @@ void Mat4::getDownVector(Vec3* dst) const void Mat4::getLeftVector(Vec3* dst) const { - GP_ASSERT(dst); + AX_ASSERT(dst); dst->x = -m[0]; dst->y = -m[1]; @@ -615,7 +615,7 @@ void Mat4::getLeftVector(Vec3* dst) const void Mat4::getRightVector(Vec3* dst) const { - GP_ASSERT(dst); + AX_ASSERT(dst); dst->x = m[0]; dst->y = m[1]; @@ -624,7 +624,7 @@ void Mat4::getRightVector(Vec3* dst) const void Mat4::getForwardVector(Vec3* dst) const { - GP_ASSERT(dst); + AX_ASSERT(dst); dst->x = -m[8]; dst->y = -m[9]; @@ -633,7 +633,7 @@ void Mat4::getForwardVector(Vec3* dst) const void Mat4::getBackVector(Vec3* dst) const { - GP_ASSERT(dst); + AX_ASSERT(dst); dst->x = m[8]; dst->y = m[9]; @@ -713,7 +713,7 @@ void Mat4::multiply(float scalar, Mat4* dst) const void Mat4::multiply(const Mat4& m, float scalar, Mat4* dst) { - GP_ASSERT(dst); + AX_ASSERT(dst); MathUtil::multiplyMatrix(m.m, scalar, dst->m); } @@ -724,7 +724,7 @@ void Mat4::multiply(const Mat4& mat) void Mat4::multiply(const Mat4& m1, const Mat4& m2, Mat4* dst) { - GP_ASSERT(dst); + AX_ASSERT(dst); MathUtil::multiplyMatrix(m1.m, m2.m, dst->m); } @@ -839,13 +839,13 @@ void Mat4::subtract(const Mat4& mat) void Mat4::subtract(const Mat4& m1, const Mat4& m2, Mat4* dst) { - GP_ASSERT(dst); + AX_ASSERT(dst); MathUtil::subtractMatrix(m1.m, m2.m, dst->m); } void Mat4::transformVector(Vec3* vector) const { - GP_ASSERT(vector); + AX_ASSERT(vector); transformVector(vector->x, vector->y, vector->z, 0.0f, vector); } @@ -856,20 +856,20 @@ void Mat4::transformVector(const Vec3& vector, Vec3* dst) const void Mat4::transformVector(float x, float y, float z, float w, Vec3* dst) const { - GP_ASSERT(dst); + AX_ASSERT(dst); MathUtil::transformVec4(m, x, y, z, w, reinterpret_cast(dst)); } void Mat4::transformVector(Vec4* vector) const { - GP_ASSERT(vector); + AX_ASSERT(vector); transformVector(*vector, vector); } void Mat4::transformVector(const Vec4& vector, Vec4* dst) const { - GP_ASSERT(dst); + AX_ASSERT(dst); MathUtil::transformVec4(m, reinterpret_cast(&vector), reinterpret_cast(dst)); } diff --git a/core/math/Mat4.h b/core/math/Mat4.h index cbb0a92c6533..4d064e0e1485 100644 --- a/core/math/Mat4.h +++ b/core/math/Mat4.h @@ -772,7 +772,7 @@ class AX_DLL Mat4 */ void set(const float* mat) { - GP_ASSERT(mat); + AX_ASSERT(mat); memcpy(m, mat, sizeof(m)); } @@ -821,7 +821,7 @@ class AX_DLL Mat4 */ inline void transformPoint(Vec3* point) const { - GP_ASSERT(point); + AX_ASSERT(point); transformVector(point->x, point->y, point->z, 1.0f, point); } @@ -834,7 +834,7 @@ class AX_DLL Mat4 */ inline void transformPoint(const Vec3& point, Vec3* dst) const { - GP_ASSERT(dst); + AX_ASSERT(dst); transformVector(point.x, point.y, point.z, 1.0f, dst); } diff --git a/core/math/MathUtil.cpp b/core/math/MathUtil.cpp index 805c8dfb331b..f2ca2ce8dd1d 100644 --- a/core/math/MathUtil.cpp +++ b/core/math/MathUtil.cpp @@ -40,7 +40,7 @@ NS_AX_MATH_BEGIN void MathUtil::smooth(float* x, float target, float elapsedTime, float responseTime) { - GP_ASSERT(x); + AX_ASSERT(x); if (elapsedTime > 0) { @@ -50,7 +50,7 @@ void MathUtil::smooth(float* x, float target, float elapsedTime, float responseT void MathUtil::smooth(float* x, float target, float elapsedTime, float riseTime, float fallTime) { - GP_ASSERT(x); + AX_ASSERT(x); if (elapsedTime > 0) { diff --git a/core/math/Quaternion.cpp b/core/math/Quaternion.cpp index 845a04c5ecdf..bf8bef48a666 100644 --- a/core/math/Quaternion.cpp +++ b/core/math/Quaternion.cpp @@ -106,7 +106,7 @@ void Quaternion::multiply(const Quaternion& q) void Quaternion::multiply(const Quaternion& q1, const Quaternion& q2, Quaternion* dst) { - GP_ASSERT(dst); + AX_ASSERT(dst); float x = q1.w * q2.x + q1.x * q2.w + q1.y * q2.z - q1.z * q2.y; float y = q1.w * q2.y - q1.x * q2.z + q1.y * q2.w + q1.z * q2.x; @@ -153,7 +153,7 @@ void Quaternion::set(const Mat4& m) float Quaternion::toAxisAngle(Vec3* axis) const { - GP_ASSERT(axis); + AX_ASSERT(axis); Quaternion q(x, y, z, w); q.normalize(); @@ -167,8 +167,8 @@ float Quaternion::toAxisAngle(Vec3* axis) const void Quaternion::lerp(const Quaternion& q1, const Quaternion& q2, float t, Quaternion* dst) { - GP_ASSERT(dst); - GP_ASSERT(!(t < 0.0f || t > 1.0f)); + AX_ASSERT(dst); + AX_ASSERT(!(t < 0.0f || t > 1.0f)); if (t == 0.0f) { @@ -191,7 +191,7 @@ void Quaternion::lerp(const Quaternion& q1, const Quaternion& q2, float t, Quate void Quaternion::slerp(const Quaternion& q1, const Quaternion& q2, float t, Quaternion* dst) { - GP_ASSERT(dst); + AX_ASSERT(dst); slerp(q1.x, q1.y, q1.z, q1.w, q2.x, q2.y, q2.z, q2.w, t, &dst->x, &dst->y, &dst->z, &dst->w); } @@ -202,7 +202,7 @@ void Quaternion::squad(const Quaternion& q1, float t, Quaternion* dst) { - GP_ASSERT(!(t < 0.0f || t > 1.0f)); + AX_ASSERT(!(t < 0.0f || t > 1.0f)); Quaternion dstQ(0.0f, 0.0f, 0.0f, 1.0f); Quaternion dstS(0.0f, 0.0f, 0.0f, 1.0f); @@ -230,8 +230,8 @@ void Quaternion::slerp(float q1x, // It contains no division operations, no trig, no inverse trig // and no sqrt. Not only does this code tolerate small constraint // errors in the input quaternions, it actually corrects for them. - GP_ASSERT(dstx && dsty && dstz && dstw); - GP_ASSERT(!(t < 0.0f || t > 1.0f)); + AX_ASSERT(dstx && dsty && dstz && dstw); + AX_ASSERT(!(t < 0.0f || t > 1.0f)); if (t == 0.0f) { @@ -325,7 +325,7 @@ void Quaternion::slerp(float q1x, void Quaternion::slerpForSquad(const Quaternion& q1, const Quaternion& q2, float t, Quaternion* dst) { - GP_ASSERT(dst); + AX_ASSERT(dst); // cos(omega) = q1 * q2; // slerp(q1, q2, t) = (q1*sin((1-t)*omega) + q2*sin(t*omega))/sin(omega); diff --git a/core/math/Quaternion.h b/core/math/Quaternion.h index 12af42a9efa3..21349a807100 100644 --- a/core/math/Quaternion.h +++ b/core/math/Quaternion.h @@ -179,7 +179,7 @@ class AX_DLL Quaternion */ static void createFromAxisAngle(const Vec3& axis, float angle, Quaternion* dst) { - GP_ASSERT(dst); + AX_ASSERT(dst); float halfAngle = angle * 0.5f; float sinHalfAngle = sinf(halfAngle); @@ -281,7 +281,7 @@ class AX_DLL Quaternion */ constexpr void set(float* array) { - GP_ASSERT(array); + AX_ASSERT(array); x = array[0]; y = array[1]; diff --git a/core/math/Vec2.cpp b/core/math/Vec2.cpp index e5a545dc9501..3d451fe45352 100644 --- a/core/math/Vec2.cpp +++ b/core/math/Vec2.cpp @@ -98,7 +98,7 @@ float Vec2::angle(const Vec2& v1, const Vec2& v2) void Vec2::add(const Vec2& v1, const Vec2& v2, Vec2* dst) { - GP_ASSERT(dst); + AX_ASSERT(dst); dst->x = v1.x + v2.x; dst->y = v1.y + v2.y; @@ -106,7 +106,7 @@ void Vec2::add(const Vec2& v1, const Vec2& v2, Vec2* dst) void Vec2::clamp(const Vec2& min, const Vec2& max) { - GP_ASSERT(!(min.x > max.x || min.y > max.y)); + AX_ASSERT(!(min.x > max.x || min.y > max.y)); // Clamp the x value. if (x < min.x) @@ -123,8 +123,8 @@ void Vec2::clamp(const Vec2& min, const Vec2& max) void Vec2::clamp(const Vec2& v, const Vec2& min, const Vec2& max, Vec2* dst) { - GP_ASSERT(dst); - GP_ASSERT(!(min.x > max.x || min.y > max.y)); + AX_ASSERT(dst); + AX_ASSERT(!(min.x > max.x || min.y > max.y)); // Clamp the x value. dst->x = v.x; @@ -206,7 +206,7 @@ void Vec2::rotate(const Vec2& point, float angle) void Vec2::subtract(const Vec2& v1, const Vec2& v2, Vec2* dst) { - GP_ASSERT(dst); + AX_ASSERT(dst); dst->x = v1.x - v2.x; dst->y = v1.y - v2.y; diff --git a/core/math/Vec2.h b/core/math/Vec2.h index 8099b2af161f..d564fb263e0f 100644 --- a/core/math/Vec2.h +++ b/core/math/Vec2.h @@ -326,7 +326,7 @@ class AX_DLL Vec2 */ constexpr void set(const float* array) { - GP_ASSERT(array); + AX_ASSERT(array); x = array[0]; y = array[1]; diff --git a/core/math/Vec3.cpp b/core/math/Vec3.cpp index db7b96899c06..60c9235eda99 100644 --- a/core/math/Vec3.cpp +++ b/core/math/Vec3.cpp @@ -60,7 +60,7 @@ float Vec3::angle(const Vec3& v1, const Vec3& v2) void Vec3::add(const Vec3& v1, const Vec3& v2, Vec3* dst) { - GP_ASSERT(dst); + AX_ASSERT(dst); dst->x = v1.x + v2.x; dst->y = v1.y + v2.y; @@ -69,7 +69,7 @@ void Vec3::add(const Vec3& v1, const Vec3& v2, Vec3* dst) void Vec3::clamp(const Vec3& min, const Vec3& max) { - GP_ASSERT(!(min.x > max.x || min.y > max.y || min.z > max.z)); + AX_ASSERT(!(min.x > max.x || min.y > max.y || min.z > max.z)); // Clamp the x value. if (x < min.x) @@ -92,8 +92,8 @@ void Vec3::clamp(const Vec3& min, const Vec3& max) void Vec3::clamp(const Vec3& v, const Vec3& min, const Vec3& max, Vec3* dst) { - GP_ASSERT(dst); - GP_ASSERT(!(min.x > max.x || min.y > max.y || min.z > max.z)); + AX_ASSERT(dst); + AX_ASSERT(!(min.x > max.x || min.y > max.y || min.z > max.z)); // Clamp the x value. dst->x = v.x; @@ -124,7 +124,7 @@ void Vec3::cross(const Vec3& v) void Vec3::cross(const Vec3& v1, const Vec3& v2, Vec3* dst) { - GP_ASSERT(dst); + AX_ASSERT(dst); // NOTE: This code assumes Vec3 struct members are contiguous floats in memory. // We might want to revisit this (and other areas of code that make this assumption) @@ -187,7 +187,7 @@ Vec3 Vec3::getNormalized() const void Vec3::subtract(const Vec3& v1, const Vec3& v2, Vec3* dst) { - GP_ASSERT(dst); + AX_ASSERT(dst); dst->x = v1.x - v2.x; dst->y = v1.y - v2.y; diff --git a/core/math/Vec3.h b/core/math/Vec3.h index 9e13b9c0724e..014c96f05c06 100644 --- a/core/math/Vec3.h +++ b/core/math/Vec3.h @@ -329,7 +329,7 @@ class AX_DLL Vec3 */ constexpr void set(const float* array) { - GP_ASSERT(array); + AX_ASSERT(array); x = array[0]; y = array[1]; diff --git a/core/math/Vec4.cpp b/core/math/Vec4.cpp index a399c8a9a08b..3d26db646e3c 100644 --- a/core/math/Vec4.cpp +++ b/core/math/Vec4.cpp @@ -74,7 +74,7 @@ float Vec4::angle(const Vec4& v1, const Vec4& v2) void Vec4::add(const Vec4& v1, const Vec4& v2, Vec4* dst) { - GP_ASSERT(dst); + AX_ASSERT(dst); dst->x = v1.x + v2.x; dst->y = v1.y + v2.y; @@ -84,7 +84,7 @@ void Vec4::add(const Vec4& v1, const Vec4& v2, Vec4* dst) void Vec4::clamp(const Vec4& min, const Vec4& max) { - GP_ASSERT(!(min.x > max.x || min.y > max.y || min.z > max.z || min.w > max.w)); + AX_ASSERT(!(min.x > max.x || min.y > max.y || min.z > max.z || min.w > max.w)); // Clamp the x value. if (x < min.x) @@ -113,8 +113,8 @@ void Vec4::clamp(const Vec4& min, const Vec4& max) void Vec4::clamp(const Vec4& v, const Vec4& min, const Vec4& max, Vec4* dst) { - GP_ASSERT(dst); - GP_ASSERT(!(min.x > max.x || min.y > max.y || min.z > max.z || min.w > max.w)); + AX_ASSERT(dst); + AX_ASSERT(!(min.x > max.x || min.y > max.y || min.z > max.z || min.w > max.w)); // Clamp the x value. dst->x = v.x; @@ -213,7 +213,7 @@ Vec4 Vec4::getNormalized() const void Vec4::subtract(const Vec4& v1, const Vec4& v2, Vec4* dst) { - GP_ASSERT(dst); + AX_ASSERT(dst); dst->x = v1.x - v2.x; dst->y = v1.y - v2.y; diff --git a/core/math/Vec4.h b/core/math/Vec4.h index 5d1a582a0091..7541fb59eeb1 100644 --- a/core/math/Vec4.h +++ b/core/math/Vec4.h @@ -135,7 +135,7 @@ class Vec4Base */ void set(const float* array) { - GP_ASSERT(array); + AX_ASSERT(array); this->x = array[0]; this->y = array[1];