mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-02 16:19:13 +01:00
fix(editor): the uneven attribute is written in the layout of the entry it goes into
Its numbers go by position, and the positions differ between a plain track and a switch. A switch made in the style of a plain track wrote them in the layout of the plain one, so they were read back as other values: the up and down part as the value of the path p3-p4, and so on. The values are now one struct with pure functions to read, write and resolve them, which replaces eight fields and which the unit tests can reach.
This commit is contained in:
@@ -642,10 +642,10 @@ void TTrack::Load(cParser *parser, glm::dvec3 const &pOrigin)
|
||||
}
|
||||
}
|
||||
else if( str == "uneven" ) {
|
||||
// uneven <mm>[;<mm>...]: see read_uneven and TrackUneven.h. The semicolons stay in the token
|
||||
// uneven <mm>[;<mm>...]: see TrackUneven.h. The semicolons stay in the token
|
||||
auto const values { parser->getToken<std::string>( false, "\n\r\t " ) };
|
||||
if( ( eType == tt_Normal || eType == tt_Switch ) && iCategoryFlag == 1 ) {
|
||||
read_uneven( values );
|
||||
m_uneven = track_uneven::read_attribute( values, eType == tt_Switch );
|
||||
}
|
||||
}
|
||||
else if( str == "friction" ) {
|
||||
@@ -706,49 +706,9 @@ void TTrack::Load(cParser *parser, glm::dvec3 const &pOrigin)
|
||||
// to a stale origin and the renderer would draw sleepers in the wrong place).
|
||||
}
|
||||
|
||||
void TTrack::read_uneven( std::string const &Text ) {
|
||||
|
||||
auto const fields { track_uneven::read_fields<6>( Text ) };
|
||||
m_uneven = std::max( fields[ 0 ], 0.f );
|
||||
if( eType == tt_Switch ) {
|
||||
m_unevenbranch = fields[ 1 ];
|
||||
m_unevenup = fields[ 2 ];
|
||||
m_unevenside = fields[ 3 ];
|
||||
m_unevenbranchup = fields[ 4 ];
|
||||
m_unevenbranchside = fields[ 5 ];
|
||||
}
|
||||
else {
|
||||
m_unevenup = fields[ 1 ];
|
||||
m_unevenside = fields[ 2 ];
|
||||
m_unevencross = fields[ 3 ];
|
||||
m_jointdip = fields[ 4 ];
|
||||
}
|
||||
}
|
||||
|
||||
std::string TTrack::uneven_text() const {
|
||||
|
||||
auto const fields { eType == tt_Switch ?
|
||||
std::array<float, 6> { m_uneven, m_unevenbranch, m_unevenup, m_unevenside, m_unevenbranchup, m_unevenbranchside } :
|
||||
std::array<float, 6> { m_uneven, m_unevenup, m_unevenside, m_unevencross, m_jointdip, -1.f } };
|
||||
if( m_uneven <= 0.f && std::all_of( fields.begin() + 1, fields.end(), []( float const Field ) { return Field < 0.f; } ) ) {
|
||||
return {};
|
||||
}
|
||||
return "uneven " + track_uneven::write_fields( fields ) + ' ';
|
||||
}
|
||||
|
||||
track_uneven::amounts TTrack::uneven_declared( int const Path ) const {
|
||||
|
||||
track_uneven::amounts result {
|
||||
m_unevenup >= 0.f ? m_unevenup : m_uneven,
|
||||
m_unevenside >= 0.f ? m_unevenside : m_uneven,
|
||||
eType != tt_Normal ? 0.f : m_unevencross >= 0.f ? m_unevencross : m_uneven };
|
||||
if( Path == 1 ) {
|
||||
auto const branch = [ this ]( float const Part, double const Straight ) -> double {
|
||||
return Part >= 0.f ? Part : m_unevenbranch >= 0.f ? m_unevenbranch : Straight; };
|
||||
result.up = branch( m_unevenbranchup, result.up );
|
||||
result.side = branch( m_unevenbranchside, result.side );
|
||||
}
|
||||
return result;
|
||||
return track_uneven::declared( m_uneven, eType == tt_Normal, Path );
|
||||
}
|
||||
|
||||
bool TTrack::is_uneven() const {
|
||||
@@ -873,7 +833,7 @@ double TTrack::joint_depth() const {
|
||||
if( eType != tt_Normal ) {
|
||||
return 0.0;
|
||||
}
|
||||
return ( m_jointdip >= 0.f ? m_jointdip : track_uneven::dip_share * uneven_declared().up );
|
||||
return ( m_uneven.dip >= 0.f ? m_uneven.dip : track_uneven::dip_share * uneven_declared().up );
|
||||
}
|
||||
|
||||
double TTrack::joint_dip( double const Distance ) const {
|
||||
@@ -2782,7 +2742,7 @@ TTrack::export_as_text_( std::ostream &Output ) const {
|
||||
&& false == m_profile1.first.empty() ) {
|
||||
Output << "railprofile " << m_profile1.first << ' ';
|
||||
}
|
||||
Output << uneven_text();
|
||||
Output << track_uneven::write_attribute( m_uneven, eType == tt_Switch );
|
||||
if( false == m_friction.first.empty() ) {
|
||||
Output << "friction " << m_friction.first << ' ';
|
||||
}
|
||||
|
||||
@@ -239,16 +239,7 @@ public:
|
||||
TEnvironmentType eEnvironment = e_flat; // dźwięk i oświetlenie
|
||||
int iAction = 0; // czy modyfikowany eventami (specjalna obsługa przy skanowaniu)
|
||||
float fOverhead = -1.0; // można normalnie pobierać prąd (0 dla jazdy bezprądowej po danym odcinku, >0-z opuszczonym i ograniczeniem prędkości)
|
||||
float m_uneven { 0.f }; // mm, see TrackUneven.h; plain tracks and switches
|
||||
// the components set apart from m_uneven, mm; negative: m_uneven. Cross level on plain tracks only
|
||||
float m_unevenup { -1.f };
|
||||
float m_unevenside { -1.f };
|
||||
float m_unevencross { -1.f };
|
||||
// the diverging path of a switch, mm; negative: as the straight one
|
||||
float m_unevenbranch { -1.f };
|
||||
float m_unevenbranchup { -1.f };
|
||||
float m_unevenbranchside { -1.f };
|
||||
float m_jointdip { -1.f }; // depth of the dip at rail joints, mm; negative: from m_uneven; plain tracks only
|
||||
track_uneven::attribute m_uneven; // plain tracks and switches
|
||||
private:
|
||||
double fVelocity = -1.0; // ograniczenie prędkości // prędkość dla AI (powyżej rośnie prawdopowobieństwo wykolejenia)
|
||||
public:
|
||||
@@ -350,10 +341,6 @@ public:
|
||||
void VelocitySet(float v);
|
||||
double VelocityGet();
|
||||
float Friction() const;
|
||||
// the attribute of the entry. A plain track: the value;up and down;sideways;cross level;dip at the joints.
|
||||
// A switch: path p1-p2;path p3-p4;up and down of the first;sideways of the first;up and down of the second;sideways of the second
|
||||
void read_uneven( std::string const &Text );
|
||||
std::string uneven_text() const;
|
||||
// the unevenness the track declares, on a path of a switch
|
||||
track_uneven::amounts uneven_declared( int const Path = 0 ) const;
|
||||
bool is_uneven() const;
|
||||
|
||||
@@ -87,6 +87,68 @@ std::string write_fields( std::array<float, Count> const &Fields ) {
|
||||
return text.str();
|
||||
}
|
||||
|
||||
// the values of the attribute, mm, negative where not given. Cross level and the dip at joints for plain tracks, the path p3-p4 for switches
|
||||
struct attribute {
|
||||
float value { 0.f };
|
||||
float up { -1.f };
|
||||
float side { -1.f };
|
||||
float cross { -1.f };
|
||||
float dip { -1.f };
|
||||
float branch { -1.f };
|
||||
float branchup { -1.f };
|
||||
float branchside { -1.f };
|
||||
};
|
||||
|
||||
// a plain track: value;up;side;cross;dip. A switch: p1-p2;p3-p4;up of p1-p2;side of p1-p2;up of p3-p4;side of p3-p4
|
||||
inline attribute read_attribute( std::string const &Text, bool const Switch ) {
|
||||
|
||||
auto const fields { read_fields<6>( Text ) };
|
||||
attribute result;
|
||||
result.value = std::max( fields[ 0 ], 0.f );
|
||||
if( Switch ) {
|
||||
result.branch = fields[ 1 ];
|
||||
result.up = fields[ 2 ];
|
||||
result.side = fields[ 3 ];
|
||||
result.branchup = fields[ 4 ];
|
||||
result.branchside = fields[ 5 ];
|
||||
}
|
||||
else {
|
||||
result.up = fields[ 1 ];
|
||||
result.side = fields[ 2 ];
|
||||
result.cross = fields[ 3 ];
|
||||
result.dip = fields[ 4 ];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// in the layout of the entry it goes into, which can be of another type than the track the values come from
|
||||
inline std::string write_attribute( attribute const &Values, bool const Switch ) {
|
||||
|
||||
auto const fields { Switch ?
|
||||
std::array<float, 6> { Values.value, Values.branch, Values.up, Values.side, Values.branchup, Values.branchside } :
|
||||
std::array<float, 6> { Values.value, Values.up, Values.side, Values.cross, Values.dip, -1.f } };
|
||||
if( Values.value <= 0.f && std::all_of( fields.begin() + 1, fields.end(), []( float const Field ) { return Field < 0.f; } ) ) {
|
||||
return {};
|
||||
}
|
||||
return "uneven " + write_fields( fields ) + ' ';
|
||||
}
|
||||
|
||||
// what a path comes to from the values: what's not given takes the first value, p3-p4 those of p1-p2. Cross level on plain tracks only
|
||||
inline amounts declared( attribute const &Values, bool const Plain, int const Path ) {
|
||||
|
||||
amounts result {
|
||||
Values.up >= 0.f ? Values.up : Values.value,
|
||||
Values.side >= 0.f ? Values.side : Values.value,
|
||||
false == Plain ? 0.f : Values.cross >= 0.f ? Values.cross : Values.value };
|
||||
if( Path == 1 ) {
|
||||
auto const branch = [ &Values ]( float const Part, double const Straight ) -> double {
|
||||
return Part >= 0.f ? Part : Values.branch >= 0.f ? Values.branch : Straight; };
|
||||
result.up = branch( Values.branchup, result.up );
|
||||
result.side = branch( Values.branchside, result.side );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template <std::size_t Count>
|
||||
using wave_set = std::array<wave, Count>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user