Skip to content

Commit

Permalink
Replace RageFastSin and RageFastCos with standard library versions be…
Browse files Browse the repository at this point in the history
…cause the standard library is faster. Use fmod in spline evaluation.
  • Loading branch information
kyzentun committed Feb 7, 2016
1 parent 9f57dd6 commit acda442
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 135 deletions.
16 changes: 8 additions & 8 deletions src/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ void Actor::PreDraw() // calculate actor properties
ssprintf("PercentThroughEffect: %f", fPercentThroughEffect) );

bool bBlinkOn = fPercentThroughEffect > 0.5f;
float fPercentBetweenColors = RageFastSin( (fPercentThroughEffect + 0.25f) * 2 * PI ) / 2 + 0.5f;
float fPercentBetweenColors = std::sin( (fPercentThroughEffect + 0.25f) * 2 * PI ) / 2 + 0.5f;
ASSERT_M( fPercentBetweenColors >= 0 && fPercentBetweenColors <= 1,
ssprintf("PercentBetweenColors: %f, PercentThroughEffect: %f", fPercentBetweenColors, fPercentThroughEffect) );
float fOriginalAlpha = tempState.diffuse[0].a;
Expand Down Expand Up @@ -516,15 +516,15 @@ void Actor::PreDraw() // calculate actor properties
break;
case rainbow:
tempState.diffuse[0] = RageColor(
RageFastCos( fPercentBetweenColors*2*PI ) * 0.5f + 0.5f,
RageFastCos( fPercentBetweenColors*2*PI + PI * 2.0f / 3.0f ) * 0.5f + 0.5f,
RageFastCos( fPercentBetweenColors*2*PI + PI * 4.0f / 3.0f) * 0.5f + 0.5f,
std::cos( fPercentBetweenColors*2*PI ) * 0.5f + 0.5f,
std::cos( fPercentBetweenColors*2*PI + PI * 2.0f / 3.0f ) * 0.5f + 0.5f,
std::cos( fPercentBetweenColors*2*PI + PI * 4.0f / 3.0f) * 0.5f + 0.5f,
fOriginalAlpha );
for( int i=1; i<NUM_DIFFUSE_COLORS; i++ )
tempState.diffuse[i] = tempState.diffuse[0];
break;
case wag:
tempState.rotation += m_vEffectMagnitude * RageFastSin( fPercentThroughEffect * 2.0f * PI );
tempState.rotation += m_vEffectMagnitude * std::sin( fPercentThroughEffect * 2.0f * PI );
break;
case spin:
// nothing needs to be here
Expand All @@ -536,21 +536,21 @@ void Actor::PreDraw() // calculate actor properties
break;
case bounce:
{
float fPercentOffset = RageFastSin( fPercentThroughEffect*PI );
float fPercentOffset = std::sin( fPercentThroughEffect*PI );
tempState.pos += m_vEffectMagnitude * fPercentOffset;
}
break;
case bob:
{
float fPercentOffset = RageFastSin( fPercentThroughEffect*PI*2 );
float fPercentOffset = std::sin( fPercentThroughEffect*PI*2 );
tempState.pos += m_vEffectMagnitude * fPercentOffset;
}
break;
case pulse:
{
float fMinZoom = m_vEffectMagnitude[0];
float fMaxZoom = m_vEffectMagnitude[1];
float fPercentOffset = RageFastSin( fPercentThroughEffect*PI );
float fPercentOffset = std::sin( fPercentThroughEffect*PI );
float fZoom = SCALE( fPercentOffset, 0.f, 1.f, fMinZoom, fMaxZoom );
tempState.scale *= fZoom;

Expand Down
18 changes: 9 additions & 9 deletions src/ArrowEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ void ArrowEffects::Update()
TIPSY_OFFSET_ARROW_MAGNITUDE;
for(int col= 0; col < MAX_COLS_PER_PLAYER; ++col)
{
data.m_tipsy_result[col]= RageFastCos(
data.m_tipsy_result[col]= std::cos(
time_times_timer + (col * TIPSY_COLUMN_FREQUENCY)) *
arrow_times_mag;
data.m_tipsy_offset_result[col]= RageFastCos(
data.m_tipsy_offset_result[col]= std::cos(
time_times_offset_timer + (col * TIPSY_OFFSET_COLUMN_FREQUENCY)) *
arrow_times_offset_mag;
}
Expand Down Expand Up @@ -360,7 +360,7 @@ float ArrowEffects::GetYOffset( const PlayerState* pPlayerState, int iCol, float
fYAdjust += fBrakeYAdjust;
}
if( fAccels[PlayerOptions::ACCEL_WAVE] != 0 )
fYAdjust += fAccels[PlayerOptions::ACCEL_WAVE] * WAVE_MOD_MAGNITUDE *RageFastSin( fYOffset/WAVE_MOD_HEIGHT );
fYAdjust += fAccels[PlayerOptions::ACCEL_WAVE] * WAVE_MOD_MAGNITUDE *std::sin( fYOffset/WAVE_MOD_HEIGHT );

fYOffset += fYAdjust;

Expand Down Expand Up @@ -396,7 +396,7 @@ float ArrowEffects::GetYOffset( const PlayerState* pPlayerState, int iCol, float
// TODO: Don't index by PlayerNumber.
PerPlayerData &data = g_EffectData[pPlayerState->m_PlayerNumber];

float fExpandMultiplier = SCALE( RageFastCos(data.m_fExpandSeconds*EXPAND_MULTIPLIER_FREQUENCY),
float fExpandMultiplier = SCALE( std::cos(data.m_fExpandSeconds*EXPAND_MULTIPLIER_FREQUENCY),
EXPAND_MULTIPLIER_SCALE_FROM_LOW, EXPAND_MULTIPLIER_SCALE_FROM_HIGH,
EXPAND_MULTIPLIER_SCALE_TO_LOW, EXPAND_MULTIPLIER_SCALE_TO_HIGH );
fScrollSpeed *= SCALE( fAccels[PlayerOptions::ACCEL_EXPAND],
Expand Down Expand Up @@ -495,15 +495,15 @@ float ArrowEffects::GetXPos( const PlayerState* pPlayerState, int iColNum, float
float fRads = acosf( fPositionBetween );
fRads += fYOffset * TORNADO_OFFSET_FREQUENCY / SCREEN_HEIGHT;

const float fAdjustedPixelOffset = SCALE( RageFastCos(fRads), TORNADO_OFFSET_SCALE_FROM_LOW, TORNADO_OFFSET_SCALE_FROM_HIGH,
const float fAdjustedPixelOffset = SCALE( std::cos(fRads), TORNADO_OFFSET_SCALE_FROM_LOW, TORNADO_OFFSET_SCALE_FROM_HIGH,
data.m_fMinTornadoX[iColNum], data.m_fMaxTornadoX[iColNum] );

fPixelOffsetFromCenter += (fAdjustedPixelOffset - fRealPixelOffset) * fEffects[PlayerOptions::EFFECT_TORNADO];
}

if( fEffects[PlayerOptions::EFFECT_DRUNK] != 0 )
fPixelOffsetFromCenter += fEffects[PlayerOptions::EFFECT_DRUNK] *
( RageFastCos( RageTimer::GetTimeSinceStartFast() + iColNum*DRUNK_COLUMN_FREQUENCY
( std::cos( RageTimer::GetTimeSinceStartFast() + iColNum*DRUNK_COLUMN_FREQUENCY
+ fYOffset*DRUNK_OFFSET_FREQUENCY/SCREEN_HEIGHT) * ARROW_SIZE*DRUNK_ARROW_MAGNITUDE );
if( fEffects[PlayerOptions::EFFECT_FLIP] != 0 )
{
Expand All @@ -520,7 +520,7 @@ float ArrowEffects::GetXPos( const PlayerState* pPlayerState, int iColNum, float

if( fEffects[PlayerOptions::EFFECT_BEAT] != 0 )
{
const float fShift = data.m_fBeatFactor*RageFastSin( fYOffset / BEAT_OFFSET_HEIGHT + PI/BEAT_PI_HEIGHT );
const float fShift = data.m_fBeatFactor*std::sin( fYOffset / BEAT_OFFSET_HEIGHT + PI/BEAT_PI_HEIGHT );
fPixelOffsetFromCenter += fEffects[PlayerOptions::EFFECT_BEAT] * fShift;
}

Expand Down Expand Up @@ -715,7 +715,7 @@ float ArrowGetPercentVisible(float fYPosWithoutReverse)
fVisibleAdjust -= fAppearances[PlayerOptions::APPEARANCE_STEALTH];
if( fAppearances[PlayerOptions::APPEARANCE_BLINK] != 0 )
{
float f = RageFastSin(RageTimer::GetTimeSinceStartFast()*10);
float f = std::sin(RageTimer::GetTimeSinceStartFast()*10);
f = Quantize( f, BLINK_MOD_FREQUENCY );
fVisibleAdjust += SCALE( f, 0, 1, -1, 0 );
}
Expand Down Expand Up @@ -783,7 +783,7 @@ float ArrowEffects::GetZPos(int iCol, float fYOffset)
const float* fEffects = curr_options->m_fEffects;

if( fEffects[PlayerOptions::EFFECT_BUMPY] != 0 )
fZPos += fEffects[PlayerOptions::EFFECT_BUMPY] * 40*RageFastSin( fYOffset/16.0f );
fZPos += fEffects[PlayerOptions::EFFECT_BUMPY] * 40*std::sin( fYOffset/16.0f );

return fZPos;
}
Expand Down
4 changes: 2 additions & 2 deletions src/CubicSpline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ void CubicSpline::p_and_tfrac_from_t(float t, bool loop, size_t& p, float& tfrac
if(loop)
{
float max_t= static_cast<float>(m_points.size());
while(t >= max_t) { t-= max_t; }
while(t < 0.0f) { t+= max_t; }
t= std::fmod(t, max_t);
if(t < 0.0f) { t+= max_t; }
p= static_cast<size_t>(t);
tfrac= t - static_cast<float>(p);
}
Expand Down
4 changes: 2 additions & 2 deletions src/GraphDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class GraphLine: public Actor
for( int i = 0; i < iSubdivisions+1; ++i )
{
const float fRotation = float(i) / iSubdivisions * 2*PI;
const float fX = RageFastCos(fRotation) * fRadius;
const float fY = -RageFastSin(fRotation) * fRadius;
const float fX = std::cos(fRotation) * fRadius;
const float fY = -std::sin(fRotation) * fRadius;
pVerts[1+i] = v;
pVerts[1+i].p.x += fX;
pVerts[1+i].p.y += fY;
Expand Down
8 changes: 4 additions & 4 deletions src/GrooveRadar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ void GrooveRadar::GrooveRadarValueMap::DrawPrimitives()
const float fDistFromCenter =
( m_fValuesOld[c] * (1-m_PercentTowardNew) + m_fValuesNew[c] * m_PercentTowardNew + 0.07f ) * fRadius;
const float fRotation = RADAR_VALUE_ROTATION(i);
const float fX = RageFastCos(fRotation) * fDistFromCenter;
const float fY = -RageFastSin(fRotation) * fDistFromCenter;
const float fX = std::cos(fRotation) * fDistFromCenter;
const float fY = -std::sin(fRotation) * fDistFromCenter;

v[1+i].p = RageVector3( fX, fY, 0 );
v[1+i].c = v[1].c;
Expand All @@ -186,8 +186,8 @@ void GrooveRadar::GrooveRadarValueMap::DrawPrimitives()
const float fDistFromCenter =
( m_fValuesOld[c] * (1-m_PercentTowardNew) + m_fValuesNew[c] * m_PercentTowardNew + 0.07f ) * fRadius;
const float fRotation = RADAR_VALUE_ROTATION(i);
const float fX = RageFastCos(fRotation) * fDistFromCenter;
const float fY = -RageFastSin(fRotation) * fDistFromCenter;
const float fX = std::cos(fRotation) * fDistFromCenter;
const float fY = -std::sin(fRotation) * fDistFromCenter;

v[i].p = RageVector3( fX, fY, 0 );
v[i].c = this->m_pTempState->diffuse[0];
Expand Down
4 changes: 2 additions & 2 deletions src/NoteField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ void NoteField::DrawPrimitives()
ASSERT(GAMESTATE->m_pCurSong != NULL);

const TimingData &timing = *pTiming;
const RageColor text_glow= RageColor(1,1,1,RageFastCos(RageTimer::GetTimeSinceStartFast()*2)/2+0.5f);
const RageColor text_glow= RageColor(1,1,1,std::cos(RageTimer::GetTimeSinceStartFast()*2)/2+0.5f);

float horiz_align= align_right;
float side_sign= 1;
Expand Down Expand Up @@ -1014,7 +1014,7 @@ void NoteField::DrawPrimitives()
*m_FieldRenderArgs.selection_end_marker != -1)
{
m_FieldRenderArgs.selection_glow= SCALE(
RageFastCos(RageTimer::GetTimeSinceStartFast()*2), -1, 1, 0.1f, 0.3f);
std::cos(RageTimer::GetTimeSinceStartFast()*2), -1, 1, 0.1f, 0.3f);
}
m_FieldRenderArgs.fade_before_targets= FADE_BEFORE_TARGETS_PERCENT;

Expand Down
4 changes: 2 additions & 2 deletions src/RageDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ void RageDisplay::DrawCircleInternal( const RageSpriteVertex &p, float radius )
for(int i = 0; i < subdivisions+1; ++i)
{
const float fRotation = float(i) / subdivisions * 2*PI;
const float fX = RageFastCos(fRotation) * radius;
const float fY = -RageFastSin(fRotation) * radius;
const float fX = std::cos(fRotation) * radius;
const float fY = -std::sin(fRotation) * radius;
v[1+i] = v[0];
v[1+i].p.x += fX;
v[1+i].p.y += fY;
Expand Down
Loading

0 comments on commit acda442

Please sign in to comment.