Fix warning.

WRAP is only safe for the int range, since it needs to cast to int to
negate; so only allow int.

When possible, use a (possibly templated) inline function instead of
a #define.
This commit is contained in:
Glenn Maynard
2003-09-01 02:04:16 +00:00
parent 985a040f49
commit 5b17149520
2 changed files with 11 additions and 4 deletions
+8 -1
View File
@@ -58,7 +58,14 @@ inline unsigned long max(unsigned long a, unsigned int b) { return a > b? a:b; }
#define CLAMP(x, l, h) {if (x > h) x = h; else if (x < l) x = l;}
#define WRAP(x, n) {if (x<0) x += ((-x/n)+1)*n; x = x%n;}
inline void wrap( int &x, int n)
{
if (x<0)
x += ((-x/n)+1)*n;
x %= n;
}
//-----------------------------------------------------------------------------
+3 -3
View File
@@ -250,13 +250,13 @@ void ScreenSelectCharacter::AfterValueChange( PlayerNumber pn )
for( int j=0; j<NUM_ATTACKS_PER_LEVEL; j++ )
m_AttackIcons[pnAffected][i][j].Load( pnAffected, pChar->m_sAttacks[i][j] );
unsigned c = m_iSelectedCharacter[pnAffected] - MAX_CHAR_ICONS_TO_SHOW/2;
WRAP( c, GAMESTATE->m_pCharacters.size() );
int c = m_iSelectedCharacter[pnAffected] - MAX_CHAR_ICONS_TO_SHOW/2;
wrap( c, GAMESTATE->m_pCharacters.size() );
for( unsigned i=0; i<MAX_CHAR_ICONS_TO_SHOW; i++ )
{
c++;
WRAP( c, GAMESTATE->m_pCharacters.size() );
wrap( c, GAMESTATE->m_pCharacters.size() );
Character* pCharacter = GAMESTATE->m_pCharacters[c];
Banner &banner = m_sprIcons[pnAffected][i];
banner.LoadIconFromCharacter( pCharacter );