diff --git a/AdvSound.h b/AdvSound.h index 9159faf6..9123ac4c 100644 --- a/AdvSound.h +++ b/AdvSound.h @@ -10,7 +10,6 @@ http://mozilla.org/MPL/2.0/. #ifndef AdvSoundH #define AdvSoundH -#include "Sound.h" #include "RealSound.h" #include "parser.h" diff --git a/Driver.cpp b/Driver.cpp index 853c7ee9..bcb60c0a 100644 --- a/Driver.cpp +++ b/Driver.cpp @@ -11,21 +11,21 @@ http://mozilla.org/MPL/2.0/. Copyright (C) 2001-2004 Marcin Wozniak, Maciej Czapkiewicz and others */ + #include "stdafx.h" #include "Driver.h" - +#include +#include "Globals.h" +#include "Logs.h" +#include "mtable.h" #include "DynObj.h" #include "Event.h" -#include "Globals.h" #include "Ground.h" -#include "Logs.h" -#include "McZapkie/MOVER.h" -#include "McZapkie/mctools.h" #include "MemCell.h" #include "World.h" -#include "mtable.h" -#include +#include "McZapkie/mctools.h" +#include "McZapkie/MOVER.h" #define LOGVELOCITY 0 #define LOGORDERS 0 @@ -149,7 +149,7 @@ void TSpeedPos::CommandCheck() case cm_SectionVelocity: // odcinek z ograniczeniem prędkości fVelNext = value1; - fSectionVelocityDist = value2; + fSectionVelocityDist = value2; iFlags |= spSectionVel; break; case cm_RoadVelocity: @@ -166,9 +166,9 @@ void TSpeedPos::CommandCheck() break; case cm_SetProximityVelocity: // musi zostać gdyż inaczej nie działają manewry - fVelNext = -1; + fVelNext = -1; iFlags |= spProximityVelocity; - // fSectionVelocityDist = value2; + // fSectionVelocityDist = value2; break; case cm_OutsideStation: // w trybie manewrowym: skanować od niej wstecz i stanąć po wyjechaniu za sygnalizator i @@ -177,7 +177,7 @@ void TSpeedPos::CommandCheck() fVelNext = -1; iFlags |= spOutsideStation; // W5 break; - default: + default: // inna komenda w evencie skanowanym powoduje zatrzymanie i wysłanie tej komendy iFlags &= ~(spShuntSemaphor | spPassengerStopPoint | spStopOnSBL); // nie manewrowa, nie przystanek, nie zatrzymać na SBL @@ -242,12 +242,12 @@ bool TSpeedPos::Update(vector3 *p, vector3 *dir, double &len) // ograniczona w skrzyżowaniu (velocity z ujemną wartością) if ((iFlags & spElapsed) == 0) // jeśli nie wjechał if (trTrack->iNumDynamics > 0) // a skrzyżowanie zawiera pojazd - { - if (Global::iWriteLogEnabled & 8) + { + if (Global::iWriteLogEnabled & 8) WriteLog("Tor " + trTrack->NameGet() + " zajety przed pojazdem. Num=" + std::to_string(trTrack->iNumDynamics) + "Dist= " + std::to_string(fDist)); - fVelNext = + fVelNext = 0.0; // to zabronić wjazdu (chyba że ten z przodu też jedzie prosto) - } + } } if (iFlags & spSwitch) // jeśli odcinek zmienny { @@ -263,16 +263,16 @@ bool TSpeedPos::Update(vector3 *p, vector3 *dir, double &len) } // poniższe nie dotyczy trybu łączenia? if ((iFlags & spElapsed) ? false : - trTrack->iNumDynamics > + trTrack->iNumDynamics > 0) // jeśli jeszcze nie wjechano na tor, a coś na nim jest - { - if (Global::iWriteLogEnabled & 8) + { + if (Global::iWriteLogEnabled & 8) WriteLog("Rozjazd " + trTrack->NameGet() + " zajety przed pojazdem. Num=" + std::to_string(trTrack->iNumDynamics) + "Dist= "+std::to_string(fDist)); //fDist -= 30.0; fVelNext = 0.0; // to niech stanie w zwiększonej odległości // else if (fVelNext==0.0) //jeśli została wyzerowana // fVelNext=trTrack->VelocityGet(); //odczyt prędkości - } + } } } } @@ -287,20 +287,19 @@ bool TSpeedPos::Update(vector3 *p, vector3 *dir, double &len) std::string TSpeedPos::GetName() { if (iFlags & spTrack) // jeśli tor - return trTrack->NameGet(); + return trTrack->NameGet(); else if (iFlags & spEvent) // jeśli event - return evEvent->asName; + return evEvent->asName; } std::string TSpeedPos::TableText() { // pozycja tabelki pr?dko?ci if (iFlags & spEnabled) { // o ile pozycja istotna - return "Flags=#" + to_hex_str(iFlags, 8) + ", Dist=" + to_string(fDist, 1, 7) + + return "Flags=" + to_hex_str(iFlags, 6) + ", Dist=" + to_string(fDist, 1, 7) + ", Vel=" + std::to_string(fVelNext) + ", Name=" + GetName(); - // if (iFlags & spTrack) // je?li tor - // return "Flags=#" + IntToHex(iFlags, 8) + ", Dist=" + FloatToStrF(fDist, ffFixed, 7, 1) - // + + //if (iFlags & spTrack) // jeśli tor + // return "Flags=#" + IntToHex(iFlags, 8) + ", Dist=" + FloatToStrF(fDist, ffFixed, 7, 1) + // ", Vel=" + AnsiString(fVelNext) + ", Track=" + trTrack->NameGet(); //else if (iFlags & spEvent) // jeśli event // return "Flags=#" + IntToHex(iFlags, 8) + ", Dist=" + FloatToStrF(fDist, ffFixed, 7, 1) + @@ -312,17 +311,17 @@ std::string TSpeedPos::TableText() bool TSpeedPos::IsProperSemaphor(TOrders order) { // sprawdzenie czy semafor jest zgodny z trybem jazdy if (order < 0x40) // Wait_for_orders, Prepare_engine, Change_direction, Connect, Disconnect, Shunt - { - if (iFlags & (spSemaphor | spShuntSemaphor)) - return true; - else if (iFlags & spOutsideStation) - return true; - } - else if (order & Obey_train) - { - if (iFlags & spSemaphor) - return true; - } + { + if (iFlags & (spSemaphor | spShuntSemaphor)) + return true; + else if (iFlags & spOutsideStation) + return true; + } + else if (order & Obey_train) + { + if (iFlags & spSemaphor) + return true; + } return false; // true gdy zatrzymanie, wtedy nie ma po co skanować dalej } @@ -337,17 +336,17 @@ bool TSpeedPos::Set(TEvent *event, double dist, TOrders order) // jeśli wskazuje stop wtedy wystawiamy true jako koniec sprawdzania // WriteLog("EventSet: Vel=" + AnsiString(fVelNext) + " iFlags=" + AnsiString(iFlags) + " order="+AnsiString(order)); if (order < 0x40) // Wait_for_orders, Prepare_engine, Change_direction, Connect, Disconnect, Shunt - { - if (iFlags & (spSemaphor | spShuntSemaphor) && fVelNext == 0.0) - return true; - else if (iFlags & spOutsideStation) - return true; - } - else if (order & Obey_train) - { - if (iFlags & spSemaphor && fVelNext == 0.0) - return true; - } + { + if (iFlags & (spSemaphor | spShuntSemaphor) && fVelNext == 0.0) + return true; + else if (iFlags & spOutsideStation) + return true; + } + else if (order & Obey_train) + { + if (iFlags & spSemaphor && fVelNext == 0.0) + return true; + } return false; // true gdy zatrzymanie, wtedy nie ma po co skanować dalej }; @@ -417,19 +416,19 @@ bool TController::TableNotFound(TEvent *e) 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) + 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ć }; void TController::TableTraceRoute(double fDistance, TDynamicObject *pVehicle) { // skanowanie trajektorii na odległość (fDistance) od (pVehicle) w kierunku przodu składu i // uzupełnianie tabelki - // WriteLog("Starting TableTraceRoute"); + // WriteLog("Starting TableTraceRoute"); if (!iDirection) // kierunek pojazdu z napędem { // jeśli kierunek jazdy nie jest okreslony iTableDirection = 0; // czekamy na ustawienie kierunku @@ -458,34 +457,34 @@ 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"); + // WriteLog("TableTraceRoute: check last track"); 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; - } + return; + } if ((iLast + 2) % iSpeedTableSize == iFirst) // musi być jeszcze miejsce wolne na - // ewentualny event, bo tor jeszcze nie - // sprawdzony - { - TablePurger(); + // ewentualny event, bo tor jeszcze nie + // sprawdzony + { + TablePurger(); return; // już lepiej, ale jeszcze nie tym razem - } + } sSpeedTable[iLast].iFlags &= 0xBE; // kontynuować próby doskanowania } // znaleziono semafor lub tarczę lub tor z prędkością zero // trzeba sprawdzić czy to nadał semafor - // WriteLog("TableTraceRoute: "+OwnerName()+" check semaphor... "); + // WriteLog("TableTraceRoute: "+OwnerName()+" check semaphor... "); // if (sSemNext) // WriteLog(sSemNext->TableText()); if (sSemNextStop && sSemNextStop->fVelNext == 0.0) // jeśli jest następny semafor to sprawdzamy czy to on nadał zero { - // WriteLog("TableTraceRoute: "+sSemNext->TableText()); - if ((OrderCurrentGet() & Obey_train) && (sSemNextStop->iFlags & spSemaphor)) + // WriteLog("TableTraceRoute: "+sSemNext->TableText()); + if ((OrderCurrentGet() & Obey_train) && (sSemNextStop->iFlags & spSemaphor)) return; else if ((OrderCurrentGet() < 0x40) && (sSemNextStop->iFlags & (spSemaphor | spShuntSemaphor | spOutsideStation))) @@ -494,12 +493,9 @@ void TController::TableTraceRoute(double fDistance, TDynamicObject *pVehicle) 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żej - fCurrentDistance = sSpeedTable[iLast].fDist; // aktualna odległość do jego Point1 - fTrackLength = - sSpeedTable[iLast].iFlags & (spElapsed | spEnd) ? 0.0 : pTrack->Length(); // nie doliczać długości gdy: + fLastDir = (sSpeedTable[iLast].iFlags & spReverse) ? -1.0 : 1.0; // flaga ustawiona, gdy Point2 toru jest bli�ej + fCurrentDistance = sSpeedTable[iLast].fDist; // aktualna odleg�o�� do jego Point1 + fTrackLength = (sSpeedTable[iLast].iFlags & (spElapsed | spEnd)) ? 0.0 : pTrack->Length(); // nie dolicza� d�ugo�ci gdy: // 32-minięty początek, // 64-jazda do końca toru } @@ -521,27 +517,27 @@ void TController::TableTraceRoute(double fDistance, TDynamicObject *pVehicle) if (TableNotFound(pEvent)) // jeśli nie ma if (TableAddNew()) { - if (Global::iWriteLogEnabled & 8) + if (Global::iWriteLogEnabled & 8) WriteLog("TableTraceRoute: new event found " + pEvent->asName + " by " + OwnerName()); 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 (!sSemNext) + sSemNext = &sSpeedTable[iLast]; + if (Global::iWriteLogEnabled & 8) + WriteLog("Signal stop. Next Semaphor ", false); if (sSemNextStop) - { - if (Global::iWriteLogEnabled & 8) - WriteLog(sSemNextStop->GetName()); - } + { + if (Global::iWriteLogEnabled & 8) + WriteLog(sSemNextStop->GetName()); + } else - { - if (Global::iWriteLogEnabled & 8) - WriteLog("none"); - } + { + if (Global::iWriteLogEnabled & 8) + WriteLog("none"); + } } else { @@ -549,18 +545,18 @@ void TController::TableTraceRoute(double fDistance, TDynamicObject *pVehicle) sSemNext == NULL) sSemNext = &sSpeedTable[iLast]; // sprawdzamy czy pierwszy na drodze - if (Global::iWriteLogEnabled & 8) - WriteLog("Signal forward. Next Semaphor ", false); + if (Global::iWriteLogEnabled & 8) + WriteLog("Signal forward. Next Semaphor ", false); if (sSemNext) - { - if (Global::iWriteLogEnabled & 8) - WriteLog(sSemNext->GetName()); - } + { + if (Global::iWriteLogEnabled & 8) + WriteLog(sSemNext->GetName()); + } else - { - if (Global::iWriteLogEnabled & 8) - WriteLog("none"); - } + { + if (Global::iWriteLogEnabled & 8) + WriteLog("none"); + } } } } // event dodajemy najpierw, żeby móc sprawdzić, czy tor został dodany po @@ -605,7 +601,7 @@ void TController::TableTraceRoute(double fDistance, TDynamicObject *pVehicle) sSpeedTable[iLast].Set(pTrack, fCurrentDistance, fLastDir < 0 ? 0x85 : 0x81); // dodanie odcinka do tabelki - // 0x85 = spEnabled, spReverse, SpCurve + // 0x85 = spEnabled, spReverse, SpCurve } } fCurrentDistance += @@ -709,24 +705,24 @@ void TController::TableCheck(double fDistance) { if (sSpeedTable[i].Update(&pos, &dir, len)) { - if (Global::iWriteLogEnabled & 8) + if (Global::iWriteLogEnabled & 8) WriteLog("TableCheck: Switch change. Delete next entries. (" + sSpeedTable[i].trTrack->NameGet() + ")"); int k = (iLast + 1) % iSpeedTableSize; // skanujemy razem z ostatnią pozycją for (int j = (i+1) % iSpeedTableSize; j != k; j = (j + 1) % iSpeedTableSize) { // kasowanie wszystkich rekordów za zmienioną zwrotnicą - if (Global::iWriteLogEnabled & 8) - WriteLog("TableCheck: Delete from table: " + sSpeedTable[j].GetName()); - sSpeedTable[j].iFlags = 0; - if (&sSpeedTable[j] == sSemNext) + if (Global::iWriteLogEnabled & 8) + WriteLog("TableCheck: Delete from table: " + sSpeedTable[j].GetName()); + sSpeedTable[j].iFlags = 0; + if (&sSpeedTable[j] == sSemNext) sSemNext = NULL; // przy kasowaniu tabelki zrzucamy także semafor - if (&sSpeedTable[j] == sSemNextStop) + if (&sSpeedTable[j] == sSemNextStop) sSemNextStop = NULL; // przy kasowaniu tabelki zrzucamy także semafor - } - if (Global::iWriteLogEnabled & 8) - { - WriteLog("TableCheck: Delete entries OK."); - WriteLog("TableCheck: New last element: " + sSpeedTable[i].GetName()); - } + } + if (Global::iWriteLogEnabled & 8) + { + WriteLog("TableCheck: Delete entries OK."); + WriteLog("TableCheck: New last element: " + sSpeedTable[i].GetName()); + } iLast = i; // pokazujemy gdzie jest ostatni kawałek break; // nie kontynuujemy pętli, trzeba doskanować ciąg dalszy } @@ -740,11 +736,11 @@ void TController::TableCheck(double fDistance) else if ((sSpeedTable[i].iFlags & 0xF0000028) == spElapsed) // jest z tyłu (najechany) i nie jest zwrotnicą ani skrzyżowaniem if (sSpeedTable[i].fVelNext < 0) // a nie ma ograniczenia prędkości - { - sSpeedTable[i].iFlags = + { + sSpeedTable[i].iFlags = 0; // to nie ma go po co trzymać (odtykacz usunie ze środka) // WriteLog("TableCheck: Track without speed. Delete from table: " + sSpeedTable[i].trTrack->NameGet()); - } + } } else if (sSpeedTable[i].iFlags & spEvent) // jeśli event { @@ -756,7 +752,7 @@ void TController::TableCheck(double fDistance) { // pociąg staje zawsze, a samochód tylko jeśli nie przejedzie całą // długością (może być zaskoczony zmianą) // WriteLog("TableCheck: Event is behind. Delete from table: " + sSpeedTable[i].evEvent->asName); - sSpeedTable[i].iFlags &= ~1; // degradacja pozycji dla samochodu; + sSpeedTable[i].iFlags &= ~1; // degradacja pozycji dla samochodu; // semafory usuwane tylko przy sprawdzaniu, // bo wysyłają komendy } @@ -830,9 +826,8 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN // już semafora) #if LOGSTOPS WriteLog(pVehicle->asName + " as " + TrainParams->TrainName + ": at " + - std::to_string(GlobalTime->hh) + ":" + - std::to_string(GlobalTime->mm) + " skipped " + - asNextStop); // informacja + std::to_string(GlobalTime->hh) + ":" + std::to_string(GlobalTime->mm) + + " skipped " + asNextStop); // informacja #endif fLastStopExpDist = mvOccupied->DistCounter + 0.250 + 0.001 * fLength; // przy jakim dystansie (stanie @@ -840,7 +835,7 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN // następny postój TrainParams->UpdateMTable( GlobalTime->hh, GlobalTime->mm, - asNextStop.substr(19, asNextStop.length())); + asNextStop.substr(19, asNextStop.length())); TrainParams->StationIndexInc(); // przejście do następnej asNextStop = TrainParams->NextStop(); // pobranie kolejnego miejsca zatrzymania @@ -985,11 +980,11 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN } if (TrainParams->StationIndex < TrainParams->StationCount) { // jeśli są dalsze stacje, czekamy do godziny odjazdu - + if (TrainParams->IsTimeToGo(GlobalTime->hh, GlobalTime->mm)) { // z dalszą akcją czekamy do godziny odjazdu /* potencjalny problem z ruszaniem z w4 - if (TrainParams->CheckTrainLatency() < 0) + if (TrainParams->CheckTrainLatency() < 0) WaitingSet(20); //Jak spóźniony to czeka 20s */ // iDrivigFlags|=moveLate1; //oflagować, gdy odjazd ze @@ -1008,10 +1003,10 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN std::to_string(GlobalTime->mm) + " next " + asNextStop); // informacja #endif - if (int(floor(sSpeedTable[i].evEvent->ValueGet(1))) & 1) + if (int(floor(sSpeedTable[i].evEvent->ValueGet(1))) & 1) iDrivigFlags |= moveStopHere; // nie podjeżdżać do semafora, // jeśli droga nie jest wolna - else + else iDrivigFlags &= ~moveStopHere; //po czasie jedź dalej iDrivigFlags |= moveStopCloser; // do następnego W4 podjechać // blisko (z dociąganiem) @@ -1074,14 +1069,14 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN // sprawdzanie eventów pasywnych miniętych if (sSpeedTable[i].fDist < 0.0 && sSemNext == &sSpeedTable[i]) { - if (Global::iWriteLogEnabled & 8) + if (Global::iWriteLogEnabled & 8) WriteLog("TableUpdate: semaphor " + sSemNext->GetName() + " passed by " + OwnerName()); sSemNext = NULL; // jeśli minęliśmy semafor od ograniczenia to go kasujemy ze // zmiennej sprawdzającej dla skanowania w przód } if (sSpeedTable[i].fDist < 0.0 && sSemNextStop == &sSpeedTable[i]) { - if (Global::iWriteLogEnabled & 8) + if (Global::iWriteLogEnabled & 8) WriteLog("TableUpdate: semaphor " + sSemNextStop->GetName() + " passed by " + OwnerName()); sSemNextStop = NULL; // jeśli minęliśmy semafor od ograniczenia to go kasujemy ze // zmiennej sprawdzającej dla skanowania w przód @@ -1095,13 +1090,13 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN // semafor a wcześniej // byl nowy to go dorzucamy do zmiennej, żeby cały // czas widział najbliższy - if (Global::iWriteLogEnabled & 8) + if (Global::iWriteLogEnabled & 8) WriteLog("TableUpdate: Next semaphor: " + sSemNext->GetName() + " by " + OwnerName()); } if (!sSemNextStop || (sSemNextStop && sSemNextStop->fVelNext != 0 && sSpeedTable[i].fVelNext == 0)) sSemNextStop = &sSpeedTable[i]; - } + } if (sSpeedTable[i].iFlags & spOutsideStation) { // jeśli W5, to reakcja zależna od trybu jazdy if (OrderCurrentGet() & Obey_train) @@ -1148,17 +1143,13 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN } else if (sSpeedTable[i].IsProperSemaphor(OrderCurrentGet())) { // to semaphor - if (sSpeedTable[i].fDist < 0) + if (sSpeedTable[i].fDist < 0) VelSignalLast = sSpeedTable[i].fVelNext; //minięty daje prędkość obowiązującą - else - { + else + { iDrivigFlags |= moveSemaphorFound; //jeśli z przodu to dajemy falgę, że jest - d_to_next_sem = Min0R(sSpeedTable[i].fDist, d_to_next_sem); - } - if (sSpeedTable[i].fDist <= d_to_next_sem) - { - VelSignalNext = sSpeedTable[i].fVelNext; - } + d_to_next_sem = Min0R(sSpeedTable[i].fDist, d_to_next_sem); + } } else if (sSpeedTable[i].iFlags & spRoadVel) { // to W6 @@ -1171,7 +1162,7 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN { if (sSpeedTable[i].fSectionVelocityDist == 0.0) { - if (Global::iWriteLogEnabled & 8) + if (Global::iWriteLogEnabled & 8) WriteLog("TableUpdate: Event is behind. SVD = 0: " + sSpeedTable[i].evEvent->asName); sSpeedTable[i].iFlags = 0; // jeśli punktowy to kasujemy i nie dajemy ograniczenia na stałe } @@ -1185,7 +1176,7 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN else if (sSpeedTable[i].fDist < -fLength) { // jeśli większe to musi wyjechać za poprzednie VelLimitLast = sSpeedTable[i].fVelNext; - if (Global::iWriteLogEnabled & 8) + if (Global::iWriteLogEnabled & 8) WriteLog("TableUpdate: Event is behind. SVD < 0: " + sSpeedTable[i].evEvent->asName); sSpeedTable[i].iFlags = 0; // wyjechaliśmy poza poprzednie, można skasować } @@ -1204,7 +1195,7 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN else if (sSpeedTable[i].fDist < -fLength - sSpeedTable[i].fSectionVelocityDist) { // VelLimitLast = -1.0; - if (Global::iWriteLogEnabled & 8) + if (Global::iWriteLogEnabled & 8) WriteLog("TableUpdate: Event is behind. SVD > 0: " + sSpeedTable[i].evEvent->asName); sSpeedTable[i].iFlags = 0; // wyjechaliśmy poza poprzednie, można skasować } @@ -1252,24 +1243,24 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN } else if (!(sSpeedTable[i].iFlags & spSectionVel)) //jeśli jakiś event pasywny ale nie ograniczenie if (go == cm_Unknown) // jeśli nie było komendy wcześniej - pierwsza się liczy - // - ustawianie VelSignal + // - ustawianie VelSignal if (v < 0.0 ? true : v >= 1.0) // bo wartość 0.1 służy do hamowania tylko - { + { go = cm_SetVelocity; // może odjechać // Ra 2014-06: (VelSignal) nie może być tu ustawiane, bo semafor może // być daleko // VelSignal=v; //nie do końca tak, to jest druga prędkość; -1 nie // wpisywać... - if (VelSignal == 0.0) + if (VelSignal == 0.0) VelSignal = -1.0; // aby stojący ruszył if (sSpeedTable[i].fDist < 0.0) // jeśli przejechany - { - if (v != 0 ? VelSignal = -1.0 : VelSignal = 0.0) + { + if (v != 0 ? VelSignal = -1.0 : VelSignal = 0.0) ; // ustawienie, gdy przejechany jest lepsze niż - // wcale, ale to jeszcze nie to + // wcale, ale to jeszcze nie to if (sSpeedTable[i].iFlags & spEvent) // jeśli event - if ((sSpeedTable[i].evEvent != eSignSkip) ? - true : + if ((sSpeedTable[i].evEvent != eSignSkip) ? + true : (sSpeedTable[i].fVelNext != 0.0)) // ale inny niż ten, // na którym minięto // S1, chyba że się @@ -1277,29 +1268,29 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN iDrivigFlags &= ~moveVisibility; // sygnał zezwalający na // jazdę wyłącza jazdę na // widoczność (S1 na SBL) - + // usunąć jeśli nie jest ograniczeniem prędkości - sSpeedTable[i].iFlags = + sSpeedTable[i].iFlags = 0; // to można usunąć (nie mogą być usuwane w skanowaniu) + } } - } - else if (sSpeedTable[i].evEvent->StopCommand()) + else if (sSpeedTable[i].evEvent->StopCommand()) { // jeśli prędkość jest zerowa, a komórka zawiera komendę - eSignNext = sSpeedTable[i].evEvent; // dla informacji - if (iDrivigFlags & + eSignNext = sSpeedTable[i].evEvent; // dla informacji + if (iDrivigFlags & moveStopHere) // jeśli ma stać, dostaje komendę od razu go = cm_Command; // komenda z komórki, do wykonania po zatrzymaniu else if (sSpeedTable[i].fDist <= 20.0) // jeśli ma dociągnąć, to niech // dociąga (moveStopCloser // dotyczy dociągania do W4, nie - // semafora) + // semafora) go = cm_Command; // komenda z komórki, do wykonania po zatrzymaniu - } + } } // jeśli nie ma zawalidrogi } // jeśli event if (v >= 0.0) { // pozycje z prędkością -1 można spokojnie pomijać - d = sSpeedTable[i].fDist; + d = sSpeedTable[i].fDist; if ((sSpeedTable[i].iFlags & spElapsed) ? false : d > 0.0) // sygnał lub ograniczenie z przodu (+32=przejechane) @@ -1355,7 +1346,7 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN } // if (v>=0.0) if (fNext >= 0.0) { // jeśli ograniczenie - if ((sSpeedTable[i].iFlags & (spEnabled | spEvent)) == + if ((sSpeedTable[i].iFlags & (spEnabled | spEvent)) == (spEnabled | spEvent)) // tylko sygnał przypisujemy if (!eSignNext) // jeśli jeszcze nic nie zapisane tam eSignNext = sSpeedTable[i].evEvent; // dla informacji @@ -1365,25 +1356,25 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN } // if (sSpeedTable[i].iFlags&1) } // for - if (VelSignalLast >= 0.0 && !(iDrivigFlags & (moveSemaphorFound | moveSwitchFound)) && - (OrderCurrentGet() & Obey_train)) + if (VelSignalLast >= 0.0 && !(iDrivigFlags & (moveSemaphorFound | moveSwitchFound)) && + (OrderCurrentGet() & Obey_train)) VelSignalLast = -1.0; // jeśli mieliśmy ograniczenie z semafora i nie ma przed nami if (VelSignalLast >= 0.0) //analiza spisanych z tabelki ograniczeń i nadpisanie aktualnego - fVelDes = Min0R(fVelDes, VelSignalLast); - if (VelLimitLast >= 0.0) - fVelDes = Min0R(fVelDes, VelLimitLast); - if (VelRoad >= 0.0) - fVelDes = Min0R(fVelDes, VelRoad); + fVelDes = Min0R(fVelDes, VelSignalLast); + if (VelLimitLast >= 0.0) + fVelDes = Min0R(fVelDes, VelLimitLast); + if (VelRoad >= 0.0) + fVelDes = Min0R(fVelDes, VelRoad); // nastepnego semafora albo zwrotnicy to uznajemy, że mijamy W5 - FirstSemaphorDist = d_to_next_sem; // przepisanie znalezionej wartosci do zmiennej + FirstSemaphorDist = d_to_next_sem; // przepisanie znalezionej wartosci do zmiennej return go; }; 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 (Global::iWriteLogEnabled & 8) + if (Global::iWriteLogEnabled & 8) WriteLog("TablePurger: Czyszczenie tabelki."); int i, j, k = iLast - iFirst; // może być 15 albo 16 pozycji, ostatniej nie ma co sprawdzać if (k < 0) @@ -1395,15 +1386,15 @@ void TController::TablePurger() true) { // jeśli jest to minięty (0x20) tor (0x03) do liczenia cięciw (0x80), a nie zwrotnica // (0x08) - for (; k > 0; --k, i = (i + 1) % iSpeedTableSize) - { - sSpeedTable[i] = sSpeedTable[(i + 1) % iSpeedTableSize]; // skopiowanie - if (&sSpeedTable[(i + 1) % iSpeedTableSize] == sSemNext) - sSemNext = &sSpeedTable[i]; // przeniesienie znacznika o semaforze - if (&sSpeedTable[(i + 1) % iSpeedTableSize] == sSemNextStop) - sSemNextStop = &sSpeedTable[i]; // przeniesienie znacznika o semaforze - } - if (Global::iWriteLogEnabled & 8) + for (; k > 0; --k, i = (i + 1) % iSpeedTableSize) + { + sSpeedTable[i] = sSpeedTable[(i + 1) % iSpeedTableSize]; // skopiowanie + if (&sSpeedTable[(i + 1) % iSpeedTableSize] == sSemNext) + sSemNext = &sSpeedTable[i]; // przeniesienie znacznika o semaforze + if (&sSpeedTable[(i + 1) % iSpeedTableSize] == sSemNextStop) + sSemNextStop = &sSpeedTable[i]; // przeniesienie znacznika o semaforze + } + if (Global::iWriteLogEnabled & 8) WriteLog("Odtykacz usuwa pozycję"); iLast = (iLast - 1 + iSpeedTableSize) % iSpeedTableSize; // cofnięcie z zawinięciem return; @@ -1428,7 +1419,7 @@ void TController::TablePurger() delete[] sSpeedTable; // to już nie potrzebne sSpeedTable = t; // bo jest nowe iSpeedTableSize += 16; - if (Global::iWriteLogEnabled & 8) + if (Global::iWriteLogEnabled & 8) WriteLog("Tabelka powiększona do "+std::to_string(iSpeedTableSize)+" pozycji"); }; //--------------------------------------------------------------------------- @@ -1450,7 +1441,7 @@ TController::TController(bool AI, TDynamicObject *NewControll, bool InitPsyche, HelpMeFlag = false; // fProximityDist=1; //nie używane ActualProximityDist = 1; - FirstSemaphorDist = 10000.0; + FirstSemaphorDist = 10000.0; vCommandLocation.x = 0; vCommandLocation.y = 0; vCommandLocation.z = 0; @@ -1531,7 +1522,7 @@ TController::TController(bool AI, TDynamicObject *NewControll, bool InitPsyche, fLength = 0.0; fMass = 0.0; //[kg] eSignNext = NULL; // sygnał zmieniający prędkość, do pokazania na [F2] - sSemNext = NULL; // pierwszy semafor w przebiegu + sSemNext = NULL; // pierwszy semafor w przebiegu sSemNextStop = NULL; // pierwszy semafor z sygnałem stój fShuntVelocity = 40; // domyślna prędkość manewrowa fStopTime = 0.0; // czas postoju przed dalszą jazdą (np. na przystanku) @@ -1890,7 +1881,7 @@ bool TController::CheckVehicles(TOrders user) { // jeśli pojazd posiada pantograf, to przydzielamy mu maskę, którą będzie informował o // jeździe bezprądowej p->iOverheadMask = pantmask; - pantmask << 1; // przesunięcie bitów, max. 32 pojazdy z pantografami w składzie + pantmask = pantmask << 1; // przesunięcie bitów, max. 32 pojazdy z pantografami w składzie } d = p->DirectionSet(d ? 1 : -1); // zwraca położenie następnego (1=zgodny,0=odwrócony - // względem czoła składu) @@ -1910,7 +1901,7 @@ bool TController::CheckVehicles(TOrders user) else if (OrderCurrentGet() & (Shunt | Connect)) { Lights(16, (pVehicles[1]->MoverParameters->CabNo) ? - 1 : + 1 : 0); //światła manewrowe (Tb1) na pojeździe z napędem if (OrderCurrentGet() & Connect) // jeśli łączenie, skanować dalej pVehicles[0]->fScanDist = @@ -2173,10 +2164,9 @@ void TController::SetDriverPsyche() bool TController::PrepareEngine() { // odpalanie silnika - bool OK; - bool voltfront, voltrear; - voltfront = false; - voltrear = false; + bool OK = false, + voltfront = false, + voltrear = false; LastReactionTime = 0.0; ReactionTime = PrepareTime; iDrivigFlags |= moveActive; // może skanować sygnały i reagować na komendy @@ -2320,7 +2310,7 @@ bool TController::PrepareEngine() if (OK) { if (eStopReason == stopSleep) // jeśli dotychczas spał - eStopReason == stopNone; // teraz nie ma powodu do stania + eStopReason = stopNone; // teraz nie ma powodu do stania iEngineActive = 1; return true; } @@ -2397,10 +2387,10 @@ bool TController::IncBrake() switch (mvOccupied->BrakeSystem) { case Individual: - if (mvOccupied->LocalBrake == ManualBrake) - OK = mvOccupied->IncManualBrakeLevel(1 + floor(0.5 + fabs(AccDesired))); - else - OK = mvOccupied->IncLocalBrakeLevel(1 + floor(0.5 + fabs(AccDesired))); + if (mvOccupied->LocalBrake == ManualBrake) + OK = mvOccupied->IncManualBrakeLevel(1 + floor(0.5 + fabs(AccDesired))); + else + OK = mvOccupied->IncLocalBrakeLevel(1 + floor(0.5 + fabs(AccDesired))); break; case Pneumatic: if ((mvOccupied->Couplers[0].Connected == NULL) && @@ -2443,11 +2433,11 @@ bool TController::IncBrake() mvOccupied->BrakeReleaser(0); break; case ElectroPneumatic: - if (mvOccupied->EngineType == ElectricInductionMotor) - { - OK = mvOccupied->IncLocalBrakeLevel(1); - } - else if (mvOccupied->fBrakeCtrlPos != mvOccupied->Handle->GetPos(bh_EPB)) + if (mvOccupied->EngineType == ElectricInductionMotor) + { + OK = mvOccupied->IncLocalBrakeLevel(1); + } + else if (mvOccupied->fBrakeCtrlPos != mvOccupied->Handle->GetPos(bh_EPB)) { mvOccupied->BrakeLevelSet(mvOccupied->Handle->GetPos(bh_EPB)); if (mvOccupied->Handle->GetPos(bh_EPR) - mvOccupied->Handle->GetPos(bh_EPN) < 0.1) @@ -2473,10 +2463,10 @@ bool TController::DecBrake() switch (mvOccupied->BrakeSystem) { case Individual: - if (mvOccupied->LocalBrake == ManualBrake) - OK = mvOccupied->DecManualBrakeLevel(1 + floor(0.5 + fabs(AccDesired))); - else - OK = mvOccupied->DecLocalBrakeLevel(1 + floor(0.5 + fabs(AccDesired))); + if (mvOccupied->LocalBrake == ManualBrake) + OK = mvOccupied->DecManualBrakeLevel(1 + floor(0.5 + fabs(AccDesired))); + else + OK = mvOccupied->DecLocalBrakeLevel(1 + floor(0.5 + fabs(AccDesired))); break; case Pneumatic: if (mvOccupied->BrakeCtrlPos > 0) @@ -2487,11 +2477,11 @@ bool TController::DecBrake() Need_BrakeRelease = true; break; case ElectroPneumatic: - if (mvOccupied->EngineType == ElectricInductionMotor) - { - OK = mvOccupied->DecLocalBrakeLevel(1); - } - else if (mvOccupied->fBrakeCtrlPos != mvOccupied->Handle->GetPos(bh_EPR)) + if (mvOccupied->EngineType == ElectricInductionMotor) + { + OK = mvOccupied->DecLocalBrakeLevel(1); + } + else if (mvOccupied->fBrakeCtrlPos != mvOccupied->Handle->GetPos(bh_EPR)) { mvOccupied->BrakeLevelSet(mvOccupied->Handle->GetPos(bh_EPR)); if (mvOccupied->Handle->GetPos(bh_EPR) - mvOccupied->Handle->GetPos(bh_EPN) < 0.1) @@ -2595,15 +2585,15 @@ bool TController::IncSpeed() OK = mvControlling->IncScndCtrl(1); } break; - case ElectricInductionMotor: - if (!mvControlling->FuseFlag) + case ElectricInductionMotor: + if (!mvControlling->FuseFlag) if (Ready || (iDrivigFlags & movePress) || (mvOccupied->ShuntMode)) //{(BrakePress<=0.01*MaxBrakePress)} - { - OK = mvControlling->IncMainCtrl(1); - } + { + OK = mvControlling->IncMainCtrl(1); + } + break; break; - break; - case WheelsDriven: + case WheelsDriven: if (!mvControlling->CabNo) mvControlling->CabActivisation(); if (sin(mvControlling->eAngle) > 0) @@ -2653,8 +2643,8 @@ bool TController::DecSpeed(bool force) break; case Dumb: case DieselElectric: - case ElectricInductionMotor: - OK = mvControlling->DecScndCtrl(2); + case ElectricInductionMotor: + OK = mvControlling->DecScndCtrl(2); if (!OK) OK = mvControlling->DecMainCtrl(2 + (mvControlling->MainCtrlPos / 2)); break; @@ -2817,8 +2807,8 @@ void TController::SpeedSet() break; case Dumb: case DieselElectric: - case ElectricInductionMotor: - break; + case ElectricInductionMotor: + break; // WheelsDriven : // begin // OK:=False; @@ -2955,8 +2945,7 @@ bool TController::PutCommand(std::string NewCommand, double NewValue1, double Ne if (ConversionError == -8) ErrorLog("Missed timetable: " + NewCommand); WriteLog("Cannot load timetable file " + NewCommand + "\r\nError " + - std::to_string(ConversionError) + " in position " + - std::to_string(TrainParams->StationCount)); + std::to_string(ConversionError) + " in position " + std::to_string(TrainParams->StationCount)); NewCommand = ""; // puste, dla wymiennej tekstury } else @@ -2970,21 +2959,20 @@ bool TController::PutCommand(std::string NewCommand, double NewValue1, double Ne NewCommand = Global::asCurrentSceneryPath + NewCommand + ".wav"; // na razie jeden if (FileExists(NewCommand)) { // wczytanie dźwięku odjazdu podawanego bezpośrenido - tsGuardSignal = - new TTextSound(NewCommand.c_str(), 30, pVehicle->GetPosition().x, - pVehicle->GetPosition().y, pVehicle->GetPosition().z, false); + tsGuardSignal = new TTextSound(NewCommand.c_str(), 30, pVehicle->GetPosition().x, + pVehicle->GetPosition().y, pVehicle->GetPosition().z, + false); // rsGuardSignal->Stop(); iGuardRadio = 0; // nie przez radio } else { - NewCommand = NewCommand.insert(NewCommand.find_last_of("."), - "radio"); // wstawienie przed kropkč + NewCommand = NewCommand.insert(NewCommand.find_last_of("."),"radio"); // wstawienie przed kropkč if (FileExists(NewCommand)) { // wczytanie dźwięku odjazdu w wersji radiowej (słychać tylko w kabinie) - tsGuardSignal = new TTextSound( - NewCommand.c_str(), -1, pVehicle->GetPosition().x, - pVehicle->GetPosition().y, pVehicle->GetPosition().z, false); + tsGuardSignal = new TTextSound(NewCommand.c_str(), -1, pVehicle->GetPosition().x, + pVehicle->GetPosition().y, pVehicle->GetPosition().z, + false); iGuardRadio = iRadioChannel; } } @@ -4091,7 +4079,7 @@ bool TController::UpdateSituation(double dt) // Ra 2F1H: z tym (fTrackBlock) to nie jest najlepszy pomysł, bo lepiej by // było porównać z odległością od sygnalizatora z przodu if ((OrderList[OrderPos] & Connect) ? (pVehicles[0]->fTrackBlock > 2000 || pVehicles[0]->fTrackBlock > FirstSemaphorDist) : - true) + true) if ((comm = BackwardScan()) != cm_Unknown) // jeśli w drugą można jechać { // należy sprawdzać odległość od znalezionego sygnalizatora, // aby w przypadku prędkości 0.1 wyciągnąć najpierw skład za @@ -4232,12 +4220,12 @@ bool TController::UpdateSituation(double dt) // VelDesired=fVelMax; //ile fabryka dala (Ra: uwzględione wagony) else if (VelSignal >= 0) // jeśli skład był zatrzymany na początku i teraz już może jechać VelDesired = Global::Min0RSpeed(VelDesired, VelSignal); - - if (mvOccupied->RunningTrack.Velmax >= + + if (mvOccupied->RunningTrack.Velmax >= 0) // ograniczenie prędkości z trajektorii ruchu VelDesired = Global::Min0RSpeed(VelDesired, - mvOccupied->RunningTrack.Velmax); // uwaga na ograniczenia szlakowej! + mvOccupied->RunningTrack.Velmax); // uwaga na ograniczenia szlakowej! if (VelforDriver >= 0) // tu jest zero przy zmianie kierunku jazdy VelDesired = Global::Min0RSpeed(VelDesired, VelforDriver); // Ra: tu może być 40, jeśli // mechanik nie ma znajomości @@ -4254,7 +4242,7 @@ bool TController::UpdateSituation(double dt) if ((sSemNext && sSemNext->fVelNext != 0.0) || (iDrivigFlags & moveStopHere)==0) { // jeśli można jechać, to odpalić dźwięk kierownika oraz zamknąć drzwi w // składzie, jeśli nie mamy czekać na sygnał też trzeba odpalić - + if (iDrivigFlags & moveGuardSignal) { // komunikat od kierownika tu, bo musi być wolna droga i odczekany czas // stania @@ -4427,16 +4415,16 @@ bool TController::UpdateSituation(double dt) if (VelNext > 0.0) AccDesired = AccPreferred; // można jechać else // jeśli daleko jechać nie można - if (ActualProximityDist > + if (ActualProximityDist > fMaxProximityDist) // ale ma kawałek do sygnalizatora - { // if ((iDrivigFlags&moveStopHere)?false:AccPreferred>0) - if (AccPreferred > 0) - AccDesired = AccPreferred; // dociagnij do semafora; - else + { // if ((iDrivigFlags&moveStopHere)?false:AccPreferred>0) + if (AccPreferred > 0) + AccDesired = AccPreferred; // dociagnij do semafora; + else VelDesired = 0.0; //,AccDesired=-fabs(fAccGravity); //stoj (hamuj z siłą // równą składowej stycznej grawitacji) - } - else + } + else VelDesired = 0.0; // VelNext=0 i stoi bliżej niż fMaxProximityDist } else // gdy jedzie wolniej niż potrzeba, albo nie ma przeszkód na drodze @@ -4653,7 +4641,7 @@ bool TController::UpdateSituation(double dt) AccDesired + 0.05))) // u góry ustawia się hamowanie na fAccThreshold // if not MinVelFlag) if (fBrakeTime < 0 ? true : (AccDesired < fAccGravity - 0.3) || - (mvOccupied->BrakeCtrlPos <= 0)) + (mvOccupied->BrakeCtrlPos <= 0)) if (!IncBrake()) // jeśli upłynął czas reakcji hamulca, chyba że // nagłe albo luzował MinVelFlag = true; diff --git a/DynObj.cpp b/DynObj.cpp index 5977c7b6..0d509f7f 100644 --- a/DynObj.cpp +++ b/DynObj.cpp @@ -1,4 +1,4 @@ -/* +/* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not @@ -1886,11 +1886,11 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424" { } } // koniec hamulce - else if (ActPar.substr(0, 1) == "") // tu mozna wpisac inny prefiks i inne rzeczy +/* else if (ActPar.substr(0, 1) == "") // tu mozna wpisac inny prefiks i inne rzeczy { // jakies inne prefiksy } - +*/ } // koniec while kropka if (MoverParameters->CategoryFlag & 2) // jeśli samochód @@ -2522,17 +2522,23 @@ bool TDynamicObject::Update(double dt, double dt1) // ts.R=MyTrack->fRadius; //ujemne promienie są już zamienione przy // wczytywaniu if (Axle0.vAngles.z != Axle1.vAngles.z) - { // wyliczenie promienia z obrotów - // osi - modyfikację zgłosił youBy + { // wyliczenie promienia z obrotów osi - modyfikację zgłosił youBy ts.R = Axle0.vAngles.z - Axle1.vAngles.z; // różnica może dawać stałą ±M_2PI - if (ts.R > M_PI) - ts.R -= M_2PI else if (ts.R < -M_PI) ts.R += M_2PI; // normalizacja + if( ( ts.R > 15000.0 ) || ( ts.R < -15000.0 ) ) { + // szkoda czasu na zbyt duże promienie, 4km to promień nie wymagający przechyłki + ts.R = 0.0; + } + else { + // normalizacja + if( ts.R > M_PI ) { ts.R -= M_2PI; } + else if( ts.R < -M_PI ) { ts.R += M_2PI; } + + if( ts.R != 0.0 ) { + // sin(0) results in division by zero // ts.R=fabs(0.5*MoverParameters->BDist/sin(ts.R*0.5)); - ts.R = -0.5 * MoverParameters->BDist / sin(ts.R * 0.5); - if ((ts.R > 15000.0) || (ts.R < -15000.0)) - ts.R = 0.0; // szkoda czasu na zbyt duże promienie, 4km to promień nie - // wymagający - // przechyłki + ts.R = -0.5 * MoverParameters->BDist / sin( ts.R * 0.5 ); + } + } } else ts.R = 0.0; @@ -2840,7 +2846,7 @@ bool TDynamicObject::Update(double dt, double dt1) i = 0; przek = przek / (np - nPrzekrF); for (TDynamicObject *p = GetFirstDynamic(MoverParameters->ActiveCab < 0 ? 1 : 0, 4); p; - (kier > 0 ? p = p->NextC(4) : p = p->PrevC(4))) + (true == kier ? p = p->NextC(4) : p = p->PrevC(4))) { if (!PrzekrF[i]) { @@ -2851,7 +2857,7 @@ bool TDynamicObject::Update(double dt, double dt1) } i = 0; for (TDynamicObject *p = GetFirstDynamic(MoverParameters->ActiveCab < 0 ? 1 : 0, 4); p; - (kier > 0 ? p = p->NextC(4) : p = p->PrevC(4))) + (true == kier ? p = p->NextC(4) : p = p->PrevC(4))) { float Nmax = ((p->MoverParameters->P2FTrans * p->MoverParameters->MaxBrakePress[0] - p->MoverParameters->BrakeCylSpring) * @@ -3389,24 +3395,24 @@ bool TDynamicObject::Update(double dt, double dt1) // NBMX Obsluga drzwi, MC: zuniwersalnione if ((dDoorMoveL < MoverParameters->DoorMaxShiftL) && (MoverParameters->DoorLeftOpened)) { - rsDoorOpen.Play(1, 0, MechInside, vPosition); + rsDoorOpen.Play(vol, 0, MechInside, vPosition); dDoorMoveL += dt1 * 0.5 * MoverParameters->DoorOpenSpeed; } if ((dDoorMoveL > 0) && (!MoverParameters->DoorLeftOpened)) { - rsDoorClose.Play(1, 0, MechInside, vPosition); + rsDoorClose.Play(vol, 0, MechInside, vPosition); dDoorMoveL -= dt1 * MoverParameters->DoorCloseSpeed; if (dDoorMoveL < 0) dDoorMoveL = 0; } if ((dDoorMoveR < MoverParameters->DoorMaxShiftR) && (MoverParameters->DoorRightOpened)) { - rsDoorOpen.Play(1, 0, MechInside, vPosition); + rsDoorOpen.Play(vol, 0, MechInside, vPosition); dDoorMoveR += dt1 * 0.5 * MoverParameters->DoorOpenSpeed; } if ((dDoorMoveR > 0) && (!MoverParameters->DoorRightOpened)) { - rsDoorClose.Play(1, 0, MechInside, vPosition); + rsDoorClose.Play(vol, 0, MechInside, vPosition); dDoorMoveR -= dt1 * MoverParameters->DoorCloseSpeed; if (dDoorMoveR < 0) dDoorMoveR = 0; @@ -3769,7 +3775,7 @@ void TDynamicObject::RenderSounds() vol = rsSilnik.AM * MoverParameters->dizel_fill + rsSilnik.AA; else vol = - rsSilnik.AM * fabs(MoverParameters->enrot / MoverParameters->nmax) + + rsSilnik.AM * fabs(MoverParameters->enrot / MoverParameters->dizel_nmax) + rsSilnik.AA * 0.9; } else @@ -4245,10 +4251,10 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName, iMultiTex = 0; // czy jest wiele tekstur wymiennych? parser.getTokens(); parser >> asModel; - if (asModel.find('#') == asModel.length()) // Ra 2015-01: nie podoba mi się to + if( asModel[asModel.size() - 1] == '#' ) // Ra 2015-01: nie podoba mi siê to { // model wymaga wielu tekstur wymiennych iMultiTex = 1; - asModel = asModel.substr(0, asModel.length() - 1); + asModel.erase( asModel.length() - 1 ); } if ((i = asModel.find(',')) != std::string::npos) { // Ra 2015-01: może szukać przecinka w @@ -4266,6 +4272,7 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName, // modele w dynamics/basedir Global::asCurrentTexturePath = BaseDir; // biezaca sciezka do tekstur to dynamic/... mdModel = TModelsManager::GetModel(asModel, true); + assert( mdModel != nullptr ); // TODO: handle this more gracefully than all going to shit if (ReplacableSkin != "none") { // tekstura wymienna jest raczej jedynie w "dynamic\" ReplacableSkin = @@ -4451,7 +4458,7 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName, iAnimations = 0; do { // kolejne liczby to ilość animacj, -1 to znacznik końca - parser.getTokens( 1, false ); + parser.getTokens( 1, false ); parser >> ile; // ilość danego typu // animacji // if (co==ANIM_PANTS) @@ -4527,7 +4534,7 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName, } if( token == "brakemode:" ) { - // Ra 15-01: gaďż˝ka nastawy hamulca + // Ra 15-01: gałka nastawy hamulca parser.getTokens(); parser >> asAnimName; smBrakeMode = mdModel->GetFromName(asAnimName.c_str()); @@ -4589,22 +4596,17 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName, // układy if ((k >= 'A') && (k <= 'J')) // 10 chyba maksimum? { - pAnimations[i++].dWheelAngle = - dWheelAngle + 1; // obrót osi napędzających - --k; // następna będzie albo taka sama, albo bierzemy kolejny - // znak + pAnimations[i++].dWheelAngle = dWheelAngle + 1; // obrót osi napędzających + --k; // następna będzie albo taka sama, albo bierzemy kolejny znak m = 2; // następujące toczne będą miały inną średnicę } else if ((k >= '1') && (k <= '9')) { - pAnimations[i++].dWheelAngle = dWheelAngle + m; // obrót osi - // tocznych - --k; // następna będzie albo taka sama, albo bierzemy kolejny - // znak + pAnimations[i++].dWheelAngle = dWheelAngle + m; // obrót osi tocznych + --k; // następna będzie albo taka sama, albo bierzemy kolejny znak } else - k = MoverParameters->AxleArangement[j++]; // pobranie kolejnego - // znaku + k = MoverParameters->AxleArangement[j++]; // pobranie kolejnego znaku } } } @@ -4773,9 +4775,8 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName, m = float4x4( *sm->GetMatrix()); // skopiowanie, bo będziemy mnożyć m( 3 )[ 1 ] = - m[3][1] + 0.054; // w górę o wysokość ślizgu (na razie tak) - while (sm->Parent) - { + m[ 3 ][ 1 ] + 0.054; // w górę o wysokość ślizgu (na razie tak) + while( sm->Parent ) { if( sm->Parent->GetMatrix() ) m = *sm->Parent->GetMatrix() * m; sm = sm->Parent; @@ -5749,19 +5750,10 @@ int TDynamicObject::RouteWish(TTrack *tr) std::string TDynamicObject::TextureTest(std::string const &name) { // Ra 2015-01: sprawdzenie dostępności tekstury o podanej nazwie - std::string x = name + ".dds"; // na razie prymitywnie - if (FileExists(x.c_str())) - return x; - else - { - x = name + ".tga"; // w zasadzie to należałoby uwzględnić deklarowaną kolejność - if (FileExists(x.c_str())) - return x; - else - { - x = name + ".bmp"; - if (FileExists(x.c_str())) - return x; + std::vector extensions = { ".dds", ".tga", ".bmp" }; + for( auto const &extension : extensions ) { + if( true == FileExists( name + extension ) ) { + return name + extension; } } return ""; // nie znaleziona diff --git a/EU07.cpp b/EU07.cpp index 5e27458d..f46fd78a 100644 --- a/EU07.cpp +++ b/EU07.cpp @@ -26,8 +26,9 @@ Stele, firleju, szociu, hunter, ZiomalCl, OLI_EU and others #include "opengl/ARB_Multisample.h" #include "Globals.h" -#include "Console.h" #include "Logs.h" +#include "Console.h" +#include "PyInt.h" #include "World.h" #include "Mover.h" @@ -58,8 +59,8 @@ LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc int InitGL(GLvoid) // All Setup For OpenGL Goes Here { - _clear87(); - _control87(MCW_EM, MCW_EM); +// _clear87(); +// _control87(MCW_EM, MCW_EM); glewInit(); // hunter-271211: przeniesione // AllocConsole(); @@ -571,8 +572,14 @@ int WINAPI WinMain(HINSTANCE hInstance, // instance LPSTR lpCmdLine, // command line parameters int nCmdShow) // window show state { -#ifdef _MSC_VER +#if defined(_MSC_VER) && defined (_DEBUG) + // memory leaks _CrtSetDbgFlag( _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG ) | _CRTDBG_LEAK_CHECK_DF ); + // floating point operation errors + auto state = _clearfp(); + state = _control87( 0, 0 ); + // this will turn on FPE for #IND and zerodiv + state = _control87( state & ~( _EM_ZERODIVIDE | _EM_INVALID ), _MCW_EM ); #endif MSG msg; // windows message structure @@ -582,7 +589,7 @@ int WINAPI WinMain(HINSTANCE hInstance, // instance Global::LoadIniFile("eu07.ini"); // teraz dopiero można przejrzeć plik z ustawieniami Global::InitKeys("keys.ini"); // wczytanie mapowania klawiszy - jest na stałe - // hunter-271211: ukrywanie konsoli + // hunter-271211: ukrywanie konsoli if (Global::iWriteLogEnabled & 2) { AllocConsole(); @@ -701,6 +708,8 @@ int WINAPI WinMain(HINSTANCE hInstance, // instance SystemParametersInfo(SPI_SETKEYBOARDSPEED, iOldSpeed, NULL, 0); SystemParametersInfo(SPI_SETKEYBOARDDELAY, iOldDelay, NULL, 0); delete pConsole; // deaktywania sterownika + TPythonInterpreter::killInstance(); + // shutdown KillGLWindow(); // kill the window return (msg.wParam); // exit the program diff --git a/Event.cpp b/Event.cpp index 157caf48..b509c064 100644 --- a/Event.cpp +++ b/Event.cpp @@ -72,6 +72,9 @@ TEvent::~TEvent() delete[] Params[8].asPointer; // zwolnić obszar case tp_GetValues: // nic break; + case tp_PutValues: // params[0].astext stores the token + SafeDeleteArray( Params[ 0 ].asText ); + break; } evJoined = NULL; // nie usuwać podczepionych tutaj }; @@ -87,6 +90,7 @@ void TEvent::Conditions(cParser *parser, string s) std::string token, str; if (!asNodeName.empty()) { // podczepienie łańcucha, jeśli nie jest pusty + // BUG: source of a memory leak -- the array never gets deleted. fix the destructor Params[9].asText = new char[asNodeName.length() + 1]; // usuwane i zamieniane na // wskaźnik strcpy(Params[9].asText, asNodeName.c_str()); @@ -457,34 +461,43 @@ void TEvent::Load(cParser *parser, vector3 *org) { // obrót względem osi parser->getTokens(); *parser >> token; - Params[9].asText = new char[255]; // nazwa submodelu - strcpy(Params[9].asText, token.c_str()); + Params[9].asText = new char[token.size() + 1]; // nazwa submodelu + std::strcpy(Params[9].asText, token.c_str()); Params[0].asInt = 1; parser->getTokens(4); - *parser >> Params[1].asdouble >> Params[2].asdouble >> Params[3].asdouble >> - Params[4].asdouble; + *parser + >> Params[1].asdouble + >> Params[2].asdouble + >> Params[3].asdouble + >> Params[4].asdouble; } else if (token.compare("translate") == 0) { // przesuw o wektor parser->getTokens(); *parser >> token; - Params[9].asText = new char[255]; // nazwa submodelu - strcpy(Params[9].asText, token.c_str()); + Params[9].asText = new char[token.size() + 1]; // nazwa submodelu + std::strcpy(Params[9].asText, token.c_str()); Params[0].asInt = 2; parser->getTokens(4); - *parser >> Params[1].asdouble >> Params[2].asdouble >> Params[3].asdouble >> - Params[4].asdouble; + *parser + >> Params[1].asdouble + >> Params[2].asdouble + >> Params[3].asdouble + >> Params[4].asdouble; } else if (token.compare("digital") == 0) { // licznik cyfrowy parser->getTokens(); *parser >> token; - Params[9].asText = new char[255]; // nazwa submodelu - strcpy(Params[9].asText, token.c_str()); + Params[9].asText = new char[token.size() + 1]; // nazwa submodelu + std::strcpy(Params[9].asText, token.c_str()); Params[0].asInt = 8; parser->getTokens(4); // jaki ma być sens tych parametrów? - *parser >> Params[1].asdouble >> Params[2].asdouble >> Params[3].asdouble >> - Params[4].asdouble; + *parser + >> Params[1].asdouble + >> Params[2].asdouble + >> Params[3].asdouble + >> Params[4].asdouble; } else if (token.substr(token.length() - 4, 4) == ".vmd") // na razie tu, może będzie inaczej { // animacja z pliku VMD @@ -499,12 +512,15 @@ void TEvent::Load(cParser *parser, vector3 *org) } parser->getTokens(); *parser >> token; - Params[9].asText = new char[255]; // nazwa submodelu - strcpy(Params[9].asText, token.c_str()); + Params[9].asText = new char[token.size() + 1]; // nazwa submodelu + std::strcpy(Params[9].asText, token.c_str()); Params[0].asInt = 4; // rodzaj animacji parser->getTokens(4); - *parser >> Params[1].asdouble >> Params[2].asdouble >> Params[3].asdouble >> - Params[4].asdouble; + *parser + >> Params[1].asdouble + >> Params[2].asdouble + >> Params[3].asdouble + >> Params[4].asdouble; } parser->getTokens(); *parser >> token; diff --git a/Globals.cpp b/Globals.cpp index c1ee6f20..413ad574 100644 --- a/Globals.cpp +++ b/Globals.cpp @@ -187,7 +187,7 @@ int Global::iBpp = 32; // chyba już nie używa się kart, na których 16bpp co // maciek001: konfiguracja wstępna portu COM bool Global::bMWDdebugEnable = false; bool Global::bMWDInputDataEnable = false; -unsigned long int Global::iMWDBaudrate = 500000; +unsigned int Global::iMWDBaudrate = 500000; std::string Global::sMWDPortId = "COM1"; // nazwa portu z którego korzystamy - na razie nie działa bool Global::bMWDBreakEnable = false; // zmienić na FALSE!!! jak już będzie działać wczytywanie z *.ini double Global::fMWDAnalogCalib[4][3] = {{1023, 0, 1023},{1023, 0, 1023},{1023, 0, 1023},{1023, 0, 1023}}; // wartość max potencjometru, wartość min potencjometru, rozdzielczość (max. wartość jaka może być -1) @@ -1247,7 +1247,7 @@ char bezogonkowo[] = "E?,?\"_++?%Sstzz" std::string Global::Bezogonkow(std::string str, bool _) { // wycięcie liter z ogonkami, bo OpenGL nie umie wyświetlić - for (unsigned int i = 1; i <= str.length(); ++i) + for (unsigned int i = 1; i < str.length(); ++i) if (str[i] & 0x80) str[i] = bezogonkowo[str[i] & 0x7F]; else if (str[i] < ' ') // znaki sterujące nie są obsługiwane diff --git a/Ground.cpp b/Ground.cpp index 63a81db9..456ca379 100644 --- a/Ground.cpp +++ b/Ground.cpp @@ -42,7 +42,6 @@ http://mozilla.org/MPL/2.0/. #define _PROBLEND 1 //--------------------------------------------------------------------------- -#pragma package(smart_init) bool bCondition; // McZapkie: do testowania warunku na event multiple string LogComment; @@ -77,7 +76,7 @@ TGroundNode::TGroundNode() asName = ""; // Color= TMaterialColor(1); // fAngle=0; //obrót dla modelu - // fLineThickness=1.0; //mm dla linii + fLineThickness=1.0; //mm dla linii for (int i = 0; i < 3; i++) { Ambient[i] = Global::whiteLight[i] * 255; @@ -117,6 +116,9 @@ TGroundNode::~TGroundNode() delete Model; Model = NULL; break; + case TP_SOUND: + SafeDelete(tsStaticSound); + break; case TP_TERRAIN: { // pierwsze nNode zawiera model E3D, reszta to trójkąty for (int i = 1; i < iCount; ++i) @@ -681,22 +683,12 @@ void TGroundNode::RenderAlphaDL() //------------------------------------------------------------------------------ //------------------ Podstawowy pojemnik terenu - sektor ----------------------- //------------------------------------------------------------------------------ -TSubRect::TSubRect() -{ - nRootNode = NULL; // lista wszystkich obiektów jest pusta - nRenderHidden = nRenderRect = nRenderRectAlpha = nRender = nRenderMixed = nRenderAlpha = - nRenderWires = NULL; - tTrackAnim = NULL; // nic nie animujemy - tTracks = NULL; // nie ma jeszcze torów - nRootMesh = nMeshed = NULL; // te listy też są puste - iNodeCount = 0; // licznik obiektów - iTracks = 0; // licznik torów -} TSubRect::~TSubRect() { if (Global::bManageNodes) // Ra: tu się coś sypie ResourceManager::Unregister(this); // wyrejestrowanie ze sprzątacza // TODO: usunąć obiekty z listy (nRootMesh), bo są one tworzone dla sektora + delete[] tTracks; } void TSubRect::NodeAdd(TGroundNode *Node) @@ -735,7 +727,7 @@ void TSubRect::NodeAdd(TGroundNode *Node) { if (t && (Node->TextureID != t)) { // jeśli są dwie różne tekstury, dodajemy drugi obiekt dla danego toru - TGroundNode *n = new TGroundNode(); + TGroundNode *n = new TGroundNode(); // BUG: source of a memory leak here n->iType = TP_DUMMYTRACK; // obiekt renderujący siatki dla tekstury n->TextureID = t; n->pTrack = Node->pTrack; // wskazuje na ten sam tor @@ -958,7 +950,7 @@ void TSubRect::Sort() if (t < n1->TextureID) // jeśli (n1) ma inną teksturę niż poprzednie { // można zrobić obiekt renderujący t = n1->TextureID; - n2 = new TGroundNode(); + n2 = new TGroundNode(); // BUG: source of a memory leak here n2->nNext2 = nRootMesh; nRootMesh = n2; // podczepienie na początku listy nRootMesh->iType = TP_MESH; // obiekt renderujący siatki dla tekstury @@ -1303,6 +1295,9 @@ void TGround::MoveGroundNode(vector3 pPosition) */ } +TGroundVertex TempVerts[ 10000 ]; // tu wczytywane s¹ trójk¹ty +BYTE TempConnectionType[ 200 ]; // Ra: sprzêgi w sk³adzie; ujemne, gdy odwrotnie + TGround::TGround() { // RootNode=NULL; @@ -1320,6 +1315,8 @@ TGround::TGround() nRootOfType[i] = NULL; // zerowanie tablic wyszukiwania bDynamicRemove = false; // na razie nic do usunięcia sTracks = new TNames(); // nazwy torów - na razie tak + ::SecureZeroMemory( TempVerts, sizeof( TempVerts ) ); + ::SecureZeroMemory( TempConnectionType, sizeof( TempConnectionType ) ); } TGround::~TGround() @@ -1410,9 +1407,6 @@ int iTrainSetWehicleNumber = 0; TGroundNode *nTrainSetNode = NULL; // poprzedni pojazd do łączenia TGroundNode *nTrainSetDriver = NULL; // pojazd, któremu zostanie wysłany rozkład -TGroundVertex TempVerts[10000]; // tu wczytywane są trójkąty -BYTE TempConnectionType[200]; // Ra: sprzęgi w składzie; ujemne, gdy odwrotnie - void TGround::RaTriangleDivider(TGroundNode *node) { // tworzy dodatkowe trójkąty i zmiejsza podany // to jest wywoływane przy wczytywaniu trójkątów @@ -1767,8 +1761,7 @@ TGroundNode * TGround::AddGroundNode(cParser *parser) *parser >> token; str = token; //str = AnsiString(token.c_str()); - tmp->tsStaticSound = new TTextSound(strdup(str.c_str()), sqrt(tmp->fSquareRadius), tmp->pCenter.x, - tmp->pCenter.y, tmp->pCenter.z, false, rmin); + tmp->tsStaticSound = new TTextSound(str, sqrt(tmp->fSquareRadius), tmp->pCenter.x, tmp->pCenter.y, tmp->pCenter.z, false, rmin); if (rmin < 0.0) rmin = 0.0; // przywrócenie poprawnej wartości, jeśli służyła do wyłączenia efektu Dopplera @@ -2273,8 +2266,9 @@ void TGround::FirstInit() for (j = 1; j < Current->iCount; ++j) { // od 1 do końca są zestawy trójkątów std::string xxxzzz = Current->nNode[j].smTerrain->pName; // pobranie nazwy - gr = GetRect(1000 * (stol_def(xxxzzz.substr(0, 3),0) - 500), - 1000 * (stol_def(xxxzzz.substr(3, 3),0) - 500)); + gr = GetRect( + ( std::stoi( xxxzzz.substr( 0, 3 )) - 500 ) * 1000, + ( std::stoi( xxxzzz.substr( 3, 3 )) - 500 ) * 1000 ); if (Global::bUseVBO) gr->nTerrain = Current->nNode + j; // zapamiętanie else @@ -2320,9 +2314,7 @@ void TGround::FirstInit() WriteLog("InitLaunchers OK"); WriteLog("InitGlobalTime"); // ABu 160205: juz nie TODO :) - GlobalTime = new TMTableTime( - hh, mm, srh, srm, ssh, - ssm); // McZapkie-300302: inicjacja czasu rozkladowego - TODO: czytac z trasy! + GlobalTime = std::make_shared( hh, mm, srh, srm, ssh, ssm ); // McZapkie-300302: inicjacja czasu rozkladowego - TODO: czytac z trasy! WriteLog("InitGlobalTime OK"); // jeszcze ustawienie pogody, gdyby nie było w scenerii wpisów glClearColor(Global::AtmoColor[0], Global::AtmoColor[1], Global::AtmoColor[2], @@ -3134,13 +3126,12 @@ bool TGround::InitEvents() strcpy(buff, Current->Params[i].asText); SafeDeleteArray(Current->Params[i].asText); Current->Params[i].asEvent = FindEvent(buff); - if (!Current->Params[i].asEvent) // Ra: tylko w logu informacja o braku - if (string(Current->Params[i].asText).substr(0, 5) != "none_") - { - WriteLog("Event \"" + string(buff) + - "\" does not exist"); - ErrorLog("Missed event: " + string(buff) + " in multiple " + - Current->asName); + if( !Current->Params[ i ].asEvent ) { // Ra: tylko w logu informacja o braku + if( ( Current->Params[ i ].asText == NULL ) + || ( std::string( Current->Params[ i ].asText ).substr( 0, 5 ) != "none_" ) ) { + WriteLog( "Event \"" + string( buff ) + "\" does not exist" ); + ErrorLog( "Missed event: " + string( buff ) + " in multiple " + Current->asName ); + } } } } diff --git a/Ground.h b/Ground.h index 4a17e4f1..588caa81 100644 --- a/Ground.h +++ b/Ground.h @@ -182,28 +182,28 @@ class TGroundNode : public Resource class TSubRect : public Resource, public CMesh { // sektor składowy kwadratu kilometrowego public: - int iTracks; // ilość torów w (tTracks) - TTrack **tTracks; // tory do renderowania pojazdów + int iTracks = 0; // ilość torów w (tTracks) + TTrack **tTracks = nullptr; // tory do renderowania pojazdów protected: - TTrack *tTrackAnim; // obiekty do przeliczenia animacji - TGroundNode *nRootMesh; // obiekty renderujące wg tekstury (wtórne, lista po nNext2) - TGroundNode *nMeshed; // lista obiektów dla których istnieją obiekty renderujące grupowo + TTrack *tTrackAnim = nullptr; // obiekty do przeliczenia animacji + TGroundNode *nRootMesh = nullptr; // obiekty renderujące wg tekstury (wtórne, lista po nNext2) + TGroundNode *nMeshed = nullptr; // lista obiektów dla których istnieją obiekty renderujące grupowo public: TGroundNode * - nRootNode; // wszystkie obiekty w sektorze, z wyjątkiem renderujących i pojazdów (nNext2) + nRootNode = nullptr; // wszystkie obiekty w sektorze, z wyjątkiem renderujących i pojazdów (nNext2) TGroundNode * - nRenderHidden; // lista obiektów niewidocznych, "renderowanych" również z tyłu (nNext3) - TGroundNode *nRenderRect; // z poziomu sektora - nieprzezroczyste (nNext3) - TGroundNode *nRenderRectAlpha; // z poziomu sektora - przezroczyste (nNext3) - TGroundNode *nRenderWires; // z poziomu sektora - druty i inne linie (nNext3) - TGroundNode *nRender; // indywidualnie - nieprzezroczyste (nNext3) - TGroundNode *nRenderMixed; // indywidualnie - nieprzezroczyste i przezroczyste (nNext3) - TGroundNode *nRenderAlpha; // indywidualnie - przezroczyste (nNext3) - int iNodeCount; // licznik obiektów, do pomijania pustych sektorów + nRenderHidden = nullptr; // lista obiektów niewidocznych, "renderowanych" również z tyłu (nNext3) + TGroundNode *nRenderRect = nullptr; // z poziomu sektora - nieprzezroczyste (nNext3) + TGroundNode *nRenderRectAlpha = nullptr; // z poziomu sektora - przezroczyste (nNext3) + TGroundNode *nRenderWires = nullptr; // z poziomu sektora - druty i inne linie (nNext3) + TGroundNode *nRender = nullptr; // indywidualnie - nieprzezroczyste (nNext3) + TGroundNode *nRenderMixed = nullptr; // indywidualnie - nieprzezroczyste i przezroczyste (nNext3) + TGroundNode *nRenderAlpha = nullptr; // indywidualnie - przezroczyste (nNext3) + int iNodeCount = 0; // licznik obiektów, do pomijania pustych sektorów public: void LoadNodes(); // utworzenie VBO sektora public: - TSubRect(); +// TSubRect() = default; virtual ~TSubRect(); virtual void Release(); // zwalnianie VBO sektora void NodeAdd(TGroundNode *Node); // dodanie obiektu do sektora na etapie rozdzielania na sektory diff --git a/MaSzyna.sln b/MaSzyna.sln deleted file mode 100644 index 59bb2771..00000000 --- a/MaSzyna.sln +++ /dev/null @@ -1,22 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.40629.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "maszyna", "maszyna.vcxproj", "{8E0232E5-1C67-442F-9E04-45ED2DDFC960}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x86 = Debug|x86 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {8E0232E5-1C67-442F-9E04-45ED2DDFC960}.Debug|x86.ActiveCfg = Debug|Win32 - {8E0232E5-1C67-442F-9E04-45ED2DDFC960}.Debug|x86.Build.0 = Debug|Win32 - {8E0232E5-1C67-442F-9E04-45ED2DDFC960}.Release|x86.ActiveCfg = Release|Win32 - {8E0232E5-1C67-442F-9E04-45ED2DDFC960}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/Maszyna.vcxproj b/Maszyna.vcxproj deleted file mode 100644 index 35fbdac9..00000000 --- a/Maszyna.vcxproj +++ /dev/null @@ -1,202 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {8E0232E5-1C67-442F-9E04-45ED2DDFC960} - Win32Proj - 8.1 - - - - Application - true - v140_xp - - - Application - false - v120 - - - - - - - - - - - - - eu07++ - $(SolutionDir)tmp\$(PlatformShortName)-$(Configuration)\$(ProjectName)\ - $(SolutionDir)bin\ - - - eu07++ - $(SolutionDir)tmp\$(PlatformShortName)-$(Configuration)\$(ProjectName)\ - $(SolutionDir)bin\ - false - - - - WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - Level3 - EditAndContinue - Disabled - $(SolutionDir);$(SolutionDir)console;$(SolutionDir)mczapkie;$(SolutionDir)opengl;$(SolutionDir)python/include;%(AdditionalIncludeDirectories) - Use - true - false - - - MachineX86 - true - Windows - $(DXSKD_DIR)lib/$(PlatformShortName);$(SolutionDir)opengl;$(SolutionDir)python/libs;%(AdditionalLibraryDirectories) - - - - - WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - MultiThreadedDLL - Level3 - ProgramDatabase - $(SolutionDir);$(SolutionDir)console;$(SolutionDir)mczapkie;$(SolutionDir)opengl;$(SolutionDir)python/include;%(AdditionalIncludeDirectories) - Use - true - - - MachineX86 - true - Windows - true - true - $(DXSKD_DIR)lib/$(PlatformShortName);$(SolutionDir)opengl;$(SolutionDir)python/libs;%(AdditionalLibraryDirectories) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Create - Create - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Maszyna.vcxproj.filters b/Maszyna.vcxproj.filters deleted file mode 100644 index 92d7f549..00000000 --- a/Maszyna.vcxproj.filters +++ /dev/null @@ -1,346 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav - - - {d91dfdb6-7d84-4b52-a16a-bad302b45e3c} - - - {fafd38ab-4c2a-48c8-8e66-ad0d928573b3} - - - {2d73d7b2-5252-499c-963a-88fa3cb1af53} - - - {aec51dd3-af67-4f08-9dcb-889f673ad7c9} - - - {36684428-8a48-435f-bca4-a24d9bfe2587} - - - {cdf75bec-91f7-413c-8b57-9e32cba49148} - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files\opengl - - - Source Files\mczapkie - - - Source Files\mczapkie - - - Source Files\console - - - Source Files\mczapkie - - - Source Files\mczapkie - - - Source Files\mczapkie - - - Source Files\console - - - Source Files - - - Source Files\console - - - - - Header Files\opengl - - - Header Files\opengl - - - Header Files - - - Header Files - - - Header Files - - - Header Files\mczapkie - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files\mczapkie - - - Header Files\mczapkie - - - Header Files\mczapkie - - - Header Files\mczapkie - - - Header Files\console - - - Header Files\console - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files\opengl - - - Header Files\console - - - - - Resource Files - - - - - Resource Files - - - \ No newline at end of file diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h index 741af16f..8b6ad6be 100644 --- a/McZapkie/MOVER.h +++ b/McZapkie/MOVER.h @@ -496,10 +496,10 @@ struct TScheme typedef TScheme TSchemeTable[ResArraySize + 1]; /*tablica rezystorow rozr.*/ struct TDEScheme { - double RPM; /*obroty diesla*/ - double GenPower; /*moc maksymalna*/ - double Umax; /*napiecie maksymalne*/ - double Imax; /*prad maksymalny*/ + double RPM = 0.0; /*obroty diesla*/ + double GenPower = 0.0; /*moc maksymalna*/ + double Umax = 0.0; /*napiecie maksymalne*/ + double Imax = 0.0; /*prad maksymalny*/ }; typedef TDEScheme TDESchemeTable[33]; /*tablica rezystorow rozr.*/ struct TShuntScheme @@ -569,23 +569,28 @@ struct TTransmision enum TCouplerType { NoCoupler, Articulated, Bare, Chain, Screw, Automatic }; +//class TMoverParameters; // wyforwardowanie klasy coby typ byl widoczny w ponizszej strukturze -class TMoverParameters; // wyforwardowanie klasy coby typ byl widoczny w ponizszej strukturze struct TCoupling { /*parametry*/ - double SpringKB; double SpringKC; double beta; /*stala sprezystosci zderzaka/sprzegu, %tlumiennosci */ - double DmaxB; double FmaxB; double DmaxC; double FmaxC; /*tolerancja scisku/rozciagania, sila rozerwania*/ - TCouplerType CouplerType; /*typ sprzegu*/ + double SpringKB = 1.0; /*stala sprezystosci zderzaka/sprzegu, %tlumiennosci */ + double SpringKC = 1.0; + double beta = 0.0; + double DmaxB = 0.1; /*tolerancja scisku/rozciagania, sila rozerwania*/ + double FmaxB = 1000.0; + double DmaxC = 0.1; + double FmaxC = 1000.0; + TCouplerType CouplerType = NoCoupler; /*typ sprzegu*/ /*zmienne*/ - int CouplingFlag; /*0 - wirtualnie, 1 - sprzegi, 2 - pneumatycznie, 4 - sterowanie, 8 - kabel mocy*/ - int AllowedFlag; //Ra: znaczenie jak wyżej, maska dostępnych - bool Render; /*ABu: czy rysowac jak zaczepiony sprzeg*/ - double CoupleDist; /*ABu: optymalizacja - liczenie odleglosci raz na klatkę, bez iteracji*/ - TMoverParameters* Connected; /*co jest podlaczone*/ - int ConnectedNr; //Ra: od której strony podłączony do (Connected): 0=przód, 1=tył - double CForce; /*sila z jaka dzialal*/ - double Dist; /*strzalka ugiecia zderzaków*/ - bool CheckCollision; /*czy sprawdzac sile czy pedy*/ + int CouplingFlag = 0; /*0 - wirtualnie, 1 - sprzegi, 2 - pneumatycznie, 4 - sterowanie, 8 - kabel mocy*/ + int AllowedFlag = 3; //Ra: znaczenie jak wyżej, maska dostępnych + bool Render = false; /*ABu: czy rysowac jak zaczepiony sprzeg*/ + double CoupleDist = 0.0; /*ABu: optymalizacja - liczenie odleglosci raz na klatkę, bez iteracji*/ + class TMoverParameters *Connected = nullptr; /*co jest podlaczone*/ + int ConnectedNr = 0; //Ra: od której strony podłączony do (Connected): 0=przód, 1=tył + double CForce = 0.0; /*sila z jaka dzialal*/ + double Dist = 0.0; /*strzalka ugiecia zderzaków*/ + bool CheckCollision = false; /*czy sprawdzac sile czy pedy*/ }; class TMoverParameters @@ -642,10 +647,11 @@ public: TBrakeHandle BrakeLocHandle; double MBPM; /*masa najwiekszego cisnienia*/ - TBrake *Hamulec; - TDriverHandle *Handle; - TDriverHandle *LocHandle; - TReservoir *Pipe; TReservoir *Pipe2; + std::shared_ptr Hamulec; + std::shared_ptr Handle; + std::shared_ptr LocHandle; + std::shared_ptr Pipe; + std::shared_ptr Pipe2; TLocalBrake LocalBrake; /*rodzaj hamulca indywidualnego*/ TBrakePressureTable BrakePressureTable; /*wyszczegolnienie cisnien w rurze*/ @@ -1110,11 +1116,19 @@ public: /*funkcje ladujace pliki opisujace pojazd*/ bool LoadFIZ(std::string chkpath); //Q 20160717 bool LoadChkFile(std::string chkpath); - bool readMPT(int ln, std::string line); //Q 20160717 - bool readRLIST(int ln, std::string line); //Q 20160718 - bool readBPT(int ln, std::string line); //Q 20160721 - void BrakeValveDecode(std::string s); //Q 20160719 - void BrakeSubsystemDecode(); //Q 20160719 + bool LoadFIZ_Doors( std::string const &line ); + bool readMPT0( std::string const &line ); + bool readMPT( std::string const &line ); //Q 20160717 + bool readMPTElectricSeries( std::string const &line ); + bool readMPTDieselElectric( std::string const &line ); + bool readMPTDieselEngine( std::string const &line ); + bool readRList(int const ln, std::string const &line); //Q 20160718 + bool readBPT(/*int const ln,*/ std::string const &line); //Q 20160721 + bool readDList( std::string const &line ); + bool readFFList( std::string const &line ); + bool readWWList( std::string const &line ); + void BrakeValveDecode( std::string s ); //Q 20160719 + void BrakeSubsystemDecode(); //Q 20160719 void PowerParamDecode(std::string lines, std::string prefix, TPowerParameters &PowerParamDecode); //Q 20160719 TPowerSource PowerSourceDecode(std::string s); //Q 20160719 TPowerType PowerDecode(std::string s); //Q 20160719 @@ -1124,3 +1138,34 @@ public: }; extern double Distance(TLocation Loc1, TLocation Loc2, TDimension Dim1, TDimension Dim2); + +template +bool getkeyval( _Type &Variable, std::string const &Key, std::string const &Input, std::string const &Default ) { + + std::string value; + auto lookup = Input.find( Key + "=" ); + if( lookup != std::string::npos ) { + value = Input.substr( Input.find_first_not_of( ' ', lookup + Key.size() + 1 ) ); + lookup = value.find( ' ' ); + if( lookup != std::string::npos ) { + // trim everything past the value + value.erase( lookup ); + } + } + if( false == value.empty() ) { + // set the specified variable to retrieved value + std::stringstream converter; + converter << value; + converter >> Variable; + return true; // located the variable + } + else { + // set the variable to provided default value + if( false == Default.empty() ) { + std::stringstream converter; + converter << Default; + converter >> Variable; + } + return false; // supplied the default + } +} \ No newline at end of file diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index cc9fa18e..8bcf08ee 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -1,4 +1,4 @@ -/* +/* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not @@ -12,6 +12,7 @@ http://mozilla.org/MPL/2.0/. #include "../globals.h" #include "../logs.h" #include "Oerlikon_ESt.h" +#include "../parser.h" //--------------------------------------------------------------------------- // Ra: tu należy przenosić funcje z mover.pas, które nie są z niego wywoływane. @@ -38,15 +39,15 @@ inline double sqr(double val) // SQR() zle liczylo w current() ... double ComputeCollision(double &v1, double &v2, double m1, double m2, double beta, bool vc) { // oblicza zmiane predkosci i przyrost pedu wskutek kolizji - if (v1 < v2 && vc) + if( ( v1 < v2 ) && ( vc == true ) ) return 0; else { double sum = m1 + m2; - double w1 = ((m1 - m2) * v1 + 2 * m2 * v2) / sum; - double w2 = ((m2 - m1) * v2 + 2 * m1 * v1) / sum; - v1 = w1 * sqrt(1 - beta); // niejawna zmiana predkosci wskutek zderzenia - v2 = w2 * sqrt(1 - beta); + double w1 = ( m2 * v2 * 2.0 + v1 * ( m1 - m2 ) ) / sum; + double w2 = ( m1 * v1 * 2.0 + v2 * ( m2 - m1 ) ) / sum; + v1 = w1 * std::sqrt(1.0 - beta); // niejawna zmiana predkosci wskutek zderzenia + v2 = w2 * std::sqrt(1.0 - beta); return m1 * (w2 - w1) * (1 - beta); } } @@ -351,6 +352,10 @@ TMoverParameters::TMoverParameters(double VelInitial, std::string TypeNameInit, Couplers[b].DmaxC = 0.1; Couplers[b].FmaxC = 1000.0; } + for( b = 0; b < 2; ++b ) { + HVCouplers[ b ][ 0 ] = 0.0; + HVCouplers[ b ][ 1 ] = 0.0; + } Power = 0.0; MaxLoad = 0; LoadAccepted = ""; @@ -548,7 +553,7 @@ TMoverParameters::TMoverParameters(double VelInitial, std::string TypeNameInit, ResistorsFlag = false; RventRot = 0.0; RVentType = 0; - RVentnmax = 0.0; + RVentnmax = 1.0; RVentCutOff = 0.0; enrot = 0.0; @@ -1497,9 +1502,7 @@ double TMoverParameters::ComputeMovement(double dt, double dt1, const TTrackShap Mains = false; DerailReason = 4; // Ra: powód wykolejenia: nieodpowiednia trajektoria } - V += (3.0 * AccS - AccSprev) * dt / 2.0; // przyrost predkosci - if (TestFlag(DamageFlag, dtrain_out)) if (Vel < 1) { @@ -1598,7 +1601,6 @@ double TMoverParameters::FastComputeMovement(double dt, const TTrackShape &Shape TTrackParam &Track, const TLocation &NewLoc, TRotation &NewRot) { - double Vprev, AccSprev, d; int b; // T_MoverParameters::FastComputeMovement(dt, Shape, Track, NewLoc, NewRot); @@ -1796,63 +1798,96 @@ int TMoverParameters::ShowCurrent(int AmpN) bool TMoverParameters::IncMainCtrl(int CtrlSpeed) { + // basic fail conditions: + if( ( CabNo == 0 ) + || ( MainCtrlPosNo <= 0 ) ) { + // nie ma sterowania + return false; + } + if( ( TrainType == dt_ET22 ) && ( ScndCtrlPos != 0 ) ) { + // w ET22 nie da się kręcić nastawnikiem przy włączonym boczniku + return false; + } + if( ( TrainType == dt_EZT ) && ( ActiveDir == 0 ) ) { + // w EZT nie da się załączyć pozycji bez ustawienia kierunku + return false; + } + bool OK = false; - if ((MainCtrlPosNo > 0) && (CabNo != 0)) - { if (MainCtrlPos < MainCtrlPosNo) { - if ((TrainType != dt_ET22) || - ((TrainType == dt_ET22) && - (ScndCtrlPos == - 0))) // w ET22 nie da się kręcić nastawnikiem przy włączonym boczniku - switch (EngineType) - { + switch( EngineType ) { case None: case Dumb: case DieselElectric: case ElectricInductionMotor: { - if (((CtrlSpeed == 1) && (TrainType != dt_EZT)) || - ((CtrlSpeed == 1) && (TrainType == dt_EZT) && (ActiveDir != 0))) - { // w EZT nie da się załączyć pozycji bez ustawienia kierunku - MainCtrlPos++; + if( CtrlSpeed > 1 ) { + OK = ( IncMainCtrl( 1 ) + && IncMainCtrl( CtrlSpeed - 1 ) ); // a fail will propagate up the recursion chain. should this be || instead? + } + else { + ++MainCtrlPos; OK = true; } - else if (((CtrlSpeed > 1) && (TrainType != dt_EZT)) || - ((CtrlSpeed > 1) && (TrainType == dt_EZT) && (ActiveDir != 0))) - OK = (IncMainCtrl(1) && IncMainCtrl(CtrlSpeed - 1)); break; } case ElectricSeriesMotor: { - if ((CtrlSpeed == 1) && (ActiveDir != 0)) - { - MainCtrlPos++; - OK = true; - if (Imax == ImaxHi) - if (RList[MainCtrlPos].Bn > 1) - { - if (TrainType == dt_ET42) - { - MainCtrlPos--; - OK = false; + if( ActiveDir == 0 ) { return false; } + + if( CtrlSpeed > 1 ) { + // szybkie przejœcie na bezoporow¹ + if( TrainType == dt_ET40 ) { + break; // this means ET40 won't react at all to fast acceleration command. should it issue just IncMainCtrl(1) instead? } - if (MaxCurrentSwitch(false)) - SetFlag( - SoundFlag, - sound_relay); // wylaczanie wysokiego rozruchu // Q TODO: + while( ( RList[ MainCtrlPos ].R > 0.0 ) + && IncMainCtrl( 1 ) ) { + // all work is done in the loop header + ; + } + // OK:=true ; {takie chamskie, potem poprawie} <-Ra: kto mia³ to + // poprawiæ i po co? + if( ActiveDir == -1 ) { + while( ( RList[ MainCtrlPos ].Bn > 1 ) + && IncMainCtrl( 1 ) ) { + --MainCtrlPos; + } + } + OK = false; // shouldn't this be part of the loop above? + // if (TrainType=dt_ET40) then + // while Abs (Im)>IminHi do + // dec(MainCtrlPos); + // OK:=false ; + } + else { // CtrlSpeed == 1 + ++MainCtrlPos; + OK = true; + if( Imax == ImaxHi ) { + if( RList[ MainCtrlPos ].Bn > 1 ) { + if( true == MaxCurrentSwitch( false )) { + // wylaczanie wysokiego rozruchu + SetFlag( SoundFlag, sound_relay ); + } // Q TODO: // if (EngineType=ElectricSeriesMotor) and (MainCtrlPos=1) // then // MainCtrlActualPos:=1; // + if( TrainType == dt_ET42 ) { + --MainCtrlPos; + OK = false; } - if ((CtrlSpeed == 1) && (ActiveDir == -1) && (RList[MainCtrlPos].Bn > 1) && - (TrainType != dt_PseudoDiesel)) - { // blokada wejścia na równoległą podczas jazdy do tyłu - MainCtrlPos--; + } + } + if( ActiveDir == -1 ) { + if( ( TrainType != dt_PseudoDiesel ) + && ( RList[ MainCtrlPos ].Bn > 1 ) ) { + // blokada wejścia na równoległą podczas jazdy do tyłu + --MainCtrlPos; OK = false; } + } // // if (TrainType == "et40") // if (Abs(Im) > IminHi) @@ -1861,89 +1896,59 @@ bool TMoverParameters::IncMainCtrl(int CtrlSpeed) // OK = false; // } //} - if (DynamicBrakeFlag) - if (TrainType == dt_ET42) - if (MainCtrlPos > 20) - { - MainCtrlPos--; - OK = false; } - } - else if ((CtrlSpeed > 1) && (ActiveDir != 0) && (TrainType != dt_ET40)) - { // szybkie przejście na bezoporową - while ((RList[MainCtrlPos].R > 0) && IncMainCtrl(1)) - ; // tutaj ma być pętla na "pusto" - // OK:=true ; {takie chamskie, potem poprawie} <-Ra: kto miał to - // poprawić i po co? - if (ActiveDir == -1) - while ((RList[MainCtrlPos].Bn > 1) && IncMainCtrl(1)) - MainCtrlPos--; - OK = false; - // if (TrainType=dt_ET40) then - // while Abs (Im)>IminHi do - // dec(MainCtrlPos); - // OK:=false ; - // - if (DynamicBrakeFlag) - if (TrainType == dt_ET42) - while (MainCtrlPos > 20) - MainCtrlPos--; + if( ( TrainType == dt_ET42 ) && ( true == DynamicBrakeFlag ) ) { + if( MainCtrlPos > 20 ) { + MainCtrlPos = 20; OK = false; } + } // return OK; - break; } case DieselEngine: { - if (CtrlSpeed == 1) - { - MainCtrlPos++; - OK = true; - if (MainCtrlPos > 0) - CompressorAllow = true; - else - CompressorAllow = false; + if( CtrlSpeed > 1 ) { + while( MainCtrlPos < MainCtrlPosNo ) { + IncMainCtrl( 1 ); } - else if (CtrlSpeed > 1) - { - while (MainCtrlPos < MainCtrlPosNo) - IncMainCtrl(1); - OK = true; } + else { + ++MainCtrlPos; + if( MainCtrlPos > 0 ) { CompressorAllow = true; } + else { CompressorAllow = false; } + } + OK = true; break; } case WheelsDriven: { - OK = AddPulseForce(CtrlSpeed); + OK = AddPulseForce( CtrlSpeed ); break; } - } // switch EngineType of } - else // MainCtrlPos>=MainCtrlPosNo - if (CoupledCtrl) // wspólny wał nastawnika jazdy i bocznikowania - { - if (ScndCtrlPos < ScndCtrlPosNo) // 3<3 -> false - { - ScndCtrlPos++; + else {// MainCtrlPos>=MainCtrlPosNo + if( true == CoupledCtrl ) { + // wspólny wał nastawnika jazdy i bocznikowania + if( ScndCtrlPos < ScndCtrlPosNo ) { // 3<3 -> false + ++ScndCtrlPos; OK = true; } - else + else { OK = false; } - if (OK) + } + } + + if( true == OK ) { SendCtrlToNext("MainCtrl", MainCtrlPos, CabNo); //??? SendCtrlToNext("ScndCtrl", ScndCtrlPos, CabNo); } - } - else // nie ma sterowania - OK = false; - // if OK then LastRelayTime:=0; // hunter-101012: poprawka // poprzedni warunek byl niezbyt dobry, bo przez to przy trzymaniu + @@ -4240,7 +4245,7 @@ double TMoverParameters::TractionForce(double dt) EnginePower = dmoment * enrot; if (MainCtrlPos > 1) dmoment -= - dizel_Mstand * (0.2 * enrot / nmax); // dodatkowe opory z powodu sprezarki} + dizel_Mstand * (0.2 * enrot / dizel_nmax); // dodatkowe opory z powodu sprezarki} Mm = dizel_engage * dmoment; Mw = Mm * dtrans; // dmoment i dtrans policzone przy okazji enginerotation Fw = Mw * 2.0 / WheelDiameter; @@ -4264,13 +4269,16 @@ double TMoverParameters::TractionForce(double dt) else // jazda ciapongowa { - tmp = Min0R(DElist[MainCtrlPos].GenPower, Power - HeatingPower * double(Heating)); + auto power = Power; + if( true == Heating ) { power -= HeatingPower; } + if( power < 0.0 ) { power = 0.0; } + tmp = std::min( DElist[ MainCtrlPos ].GenPower, power );// Power - HeatingPower * double( Heating )); PosRatio = DElist[MainCtrlPos].GenPower / DElist[MainCtrlPosNo].GenPower; // stosunek mocy teraz do mocy max if ((MainCtrlPos > 0) && (ConverterFlag)) if (tmpV < - (Vhyp * (Power - HeatingPower * double(Heating)) / + (Vhyp * power / DElist[MainCtrlPosNo].GenPower)) // czy na czesci prostej, czy na hiperboli Ft = (Ftmax - ((Ftmax - 1000.0 * DElist[MainCtrlPosNo].GenPower / (Vhyp + Vadd)) * @@ -5711,9 +5719,11 @@ std::string TMoverParameters::EngineDescription(int what) if (outstr == "") outstr = "OK!"; } - }; + break; + } default: outstr = "Invalid qualifier"; + break; } return outstr; } @@ -5752,9 +5762,10 @@ std::string vS; int vI; double vD; bool startBPT; -bool startMPT; +bool startMPT, startMPT0; bool startRLIST; -int MPTLINE, RLISTLINE, BPTLINE; +bool startDLIST, startFFLIST, startWWLIST; +int MPTLINE, RLISTLINE, BPTLINE, DLISTLINE, FFLISTLINE, WWLISTLINE; std::vector x; std::string aCategory, aType; @@ -5793,8 +5804,10 @@ double jMaxVoltage, jMaxCurrent, jIntR, jMinH, jMaxH, jCSW, jMinV, jMaxV, jMinPr int jCollectorsNo; std::string kEngineType, kTrans; -double kWindingRes, knmax, kVolt; +double kVolt, kWindingRes, kNMin, kNMax, kNMaxCutoff, kAIM, kshuntmode; // int kVolt; +// motorparamtable +double kMinVelFullEngage, kEngageDia, kEngageMaxForce, kEngageFriction; double lCircuitRes; int lImaxLo, lImaxHi, lIminLo, lIminHi; @@ -5871,16 +5884,16 @@ std::string getkeyval(int rettype, std::string key) int klen = key.length(); int kpos = Pos(key, xline) - 1; temp.erase(0, kpos + klen); - if (temp.find(" ") != std::string::npos) - to = temp.find(" "); + if (temp.find(' ') != std::string::npos) + to = temp.find(' '); else to = 255; kval = temp.substr(0, to); if (kval != "") kval = TrimSpace(kval); // wyciagnieta wartosc - sectionname = ExchangeCharInString(sectionname, (char)":", (char)""); - sectionname = ExchangeCharInString(sectionname, (char)".", (char)""); + sectionname = ExchangeCharInString(sectionname, ':', NULL); + sectionname = ExchangeCharInString(sectionname, '.', NULL); //--WriteLog(sectionname + "." + keyname + " val= [" + kval + "]"); // if (rettype == 1) vS = kval; @@ -5930,80 +5943,146 @@ int s2NNW(std::string s) // Q: 20160717 // ************************************************************************************************* // parsowanie Motor Param Table -bool TMoverParameters::readMPT(int ln, std::string line) -{ - // bl, mfi, mIsat, mfi0, fi, Isat, fi0 - bool as; - int bl; - startMPT = true; +bool TMoverParameters::readMPT0( std::string const &line ) { - if (ln > 0) // 0 to nazwa sekcji - MotorParamTable0: - { - //--WriteLog("MPT: " + xline); - x = Split(line); - - int s = x.size(); - if ( (s < 7) - || (s > 8) ) - { - WriteLog( "Read MPT: wrong number of arguments (" + std::to_string( s ) + ") in line " + std::to_string( ln - 1 ) ); - MPTLINE++; - return false; - } - - for(int i = 0; i < s; i++) - x[i] = TrimSpace(x[i]); - - bl = atoi(x[0].c_str()); // numer pozycji - - MotorParam[bl].mfi = atof(x[1].c_str()); - MotorParam[bl].mIsat = atof(x[2].c_str()); - MotorParam[bl].mfi0 = atof(x[3].c_str()); - MotorParam[bl].fi = atof(x[4].c_str()); - MotorParam[bl].Isat = atof(x[5].c_str()); - MotorParam[bl].fi0 = atof(x[6].c_str()); - MotorParam[bl].AutoSwitch = s == 8 ? atoi(x[7].c_str()): false; - - //--WriteLog(":::: " + p0 + "," + p1 + "," + p2 + "," + p3 + "," + p4 + "," + p5 + "," + - //p6); + cParser parser( line ); + if( false == parser.getTokens( 7, false ) ) { + WriteLog( "Read MPT0: arguments missing in line " + std::to_string( MPTLINE ) ); + return false; + } + int idx = 0; // numer pozycji + parser >> idx; + parser + >> MotorParam[ idx ].mfi + >> MotorParam[ idx ].mIsat + >> MotorParam[ idx ].mfi0 + >> MotorParam[ idx ].fi + >> MotorParam[ idx ].Isat + >> MotorParam[ idx ].fi0; + if( true == parser.getTokens( 1, false ) ) { + int autoswitch; + parser >> autoswitch; + MotorParam[ idx ].AutoSwitch = ( autoswitch == 1 ); + } + else { + MotorParam[ idx ].AutoSwitch = false; } - MPTLINE++; return true; } +bool TMoverParameters::readMPT( std::string const &line ) { + ++MPTLINE; + + switch( EngineDecode( kEngineType ) ) { + + case ElectricSeriesMotor: { return readMPTElectricSeries( line ); } + case DieselElectric: { return readMPTDieselElectric( line ); } + case DieselEngine: { return readMPTDieselEngine( line ); } + default: { return false; } + } +} + +bool TMoverParameters::readMPTElectricSeries(std::string const &line) { + + cParser parser( line ); + if( false == parser.getTokens( 5, false ) ) { + WriteLog( "Read MPT: arguments missing in line " + std::to_string( MPTLINE ) ); + return false; + } + int idx = 0; // numer pozycji + parser >> idx; + parser + >> MotorParam[ idx ].mfi + >> MotorParam[ idx ].mIsat + >> MotorParam[ idx ].fi + >> MotorParam[ idx ].Isat; + if( true == parser.getTokens( 1, false ) ) { + int autoswitch; + parser >> autoswitch; + MotorParam[ idx ].AutoSwitch = (autoswitch == 1); } + else{ + MotorParam[ idx ].AutoSwitch = false; + } + return true; +} + +bool TMoverParameters::readMPTDieselElectric( std::string const &line ) { + + cParser parser( line ); + if( false == parser.getTokens( 7, false ) ) { + WriteLog( "Read MPT: arguments missing in line " + std::to_string( MPTLINE ) ); + return false; + } + int idx = 0; // numer pozycji + parser >> idx; + parser + >> MotorParam[ idx ].mfi + >> MotorParam[ idx ].mIsat + >> MotorParam[ idx ].fi + >> MotorParam[ idx ].Isat + >> MPTRelay[ idx ].Iup + >> MPTRelay[ idx ].Idown; + + return true; +} + +bool TMoverParameters::readMPTDieselEngine( std::string const &line ) { + + cParser parser( line ); + if( false == parser.getTokens( 4, false ) ) { + WriteLog( "Read MPT: arguments missing in line " + std::to_string( MPTLINE ) ); + return false; + } + int idx = 0; // numer pozycji + parser >> idx; + parser + >> MotorParam[ idx ].mIsat + >> MotorParam[ idx ].fi + >> MotorParam[ idx ].mfi; + if( true == parser.getTokens( 1, false ) ) { + int autoswitch; + parser >> autoswitch; + MotorParam[ idx ].AutoSwitch = ( autoswitch == 1 ); + } + else { + MotorParam[ idx ].AutoSwitch = false; + } + return true; +} + + // ************************************************************************************************* // Q: 20160718 // ************************************************************************************************* // parsowanie RList -bool TMoverParameters::readRLIST(int ln, std::string line) +bool TMoverParameters::readRList(int const ln, std::string const &line) { - char *xxx = nullptr; startRLIST = true; if (ln > 0) // 0 to nazwa sekcji - RList: { // WriteLog("RLIST: " + xline); +/* line = Tab2Sp(line); // zamieniamy taby na spacje (ile tabow tyle spacji bedzie) xxx = TrimAndReduceSpaces(line.c_str()); // konwertujemy na *char i // ograniczamy spacje pomiedzy // parametrami do jednej - - x = Split(xxx); // split je wskaznik na char jak i std::string +*/ + x = Split(line); // split je wskaznik na char jak i std::string int s = x.size(); if ( ( s < 5 ) || ( s > 6 )) { WriteLog("Read RLIST: wrong number of arguments (" + std::to_string(s) + ") in line " + std::to_string(ln - 1)); - delete[] xxx; RLISTLINE++; return false; } - +/* for (int i = 0; i < s; i++) x[i] = TrimSpace(x[i]); - +*/ int k = ln - 1; RlistSize = (mSize); @@ -6018,7 +6097,6 @@ bool TMoverParameters::readRLIST(int ln, std::string line) RList[k].ScndAct = s == 6 ? atoi(x[5].c_str()) : 0; //jeśli ma boczniki w nastawniku //--WriteLog("RLIST: " + p0 + "," + p1 + "," + p2 + "," + p3 + "," + p4); } - delete[] xxx; RLISTLINE++; return true; } @@ -6027,31 +6105,27 @@ bool TMoverParameters::readRLIST(int ln, std::string line) // Q: 20160721 // ************************************************************************************************* // parsowanie Brake Param Table -bool TMoverParameters::readBPT(int ln, std::string line) -{ - char *xxx = nullptr; - startBPT = true; - int k; - - if (ln > 0) // 0 to nazwa sekcji - Cntrl. - po niej jest tablica hamulcow +bool TMoverParameters::readBPT(/*int const ln,*/ std::string const &line) { - // WriteLog("BPT: " + xline); - line = Tab2Sp(line); - xxx = TrimAndReduceSpaces(line.c_str()); - x = Split(xxx); - - int s = x.size(); - if (s != 5) + cParser parser( line ); + if( false == parser.getTokens( 5, false ) ) { - WriteLog( "Read BPT: wrong number of arguments (" + std::to_string( s ) + ") in line " + std::to_string( ln - 1 ) ); - delete[] xxx; + WriteLog( "Read BPT: arguments missing in line " + std::to_string( BPTLINE + 1 ) ); return false; } - - for (int i = 0; i < s; i++) - x[i] = TrimSpace(x[i]); - - k = atoi(x[0].c_str()); + ++BPTLINE; + std::string braketype; int idx = 0; + parser >> idx; + parser + >> BrakePressureTable[ idx ].PipePressureVal + >> BrakePressureTable[ idx ].BrakePressureVal + >> BrakePressureTable[ idx ].FlowSpeedVal + >> braketype; + if( braketype == "Pneumatic" ) { BrakePressureTable[ idx ].BrakeType = Pneumatic; } + else if( braketype == "ElectroPneumatic" ) { BrakePressureTable[ idx ].BrakeType = ElectroPneumatic; } + else { BrakePressureTable[ idx ].BrakeType = Individual; } +/* + int k = atoi( x[ 0 ].c_str() ); BrakePressureTable[k].PipePressureVal = atof(x[1].c_str()); BrakePressureTable[k].BrakePressureVal = atof(x[2].c_str()); BrakePressureTable[k].FlowSpeedVal = atof(x[3].c_str()); @@ -6061,17 +6135,89 @@ bool TMoverParameters::readBPT(int ln, std::string line) BrakePressureTable[k].BrakeType = ElectroPneumatic; else BrakePressureTable[k].BrakeType = Individual; - +*/ // WriteLog("BPTx: " + p0 + "," + p1 + "," + p2 + "," + p3 + "," + p4); //WriteLog("BPTk: " + to_string(k) + "," + to_string(BrakePressureTable[k].PipePressureVal) + // "," + to_string(BrakePressureTable[k].BrakePressureVal) + "," + // to_string(BrakePressureTable[k].FlowSpeedVal) + "," + p4); - if (k == gBCPN) - startBPT = false; + return true; +} + +bool TMoverParameters::readDList( std::string const &line ) { + + cParser parser( line ); + parser.getTokens( 4, false ); +/* warning disabled until i know what to expect ._. + if( false == parser.getTokens( 4, false ) ) { + WriteLog( "Read DList: arguments missing in line " + std::to_string( DLISTLINE + 1 ) ); + return false; } - delete[] xxx; - BPTLINE++; +*/ + ++DLISTLINE; + int idx = 0; + parser >> idx; + if( idx >= sizeof( DElist ) ) { + WriteLog( "Read DList: number of entries exceeded capacity of the data table" ); + return false; + } + parser + >> RList[ idx ].Relay + >> RList[ idx ].R + >> RList[ idx ].Mn; + + return true; +} + +bool TMoverParameters::readFFList( std::string const &line ) { + + cParser parser( line ); + if( false == parser.getTokens( 2, false ) ) { + WriteLog( "Read FList: arguments missing in line " + std::to_string( FFLISTLINE + 1 ) ); + return false; + } + int idx = FFLISTLINE++; + if( idx >= sizeof( DElist ) ) { + WriteLog( "Read FList: number of entries exceeded capacity of the data table" ); + return false; + } + parser + >> DElist[ idx ].RPM + >> DElist[ idx ].GenPower; + + return true; +} + +// parsowanie WWList +bool TMoverParameters::readWWList( std::string const &line ) { + + cParser parser( line ); + if( false == parser.getTokens( 4, false ) ) { + WriteLog( "Read WWList: arguments missing in line " + std::to_string( WWLISTLINE + 1 ) ); + return false; + } + int idx = WWLISTLINE++; + if( idx >= sizeof( DElist ) ) { + WriteLog( "Read WWList: number of entries exceeded capacity of the data table" ); + return false; + } + parser + >> DElist[ idx ].RPM + >> DElist[ idx ].GenPower + >> DElist[ idx ].Umax + >> DElist[ idx ].Imax; + + if( true == parser.getTokens( 3, false ) ) { + // optional parameters for shunt mode + parser + >> SST[ idx ].Umin + >> SST[ idx ].Umax + >> SST[ idx ].Pmax; + + SST[ idx ].Pmin = std::sqrt( std::pow( SST[ idx ].Umin, 2 ) / 47.6 ); + SST[ idx ].Pmax = std::min( SST[ idx ].Pmax, std::pow( SST[ idx ].Umax, 2 ) / 47.6 ); + } + return true; } @@ -6330,9 +6476,19 @@ bool TMoverParameters::LoadFIZ(std::string chkpath) OKFlag = 0; LineCount = 0; ConversionError = 666; + startBPT = false; BPTLINE = 0; + startMPT = false; + startMPT0 = false; MPTLINE = 0; + startRLIST = false; RLISTLINE = 0; + startDLIST = false; + startFFLIST = false; + startWWLIST = false; + WWLISTLINE = 0; + DLISTLINE = 0; + FFLISTLINE = 0; Mass = 0; file = chkpath + TypeName + ".fiz"; @@ -6343,14 +6499,14 @@ bool TMoverParameters::LoadFIZ(std::string chkpath) // appdir = ExtractFilePath(ParamStr(0)); - std::ifstream in(file.c_str()); + std::ifstream in(file); if (!in.is_open()) { WriteLog("E8 - FIZ FILE NOT EXIST."); return false; } - bool secBPT = false, secMotorParamTable0 = false, secPower = false, secEngine = false, + bool secBPT = false, secMotorParamTable = false, secPower = false, secEngine = false, secParam = false, secLoad = false, secDimensions = false, secWheels = false, secBrake = false, secBuffCoupl = false, secCntrl = false, secSecurity = false, secLight = false, secCircuit = false, secRList = false, @@ -6373,9 +6529,11 @@ bool TMoverParameters::LoadFIZ(std::string chkpath) startBPT = false; continue; } + // checking if table parsing should be switched off goes first... if( issection( "END-MPT" ) ) { startBPT = false; startMPT = false; + startMPT0 = false; continue; } if( issection( "END-RL" ) ) { @@ -6383,12 +6541,38 @@ bool TMoverParameters::LoadFIZ(std::string chkpath) startRLIST = false; continue; } - + if( issection( "END-DL" ) ) { + startBPT = false; + startDLIST = false; + continue; + } + if( issection( "endff" ) ) { + startBPT = false; + startFFLIST = false; + continue; + } + if( issection( "END-WWL" ) ) { + startBPT = false; + startWWLIST = false; + continue; + } + // ...then all recognized sections... if (issection("Param.")) { startBPT = false; secParam = true; SetFlag(OKFlag, param_ok); + getkeyval( aCategory, "Category", xline, "none" ); + getkeyval( aType, "Type", xline, "none" ); aType = ToUpper( aType ); + getkeyval( aMass, "M", xline, "0" ); + getkeyval( aMred, "Mred", xline, "0" ); + getkeyval( aVmax, "Vmax", xline, "0" ); + getkeyval( aPWR, "PWR", xline, "0" ); + getkeyval( aSandCap, "SandCap", xline, "0" ); + getkeyval( aHeatingP, "HeatingP", xline, "0" ); + getkeyval( aLightP, "LightP", xline, "0" ); + // TODO: switch other sections to the new getkeyval() code +/* aCategory = getkeyval(1, "Category"); aType = ToUpper(getkeyval(1, "Type")); aMass = atof(getkeyval(3, "M").c_str()); @@ -6398,6 +6582,7 @@ bool TMoverParameters::LoadFIZ(std::string chkpath) aSandCap = atoi(getkeyval(2, "SandCap").c_str()); aHeatingP = atof(getkeyval(3, "HeatingP").c_str()); aLightP = atof(getkeyval(3, "LightP").c_str()); +*/ continue; } @@ -6414,6 +6599,12 @@ bool TMoverParameters::LoadFIZ(std::string chkpath) continue; } + if( issection( "Doors:" ) ) { + + LoadFIZ_Doors( xline ); + continue; + } + if (issection("Dimensions:")) { startBPT = false; @@ -6547,7 +6738,47 @@ bool TMoverParameters::LoadFIZ(std::string chkpath) kTrans = (getkeyval(1, "Trans")); kVolt = atof(getkeyval(3, "Volt").c_str()); kWindingRes = atof(getkeyval(3, "WindingRes").c_str()); - knmax = atof(getkeyval(3, "nmax").c_str()); + kNMax = atof(getkeyval(3, "nmax").c_str()); + // new (diesel) engine parameters follow + // TODO: check if the entries are correct. + // TODO, TBD: possibly read the values into module variables first, instead of injecting them directly into the engine? + getkeyval( kshuntmode, "ShuntMode", xline, "0.0" ); + int flat; + getkeyval( flat, "Flat", xline, "0" ); Flat = ( flat == 1 ); + // diesel-electric + getkeyval( Ftmax, "Ftmax", xline, "" ); + getkeyval( Vhyp, "Vhyp", xline, "" ); + getkeyval( Vadd, "Vadd", xline, "" ); + getkeyval( PowerCorRatio, "Cr", xline, "" ); + getkeyval( AutoRelayType, "RelayType", xline, "" ); + // diesel + getkeyval( dizel_nmin, "nmin", xline, "" ); + getkeyval( dizel_nmax, "nmax", xline, "" ); + getkeyval( dizel_nmax_cutoff, "nmax_cutoff", xline, "0.0" ); + getkeyval( dizel_AIM, "AIM", xline, "1.0" ); + // electric induction + getkeyval( eimc[ eimc_s_dfic ], "dfic", xline, "" ); + getkeyval( eimc[ eimc_s_dfmax ], "dfmax", xline, "" ); + getkeyval( eimc[ eimc_s_p ], "p", xline, "" ); + getkeyval( eimc[ eimc_s_cfu ], "cfu", xline, "" ); + getkeyval( eimc[ eimc_s_cim ], "cim", xline, "" ); + getkeyval( eimc[ eimc_s_icif ], "icif", xline, "" ); + getkeyval( eimc[ eimc_f_Uzmax ], "Uzmax", xline, "" ); + getkeyval( eimc[ eimc_f_Uzh ], "Uzh", xline, "" ); + getkeyval( eimc[ eimc_f_DU ], "DU", xline, "" ); + getkeyval( eimc[ eimc_f_I0 ], "I0", xline, "" ); + getkeyval( eimc[ eimc_f_cfu ], "fcfu", xline, "" ); + getkeyval( eimc[ eimc_p_F0 ], "F0", xline, "" ); + getkeyval( eimc[ eimc_p_a1 ], "a1", xline, "" ); + getkeyval( eimc[ eimc_p_Pmax ], "Pmax", xline, "" ); + getkeyval( eimc[ eimc_p_Fh ], "Fh", xline, "" ); + getkeyval( eimc[ eimc_p_Ph ], "Ph", xline, "" ); + getkeyval( eimc[ eimc_p_Vh0 ], "Vh0", xline, "" ); + getkeyval( eimc[ eimc_p_Vh1 ], "Vh1", xline, "" ); + getkeyval( eimc[ eimc_p_Imax ], "Imax", xline, "" ); + getkeyval( eimc[ eimc_p_abed ], "abed", xline, "" ); + getkeyval( eimc[ eimc_p_eped ], "edep", xline, "" ); + continue; } @@ -6577,7 +6808,7 @@ bool TMoverParameters::LoadFIZ(std::string chkpath) if( issection( "RList:" ) || startRLIST ) { startBPT = false; secRList = true; - readRLIST( RLISTLINE, xline ); + readRList( RLISTLINE, xline ); continue; } @@ -6585,6 +6816,7 @@ bool TMoverParameters::LoadFIZ(std::string chkpath) { startBPT = false; secDList = true; + startDLIST = true; DLISTLINE = 0; nMmax = atof(getkeyval(3, "Mmax").c_str()); nnMmax = atof(getkeyval(3, "nMmax").c_str()); nMnmax = atof(getkeyval(3, "Mnmax").c_str()); @@ -6592,22 +6824,32 @@ bool TMoverParameters::LoadFIZ(std::string chkpath) nnominalfill = atof(getkeyval(3, "nominalfill").c_str()); nMstand = atof(getkeyval(3, "Mstand").c_str()); nSize = atoi(getkeyval(2, "Size").c_str()); + + if( kEngineType == "DieselEngine" ) { + // TODO: does the diesel really need duplicate of common variables :x + // TODO, TBD: pass the values through module variables instead of injecting them directly? + getkeyval( dizel_Mmax, "Mmax", xline, "" ); + getkeyval( dizel_nMmax, "nMmax", xline, "" ); + getkeyval( dizel_Mnmax, "Mnmax", xline, "" ); + getkeyval( dizel_nmax, "nmax", xline, "" ); + getkeyval( dizel_nominalfill, "nominalfill", xline, "" ); + getkeyval( dizel_Mstand, "Mstand", xline, "" ); + } continue; } - if (issection("WWList:")) - { + if( issection( "ffList:" ) ) { startBPT = false; - secWWList = true; - getkeyval(2, "Size"); + secffList = true; + startFFLIST = true; FFLISTLINE = 0; continue; } - if (issection("ffList:")) + if( issection( "WWList:" ) ) { startBPT = false; - secffList = true; - getkeyval(2, "Size"); + secWWList = true; + startWWLIST = true; WWLISTLINE = 0; continue; } @@ -6615,20 +6857,35 @@ bool TMoverParameters::LoadFIZ(std::string chkpath) { startBPT = false; secTurboPos = true; - getkeyval(2, "TurboPos"); + getkeyval( TurboTest, "TurboPos", xline, "" ); continue; } - if (issection("MotorParamTable0:") || startMPT) + if (issection("MotorParamTable0:") ) { startBPT = false; - secMotorParamTable0 = true; - readMPT(MPTLINE, xline); + startMPT0 = true; MPTLINE = 0; + secMotorParamTable = true; continue; } + if( issection( "MotorParamTable:" ) ) { + // diesel engine variant + startBPT = false; + startMPT = true; MPTLINE = 0; + secMotorParamTable = true; + // variables + if( kEngineType == "DieselEngine" ) { + getkeyval( dizel_minVelfullengage, "minVelfullengage", xline, "" ); + getkeyval( dizel_engageDia, "engageDia", xline, "" ); + getkeyval( dizel_engageMaxForce, "engageMaxForce", xline, "" ); + getkeyval( dizel_engagefriction, "engagefriction", xline, "" ); + } + continue; + } + if( issection( "Cntrl." ) ) { - startBPT = false; + startBPT = true; BPTLINE = 0; secCntrl = true; gBrakeSystem = ( getkeyval( 1, "BrakeSystem" ) ); gBCPN = atoi( getkeyval( 2, "BCPN" ).c_str() ); @@ -6654,13 +6911,32 @@ bool TMoverParameters::LoadFIZ(std::string chkpath) gBrakeHandle = ( getkeyval( 1, "BrakeHandle" ) ); gLocBrakeHandle = ( getkeyval( 1, "LocBrakeHandle" ) ); gMaxBPMass = atof( getkeyval( 3, "MaxBPMass" ).c_str() ); - // don't break yet, init (optional) data table + continue; } - - if( issection( "Cntrl." ) || startBPT ) { - secBPT = true; - if( gBCPN > 0 ) - readBPT( BPTLINE, xline ); // np wagony nie maja BPT + // ...and finally, table parsers. + // NOTE: once table parsing is enabled it lasts until switched off, when another section is recognized + if( true == startBPT ) { + readBPT( xline ); + continue; + } + if( true == startMPT ) { + readMPT( xline ); + continue; + } + if( true == startMPT0 ) { + readMPT0( xline ); + continue; + } + if( true == startDLIST ) { + readDList( xline ); + continue; + } + if( true == startFFLIST ) { + readFFList( xline ); + continue; + } + if( true == startWWLIST ) { + readWWList( xline ); continue; } } // is hash @@ -6771,11 +7047,11 @@ bool TMoverParameters::LoadFIZ(std::string chkpath) ADist = dAd; BDist = dBd; - if (WheelDiameterL == -1) // gdyby nie było parametru... + if (WheelDiameterL == 0.0) // gdyby nie było parametru... WheelDiameterL = WheelDiameter; //... lepsze to niż zero else WheelDiameterL = dDl; - if (WheelDiameterT == -1) // gdyby nie było parametru... + if (WheelDiameterT == 0.0) // gdyby nie było parametru... WheelDiameterT = WheelDiameter; //... lepsze to niż zero else WheelDiameterT = dDt; @@ -7207,26 +7483,19 @@ bool TMoverParameters::LoadFIZ(std::string chkpath) { EngineType = EngineDecode(kEngineType); - switch (EngineType) - { + if( false == kTrans.empty() ) { + // transmission type. moved here because more than one engine type has this entry + x = Split( kTrans, ':' ); // 18:79 - case ElectricSeriesMotor: - { - NominalVoltage = kVolt; - - x = Split(kTrans, ':'); // 18:79 - - if (x.size() != 2) - { - WriteLog("Wrong transmition definition: " + kTrans); - break; + if( x.size() != 2 ) { + ErrorLog( "Wrong transmition definition: " + kTrans ); } - p0 = TrimSpace(x[0]); - p1 = TrimSpace(x[1]); + p0 = TrimSpace( x[ 0 ] ); + p1 = TrimSpace( x[ 1 ] ); - Transmision.NToothW = atoi(p1.c_str()); - Transmision.NToothM = atoi(p0.c_str()); + Transmision.NToothW = atoi( p1.c_str() ); + Transmision.NToothM = atoi( p0.c_str() ); // ToothW to drugi parametr czyli 79 // ToothM to pierwszy czyli 18 @@ -7234,24 +7503,64 @@ bool TMoverParameters::LoadFIZ(std::string chkpath) // WriteLog("trans " + IntToStr(Transmision.NToothW ) + "/" + // IntToStr(Transmision.NToothM )); // if (kTrans != "") - if (Transmision.NToothM > 0) - Transmision.Ratio = double(Transmision.NToothW) / Transmision.NToothM; + if( Transmision.NToothM > 0 ) + Transmision.Ratio = double( Transmision.NToothW ) / Transmision.NToothM; else Transmision.Ratio = 1; + } - WindingRes = kWindingRes; - if (WindingRes == 0) - WindingRes = 0.01; + // engine type specific parameters + switch (EngineType) + { + + case ElectricSeriesMotor: + { + NominalVoltage = kVolt; + + if( kWindingRes != 0.0 ) { WindingRes = kWindingRes; } + else { WindingRes = 0.01; } // WriteLog("WindingRes " + FloatToStr(WindingRes)); - nmax = knmax / 60.0; + nmax = kNMax / 60.0; // WriteLog("nmax " + FloatToStr(nmax )); + + if( kshuntmode == 1.0 ) { + // shuntmode + ShuntModeAllow = true; + ShuntMode = false; + AnPos = 0.0; + ImaxHi = 2; + ImaxLo = 1; + } + break; + } + + case DieselEngine: { + + dizel_nmin /= 60.0; + dizel_nmax /= 60.0; + dizel_nmax_cutoff /= 60; + // NOTE: dizel_nmax seems to be duplicate of nmax. + // keep an eye on nmax being used in equations associated with DieselEngine + // as temporary work-around for potential errors the 'regular' nmax is also given the matching value here + nmax = dizel_nmax; + + if( kshuntmode > 0.0 ) { + // shuntmode + ShuntModeAllow = true; + ShuntMode = false; + AnPos = kshuntmode; //dodatkowe przełożenie + if( AnPos < 1.0 ) { + //"rozruch wysoki" ma dawać większą siłę; im większa liczba, tym wolniej jedzie + AnPos = 1.0 / AnPos; + } } break; + } + } // switch } - kTrans = ""; } // Circuit @@ -7312,6 +7621,47 @@ bool TMoverParameters::LoadFIZ(std::string chkpath) return OK; } // LoadFIZ() +bool TMoverParameters::LoadFIZ_Doors( std::string const &line ) { + + DoorOpenCtrl = 0; + std::string openctrl; getkeyval( openctrl, "OpenCtrl", line, "" ); + if( openctrl == "DriverCtrl" ) { DoorOpenCtrl = 1; } + + DoorCloseCtrl = 0; + std::string closectrl; getkeyval( closectrl, "CloseCtrl", line, "" ); + if( closectrl == "DriverCtrl" ) { DoorCloseCtrl = 1; } + else if( closectrl == "AutomaticCtrl" ) { DoorCloseCtrl = 2; } + + if( DoorCloseCtrl == 2 ) { getkeyval( DoorStayOpen, "DoorStayOpen", line, "" ); } + + getkeyval( DoorOpenSpeed, "OpenSpeed", line, "" ); + getkeyval( DoorCloseSpeed, "CloseSpeed", line, "" ); + getkeyval( DoorMaxShiftL, "DoorMaxShiftL", line, "" ); + getkeyval( DoorMaxShiftR, "DoorMaxShiftR", line, "" ); + + DoorOpenMethod = 2; //obrót, default + std::string openmethod; getkeyval( openmethod, "DoorOpenMethod", line, "" ); + if( openmethod == "Shift" ) { DoorOpenMethod = 1; } //przesuw + else if( openmethod == "Fold" ) { DoorOpenMethod = 3; } //3 submodele się obracają + else if( openmethod == "Plug" ) { DoorOpenMethod = 4; } //odskokowo-przesuwne + + std::string closurewarning; getkeyval( closurewarning, "DoorClosureWarning", line, "" ); + DoorClosureWarning = ( closurewarning == "Yes" ); + + std::string doorblocked; getkeyval( doorblocked, "DoorBlocked", line, "" ); + DoorBlocked = ( doorblocked == "Yes" ); + + getkeyval( DoorMaxPlugShift, "DoorMaxShiftPlug", line, "" ); + getkeyval( PlatformSpeed, "PlatformSpeed", line, "" ); + getkeyval( PlatformMaxShift, "PlatformMaxSpeed", line, "" ); + + PlatformOpenMethod = 2; // obrót, default + std::string platformopenmethod; getkeyval( platformopenmethod, "PlatformOpenMethod", line, "" ); + if( platformopenmethod == "Shift" ) { PlatformOpenMethod = 1; } // przesuw + + return true; +} + // ************************************************************************************************* // Q: 20160717 // ************************************************************************************************* @@ -7400,8 +7750,7 @@ bool TMoverParameters::CheckLocomotiveParameters(bool ReadyFlag, int Dir) case K: { WriteLog("XBT W, K"); - Hamulec = new TWest(MaxBrakePress[3], BrakeCylRadius, BrakeCylDist, BrakeVVolume, - BrakeCylNo, BrakeDelays, BrakeMethod, NAxles, NBpA); + Hamulec = std::make_shared(MaxBrakePress[3], BrakeCylRadius, BrakeCylDist, BrakeVVolume, BrakeCylNo, BrakeDelays, BrakeMethod, NAxles, NBpA); if (MBPM < 2) // jesli przystawka wazaca Hamulec->SetLP(0, MaxBrakePress[3], 0); else @@ -7411,8 +7760,7 @@ bool TMoverParameters::CheckLocomotiveParameters(bool ReadyFlag, int Dir) case KE: { WriteLog("XBT WKE"); - Hamulec = new TKE(MaxBrakePress[3], BrakeCylRadius, BrakeCylDist, BrakeVVolume, BrakeCylNo, - BrakeDelays, BrakeMethod, NAxles, NBpA); + Hamulec = std::make_shared(MaxBrakePress[3], BrakeCylRadius, BrakeCylDist, BrakeVVolume, BrakeCylNo, BrakeDelays, BrakeMethod, NAxles, NBpA); Hamulec->SetRM(RapidMult); if (MBPM < 2) // jesli przystawka wazaca Hamulec->SetLP(0, MaxBrakePress[3], 0); @@ -7426,9 +7774,8 @@ bool TMoverParameters::CheckLocomotiveParameters(bool ReadyFlag, int Dir) case ESt4: { WriteLog("XBT NESt3, ESt3, ESt3AL2, ESt4"); - Hamulec = new TNESt3(MaxBrakePress[3], BrakeCylRadius, BrakeCylDist, BrakeVVolume, - BrakeCylNo, BrakeDelays, BrakeMethod, NAxles, NBpA); - (static_cast(Hamulec))->SetSize(BrakeValveSize, BrakeValveParams); + Hamulec = std::make_shared(MaxBrakePress[3], BrakeCylRadius, BrakeCylDist, BrakeVVolume, BrakeCylNo, BrakeDelays, BrakeMethod, NAxles, NBpA); + static_cast(Hamulec.get())->SetSize(BrakeValveSize, BrakeValveParams); if (MBPM < 2) // jesli przystawka wazaca Hamulec->SetLP(0, MaxBrakePress[3], 0); else @@ -7439,24 +7786,28 @@ bool TMoverParameters::CheckLocomotiveParameters(bool ReadyFlag, int Dir) case LSt: { WriteLog("XBT LSt"); - Hamulec = new TLSt(MaxBrakePress[3], BrakeCylRadius, BrakeCylDist, BrakeVVolume, BrakeCylNo, - BrakeDelays, BrakeMethod, NAxles, NBpA); + Hamulec = std::make_shared(MaxBrakePress[3], BrakeCylRadius, BrakeCylDist, BrakeVVolume, BrakeCylNo, BrakeDelays, BrakeMethod, NAxles, NBpA); Hamulec->SetRM(RapidMult); break; } case EStED: { WriteLog("XBT EStED"); - Hamulec = new TEStED(MaxBrakePress[3], BrakeCylRadius, BrakeCylDist, BrakeVVolume, - BrakeCylNo, BrakeDelays, BrakeMethod, NAxles, NBpA); + Hamulec = std::make_shared(MaxBrakePress[3], BrakeCylRadius, BrakeCylDist, BrakeVVolume, BrakeCylNo, BrakeDelays, BrakeMethod, NAxles, NBpA); Hamulec->SetRM(RapidMult); + if( MBPM < 2 ) { + //jesli przystawka wazaca + Hamulec->SetLP( 0, MaxBrakePress[ 3 ], 0 ); + } + else { + Hamulec->SetLP( Mass, MBPM, MaxBrakePress[ 1 ] ); + } break; } case EP2: { WriteLog("XBT EP2"); - Hamulec = new TEStEP2(MaxBrakePress[3], BrakeCylRadius, BrakeCylDist, BrakeVVolume, - BrakeCylNo, BrakeDelays, BrakeMethod, NAxles, NBpA); + Hamulec = std::make_shared(MaxBrakePress[3], BrakeCylRadius, BrakeCylDist, BrakeVVolume, BrakeCylNo, BrakeDelays, BrakeMethod, NAxles, NBpA); Hamulec->SetLP(Mass, MBPM, MaxBrakePress[1]); break; } @@ -7464,21 +7815,18 @@ bool TMoverParameters::CheckLocomotiveParameters(bool ReadyFlag, int Dir) case CV1: { WriteLog("XBT CV1"); - Hamulec = new TCV1(MaxBrakePress[3], BrakeCylRadius, BrakeCylDist, BrakeVVolume, BrakeCylNo, - BrakeDelays, BrakeMethod, NAxles, NBpA); + Hamulec = std::make_shared(MaxBrakePress[3], BrakeCylRadius, BrakeCylDist, BrakeVVolume, BrakeCylNo, BrakeDelays, BrakeMethod, NAxles, NBpA); break; } case CV1_L_TR: { WriteLog("XBT CV1_L_T"); - Hamulec = new TCV1L_TR(MaxBrakePress[3], BrakeCylRadius, BrakeCylDist, BrakeVVolume, - BrakeCylNo, BrakeDelays, BrakeMethod, NAxles, NBpA); + Hamulec = std::make_shared(MaxBrakePress[3], BrakeCylRadius, BrakeCylDist, BrakeVVolume, BrakeCylNo, BrakeDelays, BrakeMethod, NAxles, NBpA); break; } default: - Hamulec = new TBrake(MaxBrakePress[3], BrakeCylRadius, BrakeCylDist, BrakeVVolume, - BrakeCylNo, BrakeDelays, BrakeMethod, NAxles, NBpA); + Hamulec = std::make_shared(MaxBrakePress[3], BrakeCylRadius, BrakeCylDist, BrakeVVolume, BrakeCylNo, BrakeDelays, BrakeMethod, NAxles, NBpA); } Hamulec->SetASBP(MaxBrakePress[4]); @@ -7486,50 +7834,49 @@ bool TMoverParameters::CheckLocomotiveParameters(bool ReadyFlag, int Dir) switch (BrakeHandle) { case FV4a: - Handle = new TFV4aM(); + Handle = std::make_shared(); break; case FVel6: - Handle = new TFVel6(); + Handle = std::make_shared(); break; case testH: - Handle = new Ttest(); + Handle = std::make_shared(); break; case M394: - Handle = new TM394(); + Handle = std::make_shared(); break; case Knorr: - Handle = new TH14K1(); + Handle = std::make_shared(); break; case St113: - Handle = new TSt113(); + Handle = std::make_shared(); break; default: - Handle = new TDriverHandle(); + Handle = std::make_shared(); } switch (BrakeLocHandle) { case FD1: { - LocHandle = new TFD1(); + LocHandle = std::make_shared(); LocHandle->Init(MaxBrakePress[0]); break; } case Knorr: { - LocHandle = new TH1405(); + LocHandle = std::make_shared(); LocHandle->Init(MaxBrakePress[0]); break; } default: - LocHandle = new TDriverHandle(); + LocHandle = std::make_shared(); } - Pipe = new TReservoir(); - Pipe2 = new TReservoir(); // zabezpieczenie, bo sie PG wywala... :( - Pipe->CreateCap((Max0R(Dim.L, 14) + 0.5) * Spg * 1); // dlugosc x przekroj x odejscia i takie - // tam - Pipe2->CreateCap((Max0R(Dim.L, 14) + 0.5) * Spg * 1); + Pipe = std::make_shared(); + Pipe->CreateCap( ( Max0R( Dim.L, 14 ) + 0.5 ) * Spg * 1 ); // dlugosc x przekroj x odejscia i takie tam + Pipe2 = std::make_shared(); // zabezpieczenie, bo sie PG wywala... :( + Pipe2->CreateCap( (Max0R(Dim.L, 14) + 0.5) * Spg * 1 ); if (LightsPosNo > 0) LightsPos = LightsDefPos; diff --git a/McZapkie/Oerlikon_ESt.cpp b/McZapkie/Oerlikon_ESt.cpp index 3aedf38a..705bb467 100644 --- a/McZapkie/Oerlikon_ESt.cpp +++ b/McZapkie/Oerlikon_ESt.cpp @@ -327,21 +327,17 @@ void TNESt3::Init(double PP, double HPP, double LPP, double BP, int BDF) ValveRes->CreatePress(PP); BrakeCyl->CreatePress(BP); BrakeRes->CreatePress(PP); - CntrlRes = new TReservoir(); + CntrlRes = std::make_shared(); CntrlRes->CreateCap(15); CntrlRes->CreatePress(HPP); BrakeStatus = static_cast(BP > 1.0); - Miedzypoj = new TReservoir(); + Miedzypoj = std::make_shared(); Miedzypoj->CreateCap(5); Miedzypoj->CreatePress(PP); BVM = 1.0 / (HPP - 0.05 - LPP) * MaxBP; BrakeDelayFlag = BDF; - RapidStatus = false; - LoadC, LoadM, TareBP, TareM, Podskok, LBP = 0.0; - - Zamykajacy, Przys_blok = false; if (!(typeid(*FM) == typeid(TDisk1) || typeid(*FM) == typeid(TDisk2))) // jesli zeliwo to schodz RapidStaly = false; @@ -500,35 +496,36 @@ void TNESt3::SetSize(int size, std::string params) // ustawianie dysz (rozmiaru if (params.find("ESt3") != std::string::npos) { Podskok = 0.7; - Przekladniki[1] = new TRura(); - Przekladniki[3] = new TRura(); + Przekladniki[1] = std::make_shared(); + Przekladniki[3] = std::make_shared(); } else { Podskok = -1; - Przekladniki[1] = new TRapid(); + Przekladniki[1] = std::make_shared(); if (params.find("-s216") != std::string::npos) Przekladniki[1]->SetRapidParams(2, 16); else Przekladniki[1]->SetRapidParams(2, 0); - Przekladniki[3] = new TPrzeciwposlizg(); + Przekladniki[3] = std::make_shared(); if (params.find("-ED") != std::string::npos) { - delete Przekladniki[3]; // tutaj ma być destruktor Przekladniki[1]->SetRapidParams(2, 18); - Przekladniki[3] = new TPrzekED(); + Przekladniki[3] = std::make_shared(); } } if (params.find("AL2") != std::string::npos) - Przekladniki[2] = new TPrzekCiagly(); + Przekladniki[2] = std::make_shared(); else if (params.find("PZZ") != std::string::npos) - Przekladniki[2] = new TPrzek_PZZ(); + Przekladniki[2] = std::make_shared(); else - Przekladniki[2] = new TRura(); + Przekladniki[2] = std::make_shared(); - if ((params.find("3d") + params.find("4d")) != std::string::npos) + if( ( params.find( "3d" ) != std::string::npos ) + || ( params.find( "4d" ) != std::string::npos ) ) { autom = false; + } else autom = true; if ((params.find("HBG300") != std::string::npos)) diff --git a/McZapkie/Oerlikon_ESt.h b/McZapkie/Oerlikon_ESt.h index c55ac251..ac4b3248 100644 --- a/McZapkie/Oerlikon_ESt.h +++ b/McZapkie/Oerlikon_ESt.h @@ -17,10 +17,10 @@ http://mozilla.org/MPL/2.0/. Copyright (C) 2007-2014 Maciej Cierniak */ +#include #include "hamulce.h" // Pascal unit #include "friction.h" // Pascal unit #include "mctools.h" // Pascal unit -#include /* (C) youBy @@ -72,8 +72,8 @@ class TPrzekladnik : public TReservoir // przekladnik (powtarzacz) { private: public: - TReservoir *BrakeRes; - TReservoir *Next; + std::shared_ptr BrakeRes; + std::shared_ptr Next; TPrzekladnik() : TReservoir() {}; virtual void Update(double dt); @@ -110,55 +110,51 @@ class TPrzeciwposlizg : public TRura // przy napelnianiu - rura, przy poslizgu - } }; -class TRapid : public TPrzekladnik // przekladnik dwustopniowy +// przekladnik dwustopniowy +class TRapid : public TPrzekladnik { -{ private: - bool RapidStatus; // status rapidu - double RapidMult; // przelozenie (w dol) + bool RapidStatus = false; // status rapidu + double RapidMult = 0.0; // przelozenie (w dol) // Komora2: real; - double DN; - double DL; // srednice dysz napelniania i luzowania + double DN = 0.0; + double DL = 0.0; // srednice dysz napelniania i luzowania public: void SetRapidParams(double mult, double size); void SetRapidStatus(bool rs); void Update(double dt) /*override*/; - inline TRapid() : TPrzekladnik() - { - RapidStatus = false; - RapidMult, DN, DL = 0.0; - } + inline TRapid() : + TPrzekladnik() + {} }; -class TPrzekCiagly : public TPrzekladnik // AL2 +// AL2 +class TPrzekCiagly : public TPrzekladnik { -{ private: - double mult; + double mult = 0.0; public: void SetMult(double m); void Update(double dt) /*override*/; - inline TPrzekCiagly() : TPrzekladnik() - { - mult = 0.0; - } + inline TPrzekCiagly() : + TPrzekladnik() + {} }; -class TPrzek_PZZ : public TPrzekladnik // podwojny zawor zwrotny +// podwojny zawor zwrotny +class TPrzek_PZZ : public TPrzekladnik { -{ private: - double LBP; + double LBP = 0.0; public: void SetLBP(double P); void Update(double dt) /*override*/; - inline TPrzek_PZZ() : TPrzekladnik() - { - LBP = 0.0; - } + inline TPrzek_PZZ() : + TPrzekladnik() + {} }; class TPrzekZalamany : public TPrzekladnik // Knicksventil @@ -166,59 +162,55 @@ class TPrzekZalamany : public TPrzekladnik // Knicksventil { private: public: - TPrzekZalamany() : TPrzekladnik() {}; + TPrzekZalamany() : + TPrzekladnik() + {} }; -class TPrzekED : public TRura // przy napelnianiu - rura, przy hamowaniu - upust +// przy napelnianiu - rura, przy hamowaniu - upust +class TPrzekED : public TRura { -{ private: - double MaxP; + double MaxP = 0.0; public: void SetP(double P); void Update(double dt) /*override*/; - inline TPrzekED() : TRura() - { - MaxP = 0.0; - } + inline TPrzekED() : + TRura() + {} }; -class TNESt3 : public TBrake +class TNESt3 : public TBrake { -{ private: - double Nozzles[dMAX]; // dysze - TReservoir *CntrlRes; // zbiornik sterujący - double BVM; // przelozenie PG-CH + std::shared_ptr CntrlRes; // zbiornik sterujacy + std::shared_ptr Miedzypoj; // pojemnosc posrednia (urojona) do napelniania ZP i ZS + std::shared_ptr Przekladniki[ 4 ]; + double Nozzles[ dMAX ]; // dysze + double BVM = 0.0; // przelozenie PG-CH // ValveFlag: byte; //polozenie roznych zaworkow - bool Zamykajacy; // pamiec zaworka zamykajacego + bool Zamykajacy = false; // pamiec zaworka zamykajacego // Przys_wlot: boolean; //wlot do komory przyspieszacza - bool Przys_blok; // blokada przyspieszacza - TReservoir *Miedzypoj; // pojemnosc posrednia (urojona) do napelniania ZP i ZS - TPrzekladnik *Przekladniki[4]; - bool RapidStatus; - bool RapidStaly; - double LoadC; - double TareM; - double LoadM; // masa proznego i pelnego - double TareBP; // cisnienie dla proznego - double HBG300; // zawor ograniczajacy cisnienie - double Podskok; // podskok preznosci poczatkowej + bool Przys_blok = false; // blokada przyspieszacza + bool RapidStatus = false; + bool RapidStaly = false; + double LoadC = 0.0; + double TareM = 0.0; // masa proznego + double LoadM = 0.0; // masa pelnego + double TareBP = 0.0; // cisnienie dla proznego + double HBG300 = 0.0; // zawor ograniczajacy cisnienie + double Podskok = 0.0; // podskok preznosci poczatkowej // HPBR: real; //zasilanie ZP z wysokiego cisnienia - bool autom; // odluzniacz samoczynny - double LBP; // cisnienie hamulca pomocniczego - + bool autom = false; // odluzniacz samoczynny + double LBP = 0.0; // cisnienie hamulca pomocniczego public: - inline TNESt3(double i_mbp, double i_bcr, double i_bcd, double i_brc, - int i_bcn, int i_BD, int i_mat, int i_ba, int i_nbpa) : TBrake(i_mbp, i_bcr, i_bcd, i_brc, i_bcn - , i_BD, i_mat, i_ba, i_nbpa) - { - } + inline TNESt3(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn, int i_BD, int i_mat, int i_ba, int i_nbpa) : + TBrake( i_mbp, i_bcr, i_bcd, i_brc, i_bcn, i_BD, i_mat, i_ba, i_nbpa) + {} void Init(double PP, double HPP, double LPP, double BP, int BDF) /*override*/; - virtual double GetPF(double PP, double dt, - double Vel) /*override*/; // przeplyw miedzy komora wstepna i PG + virtual double GetPF(double PP, double dt, double Vel) /*override*/; // przeplyw miedzy komora wstepna i PG void EStParams(double i_crc); // parametry charakterystyczne dla ESt virtual double GetCRP() /*override*/; void CheckState(double BCP, double &dV1); // glowny przyrzad rozrzadczy diff --git a/McZapkie/hamulce.cpp b/McZapkie/hamulce.cpp index 0c766e48..90a00b02 100644 --- a/McZapkie/hamulce.cpp +++ b/McZapkie/hamulce.cpp @@ -20,15 +20,15 @@ Copyright (C) 2007-2014 Maciej Cierniak //---FUNKCJE OGOLNE--- static double const DPL = 0.25; -double TFV4aM::pos_table[11] = {-2, 6, -1, 0, -2, 1, 4, 6, 0, 0, 0}; -double TMHZ_EN57::pos_table[11] = {-2, 10, -1, 0, 0, 2, 9, 10, 0, 0, 0}; -double TM394::pos_table[11] = {-1, 5, -1, 0, 1, 2, 4, 5, 0, 0, 0}; -double TH14K1::BPT_K[6][2] = {{10, 0}, {4, 1}, {0, 1}, {4, 0}, {4, -1}, {15, -1}}; -double TH14K1::pos_table[11] = {-1, 4, -1, 0, 1, 2, 3, 4, 0, 0, 0}; -double TSt113::BPT_K[6][2] = {{10, 0}, {4, 1}, {0, 1}, {4, 0}, {4, -1}, {15, -1}}; -double TSt113::BEP_K[7] = {0, -1, 1, 0, 0, 0, 0}; -double TSt113::pos_table[11] = {-1, 5, -1, 0, 2, 3, 4, 5, 0, 0, 1}; -double TFVel6::pos_table[11] = {-1, 6, -1, 0, 6, 4, 4.7, 5, -1, 0, 1}; +double const TFV4aM::pos_table[11] = {-2, 6, -1, 0, -2, 1, 4, 6, 0, 0, 0}; +double const TMHZ_EN57::pos_table[11] = {-2, 10, -1, 0, 0, 2, 9, 10, 0, 0, 0}; +double const TM394::pos_table[11] = {-1, 5, -1, 0, 1, 2, 4, 5, 0, 0, 0}; +double const TH14K1::BPT_K[6][2] = {{10, 0}, {4, 1}, {0, 1}, {4, 0}, {4, -1}, {15, -1}}; +double const TH14K1::pos_table[11] = {-1, 4, -1, 0, 1, 2, 3, 4, 0, 0, 0}; +double const TSt113::BPT_K[6][2] = {{10, 0}, {4, 1}, {0, 1}, {4, 0}, {4, -1}, {15, -1}}; +double const TSt113::BEP_K[7] = {0, -1, 1, 0, 0, 0, 0}; +double const TSt113::pos_table[11] = {-1, 5, -1, 0, 2, 3, 4, 5, 0, 0, 1}; +double const TFVel6::pos_table[11] = {-1, 6, -1, 0, 6, 4, 4.7, 5, -1, 0, 1}; double PR(double P1, double P2) { @@ -96,9 +96,9 @@ double PFVa(double PH, double PL, double S, double LIM, FM = FM * (LIM - PL) / DP; // jesli jestesmy przy nastawieniu, to zawor sie przymyka if ((sg > 0.5)) // jesli ponizej stosunku krytycznego if ((PH - PL) < DPL) // niewielka roznica cisnien - return (PH - PL) / DPL * FM * 2 * sqrt((sg) * (1 - sg)); + return (PH - PL) / DPL * FM * 2 * sqrt((sg) * (1 - sg)); // BUG: (1-sg) can be < 0, leading to sqrt(-x) else - return FM * 2 * sqrt((sg) * (1 - sg)); + return FM * 2 * sqrt( (sg) * ( 1 - sg ) ); // BUG: (1-sg) can be < 0, leading to sqrt(-x) else // powyzej stosunku krytycznego return FM; } @@ -147,14 +147,6 @@ void TReservoir::Flow(double dv) dVol = dVol + dv; } -TReservoir::TReservoir() -{ - // inherited:: Create; - Cap = 1; - Vol = 0; - dVol = 0; -} - void TReservoir::Act() { Vol = Vol + dVol; @@ -201,7 +193,8 @@ double TBrakeCyl::P() static double const cD = 1; static double const pD = VD - cD; - double VtoC = Vol / Cap; // stosunek cisnienia do objetosci + double VtoC = ( Cap > 0.0 ) ? Vol / Cap : 0.0; // stosunek cisnienia do objetosci. + // Added div/0 trap for vehicles with incomplete definitions (cars etc) // P:=VtoC; if (VtoC < VS) return VtoC * pS / VS; // objetosc szkodliwa @@ -264,9 +257,9 @@ TBrake::TBrake(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn 4.2; // objetosc CH w stosunku do cylindra 14" i cisnienia 4.2 atm // BrakeCyl:=TReservoir.Create; - BrakeCyl = new TBrakeCyl(); - BrakeRes = new TReservoir(); - ValveRes = new TReservoir(); + BrakeCyl = std::make_shared(); + BrakeRes = std::make_shared(); + ValveRes = std::make_shared(); // tworzenie zbiornikow BrakeCyl->CreateCap(i_bcd * BCA * 1000); @@ -279,34 +272,34 @@ TBrake::TBrake(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn switch (i_mat) { case bp_P10Bg: - FM = new TP10Bg(); + FM = std::make_shared(); break; case bp_P10Bgu: - FM = new TP10Bgu(); + FM = std::make_shared(); break; case bp_FR513: - FM = new TFR513(); + FM = std::make_shared(); break; case bp_FR510: - FM = new TFR510(); + FM = std::make_shared(); break; case bp_Cosid: - FM = new TCosid(); + FM = std::make_shared(); break; case bp_P10yBg: - FM = new TP10yBg(); + FM = std::make_shared(); break; case bp_P10yBgu: - FM = new TP10yBgu(); + FM = std::make_shared(); break; case bp_D1: - FM = new TDisk1(); + FM = std::make_shared(); break; case bp_D2: - FM = new TDisk2(); + FM = std::make_shared(); break; default: // domyslnie - FM = new TP10(); + FM = std::make_shared(); } } @@ -1842,7 +1835,7 @@ void TKE::CheckReleaser(double dt) CVP = CntrlRes->P(); // odluzniacz - if ((BrakeStatus && b_rls) == b_rls) + if ( true == ((BrakeStatus & b_rls) == b_rls)) if ((CVP - VVP < 0)) BrakeStatus &= 247; else @@ -2203,10 +2196,7 @@ double TFV4a::GetPF(double i_bcp, double PP, double HP, double dt, double ep) void TFV4a::Init(double Press) { CP = Press; - TP = 0; RP = Press; - Time = false; - TimeEP = false; } //---FV4a/M--- nowonapisany kran bez poprawki IC @@ -2342,13 +2332,7 @@ double TFV4aM::GetPF(double i_bcp, double PP, double HP, double dt, double ep) void TFV4aM::Init(double Press) { CP = Press; - TP = 0.0; RP = Press; - XP = 0.0; - Time = false; - TimeEP = false; - RedAdj = 0.0; - Fala = false; } void TFV4aM::SetReductor(double nAdj) @@ -2483,12 +2467,6 @@ double TMHZ_EN57::GetPF(double i_bcp, double PP, double HP, double dt, double ep void TMHZ_EN57::Init(double Press) { CP = Press; - TP = 0.0; - RP = 0.0; - Time = false; - TimeEP = false; - RedAdj = 0.0; - Fala = false; } void TMHZ_EN57::SetReductor(double nAdj) @@ -2591,9 +2569,7 @@ double TM394::GetPF(double i_bcp, double PP, double HP, double dt, double ep) void TM394::Init(double Press) { CP = Press; - RedAdj = 0; Time = true; - TimeEP = false; } void TM394::SetReductor(double nAdj) @@ -2615,32 +2591,23 @@ double TM394::GetPos(int i) double TH14K1::GetPF(double i_bcp, double PP, double HP, double dt, double ep) { - static int const LBDelay = 100; // szybkosc + zasilanie sterujacego + int const LBDelay = 100; // szybkosc + zasilanie sterujacego // static double const BPT_K[/*?*/ /*-1..4*/ (4) - (-1) + 1][2] = //{ (10, 0), (4, 1), (0, 1), (4, 0), (4, -1), (15, -1) }; - static double const NomPress = 5.0; + double const NomPress = 5.0; - double LimPP; - double dpPipe; - double dpMainValve; - double ActFlowSpeed; - int BCP; + int BCP = std::lround(i_bcp); + if( i_bcp < -1 ) { BCP = 1; } - BCP = lround(i_bcp); - if (i_bcp < -1) - BCP = 1; - LimPP = BPT_K[BCP + 1][1]; - if (LimPP < 0) - LimPP = 0.5 * PP; - else if (LimPP > 0) - LimPP = PP; - else - LimPP = CP; - ActFlowSpeed = BPT_K[BCP + 1][0]; + double LimPP = BPT_K[BCP + 1][1]; + if( LimPP < 0.0 ) { LimPP = 0.5 * PP; } + else if( LimPP > 0.0 ) { LimPP = PP; } + else { LimPP = CP; } + double ActFlowSpeed = BPT_K[BCP + 1][0]; - CP = CP + 6 * Min0R(abs(LimPP - CP), 0.05) * PR(CP, LimPP) * dt; // zbiornik sterujacy + CP = CP + 6 * std::min( std::abs(LimPP - CP), 0.05 ) * PR(CP, LimPP) * dt; // zbiornik sterujacy - dpMainValve = 0; + double dpMainValve = 0.0; if (BCP == -1) dpMainValve = PF(HP, PP, ActFlowSpeed / LBDelay) * dt; @@ -2657,7 +2624,6 @@ double TH14K1::GetPF(double i_bcp, double PP, double HP, double dt, double ep) void TH14K1::Init(double Press) { CP = Press; - RedAdj = 0; Time = true; TimeEP = true; } @@ -2738,7 +2704,6 @@ void TSt113::Init(double Press) { Time = true; TimeEP = true; - EPS = 0.0; } //--- test --- @@ -2799,11 +2764,8 @@ double TFD1::GetPF(double i_bcp, double PP, double HP, double dt, double ep) void TFD1::Init(double Press) { - BP = 0; MaxBP = Press; - Time = false; - TimeEP = false; - Speed = 1; + Speed = 1.0; } double TFD1::GetCP() @@ -2844,10 +2806,8 @@ double TH1405::GetPF(double i_bcp, double PP, double HP, double dt, double ep) void TH1405::Init(double Press) { - BP = 0; MaxBP = Press; Time = true; - TimeEP = false; } double TH1405::GetCP() @@ -2919,7 +2879,6 @@ void TFVel6::Init(double Press) { Time = true; TimeEP = true; - EPS = 0.0; } // END diff --git a/McZapkie/hamulce.h b/McZapkie/hamulce.h index 175bd258..d2c2db8b 100644 --- a/McZapkie/hamulce.h +++ b/McZapkie/hamulce.h @@ -1,6 +1,3 @@ -#pragma once -#ifndef INCLUDED_HAMULCE_H -#define INCLUDED_HAMULCE_H /*fizyka hamulcow dla symulatora*/ /* @@ -17,6 +14,7 @@ http://mozilla.org/MPL/2.0/. Copyright (C) 2007-2014 Maciej Cierniak */ + /* (C) youBy Co brakuje: @@ -34,58 +32,60 @@ H14K1 (zasadniczy), H1405 (pomocniczy), St113 (ep) Knorr/West EP - żeby był */ +#pragma once + #include "friction.h" // Pascal unit #include "mctools.h" // Pascal unit -//#include -static int const LocalBrakePosNo = 10; /*ilosc nastaw hamulca recznego lub pomocniczego*/ -static int const MainBrakeMaxPos = 10; /*max. ilosc nastaw hamulca zasadniczego*/ +static int const LocalBrakePosNo = 10; /*ilosc nastaw hamulca recznego lub pomocniczego*/ +static int const MainBrakeMaxPos = 10; /*max. ilosc nastaw hamulca zasadniczego*/ /*nastawy hamulca*/ -static int const bdelay_G = 1; // G -static int const bdelay_P = 2; // P -static int const bdelay_R = 4; // R -static int const bdelay_M = 8; // Mg -static int const bdelay_GR = 128; // G-R +static int const bdelay_G = 1; //G +static int const bdelay_P = 2; //P +static int const bdelay_R = 4; //R +static int const bdelay_M = 8; //Mg +static int const bdelay_GR = 128; //G-R + /*stan hamulca*/ -static int const b_off = 0; // luzowanie -static int const b_hld = 1; // trzymanie -static int const b_on = 2; // napelnianie -static int const b_rfl = 4; // uzupelnianie -static int const b_rls = 8; // odluzniacz -static int const b_ep = 16; // elektropneumatyczny -static int const b_asb = 32; // elektropneumatyczny -static int const b_dmg = 128; // wylaczony z dzialania +static int const b_off = 0; //luzowanie +static int const b_hld = 1; //trzymanie +static int const b_on = 2; //napelnianie +static int const b_rfl = 4; //uzupelnianie +static int const b_rls = 8; //odluzniacz +static int const b_ep = 16; //elektropneumatyczny +static int const b_asb = 32; //elektropneumatyczny +static int const b_dmg = 128; //wylaczony z dzialania /*uszkodzenia hamulca*/ -static int const df_on = 1; // napelnianie -static int const df_off = 2; // luzowanie -static int const df_br = 4; // wyplyw z ZP -static int const df_vv = 8; // wyplyw z komory wstepnej -static int const df_bc = 16; // wyplyw z silownika -static int const df_cv = 32; // wyplyw z ZS -static int const df_PP = 64; // zawsze niski stopien -static int const df_RR = 128; // zawsze wysoki stopien +static int const df_on = 1; //napelnianie +static int const df_off = 2; //luzowanie +static int const df_br = 4; //wyplyw z ZP +static int const df_vv = 8; //wyplyw z komory wstepnej +static int const df_bc = 16; //wyplyw z silownika +static int const df_cv = 32; //wyplyw z ZS +static int const df_PP = 64; //zawsze niski stopien +static int const df_RR = 128; //zawsze wysoki stopien /*indeksy dzwiekow FV4a*/ -static int const s_fv4a_b = 0; // hamowanie -static int const s_fv4a_u = 1; // luzowanie -static int const s_fv4a_e = 2; // hamowanie nagle -static int const s_fv4a_x = 3; // wyplyw sterujacego fala -static int const s_fv4a_t = 4; // wyplyw z czasowego +static int const s_fv4a_b = 0; //hamowanie +static int const s_fv4a_u = 1; //luzowanie +static int const s_fv4a_e = 2; //hamowanie nagle +static int const s_fv4a_x = 3; //wyplyw sterujacego fala +static int const s_fv4a_t = 4; //wyplyw z czasowego /*pary cierne*/ static int const bp_P10 = 0; static int const bp_P10Bg = 2; //żeliwo fosforowe P10 static int const bp_P10Bgu = 1; -static int const bp_LLBg = 4; // komp. b.n.t. +static int const bp_LLBg = 4; //komp. b.n.t. static int const bp_LLBgu = 3; -static int const bp_LBg = 6; // komp. n.t. +static int const bp_LBg = 6; //komp. n.t. static int const bp_LBgu = 5; -static int const bp_KBg = 8; // komp. w.t. +static int const bp_KBg = 8; //komp. w.t. static int const bp_KBgu = 7; -static int const bp_D1 = 9; // tarcze +static int const bp_D1 = 9; //tarcze static int const bp_D2 = 10; static int const bp_FR513 = 11; // Frenoplast FR513 static int const bp_Cosid = 12; // jakistam kompozyt :D @@ -94,14 +94,14 @@ static int const bp_PKPBgu = 14; static int const bp_MHS = 128; // magnetyczny hamulec szynowy static int const bp_P10yBg = 15; //żeliwo fosforowe P10 static int const bp_P10yBgu = 16; -static int const bp_FR510 = 17; // Frenoplast FR510 +static int const bp_FR510 = 17; //Frenoplast FR510 -static int const sf_Acc = 1; // przyspieszacz -static int const sf_BR = 2; // przekladnia -static int const sf_CylB = 4; // cylinder - napelnianie -static int const sf_CylU = 8; // cylinder - oproznianie -static int const sf_rel = 16; // odluzniacz -static int const sf_ep = 32; // zawory ep +static int const sf_Acc = 1; //przyspieszacz +static int const sf_BR = 2; //przekladnia +static int const sf_CylB = 4; //cylinder - napelnianie +static int const sf_CylU = 8; //cylinder - oproznianie +static int const sf_rel = 16; //odluzniacz +static int const sf_ep = 32; //zawory ep static int const bh_MIN = 0; // minimalna pozycja static int const bh_MAX = 1; // maksymalna pozycja @@ -112,456 +112,397 @@ static int const bh_MB = 5; // odciecie - utrzymanie stopnia hamowania/pierwszy static int const bh_FB = 6; // pelne static int const bh_EB = 7; // nagle static int const bh_EPR = 8; // ep - luzowanie //pelny luz dla ep kątowego -static int const bh_EPN = 9; // ep - utrzymanie //jesli rowne luzowaniu, wtedy sterowanie -// przyciskiem +static int const bh_EPN = 9; // ep - utrzymanie //jesli rowne luzowaniu, wtedy sterowanie przyciskiem static int const bh_EPB = 10; // ep - hamowanie //pelne hamowanie dla ep kątowego + static double const SpgD = 0.7917; -static double const SpO = 0.5067; // przekroj przewodu 1" w l/m -// wyj: jednostka dosyc dziwna, ale wszystkie obliczenia -// i pojemnosci sa podane w litrach (rozsadne wielkosci) -// zas dlugosc pojazdow jest podana w metrach -// a predkosc przeplywu w m/s //3.5 -// 7//1.5 -// BPT: array[-2..6] of array [0..1] of real= ((0, 5.0), (14, 5.4), (9, 5.0), (6, 4.6), (9, 4.5), -// (9, 4.0), (9, 3.5), (9, 2.8), (34, 2.8)); -// BPT: array[-2..6] of array [0..1] of real= ((0, 5.0), (7, 5.0), (2.0, 5.0), (4.5, 4.6), (4.5, -// 4.2), (4.5, 3.8), (4.5, 3.4), (4.5, 2.8), (8, 2.8)); -static double BPT[9][2] = {{0, 5.0}, {7, 5.0}, {2.0, 5.0}, {4.5, 4.6}, {4.5, 4.2}, - {4.5, 3.8}, {4.5, 3.4}, {4.5, 2.8}, {8, 2.8}}; -static double BPT_394[7][2] = {{13, 10.0}, {5, 5.0}, {0, -1}, {5, -1}, - {5, 0.0}, {5, 0.0}, {18, 0.0}}; -// double *BPT = zero_based_BPT[2]; //tablica pozycji hamulca dla zakresu -2..6 -// double *BPT_394 = zero_based_BPT_394[1]; //tablica pozycji hamulca dla zakresu -1..5 -// BPT: array[-2..6] of array [0..1] of real= ((0, 5.0), (12, 5.4), (9, 5.0), (9, 4.6), (9, 4.2), -// (9, 3.8), (9, 3.4), (9, 2.8), (34, 2.8)); -// BPT: array[-2..6] of array [0..1] of real= ((0, 0),(0, 0),(0, 0),(0, 0),(0, 0),(0, 0),(0, -// 0),(0, 0),(0, 0)); +static double const SpO = 0.5067; //przekroj przewodu 1" w l/m + //wyj: jednostka dosyc dziwna, ale wszystkie obliczenia + //i pojemnosci sa podane w litrach (rozsadne wielkosci) + //zas dlugosc pojazdow jest podana w metrach + //a predkosc przeplywu w m/s //3.5 + //7//1.5 +// BPT: array[-2..6] of array [0..1] of real= ((0, 5.0), (14, 5.4), (9, 5.0), (6, 4.6), (9, 4.5), (9, 4.0), (9, 3.5), (9, 2.8), (34, 2.8)); +// BPT: array[-2..6] of array [0..1] of real= ((0, 5.0), (7, 5.0), (2.0, 5.0), (4.5, 4.6), (4.5, 4.2), (4.5, 3.8), (4.5, 3.4), (4.5, 2.8), (8, 2.8)); +static double const BPT[9][2] = { {0 , 5.0} , {7 , 5.0} , {2.0 , 5.0} , {4.5 , 4.6} , {4.5 , 4.2} , {4.5 , 3.8} , {4.5 , 3.4} , {4.5 , 2.8} , {8 , 2.8} }; +static double const BPT_394[7][2] = { {13 , 10.0} , {5 , 5.0} , {0 , -1} , {5 , -1} , {5 , 0.0} , {5 , 0.0} , {18 , 0.0} }; +//double *BPT = zero_based_BPT[2]; //tablica pozycji hamulca dla zakresu -2..6 +//double *BPT_394 = zero_based_BPT_394[1]; //tablica pozycji hamulca dla zakresu -1..5 +// BPT: array[-2..6] of array [0..1] of real= ((0, 5.0), (12, 5.4), (9, 5.0), (9, 4.6), (9, 4.2), (9, 3.8), (9, 3.4), (9, 2.8), (34, 2.8)); +// BPT: array[-2..6] of array [0..1] of real= ((0, 0),(0, 0),(0, 0),(0, 0),(0, 0),(0, 0),(0, 0),(0, 0),(0, 0)); static int const i_bcpno = 6; // static double const pi = 3.141592653589793; //definicja w mctools -// klasa obejmujaca pojedyncze zbiorniki +//klasa obejmujaca pojedyncze zbiorniki +class TReservoir { -class TReservoir -{ protected: - double Cap; - double Vol; - double dVol; + double Cap = 1.0; + double Vol = 0.0; + double dVol = 0.0; public: - TReservoir(); void CreateCap(double Capacity); void CreatePress(double Press); virtual double pa(); virtual double P(); void Flow(double dv); void Act(); + + TReservoir() = default; }; typedef TReservoir *PReservoir; -class TBrakeCyl : public TReservoir -{ +class TBrakeCyl : public TReservoir { + public: - virtual double pa() /*override*/; - virtual double P() /*override*/; - TBrakeCyl() : TReservoir(){}; + virtual double pa()/*override*/; + virtual double P()/*override*/; + TBrakeCyl() : TReservoir() {}; }; -// klasa obejmujaca uklad hamulca zespolonego pojazdu +//klasa obejmujaca uklad hamulca zespolonego pojazdu +class TBrake { -class TBrake -{ protected: - TReservoir *BrakeCyl; // silownik - TReservoir *BrakeRes; // ZP - TReservoir *ValveRes; // komora wstepna - int BCN; // ilosc silownikow - double BCM; // przekladnia hamulcowa - double BCA; // laczny przekroj silownikow - int BrakeDelays; // dostepne opoznienia - int BrakeDelayFlag; // aktualna nastawa - TFricMat *FM; // material cierny - double MaxBP; // najwyzsze cisnienie - int BA; // osie hamowane - int NBpA; // klocki na os - double SizeBR; // rozmiar^2 ZP (w stosunku do 14") - double SizeBC; // rozmiar^2 CH (w stosunku do 14") - bool DCV; // podwojny zawor zwrotny - double ASBP; // cisnienie hamulca pp + std::shared_ptr BrakeCyl; //silownik + std::shared_ptr BrakeRes; //ZP + std::shared_ptr ValveRes; //komora wstepna + int BCN = 0; //ilosc silownikow + double BCM = 0.0; //przekladnia hamulcowa + double BCA = 0.0; //laczny przekroj silownikow + int BrakeDelays = 0; //dostepne opoznienia + int BrakeDelayFlag = 0; //aktualna nastawa + std::shared_ptr FM; //material cierny + double MaxBP = 0.0; //najwyzsze cisnienie + int BA = 0; //osie hamowane + int NBpA = 0; //klocki na os + double SizeBR = 0.0; //rozmiar^2 ZP (w stosunku do 14") + double SizeBC = 0.0; //rozmiar^2 CH (w stosunku do 14") + bool DCV = false; //podwojny zawor zwrotny + double ASBP = 0.0; //cisnienie hamulca pp - int BrakeStatus; // flaga stanu - int SoundFlag; + int BrakeStatus = 0; //flaga stanu + int SoundFlag = 0; public: - TBrake(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn, int i_BD, int i_mat, - int i_ba, int i_nbpa); - // maksymalne cisnienie, promien, skok roboczy, pojemnosc ZP; - // ilosc cylindrow, opoznienia hamulca, material klockow, osie hamowane, klocki na os; - virtual void Init(double PP, double HPP, double LPP, double BP, - int BDF); // inicjalizacja hamulca + TBrake(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn, int i_BD, int i_mat, int i_ba, int i_nbpa); + //maksymalne cisnienie, promien, skok roboczy, pojemnosc ZP, ilosc cylindrow, opoznienia hamulca, material klockow, osie hamowane, klocki na os; + virtual void Init(double PP, double HPP, double LPP, double BP, int BDF); //inicjalizacja hamulca - double GetFC(double Vel, double N); // wspolczynnik tarcia - hamulec wie lepiej - virtual double GetPF(double PP, double dt, double Vel); // przeplyw miedzy komora wstepna i PG - double GetBCF(); // sila tlokowa z tloka - virtual double GetHPFlow(double HP, double dt); // przeplyw - 8 bar - double GetBCP(); // cisnienie cylindrow hamulcowych - virtual double - GetEDBCP(); // cisnienie tylko z hamulca zasadniczego, uzywane do hamulca ED w EP09 - double GetBRP(); // cisnienie zbiornika pomocniczego - double GetVRP(); // cisnienie komory wstepnej rozdzielacza - virtual double GetCRP(); // cisnienie zbiornika sterujacego - bool SetBDF(int nBDF); // nastawiacz GPRM - void Releaser(int state); // odluzniacz - virtual void SetEPS(double nEPS); // hamulec EP - virtual void SetRM(double RMR){}; // ustalenie przelozenia rapida - virtual void SetLP(double TM, double LM, double TBP){}; // parametry przystawki wazacej - virtual void SetLBP(double P){}; // cisnienie z hamulca pomocniczego - virtual void PLC(double mass){}; // wspolczynnik cisnienia przystawki wazacej - void ASB(int state); // hamulec przeciwposlizgowy - int GetStatus(); // flaga statusu, moze sie przydac do odglosow - void SetASBP(double Press); // ustalenie cisnienia pp + double GetFC(double Vel, double N); //wspolczynnik tarcia - hamulec wie lepiej + virtual double GetPF(double PP, double dt, double Vel); //przeplyw miedzy komora wstepna i PG + double GetBCF(); //sila tlokowa z tloka + virtual double GetHPFlow(double HP, double dt); //przeplyw - 8 bar + double GetBCP(); //cisnienie cylindrow hamulcowych + virtual double GetEDBCP(); //cisnienie tylko z hamulca zasadniczego, uzywane do hamulca ED w EP09 + double GetBRP(); //cisnienie zbiornika pomocniczego + double GetVRP(); //cisnienie komory wstepnej rozdzielacza + virtual double GetCRP(); //cisnienie zbiornika sterujacego + bool SetBDF(int nBDF); //nastawiacz GPRM + void Releaser(int state); //odluzniacz + virtual void SetEPS(double nEPS); //hamulec EP + virtual void SetRM(double RMR) {}; //ustalenie przelozenia rapida + virtual void SetLP(double TM, double LM, double TBP) {}; //parametry przystawki wazacej + virtual void SetLBP(double P) {}; //cisnienie z hamulca pomocniczego + virtual void PLC(double mass) {}; //wspolczynnik cisnienia przystawki wazacej + void ASB(int state); //hamulec przeciwposlizgowy + int GetStatus(); //flaga statusu, moze sie przydac do odglosow + void SetASBP(double Press); //ustalenie cisnienia pp virtual void ForceEmptiness(); int GetSoundFlag(); - virtual void SetED(double EDstate){}; // stan hamulca ED do luzowania - - // procedure + virtual void SetED(double EDstate) {}; //stan hamulca ED do luzowania }; -class TWest : public TBrake +class TWest : public TBrake { -{ private: - double LBP; // cisnienie hamulca pomocniczego - double dVP; // pobor powietrza wysokiego cisnienia - double EPS; // stan elektropneumatyka - double TareM; - double LoadM; // masa proznego i pelnego - double TareBP; // cisnienie dla proznego - double LoadC; // wspolczynnik przystawki wazacej + double LBP = 0.0; //cisnienie hamulca pomocniczego + double dVP = 0.0; //pobor powietrza wysokiego cisnienia + double EPS = 0.0; //stan elektropneumatyka + double TareM = 0.0; //masa proznego + double LoadM = 0.0; //i pelnego + double TareBP = 0.0; //cisnienie dla proznego + double LoadC = 0.0; //wspolczynnik przystawki wazacej public: - void Init(double PP, double HPP, double LPP, double BP, int BDF) /*override*/; - void SetLBP(double P); // cisnienie z hamulca pomocniczego - double GetPF(double PP, double dt, - double Vel) /*override*/; // przeplyw miedzy komora wstepna i PG - double GetHPFlow(double HP, double dt) /*override*/; - void PLC(double mass); // wspolczynnik cisnienia przystawki wazacej - void SetEPS(double nEPS) /*override*/; // stan hamulca EP - void SetLP(double TM, double LM, double TBP); // parametry przystawki wazacej + void Init(double PP, double HPP, double LPP, double BP, int BDF)/*override*/; + void SetLBP(double P); //cisnienie z hamulca pomocniczego + double GetPF(double PP, double dt, double Vel)/*override*/; //przeplyw miedzy komora wstepna i PG + double GetHPFlow(double HP, double dt)/*override*/; + void PLC(double mass); //wspolczynnik cisnienia przystawki wazacej + void SetEPS(double nEPS)/*override*/; //stan hamulca EP + void SetLP(double TM, double LM, double TBP); //parametry przystawki wazacej - inline TWest(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn, int i_BD, - int i_mat, int i_ba, int i_nbpa) - : TBrake(i_mbp, i_bcr, i_bcd, i_brc, i_bcn, i_BD, i_mat, i_ba, i_nbpa) - { - LBP = 0, dVP = 0, EPS = 0, TareM = 0, TareBP = 0, LoadM = 0, LoadC = 0.0; - } + inline TWest(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn, int i_BD, int i_mat, int i_ba, int i_nbpa) : + TBrake( i_mbp, i_bcr, i_bcd, i_brc, i_bcn, i_BD, i_mat, i_ba, i_nbpa) + {} }; -class TESt : public TBrake +class TESt : public TBrake { -{ private: - protected: - TReservoir *CntrlRes; // zbiornik sterujący - double BVM; // przelozenie PG-CH - - public: - void Init(double PP, double HPP, double LPP, double BP, int BDF) /*override*/; - double GetPF(double PP, double dt, - double Vel) /*override*/; // przeplyw miedzy komora wstepna i PG - void EStParams(double i_crc); // parametry charakterystyczne dla ESt - double GetCRP() /*override*/; - void CheckState(double BCP, double &dV1); // glowny przyrzad rozrzadczy - void CheckReleaser(double dt); // odluzniacz - double CVs(double BP); // napelniacz sterujacego - double BVs(double BCP); // napelniacz pomocniczego - - inline TESt(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn, int i_BD, - int i_mat, int i_ba, int i_nbpa) - : TBrake(i_mbp, i_bcr, i_bcd, i_brc, i_bcn, i_BD, i_mat, i_ba, i_nbpa) - { - CntrlRes = new TReservoir(); - } -}; - -class TESt3 : public TESt - -{ - private: - // double CylFlowSpeed[2][2]; //zmienna nie uzywana - - public: - double GetPF(double PP, double dt, - double Vel) /*override*/; // przeplyw miedzy komora wstepna i PG - - inline TESt3(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn, int i_BD, - int i_mat, int i_ba, int i_nbpa) - : TESt(i_mbp, i_bcr, i_bcd, i_brc, i_bcn, i_BD, i_mat, i_ba, i_nbpa) - { - } -}; - -class TESt3AL2 : public TESt3 - -{ - private: - double TareM; - double LoadM; // masa proznego i pelnego - double TareBP; // cisnienie dla proznego - double LoadC; - - public: - TReservoir *ImplsRes; // komora impulsowa - void Init(double PP, double HPP, double LPP, double BP, int BDF) /*override*/; - double GetPF(double PP, double dt, - double Vel) /*override*/; // przeplyw miedzy komora wstepna i PG - void PLC(double mass); // wspolczynnik cisnienia przystawki wazacej - void SetLP(double TM, double LM, double TBP); // parametry przystawki wazacej - - inline TESt3AL2(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn, int i_BD, - int i_mat, int i_ba, int i_nbpa) - : TESt3(i_mbp, i_bcr, i_bcd, i_brc, i_bcn, i_BD, i_mat, i_ba, i_nbpa) - { - TareM = 0, TareBP = 0, LoadM = 0, LoadC = 0.0; - } -}; - -class TESt4R : public TESt - -{ - private: - bool RapidStatus; protected: - TReservoir *ImplsRes; // komora impulsowa - double RapidTemp; // aktualne, zmienne przelozenie + std::shared_ptr CntrlRes; // zbiornik sterujący + double BVM = 0.0; // przelozenie PG-CH public: - void Init(double PP, double HPP, double LPP, double BP, int BDF) /*override*/; - double GetPF(double PP, double dt, - double Vel) /*override*/; // przeplyw miedzy komora wstepna i PG + void Init(double PP, double HPP, double LPP, double BP, int BDF)/*override*/; + double GetPF(double PP, double dt, double Vel)/*override*/; //przeplyw miedzy komora wstepna i PG + void EStParams(double i_crc); //parametry charakterystyczne dla ESt + double GetCRP()/*override*/; + void CheckState(double BCP, double & dV1); //glowny przyrzad rozrzadczy + void CheckReleaser(double dt); //odluzniacz + double CVs(double BP); //napelniacz sterujacego + double BVs(double BCP); //napelniacz pomocniczego - inline TESt4R(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn, int i_BD, - int i_mat, int i_ba, int i_nbpa) - : TESt(i_mbp, i_bcr, i_bcd, i_brc, i_bcn, i_BD, i_mat, i_ba, i_nbpa) + inline TESt(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn, int i_BD, int i_mat, int i_ba, int i_nbpa) : + TBrake( i_mbp, i_bcr, i_bcd, i_brc, i_bcn, i_BD, i_mat, i_ba, i_nbpa) { - RapidTemp = 0.0; - ImplsRes = new TReservoir(); + CntrlRes = std::make_shared(); } }; -class TLSt : public TESt4R +class TESt3 : public TESt { + + private: + //double CylFlowSpeed[2][2]; //zmienna nie uzywana + + public: + double GetPF(double PP, double dt, double Vel)/*override*/; //przeplyw miedzy komora wstepna i PG + + inline TESt3(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn, int i_BD, int i_mat, int i_ba, int i_nbpa) : + TESt( i_mbp, i_bcr, i_bcd, i_brc, i_bcn, i_BD, i_mat, i_ba, i_nbpa) + {} +}; + +class TESt3AL2 : public TESt3 { + + private: + std::shared_ptr ImplsRes; //komora impulsowa + double TareM = 0.0; //masa proznego + double LoadM = 0.0; //i pelnego + double TareBP = 0.0; //cisnienie dla proznego + double LoadC = 0.0; + + public: + void Init(double PP, double HPP, double LPP, double BP, int BDF)/*override*/; + double GetPF(double PP, double dt, double Vel)/*override*/; //przeplyw miedzy komora wstepna i PG + void PLC(double mass); //wspolczynnik cisnienia przystawki wazacej + void SetLP(double TM, double LM, double TBP); //parametry przystawki wazacej + + inline TESt3AL2(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn, int i_BD, int i_mat, int i_ba, int i_nbpa) : + TESt3( i_mbp, i_bcr, i_bcd, i_brc, i_bcn, i_BD, i_mat, i_ba, i_nbpa) + { + ImplsRes = std::make_shared(); + } +}; + +class TESt4R : public TESt { + + private: + bool RapidStatus = false; + + protected: + std::shared_ptr ImplsRes; //komora impulsowa + double RapidTemp = 0.0; //aktualne, zmienne przelozenie + + public: + void Init(double PP, double HPP, double LPP, double BP, int BDF)/*override*/; + double GetPF(double PP, double dt, double Vel)/*override*/; //przeplyw miedzy komora wstepna i PG + + inline TESt4R(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn, int i_BD, int i_mat, int i_ba, int i_nbpa) : + TESt( i_mbp, i_bcr, i_bcd, i_brc, i_bcn, i_BD, i_mat, i_ba, i_nbpa) + { + ImplsRes = std::make_shared(); + } +}; + +class TLSt : public TESt4R { -{ private: // double CylFlowSpeed[2][2]; // zmienna nie używana protected: - double LBP; // cisnienie hamulca pomocniczego - double RM; // przelozenie rapida - double EDFlag; // luzowanie hamulca z powodu zalaczonego ED + double LBP = 0.0; //cisnienie hamulca pomocniczego + double RM = 0.0; //przelozenie rapida + double EDFlag = 0.0; //luzowanie hamulca z powodu zalaczonego ED public: - void Init(double PP, double HPP, double LPP, double BP, int BDF) /*override*/; - void SetLBP(double P); // cisnienie z hamulca pomocniczego - void SetRM(double RMR); // ustalenie przelozenia rapida - double GetPF(double PP, double dt, - double Vel) /*override*/; // przeplyw miedzy komora wstepna i PG - double GetHPFlow(double HP, double dt) /*override*/; // przeplyw - 8 bar - virtual double - GetEDBCP(); // cisnienie tylko z hamulca zasadniczego, uzywane do hamulca ED w EP09 - virtual void SetED(double EDstate); // stan hamulca ED do luzowania + void Init(double PP, double HPP, double LPP, double BP, int BDF)/*override*/; + void SetLBP(double P); //cisnienie z hamulca pomocniczego + void SetRM(double RMR); //ustalenie przelozenia rapida + double GetPF(double PP, double dt, double Vel)/*override*/; //przeplyw miedzy komora wstepna i PG + double GetHPFlow(double HP, double dt)/*override*/; //przeplyw - 8 bar + virtual double GetEDBCP(); //cisnienie tylko z hamulca zasadniczego, uzywane do hamulca ED w EP09 + virtual void SetED(double EDstate); //stan hamulca ED do luzowania - inline TLSt(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn, int i_BD, - int i_mat, int i_ba, int i_nbpa) - : TESt4R(i_mbp, i_bcr, i_bcd, i_brc, i_bcn, i_BD, i_mat, i_ba, i_nbpa) + inline TLSt(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn, int i_BD, int i_mat, int i_ba, int i_nbpa) : + TESt4R( i_mbp, i_bcr, i_bcd, i_brc, i_bcn, i_BD, i_mat, i_ba, i_nbpa) + {} +}; + +class TEStED : public TLSt { //zawor z EP09 - Est4 z oddzielnym przekladnikiem, kontrola rapidu i takie tam + + private: + std::shared_ptr Miedzypoj; //pojemnosc posrednia (urojona) do napelniania ZP i ZS + double Nozzles[ 11 ]; //dysze + bool Zamykajacy = false; //pamiec zaworka zamykajacego + bool Przys_blok = false; //blokada przyspieszacza + double TareM = 0.0; //masa proznego + double LoadM = 0.0; //i pelnego + double TareBP = 0.0; //cisnienie dla proznego + double LoadC = 0.0; + + + public: + void Init(double PP, double HPP, double LPP, double BP, int BDF)/*override*/; + double GetPF(double PP, double dt, double Vel)/*override*/; //przeplyw miedzy komora wstepna i PG + double GetEDBCP()/*override*/; //cisnienie tylko z hamulca zasadniczego, uzywane do hamulca ED + void PLC(double mass); //wspolczynnik cisnienia przystawki wazacej + void SetLP(double TM, double LM, double TBP); //parametry przystawki wazacej + + inline TEStED(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn, int i_BD, int i_mat, int i_ba, int i_nbpa) : + TLSt( i_mbp, i_bcr, i_bcd, i_brc, i_bcn, i_BD, i_mat, i_ba, i_nbpa) { + Miedzypoj = std::make_shared(); } }; -class TEStED - : public TLSt // zawor z EP09 - Est4 z oddzielnym przekladnikiem, kontrola rapidu i takie tam +class TEStEP2 : public TLSt { -{ private: - double Nozzles[11]; // dysze - bool Zamykajacy; // pamiec zaworka zamykajacego - bool Przys_blok; // blokada przyspieszacza - TReservoir *Miedzypoj; // pojemnosc posrednia (urojona) do napelniania ZP i ZS - double TareM; - double LoadM; // masa proznego i pelnego - double TareBP; // cisnienie dla proznego - double LoadC; + double TareM = 0.0; //masa proznego + double LoadM = 0.0; //masa pelnego + double TareBP = 0.0; //cisnienie dla proznego + double LoadC = 0.0; + double EPS = 0.0; + public: - void Init(double PP, double HPP, double LPP, double BP, int BDF) /*override*/; - double GetPF(double PP, double dt, - double Vel) /*override*/; // przeplyw miedzy komora wstepna i PG - double GetEDBCP() /*override*/; // cisnienie tylko z hamulca zasadniczego, uzywane do hamulca ED - void PLC(double mass); // wspolczynnik cisnienia przystawki wazacej - void SetLP(double TM, double LM, double TBP); // parametry przystawki wazacej + void Init(double PP, double HPP, double LPP, double BP, int BDF)/*override*/; //inicjalizacja + double GetPF(double PP, double dt, double Vel)/*override*/; //przeplyw miedzy komora wstepna i PG + void PLC(double mass); //wspolczynnik cisnienia przystawki wazacej + void SetEPS(double nEPS)/*override*/; //stan hamulca EP + void SetLP(double TM, double LM, double TBP); //parametry przystawki wazacej - inline TEStED(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn, int i_BD, - int i_mat, int i_ba, int i_nbpa) - : TLSt(i_mbp, i_bcr, i_bcd, i_brc, i_bcn, i_BD, i_mat, i_ba, i_nbpa) - { - Przys_blok = false; - TareM = 0, TareBP = 0, LoadM = 0, LoadC = 0.0; - Miedzypoj = new TReservoir(); - } + inline TEStEP2(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn, int i_BD, int i_mat, int i_ba, int i_nbpa) : + TLSt( i_mbp, i_bcr, i_bcd, i_brc, i_bcn, i_BD, i_mat, i_ba, i_nbpa) + {} }; -class TEStEP2 : public TLSt +class TCV1 : public TBrake { -{ private: - double TareM; - double LoadM; // masa proznego i pelnego - double TareBP; // cisnienie dla proznego - double LoadC; - double EPS; - - public: - void Init(double PP, double HPP, double LPP, double BP, int BDF) /*override*/; // inicjalizacja - double GetPF(double PP, double dt, - double Vel) /*override*/; // przeplyw miedzy komora wstepna i PG - void PLC(double mass); // wspolczynnik cisnienia przystawki wazacej - void SetEPS(double nEPS) /*override*/; // stan hamulca EP - void SetLP(double TM, double LM, double TBP); // parametry przystawki wazacej - - inline TEStEP2(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn, int i_BD, - int i_mat, int i_ba, int i_nbpa) - : TLSt(i_mbp, i_bcr, i_bcd, i_brc, i_bcn, i_BD, i_mat, i_ba, i_nbpa) - { - TareM = 0, TareBP = 0, LoadM = 0, LoadC = 0, EPS = 0.0; - } -}; - -class TCV1 : public TBrake - -{ - private: - double BVM; // przelozenie PG-CH + double BVM = 0.0; //przelozenie PG-CH protected: - TReservoir *CntrlRes; // zbiornik sterujący + std::shared_ptr CntrlRes; // zbiornik sterujący public: - void Init(double PP, double HPP, double LPP, double BP, int BDF) /*override*/; - double GetPF(double PP, double dt, - double Vel) /*override*/; // przeplyw miedzy komora wstepna i PG - double GetCRP() /*override*/; - void CheckState(double BCP, double &dV1); + void Init(double PP, double HPP, double LPP, double BP, int BDF)/*override*/; + double GetPF(double PP, double dt, double Vel)/*override*/; //przeplyw miedzy komora wstepna i PG + double GetCRP()/*override*/; + void CheckState(double BCP, double & dV1); double CVs(double BP); double BVs(double BCP); - inline TCV1(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn, int i_BD, - int i_mat, int i_ba, int i_nbpa) - : TBrake(i_mbp, i_bcr, i_bcd, i_brc, i_bcn, i_BD, i_mat, i_ba, i_nbpa) + inline TCV1(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn, int i_BD, int i_mat, int i_ba, int i_nbpa) : + TBrake( i_mbp, i_bcr, i_bcd, i_brc, i_bcn, i_BD, i_mat, i_ba, i_nbpa) { - CntrlRes = new TReservoir(); + CntrlRes = std::make_shared(); } }; -// class TCV1R : public TCV1 + //class TCV1R : public TCV1 //{ -// private: + //private: // TReservoir *ImplsRes; //komora impulsowa // bool RapidStatus; -// public: -// // function GetPF(PP, dt, Vel: real): real; override; //przeplyw miedzy komora -// wstepna i PG + //public: + // // function GetPF(PP, dt, Vel: real): real; override; //przeplyw miedzy komora wstepna i PG // // procedure Init(PP, HPP, LPP, BP: real; BDF: int); override; // inline TCV1R(double i_mbp, double i_bcr, double i_bcd, double i_brc, // int i_bcn, int i_BD, int i_mat, int i_ba, int i_nbpa, -// double PP, double HPP, double LPP, double BP, int BDF) : TCV1(i_mbp, i_bcr, i_bcd, -// i_brc, i_bcn + // double PP, double HPP, double LPP, double BP, int BDF) : TCV1(i_mbp, i_bcr, i_bcd, i_brc, i_bcn // , i_BD, i_mat, i_ba, i_nbpa, PP, HPP, LPP, BP, BDF) { } //}; -class TCV1L_TR : public TCV1 +class TCV1L_TR : public TCV1 { -{ private: - TReservoir *ImplsRes; // komora impulsowa - double LBP; // cisnienie hamulca pomocniczego + std::shared_ptr ImplsRes; //komora impulsowa + double LBP = 0.0; //cisnienie hamulca pomocniczego public: - void Init(double PP, double HPP, double LPP, double BP, int BDF) /*override*/; - double GetPF(double PP, double dt, - double Vel) /*override*/; // przeplyw miedzy komora wstepna i PG - void SetLBP(double P); // cisnienie z hamulca pomocniczego - double GetHPFlow(double HP, double dt) /*override*/; // przeplyw - 8 bar + void Init(double PP, double HPP, double LPP, double BP, int BDF)/*override*/; + double GetPF(double PP, double dt, double Vel)/*override*/; //przeplyw miedzy komora wstepna i PG + void SetLBP(double P); //cisnienie z hamulca pomocniczego + double GetHPFlow(double HP, double dt)/*override*/; //przeplyw - 8 bar - inline TCV1L_TR(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn, int i_BD, - int i_mat, int i_ba, int i_nbpa) - : TCV1(i_mbp, i_bcr, i_bcd, i_brc, i_bcn, i_BD, i_mat, i_ba, i_nbpa) + inline TCV1L_TR(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn, int i_BD, int i_mat, int i_ba, int i_nbpa) : + TCV1( i_mbp, i_bcr, i_bcd, i_brc, i_bcn, i_BD, i_mat, i_ba, i_nbpa) { - LBP = 0.0; - ImplsRes = new TReservoir(); + ImplsRes = std::make_shared(); } }; -class TKE : public TBrake // Knorr Einheitsbauart — jeden do wszystkiego +class TKE : public TBrake { //Knorr Einheitsbauart — jeden do wszystkiego -{ private: - bool RapidStatus; - TReservoir *ImplsRes; // komora impulsowa - TReservoir *CntrlRes; // zbiornik sterujący - TReservoir *Brak2Res; // zbiornik pomocniczy 2 - double BVM; // przelozenie PG-CH - double TareM; - double LoadM; // masa proznego i pelnego - double TareBP; // cisnienie dla proznego - double LoadC; // wspolczynnik zaladowania - double RM; // przelozenie rapida - double LBP; // cisnienie hamulca pomocniczego + std::shared_ptr ImplsRes; //komora impulsowa + std::shared_ptr CntrlRes; // zbiornik sterujący + std::shared_ptr Brak2Res; //zbiornik pomocniczy 2 + bool RapidStatus = false; + double BVM = 0.0; //przelozenie PG-CH + double TareM = 0.0; //masa proznego + double LoadM = 0.0; //masa pelnego + double TareBP = 0.0; //cisnienie dla proznego + double LoadC = 0.0; //wspolczynnik zaladowania + double RM = 0.0; //przelozenie rapida + double LBP = 0.0; //cisnienie hamulca pomocniczego public: - void Init(double PP, double HPP, double LPP, double BP, int BDF) /*override*/; - void SetRM(double RMR); // ustalenie przelozenia rapida - double GetPF(double PP, double dt, - double Vel) /*override*/; // przeplyw miedzy komora wstepna i PG - double GetHPFlow(double HP, double dt) /*override*/; // przeplyw - 8 bar - double GetCRP() /*override*/; - void CheckState(double BCP, double &dV1); - void CheckReleaser(double dt); // odluzniacz - double CVs(double BP); // napelniacz sterujacego - double BVs(double BCP); // napelniacz pomocniczego - void PLC(double mass); // wspolczynnik cisnienia przystawki wazacej - void SetLP(double TM, double LM, double TBP); // parametry przystawki wazacej - void SetLBP(double P); // cisnienie z hamulca pomocniczego + void Init(double PP, double HPP, double LPP, double BP, int BDF)/*override*/; + void SetRM(double RMR); //ustalenie przelozenia rapida + double GetPF(double PP, double dt, double Vel)/*override*/; //przeplyw miedzy komora wstepna i PG + double GetHPFlow(double HP, double dt)/*override*/; //przeplyw - 8 bar + double GetCRP()/*override*/; + void CheckState(double BCP, double & dV1); + void CheckReleaser(double dt); //odluzniacz + double CVs(double BP); //napelniacz sterujacego + double BVs(double BCP); //napelniacz pomocniczego + void PLC(double mass); //wspolczynnik cisnienia przystawki wazacej + void SetLP(double TM, double LM, double TBP); //parametry przystawki wazacej + void SetLBP(double P); //cisnienie z hamulca pomocniczego - inline TKE(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn, int i_BD, - int i_mat, int i_ba, int i_nbpa) - : TBrake(i_mbp, i_bcr, i_bcd, i_brc, i_bcn, i_BD, i_mat, i_ba, i_nbpa) + inline TKE(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn, int i_BD, int i_mat, int i_ba, int i_nbpa) : + TBrake( i_mbp, i_bcr, i_bcd, i_brc, i_bcn, i_BD, i_mat, i_ba, i_nbpa) { - RapidStatus = false; - TareM = 0, TareBP = 0, LoadM = 0, LoadC = 0, RM = 0, LBP = 0.0; - ImplsRes = new TReservoir(); - CntrlRes = new TReservoir(); - Brak2Res = new TReservoir(); + ImplsRes = std::make_shared(); + CntrlRes = std::make_shared(); + Brak2Res = std::make_shared(); } }; -// klasa obejmujaca krany +//klasa obejmujaca krany +class TDriverHandle { -class TDriverHandle -{ private: // BCP: integer; public: - bool Time; - bool TimeEP; - double Sounds[5]; // wielkosci przeplywow dla dzwiekow + bool Time = false; + bool TimeEP = false; + double Sounds[ 5 ]; //wielkosci przeplywow dla dzwiekow + virtual double GetPF(double i_bcp, double PP, double HP, double dt, double ep); virtual void Init(double Press); virtual double GetCP(); @@ -571,85 +512,80 @@ class TDriverHandle virtual double GetEP(double pos); }; -class TFV4a : public TDriverHandle +class TFV4a : public TDriverHandle { -{ private: - double CP; - double TP; - double RP; // zbiornik sterujący, czasowy, redukcyjny + double CP = 0.0; //zbiornik sterujący + double TP = 0.0; //zbiornik czasowy + double RP = 0.0; //zbiornik redukcyjny public: - double GetPF(double i_bcp, double PP, double HP, double dt, double ep) /*override*/; - void Init(double Press) /*override*/; + double GetPF(double i_bcp, double PP, double HP, double dt, double ep)/*override*/; + void Init(double Press)/*override*/; - inline TFV4a(void) : TDriverHandle() - { - } + inline TFV4a() : + TDriverHandle() + {} }; -class TFV4aM : public TDriverHandle +class TFV4aM : public TDriverHandle { -{ private: - double CP; - double TP; - double RP; // zbiornik sterujący, czasowy, redukcyjny - double XP; // komora powietrzna w reduktorze — jest potrzebna do odwzorowania fali - double RedAdj; // dostosowanie reduktora cisnienia (krecenie kapturkiem) + double CP = 0.0; //zbiornik sterujący + double TP = 0.0; //zbiornik czasowy + double RP = 0.0; //zbiornik redukcyjny + double XP = 0.0; //komora powietrzna w reduktorze — jest potrzebna do odwzorowania fali + double RedAdj = 0.0; //dostosowanie reduktora cisnienia (krecenie kapturkiem) // Sounds: array[0..4] of real; //wielkosci przeplywow dla dzwiekow - bool Fala; - // double pos_table[]; - // double *pos_table; // = { -2, 6, -1, 0, -2, 1, 4, 6, 0, 0, 0 }; - static double pos_table[11]; + bool Fala = false; + static double const pos_table[11]; // = { -2, 6, -1, 0, -2, 1, 4, 6, 0, 0, 0 }; + double LPP_RP(double pos); bool EQ(double pos, double i_pos); public: - double GetPF(double i_bcp, double PP, double HP, double dt, double ep) /*override*/; - void Init(double Press) /*override*/; - void SetReductor(double nAdj) /*override*/; - double GetSound(int i) /*override*/; - double GetPos(int i) /*override*/; + double GetPF(double i_bcp, double PP, double HP, double dt, double ep)/*override*/; + void Init(double Press)/*override*/; + void SetReductor(double nAdj)/*override*/; + double GetSound(int i)/*override*/; + double GetPos(int i)/*override*/; - inline TFV4aM(void) : TDriverHandle() - { - } + inline TFV4aM() : + TDriverHandle() + {} }; -class TMHZ_EN57 : public TDriverHandle +class TMHZ_EN57 : public TDriverHandle { -{ private: - double CP; - double TP; - double RP; // zbiornik sterujący, czasowy, redukcyjny - double RedAdj; // dostosowanie reduktora cisnienia (krecenie kapturkiem) - bool Fala; - // const double pos_table[11] = { -2, 10, -1, 0, 0, 2, 9, 10, 0, 0, 0 }; - static double pos_table[11]; //= { 0, 12, 1, 2, 2, 4, 11, 12, 2, 2, 2 }; + double CP = 0.0; //zbiornik sterujący + double TP = 0.0; //zbiornik czasowy + double RP = 0.0; //zbiornik redukcyjny + double RedAdj = 0.0; //dostosowanie reduktora cisnienia (krecenie kapturkiem) + bool Fala = false; + static double const pos_table[11]; //= { -2, 10, -1, 0, 0, 2, 9, 10, 0, 0, 0 }; + double LPP_RP(double pos); bool EQ(double pos, double i_pos); public: - double GetPF(double i_bcp, double PP, double HP, double dt, double ep) /*override*/; - void Init(double Press) /*override*/; - void SetReductor(double nAdj) /*override*/; - double GetSound(int i) /*override*/; - double GetPos(int i) /*override*/; - double GetCP() /*override*/; + double GetPF(double i_bcp, double PP, double HP, double dt, double ep)/*override*/; + void Init(double Press)/*override*/; + void SetReductor(double nAdj)/*override*/; + double GetSound(int i)/*override*/; + double GetPos(int i)/*override*/; + double GetCP()/*override*/; double GetEP(double pos); - inline TMHZ_EN57(void) : TDriverHandle() - { - } + inline TMHZ_EN57(void) : + TDriverHandle() + {} }; /* FBS2= class(TTDriverHandle) private - CP, TP, RP: real; //zbiornik sterujący, czasowy, redukcyjny - XP: real; //komora powietrzna w reduktorze — jest potrzebna do -odwzorowania fali + CP, TP, RP: real; //zbiornik sterujący, czasowy, redukcyjny + XP: real; //komora powietrzna w reduktorze — jest potrzebna do odwzorowania fali RedAdj: real; //dostosowanie reduktora cisnienia (krecenie kapturkiem) // Sounds: array[0..4] of real; //wielkosci przeplywow dla dzwiekow Fala: boolean; @@ -663,9 +599,8 @@ odwzorowania fali /* TD2= class(TTDriverHandle) private - CP, TP, RP: real; //zbiornik sterujący, czasowy, redukcyjny - XP: real; //komora powietrzna w reduktorze — jest potrzebna do -odwzorowania fali + CP, TP, RP: real; //zbiornik sterujący, czasowy, redukcyjny + XP: real; //komora powietrzna w reduktorze — jest potrzebna do odwzorowania fali RedAdj: real; //dostosowanie reduktora cisnienia (krecenie kapturkiem) // Sounds: array[0..4] of real; //wielkosci przeplywow dla dzwiekow Fala: boolean; @@ -677,153 +612,138 @@ odwzorowania fali function GetPos(i: int): real; override; end;*/ -class TM394 : public TDriverHandle +class TM394 : public TDriverHandle { -{ private: - double CP; // zbiornik sterujący, czasowy, redukcyjny - double RedAdj; // dostosowanie reduktora cisnienia (krecenie kapturkiem) - // double const pos_table[11] = { -1, 5, -1, 0, 1, 2, 4, 5, 0, 0, 0 }; - static double pos_table[11]; // = { 0, 6, 0, 1, 2, 3, 5, 6, 1, 1, 1 }; + double CP = 0.0; //zbiornik sterujący, czasowy, redukcyjny + double RedAdj = 0.0; //dostosowanie reduktora cisnienia (krecenie kapturkiem) + static double const pos_table[11]; // = { -1, 5, -1, 0, 1, 2, 4, 5, 0, 0, 0 }; public: - double GetPF(double i_bcp, double PP, double HP, double dt, double ep) /*override*/; - void Init(double Press) /*override*/; - void SetReductor(double nAdj) /*override*/; - double GetCP() /*override*/; - double GetPos(int i) /*override*/; + double GetPF(double i_bcp, double PP, double HP, double dt, double ep)/*override*/; + void Init(double Press)/*override*/; + void SetReductor(double nAdj)/*override*/; + double GetCP()/*override*/; + double GetPos(int i)/*override*/; - inline TM394(void) : TDriverHandle() - { - } + inline TM394(void) : + TDriverHandle() + {} }; -class TH14K1 : public TDriverHandle +class TH14K1 : public TDriverHandle { -{ private: - double static BPT_K[/*?*/ /*-1..4*/ (4) - (-1) + 1][2]; - // double const table[11] = { -1, 4, -1, 0, 1, 2, 3, 4, 0, 0, 0 }; - double static pos_table[11]; // = { 0, 5, 0, 1, 2, 3, 4, 5, 1, 1, 1 }; + static double const BPT_K[/*?*/ /*-1..4*/ (4) - (-1) + 1][2]; + static double const pos_table[11]; // = {-1, 4, -1, 0, 1, 2, 3, 4, 0, 0, 0}; + protected: - double CP; // zbiornik sterujący, czasowy, redukcyjny - double RedAdj; // dostosowanie reduktora cisnienia (krecenie kapturkiem) + double CP = 0.0; //zbiornik sterujący, czasowy, redukcyjny + double RedAdj = 0.0; //dostosowanie reduktora cisnienia (krecenie kapturkiem) public: - double GetPF(double i_bcp, double PP, double HP, double dt, double ep) /*override*/; - void Init(double Press) /*override*/; - void SetReductor(double nAdj) /*override*/; - double GetCP() /*override*/; - double GetPos(int i) /*override*/; + double GetPF(double i_bcp, double PP, double HP, double dt, double ep)/*override*/; + void Init(double Press)/*override*/; + void SetReductor(double nAdj)/*override*/; + double GetCP()/*override*/; + double GetPos(int i)/*override*/; - inline TH14K1(void) : TDriverHandle() - { - } + inline TH14K1(void) : + TDriverHandle() + {} }; -class TSt113 : public TH14K1 +class TSt113 : public TH14K1 { -{ private: - double EPS; - double static BPT_K[/*?*/ /*-1..4*/ (4) - (-1) + 1][2]; - double static BEP_K[/*?*/ /*-1..5*/ (5) - (-1) + 1]; - // double const pos_table[11] = { -1, 5, -1, 0, 2, 3, 4, 5, 0, 0, 1 }; - double static pos_table[11]; // = { 0, 6, 0, 1, 3, 4, 5, 6, 1, 1, 2 }; + double EPS = 0.0; + static double const BPT_K[/*?*/ /*-1..4*/ (4) - (-1) + 1][2]; + static double const BEP_K[/*?*/ /*-1..5*/ (5) - (-1) + 1]; + static double const pos_table[11]; // = {-1, 5, -1, 0, 2, 3, 4, 5, 0, 0, 1}; public: - double GetPF(double i_bcp, double PP, double HP, double dt, double ep) /*override*/; - double GetCP() /*override*/; - double GetPos(int i) /*override*/; - void Init(double Press) /*override*/; + double GetPF(double i_bcp, double PP, double HP, double dt, double ep)/*override*/; + double GetCP()/*override*/; + double GetPos(int i)/*override*/; + void Init(double Press)/*override*/; - inline TSt113(void) : TH14K1() - { - } + inline TSt113(void) : + TH14K1() + {} }; -class Ttest : public TDriverHandle +class Ttest : public TDriverHandle { -{ private: - double CP; + double CP = 0.0; public: - double GetPF(double i_bcp, double PP, double HP, double dt, double ep) /*override*/; - void Init(double Press) /*override*/; + double GetPF(double i_bcp, double PP, double HP, double dt, double ep)/*override*/; + void Init(double Press)/*override*/; - inline Ttest(void) : TDriverHandle() - { - } + inline Ttest(void) : + TDriverHandle() + {} }; -class TFD1 : public TDriverHandle +class TFD1 : public TDriverHandle { -{ private: - double MaxBP; // najwyzsze cisnienie - double BP; // aktualne cisnienie + double MaxBP = 0.0; //najwyzsze cisnienie + double BP = 0.0; //aktualne cisnienie public: - double Speed; // szybkosc dzialania - double GetPF(double i_bcp, double PP, double HP, double dt, double ep) /*override*/; - void Init(double Press) /*override*/; - double GetCP() /*override*/; + double Speed = 0.0; //szybkosc dzialania + + double GetPF(double i_bcp, double PP, double HP, double dt, double ep)/*override*/; + void Init(double Press)/*override*/; + double GetCP()/*override*/; void SetSpeed(double nSpeed); // procedure Init(press: real; MaxBP: real); overload; - inline TFD1(void) : TDriverHandle() - { - } + inline TFD1(void) : + TDriverHandle() + {} }; -class TH1405 : public TDriverHandle +class TH1405 : public TDriverHandle { -{ private: - double MaxBP; // najwyzsze cisnienie - double BP; // aktualne cisnienie + double MaxBP = 0.0; //najwyzsze cisnienie + double BP = 0.0; //aktualne cisnienie public: - double GetPF(double i_bcp, double PP, double HP, double dt, double ep) /*override*/; - void Init(double Press) /*override*/; - double GetCP() /*override*/; + double GetPF(double i_bcp, double PP, double HP, double dt, double ep)/*override*/; + void Init(double Press)/*override*/; + double GetCP()/*override*/; // procedure Init(press: real; MaxBP: real); overload; - inline TH1405(void) : TDriverHandle() - { - } + inline TH1405(void) : + TDriverHandle() + {} }; -class TFVel6 : public TDriverHandle +class TFVel6 : public TDriverHandle { -{ private: - double EPS; - // double const table[11] = { -1, 6, -1, 0, 6, 4, 4.7, 5, -1, 0, 1 }; - double static pos_table[11]; // = { -1, 6, -1, 0, 6, 4, 4.7, 5, -1, 0, 1 }; + double EPS = 0.0; + static double const pos_table[ 11 ]; // = {-1, 6, -1, 0, 6, 4, 4.7, 5, -1, 0, 1}; public: - double GetPF(double i_bcp, double PP, double HP, double dt, double ep) /*override*/; - double GetCP() /*override*/; - double GetPos(int i) /*override*/; - double GetSound(int i) /*override*/; - void Init(double Press) /*override*/; + double GetPF(double i_bcp, double PP, double HP, double dt, double ep)/*override*/; + double GetCP()/*override*/; + double GetPos(int i)/*override*/; + double GetSound(int i)/*override*/; + void Init(double Press)/*override*/; - inline TFVel6(void) : TDriverHandle() - { - } + inline TFVel6(void) : + TDriverHandle() + {} }; + extern double PF(double P1, double P2, double S, double DP = 0.25); extern double PF1(double P1, double P2, double S); -extern double PFVa(double PH, double PL, double S, double LIM, - double DP = 0.1); // zawor napelniajacy z PH do PL, PL do LIM -extern double PFVd(double PH, double PL, double S, double LIM, - double DP = 0.1); // zawor wypuszczajacy z PH do PL, PH do LIM - -#if !defined(NO_IMPLICIT_NAMESPACE_USE) -#endif -#endif // INCLUDED_HAMULCE_H -// END +extern double PFVa(double PH, double PL, double S, double LIM, double DP = 0.1); //zawor napelniajacy z PH do PL, PL do LIM +extern double PFVd(double PH, double PL, double S, double LIM, double DP = 0.1); //zawor wypuszczajacy z PH do PL, PH do LIM diff --git a/McZapkie/mctools.cpp b/McZapkie/mctools.cpp index 501875fc..ee5b3ba0 100644 --- a/McZapkie/mctools.cpp +++ b/McZapkie/mctools.cpp @@ -279,7 +279,7 @@ std::string Tab2Sp(std::string const &s) /*Tab to Space sign*/ { std::string s2 = ""; char tmp = (char)9; - for (int b = 0; b < s.length(); ++b) + for (std::size_t b = 0; b < s.length(); ++b) //{ // if (s[b] == tmp[0]) // s[b] = tmp[1]; @@ -294,20 +294,32 @@ std::string Tab2Sp(std::string const &s) /*Tab to Space sign*/ return s2; } -std::string ExchangeCharInString(std::string s, const char &aim, const char &target) +std::string ExchangeCharInString( std::string const &Source, char const &From, char const &To ) { - char *tmp = new char[s.length()]; - for (int b = 0; b < s.length(); ++b) - { - if (s[b] == aim) - if (target == (char)"") - b++; - else - tmp[b] = target; - else - tmp[b] = s[b]; + std::string replacement; replacement.reserve( Source.size() ); + std::for_each(Source.cbegin(), Source.cend(), [&](char const idx) { + if( idx != From ) { replacement += idx; } + else { + if( To != NULL ) { replacement += To; } } + } ); + + return replacement; +/* + int const length = Source.size(); + std::string replacement; replacement.reserve( length ); + for( int idx = 0; idx < length; ++idx ) { + if( Source[ idx ] != From ) { + replacement += Source[ idx ]; + } + else { + if( To != NULL ) { + replacement += To; + } + } } - return std::string(tmp); + + return replacement; +*/ } std::vector &Split(const std::string &s, char delim, std::vector &elems) @@ -387,29 +399,25 @@ std::string to_string(int _Val, int precision, int width) return o.str(); }; -std::string to_string(double _Val, int precision, int width) +std::string to_string(double const Value, int const Precision, int const Width) { - std::ostringstream o; - o.width(width); - o << std::fixed << std::setprecision(precision); - o << _Val; - return o.str(); + std::ostringstream converter; + converter << std::setw( Width ) << std::fixed << std::setprecision(Precision) << Value; + return converter.str(); }; -std::string to_hex_str(double _Val, int precision, int width) +std::string to_hex_str( int const Value, int const Width ) { - std::ostringstream o; - if (width) - o.width(width); - o << std::fixed << std::hex; - if (precision) - o << std::setprecision(precision); - o << _Val; - return o.str(); + std::ostringstream converter; + converter << "0x" << std::uppercase << std::setfill( '0' ) << std::setw( Width ) << std::hex << Value; + return converter.str(); }; int stol_def(const std::string &str, const int &DefaultValue) { + // NOTE: there's good chance this function is bugged, it produced wrong result on at least one occasion + // TODO: rewrite into something more reliable + // this function was developed iteratively on Codereview.stackexchange // with the assistance of @Corbin std::size_t len = str.size(); diff --git a/McZapkie/mctools.h b/McZapkie/mctools.h index 3ea1c3b2..9c0d5174 100644 --- a/McZapkie/mctools.h +++ b/McZapkie/mctools.h @@ -122,7 +122,7 @@ std::string DUE(std::string s); /*Delete Until Equal sign*/ std::string DWE(std::string s); /*Delete While Equal sign*/ std::string Ld2Sp(std::string const &s); /*Low dash to Space sign*/ std::string Tab2Sp(std::string const &s); /*Tab to Space sign*/ -std::string ExchangeCharInString(std::string s, const char &aim, const char &target); // zamienia jeden znak na drugi +std::string ExchangeCharInString(std::string const &s, const char &aim, const char &target); // zamienia jeden znak na drugi std::vector &Split(const std::string &s, char delim, std::vector &elems); std::vector Split(const std::string &s, char delim); std::vector Split(const std::string &s); @@ -134,7 +134,7 @@ std::string to_string(int _Val, int precision, int width); std::string to_string(double _Val); std::string to_string(double _Val, int precision); std::string to_string(double _Val, int precision, int width); -std::string to_hex_str(double _Val, int precision = 0, int width = 0); +std::string to_hex_str( int const _Val, int const width = 4 ); inline std::string to_string(bool _Val) { return _Val == true ? "true" : "false"; diff --git a/Model3d.cpp b/Model3d.cpp index e8390d38..a673d700 100644 --- a/Model3d.cpp +++ b/Model3d.cpp @@ -1844,7 +1844,11 @@ bool TModel3d::LoadFromFile(std::string const &FileName, bool dynamic) { Init(); // generowanie siatek i zapis E3D } } - return Root ? (iSubModelsCount > 0) : false; // brak pliku albo problem z wczytaniem + bool const result = Root ? (iSubModelsCount > 0) : false; // brak pliku albo problem z wczytaniem + if( false == result ) { + ErrorLog( "Failed to load 3d model \"" + FileName + "\"" ); + } + return result; }; void TModel3d::LoadFromBinFile(std::string const &FileName, bool dynamic) diff --git a/Names.cpp b/Names.cpp index b5eb2786..749cc70c 100644 --- a/Names.cpp +++ b/Names.cpp @@ -108,6 +108,11 @@ TNames::TNames() ZeroMemory(rTypes, 20 * sizeof(ItemRecord *)); }; +TNames::~TNames() { + + delete[] cBuffer; +} + int TNames::Add(int t, const char *n) { // dodanie obiektu typu (t) o nazwie (n) int len = strlen(n) + 1; // ze znacznikiem końca diff --git a/Names.h b/Names.h index 4eb91118..50b85da7 100644 --- a/Names.h +++ b/Names.h @@ -49,6 +49,7 @@ class TNames int iLast; // ostatnio użyty rekord public: TNames(); + ~TNames(); int Add(int t, const char *n); // dodanie obiektu typu (t) int Add(int t, const char *n, void *d); // dodanie obiektu z wskaźnikiem int Add(int t, const char *n, int d); // dodanie obiektu z numerem diff --git a/PyInt.cpp b/PyInt.cpp index 75b5c82c..c0aa2ddf 100644 --- a/PyInt.cpp +++ b/PyInt.cpp @@ -45,13 +45,19 @@ TPythonInterpreter *TPythonInterpreter::getInstance() return _instance; } -bool TPythonInterpreter::loadClassFile(const char *lookupPath, const char *className) +void +TPythonInterpreter::killInstance() { + + delete _instance; +} + +bool TPythonInterpreter::loadClassFile( std::string const &lookupPath, std::string const &className ) { - std::set::const_iterator it = _classes.find(className); + std::set::const_iterator it = _classes.find(className); if (it == _classes.end()) { FILE *sourceFile = _getFile(lookupPath, className); - if (sourceFile != NULL) + if (sourceFile != nullptr) { fseek(sourceFile, 0, SEEK_END); long fsize = ftell(sourceFile); @@ -72,10 +78,13 @@ bool TPythonInterpreter::loadClassFile(const char *lookupPath, const char *class handleError(); return false; } + _classes.insert( className ); +/* char *classNameToRemember = (char *)calloc(strlen(className) + 1, sizeof(char)); strcpy(classNameToRemember, className); _classes.insert(classNameToRemember); - free(buffer); +*/ + free(buffer); return true; } return false; @@ -83,13 +92,28 @@ bool TPythonInterpreter::loadClassFile(const char *lookupPath, const char *class return true; } -PyObject *TPythonInterpreter::newClass(const char *className) +PyObject *TPythonInterpreter::newClass( std::string const &className ) { return newClass(className, NULL); } -FILE *TPythonInterpreter::_getFile(const char *lookupPath, const char *className) +FILE *TPythonInterpreter::_getFile( std::string const &lookupPath, std::string const &className ) { + if( false == lookupPath.empty() ) { + std::string const sourcefilepath = lookupPath + className + ".py"; + FILE *file = fopen( sourcefilepath.c_str(), "r" ); +#ifdef _PY_INT_MORE_LOG + WriteLog( sourceFilePath ); +#endif // _PY_INT_MORE_LOG + if( nullptr != file ) { return file; } + } + std::string sourcefilepath = "python\\local\\" + className + ".py"; + FILE *file = fopen( sourcefilepath.c_str(), "r" ); +#ifdef _PY_INT_MORE_LOG + WriteLog( sourceFilePath ); +#endif // _PY_INT_MORE_LOG + return file; // either the file, or a nullptr on fail +/* char *sourceFilePath; if (lookupPath != NULL) { @@ -124,6 +148,7 @@ FILE *TPythonInterpreter::_getFile(const char *lookupPath, const char *className return file; } return NULL; +*/ } void TPythonInterpreter::handleError() @@ -177,14 +202,14 @@ void TPythonInterpreter::handleError() } } } -PyObject *TPythonInterpreter::newClass(const char *className, PyObject *argsTuple) +PyObject *TPythonInterpreter::newClass(std::string const &className, PyObject *argsTuple) { if (_main == NULL) { WriteLog("main turned into null"); return NULL; } - PyObject *classNameObj = PyObject_GetAttrString(_main, className); + PyObject *classNameObj = PyObject_GetAttrString(_main, className.c_str()); if (classNameObj == NULL) { #ifdef _PY_INT_MORE_LOG @@ -477,18 +502,12 @@ void TPythonScreens::update() void TPythonScreens::setLookupPath(std::string const &path) { - if (_lookupPath != NULL) - { - free(_lookupPath); - } - _lookupPath = (char *)calloc(path.length() + 1, sizeof(char)); - strcpy(_lookupPath, path.c_str()); + _lookupPath = path; } TPythonScreens::TPythonScreens() { - _lookupPath = NULL; - TPythonInterpreter::getInstance()->loadClassFile(NULL, "abstractscreenrenderer"); + TPythonInterpreter::getInstance()->loadClassFile("", "abstractscreenrenderer"); _terminationFlag = false; _renderReadyFlag = false; _cleanupReadyFlag = false; @@ -501,6 +520,7 @@ TPythonScreens::~TPythonScreens() WriteLog("Called python sceeens destructor"); #endif // _PY_INT_MORE_LOG reset(NULL); +/* if (_lookupPath != NULL) { #ifdef _PY_INT_MORE_LOG @@ -508,6 +528,7 @@ TPythonScreens::~TPythonScreens() #endif // _PY_INT_MORE_LOG free(_lookupPath); } +*/ } void TPythonScreens::run() @@ -551,7 +572,7 @@ void TPythonScreens::run() void TPythonScreens::finish() { - _thread == NULL; + _thread = NULL; } DWORD WINAPI ScreenRendererThread(LPVOID lpParam) diff --git a/PyInt.h b/PyInt.h index db9f372a..eb44a58a 100644 --- a/PyInt.h +++ b/PyInt.h @@ -30,22 +30,26 @@ class TPythonInterpreter { protected: TPythonInterpreter(); - ~TPythonInterpreter() - { - } + ~TPythonInterpreter() {} static TPythonInterpreter *_instance; int _screenRendererPriority; - std::set _classes; - PyObject *_main; +// std::set _classes; + std::set _classes; + PyObject *_main; PyObject *_stdErr; - FILE *_getFile(const char *lookupPath, const char *className); +// FILE *_getFile(const char *lookupPath, const char *className); + FILE *_getFile( std::string const &lookupPath, std::string const &className ); public: static TPythonInterpreter *getInstance(); - bool loadClassFile(const char *lookupPath, const char *className); + static void killInstance(); +/* bool loadClassFile(const char *lookupPath, const char *className); PyObject *newClass(const char *className); PyObject *newClass(const char *className, PyObject *argsTuple); - int getScreenRendererPriotity() +*/ bool loadClassFile( std::string const &lookupPath, std::string const &className ); + PyObject *newClass( std::string const &className ); + PyObject *newClass( std::string const &className, PyObject *argsTuple ); + int getScreenRendererPriotity() { return _screenRendererPriority; }; @@ -79,7 +83,7 @@ class TPythonScreens void *_thread; unsigned int _threadId; std::vector _screens; - char *_lookupPath; + std::string _lookupPath; void *_train; void _cleanup(); void _freeTrainState(); diff --git a/RealSound.cpp b/RealSound.cpp index 8878ac0c..cac192af 100644 --- a/RealSound.cpp +++ b/RealSound.cpp @@ -37,7 +37,7 @@ TRealSound::TRealSound() bLoopPlay = false; // dźwięk wyłączony } -TRealSound::TRealSound(const char *SoundName, double SoundAttenuation, double X, double Y, double Z, bool Dynamic, +TRealSound::TRealSound(std::string const &SoundName, double SoundAttenuation, double X, double Y, double Z, bool Dynamic, bool freqmod, double rmin) { Init(SoundName, SoundAttenuation, X, Y, Z, Dynamic, freqmod, rmin); @@ -250,7 +250,7 @@ void TRealSound::ResetPosition() pSound->SetCurrentPosition(0); } -TTextSound::TTextSound(const char *SoundName, double SoundAttenuation, double X, double Y, double Z, +TTextSound::TTextSound(std::string const &SoundName, double SoundAttenuation, double X, double Y, double Z, bool Dynamic, bool freqmod, double rmin) : TRealSound(SoundName, SoundAttenuation, X, Y, Z, Dynamic, freqmod, rmin) { diff --git a/RealSound.h b/RealSound.h index 9df5dfda..c2dab928 100644 --- a/RealSound.h +++ b/RealSound.h @@ -18,7 +18,7 @@ class TRealSound { protected: PSound pSound; - char *Nazwa; // dla celow odwszawiania +// char *Nazwa; // dla celow odwszawiania NOTE: currently not used anywhere double fDistance, fPreviousDistance; // dla liczenia Dopplera float fFrequency; // częstotliwość samplowania pliku int iDoppler; // Ra 2014-07: możliwość wyłączenia efektu Dopplera np. dla śpiewu ptaków @@ -31,7 +31,7 @@ class TRealSound double FA; // offset czestotliwosci bool bLoopPlay; // czy zapętlony dźwięk jest odtwarzany TRealSound(); - TRealSound(const char *SoundName, double SoundAttenuation, double X, double Y, double Z, bool Dynamic, + TRealSound( std::string const &SoundName, double SoundAttenuation, double X, double Y, double Z, bool Dynamic, bool freqmod = false, double rmin = 0.0); ~TRealSound(); void Free(); @@ -54,7 +54,7 @@ class TTextSound : public TRealSound std::string asText; float fTime; // czas trwania public: - TTextSound(const char *SoundName, double SoundAttenuation, double X, double Y, double Z, + TTextSound(std::string const &SoundName, double SoundAttenuation, double X, double Y, double Z, bool Dynamic, bool freqmod = false, double rmin = 0.0); void Init(std::string const &SoundName, double SoundAttenuation, double X, double Y, double Z, bool Dynamic, bool freqmod = false, double rmin = 0.0); diff --git a/Sound.cpp b/Sound.cpp index 3eced2f1..d19d678e 100644 --- a/Sound.cpp +++ b/Sound.cpp @@ -14,6 +14,7 @@ http://mozilla.org/MPL/2.0/. #include "Logs.h" #include "Usefull.h" #include "mczapkie/mctools.h" +#include "WavRead.h" //#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } } #define SAFE_RELEASE(p) \ { \ diff --git a/Sound.h b/Sound.h index 7eb6c589..e003ef8d 100644 --- a/Sound.h +++ b/Sound.h @@ -11,14 +11,7 @@ http://mozilla.org/MPL/2.0/. #define SoundH #include -#undef EOF -#include -//#include -//#include -#include #include -//#include "resource.h" -#include "WavRead.h" typedef LPDIRECTSOUNDBUFFER PSound; diff --git a/Track.cpp b/Track.cpp index 0ba37289..8cea4c82 100644 --- a/Track.cpp +++ b/Track.cpp @@ -59,30 +59,26 @@ TSwitchExtension::TSwitchExtension(TTrack *owner, int what) pOwner = NULL; pNextAnim = NULL; bMovement = false; // nie potrzeba przeliczać fOffset1 - Segments[0] = new TSegment(owner); // z punktu 1 do 2 - Segments[1] = new TSegment( - owner); // z punktu 3 do 4 (1=3 dla zwrotnic; odwrócony dla skrzyżowań, ewentualnie 1=4) + Segments[0] = std::make_shared(owner); // z punktu 1 do 2 + Segments[1] = std::make_shared(owner); // z punktu 3 do 4 (1=3 dla zwrotnic; odwrócony dla skrzyżowań, ewentualnie 1=4) Segments[2] = (what >= 3) ? - new TSegment(owner) : - NULL; // z punktu 2 do 4 skrzyżowanie od góry: wersja "-1": - Segments[3] = - (what >= 4) ? new TSegment(owner) : NULL; // z punktu 4 do 1 1 1=4 0 0=3 - Segments[4] = - (what >= 5) ? new TSegment(owner) : NULL; // z punktu 1 do 3 4 x 3 3 3 x 2 2 - Segments[5] = (what >= 6) ? new TSegment(owner) : - NULL; // z punktu 3 do 2 2 2 1 1 + std::make_shared(owner) : + nullptr; // z punktu 2 do 4 skrzyżowanie od góry: wersja "-1": + Segments[3] = (what >= 4) ? + std::make_shared(owner) : + nullptr; // z punktu 4 do 1 1 1=4 0 0=3 + Segments[4] = (what >= 5) ? + std::make_shared(owner) : + nullptr; // z punktu 1 do 3 4 x 3 3 3 x 2 2 + Segments[5] = (what >= 6) ? + std::make_shared(owner) : + nullptr; // z punktu 3 do 2 2 2 1 1 evPlus = evMinus = NULL; fVelocity = -1.0; // maksymalne ograniczenie prędkości (ustawianej eventem) vTrans = vector3(0, 0, 0); // docelowa translacja przesuwnicy } TSwitchExtension::~TSwitchExtension() { // nie ma nic do usuwania - // delete Segments[0]; - // delete Segments[1]; - delete Segments[2]; - delete Segments[3]; - delete Segments[4]; - delete Segments[5]; } TIsolated::TIsolated() @@ -121,7 +117,7 @@ TIsolated * TIsolated::Find(const string &n) return p; p = p->pNext; } - pRoot = new TIsolated(n, pRoot); + pRoot = new TIsolated(n, pRoot); // BUG: source of a memory leak return pRoot; }; @@ -211,7 +207,11 @@ TTrack::TTrack(TGroundNode *g) TTrack::~TTrack() { // likwidacja odcinka - if (eType == tt_Normal) + if( eType == tt_Cross ) { + delete SwitchExtension->vPoints; // skrzyżowanie może mieć punkty + } + +/* if (eType == tt_Normal) delete Segment; // dla zwrotnic nie usuwać tego (kopiowany) else { // usuwanie dodatkowych danych dla niezwykłych odcinków @@ -219,6 +219,7 @@ TTrack::~TTrack() delete SwitchExtension->vPoints; // skrzyżowanie może mieć punkty SafeDelete(SwitchExtension); } +*/ } void TTrack::Init() @@ -226,21 +227,21 @@ void TTrack::Init() switch (eType) { case tt_Switch: - SwitchExtension = new TSwitchExtension(this, 2); // na wprost i na bok + SwitchExtension = std::make_shared( this, 2 ); // na wprost i na bok break; case tt_Cross: // tylko dla skrzyżowania dróg - SwitchExtension = new TSwitchExtension(this, 6); // 6 połączeń + SwitchExtension = std::make_shared( this, 6 ); // 6 po³¹czeñ SwitchExtension->vPoints = NULL; // brak tablicy punktów SwitchExtension->iPoints = 0; SwitchExtension->bPoints = false; // tablica punktów nie wypełniona SwitchExtension->iRoads = 4; // domyślnie 4 break; case tt_Normal: - Segment = new TSegment(this); + Segment = std::make_shared( this ); break; case tt_Table: // oba potrzebne - SwitchExtension = new TSwitchExtension(this, 1); // kopia oryginalnego toru - Segment = new TSegment(this); + SwitchExtension = std::make_shared( this, 1 ); // kopia oryginalnego toru + Segment = make_shared(this); break; } } diff --git a/Track.h b/Track.h index fa313084..274f263c 100644 --- a/Track.h +++ b/Track.h @@ -48,13 +48,13 @@ class TSwitchExtension public: TSwitchExtension(TTrack *owner, int what); ~TSwitchExtension(); - TSegment *Segments[6]; // dwa tory od punktu 1, pozostałe dwa od 2? Ra 140101: 6 połączeń dla - // skrzyżowań - // TTrack *trNear[4]; //tory dołączone do punktów 1, 2, 3 i 4 - // dotychczasowe [2]+[2] wskaźniki zamienić na nowe [4] - TTrack *pNexts[2]; // tory dołączone do punktów 2 i 4 - TTrack *pPrevs[2]; // tory dołączone do punktów 1 i 3 - int iNextDirection[2]; // to też z [2]+[2] przerobić na [4] + std::shared_ptr Segments[6]; // dwa tory od punktu 1, pozosta³e dwa od 2? Ra 140101: 6 po³¹czeñ dla + // skrzy¿owañ + // TTrack *trNear[4]; //tory do³¹czone do punktów 1, 2, 3 i 4 + // dotychczasowe [2]+[2] wskaŸniki zamieniæ na nowe [4] + TTrack *pNexts[2]; // tory do³¹czone do punktów 2 i 4 + TTrack *pPrevs[2]; // tory do³¹czone do punktów 1 i 3 + int iNextDirection[2]; // to te¿ z [2]+[2] przerobiæ na [4] int iPrevDirection[2]; int CurrentIndex; // dla zwrotnicy double fOffset, fDesiredOffset; // aktualne i docelowe położenie napędu iglic @@ -126,8 +126,8 @@ class TIsolated class TTrack : public Resource { // trajektoria ruchu - opakowanie private: - TSwitchExtension *SwitchExtension; // dodatkowe dane do toru, który jest zwrotnicą - TSegment *Segment; + std::shared_ptr SwitchExtension; // dodatkowe dane do toru, który jest zwrotnicą + std::shared_ptr Segment; TTrack *trNext; // odcinek od strony punktu 2 - to powinno być w segmencie TTrack *trPrev; // odcinek od strony punktu 1 // McZapkie-070402: dodalem zmienne opisujace rozmiary tekstur @@ -204,7 +204,7 @@ class TTrack : public Resource { return Segment->GetLength(); }; - inline TSegment * CurrentSegment() + inline std::shared_ptr CurrentSegment() { return Segment; }; diff --git a/Train.cpp b/Train.cpp index d511f36f..54ae954b 100644 --- a/Train.cpp +++ b/Train.cpp @@ -11,18 +11,19 @@ http://mozilla.org/MPL/2.0/. Copyright (C) 2001-2004 Marcin Wozniak, Maciej Czapkiewicz and others */ + #include "stdafx.h" #include "Train.h" -#include "Console.h" -#include "Driver.h" #include "Globals.h" #include "Logs.h" -#include "McZapkie\MOVER.h" -#include "McZapkie\hamulce.h" #include "MdlMngr.h" #include "Timer.h" +#include "Driver.h" +#include "Console.h" +#include "McZapkie\hamulce.h" +#include "McZapkie\MOVER.h" //--------------------------------------------------------------------------- using namespace Timer; @@ -68,15 +69,27 @@ void TCab::Load(cParser &Parser) Parser >> token; if (token == "cablight") { - Parser.getTokens(9, false); - Parser >> dimm_r >> dimm_g >> dimm_b >> intlit_r >> intlit_g >> intlit_b >> intlitlow_r >> - intlitlow_g >> intlitlow_b; - Parser.getTokens(); - Parser >> token; + Parser.getTokens( 9, false ); + Parser + >> dimm_r + >> dimm_g + >> dimm_b + >> intlit_r + >> intlit_g + >> intlit_b + >> intlitlow_r + >> intlitlow_g + >> intlitlow_b; + Parser.getTokens(); Parser >> token; } - CabPos1.x = std::stod(token); - Parser.getTokens(5, false); - Parser >> CabPos1.y >> CabPos1.z >> CabPos2.x >> CabPos2.y >> CabPos2.z; + CabPos1.x = std::stod( token ); + Parser.getTokens( 5, false ); + Parser + >> CabPos1.y + >> CabPos1.z + >> CabPos2.x + >> CabPos2.y + >> CabPos2.z; bEnabled = true; bOccupied = true; @@ -216,9 +229,9 @@ bool TTrain::Init(TDynamicObject *NewDynamicObject, bool e3d) fMechPitch = 0.1; fMainRelayTimer = 0; // Hunter, do k...y nędzy, ustawiaj wartości początkowe zmiennych! - if (!LoadMMediaFile(DynamicObject->asBaseDir + DynamicObject->MoverParameters->TypeName + - ".mmd")) + if( false == LoadMMediaFile( DynamicObject->asBaseDir + DynamicObject->MoverParameters->TypeName + ".mmd" ) ) { return false; + } // McZapkie: w razie wykolejenia // dsbDerailment=TSoundsManager::GetFromName("derail.wav"); @@ -339,14 +352,13 @@ PyObject *TTrain::GetTrainState() PyGetFloatS(fPress[i][j])); } bool bEP, bPN; - bEP = (mvControlled->LocHandle->GetCP() > 0.2) || (fEIMParams[0][2] > 0.01); + bEP = ( mvControlled->LocHandle->GetCP() > 0.2 ) || ( fEIMParams[0][2] > 0.01 ); PyDict_SetItemString(dict, "dir_brake", PyGetBool(bEP)); if (typeid(mvControlled->Hamulec) == typeid(TLSt) || typeid(mvControlled->Hamulec) == typeid(TEStED)) { - TBrake *temp_ham = mvControlled->Hamulec; // TLSt* temp_ham2 = temp_ham; - bPN = (static_cast(temp_ham)->GetEDBCP() > 0.2); + bPN = ( static_cast( mvControlled->Hamulec.get() )->GetEDBCP() > 0.2 ); } else bPN = false; @@ -736,8 +748,7 @@ if ((mvControlled->PantFrontVolt) || (mvControlled->PantRearVolt) || else if (cKey == Global::Keys[k_OpenLeft]) // NBMX 17-09-2003: otwieranie drzwi { if (mvOccupied->DoorOpenCtrl == 1) - if (mvOccupied->CabNo < 0 ? mvOccupied->DoorRight(true) : - mvOccupied->DoorLeft(true)) + if (mvOccupied->CabNo < 0 ? mvOccupied->DoorRight(true) : mvOccupied->DoorLeft(true)) { dsbSwitch->SetVolume(DSBVOLUME_MAX); dsbSwitch->Play(0, 0, 0); @@ -750,9 +761,8 @@ if ((mvControlled->PantFrontVolt) || (mvControlled->PantRearVolt) || } else if (cKey == Global::Keys[k_OpenRight]) // NBMX 17-09-2003: otwieranie drzwi { - if (mvOccupied->DoorCloseCtrl == 1) - if (mvOccupied->CabNo < 0 ? mvOccupied->DoorLeft(true) : - mvOccupied->DoorRight(true)) + if (mvOccupied->DoorOpenCtrl == 1) + if (mvOccupied->CabNo < 0 ? mvOccupied->DoorLeft(true) : mvOccupied->DoorRight(true)) { dsbSwitch->SetVolume(DSBVOLUME_MAX); dsbSwitch->Play(0, 0, 0); @@ -898,7 +908,7 @@ if ((mvControlled->PantFrontVolt) || (mvControlled->PantRearVolt) || else if (cKey == Global::Keys[k_LeftSign]) // lewe swiatlo - włączenie // ABu 060205: dzielo Wingera po malutkim liftingu: { - if (!mvOccupied->LightsPosNo > 0) + if (false == (mvOccupied->LightsPosNo > 0)) { if ((GetAsyncKeyState(VK_CONTROL) < 0) && (ggRearLeftLightButton.SubModel)) // hunter-230112 - z controlem zapala z tylu @@ -1073,7 +1083,7 @@ if ((mvControlled->PantFrontVolt) || (mvControlled->PantRearVolt) || // tylne (koncowki) - // wlaczenie { - if (!mvOccupied->LightsPosNo > 0) + if (false == (mvOccupied->LightsPosNo > 0)) { if ((GetAsyncKeyState(VK_CONTROL) < 0) && (ggRearRightLightButton.SubModel)) // hunter-230112 - z controlem zapala z tylu @@ -1968,27 +1978,27 @@ if } else if (cKey == Global::Keys[k_CloseLeft]) // NBMX 17-09-2003: zamykanie drzwi { - if (mvOccupied->CabNo < 0 ? mvOccupied->DoorRight(false) : mvOccupied->DoorLeft(false)) - { - dsbSwitch->SetVolume(DSBVOLUME_MAX); - dsbSwitch->Play(0, 0, 0); - if (dsbDoorClose) - { - dsbDoorClose->SetCurrentPosition(0); - dsbDoorClose->Play(0, 0, 0); + if( mvOccupied->DoorCloseCtrl == 1 ) { + if( mvOccupied->CabNo < 0 ? mvOccupied->DoorRight( false ) : mvOccupied->DoorLeft( false ) ) { + dsbSwitch->SetVolume( DSBVOLUME_MAX ); + dsbSwitch->Play( 0, 0, 0 ); + if( dsbDoorClose ) { + dsbDoorClose->SetCurrentPosition( 0 ); + dsbDoorClose->Play( 0, 0, 0 ); + } } } } else if (cKey == Global::Keys[k_CloseRight]) // NBMX 17-09-2003: zamykanie drzwi { - if (mvOccupied->CabNo < 0 ? mvOccupied->DoorLeft(false) : mvOccupied->DoorRight(false)) - { - dsbSwitch->SetVolume(DSBVOLUME_MAX); - dsbSwitch->Play(0, 0, 0); - if (dsbDoorClose) - { - dsbDoorClose->SetCurrentPosition(0); - dsbDoorClose->Play(0, 0, 0); + if( mvOccupied->DoorCloseCtrl == 1 ) { + if( mvOccupied->CabNo < 0 ? mvOccupied->DoorLeft( false ) : mvOccupied->DoorRight( false ) ) { + dsbSwitch->SetVolume( DSBVOLUME_MAX ); + dsbSwitch->Play( 0, 0, 0 ); + if( dsbDoorClose ) { + dsbDoorClose->SetCurrentPosition( 0 ); + dsbDoorClose->Play( 0, 0, 0 ); + } } } } @@ -2105,7 +2115,7 @@ if else if (cKey == Global::Keys[k_LeftSign]) // ABu 060205: lewe swiatlo - // wylaczenie { - if (!mvOccupied->LightsPosNo > 0) + if (false == (mvOccupied->LightsPosNo > 0)) { if ((GetAsyncKeyState(VK_CONTROL) < 0) && (ggRearLeftLightButton.SubModel)) // hunter-230112 - z controlem gasi z tylu @@ -2278,7 +2288,7 @@ if if (cKey == Global::Keys[k_RightSign]) // Winger 070304: swiatla tylne // (koncowki) - wlaczenie { - if (!mvOccupied->LightsPosNo > 0) + if (false == (mvOccupied->LightsPosNo > 0)) { if ((GetAsyncKeyState(VK_CONTROL) < 0) && (ggRearRightLightButton.SubModel)) // hunter-230112 - z controlem gasi z tylu @@ -3220,7 +3230,7 @@ bool TTrain::Update() rsRunningNoise.AM = am; rsRunningNoise.AA = 0.7; rsRunningNoise.FA = fa; - rsRunningNoise.FM - fm; + rsRunningNoise.FM = fm; } mvOccupied->EventFlag = false; } @@ -5063,6 +5073,7 @@ bool TTrain::LoadMMediaFile(std::string const &asFileName) dsbCouplerDetach = TSoundsManager::GetFromName("couplerdetach.wav", true); dsbCouplerStretch = TSoundsManager::GetFromName("en57_couplerstretch.wav", true); dsbCouplerAttach = TSoundsManager::GetFromName("couplerattach.wav", true); + std::string token; do { diff --git a/TrkFoll.cpp b/TrkFoll.cpp index adbdd44a..4ed6a4dd 100644 --- a/TrkFoll.cpp +++ b/TrkFoll.cpp @@ -102,7 +102,7 @@ TTrack * TTrackFollower::SetCurrentTrack(TTrack *pTrack, int end) pCurrentTrack->AxleCounter(-1, Owner); // opuszczenie tamtego toru } pCurrentTrack = pTrack; - pCurrentSegment = (pCurrentTrack ? pCurrentTrack->CurrentSegment() : NULL); + pCurrentSegment = ( pCurrentTrack != nullptr ? pCurrentTrack->CurrentSegment() : nullptr ); if (!pCurrentTrack) Error(Owner->MoverParameters->Name + " at NULL track"); return pCurrentTrack; @@ -330,5 +330,3 @@ void TTrackFollower::Render(float fNr) } #endif //--------------------------------------------------------------------------- - -#pragma package(smart_init) diff --git a/TrkFoll.h b/TrkFoll.h index 4e3befa1..f84d5029 100644 --- a/TrkFoll.h +++ b/TrkFoll.h @@ -16,10 +16,10 @@ http://mozilla.org/MPL/2.0/. class TTrackFollower { // oś poruszająca się po torze private: - TTrack *pCurrentTrack; // na którym torze się znajduje - TSegment *pCurrentSegment; // zwrotnice mogą mieć dwa segmenty - double fCurrentDistance; // przesunięcie względem Point1 w stronę Point2 - double fDirection; // ustawienie względem toru: -1.0 albo 1.0, mnożone przez dystans + TTrack *pCurrentTrack; // na którym torze siê znajduje + std::shared_ptr pCurrentSegment; // zwrotnice mog¹ mieæ dwa segmenty + double fCurrentDistance; // przesuniêcie wzglêdem Point1 w stronê Point2 + double fDirection; // ustawienie wzglêdem toru: -1.0 albo 1.0, mno¿one przez dystans bool ComputatePosition(); // przeliczenie pozycji na torze TDynamicObject *Owner; // pojazd posiadający int iEventFlag; // McZapkie-020602: informacja o tym czy wyzwalac zdarzenie: 0,1,2,3 diff --git a/World.cpp b/World.cpp index e27d535e..8be33d74 100644 --- a/World.cpp +++ b/World.cpp @@ -35,7 +35,6 @@ http://mozilla.org/MPL/2.0/. #define TEXTURE_FILTER_CONTROL_EXT 0x8500 #define TEXTURE_LOD_BIAS_EXT 0x8501 //--------------------------------------------------------------------------- -#pragma package(smart_init) typedef void(APIENTRY *FglutBitmapCharacter)(void *font, int character); // typ funkcji FglutBitmapCharacter glutBitmapCharacterDLL = NULL; // deklaracja zmiennej diff --git a/maszyna.vcxproj.user b/maszyna.vcxproj.user deleted file mode 100644 index 7d88a6cb..00000000 --- a/maszyna.vcxproj.user +++ /dev/null @@ -1,13 +0,0 @@ - - - - T:\sources\Projects\maszyna\eu07++.exe - ..\..\Projects\maszyna - WindowsLocalDebugger - - - T:\sources\Projects\maszyna\eu07++.exe - ..\..\Projects\maszyna - WindowsLocalDebugger - - \ No newline at end of file diff --git a/mtable.cpp b/mtable.cpp index d64f8f18..ee540e84 100644 --- a/mtable.cpp +++ b/mtable.cpp @@ -15,7 +15,7 @@ http://mozilla.org/MPL/2.0/. #include "mtable.h" // using namespace Mtable; -TMTableTime *Mtable::GlobalTime; +std::shared_ptr Mtable::GlobalTime; double CompareTime(double t1h, double t1m, double t2h, double t2m) /*roznica czasu w minutach*/ // zwraca różnicę czasu @@ -529,19 +529,6 @@ void TMTableTime::UpdateMTableTime(double deltaT) GameTime = GameTime + deltaT; } -TMTableTime::TMTableTime(int InitH, int InitM, int InitSRH, int InitSRM, int InitSSH, int InitSSM) -{ - GameTime = 0.0; - dd = 0; - hh = InitH; - mm = InitM; - srh = InitSRH; - srm = InitSRM; - ssh = InitSSH; - ssm = InitSSM; - mr = 0.0; -} - bool TTrainParameters::DirectionChange() // sprawdzenie, czy po zatrzymaniu wykonać kolejne komendy { diff --git a/mtable.h b/mtable.h index 4aaed254..3bc10f3f 100644 --- a/mtable.h +++ b/mtable.h @@ -86,20 +86,29 @@ class TMTableTime { public: - double GameTime; - int dd; - int hh; - int mm; - int srh; - int srm; /*wschod slonca*/ - int ssh; - int ssm; /*zachod slonca*/ - double mr; + double GameTime = 0.0; + int dd = 0; + int hh = 0; + int mm = 0; + int srh = 0; + int srm = 0; /*wschod slonca*/ + int ssh = 0; + int ssm = 0; /*zachod slonca*/ + double mr = 0.0; void UpdateMTableTime(double deltaT); - TMTableTime(int InitH, int InitM, int InitSRH, int InitSRM, int InitSSH, int InitSSM); + TMTableTime(int InitH, int InitM, int InitSRH, int InitSRM, int InitSSH, int InitSSM) : + hh( InitH ), + mm( InitM ), + srh( InitSRH ), + srm( InitSRM ), + ssh( InitSSH ), + ssm( InitSSM ) + {} + + TMTableTime() = default; }; -extern TMTableTime *GlobalTime; +extern std::shared_ptr GlobalTime; } #if !defined(NO_IMPLICIT_NAMESPACE_USE) diff --git a/opengl/glew32.lib b/opengl/glew32.lib deleted file mode 100644 index 24793a72..00000000 Binary files a/opengl/glew32.lib and /dev/null differ diff --git a/opengl/glew32s.lib b/opengl/glew32s.lib deleted file mode 100644 index 18510029..00000000 Binary files a/opengl/glew32s.lib and /dev/null differ diff --git a/parser.cpp b/parser.cpp index 4d48193d..3eaa23a9 100644 --- a/parser.cpp +++ b/parser.cpp @@ -79,6 +79,10 @@ bool cParser::getTokens(int Count, bool ToLower, const char *Break) for (i = 0; i < Count; ++i) { std::string string = readToken(ToLower, Break); + if( true == string.empty() ) { + // no more tokens + break; + } // collect parameters if (i == 0) this->str(string); @@ -191,7 +195,7 @@ bool cParser::trimComments(std::string &String) return false; } -std::string cParser::readComment(const std::string Break) +std::string cParser::readComment(std::string const &Break) { // pobieranie znaków aż do znalezienia znacznika końca std::string token = ""; while (mStream->peek() != EOF) diff --git a/parser.h b/parser.h index 5cd57c30..8abe5da1 100644 --- a/parser.h +++ b/parser.h @@ -57,7 +57,7 @@ class cParser : public std::stringstream for (int i = 0; i < count; i++) readToken(); }; - inline bool expectToken(std::string value) + inline bool expectToken(std::string const &value) { return readToken() == value; }; @@ -77,7 +77,7 @@ class cParser : public std::stringstream protected: // methods: std::string readToken(bool ToLower = true, const char *Break = "\n\t ;"); - std::string readComment(const std::string Break = "\n\t ;"); + std::string readComment(std::string const &Break = "\n\t ;"); std::string trtest; bool trimComments(std::string &String); // members: diff --git a/stdafx.h b/stdafx.h index 09c36cfb..c822e7d0 100644 --- a/stdafx.h +++ b/stdafx.h @@ -10,6 +10,12 @@ #define _CRTDBG_MAP_ALLOC #include #include +#ifdef _DEBUG +#ifndef DBG_NEW +#define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ ) +#define new DBG_NEW +#endif +#endif // _DEBUG #endif // operating system #include "targetver.h" @@ -19,6 +25,7 @@ #undef NOMINMAX // stl #include +#include #define _USE_MATH_DEFINES #include #include diff --git a/wavread.h b/wavread.h index c2f3aa93..68ce040e 100644 --- a/wavread.h +++ b/wavread.h @@ -18,7 +18,6 @@ http://mozilla.org/MPL/2.0/. #ifndef WAVE_READ_H #define WAVE_READ_H -#include #include HRESULT WaveOpenFile(CHAR *strFileName, HMMIO *phmmioIn, WAVEFORMATEX **ppwfxInfo,