summaryrefslogtreecommitdiff
blob: 17ca00467983be2cf7eec017d43d1a72e6360a1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
diff -u StepMania-3.9-src-orig/src/Difficulty.cpp StepMania-3.9-src/src/Difficulty.cpp
--- StepMania-3.9-src-orig/src/Difficulty.cpp	2004-07-11 09:21:29.000000000 +0200
+++ StepMania-3.9-src/src/Difficulty.cpp	2006-11-27 00:15:25.000000000 +0100
@@ -57,7 +57,7 @@
 
 CourseDifficulty GetNextShownCourseDifficulty( CourseDifficulty cd )
 {
-	for( CourseDifficulty d=(CourseDifficulty)(cd+1); d<NUM_DIFFICULTIES; ((int&)d)++ )
+	for( CourseDifficulty d=(CourseDifficulty)(cd+1); d<NUM_DIFFICULTIES; enum_add(d, 1) )
 	{
 		if( GAMESTATE->IsCourseDifficultyShown(d) )
 			return d;
diff -u StepMania-3.9-src-orig/src/PlayerNumber.cpp StepMania-3.9-src/src/PlayerNumber.cpp
--- StepMania-3.9-src-orig/src/PlayerNumber.cpp	2004-07-18 00:15:39.000000000 +0200
+++ StepMania-3.9-src/src/PlayerNumber.cpp	2006-11-27 00:15:25.000000000 +0100
@@ -22,41 +22,33 @@
 
 PlayerNumber GetNextHumanPlayer( PlayerNumber pn )
 {
-	for( PlayerNumber p=(PlayerNumber)(pn+1); p<NUM_PLAYERS; ((int&)p)++ )
-	{
-		if( GAMESTATE->IsHumanPlayer(p) )
-			return p;
-	}
+	for( enum_add(pn, 1); pn < NUM_PLAYERS; enum_add(pn, 1) )
+		if( GAMESTATE->IsHumanPlayer(pn) )
+			return pn;
 	return PLAYER_INVALID;
 }
 
 PlayerNumber GetNextEnabledPlayer( PlayerNumber pn )
 {
-	for( PlayerNumber p=(PlayerNumber)(pn+1); p<NUM_PLAYERS; ((int&)p)++ )
-	{
-		if( GAMESTATE->IsPlayerEnabled(p) )
-			return p;
-	}
+	for( enum_add(pn, 1); pn < NUM_PLAYERS; enum_add(pn, 1) )
+		if( GAMESTATE->IsPlayerEnabled(pn) )
+			return pn;
 	return PLAYER_INVALID;
 }
 
 PlayerNumber GetNextCpuPlayer( PlayerNumber pn )
 {
-	for( PlayerNumber p=(PlayerNumber)(pn+1); p<NUM_PLAYERS; ((int&)p)++ )
-	{
-		if( GAMESTATE->IsCpuPlayer(p) )
-			return p;
-	}
+	for( enum_add(pn, 1); pn < NUM_PLAYERS; enum_add(pn, 1) )
+		if( GAMESTATE->IsCpuPlayer(pn) )
+			return pn;
 	return PLAYER_INVALID;
 }
 
 PlayerNumber GetNextPotentialCpuPlayer( PlayerNumber pn )
 {
-	for( PlayerNumber p=(PlayerNumber)(pn+1); p<NUM_PLAYERS; ((int&)p)++ )
-	{
-		if( !GAMESTATE->IsHumanPlayer(p) )
-			return p;
-	}
+	for( enum_add(pn, 1); pn < NUM_PLAYERS; enum_add(pn, 1) )
+		if( !GAMESTATE->IsHumanPlayer(pn) )
+			return pn;
 	return PLAYER_INVALID;
 }
 
diff -u StepMania-3.9-src-orig/src/RageUtil.h StepMania-3.9-src/src/RageUtil.h
--- StepMania-3.9-src-orig/src/RageUtil.h	2004-10-07 19:56:16.000000000 +0200
+++ StepMania-3.9-src/src/RageUtil.h	2006-11-27 00:15:25.000000000 +0100
@@ -53,6 +53,14 @@
 	return false;
 }
 
+template<class T>
+inline bool ENUM_CLAMP( T &x, T l, T h )
+{
+	if (x > h)	{ x = h; return true; }
+	else if (x < l) { x = l; return true; }
+	return false;
+}
+
 inline void wrap( int &x, int n)
 {
 	if (x<0)
diff -u StepMania-3.9-src-orig/src/ScreenBookkeeping.cpp StepMania-3.9-src/src/ScreenBookkeeping.cpp
--- StepMania-3.9-src-orig/src/ScreenBookkeeping.cpp	2004-08-22 18:28:19.000000000 +0200
+++ StepMania-3.9-src/src/ScreenBookkeeping.cpp	2006-11-27 00:15:25.000000000 +0100
@@ -74,14 +74,14 @@
 void ScreenBookkeeping::MenuLeft( PlayerNumber pn )
 {
 	m_View = (View)(m_View-1);
-	CLAMP( (int&)m_View, 0, NUM_VIEWS-1 );
+	ENUM_CLAMP( m_View, View(0), View(NUM_VIEWS-1) );
 	ChangeView( m_View );
 }
 
 void ScreenBookkeeping::MenuRight( PlayerNumber pn )
 {
 	m_View = (View)(m_View+1);
-	CLAMP( (int&)m_View, 0, NUM_VIEWS-1 );
+	ENUM_CLAMP( m_View, View(0), View(NUM_VIEWS-1) );
 	ChangeView( m_View );
 }
 
diff -u StepMania-3.9-src-orig/src/ScreenSetTime.cpp StepMania-3.9-src/src/ScreenSetTime.cpp
--- StepMania-3.9-src-orig/src/ScreenSetTime.cpp	2004-08-31 10:29:34.000000000 +0200
+++ StepMania-3.9-src/src/ScreenSetTime.cpp	2006-11-27 00:15:25.000000000 +0100
@@ -160,7 +160,7 @@
 	SetTimeSelection OldSelection = m_Selection;
 	enum_add<SetTimeSelection>( m_Selection, iDirection );
 
-	CLAMP( (int&)m_Selection, 0, NUM_SET_TIME_SELECTIONS-1 );
+	ENUM_CLAMP( m_Selection, SetTimeSelection(0), SetTimeSelection(NUM_SET_TIME_SELECTIONS-1) );
 	if( iDirection != 0 && m_Selection == OldSelection )
 		return; // can't move any more
 
diff -u StepMania-3.9-src-orig/src/Song.cpp StepMania-3.9-src/src/Song.cpp
--- StepMania-3.9-src-orig/src/Song.cpp	2004-12-20 23:25:12.000000000 +0100
+++ StepMania-3.9-src/src/Song.cpp	2006-11-27 00:15:25.000000000 +0100
@@ -916,22 +916,22 @@
 	if( pSteps )
 		return pSteps;
 	newDC = (Difficulty)(dc-1);
-	CLAMP( (int&)newDC, 0, NUM_DIFFICULTIES-1 );
+	ENUM_CLAMP( newDC, Difficulty(0), Difficulty(NUM_DIFFICULTIES-1) );
 	pSteps = GetStepsByDifficulty( st, newDC );
 	if( pSteps )
 		return pSteps;
 	newDC = (Difficulty)(dc+1);
-	CLAMP( (int&)newDC, 0, NUM_DIFFICULTIES-1 );
+	ENUM_CLAMP( newDC, Difficulty(0), Difficulty(NUM_DIFFICULTIES-1) );
 	pSteps = GetStepsByDifficulty( st, newDC );
 	if( pSteps )
 		return pSteps;
 	newDC = (Difficulty)(dc-2);
-	CLAMP( (int&)newDC, 0, NUM_DIFFICULTIES-1 );
+	ENUM_CLAMP( newDC, Difficulty(0), Difficulty(NUM_DIFFICULTIES-1) );
 	pSteps = GetStepsByDifficulty( st, newDC );
 	if( pSteps )
 		return pSteps;
 	newDC = (Difficulty)(dc+2);
-	CLAMP( (int&)newDC, 0, NUM_DIFFICULTIES-1 );
+	ENUM_CLAMP( newDC, Difficulty(0), Difficulty(NUM_DIFFICULTIES-1) );
 	pSteps = GetStepsByDifficulty( st, newDC );
 	return pSteps;
 }