From 5b17149520c755212afe4c71ae08813fd84b7fc2 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 1 Sep 2003 02:04:16 +0000 Subject: [PATCH] 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. --- stepmania/src/RageUtil.h | 9 ++++++++- stepmania/src/ScreenSelectCharacter.cpp | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/stepmania/src/RageUtil.h b/stepmania/src/RageUtil.h index e80ce0a98b..b937ab0740 100644 --- a/stepmania/src/RageUtil.h +++ b/stepmania/src/RageUtil.h @@ -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; +} + //----------------------------------------------------------------------------- diff --git a/stepmania/src/ScreenSelectCharacter.cpp b/stepmania/src/ScreenSelectCharacter.cpp index 0f7b4b1ff5..1f939fa7b5 100644 --- a/stepmania/src/ScreenSelectCharacter.cpp +++ b/stepmania/src/ScreenSelectCharacter.cpp @@ -250,13 +250,13 @@ void ScreenSelectCharacter::AfterValueChange( PlayerNumber pn ) for( int j=0; jm_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; im_pCharacters.size() ); + wrap( c, GAMESTATE->m_pCharacters.size() ); Character* pCharacter = GAMESTATE->m_pCharacters[c]; Banner &banner = m_sprIcons[pnAffected][i]; banner.LoadIconFromCharacter( pCharacter );