Skip to content

Commit e3edbc2

Browse files
committed
mathlib: make Gain and Bias inline
1 parent 7ceba77 commit e3edbc2

File tree

2 files changed

+21
-31
lines changed

2 files changed

+21
-31
lines changed

mathlib/mathlib_base.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,33 +1392,6 @@ void VectorYawRotate( const Vector &in, float flYaw, Vector &out)
13921392
out.z = in.z;
13931393
}
13941394

1395-
1396-
1397-
float Bias( float x, float biasAmt )
1398-
{
1399-
// WARNING: not thread safe
1400-
static float lastAmt = -1;
1401-
static float lastExponent = 0;
1402-
if( lastAmt != biasAmt )
1403-
{
1404-
lastExponent = log( biasAmt ) * -1.4427f; // (-1.4427 = 1 / log(0.5))
1405-
}
1406-
float fRet = pow( x, lastExponent );
1407-
Assert ( !IS_NAN( fRet ) );
1408-
return fRet;
1409-
}
1410-
1411-
1412-
float Gain( float x, float biasAmt )
1413-
{
1414-
// WARNING: not thread safe
1415-
if( x < 0.5 )
1416-
return 0.5f * Bias( 2*x, 1-biasAmt );
1417-
else
1418-
return 1 - 0.5f * Bias( 2 - 2*x, 1-biasAmt );
1419-
}
1420-
1421-
14221395
float SmoothCurve( float x )
14231396
{
14241397
// Actual smooth curve. Visualization:

public/mathlib/mathlib.h

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,19 @@ void VectorYawRotate( const Vector& in, float flYaw, Vector &out);
10821082
// 0 1
10831083
//
10841084
// With a biasAmt of 0.5, Bias returns X.
1085-
float Bias( float x, float biasAmt );
1085+
inline float Bias( float x, float biasAmt )
1086+
{
1087+
// WARNING: not thread safe
1088+
static float lastAmt = -1;
1089+
static float lastExponent = 0;
1090+
if( lastAmt != biasAmt )
1091+
{
1092+
lastExponent = log( biasAmt ) * -1.4427f; // (-1.4427 = 1 / log(0.5))
1093+
}
1094+
float fRet = pow( x, lastExponent );
1095+
Assert ( !IS_NAN( fRet ) );
1096+
return fRet;
1097+
}
10861098

10871099

10881100
// Gain is similar to Bias, but biasAmt biases towards or away from 0.5.
@@ -1114,9 +1126,14 @@ float Bias( float x, float biasAmt );
11141126
// |*****
11151127
// |___________________
11161128
// 0 1
1117-
float Gain( float x, float biasAmt );
1118-
1119-
1129+
inline float Gain( float x, float biasAmt )
1130+
{
1131+
// WARNING: not thread safe
1132+
if( x < 0.5 )
1133+
return 0.5f * Bias( 2*x, 1-biasAmt );
1134+
else
1135+
return 1 - 0.5f * Bias( 2 - 2*x, 1-biasAmt );
1136+
}
11201137
// SmoothCurve maps a 0-1 value into another 0-1 value based on a cosine wave
11211138
// where the derivatives of the function at 0 and 1 (and 0.5) are 0. This is useful for
11221139
// any fadein/fadeout effect where it should start and end smoothly.

0 commit comments

Comments
 (0)