2 * ScoreRecordManager.cxx
3 * Daniel Nelson - 12/8/1
5 * Copyright (C) 2000 Daniel Nelson
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * Daniel Nelson - aluminumangel.org
25 * Handles the complexities of displaying the score record.
31 #include "Displayer.h"
32 #include "MetaState.h"
33 #include "WinRecord.h"
35 #include "Controller.h"
36 #include "ScoreRecordManager.h"
38 int ScoreRecordManager::top_rank
;
39 int ScoreRecordManager::top_texture
;
40 GLfloat
ScoreRecordManager::offset
;
41 GLfloat
ScoreRecordManager::velocity
;
43 bool ScoreRecordManager::spring_active
;
44 bool ScoreRecordManager::control_active
;
45 bool ScoreRecordManager::ignore_up
;
46 bool ScoreRecordManager::ignore_down
;
48 void ScoreRecordManager::initialize ( )
52 offset
= -DC_SCORE_REC_RANK_HEIGHT
/ 2.0f
;
53 velocity
= DC_SCORE_REC_START_VELOCITY
;
55 spring_active
= false;
56 control_active
= false;
57 ignore_up
= ignore_down
= false;
60 void ScoreRecordManager::gameFinish_inline_split_ ( )
62 Displayer::generateScoreRankTexture(Score::player_rank
, Score::score
,
63 MetaState::player_name
, Displayer::player_rank_texture_data
);
65 Displayer::rerankScoreRecord();
67 glGenTextures(DC_SCORE_REC_NUMBER_DRAW
, Displayer::record_textures
);
69 for (int n
= DC_SCORE_REC_NUMBER_DRAW
; n
--; ) {
70 glBindTexture(GL_TEXTURE_2D
, Displayer::record_textures
[n
]);
72 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
73 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
74 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
75 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
77 if (Score::player_rank
== 0)
78 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, DC_SCORE_REC_TEX_LENGTH_S
,
79 DC_LETTER_TEX_LENGTH
, GL_FALSE
, GL_RGBA
, GL_UNSIGNED_BYTE
,
80 Displayer::player_rank_texture_data
);
82 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, DC_SCORE_REC_TEX_LENGTH_S
,
83 DC_LETTER_TEX_LENGTH
, GL_FALSE
, GL_RGBA
, GL_UNSIGNED_BYTE
,
84 Displayer::record_texture_data
[0]);
88 void ScoreRecordManager::timeStep_inline_split_ ( )
90 // bounce off the edges
92 if (top_rank
< DC_SCORE_REC_NUMBER_DRAW
/ 2 && offset
< 0.0f
) {
94 velocity
= -DC_SCORE_REC_EDGE_BOUNCE_ELASTICITY
* velocity
;
97 } else if (top_rank
> GC_SCORE_REC_LENGTH
- 1
98 + DC_SCORE_REC_NUMBER_DRAW
/ 2 && offset
> 0.0f
) {
100 velocity
= -DC_SCORE_REC_EDGE_BOUNCE_ELASTICITY
* velocity
;
107 // switch in a new texture when needed
108 if (offset
> DC_SCORE_REC_RANK_HEIGHT
/ 2.0f
) {
109 offset
-= DC_SCORE_REC_RANK_HEIGHT
;
113 if (top_texture
== -1)
114 top_texture
= DC_SCORE_REC_NUMBER_DRAW
- 1;
116 if (top_rank
< GC_SCORE_REC_LENGTH
) {
117 glBindTexture(GL_TEXTURE_2D
, Displayer::record_textures
[top_texture
]);
118 glTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, DC_SCORE_REC_TEX_LENGTH_S
,
119 DC_LETTER_TEX_LENGTH
, GL_RGBA
, GL_UNSIGNED_BYTE
,
120 chooseTexture(top_rank
));
123 } else if (offset
< -DC_SCORE_REC_RANK_HEIGHT
/ 2.0f
) {
124 offset
+= DC_SCORE_REC_RANK_HEIGHT
;
128 if (top_texture
== DC_SCORE_REC_NUMBER_DRAW
)
131 if (top_rank
>= DC_SCORE_REC_NUMBER_DRAW
- 1) {
132 int bottom_texture
= top_texture
- 1;
133 if (bottom_texture
== -1)
134 bottom_texture
= DC_SCORE_REC_NUMBER_DRAW
- 1;
136 glBindTexture(GL_TEXTURE_2D
, Displayer::record_textures
[bottom_texture
]);
137 glTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, DC_SCORE_REC_TEX_LENGTH_S
,
138 DC_LETTER_TEX_LENGTH
, GL_RGBA
, GL_UNSIGNED_BYTE
,
139 chooseTexture(top_rank
- (DC_SCORE_REC_NUMBER_DRAW
- 1)));
143 // score record dynamics
145 GLfloat r
= offset
+ DC_SCORE_REC_RANK_HEIGHT
146 * (top_rank
- Score::player_rank
- DC_SCORE_REC_NUMBER_DRAW
/ 2);
149 if (!spring_active
&& r
> 0.0f
&& !control_active
)
150 spring_active
= true;
154 velocity
+= -DC_SCORE_REC_SPRING
* r
155 - DC_SCORE_REC_SPRING_DRAG
* velocity
;
157 if (fabs(velocity
) < DC_SCORE_REC_VELOCITY_CUTOFF
158 && fabs(r
) < DC_SCORE_REC_OFFSET_CUTOFF
) {
161 spring_active
= false;
165 // user gains control
166 if (!control_active
&& fabs(velocity
) < DC_SCORE_REC_CONTROL_VELOCITY_CUTOFF
167 && fabs(r
) < DC_SCORE_REC_CONTROL_OFFSET_CUTOFF
)
168 control_active
= true;
171 if (control_active
) {
172 if ((ignore_up
|| ignore_down
)
173 && fabs(velocity
) < DC_SCORE_REC_BOUNCE_VELOCITY_CUTOFF
)
174 ignore_up
= ignore_down
= false;
176 if ((Controller::moveCommand() & CC_UP
) && !ignore_up
) {
177 velocity
-= DC_SCORE_REC_CONTROL_VELOCITY
;
178 spring_active
= false;
180 if ((Controller::moveCommand() & CC_DOWN
) && !ignore_down
) {
181 velocity
+= DC_SCORE_REC_CONTROL_VELOCITY
;
182 spring_active
= false;
185 velocity
+= -DC_SCORE_REC_CONTROL_DRAG
* velocity
;