Skip to content

Commit e17fa6b

Browse files
authored
tweak(drawable): Decouple tint update step from render update (TheSuperHackers#1651)
1 parent b5ccac3 commit e17fa6b

File tree

4 files changed

+62
-18
lines changed

4 files changed

+62
-18
lines changed

Generals/Code/GameEngine/Include/GameClient/Drawable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class TintEnvelope : public MemoryPoolObject, public Snapshot
203203
Vector3 m_decayRate; ///< step amount to make tint turn off slow or fast
204204
Vector3 m_peakColor; ///< um, the peak color, what color we are headed toward during attack
205205
Vector3 m_currentColor; ///< um, the current color, how we are colored, now
206-
UnsignedInt m_sustainCounter;
206+
Real m_sustainCounter;
207207
Byte m_envState; ///< a randomly switchable SUSTAIN state, release is compliment
208208
Bool m_affect; ///< set TRUE if this has any effect (has a non 0,0,0 color).
209209
};

Generals/Code/GameEngine/Source/GameClient/Drawable.cpp

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4784,6 +4784,9 @@ void TintEnvelope::setDecayFrames( UnsignedInt frames )
47844784
//-------------------------------------------------------------------------------------------------
47854785
void TintEnvelope::update(void)
47864786
{
4787+
// TheSuperHackers @tweak The tint time step is now decoupled from the render update.
4788+
const Real timeScale = TheGameEngine->getActualLogicTimeScaleOverFpsRatio();
4789+
47874790
switch ( m_envState )
47884791
{
47894792
case ( ENVELOPE_STATE_REST ) : //most likely case
@@ -4794,25 +4797,31 @@ void TintEnvelope::update(void)
47944797
}
47954798
case ( ENVELOPE_STATE_DECAY ) : // much more likely than attack
47964799
{
4797-
if (m_decayRate.Length() > m_currentColor.Length() || m_currentColor.Length() <= FADE_RATE_EPSILON) //we are at rest
4800+
const Vector3 decayRate = m_decayRate * timeScale;
4801+
4802+
if (decayRate.Length() > m_currentColor.Length() || m_currentColor.Length() <= FADE_RATE_EPSILON)
47984803
{
4804+
// We are at rest
47994805
m_envState = ENVELOPE_STATE_REST;
48004806
m_affect = FALSE;
48014807
}
48024808
else
48034809
{
4804-
Vector3::Add( m_decayRate, m_currentColor, &m_currentColor );//Add the decayRate to the current color;
4810+
// Add the decayRate to the current color
4811+
Vector3::Add( decayRate, m_currentColor, &m_currentColor );
48054812
m_affect = TRUE;
48064813
}
48074814
break;
48084815
}
48094816
case ( ENVELOPE_STATE_ATTACK ) :
48104817
{
4818+
const Vector3 attackRate = m_attackRate * timeScale;
48114819
Vector3 delta;
48124820
Vector3::Subtract(m_currentColor, m_peakColor, &delta);
48134821

4814-
if (m_attackRate.Length() > delta.Length() || delta.Length() <= FADE_RATE_EPSILON) //we are at the peak
4822+
if (attackRate.Length() > delta.Length() || delta.Length() <= FADE_RATE_EPSILON)
48154823
{
4824+
// We are at the peak
48164825
if ( m_sustainCounter )
48174826
{
48184827
m_envState = ENVELOPE_STATE_SUSTAIN;
@@ -4821,20 +4830,20 @@ void TintEnvelope::update(void)
48214830
{
48224831
m_envState = ENVELOPE_STATE_DECAY;
48234832
}
4824-
48254833
}
48264834
else
48274835
{
4828-
Vector3::Add( m_attackRate, m_currentColor, &m_currentColor );//Add the attackRate to the current color;
4836+
// Add the attackRate to the current color
4837+
Vector3::Add( attackRate, m_currentColor, &m_currentColor );
48294838
m_affect = TRUE;
48304839
}
48314840

48324841
break;
48334842
}
48344843
case ( ENVELOPE_STATE_SUSTAIN ) :
48354844
{
4836-
if ( m_sustainCounter > 0 )
4837-
--m_sustainCounter;
4845+
if ( m_sustainCounter > 0.0f )
4846+
m_sustainCounter -= timeScale;
48384847
else
48394848
release();
48404849

@@ -4867,7 +4876,11 @@ void TintEnvelope::xfer( Xfer *xfer )
48674876
{
48684877

48694878
// version
4879+
#if RETAIL_COMPATIBLE_XFER_SAVE
48704880
XferVersion currentVersion = 1;
4881+
#else
4882+
XferVersion currentVersion = 2;
4883+
#endif
48714884
XferVersion version = currentVersion;
48724885
xfer->xferVersion( &version, currentVersion );
48734886

@@ -4884,7 +4897,16 @@ void TintEnvelope::xfer( Xfer *xfer )
48844897
xfer->xferUser( &m_currentColor, sizeof( Vector3 ) );
48854898

48864899
// sustain counter
4887-
xfer->xferUnsignedInt( &m_sustainCounter );
4900+
if (version <= 1)
4901+
{
4902+
UnsignedInt sustainCounter = (UnsignedInt)m_sustainCounter;
4903+
xfer->xferUnsignedInt( &sustainCounter );
4904+
m_sustainCounter = (Real)sustainCounter;
4905+
}
4906+
else
4907+
{
4908+
xfer->xferReal( &m_sustainCounter );
4909+
}
48884910

48894911
// affect
48904912
xfer->xferBool( &m_affect );

GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class TintEnvelope : public MemoryPoolObject, public Snapshot
206206
Vector3 m_decayRate; ///< step amount to make tint turn off slow or fast
207207
Vector3 m_peakColor; ///< um, the peak color, what color we are headed toward during attack
208208
Vector3 m_currentColor; ///< um, the current color, how we are colored, now
209-
UnsignedInt m_sustainCounter;
209+
Real m_sustainCounter;
210210
Byte m_envState; ///< a randomly switchable SUSTAIN state, release is compliment
211211
Bool m_affect; ///< set TRUE if this has any effect (has a non 0,0,0 color).
212212
};

GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5541,6 +5541,9 @@ void TintEnvelope::setDecayFrames( UnsignedInt frames )
55415541
//-------------------------------------------------------------------------------------------------
55425542
void TintEnvelope::update(void)
55435543
{
5544+
// TheSuperHackers @tweak The tint time step is now decoupled from the render update.
5545+
const Real timeScale = TheGameEngine->getActualLogicTimeScaleOverFpsRatio();
5546+
55445547
switch ( m_envState )
55455548
{
55465549
case ( ENVELOPE_STATE_REST ) : //most likely case
@@ -5551,25 +5554,31 @@ void TintEnvelope::update(void)
55515554
}
55525555
case ( ENVELOPE_STATE_DECAY ) : // much more likely than attack
55535556
{
5554-
if (m_decayRate.Length() > m_currentColor.Length() || m_currentColor.Length() <= FADE_RATE_EPSILON) //we are at rest
5557+
const Vector3 decayRate = m_decayRate * timeScale;
5558+
5559+
if (decayRate.Length() > m_currentColor.Length() || m_currentColor.Length() <= FADE_RATE_EPSILON)
55555560
{
5561+
// We are at rest
55565562
m_envState = ENVELOPE_STATE_REST;
55575563
m_affect = FALSE;
55585564
}
55595565
else
55605566
{
5561-
Vector3::Add( m_decayRate, m_currentColor, &m_currentColor );//Add the decayRate to the current color;
5567+
// Add the decayRate to the current color
5568+
Vector3::Add( decayRate, m_currentColor, &m_currentColor );
55625569
m_affect = TRUE;
55635570
}
55645571
break;
55655572
}
55665573
case ( ENVELOPE_STATE_ATTACK ) :
55675574
{
5575+
const Vector3 attackRate = m_attackRate * timeScale;
55685576
Vector3 delta;
55695577
Vector3::Subtract(m_currentColor, m_peakColor, &delta);
55705578

5571-
if (m_attackRate.Length() > delta.Length() || delta.Length() <= FADE_RATE_EPSILON) //we are at the peak
5579+
if (attackRate.Length() > delta.Length() || delta.Length() <= FADE_RATE_EPSILON)
55725580
{
5581+
// We are at the peak
55735582
if ( m_sustainCounter )
55745583
{
55755584
m_envState = ENVELOPE_STATE_SUSTAIN;
@@ -5578,20 +5587,20 @@ void TintEnvelope::update(void)
55785587
{
55795588
m_envState = ENVELOPE_STATE_DECAY;
55805589
}
5581-
55825590
}
55835591
else
55845592
{
5585-
Vector3::Add( m_attackRate, m_currentColor, &m_currentColor );//Add the attackRate to the current color;
5593+
// Add the attackRate to the current color
5594+
Vector3::Add( attackRate, m_currentColor, &m_currentColor );
55865595
m_affect = TRUE;
55875596
}
55885597

55895598
break;
55905599
}
55915600
case ( ENVELOPE_STATE_SUSTAIN ) :
55925601
{
5593-
if ( m_sustainCounter > 0 )
5594-
--m_sustainCounter;
5602+
if ( m_sustainCounter > 0.0f )
5603+
m_sustainCounter -= timeScale;
55955604
else
55965605
release();
55975606

@@ -5624,7 +5633,11 @@ void TintEnvelope::xfer( Xfer *xfer )
56245633
{
56255634

56265635
// version
5636+
#if RETAIL_COMPATIBLE_XFER_SAVE
56275637
XferVersion currentVersion = 1;
5638+
#else
5639+
XferVersion currentVersion = 2;
5640+
#endif
56285641
XferVersion version = currentVersion;
56295642
xfer->xferVersion( &version, currentVersion );
56305643

@@ -5641,7 +5654,16 @@ void TintEnvelope::xfer( Xfer *xfer )
56415654
xfer->xferUser( &m_currentColor, sizeof( Vector3 ) );
56425655

56435656
// sustain counter
5644-
xfer->xferUnsignedInt( &m_sustainCounter );
5657+
if (version <= 1)
5658+
{
5659+
UnsignedInt sustainCounter = (UnsignedInt)m_sustainCounter;
5660+
xfer->xferUnsignedInt( &sustainCounter );
5661+
m_sustainCounter = (Real)sustainCounter;
5662+
}
5663+
else
5664+
{
5665+
xfer->xferReal( &m_sustainCounter );
5666+
}
56455667

56465668
// affect
56475669
xfer->xferBool( &m_affect );

0 commit comments

Comments
 (0)