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

Merge pull request #80 from Unofficial-MaSzyna-Developement/high-beam-lights

High beam headlights
This commit is contained in:
Ryba04
2025-02-02 00:13:27 +01:00
committed by GitHub
12 changed files with 909 additions and 642 deletions

View File

@@ -5704,6 +5704,7 @@ void TController::TakeControl( bool const Aidriver, bool const Forcevehiclecheck
{ // teraz AI prowadzi
AIControllFlag = AIdriver;
pVehicle->Controller = AIdriver;
control_lights(); // reinicjalizacja swiatel
mvOccupied->CabActivisation(true);
iDirection = 0; // kierunek jazdy trzeba dopiero zgadnąć
TableClear(); // ponowne utworzenie tabelki, bo człowiek mógł pojechać niezgodnie z sygnałami
@@ -5740,6 +5741,8 @@ void TController::TakeControl( bool const Aidriver, bool const Forcevehiclecheck
}
else
{ // a teraz użytkownik
if (!is_train() || !is_car()) // gasimy swiatla jesli przejmujemy odstawione
pVehicle->RaLightsSet(0, 0);
AIControllFlag = Humandriver;
pVehicle->Controller = Humandriver;
if( eAction == TAction::actSleep ) {

View File

@@ -1168,6 +1168,28 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist)
}
btnOn = true;
}
// logika dlugich
if (TestFlag(MoverParameters->iLights[end::front], light::highbeamlight_left))
m_highbeam13.TurnxOnWithOnAsFallback();
else
m_highbeam13.TurnOff();
if (TestFlag(MoverParameters->iLights[end::front], light::highbeamlight_right))
m_highbeam12.TurnxOnWithOnAsFallback();
else
m_highbeam12.TurnOff();
// i to samo od dupy strony
if (TestFlag(MoverParameters->iLights[end::rear], light::highbeamlight_left))
m_highbeam23.TurnxOnWithOnAsFallback();
else
m_highbeam23.TurnOff();
if (TestFlag(MoverParameters->iLights[end::rear], light::highbeamlight_right))
m_highbeam22.TurnxOnWithOnAsFallback();
else
m_highbeam22.TurnOff();
}
// interior light levels
auto sectionlightcolor { glm::vec4( 1.f ) };
@@ -2197,9 +2219,13 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424"
m_headlamp11.Init( "headlamp11", mdModel ); // górne
m_headlamp12.Init( "headlamp12", mdModel ); // prawe
m_headlamp13.Init( "headlamp13", mdModel ); // lewe
m_highbeam12.Init("highbeam12", mdModel); // prawe dlugie
m_highbeam13.Init("highbeam13", mdModel); // lewe dlugie
m_headlamp21.Init( "headlamp21", mdModel );
m_headlamp22.Init( "headlamp22", mdModel );
m_headlamp23.Init( "headlamp23", mdModel );
m_highbeam22.Init("highbeam22", mdModel);
m_highbeam23.Init("highbeam23", mdModel);
m_headsignal12.Init( "headsignal12", mdModel );
m_headsignal13.Init( "headsignal13", mdModel );
m_headsignal22.Init( "headsignal22", mdModel );
@@ -2216,6 +2242,10 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424"
iInventory[ end::front ] |= m_headlamp11.Active() ? light::headlight_upper : 0;
iInventory[ end::front ] |= m_headlamp12.Active() ? light::headlight_right : 0;
iInventory[ end::front ] |= m_headlamp13.Active() ? light::headlight_left : 0;
iInventory[end::front] |= m_highbeam12.Active() ? light::highbeamlight_right : 0;
iInventory[end::front] |= m_highbeam13.Active() ? light::highbeamlight_left : 0;
iInventory[ end::rear ] |= m_headlamp21.Active() ? light::headlight_upper : 0;
iInventory[ end::rear ] |= m_headlamp22.Active() ? light::headlight_right : 0;
iInventory[ end::rear ] |= m_headlamp23.Active() ? light::headlight_left : 0;
@@ -2223,6 +2253,11 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424"
iInventory[ end::front ] |= m_headsignal13.Active() ? light::auxiliary_left : 0;
iInventory[ end::rear ] |= m_headsignal22.Active() ? light::auxiliary_right : 0;
iInventory[ end::rear ] |= m_headsignal23.Active() ? light::auxiliary_left : 0;
iInventory[end::rear] |= m_highbeam22.Active() ? light::highbeamlight_right : 0;
iInventory[end::rear] |= m_highbeam23.Active() ? light::highbeamlight_left : 0;
btMechanik1.Init( "mechanik1", mdLowPolyInt, false);
btMechanik2.Init( "mechanik2", mdLowPolyInt, false);
if( MoverParameters->dizel_heat.water.config.shutters ) {
@@ -4162,6 +4197,10 @@ void TDynamicObject::TurnOff()
m_headlamp21.TurnOff();
m_headlamp22.TurnOff();
m_headlamp23.TurnOff();
m_highbeam12.TurnOff();
m_highbeam13.TurnOff();
m_highbeam22.TurnOff();
m_highbeam23.TurnOff();
m_headsignal12.TurnOff();
m_headsignal13.TurnOff();
m_headsignal22.TurnOff();
@@ -7001,7 +7040,6 @@ void TDynamicObject::Damage(char flag)
};
void TDynamicObject::SetLights() {
auto const isfrontcaboccupied { MoverParameters->CabOccupied * DirectionGet() >= 0 };
int const automaticmarkers { MoverParameters->CabActive == 0 && ( MoverParameters->InactiveCabFlag & activation::redmarkers )
? light::redmarker_left + light::redmarker_right : 0 };
@@ -7055,6 +7093,47 @@ void TDynamicObject::RaLightsSet(int head, int rear)
if( head >= 0 ) {
auto const vehicleend { iDirection > 0 ? end::front : end::rear };
MoverParameters->iLights[ vehicleend ] = ( head & iInventory[ vehicleend ] );
bool tLeft = MoverParameters->iLights[vehicleend] & (light::auxiliary_left | light::headlight_left); // roboczo czy jakiekolwiek swiatlo z lewej jest zapalone
bool tRight = MoverParameters->iLights[vehicleend] & (light::auxiliary_right | light::headlight_right); // a tu z prawej
if (Controller == Humandriver) {
switch (MoverParameters->modernDimmerState)
{
case 0:
// wylaczone
MoverParameters->iLights[vehicleend] &= 0 | light::rearendsignals; // zostawiamy tylko tabliczki jesli sa
HighBeamLights = false;
DimHeadlights = false;
break;
case 1:
// przyciemnione normalne
DimHeadlights = true; // odpalamy przyciemnienie normalnych reflektorow
HighBeamLights = false;
break;
case 3:
// dlugie przyciemnione
DimHeadlights = true;
HighBeamLights = true;
MoverParameters->iLights[vehicleend] &=
light::headlight_upper | light::rearendsignals | light::redmarker_left | light::redmarker_right | light::rearendsignals; // nie ruszamy gornych i koncowek
MoverParameters->iLights[vehicleend] |= tLeft ? light::highbeamlight_left : 0; // jesli swiatlo z lewej zapalone to odpal dlugie
MoverParameters->iLights[vehicleend] |= tRight ? light::highbeamlight_right : 0; // a tu z prawej
break;
case 4:
// zwykle dlugie
DimHeadlights = false;
HighBeamLights = true;
MoverParameters->iLights[vehicleend] &=
light::headlight_upper | light::rearendsignals | light::redmarker_left | light::redmarker_right | light::rearendsignals; // nie ruszamy gornych i koncowek
MoverParameters->iLights[vehicleend] |= tLeft ? light::highbeamlight_left : 0; // jesli swiatlo z lewej zapalone to odpal dlugie
MoverParameters->iLights[vehicleend] |= tRight ? light::highbeamlight_right : 0; // a tu z prawej
break;
default: // to case 2 - zwykle
DimHeadlights = false;
HighBeamLights = false;
break;
}
}
}
if( rear >= 0 ) {
auto const vehicleend{ iDirection > 0 ? end::rear : end::front };

View File

@@ -469,9 +469,13 @@ private:
AirCoupler m_headlamp11; // oswietlenie czolowe - przod
AirCoupler m_headlamp12;
AirCoupler m_headlamp13;
AirCoupler m_highbeam12; // dlugie
AirCoupler m_highbeam13;
AirCoupler m_headlamp21; // oswietlenie czolowe - tyl
AirCoupler m_headlamp22;
AirCoupler m_headlamp23;
AirCoupler m_highbeam22;
AirCoupler m_highbeam23;
AirCoupler m_headsignal12;
AirCoupler m_headsignal13;
AirCoupler m_headsignal22;
@@ -571,6 +575,7 @@ private:
public:
bool DimHeadlights{ false }; // status of the headlight dimming toggle. NOTE: single toggle for all lights is a simplification. TODO: separate per-light switches
bool HighBeamLights { false }; // status of the highbeam toggle
// checks whether there's unbroken connection of specified type to specified vehicle
bool is_connected( TDynamicObject const *Vehicle, coupling const Coupling = coupling::coupler ) const;
TDynamicObject * PrevAny() const;

View File

@@ -205,6 +205,8 @@ enum light {
rearendsignals = ( 1 << 6 ),
auxiliary_left = ( 1 << 7 ),
auxiliary_right = ( 1 << 8 ),
highbeamlight_left = ( 1 << 9 ),
highbeamlight_right = ( 1 << 10 )
};
// door operation methods; exclusive
@@ -831,7 +833,8 @@ private:
*/
// basic approximation of a generic device
// TBD: inheritance or composition?
struct basic_device {
struct basic_device
{
// config
start_t start_type{start_t::manual};
// ld inputs
@@ -842,14 +845,16 @@ private:
bool is_active{false}; // device is working
};
struct basic_light : public basic_device {
struct basic_light : public basic_device
{
// config
float dimming{1.0f}; // light strength multiplier
// ld outputs
float intensity{0.0f}; // current light strength
};
struct cooling_fan : public basic_device {
struct cooling_fan : public basic_device
{
// config
float speed{0.f}; // cooling fan rpm; either fraction of parent rpm, or absolute value if negative
float sustain_time{0.f}; // time of sustaining work of cooling fans after stop
@@ -860,12 +865,14 @@ private:
};
// basic approximation of a fuel pump
struct fuel_pump : public basic_device {
struct fuel_pump : public basic_device
{
// TODO: fuel consumption, optional automatic engine start after activation
};
// basic approximation of an oil pump
struct oil_pump : public basic_device {
struct oil_pump : public basic_device
{
// config
float pressure_minimum{0.f}; // lowest acceptable working pressure
float pressure_maximum{0.65f}; // oil pressure at maximum engine revolutions
@@ -878,21 +885,24 @@ private:
};
// basic approximation of a water pump
struct water_pump : public basic_device {
struct water_pump : public basic_device
{
// ld inputs
// TODO: move to breaker list in the basic device once implemented
bool breaker{false}; // device is allowed to operate
};
// basic approximation of a solenoid valve
struct basic_valve : basic_device {
struct basic_valve : basic_device
{
// config
bool solenoid{true}; // requires electric power to operate
bool spring{true}; // spring return or double acting actuator
};
// basic approximation of a pantograph
struct basic_pantograph {
struct basic_pantograph
{
// ld inputs
basic_valve valve; // associated pneumatic valve
// ld outputs
@@ -902,7 +912,8 @@ private:
};
// basic approximation of doors
struct basic_door {
struct basic_door
{
// config
// ld inputs
bool open_permit{false}; // door can be opened
@@ -926,7 +937,8 @@ private:
bool step_unfolding{false}; // the doorstep is currently opening
};
struct door_data {
struct door_data
{
// config
control_t open_control{control_t::passenger};
float open_rate{1.f};
@@ -959,12 +971,13 @@ private:
std::array<basic_door, 2> instances; // door on the right and left side of the vehicle
// ld outputs
bool is_locked{false};
double doorLockSpeed = 10.0; // predkosc przy ktorej wyzwalana jest blokada drzwi
};
struct water_heater {
struct water_heater
{
// config
struct heater_config_t {
struct heater_config_t
{
float temp_min{-1}; // lowest accepted temperature
float temp_max{-1}; // highest accepted temperature
} config;
@@ -976,7 +989,8 @@ private:
bool is_damaged{false}; // device is damaged
};
struct heat_data {
struct heat_data
{
// input, state of relevant devices
bool cooling{false}; // TODO: user controlled device, implement
// bool okienko { true }; // window in the engine compartment
@@ -991,9 +1005,11 @@ private:
double kfo{25.0};
double kfo2{25.0};
// system parts
struct fluid_circuit_t {
struct fluid_circuit_t
{
struct circuit_config_t {
struct circuit_config_t
{
float temp_min{-1}; // lowest accepted temperature
float temp_max{-1}; // highest accepted temperature
float temp_cooling{-1}; // active cooling activation point
@@ -1004,9 +1020,7 @@ private:
bool is_warm{false}; // fluid is too hot
bool is_hot{false}; // fluid temperature crossed cooling threshold
bool is_flowing{false}; // fluid is being pushed through the circuit
} water,
water_aux,
oil;
} water, water_aux, oil;
// output, state of affected devices
bool PA{false}; // malfunction flag
float rpmw{0.0}; // current main circuit fan revolutions
@@ -1029,7 +1043,8 @@ private:
float powerfactor{1.0}; // coefficient of heat generation for engines other than su45
};
struct spring_brake {
struct spring_brake
{
std::shared_ptr<TReservoir> Cylinder;
bool Activate{false}; // Input: switching brake on/off in exploitation - main valve/switch
bool ShuttOff{true}; // Input: shutting brake off during failure - valve in pneumatic container
@@ -1051,11 +1066,9 @@ private:
double ValvePNBrakeArea{0.0}; // Conf: Area of bypass to brake cylinders
int MultiTractionCoupler{127}; // Conf: Coupling flag necessary for transmitting the command
};
public:
double dMoveLen = 0.0;
/*---opis lokomotywy, wagonu itp*/
/*--opis serii--*/
@@ -1098,7 +1111,8 @@ public:
int NPoweredAxles = 0; /*ilosc osi napednych liczona z powyzszego*/
int NAxles = 0; /*ilosc wszystkich osi j.w.*/
int BearingType = 1; /*lozyska: 0 - slizgowe, 1 - toczne*/
double ADist = 0.0; double BDist = 0.0; /*odlegosc osi oraz czopow skretu*/
double ADist = 0.0;
double BDist = 0.0; /*odlegosc osi oraz czopow skretu*/
/*hamulce:*/
int NBpA = 0; /*ilosc el. ciernych na os: 0 1 2 lub 4*/
int SandCapacity = 0; /*zasobnik piasku [kg]*/
@@ -1192,7 +1206,6 @@ public:
int Lights[2][17]; // pozycje świateł, przód - tył, 1 .. 16
int ScndInMain{0}; /*zaleznosc bocznika od nastawnika*/
bool MBrake = false; /*Czy jest hamulec reczny*/
double maxTachoSpeed = 0.0; // maksymalna predkosc na tarczce predkosciomierza analogowego
double StopBrakeDecc = 0.0;
bool ReleaseParkingBySpringBrake{false};
bool ReleaseParkingBySpringBrakeWhenDoorIsOpen{false};
@@ -1225,12 +1238,14 @@ public:
double WindingRes = 0.0;
double u = 0.0; // wspolczynnik tarcia yB wywalic!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
double CircuitRes = 0.0; /*rezystancje silnika i obwodu*/
int IminLo = 0; int IminHi = 0; /*prady przelacznika automatycznego rozruchu, uzywane tez przez ai_driver*/
int IminLo = 0;
int IminHi = 0; /*prady przelacznika automatycznego rozruchu, uzywane tez przez ai_driver*/
int ImaxLo = 0; // maksymalny prad niskiego rozruchu
int ImaxHi = 0; // maksymalny prad wysokiego rozruchu
bool MotorOverloadRelayHighThreshold{false};
double nmax = 0.0; /*maksymalna dop. ilosc obrotow /s*/
double InitialCtrlDelay = 0.0; double CtrlDelay = 0.0; /* -//- -//- miedzy kolejnymi poz.*/
double InitialCtrlDelay = 0.0;
double CtrlDelay = 0.0; /* -//- -//- miedzy kolejnymi poz.*/
double CtrlDownDelay = 0.0; /* -//- -//- przy schodzeniu z poz.*/ /*hunter-101012*/
int FastSerialCircuit = 0; /*0 - po kolei zamyka styczniki az do osiagniecia szeregowej, 1 - natychmiastowe wejscie na szeregowa*/ /*hunter-111012*/
int BackwardsBranchesAllowed = 1;
@@ -1286,7 +1301,9 @@ public:
double dizel_FuelConsumption = 0.0; /*współczynnik zużycia paliwa przeliczony do jednostek maszynowych, l/obrót*/
double dizel_FuelConsumptionActual = 0.0; /*chwilowe spalanie paliwa w l/h*/
double dizel_FuelConsumptedTotal = 0.0; /*ilość paliwa zużyta od początku symulacji, l*/
double dizel_engageDia = 0.5; double dizel_engageMaxForce = 6000.0; double dizel_engagefriction = 0.5; /*parametry sprzegla*/
double dizel_engageDia = 0.5;
double dizel_engageMaxForce = 6000.0;
double dizel_engagefriction = 0.5; /*parametry sprzegla*/
double engagedownspeed = 0.9;
double engageupspeed = 0.5;
/*parametry przetwornika momentu*/
@@ -1366,26 +1383,30 @@ public:
double DCEMUED_EP_delay{0.0}; // opóźnienie włączenia hamulca EP przy hamowaniu ED - zwłoka wstępna
/*-dla wagonow*/
struct load_attributes {
struct load_attributes
{
std::string name; // name of the cargo
float offset_min{0.f}; // offset applied to cargo model when load amount is 0
load_attributes() = default;
load_attributes( std::string const &Name, float const Offsetmin ) :
name( Name ), offset_min( Offsetmin )
{}
load_attributes(std::string const &Name, float const Offsetmin) : name(Name), offset_min(Offsetmin) {}
};
std::vector<load_attributes> LoadAttributes;
float MaxLoad = 0.f; /*masa w T lub ilosc w sztukach - ladownosc*/
double OverLoadFactor = 0.0; /*ile razy moze byc przekroczona ladownosc*/
float LoadSpeed = 0.f; float UnLoadSpeed = 0.f;/*szybkosc na- i rozladunku jednostki/s*/
float LoadSpeed = 0.f;
float UnLoadSpeed = 0.f; /*szybkosc na- i rozladunku jednostki/s*/
#ifdef EU07_USEOLDDOORCODE
int DoorOpenCtrl = 0; int DoorCloseCtrl = 0; /*0: przez pasazera, 1: przez maszyniste, 2: samoczynne (zamykanie)*/
int DoorOpenCtrl = 0;
int DoorCloseCtrl = 0; /*0: przez pasazera, 1: przez maszyniste, 2: samoczynne (zamykanie)*/
double DoorStayOpen = 0.0; /*jak dlugo otwarte w przypadku DoorCloseCtrl=2*/
bool DoorClosureWarning = false; /*czy jest ostrzeganie przed zamknieciem*/
bool DoorClosureWarningAuto = false; // departure signal plays automatically while door closing button is held down
double DoorOpenSpeed = 1.0; double DoorCloseSpeed = 1.0; /*predkosc otwierania i zamykania w j.u. */
double DoorMaxShiftL = 0.5; double DoorMaxShiftR = 0.5; double DoorMaxPlugShift = 0.1;/*szerokosc otwarcia lub kat*/
double DoorOpenSpeed = 1.0;
double DoorCloseSpeed = 1.0; /*predkosc otwierania i zamykania w j.u. */
double DoorMaxShiftL = 0.5;
double DoorMaxShiftR = 0.5;
double DoorMaxPlugShift = 0.1; /*szerokosc otwarcia lub kat*/
int DoorOpenMethod = 2; /*sposob otwarcia - 1: przesuwne, 2: obrotowe, 3: trójelementowe*/
float DoorCloseDelay{0.f}; // delay (in seconds) before the door begin closing, once conditions to close are met
double PlatformSpeed = 0.5; /*szybkosc stopnia*/
@@ -1429,12 +1450,16 @@ public:
bool TruckHunting{true}; // enable/disable truck hunting calculation
/*! rotacja kol [obr/s]*/
double EnginePower = 0.0; /*! chwilowa moc silnikow*/
double dL = 0.0; double Fb = 0.0; double Ff = 0.0; /*przesuniecie, sila hamowania i tarcia*/
double FTrain = 0.0; double FStand = 0.0; /*! sila pociagowa i oporow ruchu*/
double dL = 0.0;
double Fb = 0.0;
double Ff = 0.0; /*przesuniecie, sila hamowania i tarcia*/
double FTrain = 0.0;
double FStand = 0.0; /*! sila pociagowa i oporow ruchu*/
double FTotal = 0.0; /*! calkowita sila dzialajaca na pojazd*/
double UnitBrakeForce = 0.0; /*!s siła hamowania przypadająca na jeden element*/
double Ntotal = 0.0; /*!s siła nacisku klockow*/
bool SlippingWheels = false; bool SandDose = false; /*! poslizg kol, sypanie piasku*/
bool SlippingWheels = false;
bool SandDose = false; /*! poslizg kol, sypanie piasku*/
bool SandDoseManual = false; /*piaskowanie reczne*/
bool SandDoseAuto = false; /*piaskowanie automatyczne*/
bool SandDoseAutoAllow = true; /*zezwolenie na automatyczne piaskowanie*/
@@ -1517,7 +1542,6 @@ public:
double LimPipePress = 0.0; /*stabilizator cisnienia*/
double ActFlowSpeed = 0.0; /*szybkosc stabilizatora*/
int DamageFlag = 0; // kombinacja bitowa stalych dtrain_* }
int EngDmgFlag = 0; // kombinacja bitowa stalych usterek}
int DerailReason = 0; // przyczyna wykolejenia
@@ -1533,7 +1557,8 @@ public:
TTrackShape RunningShape; /*geometria toru po ktorym jedzie pojazd*/
TTrackParam RunningTrack; /*parametry toru po ktorym jedzie pojazd*/
double OffsetTrackH = 0.0; double OffsetTrackV = 0.0; /*przesuniecie poz. i pion. w/m osi toru*/
double OffsetTrackH = 0.0;
double OffsetTrackV = 0.0; /*przesuniecie poz. i pion. w/m osi toru*/
/*-zmienne dla lokomotyw*/
bool Mains = false; /*polozenie glownego wylacznika*/
@@ -1554,7 +1579,10 @@ public:
int CabActive = 0; // numer kabiny, z której jest sterowanie: 1 lub -1; w przeciwnym razie brak sterowania - rozrzad
int CabOccupied = 0; // numer kabiny, w ktorej jest obsada (zwykle jedna na skład) // TODO: move to TController
bool CabMaster = false; // czy pojazd jest nadrzędny w składzie
inline bool IsCabMaster() { return ((CabActive == CabOccupied) && CabMaster); } //czy aktualna kabina jest na pewno tą, z której można sterować
inline bool IsCabMaster()
{
return ((CabActive == CabOccupied) && CabMaster);
} // czy aktualna kabina jest na pewno tą, z której można sterować
bool AutomaticCabActivation = true; // czy zmostkowany rozrzad przelacza sie sam przy zmianie kabiny
int InactiveCabFlag = 0; // co sie dzieje przy dezaktywacji kabiny
bool InactiveCabPantsCheck = false; // niech DynamicObject sprawdzi pantografy
@@ -1582,7 +1610,8 @@ public:
// Ra: Im jest ujemny, jeśli lok jedzie w stronę sprzęgu 1
// a ujemne powinien być przy odwróconej polaryzacji sieci...
// w wielu miejscach jest używane abs(Im)
int Imin = 0; int Imax = 0; /*prad przelaczania automatycznego rozruchu, prad bezpiecznika*/
int Imin = 0;
int Imax = 0; /*prad przelaczania automatycznego rozruchu, prad bezpiecznika*/
double EngineVoltage = 0.0; // voltage supplied to engine
int MainCtrlActualPos = 0; /*wskaznik RList*/
int ScndCtrlActualPos = 0; /*wskaznik MotorParam*/
@@ -1705,6 +1734,26 @@ public:
int iProblem = 0; // flagi problemów z taborem, aby AI nie musiało porównywać; 0=może jechać
int iLights[2]; // bity zapalonych świateł tutaj, żeby dało się liczyć pobór prądu
// Status nowszego hebelka od przyciemniania swiatel/swiatel dlugich
// 0 - swiatla wylaczone (opcja dziala tylko gdy w fiz zdefiniowano OffState w sekcji Switches; w przeciwnym wypadku pstryk startuje z wartoscia == 1
// 1 - swiatla normalne przyciemnione
// 2 - swiatla normalne
// 3 - swiatla dlugie przyciemnione
// 4 - swiatla dlugie normalne
int modernDimmerState{0};
bool modernContainOffPos{true};
bool enableModernDimmer {false};
// Barwa reflektora
int refR{255}; // Czerwony
int refG{255}; // Zielony
int refB{255}; // Niebieski
double dimMultiplier{0.6f}; // mnoznik swiatel przyciemnionych
double normMultiplier{1.0f}; // mnoznik swiatel zwyklych
double highDimMultiplier{2.5f}; // mnoznik dlugich przyciemnionych
double highMultiplier{2.8f}; // mnoznik dlugich
plc::basic_controller m_plc;
int AIHintPantstate{ 0 }; // suggested pantograph setup
@@ -1969,6 +2018,7 @@ private:
void LoadFIZ_DCEMUED(std::string const &line);
void LoadFIZ_SpringBrake(std::string const &line);
void LoadFIZ_Light( std::string const &line );
void LoadFIZ_Headlights(std::string const &Line);
void LoadFIZ_Clima( std::string const &line );
void LoadFIZ_Power( std::string const &Line );
void LoadFIZ_SpeedControl( std::string const &Line );

View File

@@ -8617,7 +8617,8 @@ TMoverParameters::update_doors( double const Deltatime ) {
Doors.is_locked =
( true == Doors.has_lock )
&& ( true == Doors.lock_enabled ) && (Vel >= Doors.doorLockSpeed);
&& ( true == Doors.lock_enabled )
&& ( Vel >= 10.0 );
for( auto &door : Doors.instances ) {
// revoke permit if...
@@ -9665,6 +9666,14 @@ bool TMoverParameters::LoadFIZ(std::string chkpath)
continue;
}
if (issection("Headlights:", inputline))
{
startBPT = false;
fizlines.emplace("Headlights", inputline);
LoadFIZ_Headlights(inputline);
continue;
}
if (issection("Blending:", inputline)) {
startBPT = false; LISTLINE = 0;
@@ -9934,6 +9943,13 @@ bool TMoverParameters::LoadFIZ(std::string chkpath)
else
result = false;
if (!modernContainOffPos)
modernDimmerState = 2; // jak nie ma opcji wylaczonej to niech sie odpali normalnie
if (!enableModernDimmer)
{
modernDimmerState = 2;
}
WriteLog("CERROR: " + to_string(ConversionError) + ", SUCCES: " + to_string(result));
return result;
}
@@ -10025,6 +10041,18 @@ void TMoverParameters::LoadFIZ_Load( std::string const &line ) {
extract_value( UnLoadSpeed, "UnLoadSpeed", line, "" );
}
void TMoverParameters::LoadFIZ_Headlights(std::string const &line)
{
extract_value(refR, "LampRed", line, "");
extract_value(refG, "LampGreen", line, "");
extract_value(refB, "LampBlue", line, "");
extract_value(dimMultiplier, "DimmedMultiplier", line, "");
extract_value(normMultiplier, "NormalMultiplier", line, "");
extract_value(highDimMultiplier, "HighbeamDimmedMultiplier", line, "");
extract_value(highMultiplier, "HighBeamMultiplier", line, "");
}
void TMoverParameters::LoadFIZ_Dimensions( std::string const &line ) {
extract_value( Dim.L, "L", line, "" );
@@ -10290,7 +10318,7 @@ void TMoverParameters::LoadFIZ_Doors( std::string const &line ) {
extract_value( Doors.has_warning, "DoorClosureWarning", line, "" );
extract_value( Doors.has_autowarning, "DoorClosureWarningAuto", line, "" );
extract_value( Doors.has_lock, "DoorBlocked", line, "" );
extract_value(Doors.doorLockSpeed, "DoorLockSpeed", line, "");
{
auto const remotedoorcontrol {
( Doors.open_control == control_t::driver )
@@ -10538,10 +10566,6 @@ void TMoverParameters::LoadFIZ_Cntrl( std::string const &line ) {
}
// mbrake
extract_value( MBrake, "ManualBrake", line, "" );
// maksymalna predkosc dostepna na tarczce predkosciomierza
extract_value(maxTachoSpeed, "MaxTachoSpeed", line, "");
// dynamicbrake
{
std::map<std::string, int> dynamicbrakes{
@@ -11119,6 +11143,8 @@ void TMoverParameters::LoadFIZ_Switches( std::string const &Input ) {
extract_value( UniversalResetButtonFlag[ 0 ], "RelayResetButton1", Input, "" );
extract_value( UniversalResetButtonFlag[ 1 ], "RelayResetButton2", Input, "" );
extract_value( UniversalResetButtonFlag[ 2 ], "RelayResetButton3", Input, "" );
extract_value(enableModernDimmer, "ModernDimmer", Input, "");
extract_value(modernContainOffPos, "ModernDimmerOffPosition", Input, "");
// pantograph presets
{
auto &presets { PantsPreset.first };

113
Train.cpp
View File

@@ -377,6 +377,8 @@ TTrain::commandhandler_map const TTrain::m_commandhandlers = {
{ user_command::headlighttogglerearupper, &TTrain::OnCommand_headlighttogglerearupper },
{ user_command::headlightenablerearupper, &TTrain::OnCommand_headlightenablerearupper },
{ user_command::headlightdisablerearupper, &TTrain::OnCommand_headlightdisablerearupper },
{user_command::modernlightdimmerdecrease, &TTrain::OnCommand_modernlightdimmerdecrease},
{user_command::modernlightdimmerincrease, &TTrain::OnCommand_modernlightdimmerincrease},
{ user_command::redmarkertogglerearleft, &TTrain::OnCommand_redmarkertogglerearleft },
{ user_command::redmarkerenablerearleft, &TTrain::OnCommand_redmarkerenablerearleft },
{ user_command::redmarkerdisablerearleft, &TTrain::OnCommand_redmarkerdisablerearleft },
@@ -4699,6 +4701,44 @@ void TTrain::OnCommand_headlightdisablerearupper( TTrain *Train, command_data co
}
}
void TTrain::OnCommand_modernlightdimmerincrease(TTrain* Train, command_data const& Command)
{
if (!Train->mvOccupied->enableModernDimmer)
return; // if modern dimmer is disabled, skip entire command
if (Command.action == GLFW_PRESS)
{
// update modern dimmer state
if (Train->mvOccupied->modernDimmerState < 4)
Train->mvOccupied->modernDimmerState++;
Train->Dynamic()->SetLights();
// visual feedback
if (Train->ggModernLightDimSw.SubModel != nullptr)
if (Train->mvOccupied->modernContainOffPos)
Train->ggModernLightDimSw.UpdateValue(Train->mvOccupied->modernDimmerState, Train->dsbSwitch);
else
Train->ggModernLightDimSw.UpdateValue(Train->mvOccupied->modernDimmerState - 1, Train->dsbSwitch);
}
}
void TTrain::OnCommand_modernlightdimmerdecrease(TTrain *Train, command_data const &Command)
{
if (!Train->mvOccupied->enableModernDimmer)
return; // if modern dimmer is disabled, skip entire command
if (Command.action == GLFW_PRESS)
{
byte minPos = (Train->mvOccupied->modernContainOffPos) ? 0 : 1; // prevent switching to 0 if its not enabled
// update modern dimmer state
if (Train->mvOccupied->modernDimmerState > minPos)
Train->mvOccupied->modernDimmerState--;
Train->Dynamic()->SetLights();
// visual feedback
if (Train->ggModernLightDimSw.SubModel != nullptr)
if (Train->mvOccupied->modernContainOffPos)
Train->ggModernLightDimSw.UpdateValue(Train->mvOccupied->modernDimmerState, Train->dsbSwitch);
else
Train->ggModernLightDimSw.UpdateValue(Train->mvOccupied->modernDimmerState - 1, Train->dsbSwitch);
}
}
void TTrain::OnCommand_redmarkertogglerearleft( TTrain *Train, command_data const &Command ) {
if( Command.action == GLFW_PRESS ) {
// NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc
@@ -4878,10 +4918,12 @@ void TTrain::OnCommand_endsignalstoggle( TTrain *Train, command_data const &Comm
}
void TTrain::OnCommand_headlightsdimtoggle( TTrain *Train, command_data const &Command ) {
if (Train->DynamicObject->MoverParameters->enableModernDimmer)
return;
if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down
if( false == Train->DynamicObject->DimHeadlights ) {
if (Train->DynamicObject->MoverParameters->modernDimmerState == 2)
{
// turn on
OnCommand_headlightsdimenable( Train, Command );
}
@@ -4894,37 +4936,57 @@ void TTrain::OnCommand_headlightsdimtoggle( TTrain *Train, command_data const &C
void TTrain::OnCommand_headlightsdimenable( TTrain *Train, command_data const &Command ) {
if (Train->DynamicObject->MoverParameters->enableModernDimmer)
return;
if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down
if( Train->ggDimHeadlightsButton.SubModel == nullptr ) {
if( Train->ggDimHeadlightsButton.SubModel != nullptr ) {
// TODO: proper control deviced definition for the interiors, that doesn't hinge of presence of 3d submodels
WriteLog( "Dim Headlights switch is missing, or wasn't defined" );
return;
}
// visual feedback
Train->ggDimHeadlightsButton.UpdateValue(1.0, Train->dsbSwitch);
}
if( true == Train->DynamicObject->DimHeadlights ) { return; } // already enabled
/* // to jest stara logika
if (true == Train->DynamicObject->DimHeadlights)
{
return;
} // already enabled
Train->DynamicObject->DimHeadlights = true;
*/
WriteLog("Switch do 1");
Train->DynamicObject->MoverParameters->modernDimmerState = 1; // ustawiamy modern dimmer na flage przyciemnienia
Train->DynamicObject->RaLightsSet(Train->DynamicObject->MoverParameters->iLights[0],
Train->DynamicObject->MoverParameters->iLights[1]
); // aktualizacja swiatelek
}
}
void TTrain::OnCommand_headlightsdimdisable( TTrain *Train, command_data const &Command ) {
if (Train->DynamicObject->MoverParameters->enableModernDimmer) // nie wiem dlaczego to tak dziala ze jest odwrocona logika
return;
if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down
if( Train->ggDimHeadlightsButton.SubModel == nullptr ) {
if( Train->ggDimHeadlightsButton.SubModel != nullptr ) {
// TODO: proper control deviced definition for the interiors, that doesn't hinge of presence of 3d submodels
WriteLog( "Dim Headlights switch is missing, or wasn't defined" );
return;
}
// visual feedback
Train->ggDimHeadlightsButton.UpdateValue(0.0, Train->dsbSwitch);
}
/* // stara logika przyciemniania
if( false == Train->DynamicObject->DimHeadlights ) { return; } // already enabled
Train->DynamicObject->DimHeadlights = false;
*/
WriteLog("Switch do 2");
Train->DynamicObject->MoverParameters->modernDimmerState = 2; // ustawiamy modern dimmer na flage rozjasnienia
Train->DynamicObject->RaLightsSet(
Train->DynamicObject->MoverParameters->iLights[0],
Train->DynamicObject->MoverParameters->iLights[1]
); // aktualizacja swiatelek
}
}
@@ -6943,23 +7005,16 @@ bool TTrain::Update( double const Deltatime )
// McZapkie: predkosc wyswietlana na tachometrze brana jest z obrotow kol
auto const maxtacho { 3.0 };
double maxSpeed = mvControlled->Vmax * 1.05; // zachowanie starej logiki jak nie ma definicji max tarczki
if (mvOccupied->maxTachoSpeed != 0)
{
maxSpeed = mvOccupied->maxTachoSpeed;
}
fTachoVelocity = static_cast<float>(std::min(std::abs(11.31 * mvControlled->WheelDiameter * mvControlled->nrot), maxSpeed));
fTachoVelocity = static_cast<float>( std::min( std::abs(11.31 * mvControlled->WheelDiameter * mvControlled->nrot), mvControlled->Vmax * 1.05) );
{ // skacze osobna zmienna
float ff = simulation::Time.data().wSecond; // skacze co sekunde - pol sekundy
// pomiar, pol sekundy ustawienie
if (ff != fTachoTimer) // jesli w tej sekundzie nie zmienial
{
if (fTachoVelocity >= 5) // jedzie
if (fTachoVelocity > 1) // jedzie
fTachoVelocityJump = fTachoVelocity + (2.0 - LocalRandom(3) + LocalRandom(3)) * 0.5;
else if (fTachoVelocity < 5 && fTachoVelocity > 1)
fTachoVelocityJump = Random(0, 4); // tu ma sie bujac jak wariat i zatrzymac na jakiejs predkosci
// fTachoVelocityJump = 0; // stoi
else
fTachoVelocityJump = 0; // stoi
fTachoTimer = ff; // juz zmienil
}
}
@@ -8030,12 +8085,14 @@ bool TTrain::Update( double const Deltatime )
ggRightLightButton.Update();
ggLeftEndLightButton.Update();
ggRightEndLightButton.Update();
ggModernLightDimSw.Update();
// hunter-230112
ggRearUpperLightButton.Update();
ggRearLeftLightButton.Update();
ggRearRightLightButton.Update();
ggRearLeftEndLightButton.Update();
ggRearRightEndLightButton.Update();
ggDimHeadlightsButton.Update();
ggDimHeadlightsButton.Update();
//------------
ggConverterButton.Update();
@@ -9626,6 +9683,7 @@ void TTrain::clear_cab_controls()
ggRightLightButton.Clear();
ggUpperLightButton.Clear();
ggDimHeadlightsButton.Clear();
ggModernLightDimSw.Clear();
ggLeftEndLightButton.Clear();
ggRightEndLightButton.Clear();
ggLightsButton.Clear();
@@ -9657,6 +9715,14 @@ void TTrain::set_cab_controls( int const Cab ) {
m_linebreakerstate > 0 ? 1.f :
0.f ) );
}
if (ggModernLightDimSw.SubModel != nullptr) {
if (mvOccupied->modernContainOffPos)
ggModernLightDimSw.PutValue(mvOccupied->modernDimmerState);
else
ggModernLightDimSw.PutValue(mvOccupied->modernDimmerState - 1);
}
// motor connectors
ggStLinOffButton.PutValue(
( mvControlled->StLinSwitchOff ?
@@ -9784,7 +9850,7 @@ void TTrain::set_cab_controls( int const Cab ) {
ggRightLightButton.PutValue( -1.f );
}
}
if( true == DynamicObject->DimHeadlights ) {
if( 1 == DynamicObject->MoverParameters->modernDimmerState ) {
ggDimHeadlightsButton.PutValue( 1.f );
}
// cab lights
@@ -10219,6 +10285,7 @@ bool TTrain::initialize_gauge(cParser &Parser, std::string const &Label, int con
{ "leftend_sw:", ggLeftEndLightButton },
{ "rightend_sw:", ggRightEndLightButton },
{ "lights_sw:", ggLightsButton },
{ "moderndimmer_sw:", ggModernLightDimSw },
{ "rearupperlight_sw:", ggRearUpperLightButton },
{ "rearleftlight_sw:", ggRearLeftLightButton },
{ "rearrightlight_sw:", ggRearRightLightButton },

View File

@@ -401,6 +401,8 @@ class TTrain {
static void OnCommand_headlighttogglerearupper( TTrain *Train, command_data const &Command );
static void OnCommand_headlightenablerearupper( TTrain *Train, command_data const &Command );
static void OnCommand_headlightdisablerearupper( TTrain *Train, command_data const &Command );
static void OnCommand_modernlightdimmerincrease(TTrain *Train, command_data const &Command);
static void OnCommand_modernlightdimmerdecrease(TTrain *Train, command_data const &Command);
static void OnCommand_redmarkertogglerearleft( TTrain *Train, command_data const &Command );
static void OnCommand_redmarkerenablerearleft( TTrain *Train, command_data const &Command );
static void OnCommand_redmarkerdisablerearleft( TTrain *Train, command_data const &Command );
@@ -580,6 +582,7 @@ public: // reszta może by?publiczna
TGauge ggRightEndLightButton;
TGauge ggLightsButton; // przelacznik reflektorow (wszystkich)
TGauge ggDimHeadlightsButton; // headlights dimming switch
TGauge ggModernLightDimSw; // modern lights dimmer
// hunter-230112: przelacznik swiatel tylnich
TGauge ggRearUpperLightButton;

View File

@@ -153,6 +153,8 @@ commanddescription_sequence Commands_descriptions = {
{ "radiovolumeset", command_target::vehicle, command_mode::oneoff },
{ "cabchangeforward", command_target::vehicle, command_mode::oneoff },
{ "cabchangebackward", command_target::vehicle, command_mode::oneoff },
{"modernlightdimmerdecrease", command_target::vehicle, command_mode::oneoff},
{"modernlightdimmerincrease", command_target::vehicle, command_mode::oneoff},
{ "viewturn", command_target::entity, command_mode::oneoff },
{ "movehorizontal", command_target::entity, command_mode::oneoff },
{ "movehorizontalfast", command_target::entity, command_mode::oneoff },

View File

@@ -147,6 +147,9 @@ enum class user_command {
cabchangeforward,
cabchangebackward,
modernlightdimmerdecrease,
modernlightdimmerincrease,
viewturn,
movehorizontal,
movehorizontalfast,

View File

@@ -506,7 +506,7 @@ drivermouse_input::bindings( std::string const &Control ) const {
void
drivermouse_input::default_bindings() {
// pierwsza komenda jest od zwiekszania a druga od zmniejszania - ewentualnie kolejno lewy i prawy przycisk
m_buttonbindings = {
{ "jointctrl:", {
user_command::jointcontrollerset,
@@ -737,6 +737,9 @@ drivermouse_input::default_bindings() {
{ "dimheadlights_sw:", {
user_command::headlightsdimtoggle,
user_command::none } },
{"moderndimmer_sw:", {
user_command::modernlightdimmerincrease,
user_command::modernlightdimmerdecrease } },
{ "leftend_sw:", {
user_command::redmarkertoggleleft,
user_command::none } },

View File

@@ -65,17 +65,42 @@ light_array::update() {
light.count = 0
+ ( ( lights & light::headlight_left ) ? 1 : 0 )
+ ( ( lights & light::headlight_right ) ? 1 : 0 )
+ ( ( lights & light::headlight_upper ) ? 1 : 0 );
+ ( ( lights & light::headlight_upper ) ? 1 : 0 )
+ ( ( lights & light::highbeamlight_left ) ? 1: 0)
+ ( ( lights & light::highbeamlight_right ) ? 1 : 0);
if( light.count > 0 ) {
light.intensity = std::max(0.0f, std::log((float)light.count + 1.0f));
light.intensity *= ( light.owner->DimHeadlights ? 0.6f : 1.0f );
if (light.owner->DimHeadlights && !light.owner->HighBeamLights) // tylko przyciemnione
light.intensity *= light.owner->MoverParameters->dimMultiplier;
else if (!light.owner->DimHeadlights && !light.owner->HighBeamLights) // normalne
light.intensity *= light.owner->MoverParameters->normMultiplier;
else if (light.owner->DimHeadlights && light.owner->HighBeamLights) // przyciemnione dlugie
light.intensity *= light.owner->MoverParameters->highDimMultiplier;
else if (!light.owner->DimHeadlights && light.owner->HighBeamLights) // dlugie zwykle
light.intensity *= light.owner->MoverParameters->highMultiplier;
// TBD, TODO: intensity can be affected further by other factors
light.state = {
( ( lights & light::headlight_left ) ? 1.f : 0.f ),
( ( lights & light::headlight_left | light::highbeamlight_left ) ? 1.f : 0.f ),
( ( lights & light::headlight_upper ) ? 1.f : 0.f ),
( ( lights & light::headlight_right ) ? 1.f : 0.f ) };
light.state *= ( light.owner->DimHeadlights ? 0.6f : 1.0f );
( ( lights & light::headlight_right | light::highbeamlight_right) ? 1.f : 0.f ) };
light.color = {
static_cast<float>(light.owner->MoverParameters->refR) / 255.0f,
static_cast<float>(light.owner->MoverParameters->refG) / 255.0f,
static_cast<float>(light.owner->MoverParameters->refB) / 255.0f
};
if (light.owner->DimHeadlights && !light.owner->HighBeamLights) // tylko przyciemnione
light.state *= light.owner->MoverParameters->dimMultiplier;
else if (!light.owner->DimHeadlights && !light.owner->HighBeamLights)
light.state *= light.owner->MoverParameters->normMultiplier;
else if (light.owner->DimHeadlights && light.owner->HighBeamLights) // przyciemnione dlugie
light.state *= light.owner->MoverParameters->highDimMultiplier;
else if (!light.owner->DimHeadlights && light.owner->HighBeamLights) // dlugie zwykle
light.state *= light.owner->MoverParameters->highMultiplier;
}
else {
light.intensity = 0.0f;

View File

@@ -249,6 +249,7 @@ std::string locale::label_cab_control(std::string const &Label)
{ "leftlight_sw:", STRN("left headlight") },
{ "rightlight_sw:", STRN("right headlight") },
{ "dimheadlights_sw:", STRN("headlights dimmer") },
{ "moderndimmer_sw:", STRN("headlights dimmer") },
{ "leftend_sw:", STRN("left marker light") },
{ "rightend_sw:", STRN("right marker light") },
{ "lights_sw:", STRN("light pattern") },
@@ -319,7 +320,7 @@ std::string locale::label_cab_control(std::string const &Label)
{ "universal6:", STRN("interactive part") },
{ "universal7:", STRN("interactive part") },
{ "universal8:", STRN("interactive part") },
{ "universal9:", STRN("interactive part") }
{ "universal9:", STRN("interactive part") },
};
auto const it = cabcontrols_labels.find( Label );