Fixes for datatype size on amd64.
[crack-attack.git] / src / ScoreRecordManager.cxx
blobde89c45c05f522102ef427ecb3c5bf7c10149ff3
1 /*
2 * ScoreRecordManager.cxx
3 * Daniel Nelson - 12/8/1
5 * Copyright (C) 2000 Daniel Nelson
6 *
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
22 * 174 W. 18th Ave.
23 * Columbus, OH 43210
25 * Handles the complexities of displaying the score record.
28 #include "ScoreRecordManager.h"
30 #include "Game.h"
31 #include "Displayer.h"
32 #include "MetaState.h"
33 #include "WinRecord.h"
34 #include "Score.h"
35 #include "Controller.h"
37 int ScoreRecordManager::top_rank;
38 int ScoreRecordManager::top_texture;
39 GLfloat ScoreRecordManager::offset;
40 GLfloat ScoreRecordManager::velocity;
42 bool ScoreRecordManager::spring_active;
43 bool ScoreRecordManager::control_active;
44 bool ScoreRecordManager::ignore_up;
45 bool ScoreRecordManager::ignore_down;
47 void ScoreRecordManager::initialize ( )
49 top_rank = 0;
50 top_texture = 0;
51 offset = -DC_SCORE_REC_RANK_HEIGHT / 2.0f;
52 velocity = DC_SCORE_REC_START_VELOCITY;
54 spring_active = false;
55 control_active = false;
56 ignore_up = ignore_down = false;
59 void ScoreRecordManager::gameFinish_inline_split_ ( )
61 Displayer::generateScoreRankTexture(Score::player_rank, Score::score,
62 MetaState::player_name, Displayer::player_rank_texture_data);
64 Displayer::rerankScoreRecord();
66 glGenTextures(DC_SCORE_REC_NUMBER_DRAW, Displayer::record_textures);
68 for (int n = DC_SCORE_REC_NUMBER_DRAW; n--; ) {
69 glBindTexture(GL_TEXTURE_2D, Displayer::record_textures[n]);
71 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
72 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
73 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
74 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
76 if (Score::player_rank == 0)
77 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, DC_SCORE_REC_TEX_LENGTH_S,
78 DC_LETTER_TEX_LENGTH, GL_FALSE, GL_RGBA, GL_UNSIGNED_BYTE,
79 Displayer::player_rank_texture_data);
80 else
81 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, DC_SCORE_REC_TEX_LENGTH_S,
82 DC_LETTER_TEX_LENGTH, GL_FALSE, GL_RGBA, GL_UNSIGNED_BYTE,
83 Displayer::record_texture_data[0]);
87 void ScoreRecordManager::timeStep_inline_split_ ( )
89 // bounce off the edges
90 if (control_active) {
91 if (top_rank < DC_SCORE_REC_NUMBER_DRAW / 2 && offset < 0.0f) {
92 offset = -offset;
93 velocity = -DC_SCORE_REC_EDGE_BOUNCE_ELASTICITY * velocity;
94 ignore_up = true;
96 } else if (top_rank > GC_SCORE_REC_LENGTH - 1
97 + DC_SCORE_REC_NUMBER_DRAW / 2 && offset > 0.0f) {
98 offset = -offset;
99 velocity = -DC_SCORE_REC_EDGE_BOUNCE_ELASTICITY * velocity;
100 ignore_down = true;
104 offset += velocity;
106 // switch in a new texture when needed
107 if (offset > DC_SCORE_REC_RANK_HEIGHT / 2.0f) {
108 offset -= DC_SCORE_REC_RANK_HEIGHT;
109 top_rank++;
111 top_texture--;
112 if (top_texture == -1)
113 top_texture = DC_SCORE_REC_NUMBER_DRAW - 1;
115 if (top_rank < GC_SCORE_REC_LENGTH) {
116 glBindTexture(GL_TEXTURE_2D, Displayer::record_textures[top_texture]);
117 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, DC_SCORE_REC_TEX_LENGTH_S,
118 DC_LETTER_TEX_LENGTH, GL_RGBA, GL_UNSIGNED_BYTE,
119 chooseTexture(top_rank));
122 } else if (offset < -DC_SCORE_REC_RANK_HEIGHT / 2.0f) {
123 offset += DC_SCORE_REC_RANK_HEIGHT;
124 top_rank--;
126 top_texture++;
127 if (top_texture == DC_SCORE_REC_NUMBER_DRAW)
128 top_texture = 0;
130 if (top_rank >= DC_SCORE_REC_NUMBER_DRAW - 1) {
131 int bottom_texture = top_texture - 1;
132 if (bottom_texture == -1)
133 bottom_texture = DC_SCORE_REC_NUMBER_DRAW - 1;
135 glBindTexture(GL_TEXTURE_2D, Displayer::record_textures[bottom_texture]);
136 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, DC_SCORE_REC_TEX_LENGTH_S,
137 DC_LETTER_TEX_LENGTH, GL_RGBA, GL_UNSIGNED_BYTE,
138 chooseTexture(top_rank - (DC_SCORE_REC_NUMBER_DRAW - 1)));
142 // score record dynamics
144 GLfloat r = offset + DC_SCORE_REC_RANK_HEIGHT
145 * (top_rank - Score::player_rank - DC_SCORE_REC_NUMBER_DRAW / 2);
147 // spring engages
148 if (!spring_active && r > 0.0f && !control_active)
149 spring_active = true;
151 // spring dynamics
152 if (spring_active) {
153 velocity += -DC_SCORE_REC_SPRING * r
154 - DC_SCORE_REC_SPRING_DRAG * velocity;
156 if (fabs(velocity) < DC_SCORE_REC_VELOCITY_CUTOFF
157 && fabs(r) < DC_SCORE_REC_OFFSET_CUTOFF) {
158 velocity = 0.0f;
159 offset = 0.0f;
160 spring_active = false;
164 // user gains control
165 if (!control_active && fabs(velocity) < DC_SCORE_REC_CONTROL_VELOCITY_CUTOFF
166 && fabs(r) < DC_SCORE_REC_CONTROL_OFFSET_CUTOFF)
167 control_active = true;
169 // control dynamics
170 if (control_active) {
171 if ((ignore_up || ignore_down)
172 && fabs(velocity) < DC_SCORE_REC_BOUNCE_VELOCITY_CUTOFF)
173 ignore_up = ignore_down = false;
175 if ((Controller::moveCommand() & CC_UP) && !ignore_up) {
176 velocity -= DC_SCORE_REC_CONTROL_VELOCITY;
177 spring_active = false;
179 if ((Controller::moveCommand() & CC_DOWN) && !ignore_down) {
180 velocity += DC_SCORE_REC_CONTROL_VELOCITY;
181 spring_active = false;
184 velocity += -DC_SCORE_REC_CONTROL_DRAG * velocity;