18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 18:47:06 +01:00

refactor(physics): the last outside writes into the vehicle go through operations

What the AI, the cab and TDynamicObject still set in the physics directly is
named now: the stabiliser of the brake pipe reset as a driver takes over a cab
(ResetPipeStabiliser()), the spring brake released by hand
(ReleaseSpringBrake()), the mode of the brake (SetBrakeOperatingMode()), the
brake cut out by the player (ClaimBrakeCutOut()), the pressure of the consist's
brake pipe (SetEquivalentPipePressure()), the inverters switched from the cab
(SwitchInverter()), the odometer (SetOdometer(), ShowOdometer()).

The state the pantographs' sounds last followed belonged to the sounds, not to
the physics: it moves from basic_pantograph to TDynamicObject.

Outside physics/ nothing writes into a vehicle's state any more but the
definition the scenery and the .mmd adjust as the vehicle loads.

No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
This commit is contained in:
2026-11-29 12:52:28 +01:00
parent f65411a668
commit 439adc2f46
9 changed files with 37 additions and 17 deletions
-1
View File
@@ -132,7 +132,6 @@ struct basic_pantograph
basic_valve valve; // associated pneumatic valve
// ld outputs
bool is_active{false}; // device is working
bool sound_event{false}; // indicates last state which generated sound event
double voltage{0.0};
};
+20
View File
@@ -1710,6 +1710,26 @@ class Vehicle
void FuseOff(void); // wylaczenie nadmiarowego
// the faults of the equipment the scenery or the network sets: each sets its fault, or clears it where it was set
void SetEquipmentFaults(EquipmentFaultSet Faults);
// the stabiliser of the brake pipe set to the pressure the pipe has, as a driver taking over a cab finds it
void ResetPipeStabiliser()
{
brakes.pipeLimiterPressure = brakePipe.Pressure();
actFlowSpeed = 0;
}
// the spring brake released by hand, without the command to the other vehicles (SpringBrakeActivate())
void ReleaseSpringBrake() { brakes.spring.activate = false; }
// the mode of the brake (bom_*: PS/PN/EP/MED) set at the selector
void SetBrakeOperatingMode(int const Mode) { brakes.operatingMode = Mode; }
// the brake cut out or put back by the player, which the AI's wagon inspector no longer puts back on its own
void ClaimBrakeCutOut() { brakes.cutOutByInspector = false; }
// the pressure of the brake pipe of the consist, as the driver's vehicle measures it
void SetEquivalentPipePressure(double const Pressure) { brakes.equivalentPipePressure = Pressure; }
// the inverters of an induction motor drive, switched in and out from the cab
bool InverterActivated(std::size_t const Index) const { return inductionMotor.inverters[Index].Activate; }
void SwitchInverter(std::size_t const Index, bool const State) { inductionMotor.inverters[Index].Activate = State; }
// the distance run, kept between the sessions, and whether a cab shows it
void SetOdometer(odometer::reading const &Reading) { Odometer = Reading; }
void ShowOdometer() { Odometer.shown = true; }
bool UniversalResetButton(int const Button, range_t const Notify = range_t::consist);
bool RelayReset(int const Relays, range_t const Notify = range_t::consist); // resets specified relays
// the drive of the kind of engine of the vehicle (physics/components/drive.h)
+2
View File
@@ -1046,6 +1046,8 @@ public:
// the blending of the ED and EP brakes of the consist this vehicle leads, with induction motors
physics::ConsistBrakeBlending brakeBlending;
// the state of each pantograph the sounds last followed, up or down
ByEnd<bool> m_pantographsoundstate{ false, false };
// vehicle shaking calculations
// TBD, TODO: make an object out of it
+3 -4
View File
@@ -107,8 +107,7 @@ void TController::Activation()
if( occupied->brakes.config.handlePositions > 0
&& ( BrakeSystem == TBrakeSystem::Pneumatic
|| BrakeSystem == TBrakeSystem::ElectroPneumatic ) ) {
occupied->brakes.pipeLimiterPressure = occupied->brakePipe.Pressure();
occupied->SetActFlowSpeed(0);
occupied->ResetPipeStabiliser();
}
BrakeLevelSet( occupied->brakes.HandlePosition() );
}
@@ -170,7 +169,7 @@ void TController::AutoRewident()
}
// potentially release manual brake
d->physics->DecManualBrakeLevel( ManualBrakePosNo );
d->physics->brakes.spring.activate = false;
d->physics->ReleaseSpringBrake();
}
BrakeReinspectionPending = reinspect;
//ustawianie trybu pracy zadajnika hamulca, wystarczy raz po inicjalizacji AI
@@ -178,7 +177,7 @@ void TController::AutoRewident()
// if a human is in charge leave the brake mode up to them, otherwise do as you like
for( int i = 1; i <= 8; i *= 2 ) {
if( ( occupied->brakes.config.availableOperatingModes & i ) > 0 ) {
occupied->brakes.operatingMode = i;
occupied->SetBrakeOperatingMode(i);
}
}
}
+1 -1
View File
@@ -468,7 +468,7 @@ void TTrain::OnCommand_trainbrakeoperationtoggle(TTrain *Train, command_data con
vehicle->physics->brakes.distributor->SetBrakeStatus(vehicle->physics->brakes.distributor->GetBrakeStatus() ^ b_dmg);
// the brake is the player's now, the wagon inspector won't put it back on its own
vehicle->physics->brakes.cutOutByInspector = false;
vehicle->physics->ClaimBrakeCutOut();
}
}
+3 -3
View File
@@ -421,7 +421,7 @@ void TTrain::OnCommand_inverterenable(TTrain *Train, command_data const &Command
{
if (itemindex < p->physics->inductionMotor.inverterCount)
{
p->physics->inductionMotor.inverters[itemindex].Activate = true;
p->physics->SwitchInverter(itemindex, true);
break;
}
else
@@ -460,7 +460,7 @@ void TTrain::OnCommand_inverterdisable(TTrain *Train, command_data const &Comman
{
if (itemindex < p->physics->inductionMotor.inverterCount)
{
p->physics->inductionMotor.inverters[itemindex].Activate = false;
p->physics->SwitchInverter(itemindex, false);
break;
}
else
@@ -499,7 +499,7 @@ void TTrain::OnCommand_invertertoggle(TTrain *Train, command_data const &Command
{
if (itemindex < p->physics->inductionMotor.inverterCount)
{
p->physics->inductionMotor.inverters[itemindex].Activate = !p->physics->inductionMotor.inverters[itemindex].Activate;
p->physics->SwitchInverter(itemindex, !p->physics->InverterActivated(itemindex));
// visual feedback
item.UpdateValue(p->physics->inductionMotor.inverters[itemindex].Activate ? 1.0 : 0.0, Train->dsbSwitch);
break;
+2 -2
View File
@@ -552,7 +552,7 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName)
DynamicObject->mdKabina->Init(); // obrócenie modelu oraz optymalizacja, również zapisanie binarnego
// the vehicle has a cab, a player is in it: the odometer store keeps the vehicle also when its type has no
// driver's brake valve (eu07/maszyna#72)
DynamicObject->physics->Odometer.shown = true;
DynamicObject->physics->ShowOdometer();
}
set_cab_controls(NewCabNo < 0 ? 2 : NewCabNo);
@@ -2006,7 +2006,7 @@ bool TTrain::initialize_gauge(cParser &Parser, std::string const &Label, int con
gauge.AssignDouble(&controlled->Odometer.km);
// the vehicle the counter counts for is one the odometer store keeps, also in the sessions the counter seeds
// nothing (its state is a saved one by then) and when it's the motor car of the unit the cab is in
controlled->Odometer.shown = true;
controlled->ShowOdometer();
}
else if (Label == "shuntmodepower:")
{
+1 -1
View File
@@ -237,7 +237,7 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424"
// utworzenie parametrów fizyki
physics = new physics::Vehicle(iDirection ? fVel : -fVel, Type_Name, asName, Cab);
// the vehicle carries on with the odometer state of its earlier sessions (eu07/maszyna#72)
physics->Odometer = odometer::starting_state( odometer::states(), asName, asBaseDir );
physics->SetOdometer( odometer::starting_state( odometer::states(), asName, asBaseDir ) );
// McZapkie: TypeName musi byc nazwą CHK/MMD pojazdu
if (!physics->LoadFIZ(asBaseDir))
{ // jak wczytanie CHK się nie uda, to błąd
+5 -5
View File
@@ -302,7 +302,7 @@ void TDynamicObject::updateTractionVoltage( double const dt1 )
void TDynamicObject::updateDriver( double const dt1 )
{
if( Mechanik->primary() ) {
physics->brakes.equivalentPipePressure = GetEPP(); // srednie cisnienie w PG
physics->SetEquivalentPipePressure( GetEPP() ); // srednie cisnienie w PG
}
if (Mechanik->primary() &&
(physics->EngineType == TEngineType::DieselEngine ||
@@ -843,7 +843,7 @@ void TDynamicObject::updatePantographMotion( int const i, TAnimPant *p, double c
void TDynamicObject::playPantographDropSounds()
{
// TBD, TODO: generate sound event during physics update instead?
if( physics->pantographs[VehicleEnd::front].sound_event != physics->pantographs[ VehicleEnd::front ].is_active ) {
if( m_pantographsoundstate[ VehicleEnd::front ] != physics->pantographs[ VehicleEnd::front ].is_active ) {
if( physics->pantographs[ VehicleEnd::front ].is_active ) {
// pantograph moving up
// TBD: add a sound?
@@ -857,9 +857,9 @@ void TDynamicObject::playPantographDropSounds()
}
}
}
physics->pantographs[ VehicleEnd::front ].sound_event = physics->pantographs[ VehicleEnd::front ].is_active;
m_pantographsoundstate[ VehicleEnd::front ] = physics->pantographs[ VehicleEnd::front ].is_active;
}
if( physics->pantographs[ VehicleEnd::rear ].sound_event != physics->pantographs[ VehicleEnd::rear ].is_active ) {
if( m_pantographsoundstate[ VehicleEnd::rear ] != physics->pantographs[ VehicleEnd::rear ].is_active ) {
if( physics->pantographs[ VehicleEnd::rear ].is_active ) {
// pantograph moving up
// TBD: add a sound?
@@ -873,7 +873,7 @@ void TDynamicObject::playPantographDropSounds()
}
}
}
physics->pantographs[ VehicleEnd::rear ].sound_event = physics->pantographs[ VehicleEnd::rear ].is_active;
m_pantographsoundstate[ VehicleEnd::rear ] = physics->pantographs[ VehicleEnd::rear ].is_active;
}
}