mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-23 03:59:18 +02:00
Merge branch 'tmj-dev' into lua
This commit is contained in:
74
Driver.cpp
74
Driver.cpp
@@ -1355,7 +1355,7 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN
|
|||||||
|
|
||||||
// modifies brake distance for low target speeds, to ease braking rate in such situations
|
// modifies brake distance for low target speeds, to ease braking rate in such situations
|
||||||
float
|
float
|
||||||
TController::braking_distance_multiplier( float const Targetvelocity ) {
|
TController::braking_distance_multiplier( float const Targetvelocity ) const {
|
||||||
|
|
||||||
if( Targetvelocity > 65.f ) { return 1.f; }
|
if( Targetvelocity > 65.f ) { return 1.f; }
|
||||||
if( Targetvelocity < 5.f ) { return 1.f; }
|
if( Targetvelocity < 5.f ) { return 1.f; }
|
||||||
@@ -1422,11 +1422,15 @@ void TController::TablePurger()
|
|||||||
iLast = sSpeedTable.size() - 1;
|
iLast = sSpeedTable.size() - 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
void TController::TableSort()
|
void TController::TableSort() {
|
||||||
{
|
|
||||||
|
if( sSpeedTable.size() < 3 ) {
|
||||||
|
// we skip last slot and no point in checking if there's only one other entry
|
||||||
|
return;
|
||||||
|
}
|
||||||
TSpeedPos sp_temp = TSpeedPos(); // uzywany do przenoszenia
|
TSpeedPos sp_temp = TSpeedPos(); // uzywany do przenoszenia
|
||||||
for (std::size_t i = 0; i < (iLast - 1) && iLast > 1 && iLast != -1; ++i)
|
for( std::size_t i = 0; i < ( iLast - 1 ); ++i ) {
|
||||||
{ // pętla tylko do dwóch pozycji od końca bo ostatniej nie modyfikujemy
|
// pętla tylko do dwóch pozycji od końca bo ostatniej nie modyfikujemy
|
||||||
if (sSpeedTable[i].fDist > sSpeedTable[i + 1].fDist)
|
if (sSpeedTable[i].fDist > sSpeedTable[i + 1].fDist)
|
||||||
{ // jesli pozycja wcześniejsza jest dalej to źle
|
{ // jesli pozycja wcześniejsza jest dalej to źle
|
||||||
sp_temp = sSpeedTable[i + 1];
|
sp_temp = sSpeedTable[i + 1];
|
||||||
@@ -3992,6 +3996,11 @@ TController::UpdateSituation(double dt) {
|
|||||||
// bottom margin raised to 2 km/h to give the AI more leeway at low speed limits
|
// bottom margin raised to 2 km/h to give the AI more leeway at low speed limits
|
||||||
fVelPlus = clamp( std::ceil( 0.05 * VelDesired ), 2.0, 5.0 );
|
fVelPlus = clamp( std::ceil( 0.05 * VelDesired ), 2.0, 5.0 );
|
||||||
}
|
}
|
||||||
|
if( mvOccupied->BrakeDelayFlag == bdelay_G ) {
|
||||||
|
// increase distances for cargo trains to take into account slower reaction to brakes
|
||||||
|
fMinProximityDist += 10.0;
|
||||||
|
fMaxProximityDist += 10.0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// samochod (sokista też)
|
// samochod (sokista też)
|
||||||
@@ -4302,6 +4311,12 @@ TController::UpdateSituation(double dt) {
|
|||||||
if( vehicle->fTrackBlock <= fMinProximityDist ) {
|
if( vehicle->fTrackBlock <= fMinProximityDist ) {
|
||||||
VelDesired = 0.0;
|
VelDesired = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( ( mvOccupied->CategoryFlag & 1 )
|
||||||
|
&& ( OrderCurrentGet() & Obey_train ) ) {
|
||||||
|
// trains which move normally should try to stop at safe margin
|
||||||
|
ActualProximityDist -= fDriverDist;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -4563,6 +4578,34 @@ TController::UpdateSituation(double dt) {
|
|||||||
}
|
}
|
||||||
// koniec predkosci nastepnej
|
// koniec predkosci nastepnej
|
||||||
|
|
||||||
|
// decisions based on current speed
|
||||||
|
if( mvOccupied->CategoryFlag == 1 ) {
|
||||||
|
// try to estimate increase of current velocity before engaged brakes start working
|
||||||
|
auto const speedestimate = vel + vel * ( 1.0 - fBrake_a0[ 0 ] ) * AbsAccS;
|
||||||
|
if( speedestimate > VelDesired ) {
|
||||||
|
// jesli jedzie za szybko do AKTUALNEGO
|
||||||
|
if( VelDesired == 0.0 ) {
|
||||||
|
// jesli stoj, to hamuj, ale i tak juz za pozno :)
|
||||||
|
AccDesired = std::min( AccDesired, -0.85 ); // hamuj solidnie
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if( speedestimate > ( VelDesired + fVelPlus ) ) {
|
||||||
|
// if it looks like we'll exceed maximum allowed speed start thinking about slight slowing down
|
||||||
|
AccDesired = std::min( AccDesired, -0.25 );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// close enough to target to stop accelerating
|
||||||
|
AccDesired = std::min(
|
||||||
|
AccDesired, // but don't override decceleration for VelNext
|
||||||
|
interpolate( // ease off as you close to the target velocity
|
||||||
|
-0.06, AccPreferred,
|
||||||
|
clamp( speedestimate - vel, 0.0, fVelPlus ) / fVelPlus ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// for cars the older version works better
|
||||||
if( vel > VelDesired ) {
|
if( vel > VelDesired ) {
|
||||||
// jesli jedzie za szybko do AKTUALNEGO
|
// jesli jedzie za szybko do AKTUALNEGO
|
||||||
if( VelDesired == 0.0 ) {
|
if( VelDesired == 0.0 ) {
|
||||||
@@ -4583,10 +4626,15 @@ TController::UpdateSituation(double dt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// koniec predkosci aktualnej
|
// koniec predkosci aktualnej
|
||||||
|
|
||||||
// last step sanity check, until the whole calculation is straightened out
|
// last step sanity check, until the whole calculation is straightened out
|
||||||
AccDesired = std::min( AccDesired, AccPreferred );
|
AccDesired = std::min( AccDesired, AccPreferred );
|
||||||
|
if( mvOccupied->CategoryFlag == 1 ) {
|
||||||
|
// also take into account impact of gravity
|
||||||
|
AccDesired = clamp( AccDesired - fAccGravity, -0.9, 0.9 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -4643,15 +4691,20 @@ TController::UpdateSituation(double dt) {
|
|||||||
}
|
}
|
||||||
// NOTE: as a stop-gap measure the routine is limited to trains only while car calculations seem off
|
// NOTE: as a stop-gap measure the routine is limited to trains only while car calculations seem off
|
||||||
if( mvControlling->CategoryFlag == 1 ) {
|
if( mvControlling->CategoryFlag == 1 ) {
|
||||||
|
if( vel < VelDesired ) {
|
||||||
|
// don't adjust acceleration when going above current goal speed
|
||||||
if( -AccDesired * BrakeAccFactor() < (
|
if( -AccDesired * BrakeAccFactor() < (
|
||||||
( ( fReady > 0.4 ) || ( VelNext > vel - 40.0 ) ) ?
|
( ( fReady > 0.4 )
|
||||||
|
|| ( VelNext > vel - 40.0 ) ) ?
|
||||||
fBrake_a0[ 0 ] * 0.8 :
|
fBrake_a0[ 0 ] * 0.8 :
|
||||||
-fAccThreshold )
|
-fAccThreshold )
|
||||||
/ braking_distance_multiplier( VelNext ) ) {
|
/ braking_distance_multiplier( VelNext ) ) {
|
||||||
AccDesired = std::max( -0.06, AccDesired );
|
AccDesired = std::max( -0.06, AccDesired );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
ReactionTime = 0.25; // i orientuj się szybciej, jeśli hamujesz
|
// i orientuj się szybciej, jeśli hamujesz
|
||||||
|
ReactionTime = 0.25;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mvOccupied->BrakeSystem == Pneumatic) // napełnianie uderzeniowe
|
if (mvOccupied->BrakeSystem == Pneumatic) // napełnianie uderzeniowe
|
||||||
@@ -5538,6 +5591,13 @@ bool TController::IsStop()
|
|||||||
return TrainParams->IsStop();
|
return TrainParams->IsStop();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// returns most recently calculated distance to potential obstacle ahead
|
||||||
|
double
|
||||||
|
TController::TrackBlock() const {
|
||||||
|
|
||||||
|
return pVehicles[ TMoverParameters::side::front ]->fTrackBlock;
|
||||||
|
}
|
||||||
|
|
||||||
void TController::MoveTo(TDynamicObject *to)
|
void TController::MoveTo(TDynamicObject *to)
|
||||||
{ // przesunięcie AI do innego pojazdu (przy zmianie kabiny)
|
{ // przesunięcie AI do innego pojazdu (przy zmianie kabiny)
|
||||||
// mvOccupied->CabDeactivisation(); //wyłączenie kabiny w opuszczanym
|
// mvOccupied->CabDeactivisation(); //wyłączenie kabiny w opuszczanym
|
||||||
|
|||||||
77
Driver.h
77
Driver.h
@@ -171,8 +171,8 @@ extern bool WriteLogFlag; // logowanie parametrów fizycznych
|
|||||||
static const int BrakeAccTableSize = 20;
|
static const int BrakeAccTableSize = 20;
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
class TController
|
class TController {
|
||||||
{
|
|
||||||
private: // obsługa tabelki prędkości (musi mieć możliwość odhaczania stacji w rozkładzie)
|
private: // obsługa tabelki prędkości (musi mieć możliwość odhaczania stacji w rozkładzie)
|
||||||
int iLast{ 0 }; // ostatnia wypełniona pozycja w tabeli <iFirst (modulo iSpeedTableSize)
|
int iLast{ 0 }; // ostatnia wypełniona pozycja w tabeli <iFirst (modulo iSpeedTableSize)
|
||||||
int iTableDirection{ 0 }; // kierunek zapełnienia tabelki względem pojazdu z AI
|
int iTableDirection{ 0 }; // kierunek zapełnienia tabelki względem pojazdu z AI
|
||||||
@@ -183,19 +183,19 @@ class TController
|
|||||||
std::size_t SemNextIndex{ std::size_t(-1) };
|
std::size_t SemNextIndex{ std::size_t(-1) };
|
||||||
std::size_t SemNextStopIndex{ std::size_t( -1 ) };
|
std::size_t SemNextStopIndex{ std::size_t( -1 ) };
|
||||||
double dMoveLen = 0.0; // odległość przejechana od ostatniego sprawdzenia tabelki
|
double dMoveLen = 0.0; // odległość przejechana od ostatniego sprawdzenia tabelki
|
||||||
private: // parametry aktualnego składu
|
// parametry aktualnego składu
|
||||||
double fLength = 0.0; // długość składu (do wyciągania z ograniczeń)
|
double fLength = 0.0; // długość składu (do wyciągania z ograniczeń)
|
||||||
double fMass = 0.0; // całkowita masa do liczenia stycznej składowej grawitacji
|
double fMass = 0.0; // całkowita masa do liczenia stycznej składowej grawitacji
|
||||||
|
public:
|
||||||
double fAccGravity = 0.0; // przyspieszenie składowej stycznej grawitacji
|
double fAccGravity = 0.0; // przyspieszenie składowej stycznej grawitacji
|
||||||
public:
|
|
||||||
TEvent *eSignNext = nullptr; // sygnał zmieniający prędkość, do pokazania na [F2]
|
TEvent *eSignNext = nullptr; // sygnał zmieniający prędkość, do pokazania na [F2]
|
||||||
std::string asNextStop; // nazwa następnego punktu zatrzymania wg rozkładu
|
std::string asNextStop; // nazwa następnego punktu zatrzymania wg rozkładu
|
||||||
int iStationStart = 0; // numer pierwszej stacji pokazywanej na podglądzie rozkładu
|
int iStationStart = 0; // numer pierwszej stacji pokazywanej na podglądzie rozkładu
|
||||||
private: // parametry sterowania pojazdem (stan, hamowanie)
|
// parametry sterowania pojazdem (stan, hamowanie)
|
||||||
|
private:
|
||||||
double fShuntVelocity = 40.0; // maksymalna prędkość manewrowania, zależy m.in. od składu // domyślna prędkość manewrowa
|
double fShuntVelocity = 40.0; // maksymalna prędkość manewrowania, zależy m.in. od składu // domyślna prędkość manewrowa
|
||||||
int iVehicles = 0; // ilość pojazdów w składzie
|
int iVehicles = 0; // ilość pojazdów w składzie
|
||||||
int iEngineActive = 0; // ABu: Czy silnik byl juz zalaczony; Ra: postęp w załączaniu
|
int iEngineActive = 0; // ABu: Czy silnik byl juz zalaczony; Ra: postęp w załączaniu
|
||||||
// vector3 vMechLoc; //pozycja pojazdu do liczenia odległości od semafora (?)
|
|
||||||
bool Psyche = false;
|
bool Psyche = false;
|
||||||
int iDrivigFlags = // flagi bitowe ruchu
|
int iDrivigFlags = // flagi bitowe ruchu
|
||||||
moveStopPoint | // podjedź do W4 możliwie blisko
|
moveStopPoint | // podjedź do W4 możliwie blisko
|
||||||
@@ -245,25 +245,20 @@ private:
|
|||||||
double AccPreferred = 0.0; // preferowane przyspieszenie (wg psychiki kierującego, zmniejszana przy wykryciu kolizji)
|
double AccPreferred = 0.0; // preferowane przyspieszenie (wg psychiki kierującego, zmniejszana przy wykryciu kolizji)
|
||||||
double AccDesired = AccPreferred; // przyspieszenie, jakie ma utrzymywać (<0:nie przyspieszaj,<-0.1:hamuj)
|
double AccDesired = AccPreferred; // przyspieszenie, jakie ma utrzymywać (<0:nie przyspieszaj,<-0.1:hamuj)
|
||||||
double VelDesired = 0.0; // predkość, z jaką ma jechać, wynikająca z analizy tableki; <=VelSignal
|
double VelDesired = 0.0; // predkość, z jaką ma jechać, wynikająca z analizy tableki; <=VelSignal
|
||||||
double fAccDesiredAv = 0.0; // uśrednione przyspieszenie z kolejnych przebłysków świadomości, żeby
|
double fAccDesiredAv = 0.0; // uśrednione przyspieszenie z kolejnych przebłysków świadomości, żeby ograniczyć migotanie
|
||||||
// ograniczyć migotanie
|
|
||||||
public:
|
|
||||||
double VelforDriver = -1.0; // prędkość, używana przy zmianie kierunku (ograniczenie przy nieznajmości szlaku?)
|
double VelforDriver = -1.0; // prędkość, używana przy zmianie kierunku (ograniczenie przy nieznajmości szlaku?)
|
||||||
double VelSignal = 0.0; // ograniczenie prędkości z kompilacji znaków i sygnałów // normalnie na początku ma stać, no chyba że jedzie
|
double VelSignal = 0.0; // ograniczenie prędkości z kompilacji znaków i sygnałów // normalnie na początku ma stać, no chyba że jedzie
|
||||||
double VelLimit = -1.0; // predkość zadawana przez event jednokierunkowego ograniczenia prędkości // -1: brak ograniczenia prędkości
|
double VelLimit = -1.0; // predkość zadawana przez event jednokierunkowego ograniczenia prędkości // -1: brak ograniczenia prędkości
|
||||||
public:
|
|
||||||
double VelSignalLast = -1.0; // prędkość zadana na ostatnim semaforze // ostatni semafor też bez ograniczenia
|
double VelSignalLast = -1.0; // prędkość zadana na ostatnim semaforze // ostatni semafor też bez ograniczenia
|
||||||
double VelSignalNext = 0.0; // prędkość zadana na następnym semaforze
|
double VelSignalNext = 0.0; // prędkość zadana na następnym semaforze
|
||||||
double VelLimitLast = -1.0; // prędkość zadana przez ograniczenie // ostatnie ograniczenie bez ograniczenia
|
double VelLimitLast = -1.0; // prędkość zadana przez ograniczenie // ostatnie ograniczenie bez ograniczenia
|
||||||
double VelRoad = -1.0; // aktualna prędkość drogowa (ze znaku W27) (PutValues albo komendą) // prędkość drogowa bez ograniczenia
|
double VelRoad = -1.0; // aktualna prędkość drogowa (ze znaku W27) (PutValues albo komendą) // prędkość drogowa bez ograniczenia
|
||||||
public:
|
|
||||||
double VelNext = 120.0; // prędkość, jaka ma być po przejechaniu długości ProximityDist
|
double VelNext = 120.0; // prędkość, jaka ma być po przejechaniu długości ProximityDist
|
||||||
private:
|
private:
|
||||||
double fProximityDist = 0.0; // odleglosc podawana w SetProximityVelocity(); >0:przeliczać do punktu, <0:podana wartość
|
double fProximityDist = 0.0; // odleglosc podawana w SetProximityVelocity(); >0:przeliczać do punktu, <0:podana wartość
|
||||||
double FirstSemaphorDist = 10000.0; // odległość do pierwszego znalezionego semafora
|
double FirstSemaphorDist = 10000.0; // odległość do pierwszego znalezionego semafora
|
||||||
public:
|
public:
|
||||||
double
|
double ActualProximityDist = 1.0; // odległość brana pod uwagę przy wyliczaniu prędkości i przyspieszenia
|
||||||
ActualProximityDist = 1.0; // odległość brana pod uwagę przy wyliczaniu prędkości i przyspieszenia
|
|
||||||
private:
|
private:
|
||||||
vector3 vCommandLocation; // polozenie wskaznika, sygnalizatora lub innego obiektu do ktorego
|
vector3 vCommandLocation; // polozenie wskaznika, sygnalizatora lub innego obiektu do ktorego
|
||||||
// odnosi sie komenda
|
// odnosi sie komenda
|
||||||
@@ -297,7 +292,7 @@ private:
|
|||||||
double fStopTime = 0.0; // czas postoju przed dalszą jazdą (np. na przystanku)
|
double fStopTime = 0.0; // czas postoju przed dalszą jazdą (np. na przystanku)
|
||||||
double WaitingTime = 0.0; // zliczany czas oczekiwania do samoistnego ruszenia
|
double WaitingTime = 0.0; // zliczany czas oczekiwania do samoistnego ruszenia
|
||||||
double WaitingExpireTime = 31.0; // tyle ma czekać, zanim się ruszy // maksymlany czas oczekiwania do samoistnego ruszenia
|
double WaitingExpireTime = 31.0; // tyle ma czekać, zanim się ruszy // maksymlany czas oczekiwania do samoistnego ruszenia
|
||||||
// TEvent* eSignLast; //ostatnio znaleziony sygnał, o ile nie minięty
|
|
||||||
private: //---//---//---//---// koniec zmiennych, poniżej metody //---//---//---//---//
|
private: //---//---//---//---// koniec zmiennych, poniżej metody //---//---//---//---//
|
||||||
void SetDriverPsyche();
|
void SetDriverPsyche();
|
||||||
bool PrepareEngine();
|
bool PrepareEngine();
|
||||||
@@ -314,23 +309,16 @@ private:
|
|||||||
void AutoRewident(); // ustawia hamulce w składzie
|
void AutoRewident(); // ustawia hamulce w składzie
|
||||||
double ESMVelocity(bool Main);
|
double ESMVelocity(bool Main);
|
||||||
public:
|
public:
|
||||||
Mtable::TTrainParameters *Timetable()
|
Mtable::TTrainParameters *Timetable() {
|
||||||
{
|
return TrainParams; };
|
||||||
return TrainParams;
|
|
||||||
};
|
|
||||||
void PutCommand(std::string NewCommand, double NewValue1, double NewValue2,
|
void PutCommand(std::string NewCommand, double NewValue1, double NewValue2,
|
||||||
const TLocation &NewLocation, TStopReason reason = stopComm);
|
const TLocation &NewLocation, TStopReason reason = stopComm);
|
||||||
bool PutCommand(std::string NewCommand, double NewValue1, double NewValue2,
|
bool PutCommand(std::string NewCommand, double NewValue1, double NewValue2,
|
||||||
const vector3 *NewLocation, TStopReason reason = stopComm);
|
const vector3 *NewLocation, TStopReason reason = stopComm);
|
||||||
void UpdateSituation(double dt); // uruchamiac przynajmniej raz na sekundę
|
void UpdateSituation(double dt); // uruchamiac przynajmniej raz na sekundę
|
||||||
// procedury dotyczace rozkazow dla maszynisty
|
// procedury dotyczace rozkazow dla maszynisty
|
||||||
void SetVelocity(double NewVel, double NewVelNext,
|
// uaktualnia informacje o prędkości
|
||||||
TStopReason r = stopNone); // uaktualnia informacje o prędkości
|
void SetVelocity(double NewVel, double NewVelNext, TStopReason r = stopNone);
|
||||||
/*
|
|
||||||
bool SetProximityVelocity(
|
|
||||||
double NewDist,
|
|
||||||
double NewVelNext); // uaktualnia informacje o prędkości przy nastepnym semaforze
|
|
||||||
*/
|
|
||||||
public:
|
public:
|
||||||
void JumpToNextOrder();
|
void JumpToNextOrder();
|
||||||
void JumpToFirstOrder();
|
void JumpToFirstOrder();
|
||||||
@@ -349,9 +337,7 @@ private:
|
|||||||
void OrdersInit(double fVel);
|
void OrdersInit(double fVel);
|
||||||
void OrdersClear();
|
void OrdersClear();
|
||||||
void OrdersDump();
|
void OrdersDump();
|
||||||
TController(bool AI, TDynamicObject *NewControll, bool InitPsyche,
|
TController( bool AI, TDynamicObject *NewControll, bool InitPsyche, bool primary = true );
|
||||||
bool primary = true // czy ma aktywnie prowadzić?
|
|
||||||
);
|
|
||||||
std::string OrderCurrent();
|
std::string OrderCurrent();
|
||||||
void WaitingSet(double Seconds);
|
void WaitingSet(double Seconds);
|
||||||
|
|
||||||
@@ -360,33 +346,24 @@ private:
|
|||||||
void DirectionForward(bool forward);
|
void DirectionForward(bool forward);
|
||||||
int OrderDirectionChange(int newdir, TMoverParameters *Vehicle);
|
int OrderDirectionChange(int newdir, TMoverParameters *Vehicle);
|
||||||
void Lights(int head, int rear);
|
void Lights(int head, int rear);
|
||||||
// double Distance(vector3 &p1, vector3 &n, vector3 &p2);
|
// Ra: metody obsługujące skanowanie toru
|
||||||
|
|
||||||
private: // Ra: metody obsługujące skanowanie toru
|
|
||||||
TEvent *CheckTrackEvent(TTrack *Track, double const fDirection ) const;
|
TEvent *CheckTrackEvent(TTrack *Track, double const fDirection ) const;
|
||||||
// bool TableCheckEvent(TEvent *e);
|
|
||||||
bool TableAddNew();
|
bool TableAddNew();
|
||||||
bool TableNotFound(TEvent const *Event) const;
|
bool TableNotFound(TEvent const *Event) const;
|
||||||
// TEvent *TableCheckTrackEvent(double fDirection, TTrack *Track);
|
|
||||||
void TableTraceRoute(double fDistance, TDynamicObject *pVehicle = nullptr);
|
void TableTraceRoute(double fDistance, TDynamicObject *pVehicle = nullptr);
|
||||||
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);
|
||||||
// modifies brake distance for low target speeds, to ease braking rate in such situations
|
// modifies brake distance for low target speeds, to ease braking rate in such situations
|
||||||
float
|
float
|
||||||
braking_distance_multiplier( float const Targetvelocity );
|
braking_distance_multiplier( float const Targetvelocity ) const;
|
||||||
void TablePurger();
|
void TablePurger();
|
||||||
void TableSort();
|
void TableSort();
|
||||||
inline double MoveDistanceGet()
|
inline double MoveDistanceGet() const {
|
||||||
{
|
return dMoveLen; }
|
||||||
return dMoveLen;
|
inline void MoveDistanceReset() {
|
||||||
}
|
dMoveLen = 0.0; }
|
||||||
inline void MoveDistanceReset()
|
|
||||||
{
|
|
||||||
dMoveLen = 0.0;
|
|
||||||
}
|
|
||||||
public:
|
public:
|
||||||
inline void MoveDistanceAdd(double distance)
|
inline void MoveDistanceAdd(double distance) {
|
||||||
{
|
|
||||||
dMoveLen += distance * iDirection; //jak jedzie do tyłu to trzeba uwzględniać, że distance jest ujemna
|
dMoveLen += distance * iDirection; //jak jedzie do tyłu to trzeba uwzględniać, że distance jest ujemna
|
||||||
}
|
}
|
||||||
std::size_t TableSize() const { return sSpeedTable.size(); }
|
std::size_t TableSize() const { return sSpeedTable.size(); }
|
||||||
@@ -396,8 +373,7 @@ private:
|
|||||||
private: // Ra: stare funkcje skanujące, używane do szukania sygnalizatora z tyłu
|
private: // Ra: stare funkcje skanujące, używane do szukania sygnalizatora z tyłu
|
||||||
bool BackwardTrackBusy(TTrack *Track);
|
bool BackwardTrackBusy(TTrack *Track);
|
||||||
TEvent *CheckTrackEventBackward(double fDirection, TTrack *Track);
|
TEvent *CheckTrackEventBackward(double fDirection, TTrack *Track);
|
||||||
TTrack *BackwardTraceRoute(double &fDistance, double &fDirection, TTrack *Track,
|
TTrack *BackwardTraceRoute(double &fDistance, double &fDirection, TTrack *Track, TEvent *&Event);
|
||||||
TEvent *&Event);
|
|
||||||
void SetProximityVelocity(double dist, double vel, const vector3 *pos);
|
void SetProximityVelocity(double dist, double vel, const vector3 *pos);
|
||||||
TCommandType BackwardScan();
|
TCommandType BackwardScan();
|
||||||
|
|
||||||
@@ -417,13 +393,16 @@ private:
|
|||||||
return ( ( iDrivigFlags & movePrimary ) != 0 ); };
|
return ( ( iDrivigFlags & movePrimary ) != 0 ); };
|
||||||
inline
|
inline
|
||||||
int DrivigFlags() const {
|
int DrivigFlags() const {
|
||||||
return iDrivigFlags;
|
return iDrivigFlags; };
|
||||||
};
|
// returns most recently calculated distance to potential obstacle ahead
|
||||||
|
double
|
||||||
|
TrackBlock() const;
|
||||||
void MoveTo(TDynamicObject *to);
|
void MoveTo(TDynamicObject *to);
|
||||||
void DirectionInitial();
|
void DirectionInitial();
|
||||||
std::string TableText(std::size_t const Index);
|
std::string TableText(std::size_t const Index);
|
||||||
int CrossRoute(TTrack *tr);
|
int CrossRoute(TTrack *tr);
|
||||||
void RouteSwitch(int d);
|
void RouteSwitch(int d);
|
||||||
std::string OwnerName() const;
|
std::string OwnerName() const;
|
||||||
TMoverParameters const *Controlling() const { return mvControlling; }
|
TMoverParameters const *Controlling() const {
|
||||||
|
return mvControlling; }
|
||||||
};
|
};
|
||||||
|
|||||||
57
Ground.cpp
57
Ground.cpp
@@ -2437,7 +2437,7 @@ bool TGround::InitEvents()
|
|||||||
Current->Params[9].asTrack = tmp->pTrack;
|
Current->Params[9].asTrack = tmp->pTrack;
|
||||||
if (!Current->Params[9].asTrack)
|
if (!Current->Params[9].asTrack)
|
||||||
{
|
{
|
||||||
ErrorLog("Bad event: Track \"" + cellastext + "\" does not exist in \"" + Current->asName + "\"");
|
ErrorLog( "Bad event: multi-event \"" + Current->asName + "\" cannot find track \"" + cellastext + "\"" );
|
||||||
Current->iFlags &= ~(conditional_trackoccupied | conditional_trackfree); // zerowanie flag
|
Current->iFlags &= ~(conditional_trackoccupied | conditional_trackfree); // zerowanie flag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2448,7 +2448,7 @@ bool TGround::InitEvents()
|
|||||||
Current->Params[9].asMemCell = tmp->MemCell;
|
Current->Params[9].asMemCell = tmp->MemCell;
|
||||||
if (!Current->Params[9].asMemCell)
|
if (!Current->Params[9].asMemCell)
|
||||||
{
|
{
|
||||||
ErrorLog("Bad event: MemCell \"" + cellastext + "\" does not exist in \"" + Current->asName + "\"");
|
ErrorLog( "Bad event: multi-event \"" + Current->asName + "\" cannot find memory cell \"" + cellastext + "\"" );
|
||||||
Current->iFlags &= ~(conditional_memstring | conditional_memval1 | conditional_memval2);
|
Current->iFlags &= ~(conditional_memstring | conditional_memval1 | conditional_memval2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2459,11 +2459,11 @@ bool TGround::InitEvents()
|
|||||||
cellastext = Current->Params[ i ].asText;
|
cellastext = Current->Params[ i ].asText;
|
||||||
SafeDeleteArray(Current->Params[i].asText);
|
SafeDeleteArray(Current->Params[i].asText);
|
||||||
Current->Params[i].asEvent = FindEvent(cellastext);
|
Current->Params[i].asEvent = FindEvent(cellastext);
|
||||||
if( !Current->Params[ i ].asEvent ) { // Ra: tylko w logu informacja o braku
|
if( !Current->Params[ i ].asEvent ) {
|
||||||
|
// Ra: tylko w logu informacja o braku
|
||||||
if( ( Current->Params[ i ].asText == NULL )
|
if( ( Current->Params[ i ].asText == NULL )
|
||||||
|| ( std::string( Current->Params[ i ].asText ).substr( 0, 5 ) != "none_" ) ) {
|
|| ( std::string( Current->Params[ i ].asText ).substr( 0, 5 ) != "none_" ) ) {
|
||||||
WriteLog( "Event \"" + cellastext + "\" does not exist" );
|
ErrorLog( "Bad event: multi-event \"" + Current->asName + "\" cannot find event \"" + cellastext + "\"" );
|
||||||
ErrorLog( "Missed event: " + cellastext + " in multiple " + Current->asName );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3410,18 +3410,22 @@ bool TGround::CheckQuery()
|
|||||||
owner != nullptr ?
|
owner != nullptr ?
|
||||||
owner->fReady :
|
owner->fReady :
|
||||||
-1.0 );
|
-1.0 );
|
||||||
|
auto const collisiondistance = (
|
||||||
|
owner != nullptr ?
|
||||||
|
owner->TrackBlock() :
|
||||||
|
-1.0 );
|
||||||
|
|
||||||
tmpEvent->Params[ 9 ].asMemCell->UpdateValues(
|
tmpEvent->Params[ 9 ].asMemCell->UpdateValues(
|
||||||
tmpEvent->Activator->MoverParameters->TypeName, // typ pojazdu
|
tmpEvent->Activator->MoverParameters->TypeName, // typ pojazdu
|
||||||
consistbrakelevel,
|
consistbrakelevel,
|
||||||
0, // na razie nic
|
collisiondistance,
|
||||||
tmpEvent->iFlags & ( update_memstring | update_memval1 | update_memval2 ) );
|
tmpEvent->iFlags & ( update_memstring | update_memval1 | update_memval2 ) );
|
||||||
|
|
||||||
WriteLog(
|
WriteLog(
|
||||||
"whois request (" + to_string( tmpEvent->iFlags ) + ") "
|
"whois request (" + to_string( tmpEvent->iFlags ) + ") "
|
||||||
+ "[name: " + tmpEvent->Activator->MoverParameters->TypeName + "], "
|
+ "[name: " + tmpEvent->Activator->MoverParameters->TypeName + "], "
|
||||||
+ "[consist brake level: " + to_string( consistbrakelevel, 2 ) + "], "
|
+ "[consist brake level: " + to_string( consistbrakelevel, 2 ) + "], "
|
||||||
+ "[]" );
|
+ "[obstacle distance: " + to_string( collisiondistance, 2 ) + " m]" );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// jeśli parametry ładunku
|
// jeśli parametry ładunku
|
||||||
@@ -3589,6 +3593,45 @@ TGround::Update_Lights() {
|
|||||||
m_lights.update();
|
m_lights.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TGround::Update_Hidden() {
|
||||||
|
|
||||||
|
// rednerowanie globalnych (nie za często?)
|
||||||
|
for( TGroundNode *node = srGlobal.nRenderHidden; node; node = node->nNext3 ) {
|
||||||
|
node->RenderHidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
// render events and sounds from sectors near enough to the viewer
|
||||||
|
auto const range = 2750.0; // audible range of 100 db sound
|
||||||
|
int const camerax = static_cast<int>( std::floor( Global::pCameraPosition.x / 1000.0 ) + iNumRects / 2 );
|
||||||
|
int const cameraz = static_cast<int>( std::floor( Global::pCameraPosition.z / 1000.0 ) + iNumRects / 2 );
|
||||||
|
int const segmentcount = 2 * static_cast<int>( std::ceil( range / 1000.0 ) );
|
||||||
|
int const originx = std::max( 0, camerax - segmentcount / 2 );
|
||||||
|
int const originz = std::max( 0, cameraz - segmentcount / 2 );
|
||||||
|
|
||||||
|
for( int column = originx; column <= originx + segmentcount; ++column ) {
|
||||||
|
for( int row = originz; row <= originz + segmentcount; ++row ) {
|
||||||
|
|
||||||
|
auto &cell = Rects[ column ][ row ];
|
||||||
|
|
||||||
|
for( int subcellcolumn = 0; subcellcolumn < iNumSubRects; ++subcellcolumn ) {
|
||||||
|
for( int subcellrow = 0; subcellrow < iNumSubRects; ++subcellrow ) {
|
||||||
|
auto subcell = cell.FastGetSubRect( subcellcolumn, subcellrow );
|
||||||
|
if( subcell == nullptr ) { continue; }
|
||||||
|
// renderowanie obiektów aktywnych a niewidocznych
|
||||||
|
for( auto node = subcell->nRenderHidden; node; node = node->nNext3 ) {
|
||||||
|
node->RenderHidden();
|
||||||
|
}
|
||||||
|
// jeszcze dźwięki pojazdów by się przydały, również niewidocznych
|
||||||
|
// TODO: move to sound renderer
|
||||||
|
subcell->RenderSounds();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Winger 170204 - szukanie trakcji nad pantografami
|
// Winger 170204 - szukanie trakcji nad pantografami
|
||||||
bool TGround::GetTraction(TDynamicObject *model)
|
bool TGround::GetTraction(TDynamicObject *model)
|
||||||
{ // aktualizacja drutu zasilającego dla każdego pantografu, żeby odczytać napięcie
|
{ // aktualizacja drutu zasilającego dla każdego pantografu, żeby odczytać napięcie
|
||||||
|
|||||||
3
Ground.h
3
Ground.h
@@ -228,7 +228,7 @@ public:
|
|||||||
return pSubRects + iRow * iNumSubRects + iCol; // zwrócenie właściwego
|
return pSubRects + iRow * iNumSubRects + iCol; // zwrócenie właściwego
|
||||||
};
|
};
|
||||||
// pobranie wskaźnika do małego kwadratu, bez tworzenia jeśli nie ma
|
// pobranie wskaźnika do małego kwadratu, bez tworzenia jeśli nie ma
|
||||||
TSubRect * FastGetSubRect(int iCol, int iRow) {
|
TSubRect *FastGetSubRect(int iCol, int iRow) const {
|
||||||
return (
|
return (
|
||||||
pSubRects ?
|
pSubRects ?
|
||||||
pSubRects + iRow * iNumSubRects + iCol :
|
pSubRects + iRow * iNumSubRects + iCol :
|
||||||
@@ -289,6 +289,7 @@ class TGround
|
|||||||
void UpdatePhys(double dt, int iter); // aktualizacja fizyki stałym krokiem
|
void UpdatePhys(double dt, int iter); // aktualizacja fizyki stałym krokiem
|
||||||
bool Update(double dt, int iter); // aktualizacja przesunięć zgodna z FPS
|
bool Update(double dt, int iter); // aktualizacja przesunięć zgodna z FPS
|
||||||
void Update_Lights(); // updates scene lights array
|
void Update_Lights(); // updates scene lights array
|
||||||
|
void Update_Hidden(); // updates invisible elements of the scene
|
||||||
bool AddToQuery(TEvent *Event, TDynamicObject *Node);
|
bool AddToQuery(TEvent *Event, TDynamicObject *Node);
|
||||||
bool GetTraction(TDynamicObject *model);
|
bool GetTraction(TDynamicObject *model);
|
||||||
bool CheckQuery();
|
bool CheckQuery();
|
||||||
|
|||||||
@@ -2532,7 +2532,7 @@ void TTrain::OnCommand_instrumentlighttoggle( TTrain *Train, command_data const
|
|||||||
// TODO: proper control deviced definition for the interiors, that doesn't hinge of presence of 3d submodels
|
// TODO: proper control deviced definition for the interiors, that doesn't hinge of presence of 3d submodels
|
||||||
if( Train->ggInstrumentLightButton.SubModel == nullptr ) {
|
if( Train->ggInstrumentLightButton.SubModel == nullptr ) {
|
||||||
if( Command.action == GLFW_PRESS ) {
|
if( Command.action == GLFW_PRESS ) {
|
||||||
WriteLog( "Universal3 switch is missing, or wasn't defined" );
|
WriteLog( "Instrument light switch is missing, or wasn't defined" );
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1052,6 +1052,7 @@ bool TWorld::Update()
|
|||||||
|
|
||||||
Ground.CheckQuery();
|
Ground.CheckQuery();
|
||||||
|
|
||||||
|
Ground.Update_Hidden();
|
||||||
Ground.Update_Lights();
|
Ground.Update_Lights();
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -1452,6 +1453,10 @@ TWorld::Update_UI() {
|
|||||||
+ ", Fr: " + to_string( tmp->MoverParameters->RunningTrack.friction, 2 )
|
+ ", Fr: " + to_string( tmp->MoverParameters->RunningTrack.friction, 2 )
|
||||||
+ ( tmp->MoverParameters->SlippingWheels ? " (!)" : "" );
|
+ ( tmp->MoverParameters->SlippingWheels ? " (!)" : "" );
|
||||||
|
|
||||||
|
if( tmp->Mechanik ) {
|
||||||
|
uitextline2 += "; Ag: " + to_string( tmp->Mechanik->fAccGravity, 2 );
|
||||||
|
}
|
||||||
|
|
||||||
uitextline2 +=
|
uitextline2 +=
|
||||||
"; TC:"
|
"; TC:"
|
||||||
+ to_string( tmp->MoverParameters->TotalCurrent, 0 );
|
+ to_string( tmp->MoverParameters->TotalCurrent, 0 );
|
||||||
|
|||||||
29
renderer.cpp
29
renderer.cpp
@@ -22,6 +22,8 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include "Logs.h"
|
#include "Logs.h"
|
||||||
#include "usefull.h"
|
#include "usefull.h"
|
||||||
|
|
||||||
|
#define EU07_NEW_CAB_RENDERCODE
|
||||||
|
|
||||||
opengl_renderer GfxRenderer;
|
opengl_renderer GfxRenderer;
|
||||||
extern TWorld World;
|
extern TWorld World;
|
||||||
|
|
||||||
@@ -1343,19 +1345,6 @@ opengl_renderer::Render( TGround *Ground ) {
|
|||||||
|
|
||||||
m_drawqueue.clear();
|
m_drawqueue.clear();
|
||||||
|
|
||||||
switch( m_renderpass.draw_mode ) {
|
|
||||||
case rendermode::color: {
|
|
||||||
// rednerowanie globalnych (nie za często?)
|
|
||||||
for( TGroundNode *node = Ground->srGlobal.nRenderHidden; node; node = node->nNext3 ) {
|
|
||||||
node->RenderHidden();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::vec3 const cameraposition { m_renderpass.camera.position() };
|
glm::vec3 const cameraposition { m_renderpass.camera.position() };
|
||||||
int const camerax = static_cast<int>( std::floor( cameraposition.x / 1000.0f ) + iNumRects / 2 );
|
int const camerax = static_cast<int>( std::floor( cameraposition.x / 1000.0f ) + iNumRects / 2 );
|
||||||
int const cameraz = static_cast<int>( std::floor( cameraposition.z / 1000.0f ) + iNumRects / 2 );
|
int const cameraz = static_cast<int>( std::floor( cameraposition.z / 1000.0f ) + iNumRects / 2 );
|
||||||
@@ -1372,20 +1361,6 @@ opengl_renderer::Render( TGround *Ground ) {
|
|||||||
for( int row = originz; row <= originz + segmentcount; ++row ) {
|
for( int row = originz; row <= originz + segmentcount; ++row ) {
|
||||||
|
|
||||||
auto *cell = &Ground->Rects[ column ][ row ];
|
auto *cell = &Ground->Rects[ column ][ row ];
|
||||||
|
|
||||||
for( int subcellcolumn = 0; subcellcolumn < iNumSubRects; ++subcellcolumn ) {
|
|
||||||
for( int subcellrow = 0; subcellrow < iNumSubRects; ++subcellrow ) {
|
|
||||||
auto subcell = cell->FastGetSubRect( subcellcolumn, subcellrow );
|
|
||||||
if( subcell == nullptr ) { continue; }
|
|
||||||
// renderowanie obiektów aktywnych a niewidocznych
|
|
||||||
for( auto node = subcell->nRenderHidden; node; node = node->nNext3 ) {
|
|
||||||
node->RenderHidden();
|
|
||||||
}
|
|
||||||
// jeszcze dźwięki pojazdów by się przydały, również niewidocznych
|
|
||||||
subcell->RenderSounds();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( m_renderpass.camera.visible( cell->m_area ) ) {
|
if( m_renderpass.camera.visible( cell->m_area ) ) {
|
||||||
Render( cell );
|
Render( cell );
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user