{
case spin:
m_current.rotation += m_fEffectDelta*m_vEffectMagnitude;
- wrap( m_current.rotation.x, 360 );
- wrap( m_current.rotation.y, 360 );
- wrap( m_current.rotation.z, 360 );
+ wrap( m_current.rotation.x, 360.0f );
+ wrap( m_current.rotation.y, 360.0f );
+ wrap( m_current.rotation.z, 360.0f );
break;
}
return false;
}
-inline void wrap( int &x, int n )
+template<typename T>
+inline void wrap( T &x, T n )
{
- if (x<0)
- x += ((-x/n)+1)*n;
- x %= n;
+ int xi = x;
+ if (xi<0)
+ xi += ((-xi/n)+1)*n;
+ xi %= n;
+ x = static_cast<T>(xi);
}
-inline void wrap( unsigned &x, unsigned n )
+
+template<>
+inline void wrap<unsigned>( unsigned &x, unsigned n )
{
x %= n;
}
-inline void wrap( float &x, float n )
+
+template<>
+inline void wrap<float>( float &x, float n )
{
if (x<0)
x += truncf(((-x/n)+1))*n;
x = fmodf(x,n);
}
+inline void wrap( int &x, size_t n )
+{
+ wrap<int>(x, n);
+}
+
inline float fracf( float f ) { return f - truncf(f); }
template<class T>
BitmapText &txt2 = m_textFunction[i];
- int iWrap;
-
switch( i )
{
case DebugLine_Autoplay:
{
PlayerController pc = (PlayerController)(PREFSMAN->m_AutoPlay+1);
- iWrap = (int)pc;
- wrap( iWrap, NUM_PLAYER_CONTROLLERS );
- pc = (PlayerController)iWrap;
+ wrap( pc, NUM_PLAYER_CONTROLLERS );
PREFSMAN->m_AutoPlay.Set( pc );
FOREACH_HumanPlayer(pn)
GAMESTATE->m_pPlayerState[pn]->m_PlayerController = PREFSMAN->m_AutoPlay;
if( type != IET_FIRST_PRESS )
return true; /* eat the input but do nothing */
SongOptions::AutosyncType as = (SongOptions::AutosyncType)(GAMESTATE->m_SongOptions.m_AutosyncType+1);
- iWrap = (int)as;
- wrap( iWrap, SongOptions::NUM_AUTOSYNC_TYPES );
- as = (SongOptions::AutosyncType)iWrap;
+ wrap( as, SongOptions::NUM_AUTOSYNC_TYPES );
GAMESTATE->m_SongOptions.m_AutosyncType = as;
MESSAGEMAN->Broadcast( MESSAGE_AUTOSYNC_CHANGED );
}
case DebugLine_CoinMode:
{
CoinMode cm = (CoinMode)(PREFSMAN->m_CoinMode+1);
- iWrap = (int)cm;
- wrap( iWrap, NUM_COIN_MODES );
- cm = (CoinMode)iWrap;
+ wrap( cm, NUM_COIN_MODES );
PREFSMAN->m_CoinMode.Set( cm );
SCREENMAN->RefreshCreditsMessages();
}
do
{
m_iFocusY = (KeyboardRow)(m_iFocusY + iDir);
- wrap( (int&)m_iFocusY, NUM_KEYBOARD_ROWS );
+ wrap( m_iFocusY, NUM_KEYBOARD_ROWS );
// HACK: Round to nearest option so that we always stop
// on KEYBOARD_ROW_SPECIAL.