Skip to content

Commit fa17ba6

Browse files
committed
Clean Rage::Color implementation.
Now with tests to ensure invalid colors don't get made. Also, first legitmate usage of the cppformat submodule. Remember to update!
1 parent 624cd48 commit fa17ba6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1068
-520
lines changed

src/Actor.cpp

+129-41
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ void Actor::InitState()
9494
m_baseRotation = Rage::Vector3( 0, 0, 0 );
9595
m_baseScale = Rage::Vector3( 1, 1, 1 );
9696
m_fBaseAlpha = 1;
97-
m_internalDiffuse = RageColor( 1, 1, 1, 1 );
98-
m_internalGlow = RageColor( 0, 0, 0, 0 );
97+
m_internalDiffuse = Rage::Color( 1, 1, 1, 1 );
98+
m_internalGlow = Rage::Color( 0, 0, 0, 0 );
9999

100100
m_start.Init();
101101
m_current.Init();
@@ -114,13 +114,13 @@ void Actor::InitState()
114114
m_fEffectOffset = 0;
115115
m_EffectClock = CLOCK_TIMER;
116116
m_vEffectMagnitude = Rage::Vector3(0,0,10);
117-
m_effectColor1 = RageColor(1,1,1,1);
118-
m_effectColor2 = RageColor(1,1,1,1);
117+
m_effectColor1 = Rage::Color(1,1,1,1);
118+
m_effectColor2 = Rage::Color(1,1,1,1);
119119

120120
m_bVisible = true;
121121
m_fShadowLengthX = 0;
122122
m_fShadowLengthY = 0;
123-
m_ShadowColor = RageColor(0,0,0,0.5f);
123+
m_ShadowColor = Rage::Color(0,0,0,0.5f);
124124
m_bIsAnimating = true;
125125
m_fHibernateSecondsLeft = 0;
126126
m_iDrawOrder = 0;
@@ -330,8 +330,8 @@ void Actor::Draw()
330330
m_FakeParent->BeginDraw();
331331
}
332332
size_t wrapper_states_used= 0;
333-
RageColor last_diffuse;
334-
RageColor last_glow;
333+
Rage::Color last_diffuse;
334+
Rage::Color last_glow;
335335
bool use_last_diffuse= false;
336336
// dont_abort_draw exists because if one of the layers is invisible,
337337
// there's no point in continuing. -Kyz
@@ -417,7 +417,7 @@ void Actor::Draw()
417417

418418
void Actor::PostDraw() // reset internal diffuse and glow
419419
{
420-
m_internalDiffuse = RageColor(1, 1, 1, 1);
420+
m_internalDiffuse = Rage::Color(1, 1, 1, 1);
421421
m_internalGlow.a = 0;
422422
}
423423

@@ -517,7 +517,7 @@ void Actor::PreDraw() // calculate actor properties
517517
tempState.glow.a *= fOriginalAlpha; // don't glow if the Actor is transparent!
518518
break;
519519
case rainbow:
520-
tempState.diffuse[0] = RageColor(
520+
tempState.diffuse[0] = Rage::Color(
521521
RageFastCos( fPercentBetweenColors*2*PI ) * 0.5f + 0.5f,
522522
RageFastCos( fPercentBetweenColors*2*PI + PI * 2.0f / 3.0f ) * 0.5f + 0.5f,
523523
RageFastCos( fPercentBetweenColors*2*PI + PI * 4.0f / 3.0f) * 0.5f + 0.5f,
@@ -569,7 +569,7 @@ void Actor::PreDraw() // calculate actor properties
569569
if( m_fBaseAlpha != 1 )
570570
m_internalDiffuse.a *= m_fBaseAlpha;
571571

572-
if( m_internalDiffuse != RageColor(1, 1, 1, 1) )
572+
if( m_internalDiffuse != Rage::Color(1, 1, 1, 1) )
573573
{
574574
if( m_pTempState != &tempState )
575575
{
@@ -1115,7 +1115,7 @@ void Actor::ResetEffectTimeIfDifferent(Effect new_effect)
11151115
}
11161116
}
11171117

1118-
void Actor::SetEffectDiffuseBlink( float fEffectPeriodSeconds, RageColor c1, RageColor c2 )
1118+
void Actor::SetEffectDiffuseBlink( float fEffectPeriodSeconds, Rage::Color c1, Rage::Color c2 )
11191119
{
11201120
ASSERT( fEffectPeriodSeconds > 0 );
11211121
// todo: account for SSC_FUTURES -aj
@@ -1125,7 +1125,7 @@ void Actor::SetEffectDiffuseBlink( float fEffectPeriodSeconds, RageColor c1, Rag
11251125
m_effectColor2 = c2;
11261126
}
11271127

1128-
void Actor::SetEffectDiffuseShift( float fEffectPeriodSeconds, RageColor c1, RageColor c2 )
1128+
void Actor::SetEffectDiffuseShift( float fEffectPeriodSeconds, Rage::Color c1, Rage::Color c2 )
11291129
{
11301130
ASSERT( fEffectPeriodSeconds > 0 );
11311131
// todo: account for SSC_FUTURES -aj
@@ -1135,7 +1135,7 @@ void Actor::SetEffectDiffuseShift( float fEffectPeriodSeconds, RageColor c1, Rag
11351135
m_effectColor2 = c2;
11361136
}
11371137

1138-
void Actor::SetEffectDiffuseRamp( float fEffectPeriodSeconds, RageColor c1, RageColor c2 )
1138+
void Actor::SetEffectDiffuseRamp( float fEffectPeriodSeconds, Rage::Color c1, Rage::Color c2 )
11391139
{
11401140
ASSERT( fEffectPeriodSeconds > 0 );
11411141
// todo: account for SSC_FUTURES -aj
@@ -1145,7 +1145,7 @@ void Actor::SetEffectDiffuseRamp( float fEffectPeriodSeconds, RageColor c1, Rage
11451145
m_effectColor2 = c2;
11461146
}
11471147

1148-
void Actor::SetEffectGlowBlink( float fEffectPeriodSeconds, RageColor c1, RageColor c2 )
1148+
void Actor::SetEffectGlowBlink( float fEffectPeriodSeconds, Rage::Color c1, Rage::Color c2 )
11491149
{
11501150
ASSERT( fEffectPeriodSeconds > 0 );
11511151
// todo: account for SSC_FUTURES -aj
@@ -1155,7 +1155,7 @@ void Actor::SetEffectGlowBlink( float fEffectPeriodSeconds, RageColor c1, RageCo
11551155
m_effectColor2 = c2;
11561156
}
11571157

1158-
void Actor::SetEffectGlowShift( float fEffectPeriodSeconds, RageColor c1, RageColor c2 )
1158+
void Actor::SetEffectGlowShift( float fEffectPeriodSeconds, Rage::Color c1, Rage::Color c2 )
11591159
{
11601160
ASSERT( fEffectPeriodSeconds > 0 );
11611161
// todo: account for SSC_FUTURES -aj
@@ -1165,7 +1165,7 @@ void Actor::SetEffectGlowShift( float fEffectPeriodSeconds, RageColor c1, RageCo
11651165
m_effectColor2 = c2;
11661166
}
11671167

1168-
void Actor::SetEffectGlowRamp( float fEffectPeriodSeconds, RageColor c1, RageColor c2 )
1168+
void Actor::SetEffectGlowRamp( float fEffectPeriodSeconds, Rage::Color c1, Rage::Color c2 )
11691169
{
11701170
ASSERT( fEffectPeriodSeconds > 0 );
11711171
// todo: account for SSC_FUTURES -aj
@@ -1309,7 +1309,7 @@ float Actor::GetTweenTimeLeft() const
13091309
* we can simply say eg. "for x in states(Actor) do x.SetDiffuseColor(c) end".
13101310
* However, we'd then have to give every TweenState a userdata in Lua while it's
13111311
* being manipulated, which would add overhead ... */
1312-
void Actor::SetGlobalDiffuseColor( RageColor c )
1312+
void Actor::SetGlobalDiffuseColor( Rage::Color c )
13131313
{
13141314
for( int i=0; i<NUM_DIFFUSE_COLORS; i++ ) // color, not alpha
13151315
{
@@ -1328,7 +1328,7 @@ void Actor::SetGlobalDiffuseColor( RageColor c )
13281328
}
13291329
}
13301330

1331-
void Actor::SetDiffuseColor( RageColor c )
1331+
void Actor::SetDiffuseColor( Rage::Color c )
13321332
{
13331333
for( int i=0; i<NUM_DIFFUSE_COLORS; i++ )
13341334
{
@@ -1350,8 +1350,8 @@ void Actor::TweenState::Init()
13501350
crop = RectF( 0,0,0,0 );
13511351
fade = RectF( 0,0,0,0 );
13521352
for( int i=0; i<NUM_DIFFUSE_COLORS; i++ )
1353-
diffuse[i] = RageColor( 1, 1, 1, 1 );
1354-
glow = RageColor( 1, 1, 1, 0 );
1353+
diffuse[i] = Rage::Color( 1, 1, 1, 1 );
1354+
glow = Rage::Color( 1, 1, 1, 0 );
13551355
aux = 0;
13561356
}
13571357

@@ -1644,18 +1644,88 @@ class LunaActor : public Luna<Actor>
16441644
static int fadetop( T* p, lua_State *L ) { p->SetFadeTop(FArg(1)); COMMON_RETURN_SELF; }
16451645
static int faderight( T* p, lua_State *L ) { p->SetFadeRight(FArg(1)); COMMON_RETURN_SELF; }
16461646
static int fadebottom( T* p, lua_State *L ) { p->SetFadeBottom(FArg(1)); COMMON_RETURN_SELF; }
1647-
static int diffuse( T* p, lua_State *L ) { RageColor c; c.FromStackCompat( L, 1 ); p->SetDiffuse( c ); COMMON_RETURN_SELF; }
1648-
static int diffuseupperleft( T* p, lua_State *L ) { RageColor c; c.FromStackCompat( L, 1 ); p->SetDiffuseUpperLeft( c ); COMMON_RETURN_SELF; }
1649-
static int diffuseupperright( T* p, lua_State *L ) { RageColor c; c.FromStackCompat( L, 1 ); p->SetDiffuseUpperRight( c ); COMMON_RETURN_SELF; }
1650-
static int diffuselowerleft( T* p, lua_State *L ) { RageColor c; c.FromStackCompat( L, 1 ); p->SetDiffuseLowerLeft( c ); COMMON_RETURN_SELF; }
1651-
static int diffuselowerright( T* p, lua_State *L ) { RageColor c; c.FromStackCompat( L, 1 ); p->SetDiffuseLowerRight( c ); COMMON_RETURN_SELF; }
1652-
static int diffuseleftedge( T* p, lua_State *L ) { RageColor c; c.FromStackCompat( L, 1 ); p->SetDiffuseLeftEdge( c ); COMMON_RETURN_SELF; }
1653-
static int diffuserightedge( T* p, lua_State *L ) { RageColor c; c.FromStackCompat( L, 1 ); p->SetDiffuseRightEdge( c ); COMMON_RETURN_SELF; }
1654-
static int diffusetopedge( T* p, lua_State *L ) { RageColor c; c.FromStackCompat( L, 1 ); p->SetDiffuseTopEdge( c ); COMMON_RETURN_SELF; }
1655-
static int diffusebottomedge( T* p, lua_State *L ) { RageColor c; c.FromStackCompat( L, 1 ); p->SetDiffuseBottomEdge( c ); COMMON_RETURN_SELF; }
1656-
static int diffusealpha( T* p, lua_State *L ) { p->SetDiffuseAlpha(FArg(1)); COMMON_RETURN_SELF; }
1657-
static int diffusecolor( T* p, lua_State *L ) { RageColor c; c.FromStackCompat( L, 1 ); p->SetDiffuseColor( c ); COMMON_RETURN_SELF; }
1658-
static int glow( T* p, lua_State *L ) { RageColor c; c.FromStackCompat( L, 1 ); p->SetGlow( c ); COMMON_RETURN_SELF; }
1647+
static int diffuse( T* p, lua_State *L )
1648+
{
1649+
Rage::Color c;
1650+
FromStackCompat( c, L, 1 );
1651+
p->SetDiffuse( c );
1652+
COMMON_RETURN_SELF;
1653+
}
1654+
static int diffuseupperleft( T* p, lua_State *L )
1655+
{
1656+
Rage::Color c;
1657+
FromStackCompat( c, L, 1 );
1658+
p->SetDiffuseUpperLeft( c );
1659+
COMMON_RETURN_SELF;
1660+
}
1661+
static int diffuseupperright( T* p, lua_State *L )
1662+
{
1663+
Rage::Color c;
1664+
FromStackCompat( c, L, 1 );
1665+
p->SetDiffuseUpperRight( c );
1666+
COMMON_RETURN_SELF;
1667+
}
1668+
static int diffuselowerleft( T* p, lua_State *L )
1669+
{
1670+
Rage::Color c;
1671+
FromStackCompat( c, L, 1 );
1672+
p->SetDiffuseLowerLeft( c );
1673+
COMMON_RETURN_SELF;
1674+
}
1675+
static int diffuselowerright( T* p, lua_State *L )
1676+
{
1677+
Rage::Color c;
1678+
FromStackCompat( c, L, 1 );
1679+
p->SetDiffuseLowerRight( c );
1680+
COMMON_RETURN_SELF;
1681+
}
1682+
static int diffuseleftedge( T* p, lua_State *L )
1683+
{
1684+
Rage::Color c;
1685+
FromStackCompat( c, L, 1 );
1686+
p->SetDiffuseLeftEdge( c );
1687+
COMMON_RETURN_SELF;
1688+
}
1689+
static int diffuserightedge( T* p, lua_State *L )
1690+
{
1691+
Rage::Color c;
1692+
FromStackCompat( c, L, 1 );
1693+
p->SetDiffuseRightEdge( c );
1694+
COMMON_RETURN_SELF;
1695+
}
1696+
static int diffusetopedge( T* p, lua_State *L )
1697+
{
1698+
Rage::Color c;
1699+
FromStackCompat( c, L, 1 );
1700+
p->SetDiffuseTopEdge( c );
1701+
COMMON_RETURN_SELF;
1702+
}
1703+
static int diffusebottomedge( T* p, lua_State *L )
1704+
{
1705+
Rage::Color c;
1706+
FromStackCompat( c, L, 1 );
1707+
p->SetDiffuseBottomEdge( c );
1708+
COMMON_RETURN_SELF;
1709+
}
1710+
static int diffusealpha( T* p, lua_State *L )
1711+
{
1712+
p->SetDiffuseAlpha(FArg(1));
1713+
COMMON_RETURN_SELF;
1714+
}
1715+
static int diffusecolor( T* p, lua_State *L )
1716+
{
1717+
Rage::Color c;
1718+
FromStackCompat( c, L, 1 );
1719+
p->SetDiffuseColor( c );
1720+
COMMON_RETURN_SELF;
1721+
}
1722+
static int glow( T* p, lua_State *L )
1723+
{
1724+
Rage::Color c;
1725+
FromStackCompat( c, L, 1 );
1726+
p->SetGlow( c );
1727+
COMMON_RETURN_SELF;
1728+
}
16591729
static int aux( T* p, lua_State *L ) { p->SetAux( FArg(1) ); COMMON_RETURN_SELF; }
16601730
static int getaux( T* p, lua_State *L ) { lua_pushnumber( L, p->GetAux() ); return 1; }
16611731
static int rotationx( T* p, lua_State *L ) { p->SetRotationX(FArg(1)); COMMON_RETURN_SELF; }
@@ -1676,17 +1746,23 @@ class LunaActor : public Luna<Actor>
16761746
static int shadowlength( T* p, lua_State *L ) { p->SetShadowLength(FArg(1)); COMMON_RETURN_SELF; }
16771747
static int shadowlengthx( T* p, lua_State *L ) { p->SetShadowLengthX(FArg(1)); COMMON_RETURN_SELF; }
16781748
static int shadowlengthy( T* p, lua_State *L ) { p->SetShadowLengthY(FArg(1)); COMMON_RETURN_SELF; }
1679-
static int shadowcolor( T* p, lua_State *L ) { RageColor c; c.FromStackCompat( L, 1 ); p->SetShadowColor( c ); COMMON_RETURN_SELF; }
1749+
static int shadowcolor( T* p, lua_State *L )
1750+
{
1751+
Rage::Color c;
1752+
FromStackCompat( c, L, 1 );
1753+
p->SetShadowColor( c );
1754+
COMMON_RETURN_SELF;
1755+
}
16801756
static int horizalign( T* p, lua_State *L ) { p->SetHorizAlign(Enum::Check<HorizAlign>(L, 1)); COMMON_RETURN_SELF; }
16811757
static int vertalign( T* p, lua_State *L ) { p->SetVertAlign(Enum::Check<VertAlign>(L, 1)); COMMON_RETURN_SELF; }
16821758
static int halign( T* p, lua_State *L ) { p->SetHorizAlign(FArg(1)); COMMON_RETURN_SELF; }
16831759
static int valign( T* p, lua_State *L ) { p->SetVertAlign(FArg(1)); COMMON_RETURN_SELF; }
1684-
static int diffuseblink( T* p, lua_State *L ) { p->SetEffectDiffuseBlink(1.0f, RageColor(0.5f,0.5f,0.5f,0.5f), RageColor(1,1,1,1)); COMMON_RETURN_SELF; }
1685-
static int diffuseshift( T* p, lua_State *L ) { p->SetEffectDiffuseShift(1.0f, RageColor(0,0,0,1), RageColor(1,1,1,1)); COMMON_RETURN_SELF; }
1686-
static int diffuseramp( T* p, lua_State *L ) { p->SetEffectDiffuseRamp(1.0f, RageColor(0,0,0,1), RageColor(1,1,1,1)); COMMON_RETURN_SELF; }
1687-
static int glowblink( T* p, lua_State *L ) { p->SetEffectGlowBlink(1.0f, RageColor(1,1,1,0.2f), RageColor(1,1,1,0.8f)); COMMON_RETURN_SELF; }
1688-
static int glowshift( T* p, lua_State *L ) { p->SetEffectGlowShift(1.0f, RageColor(1,1,1,0.2f), RageColor(1,1,1,0.8f)); COMMON_RETURN_SELF; }
1689-
static int glowramp( T* p, lua_State *L ) { p->SetEffectGlowRamp(1.0f, RageColor(1,1,1,0.2f), RageColor(1,1,1,0.8f)); COMMON_RETURN_SELF; }
1760+
static int diffuseblink( T* p, lua_State *L ) { p->SetEffectDiffuseBlink(1.0f, Rage::Color(0.5f,0.5f,0.5f,0.5f), Rage::Color(1,1,1,1)); COMMON_RETURN_SELF; }
1761+
static int diffuseshift( T* p, lua_State *L ) { p->SetEffectDiffuseShift(1.0f, Rage::Color(0,0,0,1), Rage::Color(1,1,1,1)); COMMON_RETURN_SELF; }
1762+
static int diffuseramp( T* p, lua_State *L ) { p->SetEffectDiffuseRamp(1.0f, Rage::Color(0,0,0,1), Rage::Color(1,1,1,1)); COMMON_RETURN_SELF; }
1763+
static int glowblink( T* p, lua_State *L ) { p->SetEffectGlowBlink(1.0f, Rage::Color(1,1,1,0.2f), Rage::Color(1,1,1,0.8f)); COMMON_RETURN_SELF; }
1764+
static int glowshift( T* p, lua_State *L ) { p->SetEffectGlowShift(1.0f, Rage::Color(1,1,1,0.2f), Rage::Color(1,1,1,0.8f)); COMMON_RETURN_SELF; }
1765+
static int glowramp( T* p, lua_State *L ) { p->SetEffectGlowRamp(1.0f, Rage::Color(1,1,1,0.2f), Rage::Color(1,1,1,0.8f)); COMMON_RETURN_SELF; }
16901766
static int rainbow( T* p, lua_State *L ) { p->SetEffectRainbow(2.0f); COMMON_RETURN_SELF; }
16911767
static int wag( T* p, lua_State *L ) { p->SetEffectWag(2.0f, Rage::Vector3(0,0,20)); COMMON_RETURN_SELF; }
16921768
static int bounce( T* p, lua_State *L ) { p->SetEffectBounce(2.0f, Rage::Vector3(0,20,0)); COMMON_RETURN_SELF; }
@@ -1695,8 +1771,20 @@ class LunaActor : public Luna<Actor>
16951771
static int spin( T* p, lua_State *L ) { p->SetEffectSpin(Rage::Vector3(0,0,180)); COMMON_RETURN_SELF; }
16961772
static int vibrate( T* p, lua_State *L ) { p->SetEffectVibrate(Rage::Vector3(10,10,10)); COMMON_RETURN_SELF; }
16971773
static int stopeffect( T* p, lua_State *L ) { p->StopEffect(); COMMON_RETURN_SELF; }
1698-
static int effectcolor1( T* p, lua_State *L ) { RageColor c; c.FromStackCompat( L, 1 ); p->SetEffectColor1( c ); COMMON_RETURN_SELF; }
1699-
static int effectcolor2( T* p, lua_State *L ) { RageColor c; c.FromStackCompat( L, 1 ); p->SetEffectColor2( c ); COMMON_RETURN_SELF; }
1774+
static int effectcolor1( T* p, lua_State *L )
1775+
{
1776+
Rage::Color c;
1777+
FromStackCompat( c, L, 1 );
1778+
p->SetEffectColor1( c );
1779+
COMMON_RETURN_SELF;
1780+
}
1781+
static int effectcolor2( T* p, lua_State *L )
1782+
{
1783+
Rage::Color c;
1784+
FromStackCompat( c, L, 1 );
1785+
p->SetEffectColor2( c );
1786+
COMMON_RETURN_SELF;
1787+
}
17001788
static int effectperiod( T* p, lua_State *L )
17011789
{
17021790
float fPeriod = FArg(1);

0 commit comments

Comments
 (0)