From 242474dd11130b56f73dba1eb167efa738206dd3 Mon Sep 17 00:00:00 2001 From: Hirek193 Date: Sun, 29 Nov 2026 12:33:13 +0100 Subject: [PATCH] refactor(physics): the lights, the load and the event flags are private to the vehicle - The lights switched on at each end (iLights) are LitLights(), changed through SetLitLights(): the cab's switches, the AI's light patterns and the scenery's toggles of the end signals all go through it. - The exchange of the load, which TDynamicObject ran by setting the status, the amount and the mass itself, goes through UnloadStep(), LoadStep(), FinishLoadExchange() and AcknowledgeLoadExchange(), with the same arithmetic; the change of the kind of the load is taken once (TakeLoadTypeChange()). - The events the physics reports for the sounds to follow up are raised and cleared by name (RaiseEventFlag(), ClearEventFlag(), ClearSoundFlags()). No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit. --- application/driveruipanels.cpp | 2 +- physics/components/body.cpp | 12 +-- physics/components/collisions.cpp | 14 +-- physics/components/commands.cpp | 8 +- physics/components/controllers.cpp | 24 ++--- physics/components/doors.cpp | 62 ++++++++----- physics/components/drive.cpp | 7 +- physics/components/electrics.cpp | 10 +-- physics/components/fizsections.cpp | 2 +- physics/components/pneumatics.cpp | 2 +- physics/components/setup.cpp | 6 +- physics/components/traction.cpp | 18 ++-- physics/vehicle.h | 45 ++++++++-- simulation/blackboxrecorder.cpp | 2 +- tests/unit/test_auxiliaries.cpp | 4 +- tests/unit/test_commands.cpp | 14 +-- tests/unit/test_loads.cpp | 44 +++++----- vehicle/ai/driver.cpp | 4 +- vehicle/ai/situation.cpp | 4 +- vehicle/cab/lightcommands.cpp | 136 ++++++++++++++--------------- vehicle/cab/setup.cpp | 10 +-- vehicle/cab/train.cpp | 12 +-- vehicle/cab/update.cpp | 22 ++--- vehicle/dynamic/lifecycle.cpp | 2 +- vehicle/dynamic/lights.cpp | 22 ++--- vehicle/dynamic/load.cpp | 29 +++--- vehicle/dynamic/movement.cpp | 2 +- vehicle/dynamic/sounds.cpp | 18 ++-- vehicle/dynamic/update.cpp | 4 +- vehicle/dynamic/vehicletable.cpp | 2 +- vehicle/dynamic/visual.cpp | 44 +++++----- widgets/vehicleparams.cpp | 10 +-- world/Event.cpp | 8 +- world/station.cpp | 12 +-- 34 files changed, 331 insertions(+), 286 deletions(-) diff --git a/application/driveruipanels.cpp b/application/driveruipanels.cpp index f667e43a3..ae9eebe15 100644 --- a/application/driveruipanels.cpp +++ b/application/driveruipanels.cpp @@ -802,7 +802,7 @@ debug_panel::update_section_vehicle( std::vector &Output ) { STR_C("Name: %s%s\nLoad: %.0f %s\nStatus: %s%s\nCouplers:\n front: %s\n rear: %s"), physics.Name.c_str(), std::string( isowned ? STR(", owned by: ") + vehicle.ctOwner->OwnerName() : "" ).c_str(), - physics.LoadAmount, + physics.LoadAmount(), physics.LoadType.name.c_str(), physics.EngineDescription( 0 ).c_str(), // TODO: put wheel flat reporting in the enginedescription() diff --git a/physics/components/body.cpp b/physics/components/body.cpp index 7a54d9e5b..145f7e141 100644 --- a/physics/components/body.cpp +++ b/physics/components/body.cpp @@ -73,8 +73,8 @@ physics::Vehicle::Vehicle(double VelInitial, std::string const &TypeNameInit, st WriteLog("init default physic values for " + NameInit + ", [" + TypeNameInit + "]"); // BrakeLevelSet(-2); //Pascal ustawia na 0, przestawimy na odcięcie (CHK jest jeszcze nie wczytane!) - iLights[0] = 0; - iLights[1] = 0; // światła zgaszone + litLights[0] = 0; + litLights[1] = 0; // światła zgaszone // inicjalizacja stalych for (auto &scheme : RList) @@ -410,7 +410,7 @@ void physics::Vehicle::compute_movement_(double const Deltatime) { // sprawdzanie i ewentualnie wykonywanie->kasowanie poleceń - if (LoadStatus > 0) // czas doliczamy tylko jeśli trwa (roz)ładowanie + if (loadStatus > 0) // czas doliczamy tylko jeśli trwa (roz)ładowanie LastLoadChangeTime += Deltatime; // czas (roz)ładunku RunInternalCommand(); @@ -457,7 +457,7 @@ void physics::Vehicle::compute_movement_(double const Deltatime) // automatyczny rozruch, silnik spalinowy if (Drive().UpdateEngine(*this, Deltatime)) { - SetFlag(SoundFlag, sound::relay); + SetFlag(soundFlag, sound::relay); } // TODO: gather and move current calculations to dedicated method @@ -747,7 +747,7 @@ void physics::Vehicle::ComputeMass() // Ra: na razie tak, ale nie wszędzie masy wirujące się wliczają TotalMass = Mass + Mred; - if (LoadAmount == 0) + if (loadAmount == 0) { return; } @@ -765,7 +765,7 @@ void physics::Vehicle::ComputeMass() loadtypeunitweight = lookup != simulation::Weights.end() ? lookup->second : 1000.f; // legacy default unit weight value } - TotalMass += LoadAmount * loadtypeunitweight; + TotalMass += loadAmount * loadtypeunitweight; } // ************************************************************************************************* diff --git a/physics/components/collisions.cpp b/physics/components/collisions.cpp index d8b34be61..b78a9010f 100644 --- a/physics/components/collisions.cpp +++ b/physics/components/collisions.cpp @@ -199,7 +199,7 @@ void physics::Vehicle::damage_coupler(VehicleEnd const End) } // HACK: don't break articulated couplings no matter what if (DamageFlag.Set(VehicleDamage::coupling)) - EventFlag = true; + eventFlag = true; auto const hosetorn{thiscoupler.CouplingFlag.HasAll(Coupling::brakeHose)}; if (hosetorn) @@ -248,7 +248,7 @@ collision::crush_curve physics::Vehicle::crush_curve_at(VehicleEnd const End) co double physics::Vehicle::buffer_height_at(VehicleEnd const End) const { - auto const loadshare{MaxLoad > 0.f ? LoadAmount / MaxLoad : 0.0}; + auto const loadshare{maxLoad > 0.f ? loadAmount / maxLoad : 0.0}; return collision::buffer_height(Couplers[End].collision, collision_kind(), loadshare); } @@ -264,7 +264,7 @@ void physics::Vehicle::derail_in_collision(DerailReason const Reason, std::strin DerailAcceleration = 0.0; DerailSide = 0; CollisionDerail = Reason; - EventFlag = true; + eventFlag = true; MainSwitch(false, range_t::local); if (Vel < 5.0) { @@ -671,7 +671,7 @@ double physics::Vehicle::centre_of_gravity() const auto const kind{EngineType == TEngineType::None ? derailment::vehicle_class::unpowered : derailment::vehicle_class::powered}; auto const empty{CentreOfGravity > 0.0 ? CentreOfGravity : derailment::default_centre_of_gravity(Dim.H, kind)}; auto const loadmass{TotalMass - Mass - Mred}; - auto const loadshare{MaxLoad > 0.f ? LoadAmount / MaxLoad : 1.0}; + auto const loadshare{maxLoad > 0.f ? loadAmount / maxLoad : 1.0}; return derailment::loaded_centre_of_gravity(empty, Mass, loadmass, loadshare, Floor, Dim.H); } @@ -739,7 +739,7 @@ void physics::Vehicle::derail(derailment::verdict const &Verdict, derailment::ve // out of the curve; a buckle bending the line against the curve more than the curve does throws it into the curve DerailAcceleration = std::abs(Track.radius) > 1e-3 && derailment::line_curvature(Track) < 0.0 ? -Verdict.acceleration : Verdict.acceleration; DerailSide = 0; - EventFlag = true; + eventFlag = true; MainSwitch(false, range_t::local); // the brake hoses tear: the brake pipe vents and the rest of the train brakes in emergency tear_brake_hoses(*this); @@ -797,7 +797,7 @@ void physics::Vehicle::Derail(DerailReason const Reason) { if (DamageFlag.Set(VehicleDamage::derailed)) { - EventFlag = true; + eventFlag = true; MainSwitch(false, range_t::local); auto const velocity{V}; @@ -861,7 +861,7 @@ void physics::Vehicle::pull_off(int const Side, double const Acceleration, std:: DerailCause = derail_motion::cause::pulled_off; DerailAcceleration = Acceleration; DerailSide = Side; - EventFlag = true; + eventFlag = true; MainSwitch(false, range_t::local); tear_brake_hoses(*this); derailment_monitor.reset(); diff --git a/physics/components/commands.cpp b/physics/components/commands.cpp index da3ffc58b..65d16f643 100644 --- a/physics/components/commands.cpp +++ b/physics/components/commands.cpp @@ -734,16 +734,16 @@ bool physics::Vehicle::RunLoadCommand(VehicleCommand const Command, double CValu { OK = false; // będzie powtarzane aż się załaduje if (Vel < 0.1 // tolerance margin for small vehicle movements in the consist - && MaxLoad > 0 && LoadAmount < MaxLoad * (1.0 + OverLoadFactor) && Distance(Loc, CommandIn.Location, Dim, Dim) < (CValue2 > 1.0 ? CValue2 : 10.0)) + && maxLoad > 0 && loadAmount < maxLoad * (1.0 + OverLoadFactor) && Distance(Loc, CommandIn.Location, Dim, Dim) < (CValue2 > 1.0 ? CValue2 : 10.0)) { // ten peron/rampa auto const loadname{ToLower(std::string{Argument})}; - if (LoadAmount == 0.f) + if (loadAmount == 0.f) { AssignLoad(loadname); } OK = LoadingDone(LoadSpeed, - loadname); // zmienia LoadStatus + loadname); // zmienia loadStatus } else { @@ -755,7 +755,7 @@ bool physics::Vehicle::RunLoadCommand(VehicleCommand const Command, double CValu { OK = false; // będzie powtarzane aż się rozładuje if (Vel < 0.1 // tolerance margin for small vehicle movements in the consist - && LoadAmount > 0 // czy jest co rozladowac? + && loadAmount > 0 // czy jest co rozladowac? && Distance(Loc, CommandIn.Location, Dim, Dim) < (CValue2 > 1.0 ? CValue2 : 10.0)) { // ten peron /*mozna to rozladowac*/ diff --git a/physics/components/controllers.cpp b/physics/components/controllers.cpp index 778f05a25..f16a99577 100644 --- a/physics/components/controllers.cpp +++ b/physics/components/controllers.cpp @@ -148,7 +148,7 @@ bool physics::Vehicle::IncMainCtrlSeriesMotor(int const CtrlSpeed) /* NOTE: disabled, relay configuration was moved to compute_movement_ if( true == MaxCurrentSwitch( false )) { // wylaczanie wysokiego rozruchu - SetFlag( SoundFlag, sound::relay ); + SetFlag( soundFlag, sound::relay ); } */ if (TrainType == train_type::et42) @@ -601,7 +601,7 @@ bool physics::Vehicle::AutoRelayShuntStep(bool const ARFASI2) if (lineContactors.TimeSinceSwitch() > CtrlDelay && ARFASI2) { ++ScndCtrlActualPos; - SetFlag(SoundFlag, sound::shuntfield); + SetFlag(soundFlag, sound::shuntfield); OK = true; } } @@ -610,7 +610,7 @@ bool physics::Vehicle::AutoRelayShuntStep(bool const ARFASI2) if (lineContactors.TimeSinceSwitch() > CtrlDownDelay && TrainType != train_type::emu) { --ScndCtrlActualPos; - SetFlag(SoundFlag, sound::shuntfield); + SetFlag(soundFlag, sound::shuntfield); OK = true; } } @@ -643,7 +643,7 @@ bool physics::Vehicle::AutoRelayMainStep(bool const ARFASI) if (lineContactors.TimeSinceSwitch() > CtrlDownDelay) { --ScndCtrlActualPos; // boczniki nie dzialaja na poz. oporowych - SetFlag(SoundFlag, sound::shuntfield); + SetFlag(soundFlag, sound::shuntfield); OK = true; } } @@ -677,7 +677,7 @@ bool physics::Vehicle::AutoRelayMainUp(bool const ARFASI) } if (RList[MainCtrlActualPos].R == 0) { - SetFlag(SoundFlag, sound::parallel | sound::loud); + SetFlag(soundFlag, sound::parallel | sound::loud); OK = true; } } @@ -727,12 +727,12 @@ bool physics::Vehicle::AutoRelayMainNotchUp() if (RList[MainCtrlActualPos].R == 0 && MainCtrlActualPos != MainCtrlPosNo) { // wejscie na bezoporowa - SetFlag(SoundFlag, sound::parallel | sound::loud); + SetFlag(soundFlag, sound::parallel | sound::loud); } else if (RList[MainCtrlActualPos].R > 0 && RList[MainCtrlActualPos - 1].R == 0) { // wejscie na drugi uklad - SetFlag(SoundFlag, sound::parallel); + SetFlag(soundFlag, sound::parallel); } } return OK; @@ -750,7 +750,7 @@ bool physics::Vehicle::AutoRelayMainDown() OK = true; if (RList[MainCtrlActualPos].R == 0) { - SetFlag(SoundFlag, sound::parallel); + SetFlag(soundFlag, sound::parallel); } } else if (lineContactors.TimeSinceSwitch() > CtrlDownDelay) @@ -764,7 +764,7 @@ bool physics::Vehicle::AutoRelayMainDown() if (MainCtrlActualPos > 0 && RList[MainCtrlActualPos].R == 0) { // dzwieki schodzenia z bezoporowej} - SetFlag(SoundFlag, sound::parallel); + SetFlag(soundFlag, sound::parallel); } } return OK; @@ -784,7 +784,7 @@ bool physics::Vehicle::AutoRelayLineContactorsStep(bool const motorconnectorsoff lineContactors.Close(); MainCtrlActualPos = 1; DelayCtrlFlag = false; - SetFlag(SoundFlag, sound::relay | sound::loud); + SetFlag(soundFlag, sound::relay | sound::loud); OK = true; } } @@ -818,7 +818,7 @@ bool physics::Vehicle::CamshaftRunDown() if (ScndCtrlActualPos > 0) { --ScndCtrlActualPos; - SetFlag(SoundFlag, sound::shuntfield); + SetFlag(soundFlag, sound::shuntfield); } else { @@ -875,7 +875,7 @@ bool physics::Vehicle::CamshaftRunDownEMU() { // potem boki ++ScndCtrlActualPos; - SetFlag(SoundFlag, sound::shuntfield); + SetFlag(soundFlag, sound::shuntfield); } else { diff --git a/physics/components/doors.cpp b/physics/components/doors.cpp index 994015968..5fecf74ec 100644 --- a/physics/components/doors.cpp +++ b/physics/components/doors.cpp @@ -76,13 +76,13 @@ bool physics::Vehicle::AssignLoad(std::string const &Loadname, float const Amoun if (Loadname.empty()) { // empty the vehicle if requested - LoadTypeChange = LoadType.name != Loadname; + loadTypeChange = LoadType.name != Loadname; LoadType = load_attributes(); - LoadAmount = 0.f; + loadAmount = 0.f; return true; } // can't mix load types, at least for the time being - if (LoadAmount > 0 && LoadType.name != Loadname) + if (loadAmount > 0 && LoadType.name != Loadname) { return false; } @@ -93,13 +93,29 @@ bool physics::Vehicle::AssignLoad(std::string const &Loadname, float const Amoun // didn't find matching load configuration, this type is unsupported return false; } - LoadTypeChange = LoadType.name != Loadname; + loadTypeChange = LoadType.name != Loadname; LoadType = *loadattributes; - LoadAmount = safe_clamp(Amount, 0.f, MaxLoad); + loadAmount = safe_clamp(Amount, 0.f, maxLoad); ComputeMass(); return true; } +// a step of the exchange of the load: so much taken out, the mass with it +void physics::Vehicle::UnloadStep(float const Amount) +{ + loadStatus = 1; + loadAmount = std::max(0.f, loadAmount - Amount); + ComputeMass(); +} + +// a step of the exchange of the load: so much put in, up to the capacity, the mass with it +void physics::Vehicle::LoadStep(float const Amount) +{ + loadStatus = 2; + loadAmount = std::min(maxLoad, loadAmount + Amount); // std::max not strictly needed but, eh + ComputeMass(); +} + // ************************************************************************************************* // Q: 20160713 // Test zakończenia załadunku / rozładunku @@ -110,39 +126,39 @@ bool physics::Vehicle::LoadingDone(double const LSpeed, std::string_view Loadnam if (LSpeed == 0.0) { // zerowa prędkość zmiany, to koniec - LoadStatus = 4; + loadStatus = 4; return true; } if (Loadname.empty()) { - return LoadStatus >= 4; + return loadStatus >= 4; } if (Loadname != LoadType.name) { - return LoadStatus >= 4; + return loadStatus >= 4; } // test zakończenia załadunku/rozładunku // load exchange speed is reduced if the wagon is overloaded - auto const loadchange{static_cast(std::abs(LSpeed * LastLoadChangeTime) * (LoadAmount > MaxLoad ? 0.5 : 1.0))}; + auto const loadchange{static_cast(std::abs(LSpeed * LastLoadChangeTime) * (loadAmount > maxLoad ? 0.5 : 1.0))}; if (LSpeed < 0) { // gdy rozładunek - LoadStatus = 2; // trwa rozładunek (włączenie naliczania czasu) + loadStatus = 2; // trwa rozładunek (włączenie naliczania czasu) if (loadchange > 0) // jeśli coś przeładowano { LastLoadChangeTime = 0; // naliczony czas został zużyty - LoadAmount -= loadchange; // zmniejszenie ilości ładunku + loadAmount -= loadchange; // zmniejszenie ilości ładunku CommandIn.Value1 -= loadchange; // zmniejszenie ilości do rozładowania - if (LoadAmount <= 0 || CommandIn.Value1 <= 0) + if (loadAmount <= 0 || CommandIn.Value1 <= 0) { // pusto lub rozładowano żądaną ilość - LoadStatus = 4; // skończony rozładunek - LoadAmount = safe_clamp(LoadAmount, 0.f, MaxLoad); // ładunek nie może być ujemny + loadStatus = 4; // skończony rozładunek + loadAmount = safe_clamp(loadAmount, 0.f, maxLoad); // ładunek nie może być ujemny } - if (LoadAmount == 0.f) + if (loadAmount == 0.f) { AssignLoad(""); // jak nic nie ma, to nie ma też nazwy } @@ -152,22 +168,22 @@ bool physics::Vehicle::LoadingDone(double const LSpeed, std::string_view Loadnam else if (LSpeed > 0) { // gdy załadunek - LoadStatus = 1; // trwa załadunek (włączenie naliczania czasu) + loadStatus = 1; // trwa załadunek (włączenie naliczania czasu) if (loadchange > 0) // jeśli coś przeładowano { LastLoadChangeTime = 0; // naliczony czas został zużyty - LoadAmount += loadchange; // zwiększenie ładunku + loadAmount += loadchange; // zwiększenie ładunku CommandIn.Value1 -= loadchange; - if (LoadAmount >= MaxLoad * (1.0 + OverLoadFactor) || CommandIn.Value1 <= 0) + if (loadAmount >= maxLoad * (1.0 + OverLoadFactor) || CommandIn.Value1 <= 0) { - LoadStatus = 4; // skończony załadunek - LoadAmount = std::min(static_cast(MaxLoad * (1.0 + OverLoadFactor)), LoadAmount); + loadStatus = 4; // skończony załadunek + loadAmount = std::min(static_cast(maxLoad * (1.0 + OverLoadFactor)), loadAmount); } ComputeMass(); } } - return LoadStatus >= 4; + return loadStatus >= 4; } bool physics::Vehicle::ChangeDoorPermitPreset(int const Change, range_t const Notify) @@ -231,7 +247,7 @@ void physics::Vehicle::PermitDoors_(VehicleSide const Door, bool const State) if (State && State != Doors.instances[Door].open_permit) { - SetFlag(SoundFlag, sound::doorpermit); + SetFlag(soundFlag, sound::doorpermit); } Doors.instances[Door].open_permit = State; } @@ -392,7 +408,7 @@ void physics::Vehicle::update_doors(double const Deltatime) inputs.velocity = Vel; inputs.powered = doors_powered(); inputs.multipleUnit = is_multiple_unit(); - inputs.exchangingLoad = (LoadStatus & (2 | 1)) != 0; + inputs.exchangingLoad = (loadStatus & (2 | 1)) != 0; Doors.Update(inputs, Deltatime); } diff --git a/physics/components/drive.cpp b/physics/components/drive.cpp index fc489a3a9..b160d57b0 100644 --- a/physics/components/drive.cpp +++ b/physics/components/drive.cpp @@ -272,8 +272,11 @@ public: source.SourceType != TPowerSource::CurrentCollector || voltage <= source.CollectorParameters.MaxV || false == source.CollectorParameters.OVP); // wywalanie szybkiego z powodu niewłaściwego napięcia // (a line breaker closed ahead of the pantographs holds without voltage) - vehicle.EventFlag |= true == vehicle.lineBreaker.IsClosed() && ((false == vehicle.protection.UndervoltageHolds() && false == vehicle.lineBreaker.config.pantographsRequireIt) || false == vehicle.protection.OvervoltageHolds()) && - vehicle.MainSwitch(false, vehicle.TrainType == train_type::emu ? range_t::unit : range_t::local); // TODO: check whether we need to send this EMU-wide + if (true == vehicle.lineBreaker.IsClosed() && ((false == vehicle.protection.UndervoltageHolds() && false == vehicle.lineBreaker.config.pantographsRequireIt) || false == vehicle.protection.OvervoltageHolds()) && + vehicle.MainSwitch(false, vehicle.TrainType == train_type::emu ? range_t::unit : range_t::local)) // TODO: check whether we need to send this EMU-wide + { + vehicle.RaiseEventFlag(); + } } bool UpdateEngine(physics::Vehicle &vehicle, double /*dt*/) const override { diff --git a/physics/components/electrics.cpp b/physics/components/electrics.cpp index a40ace064..ec185a5a8 100644 --- a/physics/components/electrics.cpp +++ b/physics/components/electrics.cpp @@ -102,7 +102,7 @@ void physics::Vehicle::UpdateBatteryVoltage(double dt) auto const converteractive{lowVoltage.Is110vAvailable() || (EngineType == DieselElectric && true == lineBreaker.IsClosed()) || (EngineType == DieselEngine && true == lineBreaker.IsClosed())}; if (lowVoltage.DrainBattery(BatteryDrain(dt, converteractive)) && MainSwitch(false) && EngineType != DieselEngine && EngineType != WheelsDriven) - EventFlag = true; // wywalanie szybkiego z powodu zbyt niskiego napiecia + eventFlag = true; // wywalanie szybkiego z powodu zbyt niskiego napiecia } else { @@ -149,11 +149,11 @@ double physics::Vehicle::BatteryDrainCharged(double dt, bool const converteracti sn3 = dt * 0.05; else sn3 = 0; - if (iLights[0] & 63) // 64=blachy, nie ciągną prądu //rozpisać na poszczególne żarówki... + if (litLights[0] & 63) // 64=blachy, nie ciągną prądu //rozpisać na poszczególne żarówki... sn4 = dt * 0.003; else sn4 = 0; - if (iLights[1] & 63) // 64=blachy, nie ciągną prądu + if (litLights[1] & 63) // 64=blachy, nie ciągną prądu sn5 = dt * 0.001; else sn5 = 0; @@ -180,11 +180,11 @@ double physics::Vehicle::BatteryDrainLow(double dt, bool const converteractive) sn3 = dt * 0.001; else sn3 = 0; - if (iLights[0] & 63) // 64=blachy, nie ciągną prądu + if (litLights[0] & 63) // 64=blachy, nie ciągną prądu sn4 = dt * 0.0030; else sn4 = 0; - if (iLights[1] & 63) // 64=blachy, nie ciągną prądu + if (litLights[1] & 63) // 64=blachy, nie ciągną prądu sn5 = dt * 0.0010; else sn5 = 0; diff --git a/physics/components/fizsections.cpp b/physics/components/fizsections.cpp index 0aa4ce4f6..43f86ca05 100644 --- a/physics/components/fizsections.cpp +++ b/physics/components/fizsections.cpp @@ -131,7 +131,7 @@ void physics::Vehicle::LoadFIZ_Load(std::string const &line) LoadAttributes.emplace_back(ToLower(load), minoffset); } - extract_value(MaxLoad, "MaxLoad", line, ""); + extract_value(maxLoad, "MaxLoad", line, ""); extract_value(LoadQuantity, "LoadQ", line, ""); extract_value(OverLoadFactor, "OverLoadFactor", line, ""); extract_value(LoadSpeed, "LoadSpeed", line, ""); diff --git a/physics/components/pneumatics.cpp b/physics/components/pneumatics.cpp index 146557cf0..5ac5ccf5d 100644 --- a/physics/components/pneumatics.cpp +++ b/physics/components/pneumatics.cpp @@ -789,7 +789,7 @@ void physics::Vehicle::CompressorCheck(double dt) } if (step.vented) { - SetFlag(SoundFlag, sound::relay | sound::loud); + SetFlag(soundFlag, sound::relay | sound::loud); } // a compressor not driven by the engine doesn't draw power (some 5 A) from the high- or low voltage circuit yet } diff --git a/physics/components/setup.cpp b/physics/components/setup.cpp index c3c275366..7e7ca796d 100644 --- a/physics/components/setup.cpp +++ b/physics/components/setup.cpp @@ -147,18 +147,18 @@ bool physics::Vehicle::CheckLocomotiveParameters(bool ReadyFlag, int /*Dir*/) if (brakes.loadSetting > 0) { - if (LoadAmount < MaxLoad * 0.45) + if (loadAmount < maxLoad * 0.45) { IncBrakeMult(); IncBrakeMult(); DecBrakeMult(); // TODO: przeinesiono do physics.cpp - if (LoadAmount < MaxLoad * 0.35) + if (loadAmount < maxLoad * 0.35) DecBrakeMult(); } else { IncBrakeMult(); // TODO: przeinesiono do physics.cpp - if (LoadAmount >= MaxLoad * 0.55) + if (loadAmount >= maxLoad * 0.55) IncBrakeMult(); } } diff --git a/physics/components/traction.cpp b/physics/components/traction.cpp index d454b62cd..b3b6e349a 100644 --- a/physics/components/traction.cpp +++ b/physics/components/traction.cpp @@ -249,12 +249,12 @@ void physics::Vehicle::MotorFailuresCheck(double const n) if (MotorCurrent > 0) { if (FuzzyLogic(abs(n), nmax * 1.1, p_elengproblem) && MainSwitch(false)) - EventFlag = true; /*zbyt duze obroty - wywalanie wskutek ognia okreznego*/ + eventFlag = true; /*zbyt duze obroty - wywalanie wskutek ognia okreznego*/ if (DamageFlag.HasAll(VehicleDamage::engine) && FuzzyLogic(MotorCurrent, (double)ImaxLo / 10.0, p_elengproblem) && MainSwitch(false)) - EventFlag = true; /*uszkodzony silnik (uplywy)*/ + eventFlag = true; /*uszkodzony silnik (uplywy)*/ /* or FuzzyLogic(Abs(U/Mn),2*NominalVoltage,1)) then */ /*poprawic potem*/ if ((FuzzyLogic(abs(Im), Imax * 2, p_elengproblem) || FuzzyLogic(abs(n), nmax * 1.11, p_elengproblem)) && DamageFlag.Set(VehicleDamage::engine)) - EventFlag = true; + eventFlag = true; /*! dorobic grzanie oporow rozruchowych i silnika*/ } } @@ -856,7 +856,7 @@ void physics::Vehicle::ShuntFieldRelaysCheck(double const tmpV, double const Pos if (scndCtrlPos != shuntfieldstate) { - SetFlag(SoundFlag, sound::relay | sound::shuntfield); + SetFlag(soundFlag, sound::relay | sound::shuntfield); } } @@ -1428,8 +1428,8 @@ void physics::Vehicle::FuseOff(void) if (!FuseFlag) { FuseFlag = true; - EventFlag = true; - SetFlag(SoundFlag, sound::relay | sound::loud); + eventFlag = true; + SetFlag(soundFlag, sound::relay | sound::loud); } } @@ -1490,7 +1490,7 @@ bool physics::Vehicle::RelayReset(int const Relays, range_t const Notify) if (reset) { - SetFlag(SoundFlag, sound::relay | sound::loud); + SetFlag(soundFlag, sound::relay | sound::loud); } if (Notify != range_t::local) @@ -1520,9 +1520,9 @@ double physics::Vehicle::v2n(void) if (SlippingWheels) // nie ma zwiazku z predkoscia liniowa V { // McZapkie-221103: uszkodzenia kol podczas poslizgu if (deltan > dmgn && FuzzyLogic(deltan, dmgn, p_slippdmg) && DamageFlag.Set(VehicleDamage::wheelWear)) // podkucie - EventFlag = true; + eventFlag = true; if (deltan < -dmgn && FuzzyLogic(-deltan, dmgn, p_slippdmg) && DamageFlag.Set(VehicleDamage::thinWheel)) // wycieranie sie obreczy - EventFlag = true; + eventFlag = true; n = nrot; // predkosc obrotowa nie zalezy od predkosci liniowej } return n; diff --git a/physics/vehicle.h b/physics/vehicle.h index c733973c2..8c836d3db 100644 --- a/physics/vehicle.h +++ b/physics/vehicle.h @@ -862,7 +862,8 @@ class Vehicle load_attributes(std::string const &Name, float const Offsetmin) : name(Name), offset_min(Offsetmin) {} }; std::vector LoadAttributes; - float MaxLoad = 0.f; /*masa w T lub ilosc w sztukach - ladownosc*/ + float const &MaxLoad() const { return maxLoad; } /*masa w T lub ilosc w sztukach - ladownosc*/ + void SetMaxLoad(float const Value) { maxLoad = Value; } double OverLoadFactor = 0.0; /*ile razy moze byc przekroczona ladownosc*/ float LoadSpeed = 0.f; float UnLoadSpeed = 0.f; /*szybkosc na- i rozladunku jednostki/s*/ @@ -905,8 +906,13 @@ class Vehicle // (vehicle_table::update_coupler_physics()); with couplerphysics all in eu07.ini every vehicle is covered bool CouplerPhysics{false}; ByEnd Neighbours; // potential collision sources - bool EventFlag = false; /*!o true jesli cos nietypowego sie wydarzy*/ - int SoundFlag = 0; /*!o patrz stale sound_ */ + // something out of the ordinary happened (the line breaker knocked out, a derailment), for the sounds to follow up + bool EventFlag() const { return eventFlag; } + void RaiseEventFlag() { eventFlag = true; } + void ClearEventFlag() { eventFlag = false; } + // the events of the step the sounds are to follow up (sound::), cleared once they did + int SoundFlag() const { return soundFlag; } + void ClearSoundFlags() { soundFlag = 0; } int AIFlag{0}; // HACK: events of interest for consist owner double DistCounter = 0.0; /*! licznik kilometrow */ // the criteria of derailment (physics.derailment new), and the distance travelled since they were checked [m] @@ -1073,11 +1079,27 @@ class Vehicle double eAngle = M_PI * 0.5; /*-dla wagonow*/ - float LoadAmount = 0.f; /*masa w T lub ilosc w sztukach - zaladowane*/ + float const &LoadAmount() const { return loadAmount; } /*masa w T lub ilosc w sztukach - zaladowane*/ + void SetLoadAmount(float const Value) { loadAmount = Value; } load_attributes LoadType; std::string LoadQuantity; // jednostki miary - int LoadStatus = 0; //+1=trwa rozladunek,+2=trwa zaladunek,+4=zakończono,0=zaktualizowany model - bool LoadTypeChange{false}; // indicates load type was changed + // the exchange of the load: +1 unloading, +2 loading, +4 finished, 0 the model of the load updated + int LoadStatus() const { return loadStatus; } + // a step of the exchange: so much taken out, or put in up to the capacity, and the mass with it + void UnloadStep(float Amount); + void LoadStep(float Amount); + void FinishLoadExchange() { loadStatus = 4; } + // the end of the exchange seen to, the model of the load updated + void AcknowledgeLoadExchange() { loadStatus &= 1 | 2; } + void SetLoadStatusForTest(int const Value) { loadStatus = Value; } + // the kind of the load changed, for the model of the load to follow; true once, until changed again + bool LoadTypeChange() const { return loadTypeChange; } + bool TakeLoadTypeChange() + { + auto const changed{loadTypeChange}; + loadTypeChange = false; + return changed; + } double LastLoadChangeTime = 0.0; // raz (roz)ładowania #ifdef EU07_USEOLDDOORCODE bool DoorBlocked = false; // Czy jest blokada drzwi @@ -1109,7 +1131,9 @@ class Vehicle double TotalMassxg = 0.0; /*TotalMass*g*/ int iProblem = 0; // flagi problemów z taborem, aby AI nie musiało porównywać; 0=może jechać - ByEnd iLights; // bity zapalonych świateł tutaj, żeby dało się liczyć pobór prądu + // the lights switched on at each end (light::), from which the current they draw is counted + ByEnd const &LitLights() const { return litLights; } + void SetLitLights(VehicleEnd const End, int const Lights) { litLights[End] = Lights; } // 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 @@ -1793,6 +1817,13 @@ class Vehicle private: // the switches and the controllers the cab, the AI and the scenery change only through the operations above + float maxLoad = 0.f; + bool eventFlag = false; + int soundFlag = 0; + float loadAmount = 0.f; + int loadStatus = 0; + bool loadTypeChange{false}; + ByEnd litLights; bool signalling = false; bool radio = false; bool radioFuse = true; diff --git a/simulation/blackboxrecorder.cpp b/simulation/blackboxrecorder.cpp index 02b3bf9dd..320c444f1 100644 --- a/simulation/blackboxrecorder.cpp +++ b/simulation/blackboxrecorder.cpp @@ -112,7 +112,7 @@ std::uint16_t outward_lights(TDynamicObject const *Vehicle, bool const Head) { if (Vehicle == nullptr || Vehicle->physics == nullptr) return 0; auto const along{Vehicle->iDirection > 0}; - return static_cast(Vehicle->physics->iLights[Head == along ? VehicleEnd::front : VehicleEnd::rear]); + return static_cast(Vehicle->physics->LitLights()[Head == along ? VehicleEnd::front : VehicleEnd::rear]); } // the lamps the vehicle has at that end: the driver checks a pattern against those of it there are diff --git a/tests/unit/test_auxiliaries.cpp b/tests/unit/test_auxiliaries.cpp index c8ca48ed2..2b6ad7ed8 100644 --- a/tests/unit/test_auxiliaries.cpp +++ b/tests/unit/test_auxiliaries.cpp @@ -38,8 +38,8 @@ TEST_CASE("auxiliaries: the battery drained by the lights and the pantographs' c REQUIRE(eu07.lowVoltage.BatteryVoltage() == doctest::Approx(eu07.lowVoltage.config.nominalBatteryVoltage)); scenario.act("converter off, lights on, small compressor on"); eu07.ConverterSwitch(false); - eu07.iLights[VehicleEnd::front] = 1 | 2 | 4; - eu07.iLights[VehicleEnd::rear] = 16; + eu07.SetLitLights(VehicleEnd::front, 1 | 2 | 4); + eu07.SetLitLights(VehicleEnd::rear, 16); eu07.pantographAir.SwitchCompressor(true); scenario.wait(30.0); CHECK(eu07.lowVoltage.BatteryVoltage() < 0.83 * eu07.lowVoltage.config.nominalBatteryVoltage); diff --git a/tests/unit/test_commands.cpp b/tests/unit/test_commands.cpp index e327ac868..ac25866b9 100644 --- a/tests/unit/test_commands.cpp +++ b/tests/unit/test_commands.cpp @@ -69,8 +69,8 @@ std::vector state() { {"BrakeDelayFlag", [](auto const &M) { return M.brakes.delaySetting; }}, {"SandDose", [](auto const &M) { return flag(M.SandDose); }}, {"CabSignal", [](auto const &M) { return flag(M.SecuritySystem.is_cabsignal_blinking()); }}, - {"LoadAmount", [](auto const &M) { return M.LoadAmount; }}, - {"LoadStatus", [](auto const &M) { return M.LoadStatus; }}, + {"LoadAmount", [](auto const &M) { return M.LoadAmount(); }}, + {"LoadStatus", [](auto const &M) { return M.LoadStatus(); }}, {"SpeedCtrlValue", [](auto const &M) { return M.SpeedCtrlValue; }}, {"SpeedCtrlParking", [](auto const &M) { return flag(M.SpeedCtrlUnit.Parking); }}, {"SpringBrakeActivate", [](auto const &M) { return flag(M.brakes.spring.activate); }}, @@ -508,7 +508,7 @@ TEST_CASE("commands: don't pass a coupling without the control cable") { TEST_CASE("commands: a wagon loaded and unloaded by commands, which repeat until done") { vehicle wagon{definition::fiz("3wl_v2/3wl")}; - REQUIRE(wagon->MaxLoad > 0); + REQUIRE(wagon->MaxLoad() > 0); test::trace trace{"commands/loading", state(), 100}; wagon.record(trace); @@ -517,27 +517,27 @@ TEST_CASE("commands: a wagon loaded and unloaded by commands, which repeat until trace.mark("load"); wagon->PutCommand("Load=Coal", 12, 0, wagon->Loc); wagon.run(30.0); - CHECK(wagon->LoadAmount == doctest::Approx(12.0).epsilon(0.1)); + CHECK(wagon->LoadAmount() == doctest::Approx(12.0).epsilon(0.1)); CHECK(wagon->LoadType.name == "coal"); CHECK(wagon->CommandIn.Command == VehicleCommand::none); trace.mark("unload"); wagon->PutCommand("UnLoad=Coal", 20, 0, wagon->Loc); wagon.run(200.0); - CHECK(wagon->LoadAmount == doctest::Approx(0.0)); + CHECK(wagon->LoadAmount() == doctest::Approx(0.0)); CHECK(wagon->LoadType.name.empty()); trace.check(); } SUBCASE("a load the wagon doesn't take stays a command, not done") { wagon->PutCommand("Load=passengers", 12, 0, wagon->Loc); wagon.run(10.0); - CHECK(wagon->LoadAmount == doctest::Approx(0.0)); + CHECK(wagon->LoadAmount() == doctest::Approx(0.0)); CHECK_FALSE(wagon->CommandIn.Command == VehicleCommand::none); } SUBCASE("away from the place of the command nothing is loaded") { wagon->PutCommand("Load=Coal", 12, 5.0, TLocation{100.0, 0.0, 0.0}); wagon.run(10.0); - CHECK(wagon->LoadAmount == doctest::Approx(0.0)); + CHECK(wagon->LoadAmount() == doctest::Approx(0.0)); CHECK(wagon->LastLoadChangeTime == doctest::Approx(0.0)); } SUBCASE("unloading an empty wagon isn't done either") { diff --git a/tests/unit/test_loads.cpp b/tests/unit/test_loads.cpp index 228ea5f5b..123389155 100644 --- a/tests/unit/test_loads.cpp +++ b/tests/unit/test_loads.cpp @@ -26,7 +26,7 @@ TEST_CASE("loads: the pantographs of an electric vehicle set up by the amount of CHECK(et42->pantographs[VehicleEnd::front].valve.is_enabled == frontraised); CHECK(et42->pantographs[VehicleEnd::rear].valve.is_enabled == rearraised); // the load itself stays as it was - CHECK(et42->LoadAmount == doctest::Approx(0.0)); + CHECK(et42->LoadAmount() == doctest::Approx(0.0)); } // a vehicle without a current collector takes no such load vehicle wagon{definition::fiz("3wl_v2/3wl")}; @@ -37,21 +37,21 @@ TEST_CASE("loads: a load assigned, of one kind at a time, up to the vehicle's ca vehicle wagon{definition::fiz("3wl_v2/3wl")}; auto const empty{wagon->TotalMass}; REQUIRE(wagon->AssignLoad("coal", 10.f)); - CHECK(wagon->LoadTypeChange); + CHECK(wagon->LoadTypeChange()); CHECK(wagon->LoadType.name == "coal"); CHECK(wagon->TotalMass > empty); // more of the same: the amount set, not added, and no more than the vehicle takes - wagon->LoadTypeChange = false; + wagon->TakeLoadTypeChange(); REQUIRE(wagon->AssignLoad("coal", 1000.f)); - CHECK_FALSE(wagon->LoadTypeChange); - CHECK(wagon->LoadAmount == doctest::Approx(wagon->MaxLoad)); + CHECK_FALSE(wagon->LoadTypeChange()); + CHECK(wagon->LoadAmount() == doctest::Approx(wagon->MaxLoad())); // another kind can't be added to a load, nor can an unknown one be loaded CHECK_FALSE(wagon->AssignLoad("ruda", 5.f)); CHECK(wagon->LoadType.name == "coal"); // emptied, with no name REQUIRE(wagon->AssignLoad("")); - CHECK(wagon->LoadTypeChange); - CHECK(wagon->LoadAmount == doctest::Approx(0.0)); + CHECK(wagon->LoadTypeChange()); + CHECK(wagon->LoadAmount() == doctest::Approx(0.0)); CHECK(wagon->LoadType.name.empty()); CHECK_FALSE(wagon->AssignLoad("unknown", 5.f)); CHECK(wagon->AssignLoad("ruda", 5.f)); @@ -61,56 +61,56 @@ TEST_CASE("loads: the steps of loading and unloading") { // most of the game's wagons may be overloaded (OverLoadFactor), the 3WL not vehicle wagon{definition::fiz("3wl_v2/3wl").set("Load", "OverLoadFactor", 1.5)}; REQUIRE(wagon->AssignLoad("coal", 10.f)); - auto const capacity{wagon->MaxLoad * (1.0 + wagon->OverLoadFactor)}; + auto const capacity{wagon->MaxLoad() * (1.0 + wagon->OverLoadFactor)}; SUBCASE("no speed of the change: done at once") { CHECK(wagon->LoadingDone(0.0, "coal")); - CHECK(wagon->LoadStatus == 4); + CHECK(wagon->LoadStatus() == 4); } SUBCASE("no load, or another one, named: done when it was") { - wagon->LoadStatus = 1; + wagon->SetLoadStatusForTest(1); CHECK_FALSE(wagon->LoadingDone(1.0, "")); CHECK_FALSE(wagon->LoadingDone(1.0, "ruda")); - wagon->LoadStatus = 4; + wagon->SetLoadStatusForTest(4); CHECK(wagon->LoadingDone(1.0, "")); } SUBCASE("unloading, step by step, what was asked or all of it, the name going with the last of it") { wagon->CommandIn.Value1 = 4.0; // asked to unload wagon->LastLoadChangeTime = 2.0; // at 1 a second CHECK_FALSE(wagon->LoadingDone(-1.0, "coal")); - CHECK(wagon->LoadStatus == 2); - CHECK(wagon->LoadAmount == doctest::Approx(8.0)); + CHECK(wagon->LoadStatus() == 2); + CHECK(wagon->LoadAmount() == doctest::Approx(8.0)); CHECK(wagon->LastLoadChangeTime == doctest::Approx(0.0)); // nothing done since the last step CHECK_FALSE(wagon->LoadingDone(-1.0, "coal")); - CHECK(wagon->LoadAmount == doctest::Approx(8.0)); + CHECK(wagon->LoadAmount() == doctest::Approx(8.0)); wagon->LastLoadChangeTime = 2.0; CHECK(wagon->LoadingDone(-1.0, "coal")); - CHECK(wagon->LoadAmount == doctest::Approx(6.0)); + CHECK(wagon->LoadAmount() == doctest::Approx(6.0)); wagon->CommandIn.Value1 = 100.0; wagon->LastLoadChangeTime = 10.0; CHECK(wagon->LoadingDone(-1.0, "coal")); - CHECK(wagon->LoadAmount == doctest::Approx(0.0)); + CHECK(wagon->LoadAmount() == doctest::Approx(0.0)); CHECK(wagon->LoadType.name.empty()); } SUBCASE("loading, step by step, up to what was asked or what the vehicle takes, slower when overloaded") { wagon->CommandIn.Value1 = 5.0; wagon->LastLoadChangeTime = 2.0; CHECK_FALSE(wagon->LoadingDone(1.0, "coal")); - CHECK(wagon->LoadStatus == 1); - CHECK(wagon->LoadAmount == doctest::Approx(12.0)); + CHECK(wagon->LoadStatus() == 1); + CHECK(wagon->LoadAmount() == doctest::Approx(12.0)); wagon->LastLoadChangeTime = 3.0; CHECK(wagon->LoadingDone(1.0, "coal")); - CHECK(wagon->LoadAmount == doctest::Approx(15.0)); + CHECK(wagon->LoadAmount() == doctest::Approx(15.0)); wagon->CommandIn.Value1 = 1000.0; wagon->LastLoadChangeTime = 1000.0; CHECK(wagon->LoadingDone(1.0, "coal")); - CHECK(wagon->LoadAmount == doctest::Approx(capacity)); - CHECK(capacity == doctest::Approx(2.5 * wagon->MaxLoad)); + CHECK(wagon->LoadAmount() == doctest::Approx(capacity)); + CHECK(capacity == doctest::Approx(2.5 * wagon->MaxLoad())); // over the vehicle's own capacity, the change goes at half the speed wagon->CommandIn.Value1 = 1000.0; wagon->LastLoadChangeTime = 4.0; CHECK_FALSE(wagon->LoadingDone(-1.0, "coal")); - CHECK(wagon->LoadAmount == doctest::Approx(capacity - 2.0)); + CHECK(wagon->LoadAmount() == doctest::Approx(capacity - 2.0)); } } diff --git a/vehicle/ai/driver.cpp b/vehicle/ai/driver.cpp index 11faa4ffe..056d0e7a5 100644 --- a/vehicle/ai/driver.cpp +++ b/vehicle/ai/driver.cpp @@ -419,13 +419,13 @@ void TController::TakeControl( bool const Aidriver, bool const Forcevehiclecheck else { // jeśli nic nie robi OrderNext( DriverOrder::prepareEngine ); - if( pVehicle->physics->iLights[ ( occupied->CabActive < 0 ? + if( pVehicle->physics->LitLights()[ ( occupied->CabActive < 0 ? VehicleEnd::rear : VehicleEnd::front ) ] & ( light::headlight_left | light::headlight_right | light::headlight_upper ) ) // któreś ze świateł zapalone? { // od wersji 357 oczekujemy podania komend dla AI przez scenerię /* - if( pVehicle->physics->iLights[ occupied->CabActive < 0 ? VehicleEnd::rear : VehicleEnd::front ] & light::headlight_upper ) // górne światło zapalone + if( pVehicle->physics->LitLights()[ occupied->CabActive < 0 ? VehicleEnd::rear : VehicleEnd::front ] & light::headlight_upper ) // górne światło zapalone OrderNext( DriverOrder::obeyTrain ); // jazda pociągowa else OrderNext( DriverOrder::shunt ); // jazda manewrowa diff --git a/vehicle/ai/situation.cpp b/vehicle/ai/situation.cpp index 9d0bf70c0..ed4938226 100644 --- a/vehicle/ai/situation.cpp +++ b/vehicle/ai/situation.cpp @@ -458,7 +458,7 @@ TController::sync_lights_selector() { // same choice of the lit vehicle end as in TDynamicObject::RaLightsSet() auto const headend { ( headvehicle->iDirection > 0 ? VehicleEnd::front : VehicleEnd::rear ) }; auto const position { handover::light_selector_position( - *occupied, NumberOf( lightstable ), headvehicle->physics->iLights[ headend ], headvehicle->LightList( headend ) ) }; + *occupied, NumberOf( lightstable ), headvehicle->physics->LitLights()[ headend ], headvehicle->LightList( headend ) ) }; if( position == occupied->LightsPos() ) { return; } occupied->SetLightsPos(position); @@ -480,7 +480,7 @@ TController::sync_lights_dimmer() { auto const headend { ( headvehicle != nullptr && headvehicle->iDirection > 0 ? VehicleEnd::front : VehicleEnd::rear ) }; auto const headlightson { headvehicle != nullptr - && ( headvehicle->physics->iLights[ headend ] & ( light::headlight_left | light::headlight_right | light::headlight_upper ) ) != 0 }; + && ( headvehicle->physics->LitLights()[ headend ] & ( light::headlight_left | light::headlight_right | light::headlight_upper ) ) != 0 }; auto const position { handover::dimmer_position( *occupied, headlightson ) }; if( position != occupied->DimmerPosition() ) { diff --git a/vehicle/cab/lightcommands.cpp b/vehicle/cab/lightcommands.cpp index b432ee575..edcbcef40 100644 --- a/vehicle/cab/lightcommands.cpp +++ b/vehicle/cab/lightcommands.cpp @@ -168,7 +168,7 @@ void TTrain::OnCommand_headlighttoggleleft(TTrain *Train, command_data const &Co if (Train->ggLeftEndLightButton.SubModel != nullptr || Train->ggLeftLightButton.SubModel == nullptr) { - if ((Train->occupied->iLights[vehicleend] & light::headlight_left) == 0) + if ((Train->occupied->LitLights()[vehicleend] & light::headlight_left) == 0) { // turn on OnCommand_headlightenableleft(Train, Command); @@ -180,13 +180,13 @@ void TTrain::OnCommand_headlighttoggleleft(TTrain *Train, command_data const &Co } } else { // if the light is controlled by 3-way switch, handle both headlight and redmarker - if ((Train->occupied->iLights[vehicleend] & light::headlight_left) == 0 && - (Train->occupied->iLights[vehicleend] & light::redmarker_left) == 0) + if ((Train->occupied->LitLights()[vehicleend] & light::headlight_left) == 0 && + (Train->occupied->LitLights()[vehicleend] & light::redmarker_left) == 0) { // turn on OnCommand_headlightenableleft(Train, Command); } - else if (Train->occupied->iLights[vehicleend] & light::headlight_left) + else if (Train->occupied->LitLights()[vehicleend] & light::headlight_left) { // switch to red OnCommand_redmarkerenableleft(Train, Command); @@ -225,14 +225,14 @@ void TTrain::OnCommand_headlightenableleft(TTrain *Train, command_data const &Co // implementation auto const vehicleend{Train->cab_to_end()}; - if ((Train->occupied->iLights[vehicleend] & light::headlight_left) == 0) + if ((Train->occupied->LitLights()[vehicleend] & light::headlight_left) == 0) { - Train->occupied->iLights[vehicleend] ^= light::headlight_left; + Train->occupied->SetLitLights(vehicleend, Train->occupied->LitLights()[vehicleend] ^ (light::headlight_left)); } // if the light is controlled by 3-way switch, disable marker light if (Train->ggLeftEndLightButton.SubModel == nullptr) { - Train->occupied->iLights[vehicleend] &= ~light::redmarker_left; + Train->occupied->SetLitLights(vehicleend, Train->occupied->LitLights()[vehicleend] & ~light::redmarker_left); } } } @@ -251,12 +251,12 @@ void TTrain::OnCommand_headlightdisableleft(TTrain *Train, command_data const &C // only reacting to press, so the switch doesn't flip back and forth if key is held down auto const vehicleend{Train->cab_to_end()}; - if ((Train->occupied->iLights[vehicleend] & light::headlight_left) == 0) + if ((Train->occupied->LitLights()[vehicleend] & light::headlight_left) == 0) { return; } // already disabled - Train->occupied->iLights[vehicleend] ^= light::headlight_left; + Train->occupied->SetLitLights(vehicleend, Train->occupied->LitLights()[vehicleend] ^ (light::headlight_left)); // visual feedback Train->ggLeftLightButton.UpdateValue(0.0, Train->dsbSwitch); } @@ -273,7 +273,7 @@ void TTrain::OnCommand_headlighttoggleright(TTrain *Train, command_data const &C if (Train->ggRightEndLightButton.SubModel != nullptr || Train->ggRightLightButton.SubModel == nullptr) { - if ((Train->occupied->iLights[vehicleend] & light::headlight_right) == 0) + if ((Train->occupied->LitLights()[vehicleend] & light::headlight_right) == 0) { // turn on OnCommand_headlightenableright(Train, Command); @@ -285,13 +285,13 @@ void TTrain::OnCommand_headlighttoggleright(TTrain *Train, command_data const &C } } else { // if the light is controlled by 3-way switch, handle both headlight and redmarker - if ((Train->occupied->iLights[vehicleend] & light::headlight_right) == 0 && - (Train->occupied->iLights[vehicleend] & light::redmarker_right) == 0) + if ((Train->occupied->LitLights()[vehicleend] & light::headlight_right) == 0 && + (Train->occupied->LitLights()[vehicleend] & light::redmarker_right) == 0) { // turn on OnCommand_headlightenableright(Train, Command); } - else if (Train->occupied->iLights[vehicleend] & light::headlight_right) + else if (Train->occupied->LitLights()[vehicleend] & light::headlight_right) { // switch to red OnCommand_redmarkerenableright(Train, Command); @@ -321,14 +321,14 @@ void TTrain::OnCommand_headlightenableright(TTrain *Train, command_data const &C // implementation auto const vehicleend{Train->cab_to_end()}; - if ((Train->occupied->iLights[vehicleend] & light::headlight_right) == 0) + if ((Train->occupied->LitLights()[vehicleend] & light::headlight_right) == 0) { - Train->occupied->iLights[vehicleend] ^= light::headlight_right; + Train->occupied->SetLitLights(vehicleend, Train->occupied->LitLights()[vehicleend] ^ (light::headlight_right)); } // if the light is controlled by 3-way switch, disable marker light if (Train->ggRightEndLightButton.SubModel == nullptr) { - Train->occupied->iLights[vehicleend] &= ~light::redmarker_right; + Train->occupied->SetLitLights(vehicleend, Train->occupied->LitLights()[vehicleend] & ~light::redmarker_right); } } } @@ -347,12 +347,12 @@ void TTrain::OnCommand_headlightdisableright(TTrain *Train, command_data const & // only reacting to press, so the switch doesn't flip back and forth if key is held down auto const vehicleend{Train->cab_to_end()}; - if ((Train->occupied->iLights[vehicleend] & light::headlight_right) == 0) + if ((Train->occupied->LitLights()[vehicleend] & light::headlight_right) == 0) { return; } // already disabled - Train->occupied->iLights[vehicleend] ^= light::headlight_right; + Train->occupied->SetLitLights(vehicleend, Train->occupied->LitLights()[vehicleend] ^ (light::headlight_right)); // visual feedback Train->ggRightLightButton.UpdateValue(0.0, Train->dsbSwitch); } @@ -366,7 +366,7 @@ void TTrain::OnCommand_headlighttoggleupper(TTrain *Train, command_data const &C 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->occupied->iLights[vehicleend] & light::headlight_upper) == 0) + if ((Train->occupied->LitLights()[vehicleend] & light::headlight_upper) == 0) { // turn on OnCommand_headlightenableupper(Train, Command); @@ -393,12 +393,12 @@ void TTrain::OnCommand_headlightenableupper(TTrain *Train, command_data const &C // only reacting to press, so the switch doesn't flip back and forth if key is held down auto const vehicleend{Train->cab_to_end()}; - if ((Train->occupied->iLights[vehicleend] & light::headlight_upper) != 0) + if ((Train->occupied->LitLights()[vehicleend] & light::headlight_upper) != 0) { return; } // already enabled - Train->occupied->iLights[vehicleend] ^= light::headlight_upper; + Train->occupied->SetLitLights(vehicleend, Train->occupied->LitLights()[vehicleend] ^ (light::headlight_upper)); // visual feedback Train->ggUpperLightButton.UpdateValue(1.0, Train->dsbSwitch); } @@ -418,12 +418,12 @@ void TTrain::OnCommand_headlightdisableupper(TTrain *Train, command_data const & // only reacting to press, so the switch doesn't flip back and forth if key is held down auto const vehicleend{Train->cab_to_end()}; - if ((Train->occupied->iLights[vehicleend] & light::headlight_upper) == 0) + if ((Train->occupied->LitLights()[vehicleend] & light::headlight_upper) == 0) { return; } // already disabled - Train->occupied->iLights[vehicleend] ^= light::headlight_upper; + Train->occupied->SetLitLights(vehicleend, Train->occupied->LitLights()[vehicleend] ^ (light::headlight_upper)); // visual feedback Train->ggUpperLightButton.UpdateValue(0.0, Train->dsbSwitch); } @@ -437,7 +437,7 @@ void TTrain::OnCommand_redmarkertoggleleft(TTrain *Train, command_data const &Co // only reacting to press, so the switch doesn't flip back and forth if key is held down auto const vehicleend{Train->cab_to_end()}; - if ((Train->occupied->iLights[vehicleend] & light::redmarker_left) == 0) + if ((Train->occupied->LitLights()[vehicleend] & light::redmarker_left) == 0) { // turn on OnCommand_redmarkerenableleft(Train, Command); @@ -464,12 +464,12 @@ void TTrain::OnCommand_redmarkerenableleft(TTrain *Train, command_data const &Co // only reacting to press, so the switch doesn't flip back and forth if key is held down auto const vehicleend{Train->cab_to_end()}; - if ((Train->occupied->iLights[vehicleend] & light::redmarker_left) != 0) + if ((Train->occupied->LitLights()[vehicleend] & light::redmarker_left) != 0) { return; } // already enabled - Train->occupied->iLights[vehicleend] ^= light::redmarker_left; + Train->occupied->SetLitLights(vehicleend, Train->occupied->LitLights()[vehicleend] ^ (light::redmarker_left)); // visual feedback if (Train->ggLeftEndLightButton.SubModel != nullptr) { @@ -481,7 +481,7 @@ void TTrain::OnCommand_redmarkerenableleft(TTrain *Train, command_data const &Co // this is crude, but for now will do Train->ggLeftLightButton.UpdateValue(-1.0, Train->dsbSwitch); // if the light is controlled by 3-way switch, disable the headlight - Train->occupied->iLights[vehicleend] &= ~light::headlight_left; + Train->occupied->SetLitLights(vehicleend, Train->occupied->LitLights()[vehicleend] & ~light::headlight_left); } } } @@ -500,12 +500,12 @@ void TTrain::OnCommand_redmarkerdisableleft(TTrain *Train, command_data const &C // only reacting to press, so the switch doesn't flip back and forth if key is held down auto const vehicleend{Train->cab_to_end()}; - if ((Train->occupied->iLights[vehicleend] & light::redmarker_left) == 0) + if ((Train->occupied->LitLights()[vehicleend] & light::redmarker_left) == 0) { return; } // already disabled - Train->occupied->iLights[vehicleend] ^= light::redmarker_left; + Train->occupied->SetLitLights(vehicleend, Train->occupied->LitLights()[vehicleend] ^ (light::redmarker_left)); // visual feedback if (Train->ggLeftEndLightButton.SubModel != nullptr) { @@ -528,7 +528,7 @@ void TTrain::OnCommand_redmarkertoggleright(TTrain *Train, command_data const &C // only reacting to press, so the switch doesn't flip back and forth if key is held down auto const vehicleend{Train->cab_to_end()}; - if ((Train->occupied->iLights[vehicleend] & light::redmarker_right) == 0) + if ((Train->occupied->LitLights()[vehicleend] & light::redmarker_right) == 0) { // turn on OnCommand_redmarkerenableright(Train, Command); @@ -555,12 +555,12 @@ void TTrain::OnCommand_redmarkerenableright(TTrain *Train, command_data const &C // only reacting to press, so the switch doesn't flip back and forth if key is held down auto const vehicleend{Train->cab_to_end()}; - if ((Train->occupied->iLights[vehicleend] & light::redmarker_right) != 0) + if ((Train->occupied->LitLights()[vehicleend] & light::redmarker_right) != 0) { return; } // already enabled - Train->occupied->iLights[vehicleend] ^= light::redmarker_right; + Train->occupied->SetLitLights(vehicleend, Train->occupied->LitLights()[vehicleend] ^ (light::redmarker_right)); // visual feedback if (Train->ggRightEndLightButton.SubModel != nullptr) { @@ -572,7 +572,7 @@ void TTrain::OnCommand_redmarkerenableright(TTrain *Train, command_data const &C // this is crude, but for now will do Train->ggRightLightButton.UpdateValue(-1.0, Train->dsbSwitch); // if the light is controlled by 3-way switch, disable the headlight - Train->occupied->iLights[vehicleend] &= ~light::headlight_right; + Train->occupied->SetLitLights(vehicleend, Train->occupied->LitLights()[vehicleend] & ~light::headlight_right); } } } @@ -591,12 +591,12 @@ void TTrain::OnCommand_redmarkerdisableright(TTrain *Train, command_data const & // only reacting to press, so the switch doesn't flip back and forth if key is held down auto const vehicleend{Train->cab_to_end()}; - if ((Train->occupied->iLights[vehicleend] & light::redmarker_right) == 0) + if ((Train->occupied->LitLights()[vehicleend] & light::redmarker_right) == 0) { return; } // already disabled - Train->occupied->iLights[vehicleend] ^= light::redmarker_right; + Train->occupied->SetLitLights(vehicleend, Train->occupied->LitLights()[vehicleend] ^ (light::redmarker_right)); // visual feedback if (Train->ggRightEndLightButton.SubModel != nullptr) { @@ -625,7 +625,7 @@ void TTrain::OnCommand_headlighttogglerearleft(TTrain *Train, command_data const // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; // only reacting to press, so the switch doesn't flip back and forth if key is held down - if ((Train->occupied->iLights[vehicleotherend] & light::headlight_right) == 0) + if ((Train->occupied->LitLights()[vehicleotherend] & light::headlight_right) == 0) { OnCommand_headlightenablerearleft(Train, Command); } @@ -648,10 +648,10 @@ void TTrain::OnCommand_headlightenablerearleft(TTrain *Train, command_data const { auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; // already enabled - if ((Train->occupied->iLights[vehicleotherend] & light::headlight_right) == 0) + if ((Train->occupied->LitLights()[vehicleotherend] & light::headlight_right) == 0) { // turn on - Train->occupied->iLights[vehicleotherend] ^= light::headlight_right; + Train->occupied->SetLitLights(vehicleotherend, Train->occupied->LitLights()[vehicleotherend] ^ (light::headlight_right)); // visual feedback Train->ggRearLeftLightButton.UpdateValue(1.0, Train->dsbSwitch); } @@ -669,13 +669,13 @@ void TTrain::OnCommand_headlightdisablerearleft(TTrain *Train, command_data cons { auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; // already disabled - if ((Train->occupied->iLights[vehicleotherend] & light::headlight_right) == 0) + if ((Train->occupied->LitLights()[vehicleotherend] & light::headlight_right) == 0) { return; } // turn off - Train->occupied->iLights[vehicleotherend] ^= light::headlight_right; + Train->occupied->SetLitLights(vehicleotherend, Train->occupied->LitLights()[vehicleotherend] ^ (light::headlight_right)); // visual feedback Train->ggRearLeftLightButton.UpdateValue(0.0, Train->dsbSwitch); } @@ -688,7 +688,7 @@ void TTrain::OnCommand_headlighttogglerearright(TTrain *Train, command_data cons // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; // only reacting to press, so the switch doesn't flip back and forth if key is held down - if ((Train->occupied->iLights[vehicleotherend] & light::headlight_left) == 0) + if ((Train->occupied->LitLights()[vehicleotherend] & light::headlight_left) == 0) { OnCommand_headlightenablerearright(Train, Command); } @@ -712,10 +712,10 @@ void TTrain::OnCommand_headlightenablerearright(TTrain *Train, command_data cons // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; - if ((Train->occupied->iLights[vehicleotherend] & light::headlight_left) == 0) + if ((Train->occupied->LitLights()[vehicleotherend] & light::headlight_left) == 0) { // turn on - Train->occupied->iLights[vehicleotherend] ^= light::headlight_left; + Train->occupied->SetLitLights(vehicleotherend, Train->occupied->LitLights()[vehicleotherend] ^ (light::headlight_left)); // visual feedback Train->ggRearRightLightButton.UpdateValue(1.0, Train->dsbSwitch); } @@ -735,13 +735,13 @@ void TTrain::OnCommand_headlightdisablerearright(TTrain *Train, command_data con // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; // already disabled - if ((Train->occupied->iLights[vehicleotherend] & light::headlight_left) == 0) + if ((Train->occupied->LitLights()[vehicleotherend] & light::headlight_left) == 0) { return; } // turn off - Train->occupied->iLights[vehicleotherend] ^= light::headlight_left; + Train->occupied->SetLitLights(vehicleotherend, Train->occupied->LitLights()[vehicleotherend] ^ (light::headlight_left)); // visual feedback Train->ggRearRightLightButton.UpdateValue(0.0, Train->dsbSwitch); } @@ -760,7 +760,7 @@ void TTrain::OnCommand_headlighttogglerearupper(TTrain *Train, command_data cons { // only reacting to press, so the switch doesn't flip back and forth if key is held down auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; - if ((Train->occupied->iLights[vehicleotherend] & light::headlight_upper) == 0) + if ((Train->occupied->LitLights()[vehicleotherend] & light::headlight_upper) == 0) { OnCommand_headlightenablerearupper(Train, Command); } @@ -784,10 +784,10 @@ void TTrain::OnCommand_headlightenablerearupper(TTrain *Train, command_data cons { // only reacting to press, so the switch doesn't flip back and forth if key is held down auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; - if ((Train->occupied->iLights[vehicleotherend] & light::headlight_upper) == 0) + if ((Train->occupied->LitLights()[vehicleotherend] & light::headlight_upper) == 0) { // turn on - Train->occupied->iLights[vehicleotherend] ^= light::headlight_upper; + Train->occupied->SetLitLights(vehicleotherend, Train->occupied->LitLights()[vehicleotherend] ^ (light::headlight_upper)); // visual feedback Train->ggRearUpperLightButton.UpdateValue(1.0, Train->dsbSwitch); } @@ -808,13 +808,13 @@ void TTrain::OnCommand_headlightdisablerearupper(TTrain *Train, command_data con // only reacting to press, so the switch doesn't flip back and forth if key is held down auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; // already disabled? - if ((Train->occupied->iLights[vehicleotherend] & light::headlight_upper) == 0) + if ((Train->occupied->LitLights()[vehicleotherend] & light::headlight_upper) == 0) { return; } // turn off - Train->occupied->iLights[vehicleotherend] ^= light::headlight_upper; + Train->occupied->SetLitLights(vehicleotherend, Train->occupied->LitLights()[vehicleotherend] ^ (light::headlight_upper)); // visual feedback Train->ggRearUpperLightButton.UpdateValue(0.0, Train->dsbSwitch); } @@ -865,7 +865,7 @@ void TTrain::OnCommand_redmarkertogglerearleft(TTrain *Train, command_data const // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; // only reacting to press, so the switch doesn't flip back and forth if key is held down - if ((Train->occupied->iLights[vehicleotherend] & light::redmarker_right) == 0) + if ((Train->occupied->LitLights()[vehicleotherend] & light::redmarker_right) == 0) { OnCommand_redmarkerenablerearleft(Train, Command); } @@ -889,10 +889,10 @@ void TTrain::OnCommand_redmarkerenablerearleft(TTrain *Train, command_data const { // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; - if ((Train->occupied->iLights[vehicleotherend] & light::redmarker_right) == 0) + if ((Train->occupied->LitLights()[vehicleotherend] & light::redmarker_right) == 0) { // turn on - Train->occupied->iLights[vehicleotherend] ^= light::redmarker_right; + Train->occupied->SetLitLights(vehicleotherend, Train->occupied->LitLights()[vehicleotherend] ^ (light::redmarker_right)); // visual feedback Train->ggRearLeftEndLightButton.UpdateValue(1.0, Train->dsbSwitch); } @@ -912,12 +912,12 @@ void TTrain::OnCommand_redmarkerdisablerearleft(TTrain *Train, command_data cons { // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; - if ((Train->occupied->iLights[vehicleotherend] & light::redmarker_right) == 0) + if ((Train->occupied->LitLights()[vehicleotherend] & light::redmarker_right) == 0) { return; } // turn off - Train->occupied->iLights[vehicleotherend] ^= light::redmarker_right; + Train->occupied->SetLitLights(vehicleotherend, Train->occupied->LitLights()[vehicleotherend] ^ (light::redmarker_right)); // visual feedback Train->ggRearLeftEndLightButton.UpdateValue(0.0, Train->dsbSwitch); } @@ -937,7 +937,7 @@ void TTrain::OnCommand_redmarkertogglerearright(TTrain *Train, command_data cons // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; // only reacting to press, so the switch doesn't flip back and forth if key is held down - if ((Train->occupied->iLights[vehicleotherend] & light::redmarker_left) == 0) + if ((Train->occupied->LitLights()[vehicleotherend] & light::redmarker_left) == 0) { OnCommand_redmarkerenablerearright(Train, Command); } @@ -961,10 +961,10 @@ void TTrain::OnCommand_redmarkerenablerearright(TTrain *Train, command_data cons { // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; - if ((Train->occupied->iLights[vehicleotherend] & light::redmarker_left) == 0) + if ((Train->occupied->LitLights()[vehicleotherend] & light::redmarker_left) == 0) { // turn on - Train->occupied->iLights[vehicleotherend] ^= light::redmarker_left; + Train->occupied->SetLitLights(vehicleotherend, Train->occupied->LitLights()[vehicleotherend] ^ (light::redmarker_left)); // visual feedback Train->ggRearRightEndLightButton.UpdateValue(1.0, Train->dsbSwitch); } @@ -984,12 +984,12 @@ void TTrain::OnCommand_redmarkerdisablerearright(TTrain *Train, command_data con { // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc auto const vehicleotherend{(Train->cab_to_end() == VehicleEnd::front ? VehicleEnd::rear : VehicleEnd::front)}; - if ((Train->occupied->iLights[vehicleotherend] & light::redmarker_left) == 0) + if ((Train->occupied->LitLights()[vehicleotherend] & light::redmarker_left) == 0) { return; } // turn off - Train->occupied->iLights[vehicleotherend] ^= light::redmarker_left; + Train->occupied->SetLitLights(vehicleotherend, Train->occupied->LitLights()[vehicleotherend] ^ (light::redmarker_left)); // visual feedback Train->ggRearRightEndLightButton.UpdateValue(0.0, Train->dsbSwitch); } @@ -1014,10 +1014,10 @@ void TTrain::OnCommand_redmarkerstoggle(TTrain * /*Train*/, command_data const & auto const lightset{light::redmarker_left | light::redmarker_right}; - vehicle->physics->iLights[CouplNr] = - false == TestFlag(vehicle->physics->iLights[CouplNr], lightset) ? - vehicle->physics->iLights[CouplNr] |= lightset : // turn signals on - vehicle->physics->iLights[CouplNr] ^= lightset; // turn signals off + auto const end{static_cast(CouplNr)}; + auto const lit{vehicle->physics->LitLights()[end]}; + vehicle->physics->SetLitLights(end, false == TestFlag(lit, lightset) ? lit | lightset : // turn signals on + lit ^ lightset); // turn signals off } } @@ -1039,10 +1039,10 @@ void TTrain::OnCommand_endsignalstoggle(TTrain * /*Train*/, command_data const & auto const lightset{light::rearendsignals}; - vehicle->physics->iLights[CouplNr] = - false == TestFlag(vehicle->physics->iLights[CouplNr], lightset) ? - vehicle->physics->iLights[CouplNr] |= lightset : // turn signals on - vehicle->physics->iLights[CouplNr] ^= lightset; // turn signals off + auto const end{static_cast(CouplNr)}; + auto const lit{vehicle->physics->LitLights()[end]}; + vehicle->physics->SetLitLights(end, false == TestFlag(lit, lightset) ? lit | lightset : // turn signals on + lit ^ lightset); // turn signals off } } diff --git a/vehicle/cab/setup.cpp b/vehicle/cab/setup.cpp index 8be688c36..65a9be482 100644 --- a/vehicle/cab/setup.cpp +++ b/vehicle/cab/setup.cpp @@ -1007,19 +1007,19 @@ void TTrain::set_cab_controls(int const Cab) auto const vehicleend{cab_to_end(Cab)}; - if ((occupied->iLights[vehicleend] & light::headlight_left) != 0) + if ((occupied->LitLights()[vehicleend] & light::headlight_left) != 0) { ggLeftLightButton.PutValue(1.f); } - if ((occupied->iLights[vehicleend] & light::headlight_right) != 0) + if ((occupied->LitLights()[vehicleend] & light::headlight_right) != 0) { ggRightLightButton.PutValue(1.f); } - if ((occupied->iLights[vehicleend] & light::headlight_upper) != 0) + if ((occupied->LitLights()[vehicleend] & light::headlight_upper) != 0) { ggUpperLightButton.PutValue(1.f); } - if ((occupied->iLights[vehicleend] & light::redmarker_left) != 0) + if ((occupied->LitLights()[vehicleend] & light::redmarker_left) != 0) { if (ggLeftEndLightButton.SubModel != nullptr) { @@ -1030,7 +1030,7 @@ void TTrain::set_cab_controls(int const Cab) ggLeftLightButton.PutValue(-1.f); } } - if ((occupied->iLights[vehicleend] & light::redmarker_right) != 0) + if ((occupied->LitLights()[vehicleend] & light::redmarker_right) != 0) { if (ggRightEndLightButton.SubModel != nullptr) { diff --git a/vehicle/cab/train.cpp b/vehicle/cab/train.cpp index b9731afc9..909d44531 100644 --- a/vehicle/cab/train.cpp +++ b/vehicle/cab/train.cpp @@ -181,8 +181,8 @@ std::shared_ptr TTrain::GetTrainState(dictionary_source const dict->insert("converter_overload", controlled->converter.IsOverloaded()); dict->insert("compress", controlled->air.compressor.IsRunning()); dict->insert("pant_compressor", pantographUnit->pantographAir.IsCompressorRunning()); - dict->insert("lights_front", occupied->iLights[VehicleEnd::front]); - dict->insert("lights_rear", occupied->iLights[VehicleEnd::rear]); + dict->insert("lights_front", occupied->LitLights()[VehicleEnd::front]); + dict->insert("lights_rear", occupied->LitLights()[VehicleEnd::rear]); dict->insert("off_from_dimmer", occupied->currentDimPosition().isOff); dict->insert("lights_compartments", occupied->CompartmentLights.is_active || occupied->CompartmentLights.is_disabled); if (Dynamic()->Mechanik) @@ -194,16 +194,16 @@ std::shared_ptr TTrain::GetTrainState(dictionary_source const auto const *rearvehicle{controller->Vehicle(traindirection >= 0 ? VehicleEnd::rear : VehicleEnd::front)}; auto const frontvehicledirection{(frontvehicle->DirectionGet() == controller->Vehicle()->DirectionGet() ? 1 : -1)}; auto const rearvehicledirection{(rearvehicle->DirectionGet() == controller->Vehicle()->DirectionGet() ? 1 : -1)}; - auto const fronttrainlights{frontvehicle->physics->iLights[frontvehicledirection * cabmodifier >= 0 ? VehicleEnd::front : VehicleEnd::rear]}; - auto const reartrainlights{rearvehicle->physics->iLights[rearvehicledirection * cabmodifier >= 0 ? VehicleEnd::rear : VehicleEnd::front]}; + auto const fronttrainlights{frontvehicle->physics->LitLights()[frontvehicledirection * cabmodifier >= 0 ? VehicleEnd::front : VehicleEnd::rear]}; + auto const reartrainlights{rearvehicle->physics->LitLights()[rearvehicledirection * cabmodifier >= 0 ? VehicleEnd::rear : VehicleEnd::front]}; dict->insert("lights_train_front", fronttrainlights); dict->insert("lights_train_rear", reartrainlights); } else { // fallback, in the unlikely case we lose the controller - dict->insert("lights_train_front", occupied->iLights[VehicleEnd::front]); - dict->insert("lights_train_rear", occupied->iLights[VehicleEnd::rear]); + dict->insert("lights_train_front", occupied->LitLights()[VehicleEnd::front]); + dict->insert("lights_train_rear", occupied->LitLights()[VehicleEnd::rear]); } // reverser dict->insert("direction", occupied->DirActive); diff --git a/vehicle/cab/update.cpp b/vehicle/cab/update.cpp index 12e854beb..257b0efcc 100644 --- a/vehicle/cab/update.cpp +++ b/vehicle/cab/update.cpp @@ -966,16 +966,16 @@ void TTrain::updateTrainLamps() btLampkaSpringBrakeInactive.Turn(!occupied->brakes.spring.isActive); // light indicators // NOTE: sides are hardcoded to deal with setups where single cab is equipped with all indicators - btLampkaUpperLight.Turn((occupied->iLights[VehicleEnd::front] & light::headlight_upper) != 0); - btLampkaLeftLight.Turn((occupied->iLights[VehicleEnd::front] & light::headlight_left) != 0); - btLampkaRightLight.Turn((occupied->iLights[VehicleEnd::front] & light::headlight_right) != 0); - btLampkaLeftEndLight.Turn((occupied->iLights[VehicleEnd::front] & light::redmarker_left) != 0); - btLampkaRightEndLight.Turn((occupied->iLights[VehicleEnd::front] & light::redmarker_right) != 0); - btLampkaRearUpperLight.Turn((occupied->iLights[VehicleEnd::rear] & light::headlight_upper) != 0); - btLampkaRearLeftLight.Turn((occupied->iLights[VehicleEnd::rear] & light::headlight_left) != 0); - btLampkaRearRightLight.Turn((occupied->iLights[VehicleEnd::rear] & light::headlight_right) != 0); - btLampkaRearLeftEndLight.Turn((occupied->iLights[VehicleEnd::rear] & light::redmarker_left) != 0); - btLampkaRearRightEndLight.Turn((occupied->iLights[VehicleEnd::rear] & light::redmarker_right) != 0); + btLampkaUpperLight.Turn((occupied->LitLights()[VehicleEnd::front] & light::headlight_upper) != 0); + btLampkaLeftLight.Turn((occupied->LitLights()[VehicleEnd::front] & light::headlight_left) != 0); + btLampkaRightLight.Turn((occupied->LitLights()[VehicleEnd::front] & light::headlight_right) != 0); + btLampkaLeftEndLight.Turn((occupied->LitLights()[VehicleEnd::front] & light::redmarker_left) != 0); + btLampkaRightEndLight.Turn((occupied->LitLights()[VehicleEnd::front] & light::redmarker_right) != 0); + btLampkaRearUpperLight.Turn((occupied->LitLights()[VehicleEnd::rear] & light::headlight_upper) != 0); + btLampkaRearLeftLight.Turn((occupied->LitLights()[VehicleEnd::rear] & light::headlight_left) != 0); + btLampkaRearRightLight.Turn((occupied->LitLights()[VehicleEnd::rear] & light::headlight_right) != 0); + btLampkaRearLeftEndLight.Turn((occupied->LitLights()[VehicleEnd::rear] & light::redmarker_left) != 0); + btLampkaRearRightEndLight.Turn((occupied->LitLights()[VehicleEnd::rear] & light::redmarker_right) != 0); // others btLampkaMalfunction.Turn(controlled->diesel.heat.PA); // overheat indicator lamps @@ -1389,7 +1389,7 @@ void TTrain::updateHeatingAndInstrumentLights() InstrumentLightType == 4 ? occupied->lowVoltage.Is24vAvailable() || occupied->lowVoltage.Is110vAvailable() : false)}; InstrumentLightActive = InstrumentLightType == 3 ? true : // TODO: link the light state with the state of the master key - InstrumentLightType == 4 ? occupied->iLights[VehicleEnd::front] != 0 || occupied->iLights[VehicleEnd::rear] != 0 : + InstrumentLightType == 4 ? occupied->LitLights()[VehicleEnd::front] != 0 || occupied->LitLights()[VehicleEnd::rear] != 0 : InstrumentLightActive; btInstrumentLight.Turn(InstrumentLightActive && lightpower); btDashboardLight.Turn(DashboardLightActive && lightpower); diff --git a/vehicle/dynamic/lifecycle.cpp b/vehicle/dynamic/lifecycle.cpp index 6e0c52cd6..3af162884 100644 --- a/vehicle/dynamic/lifecycle.cpp +++ b/vehicle/dynamic/lifecycle.cpp @@ -507,7 +507,7 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424" { auto const indexstart { 0 }; auto const indexend { ActPar.find_first_not_of( "1234567890", indexstart ) }; - physics->MaxLoad = std::atoi( ActPar.substr( indexstart, indexend ).c_str() ); + physics->SetMaxLoad(std::atoi( ActPar.substr( indexstart, indexend ).c_str() )); ActPar.erase( 0, indexend ); } while( false == ActPar.empty() ) { diff --git a/vehicle/dynamic/lights.cpp b/vehicle/dynamic/lights.cpp index 132ebcdb0..b531cd9c0 100644 --- a/vehicle/dynamic/lights.cpp +++ b/vehicle/dynamic/lights.cpp @@ -114,9 +114,9 @@ void TDynamicObject::RaLightsSet(int head, int rear) // w zależności od kierunku pojazdu w składzie if( head >= 0 ) { auto const vehicleend { iDirection > 0 ? VehicleEnd::front : VehicleEnd::rear }; - physics->iLights[ vehicleend ] = head & iInventory[vehicleend]; - bool tLeft = physics->iLights[vehicleend] & (light::auxiliary_left | light::headlight_left); // roboczo czy jakiekolwiek swiatlo z lewej jest zapalone - bool tRight = physics->iLights[vehicleend] & (light::auxiliary_right | light::headlight_right); // a tu z prawej + physics->SetLitLights( vehicleend, head & iInventory[vehicleend] ); + bool tLeft = physics->LitLights()[vehicleend] & (light::auxiliary_left | light::headlight_left); // roboczo czy jakiekolwiek swiatlo z lewej jest zapalone + bool tRight = physics->LitLights()[vehicleend] & (light::auxiliary_right | light::headlight_right); // a tu z prawej if (Controller == Humandriver) { auto const dps{physics->currentDimPosition()}; @@ -128,7 +128,7 @@ void TDynamicObject::RaLightsSet(int head, int rear) // obsługa OFF if (dps.isOff) { - //physics->iLights[vehicleend] &= 0 | light::rearendsignals; // zostawiamy tylko tabliczki jesli sa + //physics->SetLitLights(vehicleend, physics->LitLights()[vehicleend] & (0 | light::rearendsignals)); // zostawiamy tylko tabliczki jesli sa HighBeamLights = false; DimHeadlights = false; // the headlights at the end of the active cab: A at the front, B at the rear @@ -156,7 +156,7 @@ void TDynamicObject::RaLightsSet(int head, int rear) } if( rear >= 0 ) { auto const vehicleend{ iDirection > 0 ? VehicleEnd::rear : VehicleEnd::front }; - physics->iLights[ vehicleend ] = rear & iInventory[vehicleend]; + physics->SetLitLights( vehicleend, rear & iInventory[vehicleend] ); } }; @@ -212,7 +212,7 @@ bool TDynamicObject::has_signal_pc1_on() const { auto const pattern { equippedlights & ( light::headlight_left | light::headlight_right | light::headlight_upper ) }; auto const patternfallback { equippedlights & ( light::auxiliary_left | light::auxiliary_right | light::headlight_upper ) }; auto const hasauxiliarylights { ( equippedlights & ( light::auxiliary_left | light::auxiliary_right ) ) != 0 }; - auto const activelights { physics->iLights[ vehicleend ] }; + auto const activelights { physics->LitLights()[ vehicleend ] }; return (pattern != 0 && activelights == pattern) || (hasauxiliarylights && activelights == patternfallback) || (pattern == 0 && patternfallback == 0 && activelights == light::rearendsignals); // pc4 @@ -225,7 +225,7 @@ bool TDynamicObject::has_signal_pc2_on() const { auto const pattern { equippedlights & ( light::redmarker_left | light::headlight_right | light::headlight_upper ) }; auto const patternfallback { equippedlights & ( light::redmarker_left | light::auxiliary_right | light::headlight_upper ) }; auto const hasauxiliarylights { ( equippedlights & ( light::auxiliary_left | light::auxiliary_right ) ) != 0 }; - auto const activelights { physics->iLights[ vehicleend ] }; + auto const activelights { physics->LitLights()[ vehicleend ] }; return activelights == pattern || (hasauxiliarylights && activelights == patternfallback); } @@ -236,7 +236,7 @@ bool TDynamicObject::has_signal_pc5_on() const { auto const equippedlights { iInventory[ vehicleend ] }; auto const pattern { equippedlights & ( light::redmarker_left | light::redmarker_right ) }; auto const patternfallback { equippedlights & light::rearendsignals }; - auto const activelights { physics->iLights[ vehicleend ] }; + auto const activelights { physics->LitLights()[ vehicleend ] }; return (pattern != 0 && activelights == pattern) || (patternfallback != 0 && activelights == patternfallback); } @@ -246,9 +246,9 @@ bool TDynamicObject::has_signal_on( VehicleEnd const Side, int const Pattern ) c auto const vehicleend { iDirection > 0 ? Side : 1 - Side }; auto const pattern { iInventory[ vehicleend ] & Pattern }; - return ( physics->iLights[ vehicleend ] == pattern ); + return ( physics->LitLights()[ vehicleend ] == pattern ); */ - return physics->iLights[Side] == (Pattern & iInventory[Side]); + return physics->LitLights()[Side] == (Pattern & iInventory[Side]); } TDimension const &TDynamicObject::Dimensions() const { @@ -295,7 +295,7 @@ bool TDynamicObject::LowVoltagePowered() const { } int TDynamicObject::LightsSwitchedOn( VehicleEnd const End ) const { - return physics->iLights[ End ]; + return physics->LitLights()[ End ]; } double TDynamicObject::HeadlightsMultiplier() const { diff --git a/vehicle/dynamic/load.cpp b/vehicle/dynamic/load.cpp index 026761d23..309fe4033 100644 --- a/vehicle/dynamic/load.cpp +++ b/vehicle/dynamic/load.cpp @@ -154,24 +154,20 @@ void TDynamicObject::update_exchange( double const Deltatime ) { m_exchange.time -= 1.0; auto const exchangesize = std::min( m_exchange.unload_count, physics->UnLoadSpeed * exchangespeed ); m_exchange.unload_count -= exchangesize; - physics->LoadStatus = 1; - physics->LoadAmount = std::max( 0.f, physics->LoadAmount - exchangesize ); - physics->ComputeMass(); + physics->UnloadStep( exchangesize ); update_load_visibility(); } if( m_exchange.unload_count < 0.01 ) { // finish any potential unloading operation before adding new load // don't load more than can fit - m_exchange.load_count = std::min( m_exchange.load_count, physics->MaxLoad - physics->LoadAmount ); + m_exchange.load_count = std::min( m_exchange.load_count, physics->MaxLoad() - physics->LoadAmount() ); while( m_exchange.load_count > 0.01 && m_exchange.time >= 1.0 ) { m_exchange.time -= 1.0; auto const exchangesize = std::min( m_exchange.load_count, physics->LoadSpeed * exchangespeed ); m_exchange.load_count -= exchangesize; - physics->LoadStatus = 2; - physics->LoadAmount = std::min( physics->MaxLoad, physics->LoadAmount + exchangesize ); // std::max not strictly needed but, eh - physics->ComputeMass(); + physics->LoadStep( exchangesize ); update_load_visibility(); } } @@ -187,7 +183,7 @@ void TDynamicObject::update_exchange( double const Deltatime ) { if( m_exchange.unload_count < 0.01 && m_exchange.load_count < 0.01 ) { - physics->LoadStatus = 4; + physics->FinishLoadExchange(); // if the exchange is completed (or canceled) close the door, if applicable if( physics->Doors.close_control == control_t::passenger || physics->Doors.close_control == control_t::mixed ) { @@ -202,7 +198,7 @@ void TDynamicObject::update_exchange( double const Deltatime ) { } } // if the vehicle was emptied potentially switch load visualization model - if( physics->LoadAmount == 0 ) { + if( physics->LoadAmount() == 0 ) { physics->AssignLoad( "" ); } } @@ -210,11 +206,10 @@ void TDynamicObject::update_exchange( double const Deltatime ) { void TDynamicObject::LoadUpdate() { - physics->LoadStatus &= 1 | 2; // po zakończeniu będzie równe zero + physics->AcknowledgeLoadExchange(); // po zakończeniu będzie równe zero // przeładowanie modelu ładunku - if( physics->LoadTypeChange ) { - // whether we succeed or not don't try more than once - physics->LoadTypeChange = false; + // whether we succeed or not don't try more than once + if( physics->TakeLoadTypeChange() ) { // bieżąca ścieżka do tekstur to dynamic/... Global.asCurrentTexturePath = asBaseDir; mdLoad = LoadMMediaFile_mdload( physics->LoadType.name ); @@ -264,9 +259,9 @@ TDynamicObject::update_load_visibility() { // each entry in load order sequence matches a single chunk of the section it points to // the length of load order sequence matches total number of load chunks auto const loadpercentage { ( - physics->MaxLoad == 0.f ? + physics->MaxLoad() == 0.f ? 0.0 : - physics->LoadAmount / physics->MaxLoad ) }; + physics->LoadAmount() / physics->MaxLoad() ) }; auto visiblechunkcount { ( SectionLoadOrder.empty() ? 0 : @@ -284,9 +279,9 @@ TDynamicObject::update_load_offset() { if( physics->LoadType.offset_min == 0.f ) { return; } auto const loadpercentage { ( - physics->MaxLoad == 0.f ? + physics->MaxLoad() == 0.f ? 0.0 : - 100.0 * physics->LoadAmount / physics->MaxLoad ) }; + 100.0 * physics->LoadAmount() / physics->MaxLoad() ) }; LoadOffset = std::lerp( physics->LoadType.offset_min, 0.f, safe_clamp( 0.0, 1.0, loadpercentage * 0.01 ) ); } diff --git a/vehicle/dynamic/movement.cpp b/vehicle/dynamic/movement.cpp index 3fd4687cc..0cccff345 100644 --- a/vehicle/dynamic/movement.cpp +++ b/vehicle/dynamic/movement.cpp @@ -293,7 +293,7 @@ bool TDynamicObject::FastUpdate(double dt) // ResetdMoveLen(); FastMove(dDOMoveLen); - if( physics->LoadStatus ) { + if( physics->LoadStatus() ) { LoadUpdate(); // zmiana modelu ładunku } update_exchange( dt ); diff --git a/vehicle/dynamic/sounds.cpp b/vehicle/dynamic/sounds.cpp index 8628b4b71..778b2163b 100644 --- a/vehicle/dynamic/sounds.cpp +++ b/vehicle/dynamic/sounds.cpp @@ -103,7 +103,7 @@ void TDynamicObject::RenderSounds() { renderPhysicsEventSounds(); renderCouplerSounds(); - physics->SoundFlag = 0; + physics->ClearSoundFlags(); // McZapkie! - koniec obslugi dzwiekow z physics.pas renderDerailmentSounds(); @@ -468,13 +468,13 @@ void TDynamicObject::renderSpringBrakeSounds() { void TDynamicObject::renderLoadExchangeSounds() { // load exchange - if( physics->LoadStatus & 1 ) { + if( physics->LoadStatus() & 1 ) { m_exchangesounds.unloading.play( sound_flags::exclusive ); } else { m_exchangesounds.unloading.stop(); } - if( physics->LoadStatus & 2 ) { + if( physics->LoadStatus() & 2 ) { m_exchangesounds.loading.play( sound_flags::exclusive ); } else { @@ -830,16 +830,16 @@ void TDynamicObject::renderStartJoltSound() { void TDynamicObject::renderPhysicsEventSounds() { // pneumatic relay - if( TestFlag( physics->SoundFlag, sound::pneumatic ) ) { + if( TestFlag( physics->SoundFlag(), sound::pneumatic ) ) { dsbPneumaticRelay .gain( - true == TestFlag( physics->SoundFlag, sound::loud ) ? + true == TestFlag( physics->SoundFlag(), sound::loud ) ? 1.0f : 0.8f ) .play(); } // door permit - if( TestFlag( physics->SoundFlag, sound::doorpermit ) ) { + if( TestFlag( physics->SoundFlag(), sound::doorpermit ) ) { // NOTE: current implementation doesn't discern between permit for left/right side, // which may be undesired in weird setups with doors only on one side // TBD, TODO: rework into dedicated sound event flag for each door location instance? @@ -983,13 +983,13 @@ void TDynamicObject::renderDerailmentSounds() { } // special events - if( physics->EventFlag ) { + if( physics->EventFlag() ) { // McZapkie: w razie wykolejenia if( true == physics->DamageFlag.HasAll(VehicleDamage::derailed) ) { rsDerailment.play( sound_flags::exclusive ); } - physics->EventFlag = false; + physics->ClearEventFlag(); } } @@ -1561,7 +1561,7 @@ void TDynamicObject::powertrain_sounds::renderRelaySounds( physics::Vehicle const &Vehicle ) { // relay sounds - auto const soundflags { Vehicle.SoundFlag }; + auto const soundflags { Vehicle.SoundFlag() }; if( TestFlag( soundflags, sound::relay ) ) { // przekaznik - gdy bezpiecznik, automatyczny rozruch itp if( true == TestFlag( soundflags, sound::shuntfield ) ) { diff --git a/vehicle/dynamic/update.cpp b/vehicle/dynamic/update.cpp index e14973129..f21a5241b 100644 --- a/vehicle/dynamic/update.cpp +++ b/vehicle/dynamic/update.cpp @@ -176,7 +176,7 @@ bool TDynamicObject::Update(double dt, double dt1) physics->InactiveCabPantsCheck = false; } - if( physics->LoadStatus ) { + if( physics->LoadStatus() ) { LoadUpdate(); // zmiana modelu ładunku } update_exchange( dt ); @@ -356,7 +356,7 @@ void TDynamicObject::switchOffMainsWithoutBattery() if( physics->MainSwitch( false, physics->TrainType == train_type::emu ? range_t::unit : range_t::local ) ) { // wyłączyć zasilanie // NOTE: we turn off entire EMU, but only the affected unit for other multi-unit consists - physics->EventFlag = true; + physics->RaiseEventFlag(); // drop pantographs // NOTE: this isn't universal behaviour // TODO: have this dependant on .fiz-driven flag diff --git a/vehicle/dynamic/vehicletable.cpp b/vehicle/dynamic/vehicletable.cpp index 544866862..f9698ae9a 100644 --- a/vehicle/dynamic/vehicletable.cpp +++ b/vehicle/dynamic/vehicletable.cpp @@ -650,7 +650,7 @@ vehicle_table::update_steps_parallel( double const Deltatime, int const Iteratio std::begin( m_groups[ group ] ), std::end( m_groups[ group ] ), [ this ]( std::uint32_t const Index ) { auto const *vehicle { m_items[ Index ] }; - return ( vehicle->physics->LoadStatus != 0 ) || ( vehicle->LoadExchangeTime() > 0.f ); } ) }; + return ( vehicle->physics->LoadStatus() != 0 ) || ( vehicle->LoadExchangeTime() > 0.f ); } ) }; ( loading ? m_maingroups : m_threadgroups ).push_back( static_cast( group ) ); } std::sort( diff --git a/vehicle/dynamic/visual.cpp b/vehicle/dynamic/visual.cpp index df1326fc9..0bb307857 100644 --- a/vehicle/dynamic/visual.cpp +++ b/vehicle/dynamic/visual.cpp @@ -349,36 +349,36 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) if (physics->lowVoltage.Is24vAvailable() || physics->lowVoltage.Is110vAvailable()) { // sygnaly konca pociagu if (m_endsignals1.Active()) { - if (TestFlag(physics->iLights[VehicleEnd::front], light::redmarker_left | light::redmarker_right ) ) { + if (TestFlag(physics->LitLights()[VehicleEnd::front], light::redmarker_left | light::redmarker_right ) ) { m_endsignals1.Turn( true ); btnOn = true; } } else { - if (TestFlag(physics->iLights[VehicleEnd::front], light::redmarker_left) && !HeadlightsAoff) + if (TestFlag(physics->LitLights()[VehicleEnd::front], light::redmarker_left) && !HeadlightsAoff) { m_endsignal13.Turn( true ); btnOn = true; } - if (TestFlag(physics->iLights[VehicleEnd::front], light::redmarker_right) && !HeadlightsAoff) + if (TestFlag(physics->LitLights()[VehicleEnd::front], light::redmarker_right) && !HeadlightsAoff) { m_endsignal12.Turn( true ); btnOn = true; } } if (m_endsignals2.Active()) { - if (TestFlag(physics->iLights[VehicleEnd::rear], light::redmarker_left | light::redmarker_right ) ) { + if (TestFlag(physics->LitLights()[VehicleEnd::rear], light::redmarker_left | light::redmarker_right ) ) { m_endsignals2.Turn( true ); btnOn = true; } } else { - if (TestFlag(physics->iLights[VehicleEnd::rear], light::redmarker_left) && !HeadlightsBoff) + if (TestFlag(physics->LitLights()[VehicleEnd::rear], light::redmarker_left) && !HeadlightsBoff) { m_endsignal23.Turn( true ); btnOn = true; } - if (TestFlag(physics->iLights[VehicleEnd::rear], light::redmarker_right) && !HeadlightsBoff) + if (TestFlag(physics->LitLights()[VehicleEnd::rear], light::redmarker_right) && !HeadlightsBoff) { m_endsignal22.Turn( true ); btnOn = true; @@ -386,12 +386,12 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) } } // tablice blaszane: - if (TestFlag(physics->iLights[VehicleEnd::front], light::rearendsignals)) { + if (TestFlag(physics->LitLights()[VehicleEnd::front], light::rearendsignals)) { m_endtab1.Turn( true ); btnOn = true; } // else btEndSignalsTab1.TurnOff(); - if (TestFlag(physics->iLights[VehicleEnd::rear], light::rearendsignals)) { + if (TestFlag(physics->LitLights()[VehicleEnd::rear], light::rearendsignals)) { m_endtab2.Turn( true ); btnOn = true; } @@ -446,7 +446,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) // ograniczeń odległości, by były widoczne z // daleka - if (TestFlag(physics->iLights[VehicleEnd::front], light::headlight_left) + if (TestFlag(physics->LitLights()[VehicleEnd::front], light::headlight_left) && !HeadlightsAoff && !HighBeamLights) { if( DimHeadlights ) { @@ -457,7 +457,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) } btnOn = true; } - if (TestFlag(physics->iLights[VehicleEnd::front], light::headlight_upper) + if (TestFlag(physics->LitLights()[VehicleEnd::front], light::headlight_upper) && !HeadlightsAoff) { if( DimHeadlights ) { @@ -468,7 +468,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) } btnOn = true; } - if (TestFlag(physics->iLights[VehicleEnd::front], light::headlight_right) + if (TestFlag(physics->LitLights()[VehicleEnd::front], light::headlight_right) && !HeadlightsAoff && !HighBeamLights) { if( DimHeadlights ) { @@ -480,7 +480,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) btnOn = true; } // else btHeadSignals13.TurnOff(); - if (TestFlag(physics->iLights[VehicleEnd::rear], light::headlight_left) + if (TestFlag(physics->LitLights()[VehicleEnd::rear], light::headlight_left) && !HeadlightsBoff && !HighBeamLights) { if( DimHeadlights ) { @@ -491,7 +491,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) } btnOn = true; } - if (TestFlag(physics->iLights[VehicleEnd::rear], light::headlight_upper) + if (TestFlag(physics->LitLights()[VehicleEnd::rear], light::headlight_upper) && !HeadlightsBoff) { if( DimHeadlights ) { @@ -502,7 +502,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) } btnOn = true; } - if (TestFlag(physics->iLights[VehicleEnd::rear], light::headlight_right) + if (TestFlag(physics->LitLights()[VehicleEnd::rear], light::headlight_right) && !HeadlightsBoff && !HighBeamLights) { if( DimHeadlights ) { @@ -514,7 +514,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) btnOn = true; } // auxiliary lights - if (TestFlag(physics->iLights[VehicleEnd::front], light::auxiliary_left) && !HeadlightsAoff) + if (TestFlag(physics->LitLights()[VehicleEnd::front], light::auxiliary_left) && !HeadlightsAoff) { if( DimHeadlights ) { m_headsignal13.TurnxOnWithOnAsFallback(); @@ -524,7 +524,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) } btnOn = true; } - if (TestFlag(physics->iLights[VehicleEnd::front], light::auxiliary_right) && !HeadlightsAoff) + if (TestFlag(physics->LitLights()[VehicleEnd::front], light::auxiliary_right) && !HeadlightsAoff) { if( DimHeadlights ) { m_headsignal12.TurnxOnWithOnAsFallback(); @@ -534,7 +534,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) } btnOn = true; } - if (TestFlag(physics->iLights[VehicleEnd::rear], light::auxiliary_left) && !HeadlightsBoff) + if (TestFlag(physics->LitLights()[VehicleEnd::rear], light::auxiliary_left) && !HeadlightsBoff) { if( DimHeadlights ) { m_headsignal23.TurnxOnWithOnAsFallback(); @@ -544,7 +544,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) } btnOn = true; } - if (TestFlag(physics->iLights[VehicleEnd::rear], light::auxiliary_right) && !HeadlightsBoff) + if (TestFlag(physics->LitLights()[VehicleEnd::rear], light::auxiliary_right) && !HeadlightsBoff) { if( DimHeadlights ) { m_headsignal22.TurnxOnWithOnAsFallback(); @@ -556,26 +556,26 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) } // logika dlugich - if (TestFlag(physics->iLights[VehicleEnd::front], light::headlight_left) + if (TestFlag(physics->LitLights()[VehicleEnd::front], light::headlight_left) && !HeadlightsAoff && HighBeamLights) m_highbeam13.TurnxOnWithOnAsFallback(); else m_highbeam13.TurnOff(); - if (TestFlag(physics->iLights[VehicleEnd::front], light::headlight_right) + if (TestFlag(physics->LitLights()[VehicleEnd::front], light::headlight_right) && !HeadlightsAoff && HighBeamLights) m_highbeam12.TurnxOnWithOnAsFallback(); else m_highbeam12.TurnOff(); // i to samo od dupy strony - if (TestFlag(physics->iLights[VehicleEnd::rear], light::headlight_left) + if (TestFlag(physics->LitLights()[VehicleEnd::rear], light::headlight_left) && !HeadlightsBoff && HighBeamLights) m_highbeam23.TurnxOnWithOnAsFallback(); else m_highbeam23.TurnOff(); - if (TestFlag(physics->iLights[VehicleEnd::rear], light::headlight_right) + if (TestFlag(physics->LitLights()[VehicleEnd::rear], light::headlight_right) && !HeadlightsBoff && HighBeamLights) m_highbeam22.TurnxOnWithOnAsFallback(); else diff --git a/widgets/vehicleparams.cpp b/widgets/vehicleparams.cpp index 14d708950..b80cb28a7 100644 --- a/widgets/vehicleparams.cpp +++ b/widgets/vehicleparams.cpp @@ -80,17 +80,17 @@ void ui::vehicleparams_panel::draw_mini(const physics::Vehicle &physics) if (physics.WarningSignal()) draw_infobutton(STR_C("horn"), ImVec2(361, 11)); - if (physics.iLights[VehicleEnd::front] & light::redmarker_left) + if (physics.LitLights()[VehicleEnd::front] & light::redmarker_left) draw_infobutton("o", ImVec2(490, 71), ImVec4(1.0f, 0.0f, 0.0f, 1.0f)); - else if (physics.iLights[VehicleEnd::front] & light::headlight_left) + else if (physics.LitLights()[VehicleEnd::front] & light::headlight_left) draw_infobutton("O", ImVec2(490, 71), ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); - if (physics.iLights[VehicleEnd::front] & light::redmarker_right) + if (physics.LitLights()[VehicleEnd::front] & light::redmarker_right) draw_infobutton("o", ImVec2(443, 71), ImVec4(1.0f, 0.0f, 0.0f, 1.0f)); - else if (physics.iLights[VehicleEnd::front] & light::headlight_right) + else if (physics.LitLights()[VehicleEnd::front] & light::headlight_right) draw_infobutton("O", ImVec2(443, 71), ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); - if (physics.iLights[VehicleEnd::front] & light::headlight_upper) + if (physics.LitLights()[VehicleEnd::front] & light::headlight_upper) draw_infobutton("O", ImVec2(467, 18), ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); } ImGui::EndChild(); diff --git a/world/Event.cpp b/world/Event.cpp index 4c8283742..b1c17dc6b 100644 --- a/world/Event.cpp +++ b/world/Event.cpp @@ -1065,15 +1065,15 @@ whois_event::run_() { // jeśli parametry ładunku targetcell->UpdateValues( m_activator->physics->LoadType.name, // nazwa ładunku - m_activator->physics->LoadAmount, // aktualna ilość - m_activator->physics->MaxLoad, // maksymalna ilość + m_activator->physics->LoadAmount(), // aktualna ilość + m_activator->physics->MaxLoad(), // maksymalna ilość m_input.flags & ( flags::text | flags::value1 | flags::value2 ) ); WriteLog( "Type: WhoIs (" + std::to_string( m_input.flags ) + ") - " + "[load type: " + m_activator->physics->LoadType.name + "], " - + "[current load: " + to_string( m_activator->physics->LoadAmount, 2 ) + "], " - + "[max load: " + to_string( m_activator->physics->MaxLoad, 2 ) + "]" ); + + "[current load: " + to_string( m_activator->physics->LoadAmount(), 2 ) + "], " + + "[max load: " + to_string( m_activator->physics->MaxLoad(), 2 ) + "]" ); } } // +8 diff --git a/world/station.cpp b/world/station.cpp index 40c343118..c5572133e 100644 --- a/world/station.cpp +++ b/world/station.cpp @@ -49,7 +49,7 @@ basic_station::update_load( TDynamicObject *First, Mtable::TTrainParameters &Sch if( parameters.LoadType.name.empty() ) { // (try to) set the cargo type for empty cars - parameters.LoadAmount = 0.f; // safety measure against edge cases + parameters.SetLoadAmount(0.f); // safety measure against edge cases parameters.AssignLoad( "passengers" ); parameters.ComputeMass(); } @@ -58,18 +58,18 @@ basic_station::update_load( TDynamicObject *First, Mtable::TTrainParameters &Sch // NOTE: for the time being we're doing simple, random load change calculation // TODO: exchange driven by station parameters and time of the day auto unloadcount = static_cast( - parameters.DamageFlag.HasAll(VehicleDamage::derailed) ? parameters.LoadAmount : - laststop ? parameters.LoadAmount : + parameters.DamageFlag.HasAll(VehicleDamage::derailed) ? parameters.LoadAmount() : + laststop ? parameters.LoadAmount() : firststop ? 0 : maintenancestop ? 0 : std::min( - parameters.LoadAmount, - static_cast(Random( parameters.MaxLoad * 0.15f * stationsizemodifier )) ) ); + parameters.LoadAmount(), + static_cast(Random( parameters.MaxLoad() * 0.15f * stationsizemodifier )) ) ); auto loadcount = static_cast( parameters.DamageFlag.HasAll(VehicleDamage::derailed) ? 0 : laststop ? 0 : maintenancestop ? 0 : - Random( parameters.MaxLoad * 0.15f * stationsizemodifier ) ); + Random( parameters.MaxLoad() * 0.15f * stationsizemodifier ) ); if( true == firststop ) { // larger group at the initial station loadcount *= 2;