mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-02 06:59:13 +01:00
fix(track): two switches laid right after one another, with no plain track between them, are joined, the vehicles no longer derail there: only the plain tracks looked for their neighbours, so the end of the main track of one switch at the start of the next one was joined to nothing, and an axle getting to it ran onto a track made to derail it. TTrack::join_switches joins the free ends of a switch to the ends of other switches in the same points, on both sides, with the codes of the ends the axles go on by: the end of either path of one at the start of the other, two facing at their starts, two meeting at their ends; done once the plain tracks are joined as the scenery is loaded, the old sceneries too, and as the editor joins a switch laid. Selftest pathwalk walks the tracks as an axle does: P2 to P1, P4 to P1, start to start and end to end go through either way
This commit is contained in:
@@ -2016,6 +2016,59 @@ bool TTrack::SetConnections(int i)
|
||||
return false;
|
||||
}
|
||||
|
||||
void TTrack::join_switches()
|
||||
{
|
||||
if( eType != tt_Switch || SwitchExtension == nullptr || simulation::Region == nullptr ) {
|
||||
return;
|
||||
}
|
||||
// the ends of the paths as the codes of the track joined to them have them: 0 the start of a switch, where both paths begin, 1 the end of
|
||||
// its first path, 3 the end of its second one; a vehicle going on onto a start keeps its direction, onto an end it turns
|
||||
auto const code = []( int const Endpoint ) { return Endpoint == 3 ? 1 : Endpoint == 5 ? 3 : 0; };
|
||||
// the paths of the switch joined to its neighbours as it's set, as Switch() takes them
|
||||
auto const bind = []( TTrack &Switch ) {
|
||||
auto const &extension { *Switch.SwitchExtension };
|
||||
auto const state { extension.CurrentIndex & 1 };
|
||||
Switch.trNext = extension.pNexts[ state ];
|
||||
Switch.trPrev = extension.pPrevs[ state ];
|
||||
Switch.iNextDirection = extension.iNextDirection[ state ];
|
||||
Switch.iPrevDirection = extension.iPrevDirection[ state ];
|
||||
};
|
||||
auto &own { *SwitchExtension };
|
||||
for( int path = 0; path < 2; ++path ) {
|
||||
for( int end = 0; end < 2; ++end ) {
|
||||
if( ( end ? own.pNexts[ path ] : own.pPrevs[ path ] ) != nullptr || own.Segments[ path ] == nullptr ) {
|
||||
continue;
|
||||
}
|
||||
auto const point { end ? own.Segments[ path ]->FastGetPoint_1() : own.Segments[ path ]->FastGetPoint_0() };
|
||||
auto const [ other, endpoint ] { simulation::Region->find_path( point, this ) };
|
||||
if( other == nullptr || other == this || other->eType != tt_Switch || other->SwitchExtension == nullptr || endpoint < 2 || endpoint > 5 ) {
|
||||
continue;
|
||||
}
|
||||
auto &theirs { *other->SwitchExtension };
|
||||
if( end == 0 ) {
|
||||
own.pPrevs[ 0 ] = own.pPrevs[ 1 ] = other;
|
||||
own.iPrevDirection[ 0 ] = own.iPrevDirection[ 1 ] = code( endpoint );
|
||||
}
|
||||
else {
|
||||
own.pNexts[ path ] = other;
|
||||
own.iNextDirection[ path ] = code( endpoint );
|
||||
}
|
||||
auto const ours { end == 0 ? 0 : path ? 3 : 1 };
|
||||
if( endpoint == 2 || endpoint == 4 ) {
|
||||
theirs.pPrevs[ 0 ] = theirs.pPrevs[ 1 ] = this;
|
||||
theirs.iPrevDirection[ 0 ] = theirs.iPrevDirection[ 1 ] = ours;
|
||||
}
|
||||
else {
|
||||
auto const theirpath { endpoint == 5 ? 1 : 0 };
|
||||
theirs.pNexts[ theirpath ] = this;
|
||||
theirs.iNextDirection[ theirpath ] = ours;
|
||||
}
|
||||
bind( *other );
|
||||
}
|
||||
}
|
||||
bind( *this );
|
||||
}
|
||||
|
||||
bool TTrack::Switch(int i, float const t, float const d)
|
||||
{ // przełączenie torów z uruchomieniem animacji
|
||||
if (SwitchExtension) // tory przełączalne mają doklejkę
|
||||
@@ -3947,6 +4000,13 @@ path_table::InitTracks() {
|
||||
}
|
||||
}
|
||||
|
||||
// the plain tracks are joined to the switches above, a switch right after another one only here, once they are
|
||||
for( auto *track : m_items ) {
|
||||
if( track->eType == tt_Switch ) {
|
||||
track->join_switches();
|
||||
}
|
||||
}
|
||||
|
||||
if( Global.CreateSwitchTrackbeds ) {
|
||||
// do this after all connections are established, otherwise missing switch connections
|
||||
// may prevent us from obtaining texture data for basic track from 'across' a switch
|
||||
|
||||
Reference in New Issue
Block a user