diff --git a/src/course.cpp b/src/course.cpp index 4886e4d..2b8afb4 100644 --- a/src/course.cpp +++ b/src/course.cpp @@ -62,12 +62,13 @@ void TCourse::SetTranslatedData(const std::string& line2) { CCourse Course; -CCourse::CCourse() { - vnc_array = nullptr; - mirrored = false; - - curr_course = nullptr; - currentCourseList = nullptr; +CCourse::CCourse() + : curr_course(nullptr) + , nx(0), ny(0) + , base_height_value(0) + , mirrored(false) + , currentCourseList(nullptr) + , vnc_array(nullptr) { } CCourse::~CCourse() { @@ -275,49 +276,25 @@ void CCourse::MakeStandardPolyhedrons() { // polyhedron "none" // poyhedron "tree" - PolyArr[1].vertices.resize(6); - PolyArr[1].vertices[0] = TVector3d(0, 0, 0); - PolyArr[1].vertices[1] = TVector3d(0, 0.15, 0.5); - PolyArr[1].vertices[2] = TVector3d(0.5, 0.15, 0); - PolyArr[1].vertices[3] = TVector3d(0, 0.15, -0.5); - PolyArr[1].vertices[4] = TVector3d(-0.5, 0.15, 0); - PolyArr[1].vertices[5] = TVector3d(0, 1, 0); + PolyArr[1].vertices = { + TVector3d(0, 0, 0), + TVector3d(0, 0.15, 0.5), + TVector3d(0.5, 0.15, 0), + TVector3d(0, 0.15, -0.5), + TVector3d(-0.5, 0.15, 0), + TVector3d(0, 1, 0) + }; - PolyArr[1].polygons.resize(8); - for (std::size_t i = 0; i < 8; i++) { - PolyArr[1].polygons[i].vertices.resize(3); - } - PolyArr[1].polygons[0].vertices[0] = 0; - PolyArr[1].polygons[0].vertices[1] = 1; - PolyArr[1].polygons[0].vertices[2] = 4; - - PolyArr[1].polygons[1].vertices[0] = 0; - 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; + PolyArr[1].polygons = { + { { 0, 1, 4 } }, + { { 0, 2, 1 } }, + { { 0, 3, 2 } }, + { { 0, 4, 3 } }, + { { 1, 5, 4 } }, + { { 2, 5, 1 } }, + { { 3, 5, 2 } }, + { { 4, 5, 3 } }, + }; } void CCourse::FreeTerrainTextures() { diff --git a/src/course.h b/src/course.h index 8f727da..fb73def 100644 --- a/src/course.h +++ b/src/course.h @@ -169,8 +169,8 @@ public: std::vector NocollArr; std::vector PolyArr; - std::vector Fields; - GLubyte *vnc_array; + std::vector Fields; + GLubyte *vnc_array; CCourseList* getGroup(std::size_t index); diff --git a/src/env.cpp b/src/env.cpp index 9e734f3..38a7b72 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -47,12 +47,9 @@ void TLight::Enable(GLenum num) const { CEnvironment Env; -CEnvironment::CEnvironment() { +CEnvironment::CEnvironment() + : lightcond{"sunny", "cloudy", "evening", "night"} { EnvID = -1; - lightcond[0] = "sunny"; - lightcond[1] = "cloudy"; - lightcond[2] = "evening"; - lightcond[3] = "night"; for (std::size_t i = 0; i < 4; i++) LightIndex[lightcond[i]] = i; Skybox = nullptr; diff --git a/src/mathlib.h b/src/mathlib.h index 7d6bc39..978f1af 100644 --- a/src/mathlib.h +++ b/src/mathlib.h @@ -37,7 +37,6 @@ struct TPlane { }; struct TPolygon { std::vector vertices; }; -struct TSphere { double radius; int divisions; }; struct TRay { TVector3d pt; TVector3d vec; }; struct TPolyhedron { diff --git a/src/particles.cpp b/src/particles.cpp index b1eca5e..abcc647 100644 --- a/src/particles.cpp +++ b/src/particles.cpp @@ -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) + std::pow((y - push_position.y), 2)); if (push_timestep > 0) { - f.x = PUSH_FACTOR * push_vector.x / push_timestep; - f.y = PUSH_FACTOR * push_vector.y / push_timestep; + f = PUSH_FACTOR / push_timestep * push_vector; f.x = clamp(-MAX_PUSH_FORCE, f.x, 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) * - size/ PARTICLE_SIZE_RANGE; - f.y *= 1.0/(PUSH_DIST_DECAY*dist_from_push + 1) * - size / PARTICLE_SIZE_RANGE; + f *= 1.0/(PUSH_DIST_DECAY*dist_from_push + 1) * + size/PARTICLE_SIZE_RANGE; } 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); 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); } @@ -144,8 +141,7 @@ void update_ui_snow(float time_step) { float push_timestep = 0; if (push_position_initialized) { - push_vector.x = push_position.x - last_push_position.x; - push_vector.y = push_position.y - last_push_position.y; + push_vector = push_position - last_push_position; push_timestep = time; } last_push_position = push_position; @@ -176,8 +172,7 @@ void update_ui_snow(float time_step) { } if (time_step < PUSH_DECAY_TIME_CONSTANT) { - push_vector.x *= 1.0 - time_step/PUSH_DECAY_TIME_CONSTANT; - push_vector.y *= 1.0 - time_step/PUSH_DECAY_TIME_CONSTANT; + push_vector *= 1.0 - time_step/PUSH_DECAY_TIME_CONSTANT; } else { push_vector.x = 0.0; push_vector.y = 0.0; @@ -199,12 +194,12 @@ void push_ui_snow(const TVector2i& pos) { // tux particles // ==================================================================== -#define MAX_PARTICLES 500000 +#define MAX_PARTICLES 10000 #define START_RADIUS 0.04 #define OLD_PART_SIZE 0.12 // orig 0.07 #define NEW_PART_SIZE 0.035 // orig 0.02 -#define MIN_AGE -0.2 -#define MAX_AGE 1.0 +#define MIN_AGE -0.2 +#define MAX_AGE 1.0 #define VARIANCE_FACTOR 0.8 #define PARTICLE_SHADOW_HEIGHT 0.05 #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]; } - TVector3d pt1 = pt + -width/2.0 * x_vec; - pt1 += -height / 2.0 * y_vec; + TVector3d pt1 = pt - width/2.0 * x_vec - height/2.0 * y_vec; TVector3d pt2 = pt1 + width * x_vec; TVector3d pt3 = pt2 + height * y_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); } -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(); if (particles.size() + num > MAX_PARTICLES) { Message("maximum number of particles exceeded"); } - for (int i=0; ipt.x = loc.x + 2.*(FRandom() - 0.5) * START_RADIUS; @@ -347,7 +341,8 @@ void update_particles(float time_step) { p->pt += static_cast(time_step) * p->vel; 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) { p = particles.erase(p); 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); - create_new_particles(left_part_pt, left_part_vel, - (int)left_particles); - create_new_particles(right_part_pt, right_part_vel, - (int)right_particles); + create_new_particles(left_part_pt, left_part_vel, (std::size_t)left_particles); + create_new_particles(right_part_pt, right_part_vel, (std::size_t)right_particles); } } @@ -490,6 +483,7 @@ TFlakeArea::TFlakeArea( maxSize = _maxSize; speed = _speed; rotate_flake = rotate; + left = right = bottom = top = front = back = 0.f; flakes.resize(num_flakes); } diff --git a/src/particles.h b/src/particles.h index a399787..f75c52f 100644 --- a/src/particles.h +++ b/src/particles.h @@ -46,8 +46,8 @@ void generate_particles(const CControl *ctrl, double dtime, const TVector3d& pos struct TFlake { TVector3d pt; - float size; TVector3d vel; + float size; const GLfloat* tex; void Draw(const TPlane& lp, const TPlane& rp, bool rotate_flake, float dir_angle) const; diff --git a/src/physics.cpp b/src/physics.cpp index efb9a72..7ce943f 100644 --- a/src/physics.cpp +++ b/src/physics.cpp @@ -56,6 +56,8 @@ CControl::CControl() : paddle_time = 0; view_init = false; finish_speed = 0; + + viewmode = ABOVE; } // -------------------------------------------------------------------- diff --git a/src/spx.h b/src/spx.h index dfdce93..1719011 100644 --- a/src/spx.h +++ b/src/spx.h @@ -98,7 +98,7 @@ class CSPList : public std::list { private: bool fnewlineflag; public: - CSPList(bool newlineflag = false); + explicit CSPList(bool newlineflag = false); void Add(const std::string& line = emptyString); void Add(std::string&& line); diff --git a/src/tux.cpp b/src/tux.cpp index ec066cd..547e5f8 100644 --- a/src/tux.cpp +++ b/src/tux.cpp @@ -408,7 +408,7 @@ void CCharShape::Draw() { ScopedRenderMode rm(TUX); glEnable(GL_NORMALIZE); - TCharNode *node = GetNode(0); + const TCharNode *node = GetNode(0); if (node == nullptr) return; DrawNodes(node); @@ -622,7 +622,7 @@ bool CCharShape::CheckPolyhedronCollision(const TCharNode *node, const TMatrix<4 } bool CCharShape::CheckCollision(const TPolyhedron& ph) { - TCharNode *node = GetNode(0); + const TCharNode *node = GetNode(0); if (node == nullptr) return false; const TMatrix<4, 4>& identity = TMatrix<4, 4>::getIdentity(); return CheckPolyhedronCollision(node, identity, identity, ph); diff --git a/src/winsys.cpp b/src/winsys.cpp index bb38060..e4bc448 100644 --- a/src/winsys.cpp +++ b/src/winsys.cpp @@ -33,8 +33,10 @@ TVector2i cursor_pos(0, 0); CWinsys Winsys; CWinsys::CWinsys() - : sfmlRenders(false) - , auto_resolution(800, 600) { + : numJoysticks(0) + , sfmlRenders(false) + , auto_resolution(800, 600) + , scale(1.f) { for (unsigned int i = 0; i < 8; i++) { if (sf::Joystick::isConnected(i)) numJoysticks++;