16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 17:29:18 +02:00

merged renderer unification branch

This commit is contained in:
tmj-fstate
2017-06-13 18:52:27 +02:00
10 changed files with 206 additions and 235 deletions

View File

@@ -469,9 +469,19 @@ void TController::TableTraceRoute(double fDistance, TDynamicObject *pVehicle)
} }
else { else {
if( iTableDirection == 0 ) { return; } if( iTableDirection == 0 ) { return; }
// NOTE: provisory fix for BUG: sempahor indices no longer matching table size
// TODO: find and really fix the reason it happens
if( ( SemNextIndex != -1 )
&& ( SemNextIndex >= sSpeedTable.size() ) ) {
SemNextIndex = -1;
}
if( ( SemNextStopIndex != -1 )
&& ( SemNextStopIndex >= sSpeedTable.size() ) ) {
SemNextStopIndex = -1;
}
// kontynuacja skanowania od ostatnio sprawdzonego toru (w ostatniej pozycji zawsze jest tor) // kontynuacja skanowania od ostatnio sprawdzonego toru (w ostatniej pozycji zawsze jest tor)
if( ( SemNextStopIndex != -1 ) if( ( SemNextStopIndex != -1 )
&& ( sSpeedTable[SemNextStopIndex].fVelNext < 1.0 ) ) { && ( sSpeedTable[SemNextStopIndex].fVelNext == 0.0 ) ) {
// znaleziono semafor lub tarczę lub tor z prędkością zero, trzeba sprawdzić czy to nadał semafor // znaleziono semafor lub tarczę lub tor z prędkością zero, trzeba sprawdzić czy to nadał semafor
// jeśli jest następny semafor to sprawdzamy czy to on nadał zero // jeśli jest następny semafor to sprawdzamy czy to on nadał zero
if( ( OrderCurrentGet() & Obey_train ) if( ( OrderCurrentGet() & Obey_train )
@@ -1335,7 +1345,6 @@ void TController::TablePurger()
// we can only update pointers safely after new table is finalized, so record their indices until then // we can only update pointers safely after new table is finalized, so record their indices until then
for( std::size_t idx = 0; idx < sSpeedTable.size() - 1; ++idx ) { for( std::size_t idx = 0; idx < sSpeedTable.size() - 1; ++idx ) {
// cache placement of semaphors in the new table, if we encounter them // cache placement of semaphors in the new table, if we encounter them
// NOTE: we rely on the semaphor actually getting added in the next step rather than skipped, but it's a pretty safe bet
if( idx == SemNextIndex ) { if( idx == SemNextIndex ) {
SemNextIndex = trimmedtable.size(); SemNextIndex = trimmedtable.size();
} }
@@ -1346,6 +1355,13 @@ void TController::TablePurger()
if( ( 0 == ( speedpoint.iFlags & spEnabled ) ) if( ( 0 == ( speedpoint.iFlags & spEnabled ) )
|| ( ( speedpoint.iFlags & ( spElapsed | spTrack | spCurve | spSwitch ) == ( spElapsed | spTrack | spCurve ) ) || ( ( speedpoint.iFlags & ( spElapsed | spTrack | spCurve | spSwitch ) == ( spElapsed | spTrack | spCurve ) )
&& ( speedpoint.fVelNext < 0.0 ) ) ) { && ( speedpoint.fVelNext < 0.0 ) ) ) {
// if the trimmed point happens to be currently active semaphor we need to invalidate their placements
if( idx == SemNextIndex ) {
SemNextIndex = -1;
}
if( idx == SemNextStopIndex ) {
SemNextStopIndex = -1;
}
continue; continue;
} }
// we're left with useful speed point record we should copy // we're left with useful speed point record we should copy
@@ -3365,8 +3381,8 @@ bool TController::UpdateSituation(double dt)
} }
ElapsedTime += dt; ElapsedTime += dt;
WaitingTime += dt; WaitingTime += dt;
fBrakeTime -= // wpisana wartość jest zmniejszana do 0, gdy ujemna należy zmienić nastawę hamulca
dt; // wpisana wartość jest zmniejszana do 0, gdy ujemna należy zmienić nastawę hamulca fBrakeTime -= dt;
fStopTime += dt; // zliczanie czasu postoju, nie ruszy dopóki ujemne fStopTime += dt; // zliczanie czasu postoju, nie ruszy dopóki ujemne
fActionTime += dt; // czas używany przy regulacji prędkości i zamykaniu drzwi fActionTime += dt; // czas używany przy regulacji prędkości i zamykaniu drzwi
if (WriteLogFlag) if (WriteLogFlag)
@@ -3384,7 +3400,7 @@ bool TController::UpdateSituation(double dt)
LastUpdatedTime = LastUpdatedTime + dt; LastUpdatedTime = LastUpdatedTime + dt;
} }
// Ra: skanowanie również dla prowadzonego ręcznie, aby podpowiedzieć prędkość // Ra: skanowanie również dla prowadzonego ręcznie, aby podpowiedzieć prędkość
if ((LastReactionTime > Min0R(ReactionTime, 2.0))) if ((LastReactionTime > std::min(ReactionTime, 2.0)))
{ {
// Ra: nie wiem czemu ReactionTime potrafi dostać 12 sekund, to jest przegięcie, bo przeżyna // Ra: nie wiem czemu ReactionTime potrafi dostać 12 sekund, to jest przegięcie, bo przeżyna
// STÓJ // STÓJ
@@ -3429,18 +3445,48 @@ bool TController::UpdateSituation(double dt)
if (AIControllFlag) if (AIControllFlag)
{ // tu bedzie logika sterowania { // tu bedzie logika sterowania
if (mvOccupied->CommandIn.Command != "") if (mvOccupied->CommandIn.Command != "")
if (!mvOccupied->RunInternalCommand()) // rozpoznaj komende bo lokomotywa jej nie if( !mvOccupied->RunInternalCommand() ) {
// rozpoznaje // rozpoznaj komende bo lokomotywa jej nie rozpoznaje
RecognizeCommand(); // samo czyta komendę wstawioną do pojazdu? RecognizeCommand(); // samo czyta komendę wstawioną do pojazdu?
if (mvOccupied->SecuritySystem.Status > 1) // jak zadziałało CA/SHP }
if (!mvOccupied->SecuritySystemReset()) // to skasuj if( mvOccupied->SecuritySystem.Status > 1 ) {
// if // jak zadziałało CA/SHP
// ((TestFlag(mvOccupied->SecuritySystem.Status,s_ebrake))&&(mvOccupied->BrakeCtrlPos==0)&&(AccDesired>0.0)) if( !mvOccupied->SecuritySystemReset() ) { // to skasuj
if ((TestFlag(mvOccupied->SecuritySystem.Status, s_SHPebrake) || if( ( mvOccupied->BrakeCtrlPos == 0 )
TestFlag(mvOccupied->SecuritySystem.Status, s_CAebrake)) && && ( AccDesired > 0.0 )
(mvOccupied->BrakeCtrlPos == 0) && (AccDesired > 0.0)) && ( ( TestFlag( mvOccupied->SecuritySystem.Status, s_SHPebrake ) )
mvOccupied->BrakeLevelSet( || ( TestFlag( mvOccupied->SecuritySystem.Status, s_CAebrake ) ) ) ) {
0); //!!! hm, może po prostu normalnie sterować hamulcem? //!!! hm, może po prostu normalnie sterować hamulcem?
mvOccupied->BrakeLevelSet( 0 );
}
}
}
// basic emergency stop handling, while at it
if( ( true == mvOccupied->EmergencyBrakeFlag ) // radio-stop
&& ( mvOccupied->Vel < 0.01 ) // and actual stop
&& ( true == mvOccupied->Radio ) ) { // and we didn't touch the radio yet
// turning off the radio should reset the flag, during security system check
if( m_radiocontroltime > 2.5 ) {
// arbitrary 2.5 sec delay between stop and disabling the radio
mvOccupied->Radio = false;
m_radiocontroltime = 0.0;
}
else {
m_radiocontroltime += LastReactionTime;
}
}
if( ( false == mvOccupied->Radio )
&& ( false == mvOccupied->EmergencyBrakeFlag ) ) {
// otherwise if it's safe to do so, turn the radio back on
if( m_radiocontroltime > 5.0 ) {
// arbitrary 5 sec delay before switching radio back on
mvOccupied->Radio = true;
m_radiocontroltime = 0.0;
}
else {
m_radiocontroltime += LastReactionTime;
}
}
} }
switch (OrderList[OrderPos]) switch (OrderList[OrderPos])
{ // ustalenie prędkości przy doczepianiu i odczepianiu, dystansów w pozostałych przypadkach { // ustalenie prędkości przy doczepianiu i odczepianiu, dystansów w pozostałych przypadkach

View File

@@ -201,8 +201,7 @@ class TController
public: public:
double fLastStopExpDist = -1.0; // odległość wygasania ostateniego przystanku double fLastStopExpDist = -1.0; // odległość wygasania ostateniego przystanku
double ReactionTime = 0.0; // czas reakcji Ra: czego i na co? świadomości AI double ReactionTime = 0.0; // czas reakcji Ra: czego i na co? świadomości AI
double fBrakeTime = 0.0; // wpisana wartość jest zmniejszana do 0, gdy ujemna należy zmienić nastawę double fBrakeTime = 0.0; // wpisana wartość jest zmniejszana do 0, gdy ujemna należy zmienić nastawę hamulca
// hamulca
private: private:
double fReady = 0.0; // poziom odhamowania wagonów double fReady = 0.0; // poziom odhamowania wagonów
bool Ready = false; // ABu: stan gotowosci do odjazdu - sprawdzenie odhamowania wagonow bool Ready = false; // ABu: stan gotowosci do odjazdu - sprawdzenie odhamowania wagonow
@@ -211,6 +210,7 @@ class TController
double deltalog = 0.05; // przyrost czasu double deltalog = 0.05; // przyrost czasu
double LastReactionTime = 0.0; double LastReactionTime = 0.0;
double fActionTime = 0.0; // czas używany przy regulacji prędkości i zamykaniu drzwi double fActionTime = 0.0; // czas używany przy regulacji prędkości i zamykaniu drzwi
double m_radiocontroltime{ 0.0 }; // timer used to control speed of radio operations
TAction eAction = actSleep; // aktualny stan TAction eAction = actSleep; // aktualny stan
bool HelpMeFlag = false; // wystawiane True jesli cos niedobrego sie dzieje bool HelpMeFlag = false; // wystawiane True jesli cos niedobrego sie dzieje
public: public:

View File

@@ -2472,10 +2472,15 @@ bool TDynamicObject::Update(double dt, double dt1)
} }
else { else {
if( MoverParameters->PantPress >= 4.6 ) { if( MoverParameters->PantPress >= 4.6 ) {
// prime the pressure switch // NOTE: we require active low power source to prime the pressure switch
MoverParameters->PantPressSwitchActive = true; // this is a work-around for potential isssues caused by the switch activating on otherwise idle vehicles, but should check whether it's accurate
// turn off the subsystems lock if( ( true == MoverParameters->Battery )
MoverParameters->PantPressLockActive = false; || ( true == MoverParameters->ConverterFlag ) ) {
// prime the pressure switch
MoverParameters->PantPressSwitchActive = true;
// turn off the subsystems lock
MoverParameters->PantPressLockActive = false;
}
if( MoverParameters->PantPress >= 4.8 ) { if( MoverParameters->PantPress >= 4.8 ) {
// Winger - automatyczne wylaczanie malej sprezarki // Winger - automatyczne wylaczanie malej sprezarki
@@ -5233,22 +5238,27 @@ TDynamicObject * TDynamicObject::ControlledFind()
// jeździć dobrze // jeździć dobrze
// również hamowanie wykonuje się zaworem w członie, a nie w silnikowym... // również hamowanie wykonuje się zaworem w członie, a nie w silnikowym...
TDynamicObject *d = this; // zaczynamy od aktualnego TDynamicObject *d = this; // zaczynamy od aktualnego
if (d->MoverParameters->TrainType & dt_EZT) // na razie dotyczy to EZT if( d->MoverParameters->TrainType & dt_EZT ) {
if (d->NextConnected ? d->MoverParameters->Couplers[1].AllowedFlag & ctrain_depot : false) // na razie dotyczy to EZT
{ // gdy jest człon od sprzęgu 1, a sprzęg łączony if( ( d->NextConnected != nullptr )
// warsztatowo (powiedzmy) && ( true == TestFlag( d->MoverParameters->Couplers[ 1 ].AllowedFlag, coupling::permanent ) ) ) {
if ((d->MoverParameters->Power < 1.0) && (d->NextConnected->MoverParameters->Power > // gdy jest człon od sprzęgu 1, a sprzęg łączony warsztatowo (powiedzmy)
1.0)) // my nie mamy mocy, ale ten drugi ma if( ( d->MoverParameters->Power < 1.0 )
&& ( d->NextConnected->MoverParameters->Power > 1.0 ) ) {
// my nie mamy mocy, ale ten drugi ma
d = d->NextConnected; // będziemy sterować tym z mocą d = d->NextConnected; // będziemy sterować tym z mocą
}
} }
else if (d->PrevConnected ? d->MoverParameters->Couplers[0].AllowedFlag & ctrain_depot : else if( ( d->PrevConnected != nullptr )
false) && ( true == TestFlag( d->MoverParameters->Couplers[ 0 ].AllowedFlag, coupling::permanent ) ) ) {
{ // gdy jest człon od sprzęgu 0, a sprzęg łączony // gdy jest człon od sprzęgu 0, a sprzęg łączony warsztatowo (powiedzmy)
// warsztatowo (powiedzmy) if( ( d->MoverParameters->Power < 1.0 )
if ((d->MoverParameters->Power < 1.0) && (d->PrevConnected->MoverParameters->Power > && ( d->PrevConnected->MoverParameters->Power > 1.0 ) ) {
1.0)) // my nie mamy mocy, ale ten drugi ma // my nie mamy mocy, ale ten drugi ma
d = d->PrevConnected; // będziemy sterować tym z mocą d = d->PrevConnected; // będziemy sterować tym z mocą
}
} }
}
return d; return d;
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@@ -610,14 +610,32 @@ void TEvent::Load(cParser *parser, vector3 *org)
} }
}; };
void TEvent::AddToQuery(TEvent *e) void TEvent::AddToQuery( TEvent *Event, TEvent *&Start ) {
{ // dodanie eventu do kolejki
if (evNext ? (e->fStartTime >= evNext->fStartTime) : false) TEvent *target( Start );
evNext->AddToQuery(e); // sortowanie wg czasu TEvent *previous( nullptr );
else while( ( Event->fStartTime >= target->fStartTime )
{ // dodanie z przodu && ( target->evNext != nullptr ) ) {
e->evNext = evNext; previous = target;
evNext = e; target = target->evNext;
}
// the new event will be either before or after the one we located
if( Event->fStartTime >= target->fStartTime ) {
assert( target->evNext == nullptr );
target->evNext = Event;
// if we have resurrected event land at the end of list, the link from previous run could potentially "add" unwanted events to the queue
Event->evNext = nullptr;
}
else {
if( previous != nullptr ) {
previous->evNext = Event;
Event->evNext = target;
}
else {
// special case, we're inserting our event before the provided start point
Event->evNext = Start;
Start = Event;
}
} }
} }

View File

@@ -105,7 +105,7 @@ class TEvent // zmienne: ev*
~TEvent(); ~TEvent();
void Init(); void Init();
void Load(cParser *parser, vector3 *org); void Load(cParser *parser, vector3 *org);
void AddToQuery(TEvent *e); static void AddToQuery( TEvent *Event, TEvent *&Start );
std::string CommandGet(); std::string CommandGet();
TCommandType Command(); TCommandType Command();
double ValueGet(int n); double ValueGet(int n);

View File

@@ -2840,17 +2840,6 @@ TTrack * TGround::FindTrack(vector3 Point, int &iConnection, TGroundNode *Exclud
if ((tmp = sr->FindTrack(&Point, iConnection, Exclude->pTrack)) != NULL) if ((tmp = sr->FindTrack(&Point, iConnection, Exclude->pTrack)) != NULL)
return tmp; return tmp;
} }
#if 0
//wyszukiwanie czołgowe (po wszystkich jak leci) - nie ma chyba sensu
for (Current=nRootOfType[TP_TRACK];Current;Current=Current->Next)
{
if ((Current->iType==TP_TRACK) && (Current!=Exclude))
{
iConnection=Current->pTrack->TestPoint(&Point);
if (iConnection>=0) return Current->pTrack;
}
}
#endif
return NULL; return NULL;
} }
@@ -2946,22 +2935,21 @@ TTraction * TGround::TractionNearestFind(glm::dvec3 &p, int dir, TGroundNode *n)
bool TGround::AddToQuery(TEvent *Event, TDynamicObject *Node) bool TGround::AddToQuery(TEvent *Event, TDynamicObject *Node)
{ {
if (Event->bEnabled) // jeśli może być dodany do kolejki (nie używany w skanowaniu) if( Event->bEnabled ) {
if (!Event->iQueued) // jeśli nie dodany jeszcze do kolejki // jeśli może być dodany do kolejki (nie używany w skanowaniu)
if( !Event->iQueued ) // jeśli nie dodany jeszcze do kolejki
{ // kolejka eventów jest posortowana względem (fStartTime) { // kolejka eventów jest posortowana względem (fStartTime)
Event->Activator = Node; Event->Activator = Node;
if (Event->Type == tp_AddValues ? (Event->fDelay == 0.0) : false) if( ( Event->Type == tp_AddValues )
{ // eventy AddValues trzeba wykonywać natychmiastowo, inaczej kolejka może zgubić && ( Event->fDelay == 0.0 ) ) {
// jakieś dodawanie // eventy AddValues trzeba wykonywać natychmiastowo, inaczej kolejka może zgubić jakieś dodawanie
// Ra: kopiowanie wykonania tu jest bez sensu, lepiej by było wydzielić funkcję // Ra: kopiowanie wykonania tu jest bez sensu, lepiej by było wydzielić funkcję
// wykonującą eventy i ją wywołać // wykonującą eventy i ją wywołać
if (EventConditon(Event)) if( EventConditon( Event ) ) { // teraz mogą być warunki do tych eventów
{ // teraz mogą być warunki do tych eventów Event->Params[ 5 ].asMemCell->UpdateValues(
Event->Params[5].asMemCell->UpdateValues( Event->Params[ 0 ].asText, Event->Params[ 1 ].asdouble,
Event->Params[0].asText, Event->Params[1].asdouble, Event->Params[ 2 ].asdouble, Event->iFlags );
Event->Params[2].asdouble, Event->iFlags); if( Event->Params[ 6 ].asTrack ) { // McZapkie-100302 - updatevalues oprocz zmiany wartosci robi putcommand dla
if (Event->Params[6].asTrack)
{ // McZapkie-100302 - updatevalues oprocz zmiany wartosci robi putcommand dla
// wszystkich 'dynamic' na danym torze // wszystkich 'dynamic' na danym torze
for( auto dynamic : Event->Params[ 6 ].asTrack->Dynamics ) { for( auto dynamic : Event->Params[ 6 ].asTrack->Dynamics ) {
Event->Params[ 5 ].asMemCell->PutCommand( Event->Params[ 5 ].asMemCell->PutCommand(
@@ -2969,39 +2957,47 @@ bool TGround::AddToQuery(TEvent *Event, TDynamicObject *Node)
&Event->Params[ 4 ].nGroundNode->pCenter ); &Event->Params[ 4 ].nGroundNode->pCenter );
} }
//if (DebugModeFlag) //if (DebugModeFlag)
WriteLog("EVENT EXECUTED: AddValues & Track command - " + WriteLog(
std::string(Event->Params[0].asText) + " " + "EVENT EXECUTED" + ( Node ? ( " by " + Node->asName ) : "" ) + ": AddValues & Track command ( "
std::to_string(Event->Params[1].asdouble) + " " + + std::string( Event->Params[ 0 ].asText ) + " "
std::to_string(Event->Params[2].asdouble)); + std::to_string( Event->Params[ 1 ].asdouble ) + " "
+ std::to_string( Event->Params[ 2 ].asdouble ) + " )" );
} }
//else if (DebugModeFlag) //else if (DebugModeFlag)
WriteLog("EVENT EXECUTED: AddValues - " + WriteLog(
std::string(Event->Params[0].asText) + " " + "EVENT EXECUTED" + ( Node ? ( " by " + Node->asName ) : "" ) + ": AddValues ( "
std::to_string(Event->Params[1].asdouble) + " " + + std::string( Event->Params[ 0 ].asText ) + " "
std::to_string(Event->Params[2].asdouble)); + std::to_string( Event->Params[ 1 ].asdouble ) + " "
+ std::to_string( Event->Params[ 2 ].asdouble ) + " )" );
} }
Event = // jeśli jest kolejny o takiej samej nazwie, to idzie do kolejki (and if there's no joint event it'll be set to null and processing will end here)
Event do {
->evJoined; // jeśli jest kolejny o takiej samej nazwie, to idzie do kolejki Event = Event->evJoined;
// NOTE: we could've received a new event from joint event above, so we need to check conditions just in case and discard the bad events
// TODO: refactor this arrangement, it's hardly optimal
} while( ( Event != nullptr )
&& ( ( false == Event->bEnabled )
|| ( Event->iQueued > 0 ) ) );
} }
if (Event) if( Event != nullptr ) {
{ // standardowe dodanie do kolejki // standardowe dodanie do kolejki
WriteLog("EVENT ADDED TO QUEUE: " + Event->asName + (Node ? (" by " + Node->asName) : ""));
Event->fStartTime =
fabs(Event->fDelay) + Timer::GetTime(); // czas od uruchomienia scenerii
if (Event->fRandomDelay > 0.0)
Event->fStartTime += Event->fRandomDelay * Random(10000) *
0.0001; // doliczenie losowego czasu opóźnienia
++Event->iQueued; // zabezpieczenie przed podwójnym dodaniem do kolejki ++Event->iQueued; // zabezpieczenie przed podwójnym dodaniem do kolejki
if (QueryRootEvent ? Event->fStartTime >= QueryRootEvent->fStartTime : false) WriteLog( "EVENT ADDED TO QUEUE" + ( Node ? ( " by " + Node->asName ) : "" ) + ": " + Event->asName );
QueryRootEvent->AddToQuery(Event); // dodanie gdzieś w środku Event->fStartTime = std::abs( Event->fDelay ) + Timer::GetTime(); // czas od uruchomienia scenerii
else if( Event->fRandomDelay > 0.0 ) {
{ // dodanie z przodu: albo nic nie ma, albo ma być wykonany szybciej niż pierwszy // doliczenie losowego czasu opóźnienia
Event->evNext = QueryRootEvent; Event->fStartTime += Event->fRandomDelay * Random( 10000 ) * 0.0001;
}
if( QueryRootEvent != nullptr ) {
TEvent::AddToQuery( Event, QueryRootEvent );
}
else {
QueryRootEvent = Event; QueryRootEvent = Event;
QueryRootEvent->evNext = nullptr;
} }
} }
} }
}
return true; return true;
} }
@@ -3078,69 +3074,25 @@ bool TGround::CheckQuery()
{ // sprawdzenie kolejki eventów oraz wykonanie tych, którym czas minął { // sprawdzenie kolejki eventów oraz wykonanie tych, którym czas minął
TLocation loc; TLocation loc;
int i; int i;
/* //Ra: to w ogóle jakiś chory kod jest; wygląda jak wyszukanie eventu z najlepszym czasem while( ( QueryRootEvent != nullptr )
Double evtime,evlowesttime; //Ra: co to za typ? && ( QueryRootEvent->fStartTime < Timer::GetTime() ) )
//evlowesttime=1000000;
if (QueryRootEvent)
{
OldQRE=QueryRootEvent;
tmpEvent=QueryRootEvent;
}
if (QueryRootEvent)
{
for (i=0;i<90;++i)
{
evtime=((tmpEvent->fStartTime)-(Timer::GetTime())); //pobranie wartości zmiennej
if (evtime<evlowesttime)
{
evlowesttime=evtime;
tmp2Event=tmpEvent;
}
if (tmpEvent->Next)
tmpEvent=tmpEvent->Next;
else
i=100;
}
if (OldQRE!=tmp2Event)
{
QueryRootEvent->AddToQuery(QueryRootEvent);
QueryRootEvent=tmp2Event;
}
}
*/
/*
if (QueryRootEvent)
{//wypisanie kolejki
tmpEvent=QueryRootEvent;
WriteLog("--> Event queue:");
while (tmpEvent)
{
WriteLog(tmpEvent->asName+" "+AnsiString(tmpEvent->fStartTime));
tmpEvent=tmpEvent->Next;
}
}
*/
while (QueryRootEvent ? QueryRootEvent->fStartTime < Timer::GetTime() : false)
{ // eventy są posortowana wg czasu wykonania { // eventy są posortowana wg czasu wykonania
tmpEvent = QueryRootEvent; // wyjęcie eventu z kolejki tmpEvent = QueryRootEvent; // wyjęcie eventu z kolejki
if (QueryRootEvent->evJoined) // jeśli jest kolejny o takiej samej nazwie if (QueryRootEvent->evJoined) // jeśli jest kolejny o takiej samej nazwie
{ // to teraz on będzie następny do wykonania { // to teraz on będzie następny do wykonania
QueryRootEvent = QueryRootEvent->evJoined; // następny będzie ten doczepiony QueryRootEvent = QueryRootEvent->evJoined; // następny będzie ten doczepiony
QueryRootEvent->evNext = tmpEvent->evNext; // pamiętając o następnym z kolejki QueryRootEvent->evNext = tmpEvent->evNext; // pamiętając o następnym z kolejki
QueryRootEvent->fStartTime = QueryRootEvent->fStartTime = tmpEvent->fStartTime; // czas musi być ten sam, bo nie jest aktualizowany
tmpEvent->fStartTime; // czas musi być ten sam, bo nie jest aktualizowany
QueryRootEvent->Activator = tmpEvent->Activator; // pojazd aktywujący QueryRootEvent->Activator = tmpEvent->Activator; // pojazd aktywujący
// w sumie można by go dodać normalnie do kolejki, ale trzeba te połączone posortować wg QueryRootEvent->iQueued = 1;
// czasu wykonania // w sumie można by go dodać normalnie do kolejki, ale trzeba te połączone posortować wg czasu wykonania
} }
else // a jak nazwa jest unikalna, to kolejka idzie dalej else // a jak nazwa jest unikalna, to kolejka idzie dalej
QueryRootEvent = QueryRootEvent->evNext; // NULL w skrajnym przypadku QueryRootEvent = QueryRootEvent->evNext; // NULL w skrajnym przypadku
if (tmpEvent->bEnabled) if (tmpEvent->bEnabled)
{ // w zasadzie te wyłączone są skanowane i nie powinny się nigdy w kolejce znaleźć { // w zasadzie te wyłączone są skanowane i nie powinny się nigdy w kolejce znaleźć
WriteLog("EVENT LAUNCHED: " + tmpEvent->asName + --tmpEvent->iQueued; // teraz moze być ponownie dodany do kolejki
(tmpEvent->Activator ? WriteLog( "EVENT LAUNCHED" + ( tmpEvent->Activator ? ( " by " + tmpEvent->Activator->asName ) : "" ) + ": " + tmpEvent->asName );
std::string(" by " + tmpEvent->Activator->asName) :
"" ));
switch (tmpEvent->Type) switch (tmpEvent->Type)
{ {
case tp_CopyValues: // skopiowanie wartości z innej komórki case tp_CopyValues: // skopiowanie wartości z innej komórki
@@ -3302,29 +3254,20 @@ bool TGround::CheckQuery()
conditional_anyelse)) // warunek spelniony albo było użyte else conditional_anyelse)) // warunek spelniony albo było użyte else
{ {
WriteLog("Multiple passed"); WriteLog("Multiple passed");
for (i = 0; i < 8; ++i) for (i = 0; i < 8; ++i) {
{ // dodawane do kolejki w kolejności zapisania // dodawane do kolejki w kolejności zapisania
if (tmpEvent->Params[i].asEvent) if( tmpEvent->Params[ i ].asEvent ) {
if (bCondition != (((tmpEvent->iFlags & (conditional_else << i)) != 0))) if( bCondition != ( ( ( tmpEvent->iFlags & ( conditional_else << i ) ) != 0 ) ) ) {
{ if( tmpEvent->Params[ i ].asEvent != tmpEvent )
if (tmpEvent->Params[i].asEvent != tmpEvent) AddToQuery( tmpEvent->Params[ i ].asEvent, tmpEvent->Activator ); // normalnie dodać
AddToQuery(tmpEvent->Params[i].asEvent, else {
tmpEvent->Activator); // normalnie dodać // jeśli ma być rekurencja to musi mieć sensowny okres powtarzania
else // jeśli ma być rekurencja if( tmpEvent->fDelay >= 5.0 ) {
if (tmpEvent->fDelay >= AddToQuery( tmpEvent, tmpEvent->Activator );
5.0) // to musi mieć sensowny okres powtarzania
if (tmpEvent->iQueued < 2)
{ // trzeba zrobić wyjątek, aby event mógł się sam dodać do
// kolejki, raz już jest, ale będzie usunięty
// pętla eventowa może być uruchomiona wiele razy, ale tylko
// pierwsze uruchomienie zadziała
tmpEvent->iQueued =
0; // tymczasowo, aby był ponownie dodany do kolejki
AddToQuery(tmpEvent, tmpEvent->Activator);
tmpEvent->iQueued =
2; // kolejny raz już absolutnie nie dodawać
} }
}
} }
}
} }
if (Global::iMultiplayer) // dajemy znać do serwera o wykonaniu if (Global::iMultiplayer) // dajemy znać do serwera o wykonaniu
if ((tmpEvent->iFlags & conditional_anyelse) == if ((tmpEvent->iFlags & conditional_anyelse) ==
@@ -3407,22 +3350,6 @@ bool TGround::CheckQuery()
break; break;
} // switch (tmpEvent->Type) } // switch (tmpEvent->Type)
} // if (tmpEvent->bEnabled) } // if (tmpEvent->bEnabled)
--tmpEvent->iQueued; // teraz moze być ponownie dodany do kolejki
/*
if (QueryRootEvent->eJoined) //jeśli jest kolejny o takiej samej nazwie
{//to teraz jego dajemy do wykonania
QueryRootEvent->eJoined->Next=QueryRootEvent->Next; //pamiętając o następnym z kolejki
QueryRootEvent->eJoined->fStartTime=QueryRootEvent->fStartTime; //czas musi być ten sam,
bo nie jest aktualizowany
//QueryRootEvent->fStartTime=0;
QueryRootEvent=QueryRootEvent->eJoined; //a wykonać ten doczepiony
}
else
{//a jak nazwa jest unikalna, to kolejka idzie dalej
//QueryRootEvent->fStartTime=0;
QueryRootEvent=QueryRootEvent->Next; //NULL w skrajnym przypadku
}
*/
} // while } // while
return true; return true;
} }
@@ -3652,10 +3579,11 @@ bool TGround::GetTraction(TDynamicObject *model)
vParam = vParam =
node->hvTraction node->hvTraction
->vParametric; // współczynniki równania parametrycznego ->vParametric; // współczynniki równania parametrycznego
fRaParam = -glm::dot(pant0, vFront); fRaParam = -DotProduct(pant0, vFront);
fRaParam = -(glm::dot(node->hvTraction->pPoint1, vFront) + auto const paramfrontdot = DotProduct( vParam, vFront );
fRaParam) / fRaParam =
glm::dot(vParam, vFront); -( DotProduct( node->hvTraction->pPoint1, vFront ) + fRaParam )
/ ( paramfrontdot != 0.0 ? paramfrontdot : 0.001 ); // div0 trap
if ((fRaParam >= -0.001) ? (fRaParam <= 1.001) : false) if ((fRaParam >= -0.001) ? (fRaParam <= 1.001) : false)
{ // jeśli tylko jest w przedziale, wyznaczyć odległość wzdłuż { // jeśli tylko jest w przedziale, wyznaczyć odległość wzdłuż
// wektorów vUp i vLeft // wektorów vUp i vLeft

View File

@@ -272,10 +272,7 @@ class TGround
TGroundRect Rects[iNumRects][iNumRects]; // mapa kwadratów kilometrowych TGroundRect Rects[iNumRects][iNumRects]; // mapa kwadratów kilometrowych
TEvent *RootEvent = nullptr; // lista zdarzeń TEvent *RootEvent = nullptr; // lista zdarzeń
TEvent *QueryRootEvent = nullptr, TEvent *QueryRootEvent = nullptr,
*tmpEvent = nullptr, *tmpEvent = nullptr;
*tmp2Event = nullptr,
*OldQRE = nullptr;
/*
TSubRect *pRendered[1500]; // lista renderowanych sektorów TSubRect *pRendered[1500]; // lista renderowanych sektorów
*/ */
int iNumNodes = 0; int iNumNodes = 0;

View File

@@ -2881,10 +2881,12 @@ void TTrain::OnCommand_hornlowactivate( TTrain *Train, command_data const &Comma
if( false == TestFlag( Train->mvOccupied->WarningSignal, 1 ) ) { if( false == TestFlag( Train->mvOccupied->WarningSignal, 1 ) ) {
// turn on // turn on
Train->mvOccupied->WarningSignal |= 1; Train->mvOccupied->WarningSignal |= 1;
/*
if( true == TestFlag( Train->mvOccupied->WarningSignal, 2 ) ) { if( true == TestFlag( Train->mvOccupied->WarningSignal, 2 ) ) {
// low and high horn are treated as mutually exclusive // low and high horn are treated as mutually exclusive
Train->mvControlled->WarningSignal &= ~2; Train->mvControlled->WarningSignal &= ~2;
} }
*/
// audio feedback // audio feedback
if( ( Train->ggHornButton.GetValue() > -0.5 ) if( ( Train->ggHornButton.GetValue() > -0.5 )
|| ( Train->ggHornLowButton.GetValue() < 0.5 ) ) { || ( Train->ggHornLowButton.GetValue() < 0.5 ) ) {
@@ -2897,8 +2899,11 @@ void TTrain::OnCommand_hornlowactivate( TTrain *Train, command_data const &Comma
} }
else if( Command.action == GLFW_RELEASE ) { else if( Command.action == GLFW_RELEASE ) {
// turn off // turn off
/*
// NOTE: we turn off both low and high horn, due to unreliability of release event when shift key is involved // NOTE: we turn off both low and high horn, due to unreliability of release event when shift key is involved
Train->mvOccupied->WarningSignal &= ~( 1 | 2 ); Train->mvOccupied->WarningSignal &= ~( 1 | 2 );
*/
Train->mvOccupied->WarningSignal &= ~1;
// audio feedback // audio feedback
if( ( Train->ggHornButton.GetValue() < -0.5 ) if( ( Train->ggHornButton.GetValue() < -0.5 )
|| ( Train->ggHornLowButton.GetValue() > 0.5 ) ) { || ( Train->ggHornLowButton.GetValue() > 0.5 ) ) {
@@ -2925,10 +2930,12 @@ void TTrain::OnCommand_hornhighactivate( TTrain *Train, command_data const &Comm
if( false == TestFlag( Train->mvOccupied->WarningSignal, 2 ) ) { if( false == TestFlag( Train->mvOccupied->WarningSignal, 2 ) ) {
// turn on // turn on
Train->mvOccupied->WarningSignal |= 2; Train->mvOccupied->WarningSignal |= 2;
/*
if( true == TestFlag( Train->mvOccupied->WarningSignal, 1 ) ) { if( true == TestFlag( Train->mvOccupied->WarningSignal, 1 ) ) {
// low and high horn are treated as mutually exclusive // low and high horn are treated as mutually exclusive
Train->mvControlled->WarningSignal &= ~1; Train->mvControlled->WarningSignal &= ~1;
} }
*/
// audio feedback // audio feedback
if( Train->ggHornButton.GetValue() < 0.5 ) { if( Train->ggHornButton.GetValue() < 0.5 ) {
Train->play_sound( Train->dsbSwitch ); Train->play_sound( Train->dsbSwitch );
@@ -2940,8 +2947,11 @@ void TTrain::OnCommand_hornhighactivate( TTrain *Train, command_data const &Comm
} }
else if( Command.action == GLFW_RELEASE ) { else if( Command.action == GLFW_RELEASE ) {
// turn off // turn off
/*
// NOTE: we turn off both low and high horn, due to unreliability of release event when shift key is involved // NOTE: we turn off both low and high horn, due to unreliability of release event when shift key is involved
Train->mvOccupied->WarningSignal &= ~( 1 | 2 ); Train->mvOccupied->WarningSignal &= ~( 1 | 2 );
*/
Train->mvOccupied->WarningSignal &= ~2;
// audio feedback // audio feedback
if( Train->ggHornButton.GetValue() > 0.5 ) { if( Train->ggHornButton.GetValue() > 0.5 ) {
Train->play_sound( Train->dsbSwitch ); Train->play_sound( Train->dsbSwitch );
@@ -4390,16 +4400,6 @@ bool TTrain::Update( double const Deltatime )
{ // ustawienie zmiennych dla silnika spalinowego { // ustawienie zmiennych dla silnika spalinowego
fEngine[1] = mvControlled->ShowEngineRotation(1); fEngine[1] = mvControlled->ShowEngineRotation(1);
fEngine[2] = mvControlled->ShowEngineRotation(2); fEngine[2] = mvControlled->ShowEngineRotation(2);
// if (ggEnrot1m.SubModel)
//{
// ggEnrot1m.UpdateValue(mvControlled->ShowEngineRotation(1));
// ggEnrot1m.Update();
//}
// if (ggEnrot2m.SubModel)
//{
// ggEnrot2m.UpdateValue(mvControlled->ShowEngineRotation(2));
// ggEnrot2m.Update();
//}
} }
else if (mvControlled->EngineType == DieselEngine) else if (mvControlled->EngineType == DieselEngine)
@@ -4407,34 +4407,12 @@ bool TTrain::Update( double const Deltatime )
fEngine[1] = mvControlled->ShowEngineRotation(1); fEngine[1] = mvControlled->ShowEngineRotation(1);
fEngine[2] = mvControlled->ShowEngineRotation(2); fEngine[2] = mvControlled->ShowEngineRotation(2);
fEngine[3] = mvControlled->ShowEngineRotation(3); fEngine[3] = mvControlled->ShowEngineRotation(3);
// if (ggEnrot1m.SubModel)
//{
// ggEnrot1m.UpdateValue(mvControlled->ShowEngineRotation(1));
// ggEnrot1m.Update();
//}
// if (ggEnrot2m.SubModel)
//{
// ggEnrot2m.UpdateValue(mvControlled->ShowEngineRotation(2));
// ggEnrot2m.Update();
//}
// if (ggEnrot3m.SubModel)
// if (mvControlled->Couplers[1].Connected)
// {
// ggEnrot3m.UpdateValue(mvControlled->ShowEngineRotation(3));
// ggEnrot3m.Update();
// }
// if (ggEngageRatio.SubModel)
//{
// ggEngageRatio.UpdateValue(mvControlled->dizel_engage);
// ggEngageRatio.Update();
//}
if (ggMainGearStatus.SubModel) if (ggMainGearStatus.SubModel)
{ {
if (mvControlled->Mains) if (mvControlled->Mains)
ggMainGearStatus.UpdateValue(1.1 - ggMainGearStatus.UpdateValue(1.1 - std::abs(mvControlled->dizel_automaticgearstatus));
fabs(mvControlled->dizel_automaticgearstatus));
else else
ggMainGearStatus.UpdateValue(0); ggMainGearStatus.UpdateValue(0.0);
ggMainGearStatus.Update(); ggMainGearStatus.Update();
} }
if (ggIgnitionKey.SubModel) if (ggIgnitionKey.SubModel)

22
Train.h
View File

@@ -449,23 +449,17 @@ public: // reszta może by?publiczna
int CAflag; // hunter-131211: dla osobnego zbijania CA i SHP int CAflag; // hunter-131211: dla osobnego zbijania CA i SHP
double fPoslizgTimer; double fPoslizgTimer;
// double fShpTimer;
// double fDblClickTimer;
// ABu: Przeniesione do public. - Wiem, ze to nieladnie...
// bool CabChange(int iDirection);
// bool InitializeCab(int NewCabNo, AnsiString asFileName);
TTrack *tor; TTrack *tor;
int keybrakecount; int keybrakecount;
// McZapkie-240302 - przyda sie do tachometru // McZapkie-240302 - przyda sie do tachometru
float fTachoVelocity; float fTachoVelocity{ 0.0f };
float fTachoVelocityJump; // ze skakaniem float fTachoVelocityJump{ 0.0f }; // ze skakaniem
float fTachoTimer; float fTachoTimer{ 0.0f };
float fTachoCount; float fTachoCount{ 0.0f };
float fHVoltage; // napi?cie dla dynamicznych ga?ek float fHVoltage{ 0.0f }; // napi?cie dla dynamicznych ga?ek
float fHCurrent[4]; // pr?dy: suma i amperomierze 1,2,3 float fHCurrent[ 4 ] = { 0.0f, 0.0f, 0.0f, 0.0f }; // pr?dy: suma i amperomierze 1,2,3
float fEngine[4]; // obroty te? trzeba pobra? float fEngine[ 4 ] = { 0.0f, 0.0f, 0.0f, 0.0f }; // obroty te? trzeba pobra?
int iCarNo, iPowerNo, iUnitNo; // liczba pojazdow, czlonow napednych i jednostek spiętych ze int iCarNo, iPowerNo, iUnitNo; // liczba pojazdow, czlonow napednych i jednostek spiętych ze sobą
// sobą
bool bDoors[20][3]; // drzwi dla wszystkich czlonow bool bDoors[20][3]; // drzwi dla wszystkich czlonow
int iUnits[20]; // numer jednostki int iUnits[20]; // numer jednostki
int iDoorNo[20]; // liczba drzwi int iDoorNo[20]; // liczba drzwi

View File

@@ -1,5 +1,5 @@
#pragma once #pragma once
#define VERSION_MAJOR 17 #define VERSION_MAJOR 17
#define VERSION_MINOR 525 #define VERSION_MINOR 603
#define VERSION_REVISION 0 #define VERSION_REVISION 0