Refactorizations:
- Use initializer lists (C++11) - Fixed several cppcheck messages, mostly about uninitialized variables in constructors - particles.cpp: Improved parameter values and simplified code git-svn-id: https://svn.code.sf.net/p/extremetuxracer/code/trunk@635 0420edf4-82e4-42fc-9478-35b55e6d67a3master
parent
f8b1ad54e4
commit
817281efc3
|
@ -62,12 +62,13 @@ void TCourse::SetTranslatedData(const std::string& line2) {
|
||||||
CCourse Course;
|
CCourse Course;
|
||||||
|
|
||||||
|
|
||||||
CCourse::CCourse() {
|
CCourse::CCourse()
|
||||||
vnc_array = nullptr;
|
: curr_course(nullptr)
|
||||||
mirrored = false;
|
, nx(0), ny(0)
|
||||||
|
, base_height_value(0)
|
||||||
curr_course = nullptr;
|
, mirrored(false)
|
||||||
currentCourseList = nullptr;
|
, currentCourseList(nullptr)
|
||||||
|
, vnc_array(nullptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
CCourse::~CCourse() {
|
CCourse::~CCourse() {
|
||||||
|
@ -275,49 +276,25 @@ void CCourse::MakeStandardPolyhedrons() {
|
||||||
// polyhedron "none"
|
// polyhedron "none"
|
||||||
|
|
||||||
// poyhedron "tree"
|
// poyhedron "tree"
|
||||||
PolyArr[1].vertices.resize(6);
|
PolyArr[1].vertices = {
|
||||||
PolyArr[1].vertices[0] = TVector3d(0, 0, 0);
|
TVector3d(0, 0, 0),
|
||||||
PolyArr[1].vertices[1] = TVector3d(0, 0.15, 0.5);
|
TVector3d(0, 0.15, 0.5),
|
||||||
PolyArr[1].vertices[2] = TVector3d(0.5, 0.15, 0);
|
TVector3d(0.5, 0.15, 0),
|
||||||
PolyArr[1].vertices[3] = TVector3d(0, 0.15, -0.5);
|
TVector3d(0, 0.15, -0.5),
|
||||||
PolyArr[1].vertices[4] = TVector3d(-0.5, 0.15, 0);
|
TVector3d(-0.5, 0.15, 0),
|
||||||
PolyArr[1].vertices[5] = TVector3d(0, 1, 0);
|
TVector3d(0, 1, 0)
|
||||||
|
};
|
||||||
|
|
||||||
PolyArr[1].polygons.resize(8);
|
PolyArr[1].polygons = {
|
||||||
for (std::size_t i = 0; i < 8; i++) {
|
{ { 0, 1, 4 } },
|
||||||
PolyArr[1].polygons[i].vertices.resize(3);
|
{ { 0, 2, 1 } },
|
||||||
}
|
{ { 0, 3, 2 } },
|
||||||
PolyArr[1].polygons[0].vertices[0] = 0;
|
{ { 0, 4, 3 } },
|
||||||
PolyArr[1].polygons[0].vertices[1] = 1;
|
{ { 1, 5, 4 } },
|
||||||
PolyArr[1].polygons[0].vertices[2] = 4;
|
{ { 2, 5, 1 } },
|
||||||
|
{ { 3, 5, 2 } },
|
||||||
PolyArr[1].polygons[1].vertices[0] = 0;
|
{ { 4, 5, 3 } },
|
||||||
PolyArr[1].polygons[1].vertices[1] = 2;
|
};
|
||||||
PolyArr[1].polygons[1].vertices[2] = 1;
|
|
||||||
|
|
||||||
PolyArr[1].polygons[2].vertices[0] = 0;
|
|
||||||
PolyArr[1].polygons[2].vertices[1] = 3;
|
|
||||||
PolyArr[1].polygons[2].vertices[2] = 2;
|
|
||||||
|
|
||||||
PolyArr[1].polygons[3].vertices[0] = 0;
|
|
||||||
PolyArr[1].polygons[3].vertices[1] = 4;
|
|
||||||
PolyArr[1].polygons[3].vertices[2] = 3;
|
|
||||||
|
|
||||||
PolyArr[1].polygons[4].vertices[0] = 1;
|
|
||||||
PolyArr[1].polygons[4].vertices[1] = 5;
|
|
||||||
PolyArr[1].polygons[4].vertices[2] = 4;
|
|
||||||
|
|
||||||
PolyArr[1].polygons[5].vertices[0] = 2;
|
|
||||||
PolyArr[1].polygons[5].vertices[1] = 5;
|
|
||||||
PolyArr[1].polygons[5].vertices[2] = 1;
|
|
||||||
|
|
||||||
PolyArr[1].polygons[6].vertices[0] = 3;
|
|
||||||
PolyArr[1].polygons[6].vertices[1] = 5;
|
|
||||||
PolyArr[1].polygons[6].vertices[2] = 2;
|
|
||||||
|
|
||||||
PolyArr[1].polygons[7].vertices[0] = 4;
|
|
||||||
PolyArr[1].polygons[7].vertices[1] = 5;
|
|
||||||
PolyArr[1].polygons[7].vertices[2] = 3;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCourse::FreeTerrainTextures() {
|
void CCourse::FreeTerrainTextures() {
|
||||||
|
|
|
@ -169,8 +169,8 @@ public:
|
||||||
std::vector<TItem> NocollArr;
|
std::vector<TItem> NocollArr;
|
||||||
std::vector<TPolyhedron> PolyArr;
|
std::vector<TPolyhedron> PolyArr;
|
||||||
|
|
||||||
std::vector<CourseFields> Fields;
|
std::vector<CourseFields> Fields;
|
||||||
GLubyte *vnc_array;
|
GLubyte *vnc_array;
|
||||||
|
|
||||||
CCourseList* getGroup(std::size_t index);
|
CCourseList* getGroup(std::size_t index);
|
||||||
|
|
||||||
|
|
|
@ -47,12 +47,9 @@ void TLight::Enable(GLenum num) const {
|
||||||
|
|
||||||
CEnvironment Env;
|
CEnvironment Env;
|
||||||
|
|
||||||
CEnvironment::CEnvironment() {
|
CEnvironment::CEnvironment()
|
||||||
|
: lightcond{"sunny", "cloudy", "evening", "night"} {
|
||||||
EnvID = -1;
|
EnvID = -1;
|
||||||
lightcond[0] = "sunny";
|
|
||||||
lightcond[1] = "cloudy";
|
|
||||||
lightcond[2] = "evening";
|
|
||||||
lightcond[3] = "night";
|
|
||||||
for (std::size_t i = 0; i < 4; i++)
|
for (std::size_t i = 0; i < 4; i++)
|
||||||
LightIndex[lightcond[i]] = i;
|
LightIndex[lightcond[i]] = i;
|
||||||
Skybox = nullptr;
|
Skybox = nullptr;
|
||||||
|
|
|
@ -37,7 +37,6 @@ struct TPlane {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TPolygon { std::vector<int> vertices; };
|
struct TPolygon { std::vector<int> vertices; };
|
||||||
struct TSphere { double radius; int divisions; };
|
|
||||||
struct TRay { TVector3d pt; TVector3d vec; };
|
struct TRay { TVector3d pt; TVector3d vec; };
|
||||||
|
|
||||||
struct TPolyhedron {
|
struct TPolyhedron {
|
||||||
|
|
|
@ -108,14 +108,11 @@ void TGuiParticle::Update(float time_step, float push_timestep, const TVector2d&
|
||||||
float dist_from_push = (std::pow((x - push_position.x), 2) +
|
float dist_from_push = (std::pow((x - push_position.x), 2) +
|
||||||
std::pow((y - push_position.y), 2));
|
std::pow((y - push_position.y), 2));
|
||||||
if (push_timestep > 0) {
|
if (push_timestep > 0) {
|
||||||
f.x = PUSH_FACTOR * push_vector.x / push_timestep;
|
f = PUSH_FACTOR / push_timestep * push_vector;
|
||||||
f.y = PUSH_FACTOR * push_vector.y / push_timestep;
|
|
||||||
f.x = clamp(-MAX_PUSH_FORCE, f.x, MAX_PUSH_FORCE);
|
f.x = clamp(-MAX_PUSH_FORCE, f.x, MAX_PUSH_FORCE);
|
||||||
f.y = clamp(-MAX_PUSH_FORCE, f.y, MAX_PUSH_FORCE);
|
f.y = clamp(-MAX_PUSH_FORCE, f.y, MAX_PUSH_FORCE);
|
||||||
f.x *= 1.0/(PUSH_DIST_DECAY*dist_from_push + 1) *
|
f *= 1.0/(PUSH_DIST_DECAY*dist_from_push + 1) *
|
||||||
size/ PARTICLE_SIZE_RANGE;
|
size/PARTICLE_SIZE_RANGE;
|
||||||
f.y *= 1.0/(PUSH_DIST_DECAY*dist_from_push + 1) *
|
|
||||||
size / PARTICLE_SIZE_RANGE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vel.x += (f.x - vel.x * AIR_DRAG) * time_step;
|
vel.x += (f.x - vel.x * AIR_DRAG) * time_step;
|
||||||
|
@ -124,7 +121,7 @@ void TGuiParticle::Update(float time_step, float push_timestep, const TVector2d&
|
||||||
x += vel.x * time_step * (size / PARTICLE_SIZE_RANGE);
|
x += vel.x * time_step * (size / PARTICLE_SIZE_RANGE);
|
||||||
y += vel.y * time_step * (size / PARTICLE_SIZE_RANGE);
|
y += vel.y * time_step * (size / PARTICLE_SIZE_RANGE);
|
||||||
|
|
||||||
x = clamp(-0.05f, x, 1.f);
|
x = clamp(-0.05f, x, 1.05f);
|
||||||
sprite.setPosition(x*Winsys.resolution.width, y*Winsys.resolution.height);
|
sprite.setPosition(x*Winsys.resolution.width, y*Winsys.resolution.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,8 +141,7 @@ void update_ui_snow(float time_step) {
|
||||||
float push_timestep = 0;
|
float push_timestep = 0;
|
||||||
|
|
||||||
if (push_position_initialized) {
|
if (push_position_initialized) {
|
||||||
push_vector.x = push_position.x - last_push_position.x;
|
push_vector = push_position - last_push_position;
|
||||||
push_vector.y = push_position.y - last_push_position.y;
|
|
||||||
push_timestep = time;
|
push_timestep = time;
|
||||||
}
|
}
|
||||||
last_push_position = push_position;
|
last_push_position = push_position;
|
||||||
|
@ -176,8 +172,7 @@ void update_ui_snow(float time_step) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (time_step < PUSH_DECAY_TIME_CONSTANT) {
|
if (time_step < PUSH_DECAY_TIME_CONSTANT) {
|
||||||
push_vector.x *= 1.0 - time_step/PUSH_DECAY_TIME_CONSTANT;
|
push_vector *= 1.0 - time_step/PUSH_DECAY_TIME_CONSTANT;
|
||||||
push_vector.y *= 1.0 - time_step/PUSH_DECAY_TIME_CONSTANT;
|
|
||||||
} else {
|
} else {
|
||||||
push_vector.x = 0.0;
|
push_vector.x = 0.0;
|
||||||
push_vector.y = 0.0;
|
push_vector.y = 0.0;
|
||||||
|
@ -199,12 +194,12 @@ void push_ui_snow(const TVector2i& pos) {
|
||||||
// tux particles
|
// tux particles
|
||||||
// ====================================================================
|
// ====================================================================
|
||||||
|
|
||||||
#define MAX_PARTICLES 500000
|
#define MAX_PARTICLES 10000
|
||||||
#define START_RADIUS 0.04
|
#define START_RADIUS 0.04
|
||||||
#define OLD_PART_SIZE 0.12 // orig 0.07
|
#define OLD_PART_SIZE 0.12 // orig 0.07
|
||||||
#define NEW_PART_SIZE 0.035 // orig 0.02
|
#define NEW_PART_SIZE 0.035 // orig 0.02
|
||||||
#define MIN_AGE -0.2
|
#define MIN_AGE -0.2
|
||||||
#define MAX_AGE 1.0
|
#define MAX_AGE 1.0
|
||||||
#define VARIANCE_FACTOR 0.8
|
#define VARIANCE_FACTOR 0.8
|
||||||
#define PARTICLE_SHADOW_HEIGHT 0.05
|
#define PARTICLE_SHADOW_HEIGHT 0.05
|
||||||
#define PARTICLE_SHADOW_ALPHA 0.1
|
#define PARTICLE_SHADOW_ALPHA 0.1
|
||||||
|
@ -291,8 +286,7 @@ void Particle::draw_billboard(const CControl *ctrl, double width, double height,
|
||||||
z_vec.z = ctrl->view_mat[2][2];
|
z_vec.z = ctrl->view_mat[2][2];
|
||||||
}
|
}
|
||||||
|
|
||||||
TVector3d pt1 = pt + -width/2.0 * x_vec;
|
TVector3d pt1 = pt - width/2.0 * x_vec - height/2.0 * y_vec;
|
||||||
pt1 += -height / 2.0 * y_vec;
|
|
||||||
TVector3d pt2 = pt1 + width * x_vec;
|
TVector3d pt2 = pt1 + width * x_vec;
|
||||||
TVector3d pt3 = pt2 + height * y_vec;
|
TVector3d pt3 = pt2 + height * y_vec;
|
||||||
TVector3d pt4 = pt3 + -width * x_vec;
|
TVector3d pt4 = pt3 + -width * x_vec;
|
||||||
|
@ -314,13 +308,13 @@ void Particle::draw_billboard(const CControl *ctrl, double width, double height,
|
||||||
glDisableClientState(GL_VERTEX_ARRAY);
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void create_new_particles(const TVector3d& loc, const TVector3d& vel, int num) {
|
void create_new_particles(const TVector3d& loc, const TVector3d& vel, std::size_t num) {
|
||||||
double speed = vel.Length();
|
double speed = vel.Length();
|
||||||
|
|
||||||
if (particles.size() + num > MAX_PARTICLES) {
|
if (particles.size() + num > MAX_PARTICLES) {
|
||||||
Message("maximum number of particles exceeded");
|
Message("maximum number of particles exceeded");
|
||||||
}
|
}
|
||||||
for (int i=0; i<num; i++) {
|
for (std::size_t i=0; i<num; i++) {
|
||||||
particles.emplace_back();
|
particles.emplace_back();
|
||||||
Particle* newp = &particles.back();
|
Particle* newp = &particles.back();
|
||||||
newp->pt.x = loc.x + 2.*(FRandom() - 0.5) * START_RADIUS;
|
newp->pt.x = loc.x + 2.*(FRandom() - 0.5) * START_RADIUS;
|
||||||
|
@ -347,7 +341,8 @@ void update_particles(float time_step) {
|
||||||
|
|
||||||
p->pt += static_cast<double>(time_step) * p->vel;
|
p->pt += static_cast<double>(time_step) * p->vel;
|
||||||
double ycoord = Course.FindYCoord(p->pt.x, p->pt.z);
|
double ycoord = Course.FindYCoord(p->pt.x, p->pt.z);
|
||||||
if (p->pt.y < ycoord - 3) {p->age = p->death + 1;}
|
if (p->pt.y < ycoord - 3)
|
||||||
|
p->age = p->death + 1;
|
||||||
if (p->age >= p->death) {
|
if (p->age >= p->death) {
|
||||||
p = particles.erase(p);
|
p = particles.erase(p);
|
||||||
continue;
|
continue;
|
||||||
|
@ -433,10 +428,8 @@ void generate_particles(const CControl *ctrl, double dtime, const TVector3d& pos
|
||||||
right_part_vel *= std::min(MAX_PARTICLE_SPEED, speed * PARTICLE_SPEED_MULTIPLIER);
|
right_part_vel *= std::min(MAX_PARTICLE_SPEED, speed * PARTICLE_SPEED_MULTIPLIER);
|
||||||
|
|
||||||
|
|
||||||
create_new_particles(left_part_pt, left_part_vel,
|
create_new_particles(left_part_pt, left_part_vel, (std::size_t)left_particles);
|
||||||
(int)left_particles);
|
create_new_particles(right_part_pt, right_part_vel, (std::size_t)right_particles);
|
||||||
create_new_particles(right_part_pt, right_part_vel,
|
|
||||||
(int)right_particles);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -490,6 +483,7 @@ TFlakeArea::TFlakeArea(
|
||||||
maxSize = _maxSize;
|
maxSize = _maxSize;
|
||||||
speed = _speed;
|
speed = _speed;
|
||||||
rotate_flake = rotate;
|
rotate_flake = rotate;
|
||||||
|
left = right = bottom = top = front = back = 0.f;
|
||||||
|
|
||||||
flakes.resize(num_flakes);
|
flakes.resize(num_flakes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,8 +46,8 @@ void generate_particles(const CControl *ctrl, double dtime, const TVector3d& pos
|
||||||
|
|
||||||
struct TFlake {
|
struct TFlake {
|
||||||
TVector3d pt;
|
TVector3d pt;
|
||||||
float size;
|
|
||||||
TVector3d vel;
|
TVector3d vel;
|
||||||
|
float size;
|
||||||
const GLfloat* tex;
|
const GLfloat* tex;
|
||||||
|
|
||||||
void Draw(const TPlane& lp, const TPlane& rp, bool rotate_flake, float dir_angle) const;
|
void Draw(const TPlane& lp, const TPlane& rp, bool rotate_flake, float dir_angle) const;
|
||||||
|
|
|
@ -56,6 +56,8 @@ CControl::CControl() :
|
||||||
paddle_time = 0;
|
paddle_time = 0;
|
||||||
view_init = false;
|
view_init = false;
|
||||||
finish_speed = 0;
|
finish_speed = 0;
|
||||||
|
|
||||||
|
viewmode = ABOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
|
|
|
@ -98,7 +98,7 @@ class CSPList : public std::list<std::string> {
|
||||||
private:
|
private:
|
||||||
bool fnewlineflag;
|
bool fnewlineflag;
|
||||||
public:
|
public:
|
||||||
CSPList(bool newlineflag = false);
|
explicit CSPList(bool newlineflag = false);
|
||||||
|
|
||||||
void Add(const std::string& line = emptyString);
|
void Add(const std::string& line = emptyString);
|
||||||
void Add(std::string&& line);
|
void Add(std::string&& line);
|
||||||
|
|
|
@ -408,7 +408,7 @@ void CCharShape::Draw() {
|
||||||
ScopedRenderMode rm(TUX);
|
ScopedRenderMode rm(TUX);
|
||||||
glEnable(GL_NORMALIZE);
|
glEnable(GL_NORMALIZE);
|
||||||
|
|
||||||
TCharNode *node = GetNode(0);
|
const TCharNode *node = GetNode(0);
|
||||||
if (node == nullptr) return;
|
if (node == nullptr) return;
|
||||||
|
|
||||||
DrawNodes(node);
|
DrawNodes(node);
|
||||||
|
@ -622,7 +622,7 @@ bool CCharShape::CheckPolyhedronCollision(const TCharNode *node, const TMatrix<4
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCharShape::CheckCollision(const TPolyhedron& ph) {
|
bool CCharShape::CheckCollision(const TPolyhedron& ph) {
|
||||||
TCharNode *node = GetNode(0);
|
const TCharNode *node = GetNode(0);
|
||||||
if (node == nullptr) return false;
|
if (node == nullptr) return false;
|
||||||
const TMatrix<4, 4>& identity = TMatrix<4, 4>::getIdentity();
|
const TMatrix<4, 4>& identity = TMatrix<4, 4>::getIdentity();
|
||||||
return CheckPolyhedronCollision(node, identity, identity, ph);
|
return CheckPolyhedronCollision(node, identity, identity, ph);
|
||||||
|
|
|
@ -33,8 +33,10 @@ TVector2i cursor_pos(0, 0);
|
||||||
CWinsys Winsys;
|
CWinsys Winsys;
|
||||||
|
|
||||||
CWinsys::CWinsys()
|
CWinsys::CWinsys()
|
||||||
: sfmlRenders(false)
|
: numJoysticks(0)
|
||||||
, auto_resolution(800, 600) {
|
, sfmlRenders(false)
|
||||||
|
, auto_resolution(800, 600)
|
||||||
|
, scale(1.f) {
|
||||||
for (unsigned int i = 0; i < 8; i++) {
|
for (unsigned int i = 0; i < 8; i++) {
|
||||||
if (sf::Joystick::isConnected(i))
|
if (sf::Joystick::isConnected(i))
|
||||||
numJoysticks++;
|
numJoysticks++;
|
||||||
|
|
Loading…
Reference in New Issue