Fixed several cppcheck messages

git-svn-id: https://svn.code.sf.net/p/extremetuxracer/code/trunk@437 0420edf4-82e4-42fc-9478-35b55e6d67a3
master
pkeus 2013-09-03 11:14:32 +00:00
parent bbadb5adb2
commit 4c37a66b4e
17 changed files with 57 additions and 96 deletions

View File

@ -140,7 +140,6 @@ wstring CFont::UnicodeStr (const char *s) {
int CFont::LoadFont (const string& name, const char *path) {
fonts.push_back(new FTGLPixmapFont (path));
// fonts.push_back(new FTGLTextureFont (path));
if (fonts.back()->Error()) {
Message ("Failed to open font");
return -1;

View File

@ -188,7 +188,7 @@ void TCheckbox::Draw () const {
Tex.Draw (CHECKBOX, position.x + width - 32, position.y, 1.0);
if (checked)
Tex.Draw (CHECKMARK_SMALL, position.x + width - 32, position.y, 1.0);
if (focus == focus)
if (focus)
FT.SetColor (colDYell);
else
FT.SetColor (colWhite);

View File

@ -146,7 +146,6 @@ void draw_partial_tri_fan (double fraction) {
if (trifan) {
glEnd();
trifan = false;
}
}

View File

@ -442,13 +442,7 @@ TQuaternion MakeRotationQuaternion (const TVector3& s, const TVector3& t) {
}
TQuaternion InterpolateQuaternions (const TQuaternion& q, TQuaternion r, double t) {
TQuaternion res;
double cosphi;
double sinphi;
double phi;
double scale0, scale1;
cosphi = q.x * r.x + q.y * r.y + q.z * r.z + q.w * r.w;
double cosphi = q.x * r.x + q.y * r.y + q.z * r.z + q.w * r.w;
if (cosphi < 0.0) {
cosphi = -cosphi;
@ -458,9 +452,10 @@ TQuaternion InterpolateQuaternions (const TQuaternion& q, TQuaternion r, double
r.w = -r.w;
}
double scale0, scale1;
if (1.0 - cosphi > EPS) {
phi = acos (cosphi);
sinphi = sin (phi);
double phi = acos (cosphi);
double sinphi = sin (phi);
scale0 = sin (phi * (1.0 - t)) / sinphi;
scale1 = sin (phi * t) / sinphi;
} else {
@ -468,6 +463,7 @@ TQuaternion InterpolateQuaternions (const TQuaternion& q, TQuaternion r, double
scale1 = t;
}
TQuaternion res;
res.x = scale0 * q.x + scale1 * r.x;
res.y = scale0 * q.y + scale1 * r.y;
res.z = scale0 * q.z + scale1 * r.z;
@ -561,7 +557,7 @@ void backsb (double *matrix, int n, double *soln) {
bool IntersectPolygon (const TPolygon& p, TVector3 *v) {
TRay ray;
double d, s, nuDotProd, wec;
double d, s, nuDotProd;
double distsq;
TVector3 nml = MakeNormal (p, v);
@ -608,7 +604,7 @@ bool IntersectPolygon (const TPolygon& p, TVector3 *v) {
TVector3 edge_nml = CrossProduct (nml,
SubtractVectors (v[p.vertices[ (i+1) % p.num_vertices ]], v[p.vertices[i]]));
wec = DotProduct (SubtractVectors (pt, v[p.vertices[i]]), edge_nml);
double wec = DotProduct (SubtractVectors (pt, v[p.vertices[i]]), edge_nml);
if (wec < 0) return false;
}
return true;

View File

@ -396,15 +396,9 @@ double adjust_particle_count (double particles) {
}
void generate_particles (const CControl *ctrl, double dtime, const TVector3& pos, double speed) {
double brake_particles;
double turn_particles;
double roll_particles;
double surf_y;
double left_particles, right_particles;
TMatrix rot_mat;
TTerrType *TerrList = &Course.TerrList[0];
surf_y = Course.FindYCoord (pos.x, pos.z);
double surf_y = Course.FindYCoord (pos.x, pos.z);
int id = Course.GetTerrainIdx (pos.x, pos.z, 0.5);
if (id >= 0 && TerrList[id].particles && pos.y < surf_y) {
@ -420,27 +414,28 @@ void generate_particles (const CControl *ctrl, double dtime, const TVector3& pos
right_part_pt.y = left_part_pt.y = surf_y;
brake_particles = dtime *
BRAKE_PARTICLES * (ctrl->is_braking ? 1.0 : 0.0)
* min (speed / PARTICLE_SPEED_FACTOR, 1.0);
turn_particles = dtime * MAX_TURN_PARTICLES
* min (speed / PARTICLE_SPEED_FACTOR, 1.0);
roll_particles = dtime * MAX_ROLL_PARTICLES
* min (speed / PARTICLE_SPEED_FACTOR, 1.0);
double brake_particles = dtime *
BRAKE_PARTICLES * (ctrl->is_braking ? 1.0 : 0.0)
* min (speed / PARTICLE_SPEED_FACTOR, 1.0);
double turn_particles = dtime * MAX_TURN_PARTICLES
* min (speed / PARTICLE_SPEED_FACTOR, 1.0);
double roll_particles = dtime * MAX_ROLL_PARTICLES
* min (speed / PARTICLE_SPEED_FACTOR, 1.0);
left_particles = turn_particles *
fabs (min(ctrl->turn_fact, 0.)) +
brake_particles +
roll_particles * fabs (min(ctrl->turn_animation, 0.));
double left_particles = turn_particles *
fabs (min(ctrl->turn_fact, 0.)) +
brake_particles +
roll_particles * fabs (min(ctrl->turn_animation, 0.));
right_particles = turn_particles *
fabs (max(ctrl->turn_fact, 0.)) +
brake_particles +
roll_particles * fabs (max(ctrl->turn_animation, 0.));
double right_particles = turn_particles *
fabs (max(ctrl->turn_fact, 0.)) +
brake_particles +
roll_particles * fabs (max(ctrl->turn_animation, 0.));
left_particles = adjust_particle_count (left_particles);
right_particles = adjust_particle_count (right_particles);
TMatrix rot_mat;
RotateAboutVectorMatrix(
rot_mat, ctrl->cdirection,
MAX (-MAX_PARTICLE_ANGLE,
@ -567,7 +562,6 @@ void CFlakes::MakeSnowFlake (size_t ar, size_t i) {
areas[ar].flakes[i].pt.y = -XRandom (areas[ar].top, areas[ar].bottom);
areas[ar].flakes[i].pt.z = areas[ar].back - FRandom () * (areas[ar].back - areas[ar].front);
float p_dist = FRandom ();
areas[ar].flakes[i].size = XRandom (areas[ar].minSize, areas[ar].maxSize);
areas[ar].flakes[i].vel.x = 0;
areas[ar].flakes[i].vel.z = 0;
@ -1037,9 +1031,8 @@ void CWind::CalcDestAngle () {
}
void CWind::Update (float timestep) {
float xx, zz;
if (!windy) return;
// the wind needn't be updated in each frame
CurrTime = CurrTime + timestep;
if (CurrTime > UPDATE_TIME) {
@ -1070,8 +1063,8 @@ void CWind::Update (float timestep) {
if (WAngle > params.maxAngle) WAngle = params.maxAngle;
if (WAngle < params.minAngle) WAngle = params.minAngle;
xx = sin (WAngle * 3.14159 / 180);
zz = sqrt (1 - xx * xx);
float xx = sin (WAngle * 3.14159 / 180);
float zz = sqrt (1 - xx * xx);
if ((WAngle > 90 && WAngle < 270) || (WAngle > 450 && WAngle < 630)) {
zz = -zz;
}

View File

@ -117,7 +117,6 @@ bool CControl::CheckTreeCollisions (const TVector3& pos, TVector3 *tree_loc, dou
CCharShape *shape = Char.GetShape (g_game.char_id);
double diam = 0.0;
double height;
TVector3 loc(0, 0, 0);
bool hit = false;
TMatrix mat;
@ -129,7 +128,7 @@ bool CControl::CheckTreeCollisions (const TVector3& pos, TVector3 *tree_loc, dou
for (size_t i=0; i<num_trees; i++) {
diam = trees[i].diam;
height = trees[i].height;
double height = trees[i].height;
loc = trees[i].pt;
TVector3 distvec(loc.x - pos.x, 0.0, loc.z - pos.z);
@ -173,7 +172,6 @@ bool CControl::CheckTreeCollisions (const TVector3& pos, TVector3 *tree_loc, dou
void CControl::AdjustTreeCollision (const TVector3& pos, TVector3 *vel) {
TVector3 treeLoc;
double tree_diam;
double factor;
if (CheckTreeCollisions (pos, &treeLoc, &tree_diam)) {
TVector3 treeNml(
@ -187,6 +185,7 @@ void CControl::AdjustTreeCollision (const TVector3& pos, TVector3 *vel) {
double costheta = DotProduct (*vel, treeNml);
if (costheta < 0) {
double factor;
if (cairborne) factor = 0.5;
else factor = 1.5;
*vel = AddVectors (
@ -357,22 +356,19 @@ TVector3 CControl::CalcJumpForce () {
}
TVector3 CControl::CalcFrictionForce (double speed, const TVector3& nmlforce) {
double fric_f_mag;
TMatrix fric_rot_mat;
double steer_angle;
if ((cairborne == false && speed > minFrictspeed) || g_game.finish) {
TVector3 tmp_nml_f = nmlforce;
fric_f_mag = NormVector (tmp_nml_f) * ff.frict_coeff;
double fric_f_mag = NormVector (tmp_nml_f) * ff.frict_coeff;
fric_f_mag = MIN (MAX_FRICT_FORCE, fric_f_mag);
TVector3 frictforce = ScaleVector (fric_f_mag, ff.frictdir);
steer_angle = turn_fact * MAX_TURN_ANGLE;
double steer_angle = turn_fact * MAX_TURN_ANGLE;
if (fabs (fric_f_mag * sin (steer_angle * M_PI / 180)) > MAX_TURN_PERP) {
steer_angle = RADIANS_TO_ANGLES (asin (MAX_TURN_PERP / fric_f_mag)) *
turn_fact / fabs (turn_fact);
}
TMatrix fric_rot_mat;
RotateAboutVectorMatrix (fric_rot_mat, ff.surfnml, steer_angle);
frictforce = TransformVector (fric_rot_mat, frictforce);
return ScaleVector (1.0 + MAX_TURN_PEN, frictforce);
@ -488,8 +484,6 @@ double CControl::AdjustTimeStep (double h, TVector3 vel) {
}
void CControl::SolveOdeSystem (double timestep) {
bool failed = false;
double speed;
double pos_err[3], vel_err[3], tot_pos_err, tot_vel_err;
double err=0, tol=0;
@ -525,7 +519,7 @@ void CControl::SolveOdeSystem (double timestep) {
TVector3 saved_vel = new_vel;
TVector3 saved_f = new_f;
failed = false;
bool failed = false;
for (;;) {
solver.InitOdeData (x, new_pos.x, h);
solver.InitOdeData (y, new_pos.y, h);
@ -613,7 +607,7 @@ void CControl::SolveOdeSystem (double timestep) {
t = t + h;
TVector3 tmp_vel = new_vel;
speed = NormVector (tmp_vel);
double speed = NormVector (tmp_vel);
if (param.perf_level > 2) generate_particles (this, h, new_pos, speed);
new_f = CalcNetForce (new_pos, new_vel);

View File

@ -1147,15 +1147,8 @@ void ResetQuadtree() {
}
static int get_root_level (int nx, int nz) {
int xlev, zlev;
xlev = (int) (log(static_cast<double>(nx)) / log (2.0));
zlev = (int) (log(static_cast<double>(nz)) / log (2.0));
if ((nx >> xlev) << xlev == nx) {
} else nx += 1;
if ((nz >> zlev) << zlev == nz) {
} else nz += 1;
int xlev = (int) (log(static_cast<double>(nx)) / log (2.0));
int zlev = (int) (log(static_cast<double>(nz)) / log (2.0));
return max (xlev, zlev);
}

View File

@ -235,13 +235,10 @@ int SlideVolume (CControl *ctrl, double speed, int typ) {
}
void PlayTerrainSound (CControl *ctrl, bool airborne) {
int terridx = -1;
TTerrType *TerrList = &Course.TerrList[0];
if (airborne == false) {
terridx = Course.GetTerrainIdx (ctrl->cpos.x, ctrl->cpos.z, 0.5);
int terridx = Course.GetTerrainIdx (ctrl->cpos.x, ctrl->cpos.z, 0.5);
if (terridx >= 0) {
newsound = (int)Sound.GetSoundIdx (TerrList[terridx].sound);
newsound = (int)Sound.GetSoundIdx (Course.TerrList[terridx].sound);
} else newsound = -1;
} else newsound = -1;
if ((newsound != lastsound) && (lastsound >= 0)) Sound.Halt (lastsound);

View File

@ -155,6 +155,7 @@ int CScore::CalcRaceResult () {
g_game.score = (int)(herringpt + timept);
if (g_game.score < 0) g_game.score = 0;
TScore TempScore;
TempScore.points = g_game.score;
TempScore.herrings = g_game.herring;
TempScore.time = g_game.time;

View File

@ -39,7 +39,6 @@ struct TScoreList {
class CScore : public State {
private:
vector<TScoreList> Scorelist;
TScore TempScore;
void Enter();
void Loop(double time_step);

View File

@ -440,16 +440,16 @@ bool CSPList::Load (const string &filepath) {
std::ifstream tempfile(filepath.c_str());
string line;
bool backflag = false;
if (!tempfile) {
Message ("CSPList::Load - unable to open " + filepath, "");
return false;
} else {
bool backflag = false;
while (getline(tempfile, line)) {
// delete new line char if in string
size_t npos = line.rfind ('\n');
if (npos >= 0) SDeleteN (line, npos, 1);
if (npos != string::npos) SDeleteN (line, npos, 1);
bool valid = true;
if (line.empty()) valid = false; // empty line

View File

@ -543,7 +543,7 @@ void CTexture::FreeTextureList () {
}
TTexture* CTexture::GetTexture (size_t idx) const {
if (idx >= CommonTex.size() || idx < 0) return NULL;
if (idx >= CommonTex.size()) return NULL;
return CommonTex[idx];
}
@ -552,7 +552,7 @@ TTexture* CTexture::GetTexture (const string& name) const {
}
bool CTexture::BindTex (size_t idx) {
if (idx < 0 || idx >= CommonTex.size()) return false;
if (idx >= CommonTex.size()) return false;
CommonTex[idx]->Bind();
return true;
}

View File

@ -121,7 +121,6 @@ void SetRotation (double x, double y, double z) {
}
void CharKeys (unsigned int key, bool special, bool release, int x, int y) {
int keyfact;
must_render = true;
if (ToolsFinalStage ()) {
@ -136,8 +135,6 @@ void CharKeys (unsigned int key, bool special, bool release, int x, int y) {
if (key == 304) shift = !release;
if (key == 306) control = !release;
if (key == 308) alt = !release;
if (shift) keyfact = -1;
else keyfact = 1;
if (release) return;
@ -276,19 +273,16 @@ void CharMouse (int button, int state, int x, int y) {
}
void CharMotion (int x, int y) {
int diffx, diffy;
float diffposx, diffposy;
must_render = true;
if (rotactive) {
diffx = cursor_pos.x - startx;
diffy = cursor_pos.y - starty;
int diffx = cursor_pos.x - startx;
int diffy = cursor_pos.y - starty;
yrotation = startroty + diffx;
xrotation = startrotx + diffy;
}
if (moveactive) {
diffposx = (double)(cursor_pos.x - startx) / 200;
diffposy = (double)(cursor_pos.y - starty) / 200;
float diffposx = (double)(cursor_pos.x - startx) / 200;
float diffposy = (double)(cursor_pos.y - starty) / 200;
yposition = startposy - diffposy;
xposition = startposx + diffposx;
}
@ -367,7 +361,6 @@ void RenderChar (double timestep) {
FT.SetFont ("normal");
FT.SetSize (16);
int xl, yt;
for (size_t i=0; i<=lastnode; i++) {
if (i != curr_node) {
FT.SetColor (colLGrey);
@ -376,8 +369,8 @@ void RenderChar (double timestep) {
FT.SetColor (colYellow);
FT.SetFont ("bold");
}
xl = ITrunc ((int)i, charbase) * 100 + 20;
yt = IFrac ((int)i, charbase) * 18 + 60;
int xl = ITrunc ((int)i, charbase) * 100 + 20;
int yt = IFrac ((int)i, charbase) * 18 + 60;
FT.DrawString (xl, yt, TestChar.GetNodeJoint (i));
}
@ -387,7 +380,7 @@ void RenderChar (double timestep) {
for (size_t i=0; i<num; i++) {
is_visible = false;
type = action->type[i];
yt = Winsys.resolution.height - 120 + (int)i * 18;
int yt = Winsys.resolution.height - 120 + (int)i * 18;
switch (type) {
case 0:
DrawActionVec (i, "trans", yt, action->vec[i]);

View File

@ -210,15 +210,14 @@ void SingleFrameMotion (int x, int y) {
}
void PrintFrameParams (int ytop, TKeyframe *frame) {
int y, x;
int offs = 18;
for (int i=0; i<=last_joint; i++) {
if (i == curr_joint) FT.SetColor (colYellow);
else FT.SetColor (colLGrey);
x = ITrunc (i, jointbase) * 140 + 20;
y = IFrac (i, jointbase) * offs + ytop;
int x = ITrunc (i, jointbase) * 140 + 20;
int y = IFrac (i, jointbase) * offs + ytop;
FT.DrawString (x, y, TestFrame.GetJointName(i));
if (i < 4) FT.DrawString (x+80, y, Float_StrN (frame->val[i], 2));
@ -258,7 +257,6 @@ void RenderSingleFrame (double timestep) {
FT.SetFont ("normal");
FT.SetSize (16);
int xl, yt;
for (size_t i=0; i<TestFrame.numFrames(); i++) {
if (i != curr_frame) {
FT.SetColor (colLGrey);
@ -267,8 +265,8 @@ void RenderSingleFrame (double timestep) {
FT.SetColor (colYellow);
FT.SetFont ("bold");
}
xl = ITrunc ((int)i, framebase) * 100 + 20;
yt = IFrac ((int)i, framebase) * 18 + 20;
int xl = ITrunc ((int)i, framebase) * 100 + 20;
int yt = IFrac ((int)i, framebase) * 18 + 20;
FT.DrawString (xl, yt, Int_StrN ((int)i));
}

View File

@ -945,9 +945,9 @@ void CCharShape::SaveCharNodes (const string& dir, const string& filename) {
if (node->parent_name >= node->node_name) Message ("wrong parent index");
string line = "*[node] " + Int_StrN ((int)node->node_name);
line += " [par] " + Int_StrN ((int)node->parent_name);
bool rotflag = false;
if (!act->order.empty()) {
bool rotflag = false;
TVector3 rotation;
line += " [order] " + act->order;
for (size_t ii=0; ii<act->order.size(); ii++) {

View File

@ -208,7 +208,6 @@ void update_view (CControl *ctrl, double dt) {
TVector3 vel_dir = ctrl->cvel;
NormVector (vel_dir);
double course_angle = Course.GetCourseAngle();
switch (ctrl->viewmode) {
case BEHIND: {

View File

@ -47,4 +47,4 @@ BEGIN
END
END
IDI_ICON1 ICON DISCARDABLE "resources\etracericon.ico"
IDI_ICON1 ICON DISCARDABLE "resources\etracericon.ico"