Make autopackage work
[crack-attack.git] / src / ScoreRecordManager.cxx
blob81d7f9fde1684eca75e523c7a6b968f6cfb3d42e
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 using namespace std;
30 #include "Game.h"
31 #include "Displayer.h"
32 #include "MetaState.h"
33 #include "WinRecord.h"
34 #include "Score.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 ( )
50 top_rank = 0;
51 top_texture = 0;
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);
81 else
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
91 if (control_active) {
92 if (top_rank < DC_SCORE_REC_NUMBER_DRAW / 2 && offset < 0.0f) {
93 offset = -offset;
94 velocity = -DC_SCORE_REC_EDGE_BOUNCE_ELASTICITY * velocity;
95 ignore_up = true;
97 } else if (top_rank > GC_SCORE_REC_LENGTH - 1
98 + DC_SCORE_REC_NUMBER_DRAW / 2 && offset > 0.0f) {
99 offset = -offset;
100 velocity = -DC_SCORE_REC_EDGE_BOUNCE_ELASTICITY * velocity;
101 ignore_down = true;
105 offset += 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;
110 top_rank++;
112 top_texture--;
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;
125 top_rank--;
127 top_texture++;
128 if (top_texture == DC_SCORE_REC_NUMBER_DRAW)
129 top_texture = 0;
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);
148 // spring engages
149 if (!spring_active && r > 0.0f && !control_active)
150 spring_active = true;
152 // spring dynamics
153 if (spring_active) {
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) {
159 velocity = 0.0f;
160 offset = 0.0f;
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;
170 // control dynamics
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;