Skip to content

Commit b71b3a9

Browse files
authored
[GEN][ZH] Fix compile errors with ALLOW_TEMPORARIES in WWMath (#603)
1 parent 0538f1f commit b71b3a9

File tree

8 files changed

+54
-20
lines changed

8 files changed

+54
-20
lines changed

Generals/Code/Libraries/Source/WWVegas/WWMath/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,6 @@ target_sources(g_wwmath PRIVATE ${WWMATH_SRC})
8888
target_link_libraries(g_wwmath PRIVATE
8989
g_wwcommon
9090
)
91+
92+
# @todo Test its impact and see what to do with the legacy functions.
93+
#add_compile_definitions(z_wwmath PUBLIC ALLOW_TEMPORARIES) # Enables legacy math with "temporaries"

Generals/Code/Libraries/Source/WWVegas/WWMath/matrix3d.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ void Matrix3D::Lerp(const Matrix3D &A, const Matrix3D &B, float factor, Matrix3D
11871187

11881188
// Lerp position
11891189
#ifdef ALLOW_TEMPORARIES
1190-
Vector3 pos = Lerp(A.Get_Translation(), B.Get_Translation(), factor);
1190+
Vector3 pos = Vector3::Lerp(A.Get_Translation(), B.Get_Translation(), factor);
11911191
#else
11921192
Vector3 pos;
11931193
Vector3::Lerp(A.Get_Translation(), B.Get_Translation(), factor, &pos);

Generals/Code/Libraries/Source/WWVegas/WWMath/matrix3d.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,7 +1662,7 @@ WWINLINE void Matrix3D::mulVector3Array(const Vector3* in, Vector3* out, int cou
16621662
{
16631663
assert(in != out);
16641664
#ifdef ALLOW_TEMPORARIES
1665-
for (i=0; i<count; i++)
1665+
for (int i=0; i<count; i++)
16661666
{
16671667
out[i] = (*this) * in[i];
16681668
}
@@ -1682,7 +1682,7 @@ WWINLINE void Matrix3D::mulVector3Array(const Vector3* in, Vector3* out, int cou
16821682
WWINLINE void Matrix3D::mulVector3Array(Vector3* inout, int count) const
16831683
{
16841684
#ifdef ALLOW_TEMPORARIES
1685-
for (i=0; i<count; i++)
1685+
for (int i=0; i<count; i++)
16861686
{
16871687
inout[i] = (*this) * inout[i];
16881688
}

Generals/Code/Libraries/Source/WWVegas/WWMath/vector3.h

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class Vector3
146146
WWINLINE friend bool Equal_Within_Epsilon(const Vector3 &a,const Vector3 &b,float epsilon);
147147

148148
// dot product / inner product
149-
//WWINLINE friend float operator * (const Vector3 &a,const Vector3 &b);
149+
WWINLINE friend float operator * (const Vector3 &a,const Vector3 &b);
150150
static WWINLINE float Dot_Product(const Vector3 &a,const Vector3 &b);
151151

152152
// cross product / outer product
@@ -185,6 +185,10 @@ class Vector3
185185
// Linearly interpolate two Vector3's
186186
static void Lerp(const Vector3 & a, const Vector3 & b, float alpha,Vector3 * set_result);
187187

188+
#ifdef ALLOW_TEMPORARIES
189+
static Vector3 Lerp(const Vector3 & a, const Vector3 & b, float alpha);
190+
#endif
191+
188192
// Color Conversion
189193
WWINLINE unsigned long Convert_To_ABGR( void ) const;
190194
WWINLINE unsigned long Convert_To_ARGB( void ) const;
@@ -284,12 +288,12 @@ WWINLINE Vector3 operator - (const Vector3 &a,const Vector3 &b)
284288
* *
285289
* HISTORY: *
286290
*========================================================================*/
287-
//WWINLINE float operator * (const Vector3 &a,const Vector3 &b)
288-
//{
289-
// return a.X*b.X +
290-
// a.Y*b.Y +
291-
// a.Z*b.Z;
292-
//}
291+
WWINLINE float operator * (const Vector3 &a,const Vector3 &b)
292+
{
293+
return a.X*b.X +
294+
a.Y*b.Y +
295+
a.Z*b.Z;
296+
}
293297

294298
WWINLINE float Vector3::Dot_Product(const Vector3 &a,const Vector3 &b)
295299
{
@@ -541,6 +545,16 @@ WWINLINE void Vector3::Lerp(const Vector3 & a, const Vector3 & b, float alpha,Ve
541545
set_result->Z = (a.Z + (b.Z - a.Z)*alpha);
542546
}
543547

548+
549+
#ifdef ALLOW_TEMPORARIES
550+
WWINLINE Vector3 Vector3::Lerp(const Vector3 & a, const Vector3 & b, float alpha)
551+
{
552+
Vector3 set_result;
553+
Vector3::Lerp(a, b, alpha, &set_result);
554+
return set_result;
555+
}
556+
#endif
557+
544558
/***********************************************************************************************
545559
* Vector3::Add -- Add two vector3's without return-by-value *
546560
* *

GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,6 @@ target_sources(z_wwmath PRIVATE ${WWMATH_SRC})
8888
target_link_libraries(z_wwmath PRIVATE
8989
z_wwcommon
9090
)
91+
92+
# @todo Test its impact and see what to do with the legacy functions.
93+
#add_compile_definitions(z_wwmath PUBLIC ALLOW_TEMPORARIES) # Enables legacy math with "temporaries"

GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/matrix3d.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ void Matrix3D::Lerp(const Matrix3D &A, const Matrix3D &B, float factor, Matrix3D
11871187

11881188
// Lerp position
11891189
#ifdef ALLOW_TEMPORARIES
1190-
Vector3 pos = Lerp(A.Get_Translation(), B.Get_Translation(), factor);
1190+
Vector3 pos = Vector3::Lerp(A.Get_Translation(), B.Get_Translation(), factor);
11911191
#else
11921192
Vector3 pos;
11931193
Vector3::Lerp(A.Get_Translation(), B.Get_Translation(), factor, &pos);

GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/matrix3d.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,7 +1662,7 @@ WWINLINE void Matrix3D::mulVector3Array(const Vector3* in, Vector3* out, int cou
16621662
{
16631663
assert(in != out);
16641664
#ifdef ALLOW_TEMPORARIES
1665-
for (i=0; i<count; i++)
1665+
for (int i=0; i<count; i++)
16661666
{
16671667
out[i] = (*this) * in[i];
16681668
}
@@ -1682,7 +1682,7 @@ WWINLINE void Matrix3D::mulVector3Array(const Vector3* in, Vector3* out, int cou
16821682
WWINLINE void Matrix3D::mulVector3Array(Vector3* inout, int count) const
16831683
{
16841684
#ifdef ALLOW_TEMPORARIES
1685-
for (i=0; i<count; i++)
1685+
for (int i=0; i<count; i++)
16861686
{
16871687
inout[i] = (*this) * inout[i];
16881688
}

GeneralsMD/Code/Libraries/Source/WWVegas/WWMath/vector3.h

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class Vector3
146146
WWINLINE friend bool Equal_Within_Epsilon(const Vector3 &a,const Vector3 &b,float epsilon);
147147

148148
// dot product / inner product
149-
//WWINLINE friend float operator * (const Vector3 &a,const Vector3 &b);
149+
WWINLINE friend float operator * (const Vector3 &a,const Vector3 &b);
150150
static WWINLINE float Dot_Product(const Vector3 &a,const Vector3 &b);
151151

152152
// cross product / outer product
@@ -185,6 +185,10 @@ class Vector3
185185
// Linearly interpolate two Vector3's
186186
static void Lerp(const Vector3 & a, const Vector3 & b, float alpha,Vector3 * set_result);
187187

188+
#ifdef ALLOW_TEMPORARIES
189+
static Vector3 Lerp(const Vector3 & a, const Vector3 & b, float alpha);
190+
#endif
191+
188192
// Color Conversion
189193
WWINLINE unsigned long Convert_To_ABGR( void ) const;
190194
WWINLINE unsigned long Convert_To_ARGB( void ) const;
@@ -284,12 +288,12 @@ WWINLINE Vector3 operator - (const Vector3 &a,const Vector3 &b)
284288
* *
285289
* HISTORY: *
286290
*========================================================================*/
287-
//WWINLINE float operator * (const Vector3 &a,const Vector3 &b)
288-
//{
289-
// return a.X*b.X +
290-
// a.Y*b.Y +
291-
// a.Z*b.Z;
292-
//}
291+
WWINLINE float operator * (const Vector3 &a,const Vector3 &b)
292+
{
293+
return a.X*b.X +
294+
a.Y*b.Y +
295+
a.Z*b.Z;
296+
}
293297

294298
WWINLINE float Vector3::Dot_Product(const Vector3 &a,const Vector3 &b)
295299
{
@@ -541,6 +545,16 @@ WWINLINE void Vector3::Lerp(const Vector3 & a, const Vector3 & b, float alpha,Ve
541545
set_result->Z = (a.Z + (b.Z - a.Z)*alpha);
542546
}
543547

548+
549+
#ifdef ALLOW_TEMPORARIES
550+
WWINLINE Vector3 Vector3::Lerp(const Vector3 & a, const Vector3 & b, float alpha)
551+
{
552+
Vector3 set_result;
553+
Vector3::Lerp(a, b, alpha, &set_result);
554+
return set_result;
555+
}
556+
#endif
557+
544558
/***********************************************************************************************
545559
* Vector3::Add -- Add two vector3's without return-by-value *
546560
* *

0 commit comments

Comments
 (0)