Refactorizations:

- Removed several unused variables
- Use int instead of float instead of double where appropriate
- Fixed keymapping in credits screen (u disables UI snow, not Tab)

git-svn-id: https://svn.code.sf.net/p/extremetuxracer/code/trunk@455 0420edf4-82e4-42fc-9478-35b55e6d67a3
master
pkeus 2013-09-30 15:26:28 +00:00
parent 265d258f4e
commit 7895b95675
22 changed files with 83 additions and 145 deletions

View File

@ -150,8 +150,7 @@ void CGameConfig::Motion (int x, int y) {
// ------------------ Init --------------------------------------------
static TArea area;
static int framewidth, frameheight;
static int dd, rightpos;
static int dd;
void CGameConfig::Enter() {
Winsys.ShowCursor (!param.ice_cursor);
@ -161,13 +160,12 @@ void CGameConfig::Enter() {
for (int i=0; i<NUM_RESOLUTIONS; i++) res_names[i] = Winsys.GetResName (i);
framewidth = 550 * Winsys.scale;
frameheight = 50 * Winsys.scale;
int framewidth = 550 * Winsys.scale;
area = AutoAreaN (30, 80, framewidth);
FT.AutoSizeN (4);
dd = FT.AutoDistanceN (3);
if (dd < 36) dd = 36;
rightpos = area.right -48;
int rightpos = area.right -48;
ResetGUI ();
fullscreen = AddCheckbox (area.left, area.top, framewidth-16, Trans.Text(31));

View File

@ -33,8 +33,8 @@ GNU General Public License for more details.
static const bool clip_course = true;
void setup_course_tex_gen () {
static GLfloat xplane[4] = {1.0 / TEX_SCALE, 0.0, 0.0, 0.0 };
static GLfloat zplane[4] = {0.0, 0.0, 1.0 / TEX_SCALE, 0.0 };
static const GLfloat xplane[4] = {1.0 / TEX_SCALE, 0.0, 0.0, 0.0 };
static const GLfloat zplane[4] = {0.0, 0.0, 1.0 / TEX_SCALE, 0.0 };
glTexGenfv (GL_S, GL_OBJECT_PLANE, xplane);
glTexGenfv (GL_T, GL_OBJECT_PLANE, zplane);
}
@ -88,8 +88,8 @@ void DrawTrees() {
glTranslate(treeLocs[i].pt);
if (param.perf_level > 1) glRotatef (1, 0, 1, 0);
double treeRadius = treeLocs[i].diam / 2.0;
double treeHeight = treeLocs[i].height;
float treeRadius = treeLocs[i].diam / 2.0;
float treeHeight = treeLocs[i].height;
glNormal3i(0, 0, 1);
static const GLshort tex[] = {

View File

@ -63,8 +63,8 @@ void CCredits::LoadCreditList () {
}
void CCredits::DrawCreditsText (double time_step) {
double w = (double)Winsys.resolution.width;
double h = (double)Winsys.resolution.height;
int w = Winsys.resolution.width;
int h = Winsys.resolution.height;
double offs = 0.0;
if (moving) y_offset += time_step * 30;
@ -85,25 +85,25 @@ void CCredits::DrawCreditsText (double time_step) {
glDisable (GL_TEXTURE_2D);
glColor(colBackgr);
glRectf (0, 0, w, BOTT_Y);
glRecti (0, 0, w, BOTT_Y);
glBegin( GL_QUADS );
glVertex2f (0, BOTT_Y);
glVertex2f (w, BOTT_Y);
glVertex2i(0, BOTT_Y);
glVertex2i(w, BOTT_Y);
glColor(colBackgr, 0);
glVertex2f (w, BOTT_Y + 30);
glVertex2f (0, BOTT_Y + 30);
glVertex2i(w, BOTT_Y + 30);
glVertex2i(0, BOTT_Y + 30);
glEnd();
glColor(colBackgr);
glRectf (0, h - TOP_Y, w, h);
glRecti (0, h - TOP_Y, w, h);
glBegin( GL_QUADS );
glVertex2f (w, h - TOP_Y);
glVertex2f (0, h - TOP_Y);
glVertex2i(w, h - TOP_Y);
glVertex2i(0, h - TOP_Y);
glColor(colBackgr, 0);
glVertex2f (0, h - TOP_Y - 30);
glVertex2f (w, h - TOP_Y - 30);
glVertex2i(0, h - TOP_Y - 30);
glVertex2i (w, h - TOP_Y - 30);
glEnd();
glColor4f (1, 1, 1, 1);
@ -111,58 +111,13 @@ void CCredits::DrawCreditsText (double time_step) {
if (offs < TOP_Y) y_offset = 0;
}
static void DrawBackLogo (int x, int y, double size) {
GLint w, h;
GLfloat width, height, top, bott, left, right;
glEnable (GL_TEXTURE_2D);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Tex.GetTexture(T_TITLE)->Bind();
glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
width = w * size;
height = h * size;
top = Winsys.resolution.height - y;
bott = top - height;
if (x >= 0) left = x;
else left = (Winsys.resolution.width - width) / 2;
right = left + width;
glColor4f(1.0, 1.0, 1.0, 0.4);
static const GLshort tex[] = {
0, 0,
1, 0,
1, 1,
0, 1
};
const GLfloat vtx[] = {
left, bott,
right, bott,
right, top,
left, top
};
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, vtx);
glTexCoordPointer(2, GL_SHORT, 0, tex);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
}
void CCredits::Keyb (unsigned int key, bool special, bool release, int x, int y) {
if (release) return;
switch (key) {
case 109:
case SDLK_m:
moving = !moving;
break;
case 9:
case SDLK_u:
param.ui_snow = !param.ui_snow;
break;
default:
@ -194,7 +149,6 @@ void CCredits::Loop(double time_step) {
ScopedRenderMode rm(GUI);
SetupGuiDisplay ();
// DrawBackLogo (-1, AutoYPos (200), 1.0);
DrawCreditsText (time_step);
if (param.ui_snow) {
update_ui_snow (time_step);

View File

@ -345,8 +345,8 @@ void CEnvironment::DrawFog () {
// only the alpha channel is used
static const GLfloat bottom_dens[4] = {0, 0, 0, 1.0};
static const GLfloat top_dens[4] = { 0, 0, 0, 0.9 };
static const GLfloat leftright_dens[4] = { 0, 0, 0, 0.3 };
static const GLfloat top_dens[4] = { 0, 0, 0, 0.9 };
static const GLfloat leftright_dens[4] = { 0, 0, 0, 0.3 };
static const GLfloat top_bottom_dens[4] = { 0, 0, 0, 0.0 };
glBegin (GL_QUAD_STRIP);

View File

@ -65,8 +65,8 @@ void CGameOver::Mouse (int button, int state, int x, int y) {
void GameOverMessage (const CControl *ctrl) {
int fwidth = 500;
float leftframe = (Winsys.resolution.width - fwidth) / 2;
float topframe = 80;
int leftframe = (Winsys.resolution.width - fwidth) / 2;
int topframe = 80;
const TColor& backcol = colWhite;
static const TColor framecol(0.7, 0.7, 1, 1);
@ -193,9 +193,8 @@ void CGameOver::Enter() {
void CGameOver::Loop(double time_step) {
CControl *ctrl = Players.GetCtrl (g_game.player_id);
int width, height;
width = Winsys.resolution.width;
height = Winsys.resolution.height;
int width = Winsys.resolution.width;
int height = Winsys.resolution.height;
check_gl_error();
Music.Update ();

View File

@ -718,8 +718,7 @@ TArea AutoAreaN (double top_perc, double bott_perc, int w) {
res.top = AutoYPosN (top_perc);
res.bottom = AutoYPosN (bott_perc);
if (w > Winsys.resolution.width) w = Winsys.resolution.width;
double left = (Winsys.resolution.width - w) / 2;
res.left = (int) left;
res.left = (Winsys.resolution.width - w) / 2;
res.right = Winsys.resolution.width - res.left;
return res;
}

View File

@ -31,7 +31,7 @@ GNU General Public License for more details.
CHelp Help;
static int xleft1, xleft2, ytop;
static int ytop;
void CHelp::Keyb(unsigned int key, bool special, bool release, int x, int y) {
State::manager.RequestEnterState (GameTypeSelect);
@ -49,8 +49,6 @@ void CHelp::Enter() {
Winsys.ShowCursor (false);
Music.Play (param.credits_music, -1);
xleft1 = 40;
xleft2 = (int)(Winsys.resolution.width / 2) + 20;
ytop = AutoYPosN (15);
}
@ -67,7 +65,8 @@ void CHelp::Loop(double timestep) {
}
FT.AutoSizeN (4);
FT.SetColor (colWhite);
FT.SetColor(colWhite);
const int xleft1 = 40;
FT.DrawString (xleft1, AutoYPosN (5), Trans.Text (57));
FT.AutoSizeN (3);

View File

@ -221,15 +221,15 @@ void draw_gauge (double speed, double energy) {
glColor4fv (hud_white);
Tex.BindTex(GAUGE_OUTLINE);
const GLfloat vtx3 [] = {
0.0, 0.0,
GAUGE_IMG_SIZE, 0.0,
static const GLshort vtx3 [] = {
0, 0,
GAUGE_IMG_SIZE, 0,
GAUGE_IMG_SIZE, GAUGE_IMG_SIZE,
0.0, GAUGE_IMG_SIZE
0, GAUGE_IMG_SIZE
};
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, vtx3);
glVertexPointer(2, GL_SHORT, 0, vtx3);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
@ -247,7 +247,7 @@ void DrawSpeed (double speed) {
}
}
void DrawWind (double dir, double speed) {
void DrawWind(float dir, float speed) {
Tex.Draw (SPEEDMETER, 10, Winsys.resolution.height - 150, 1.0);
glPushMatrix ();
glDisable (GL_TEXTURE_2D);
@ -276,8 +276,7 @@ void DrawWind2 (float dir, float speed, const CControl *ctrl) {
glDisable (GL_TEXTURE_2D);
float alpha, red, blue, len;
len = 45;
float alpha, red, blue;
if (speed <= 50) {
alpha = speed / 50;
red = 0;
@ -292,32 +291,30 @@ void DrawWind2 (float dir, float speed, const CControl *ctrl) {
glTranslatef (72, 66, 0);
glRotatef(dir, 0, 0, 1);
glEnableClientState(GL_VERTEX_ARRAY);
const GLfloat vtx1 [] = {
static const int len = 45;
static const GLshort vtx1 [] = {
-5, 0.0,
5, 0.0,
5, -len,
- 5, -len
};
glVertexPointer(2, GL_FLOAT, 0, vtx1);
glVertexPointer(2, GL_SHORT, 0, vtx1);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glPopMatrix ();
// direction indicator
TVector3 movdir = ctrl->cvel;
NormVector (movdir);
float dir_angle = atan (movdir.x / movdir.z) * 57.3;
glPushMatrix ();
glColor4f (0, 0.5, 0, 1.0);
glTranslatef (72, 66, 0);
glRotatef (dir_angle + 180, 0, 0, 1);
const GLfloat vtx2 [] = {
-2, 0.0,
2, 0.0,
glRotatef (dir_angle + 180 - dir, 0, 0, 1);
static const GLshort vtx2 [] = {
-2, 0,
2, 0,
2, -50,
-2, -50
};
glVertexPointer(2, GL_FLOAT, 0, vtx2);
glVertexPointer(2, GL_SHORT, 0, vtx2);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix ();
@ -405,8 +402,7 @@ void DrawHud (const CControl *ctrl) {
if (!param.show_hud)
return;
TVector3 vel = ctrl->cvel;
double speed = NormVector (vel);
double speed = VectorLength(ctrl->cvel);
SetupGuiDisplay ();
draw_gauge (speed * 3.6, ctrl->jump_amt);
@ -417,5 +413,5 @@ void DrawHud (const CControl *ctrl) {
DrawSpeed (speed * 3.6);
DrawFps ();
DrawCoursePosition (ctrl);
if (g_game.wind_id > 0) DrawWind2 (Wind.Angle (), Wind.Speed (), ctrl);
DrawWind2 (Wind.Angle (), Wind.Speed (), ctrl);
}

View File

@ -79,7 +79,7 @@ void CNewPlayer::Motion (int x, int y) {
if (param.ui_snow) push_ui_snow (cursor_pos);
}
static int prevleft, prevtop, prevwidth, prevoffs;
static int prevleft, prevtop, prevwidth;
void CNewPlayer::Enter() {
Winsys.KeyRepeat (true);
@ -89,11 +89,11 @@ void CNewPlayer::Enter() {
int framewidth = 400 * Winsys.scale;
int frameheight = 50 * Winsys.scale;
int frametop = AutoYPosN (38);
TArea area = AutoAreaN (30, 80, framewidth);
prevleft = area.left;
TArea area = AutoAreaN(30, 80, framewidth);
int prevoffs = 80;
prevleft = area.left + prevoffs;
prevtop = AutoYPosN (52);
prevwidth = 75 * Winsys.scale;
prevoffs = 80;
ResetGUI();
@ -140,7 +140,7 @@ void CNewPlayer::Loop(double timestep) {
if (avatar->focussed()) col = colDYell;
else col = colWhite;
Players.GetAvatarTexture(avatar->GetValue())->DrawFrame(
prevleft + prevoffs, prevtop, prevwidth, prevwidth, 2, col);
prevleft, prevtop, prevwidth, prevwidth, 2, col);
DrawGUI();
Winsys.SwapBuffers();

View File

@ -127,7 +127,7 @@ void PrintGLInfo () {
}
}
void set_material (const TColor& diffuse_colour, const TColor& specular_colour, double specular_exp) {
void set_material (const TColor& diffuse_colour, const TColor& specular_colour, float specular_exp) {
GLfloat mat_amb_diff[4] = {
static_cast<GLfloat>(diffuse_colour.r),
static_cast<GLfloat>(diffuse_colour.g),
@ -163,7 +163,7 @@ void ClearRenderContext (const TColor& col) {
}
void SetupGuiDisplay () {
double offset = 0.0;
static const float offset = 0.f;
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();

View File

@ -50,7 +50,7 @@ void PrintGLInfo();
void set_material (const TColor& diffuse_colour,
const TColor& specular_colour,
double specular_exp);
float specular_exp);
void PushRenderMode(TRenderMode mode);

View File

@ -215,7 +215,7 @@ void draw_ui_snow () {
glDisableClientState(GL_VERTEX_ARRAY);
}
void push_ui_snow (const TVector2& pos) {
void push_ui_snow (const TVector2i& pos) {
push_position = TVector2(pos.x/(double)Winsys.resolution.width, 1.0 - pos.y/(double)Winsys.resolution.height);
if (!push_position_initialized) last_push_position = push_position;
push_position_initialized = true;

View File

@ -27,7 +27,7 @@ GNU General Public License for more details.
void init_ui_snow ();
void update_ui_snow (double time_step);
void push_ui_snow (const TVector2& pos);
void push_ui_snow (const TVector2i& pos);
void draw_ui_snow ();
// --------------------------------------------------------------------

View File

@ -136,7 +136,6 @@ void CRaceSelect::Keyb(unsigned int key, bool special, bool release, int x, int
static TArea area;
static int framewidth, frameheight, frametop;
static int prevtop, prevwidth, prevheight;
static int icontop, iconsize, iconspace, iconleft, iconsumwidth;
static int boxleft, boxwidth;
void CRaceSelect::Enter() {
@ -155,11 +154,11 @@ void CRaceSelect::Enter() {
prevwidth = 192 * Winsys.scale;
boxwidth = framewidth - prevwidth - 20;
boxleft = area.right - boxwidth;
icontop = AutoYPosN (40);
iconsize = 32 * Winsys.scale;
iconspace = (int)((iconsize+6) * 1.5);
iconsumwidth = iconspace * 4 + iconsize;
iconleft = (Winsys.resolution.width - iconsumwidth) / 2;
int icontop = AutoYPosN(40);
int iconsize = 32 * Winsys.scale;
int iconspace = (int) ((iconsize + 6) * 1.5);
int iconsumwidth = iconspace * 4 + iconsize;
int iconleft = (Winsys.resolution.width - iconsumwidth) / 2;
ResetGUI ();

View File

@ -81,21 +81,20 @@ void CRegist::Motion (int x, int y) {
if (param.ui_snow) push_ui_snow (cursor_pos);
}
static int framewidth, frameheight, arrowwidth, sumwidth;
static int framewidth, frameheight, arrowwidth;
static TArea area;
static double scale, texsize;
static double texsize;
void CRegist::Enter (void) {
Winsys.ShowCursor (!param.ice_cursor);
Music.Play (param.menu_music, -1);
scale = Winsys.scale;
framewidth = (int)(scale * 280);
frameheight = (int)(scale * 50);
framewidth = (int) (Winsys.scale * 280);
frameheight = (int) (Winsys.scale * 50);
arrowwidth = 50;
sumwidth = framewidth * 2 + arrowwidth * 2;
int sumwidth = framewidth * 2 + arrowwidth * 2;
area = AutoAreaN (30, 80, sumwidth);
texsize = 128 * scale;
texsize = 128 * Winsys.scale;
ResetGUI ();
player = AddUpDown(area.left + framewidth + 8, area.top, 0, (int)Players.numPlayers() - 1, (int)g_game.start_player);
@ -127,7 +126,7 @@ void CRegist::Loop (double timestep) {
Tex.Draw (BOTTOM_RIGHT, ww-256, hh-256, 1);
Tex.Draw (TOP_LEFT, 0, 0, 1);
Tex.Draw (TOP_RIGHT, ww-256, 0, 1);
Tex.Draw (T_TITLE_SMALL, CENTER, AutoYPosN (5), scale);
Tex.Draw(T_TITLE_SMALL, CENTER, AutoYPosN(5), Winsys.scale);
// DrawFrameX (area.left, area.top, area.right-area.left, area.bottom - area.top,
// 0, colMBackgr, col, 0.2);

View File

@ -150,7 +150,7 @@ int CScore::CalcRaceResult () {
if (g_game.time <= g_game.time_req.z &&
g_game.herring >= g_game.herring_req.k) g_game.race_result = 2;
double herringpt = g_game.herring * 10;
int herringpt = g_game.herring * 10;
double timept = Course.GetDimensions().y - (g_game.time * 10);
g_game.score = (int)(herringpt + timept);
if (g_game.score < 0) g_game.score = 0;

View File

@ -89,7 +89,7 @@ void State::Manager::PollEvent() {
break;
case SDL_MOUSEMOTION: {
TVector2 old = cursor_pos;
TVector2i old = cursor_pos;
cursor_pos.x = event.motion.x;
cursor_pos.y = event.motion.y;
current->Motion(event.motion.x-old.x, event.motion.y-old.y);

View File

@ -353,9 +353,7 @@ bool TTexture::LoadMipmap(const string& filename, bool repeatable) {
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
gluBuild2DMipmaps
(GL_TEXTURE_2D, texImage.depth, texImage.nx,
texImage.ny, format, GL_UNSIGNED_BYTE, texImage.data);
gluBuild2DMipmaps(GL_TEXTURE_2D, texImage.depth, texImage.nx, texImage.ny, format, GL_UNSIGNED_BYTE, texImage.data);
texImage.DisposeData();
return true;
@ -480,8 +478,8 @@ void TTexture::DrawFrame(int x, int y, double w, double h, int frame, const TCol
if (id < 1)
return;
GLint ww = GLint (w);
GLint hh = GLint (h);
GLint ww = GLint(w);
GLint hh = GLint(h);
GLint xx = x;
GLint yy = Winsys.resolution.height - hh - y;
@ -496,14 +494,14 @@ void TTexture::DrawFrame(int x, int y, double w, double h, int frame, const TCol
glColor(col, 1.0);
glDisable (GL_TEXTURE_2D);
const GLfloat vtx[] = {
const GLint vtx [] = {
xx - frame, yy - frame,
xx + ww + frame, yy - frame,
xx + ww + frame, yy + hh + frame,
xx - frame, yy + hh + frame
};
glVertexPointer(2, GL_FLOAT, 0, vtx);
glVertexPointer(2, GL_INT, 0, vtx);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glEnable (GL_TEXTURE_2D);

View File

@ -281,8 +281,8 @@ void CharMotion (int x, int y) {
xrotation = startrotx + diffy;
}
if (moveactive) {
float diffposx = (double)(cursor_pos.x - startx) / 200;
float diffposy = (double)(cursor_pos.y - starty) / 200;
float diffposx = (float)(cursor_pos.x - startx) / 200;
float diffposy = (float) (cursor_pos.y - starty) / 200;
yposition = startposy - diffposy;
xposition = startposx + diffposx;
}

View File

@ -209,10 +209,10 @@ void update_view (CControl *ctrl, double dt) {
TVector3 vel_dir = ctrl->cvel;
NormVector (vel_dir);
TVector3 view_vec = MakeViewVector();
switch (ctrl->viewmode) {
case BEHIND: {
TVector3 view_vec = MakeViewVector ();
TVector3 vel_proj = ProjectToPlane (y_vec, vel_dir);
NormVector (vel_proj);
TQuaternion rot_quat = MakeRotationQuaternion (mz_vec, vel_proj);
@ -257,8 +257,6 @@ void update_view (CControl *ctrl, double dt) {
}
case FOLLOW: { // normale Einstellung
TVector3 view_vec = MakeViewVector ();
TVector3 vel_proj = ProjectToPlane (y_vec, vel_dir);
NormVector (vel_proj);
TQuaternion rot_quat = MakeRotationQuaternion (mz_vec, vel_proj);
@ -303,7 +301,6 @@ void update_view (CControl *ctrl, double dt) {
}
case ABOVE: {
TVector3 view_vec = MakeViewVector ();
view_pt = AddVectors (ctrl->cpos, view_vec);
double ycoord = Course.FindYCoord (view_pt.x, view_pt.z);
if (view_pt.y < ycoord + MIN_CAMERA_HEIGHT) {

View File

@ -33,7 +33,7 @@ GNU General Public License for more details.
#define USE_JOYSTICK true
TVector2 cursor_pos(0, 0);
TVector2i cursor_pos(0, 0);
CWinsys Winsys;

View File

@ -23,7 +23,7 @@ GNU General Public License for more details.
#define NUM_RESOLUTIONS 10
extern TVector2 cursor_pos;
extern TVector2i cursor_pos;
struct TScreenRes {
int width, height;