mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-03 07:20:22 +01:00
refactor(track): what goes with unevenness in one place, readable
The rules stay in TrackUneven.h with no dependence on the engine, as they can be tested. Their use on the tracks moves out of Track.cpp to TrackUneven.cpp, split into steps: the group of switches, the values of its paths, the meeting of two ends. One set of helpers for the paths of a track takes the place of the same conditions written out in several places, and the value at the ends of a switch is worked out in one place. The clatter of an axle leaves the long Update of a vehicle. The fields in the editor say themselves when they show. No change in behaviour.
This commit is contained in:
@@ -3661,25 +3661,7 @@ bool TDynamicObject::Update(double dt, double dt1)
|
||||
1 :
|
||||
ctOwner->Vehicle()->DirectionGet() == DirectionGet() ? 1 : -1 ) };
|
||||
for( auto &axle : m_axlesounds ) {
|
||||
// on a track with dipping joints the clatter comes from them, elsewhere the axle counts a rail off itself
|
||||
// by the outer axle on its side of the vehicle: the two can be on different tracks
|
||||
auto const &outer { axle.offset >= 0.0 ? Axle0 : Axle1 };
|
||||
auto const railphase { outer.RailPhase( axle.offset - std::copysign( 0.5 * fAxleDist, axle.offset ) ) };
|
||||
auto crossed { false };
|
||||
if( railphase >= 0.0 ) {
|
||||
// the rails under the axle, which aren't always those under the track the vehicle is on
|
||||
crossed = axle.atjoints && std::abs( railphase - axle.distance ) > 0.5 * outer.GetTrack()->fSoundDistance;
|
||||
axle.distance = railphase;
|
||||
}
|
||||
else {
|
||||
axle.distance += dDOMoveLen * directioninconsist;
|
||||
crossed = axle.distance < 0 || axle.distance > dRailLength;
|
||||
if( crossed ) {
|
||||
axle.distance = clamp_circular( axle.distance, dRailLength );
|
||||
}
|
||||
}
|
||||
axle.atjoints = ( railphase >= 0.0 );
|
||||
if( crossed ) {
|
||||
if( axle_passed_joint( axle, dDOMoveLen, directioninconsist ) ) {
|
||||
if( MoverParameters->Vel > 0.1 ) {
|
||||
// NOTE: for combined clatter sound we supply 1/100th of actual value, as the sound module converts does the opposite, converting received (typically) 0-1 values to 0-100 range
|
||||
auto const frequency = true == axle.clatter.is_combined() ? MoverParameters->Vel * 0.01 : 1.0;
|
||||
@@ -8089,6 +8071,28 @@ TDynamicObject::update_shake( double const Timedelta ) {
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
TDynamicObject::axle_passed_joint( axle_sounds &Axle, double const Move, int const Direction ) {
|
||||
|
||||
// by the outer axle on its side of the vehicle: the two can be on different tracks
|
||||
auto const &outer { Axle.offset >= 0.0 ? Axle0 : Axle1 };
|
||||
auto const railphase { outer.RailPhase( Axle.offset - std::copysign( 0.5 * fAxleDist, Axle.offset ) ) };
|
||||
if( railphase >= 0.0 ) {
|
||||
// the rails under the axle, which aren't always those under the track the vehicle is on
|
||||
auto const passed { Axle.atjoints && std::abs( railphase - Axle.distance ) > 0.5 * outer.GetTrack()->fSoundDistance };
|
||||
Axle.distance = railphase;
|
||||
Axle.atjoints = true;
|
||||
return passed;
|
||||
}
|
||||
Axle.atjoints = false;
|
||||
Axle.distance += Move * Direction;
|
||||
if( Axle.distance >= 0 && Axle.distance <= dRailLength ) {
|
||||
return false;
|
||||
}
|
||||
Axle.distance = clamp_circular( Axle.distance, dRailLength );
|
||||
return true;
|
||||
}
|
||||
|
||||
std::pair<double, double>
|
||||
TDynamicObject::shake_angles() const {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user