From 8cb40714b8ebff98aee8edd08662ce1469378ebc Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 20 Mar 2010 17:49:31 +0000 Subject: [PATCH] Fix bug in SlopeTrack gradient calculation --- src/Engine.cpp | 15 ++++++++------- src/SlopeTrack.cpp | 2 +- src/Train.cpp | 13 +++++-------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/Engine.cpp b/src/Engine.cpp index 2706333..c34f775 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -207,13 +207,14 @@ void Engine::update(int delta, float gradient) const double B = isBrakeOn ? brakeForce() : 0.0; const double G = gravity(gradient); -#if 1 - if (gradient > 0.01f) - debug() << "U = " << gradient; - else if (gradient < -0.01f) - debug() << "D =" << gradient; - else - debug() << "F =" << gradient; +#if 0 + static float lastGradient = gradient; + if (abs(gradient - lastGradient) > 0.01f) { + error() << "too big gradient change " + << lastGradient << " -> " + << gradient; + } + lastGradient = gradient; #endif // The applied tractive effort is controlled by the throttle diff --git a/src/SlopeTrack.cpp b/src/SlopeTrack.cpp index bee5bfa..78d3473 100644 --- a/src/SlopeTrack.cpp +++ b/src/SlopeTrack.cpp @@ -206,7 +206,7 @@ float SlopeTrack::gradient(const track::TravelToken& token, float delta) const if (token.direction == -axis) delta = length - delta; - return curve.deriv(delta).y; + return curve.deriv(delta / length).y; } void SlopeTrack::transform(const track::TravelToken& token, float delta) const diff --git a/src/Train.cpp b/src/Train.cpp index 314b000..9b6d04f 100644 --- a/src/Train.cpp +++ b/src/Train.cpp @@ -286,16 +286,11 @@ void Train::update(int delta) it != parts.end(); ++it) { float gradient = (*it).travelToken.gradient((*it).segmentDelta); - - debug() << "dir=" << (*it).direction << " ms=" << (*it).movementSign - << " g=" << gradient; - if ((*it).direction.x < 0 || (*it).direction.z < 0) gradient *= -1.0f; gradient *= (*it).movementSign; - (*it).vehicle->update(delta, gradient); } @@ -325,9 +320,11 @@ void Train::enterSegment(Part& aPart, const track::Connection& aConnection) { Point pos; tie(pos, aPart.direction) = aConnection; - - //debug() << "Train part entered segment at " << pos - // << " moving " << aPart.direction; + +#if 0 + debug() << "Train part entered segment at " << pos + << " moving " << aPart.direction; +#endif if (!map->isValidTrack(pos)) throw runtime_error("Train fell off end of track!"); -- 2.39.2