From 334f1f865fde7123608a4c7363e33424464273d6 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 2 Nov 2011 12:46:16 +0200 Subject: [PATCH] Make wrap a template to avoid type-punning --- src/RageUtil.h | 11 +++++++---- src/ScreenTextEntry.cpp | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/RageUtil.h b/src/RageUtil.h index 476cd2b1..a5a566e8 100755 --- a/src/RageUtil.h +++ b/src/RageUtil.h @@ -56,11 +56,14 @@ inline bool CLAMP(float &x, float l, float h) return false; } -inline void wrap( int &x, int n ) +template +inline void wrap( T &x, int 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(xi); } inline void wrap( unsigned &x, unsigned n ) { diff --git a/src/ScreenTextEntry.cpp b/src/ScreenTextEntry.cpp index ce12642b..83352d0a 100755 --- a/src/ScreenTextEntry.cpp +++ b/src/ScreenTextEntry.cpp @@ -289,7 +289,7 @@ void ScreenTextEntry::MoveY( int iDir ) 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. -- 2.11.0