mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 13:59:19 +02:00
Sortowanie tabelki po odległości
This commit is contained in:
36
Driver.cpp
36
Driver.cpp
@@ -675,6 +675,7 @@ void TController::TableCheck(double fDistance)
|
|||||||
if( iTableDirection != iDirection ) {
|
if( iTableDirection != iDirection ) {
|
||||||
// jak zmiana kierunku, to skanujemy od końca składu
|
// jak zmiana kierunku, to skanujemy od końca składu
|
||||||
TableTraceRoute( fDistance, pVehicles[ 1 ] );
|
TableTraceRoute( fDistance, pVehicles[ 1 ] );
|
||||||
|
TableSort();
|
||||||
}
|
}
|
||||||
else if (iTableDirection)
|
else if (iTableDirection)
|
||||||
{ // trzeba sprawdzić, czy coś się zmieniło
|
{ // trzeba sprawdzić, czy coś się zmieniło
|
||||||
@@ -692,11 +693,14 @@ void TController::TableCheck(double fDistance)
|
|||||||
if( Global::iWriteLogEnabled & 8 ) {
|
if( Global::iWriteLogEnabled & 8 ) {
|
||||||
WriteLog( "Speed table for " + OwnerName() + " detected switch change at " + sSpeedTable[ i ].trTrack->NameGet() + " (generating fresh trace)" );
|
WriteLog( "Speed table for " + OwnerName() + " detected switch change at " + sSpeedTable[ i ].trTrack->NameGet() + " (generating fresh trace)" );
|
||||||
}
|
}
|
||||||
// NOTE: dirty trick to perform scan from the beginning
|
// usuwamy wszystko za tym torem
|
||||||
// a workaround for current routines not preserving properly scan distance if started from the middle
|
while (sSpeedTable.back().trTrack != sSpeedTable[i].trTrack)
|
||||||
// and the scan extending far beyond specified limit as result
|
{ // usuwamy wszystko dopóki nie trafimy na tą zwrotnicę
|
||||||
iTableDirection = -iDirection;
|
sSpeedTable.pop_back();
|
||||||
|
iLast--;
|
||||||
|
}
|
||||||
TableTraceRoute( fDistance, pVehicles[ 1 ] );
|
TableTraceRoute( fDistance, pVehicles[ 1 ] );
|
||||||
|
TableSort();
|
||||||
// nie kontynuujemy pętli, trzeba doskanować ciąg dalszy
|
// nie kontynuujemy pętli, trzeba doskanować ciąg dalszy
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -734,6 +738,7 @@ void TController::TableCheck(double fDistance)
|
|||||||
// WriteLog("TableCheck: Upate last track. Dist=" + AnsiString(sSpeedTable[iLast].fDist));
|
// WriteLog("TableCheck: Upate last track. Dist=" + AnsiString(sSpeedTable[iLast].fDist));
|
||||||
if( sSpeedTable[ iLast ].fDist < fDistance ) {
|
if( sSpeedTable[ iLast ].fDist < fDistance ) {
|
||||||
TableTraceRoute( fDistance, pVehicles[ 1 ] ); // doskanowanie dalszego odcinka
|
TableTraceRoute( fDistance, pVehicles[ 1 ] ); // doskanowanie dalszego odcinka
|
||||||
|
TableSort();
|
||||||
}
|
}
|
||||||
// garbage collection
|
// garbage collection
|
||||||
TablePurger();
|
TablePurger();
|
||||||
@@ -1377,6 +1382,29 @@ void TController::TablePurger()
|
|||||||
iLast = sSpeedTable.size() - 1;
|
iLast = sSpeedTable.size() - 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void TController::TableSort()
|
||||||
|
{
|
||||||
|
TSpeedPos sp_temp = TSpeedPos(); // uzywany do przenoszenia
|
||||||
|
for (std::size_t i = 0; i < iLast - 1; i++)
|
||||||
|
{ // pętla tylko do dwóch pozycji od końca bo ostatniej nie modyfikujemy
|
||||||
|
if (sSpeedTable[i].fDist > sSpeedTable[i + 1].fDist)
|
||||||
|
{ // jesli pozycja wcześniejsza jest dalej to źle
|
||||||
|
sp_temp = sSpeedTable[i + 1];
|
||||||
|
sSpeedTable[i + 1] = sSpeedTable[i]; // zamiana
|
||||||
|
sSpeedTable[i] = sp_temp;
|
||||||
|
// jeszcze sprawdzenie czy pozycja nie była indeksowana dla eventów
|
||||||
|
if (SemNextIndex == i)
|
||||||
|
SemNextIndex++;
|
||||||
|
else if (SemNextIndex == i + 1)
|
||||||
|
SemNextIndex--;
|
||||||
|
if (SemNextStopIndex == i)
|
||||||
|
SemNextStopIndex++;
|
||||||
|
else if (SemNextStopIndex == i + 1)
|
||||||
|
SemNextStopIndex--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
TController::TController(bool AI, TDynamicObject *NewControll, bool InitPsyche, bool primary) :// czy ma aktywnie prowadzić?
|
TController::TController(bool AI, TDynamicObject *NewControll, bool InitPsyche, bool primary) :// czy ma aktywnie prowadzić?
|
||||||
|
|||||||
1
Driver.h
1
Driver.h
@@ -371,6 +371,7 @@ private: // parametry aktualnego składu
|
|||||||
void TableCheck(double fDistance);
|
void TableCheck(double fDistance);
|
||||||
TCommandType TableUpdate(double &fVelDes, double &fDist, double &fNext, double &fAcc);
|
TCommandType TableUpdate(double &fVelDes, double &fDist, double &fNext, double &fAcc);
|
||||||
void TablePurger();
|
void TablePurger();
|
||||||
|
void TableSort();
|
||||||
inline double MoveDistanceGet()
|
inline double MoveDistanceGet()
|
||||||
{
|
{
|
||||||
return dMoveLen;
|
return dMoveLen;
|
||||||
|
|||||||
Reference in New Issue
Block a user