mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 17:46:48 +01:00
refactor(physics): the motion of the vehicle is private to it
The speed along the couplers, the location, the offsets from the track axis,
the accelerations, the distance counter and the distance moved since the last
check, the flat of the wheels and the truck hunting, the distance of the
derailment check, whether the vehicle is inside a consist and in the coupler
model, the analog demand of the integrated controller and the flow of the pipe
stabiliser are private to physics::Vehicle. TDynamicObject places and moves the
vehicle, the scenery puts road vehicles on their way and the contacts push them
through the operations (SetV(), SetLoc(), SetOffsetTrackH(), ...), and the
jolts of the track are ShakeVertically() and ShakeHorizontally(), the same
additions as before.
No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
This commit is contained in:
@@ -106,8 +106,8 @@ void physics::Vehicle::CollisionDetect(VehicleEnd const End, double const dt)
|
||||
// the velocities along this vehicle's axis: the other vehicle's one is turned around when the vehicles face each
|
||||
// other (touch with the same ends), as in CouplerForce()
|
||||
auto const otherdirection{DirPatch(End, otherend)};
|
||||
auto velocity{V};
|
||||
auto othervehiclevelocity{othervehicle->V * otherdirection};
|
||||
auto velocity{travelSpeed};
|
||||
auto othervehiclevelocity{othervehicle->travelSpeed * otherdirection};
|
||||
// calculate collision force and new velocities for involved vehicles
|
||||
auto const VirtualCoupling{(thiscoupler.CouplingFlag == Coupling::none)};
|
||||
auto CCF{0.0};
|
||||
@@ -175,16 +175,16 @@ void physics::Vehicle::CollisionDetect(VehicleEnd const End, double const dt)
|
||||
};
|
||||
if (false == wall(*this))
|
||||
{
|
||||
auto const accelerationchange{(velocity - V) / dt};
|
||||
AccS += accelerationchange * accelerationspike;
|
||||
V = velocity;
|
||||
auto const accelerationchange{(velocity - travelSpeed) / dt};
|
||||
accS += accelerationchange * accelerationspike;
|
||||
travelSpeed = velocity;
|
||||
}
|
||||
if (false == wall(*othervehicle))
|
||||
{
|
||||
auto const othervehiclenewvelocity{othervehiclevelocity * otherdirection}; // back along the other vehicle's axis
|
||||
auto const othervehicleaccelerationchange{(othervehiclenewvelocity - othervehicle->V) / dt};
|
||||
othervehicle->AccS += othervehicleaccelerationchange * accelerationspike;
|
||||
othervehicle->V = othervehiclenewvelocity;
|
||||
auto const othervehicleaccelerationchange{(othervehiclenewvelocity - othervehicle->travelSpeed) / dt};
|
||||
othervehicle->accS += othervehicleaccelerationchange * accelerationspike;
|
||||
othervehicle->travelSpeed = othervehiclenewvelocity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -462,11 +462,11 @@ bool physics::Vehicle::crush_hit(VehicleEnd const End, double const dt)
|
||||
auto const apart{End == VehicleEnd::front ? -1.0 : 1.0};
|
||||
if (false == wall)
|
||||
{
|
||||
V += apart * hit.impulse / mass;
|
||||
travelSpeed += apart * hit.impulse / mass;
|
||||
}
|
||||
if (false == otherwall)
|
||||
{
|
||||
othervehicle->V -= apart * hit.impulse / othermass * otherdirection;
|
||||
othervehicle->travelSpeed -= apart * hit.impulse / othermass * otherdirection;
|
||||
}
|
||||
record_hit(thiscoupler, hit.force, hit.duration);
|
||||
record_hit(othercoupler, hit.force, hit.duration);
|
||||
@@ -708,7 +708,7 @@ void physics::Vehicle::check_derailment(TTrackShape const &Shape, TTrackParam co
|
||||
track.buckle_curvature = Shape.buckle_curvature;
|
||||
track.damage = Track.DamageFlag;
|
||||
|
||||
auto const verdict{derailment_monitor.update(vehicle, track, V, Distance)};
|
||||
auto const verdict{derailment_monitor.update(vehicle, track, travelSpeed, Distance)};
|
||||
if (verdict.result == derailment::outcome::none)
|
||||
{
|
||||
return;
|
||||
@@ -725,7 +725,7 @@ void physics::Vehicle::check_derailment(TTrackShape const &Shape, TTrackParam co
|
||||
}
|
||||
derailment_reported = Track.Name;
|
||||
++derailment_reports;
|
||||
WriteLog("derailment monitor: " + Name + " " + derailment::report(verdict, vehicle, track, V, Track.Name != nullptr ? *Track.Name : std::string{}));
|
||||
WriteLog("derailment monitor: " + Name + " " + derailment::report(verdict, vehicle, track, travelSpeed, Track.Name != nullptr ? *Track.Name : std::string{}));
|
||||
}
|
||||
|
||||
void physics::Vehicle::derail(derailment::verdict const &Verdict, derailment::vehicle_state const &Vehicle, derailment::track_state const &Track, std::string const *TrackName)
|
||||
@@ -743,7 +743,7 @@ void physics::Vehicle::derail(derailment::verdict const &Verdict, derailment::ve
|
||||
MainSwitch(false, range_t::local);
|
||||
// the brake hoses tear: the brake pipe vents and the rest of the train brakes in emergency
|
||||
tear_brake_hoses(*this);
|
||||
ErrorLog("Bad driving: " + Name + " " + derailment::report(Verdict, Vehicle, Track, V, TrackName != nullptr ? *TrackName : std::string{}));
|
||||
ErrorLog("Bad driving: " + Name + " " + derailment::report(Verdict, Vehicle, Track, travelSpeed, TrackName != nullptr ? *TrackName : std::string{}));
|
||||
if (Track.buckle_curvature != 0.0)
|
||||
{
|
||||
ErrorLog(std::format("Bad driving: {} derailed on buckled track, the buckle bending the line by 1/{:.0f} m {} the curve", Name, 1.0 / std::abs(Track.buckle_curvature),
|
||||
@@ -761,7 +761,7 @@ void physics::Vehicle::rerail()
|
||||
DerailAcceleration = 0.0;
|
||||
DerailSide = 0;
|
||||
derailment_monitor.reset();
|
||||
derailment_distance = 0.0;
|
||||
derailmentDistance = 0.0;
|
||||
derailment_reported.reset();
|
||||
// nor derailed in a collision
|
||||
CollisionDerail = NONE;
|
||||
@@ -770,8 +770,8 @@ void physics::Vehicle::rerail()
|
||||
// its place on the road)
|
||||
if (TestFlag(CategoryFlag, 1))
|
||||
{
|
||||
OffsetTrackH = 0.0;
|
||||
OffsetTrackV = 0.0;
|
||||
offsetTrackH = 0.0;
|
||||
offsetTrackV = 0.0;
|
||||
}
|
||||
// a derailed vehicle which stopped sleeps (Global.physics_sleepheld) with the friction of the derailment in FStand and
|
||||
// where the derailment put it, until something wakes it: the physics on, for the friction of the rails and its place on
|
||||
@@ -783,7 +783,7 @@ void physics::Vehicle::repair_damage()
|
||||
{
|
||||
DamageFlag = {};
|
||||
equipmentFaults = {};
|
||||
WheelFlat = 0.0;
|
||||
wheelFlat = 0.0;
|
||||
brakes.alarmChain = false;
|
||||
// the crushed ends rebuilt
|
||||
for (auto &coupler : Couplers)
|
||||
@@ -800,15 +800,15 @@ void physics::Vehicle::Derail(DerailReason const Reason)
|
||||
eventFlag = true;
|
||||
MainSwitch(false, range_t::local);
|
||||
|
||||
auto const velocity{V};
|
||||
AccS *= 0.65;
|
||||
V *= 0.65;
|
||||
auto const velocity{travelSpeed};
|
||||
accS *= 0.65;
|
||||
travelSpeed *= 0.65;
|
||||
// physics.collisions new: the vehicles coupled to it lose the speed with it. the cut in a step stands for the
|
||||
// train coming to a stop with the vehicle; the coupled ones keeping their speed would run into it at a third of
|
||||
// the speed of the train, and crush their ends and ride up onto it for a hit no train had
|
||||
if (Global.collisions == global_settings::collision_model::physical && TestFlag(CategoryFlag, 1))
|
||||
{
|
||||
change_train_velocity(V - velocity);
|
||||
change_train_velocity(travelSpeed - velocity);
|
||||
}
|
||||
RunningShape.R = 0;
|
||||
if (Vel < 5.0)
|
||||
|
||||
Reference in New Issue
Block a user