16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-19 04:19:19 +02:00

build 170506. minor diagnostics, performance and rendering enhancements

This commit is contained in:
tmj-fstate
2017-05-06 14:31:53 +02:00
parent 381eff2e8c
commit fc2fc3e27c
9 changed files with 80 additions and 189 deletions

View File

@@ -386,13 +386,7 @@ void TSpeedPos::Set(TTrack *track, double dist, int flag)
void TController::TableClear()
{ // wyczyszczenie tablicy
#ifdef EU07_USE_OLD_SPEEDTABLE
iFirst = iLast = 0;
for (int i = 0; i < iSpeedTableSize; ++i) // czyszczenie tabeli prędkości
sSpeedTable[i].Clear();
#else
sSpeedTable.clear();
#endif
iLast = -1;
iTableDirection = 0; // nieznany
tLast = nullptr;
@@ -413,41 +407,20 @@ TEvent * TController::CheckTrackEvent(double fDirection, TTrack *Track)
bool TController::TableAddNew()
{ // zwiększenie użytej tabelki o jeden rekord
#ifdef EU07_USE_OLD_SPEEDTABLE
iLast = ( iLast + 1 ) % iSpeedTableSize;
// TODO: jeszcze sprawdzić, czy się na iFirst nie nałoży
// TODO: wstawić tu wywołanie odtykacza - teraz jest to w TableTraceRoute()
// TODO: jeśli ostatnia pozycja zajęta, ustawiać dodatkowe flagi - teraz jest to w
// TableTraceRoute()
// TODO: przydało by się też posortować tabelkę wg odległości (ale nie w tym miejscu)
#else
sSpeedTable.emplace_back(); // add a new slot
iLast = sSpeedTable.size() - 1;
#endif
return true; // false gdy się nałoży
};
bool TController::TableNotFound(TEvent const *Event) const
{ // sprawdzenie, czy nie został już dodany do tabelki (np. podwójne W4 robi problemy)
#ifdef EU07_USE_OLD_SPEEDTABLE
int j = (iLast + 1) % iSpeedTableSize; // j, aby sprawdzić też ostatnią pozycję
for (int i = iFirst; i != j; i = (i + 1) % iSpeedTableSize)
if ((sSpeedTable[i].iFlags & (spEnabled | spEvent)) == (spEnabled |
spEvent)) // o ile używana pozycja
if (sSpeedTable[i].evEvent == e)
{
if (Global::iWriteLogEnabled & 8)
WriteLog("TableNotFound: Event already in SpeedTable: " + sSpeedTable[i].evEvent->asName);
return false; // już jest, drugi raz dodawać nie ma po co
}
return true; // nie ma, czyli można dodać
#else
auto lookup = std::find_if(
sSpeedTable.begin(),
sSpeedTable.end(),
[Event]( TSpeedPos const &speedpoint ){
return ( ( true == TestFlag( speedpoint.iFlags, spEnabled | spEvent ) )
&& ( speedpoint.evEvent == Event ) ); } );
auto lookup =
std::find_if(
sSpeedTable.begin(),
sSpeedTable.end(),
[Event]( TSpeedPos const &speedpoint ){
return ( ( true == TestFlag( speedpoint.iFlags, spEnabled | spEvent ) )
&& ( speedpoint.evEvent == Event ) ); } );
if( ( Global::iWriteLogEnabled & 8 )
&& ( lookup != sSpeedTable.end() ) ) {
@@ -455,7 +428,6 @@ bool TController::TableNotFound(TEvent const *Event) const
}
return lookup == sSpeedTable.end();
#endif
};
void TController::TableTraceRoute(double fDistance, TDynamicObject *pVehicle)
@@ -480,9 +452,6 @@ void TController::TableTraceRoute(double fDistance, TDynamicObject *pVehicle)
fTrackLength = pTrack->Length() - fTrackLength; // przeskanowana zostanie odległość do Point2
}
fLastVel = pTrack->VelocityGet(); // aktualna prędkość
#ifdef EU07_USE_OLD_SPEEDTABLE
iFirst = iLast = 0;
#endif
sSpeedTable.clear();
iLast = -1;
tLast = nullptr; //żaden nie sprawdzony
@@ -491,65 +460,21 @@ void TController::TableTraceRoute(double fDistance, TDynamicObject *pVehicle)
}
else {
// kontynuacja skanowania od ostatnio sprawdzonego toru (w ostatniej pozycji zawsze jest tor)
// WriteLog("TableTraceRoute: check last track");
#ifdef EU07_USE_OLD_SPEEDTABLE
if( sSpeedTable[ iLast ].iFlags & spEndOfTable ) // zatkanie
{ // jeśli zapełniła się tabelka
if ((iLast + 1) % iSpeedTableSize == iFirst) // jeśli nadal jest zapełniona
{
TablePurger(); // nic się nie da zrobić
return;
}
if ((iLast + 2) % iSpeedTableSize == iFirst) // musi być jeszcze miejsce wolne na
// ewentualny event, bo tor jeszcze nie
// sprawdzony
{
TablePurger();
return; // już lepiej, ale jeszcze nie tym razem
}
sSpeedTable[iLast].iFlags &= 0xBE; // kontynuować próby doskanowania
}
#endif
// znaleziono semafor lub tarczę lub tor z prędkością zero, trzeba sprawdzić czy to nadał semafor
#ifdef EU07_USE_OLD_SPEEDTABLE
if( ( sSemNextStop != nullptr )
&& ( sSemNextStop->fVelNext < 1.0 ) ) {
#else
if( ( SemNextStopIndex != -1 )
&& ( sSpeedTable[SemNextStopIndex].fVelNext < 1.0 ) ) {
#endif
// znaleziono semafor lub tarczę lub tor z prędkością zero, trzeba sprawdzić czy to nadał semafor
// jeśli jest następny semafor to sprawdzamy czy to on nadał zero
#ifdef EU07_USE_OLD_SPEEDTABLE
if( ( OrderCurrentGet() & Obey_train )
&& ( sSemNextStop->iFlags & spSemaphor ) ) {
#else
if( ( OrderCurrentGet() & Obey_train )
&& ( sSpeedTable[SemNextStopIndex].iFlags & spSemaphor ) ) {
#endif
return;
}
else {
#ifdef EU07_USE_OLD_SPEEDTABLE
if( ( OrderCurrentGet() < 0x40 )
&& ( sSemNextStop->iFlags & ( spSemaphor | spShuntSemaphor | spOutsideStation ) ) ) {
#else
if( ( OrderCurrentGet() < 0x40 )
&& ( sSpeedTable[SemNextStopIndex].iFlags & ( spSemaphor | spShuntSemaphor | spOutsideStation ) ) ) {
#endif
return;
}
}
}
#ifdef EU07_USE_OLD_SPEEDTABLE
pTrack = sSpeedTable[iLast].trTrack; // ostatnio sprawdzony tor
if (!pTrack)
return; // koniec toru, to nie ma co sprawdzać (nie ma prawa tak być)
fLastDir = (sSpeedTable[iLast].iFlags & spReverse) ? -1.0 : 1.0; // flaga ustawiona, gdy Point2 toru jest bli<6C>ej
fCurrentDistance = sSpeedTable[iLast].fDist; // aktualna odleg<65>o<EFBFBD><6F> do jego Point1
fTrackLength = (sSpeedTable[iLast].iFlags & (spElapsed | spEnd)) ? 0.0 : pTrack->Length(); // nie dolicza<7A> d<>ugo<67>ci gdy:
// 32-minięty początek,
// 64-jazda do końca toru
#else
auto const &lastspeedpoint = sSpeedTable[ iLast ];
pTrack = lastspeedpoint.trTrack;
assert( pTrack != nullptr );
@@ -565,7 +490,6 @@ void TController::TableTraceRoute(double fDistance, TDynamicObject *pVehicle)
( lastspeedpoint.iFlags & ( spElapsed | spEnd ) != 0 ) ?
0.0 :
pTrack->Length() );
#endif
}
if( fCurrentDistance >= fDistance ) {
@@ -594,59 +518,10 @@ void TController::TableTraceRoute(double fDistance, TDynamicObject *pVehicle)
if( Global::iWriteLogEnabled & 8 ) {
WriteLog( "Speed table for " + OwnerName() + " found new event, " + pEvent->asName );
}
#ifdef EU07_USE_OLD_SPEEDTABLE
if( sSpeedTable[ iLast ].Set( pEvent, fCurrentDistance, OrderCurrentGet() ) ) // dodanie odczytu sygnału
{
fDistance = fCurrentDistance; // jeśli sygnał stop, to nie ma
// potrzeby dalej skanować
sSemNextStop = &sSpeedTable[iLast];
if (!sSemNext)
sSemNext = &sSpeedTable[iLast];
if (Global::iWriteLogEnabled & 8)
WriteLog("Signal stop. Next Semaphor ", false);
if (sSemNextStop)
{
if (Global::iWriteLogEnabled & 8)
WriteLog(sSemNextStop->GetName());
}
else
{
if (Global::iWriteLogEnabled & 8)
WriteLog("none");
}
}
else {
if( sSpeedTable[ iLast ].IsProperSemaphor( OrderCurrentGet() ) &&
sSemNext == NULL )
sSemNext =
&sSpeedTable[ iLast ]; // sprawdzamy czy pierwszy na drodze
if( Global::iWriteLogEnabled & 8 )
WriteLog( "Signal forward. Next Semaphor ", false );
if( sSemNext ) {
if( Global::iWriteLogEnabled & 8 )
WriteLog( sSemNext->GetName() );
}
else {
if( Global::iWriteLogEnabled & 8 )
WriteLog( "none" );
}
}
#else
auto &newspeedpoint = sSpeedTable[ iLast ];
if( newspeedpoint.Set( pEvent, fCurrentDistance, OrderCurrentGet() ) ) {
fDistance = fCurrentDistance; // jeśli sygnał stop, to nie ma potrzeby dalej skanować
#ifdef EU07_USE_OLD_SPEEDTABLE
sSemNextStop = &newspeedpoint;
if( sSemNext == nullptr ) {
sSemNext = &newspeedpoint;
}
if( Global::iWriteLogEnabled & 8 ) {
WriteLog( "(stop signal from "
+ ( sSemNextStop ? sSemNextStop->GetName() : "unknown semaphor" )
+ ")" );
}
#else
SemNextStopIndex = iLast;
if( SemNextIndex == -1 ) {
SemNextIndex = iLast;
@@ -656,20 +531,8 @@ void TController::TableTraceRoute(double fDistance, TDynamicObject *pVehicle)
+ ( SemNextStopIndex != -1 ? sSpeedTable[SemNextStopIndex].GetName() : "unknown semaphor" )
+ ")" );
}
#endif
}
else {
#ifdef EU07_USE_OLD_SPEEDTABLE
if( ( true == newspeedpoint.IsProperSemaphor( OrderCurrentGet() ) )
&& ( sSemNext == nullptr ) ) {
sSemNext = &newspeedpoint; // sprawdzamy czy pierwszy na drodze
}
if( Global::iWriteLogEnabled & 8 ) {
WriteLog( "(forward signal for "
+ ( sSemNext ? sSemNext->GetName() : "unknown semaphor" )
+ ")" );
}
#else
if( ( true == newspeedpoint.IsProperSemaphor( OrderCurrentGet() ) )
&& ( SemNextIndex == -1 ) ) {
SemNextIndex = iLast; // sprawdzamy czy pierwszy na drodze
@@ -679,15 +542,13 @@ void TController::TableTraceRoute(double fDistance, TDynamicObject *pVehicle)
+ ( SemNextIndex != -1 ? sSpeedTable[SemNextIndex].GetName() : "unknown semaphor" )
+ ")" );
}
#endif
}
#endif
}
} // event dodajemy najpierw, żeby móc sprawdzić, czy tor został dodany po odczytaniu prędkości następnego
if ((pTrack->VelocityGet() == 0.0) // zatrzymanie
|| (pTrack->iAction) // jeśli tor ma własności istotne dla skanowania
|| (pTrack->VelocityGet() != fLastVel)) // następuje zmiana prędkości
if( ( pTrack->VelocityGet() == 0.0 ) // zatrzymanie
|| ( pTrack->iAction ) // jeśli tor ma własności istotne dla skanowania
|| ( pTrack->VelocityGet() != fLastVel ) ) // następuje zmiana prędkości
{ // odcinek dodajemy do tabelki, gdy jest istotny dla ruchu
if (TableAddNew())
{ // teraz dodatkowo zapamiętanie wybranego segmentu dla skrzyżowania
@@ -723,12 +584,14 @@ void TController::TableTraceRoute(double fDistance, TDynamicObject *pVehicle)
|| ( ( tLast != nullptr )
&& ( tLast->fRadius != 0.0 ) )) // koniec łuku też jest istotny
{ // albo dla liczenia odległości przy pomocy cięciw - te usuwać po przejechaniu
if (TableAddNew())
if (TableAddNew()) {
// dodanie odcinka do tabelki
sSpeedTable[iLast].Set(
pTrack, fCurrentDistance,
( fLastDir < 0 ?
spEnabled | spCurve | spReverse :
spEnabled | spCurve ) ); // dodanie odcinka do tabelki
spEnabled | spCurve ) );
}
}
}
@@ -766,28 +629,6 @@ void TController::TableTraceRoute(double fDistance, TDynamicObject *pVehicle)
}
}
}
#ifdef EU07_USE_OLD_SPEEDTABLE
if( ( ( iLast + 3 ) % iSpeedTableSize == iFirst ) ?
true :
((iLast + 2) % iSpeedTableSize == iFirst)) // czy tabelka się nie zatka?
{ // jest ryzyko nieznalezienia ograniczenia - ograniczyć prędkość do pozwalającej
// na zatrzymanie na końcu przeskanowanej drogi
TablePurger(); // usunąć pilnie zbędne pozycje
if (((iLast + 3) % iSpeedTableSize == iFirst) ?
true :
((iLast + 2) % iSpeedTableSize == iFirst)) // czy tabelka się nie zatka?
{ // jeśli odtykacz nie pomógł (TODO: zwiększyć rozmiar tabelki)
if (TableAddNew())
sSpeedTable[iLast].Set(
pTrack, fCurrentDistance,
fLastDir < 0 ?
0x10045 :
0x10041); // zapisanie toru jako końcowego (ogranicza prędkosć)
// zapisać w logu, że należy poprawić scenerię?
return; // nie skanujemy dalej, bo nie ma miejsca
}
}
#endif
// zwiększenie skanowanej odległości tylko jeśli istnieje dalszy tor
fTrackLength = pTrack->Length();
}
@@ -796,12 +637,14 @@ void TController::TableTraceRoute(double fDistance, TDynamicObject *pVehicle)
if( ( iLast == -1 )
|| ( false == TestFlag( sSpeedTable[iLast].iFlags, spEnabled | spEnd ) ) ) {
// only if we haven't already marked end of the track
if( TableAddNew() )
if( TableAddNew() ) {
// zapisanie ostatniego sprawdzonego toru
sSpeedTable[iLast].Set(
tLast, fCurrentDistance,
( fLastDir < 0 ?
spEnabled | spEnd | spReverse :
spEnabled | spEnd )); // zapisanie ostatniego sprawdzonego toru
spEnabled | spEnd ));
}
}
// to ostatnia pozycja, bo NULL nic nie da, a może się podpiąć obrotnica, czy jakieś transportery
return;
@@ -1459,6 +1302,9 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN
void TController::TablePurger()
{ // odtykacz: usuwa mniej istotne pozycje ze środka tabelki, aby uniknąć zatkania
//(np. brak ograniczenia pomiędzy zwrotnicami, usunięte sygnały, minięte odcinki łuku)
if( sSpeedTable.size() < 2 ) {
return;
}
// simplest approach should be good enough for start -- just copy whatever is still relevant, then swap
// do a trial run first, to see if we need to bother at all
std::size_t trimcount{ 0 };
@@ -1502,7 +1348,7 @@ void TController::TablePurger()
WriteLog( "Speed table garbage collection for " + OwnerName() + " cut away " + std::to_string( trimcount ) + ( trimcount == 1 ? " record" : " records" ) );
}
// update the data
sSpeedTable = trimmedtable;
std::swap( sSpeedTable, trimmedtable );
iLast = sSpeedTable.size() - 1;
};

View File

@@ -45,6 +45,11 @@ http://mozilla.org/MPL/2.0/.
#define M_2PI 6.283185307179586476925286766559;
const float maxrot = (float)(M_PI / 3.0); // 60°
std::string const TDynamicObject::MED_labels[] = {
"masa: ", "amax: ", "Fzad: ", "FmPN: ", "FmED: ", "FrED: ", "FzPN: ", "nPrF: "
};
//---------------------------------------------------------------------------
void TAnimPant::AKP_4E()
{ // ustawienie wymiarów dla pantografu AKP-4E
@@ -5275,10 +5280,19 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
//---------------------------------------------------------------------------
void TDynamicObject::RadioStop()
{ // zatrzymanie pojazdu
if (Mechanik) // o ile ktoś go prowadzi
if (MoverParameters->SecuritySystem.RadioStop &&
MoverParameters->Radio) // jeśli pojazd ma RadioStop i jest on aktywny
Mechanik->PutCommand("Emergency_brake", 1.0, 1.0, &vPosition, stopRadio);
if( Mechanik ) {
// o ile ktoś go prowadzi
if( ( MoverParameters->SecuritySystem.RadioStop )
&& ( MoverParameters->Radio ) ) {
// jeśli pojazd ma RadioStop i jest on aktywny
Mechanik->PutCommand( "Emergency_brake", 1.0, 1.0, &vPosition, stopRadio );
// add onscreen notification for human driver
// TODO: do it selectively for the 'local' driver once the multiplayer is in
if( false == Mechanik->AIControllFlag ) {
Global::tranTexts.AddLine( "!! RADIO-STOP !!", 0.0, 10.0, false );
}
}
}
};
//---------------------------------------------------------------------------

View File

@@ -546,6 +546,7 @@ public: // modele składowe pojazdu
std::string TextureTest(std::string const &name);
void OverheadTrack(float o);
double MED[9][8]; // lista zmiennych do debugowania hamulca ED
static std::string const MED_labels[ 8 ];
};
//---------------------------------------------------------------------------

View File

@@ -773,6 +773,7 @@ public:
double Ftmax = 0.0;
/*- dla lokomotyw z silnikami indukcyjnymi -*/
double eimc[26];
static std::vector<std::string> const eimc_labels;
/*-dla wagonow*/
double MaxLoad = 0.0; /*masa w T lub ilosc w sztukach - ladownosc*/
std::string LoadAccepted; std::string LoadQuantity; /*co moze byc zaladowane, jednostki miary*/
@@ -939,6 +940,7 @@ public:
/*- zmienne dla lokomotyw z silnikami indukcyjnymi -*/
double eimv[21];
static std::vector<std::string> const eimv_labels;
/*-zmienne dla drezyny*/
double PulseForce = 0.0; /*przylozona sila*/

View File

@@ -22,6 +22,18 @@ http://mozilla.org/MPL/2.0/.
const double dEpsilon = 0.01; // 1cm (zależy od typu sprzęgu...)
const double CouplerTune = 0.1; // skalowanie tlumiennosci
std::vector<std::string> const TMoverParameters::eimc_labels = {
"dfic: ", "dfmax:", "p: ", "scfu: ", "cim: ", "icif: ", "Uzmax:", "Uzh: ", "DU: ", "I0: ",
"fcfu: ", "F0: ", "a1: ", "Pmax: ", "Fh: ", "Ph: ", "Vh0: ", "Vh1: ", "Imax: ", "abed: ",
"eped: "
};
std::vector<std::string> const TMoverParameters::eimv_labels = {
"Fkrt:", "Fmax:", "ks: ", "df: ", "fp: ", "Us: ", "pole:", "Ic: ", "If: ", "M: ",
"Fr: ", "Ipoj:", "Pm: ", "Pe: ", "eta: ", "fkr: ", "Uzsm:", "Pmax:", "Fzad:", "Imax:",
"Fful:"
};
inline long Trunc(float f)
{
return (long)f;

View File

@@ -205,6 +205,11 @@ TTrain::commandhandler_map const TTrain::m_commandhandlers = {
{ user_command::radiotoggle, &TTrain::OnCommand_radiotoggle }
};
std::vector<std::string> const TTrain::fPress_labels = {
"ch1: ", "ch2: ", "ch3: ", "ch4: ", "ch5: ", "ch6: ", "ch7: ", "ch8: ", "ch9: ", "ch0: "
};
TTrain::TTrain()
{
ActiveUniversal4 = false;
@@ -2767,7 +2772,10 @@ void TTrain::OnCommand_radiotoggle( TTrain *Train, command_data const &Command )
if( Command.action == GLFW_PRESS ) {
WriteLog( "Radio switch is missing, or wasn't defined" );
}
/*
// NOTE: we ignore the lack of 3d model to allow system reset after receiving radio-stop signal
return;
*/
}
if( Command.action == GLFW_PRESS ) {

View File

@@ -484,6 +484,7 @@ public: // reszta może by?publiczna
public:
float fPress[20][3]; // cisnienia dla wszystkich czlonow
static std::vector<std::string> const fPress_labels;
float fEIMParams[9][10]; // parametry dla silnikow asynchronicznych
int RadioChannel() { return iRadioChannel; };
inline TDynamicObject *Dynamic() { return DynamicObject; };

View File

@@ -2131,21 +2131,22 @@ TWorld::Update_UI() {
// induction motor data
if( tmp->MoverParameters->EngineType == ElectricInductionMotor ) {
UITable->text_lines.emplace_back( " eimc: eimv: press:", Global::UITextColor );
UITable->text_lines.emplace_back( " eimc: eimv: press:", Global::UITextColor );
for( int i = 0; i <= 20; ++i ) {
std::string parameters =
to_string(tmp->MoverParameters->eimc[i], 2, 9)
+ " " + to_string( tmp->MoverParameters->eimv[ i ], 2, 9 );
tmp->MoverParameters->eimc_labels[ i ] + to_string( tmp->MoverParameters->eimc[ i ], 2, 9 )
+ " | "
+ tmp->MoverParameters->eimv_labels[ i ] + to_string( tmp->MoverParameters->eimv[ i ], 2, 9 );
if( i <= 10 ) {
parameters += " " + to_string( Train->fPress[ i ][ 0 ], 2, 9 );
if( i < 10 ) {
parameters += " | " + Train->fPress_labels[i] + to_string( Train->fPress[ i ][ 0 ], 2, 9 );
}
else if( i == 12 ) {
parameters += " med:";
parameters += " med:";
}
else if( i >= 13 ) {
parameters += " " + to_string( tmp->MED[ 0 ][ i - 13 ], 2, 9 );
parameters += " | " + tmp->MED_labels[ i - 13 ] + to_string( tmp->MED[ 0 ][ i - 13 ], 2, 9 );
}
UITable->text_lines.emplace_back( parameters, Global::UITextColor );

View File

@@ -167,8 +167,14 @@ opengl_renderer::Render( world_environment *Environment ) {
::glDisable( GL_DEPTH_TEST );
::glDepthMask( GL_FALSE );
::glPushMatrix();
/*
::glTranslatef( Global::pCameraPosition.x, Global::pCameraPosition.y, Global::pCameraPosition.z );
*/
glm::mat4 worldcamera;
World.Camera.SetMatrix( worldcamera );
glLoadIdentity();
glMultMatrixf( glm::value_ptr( glm::mat4( glm::mat3( worldcamera ) ) ) );
// setup fog
if( Global::fFogEnd > 0 ) {
// fog setup