18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 14:07:06 +01:00
Files
maszyna/physics/components/devices.h
Hirek 439adc2f46 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.
2026-11-29 12:52:28 +01:00

244 lines
9.0 KiB
C++

/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
// the devices of a vehicle: pumps, fans, valves, pantographs, doors, the genset (nested in physics::Vehicle before)
#pragma once
#include <algorithm>
#include <vector>
#include "physics/vehicletypes.h"
namespace physics
{
/* TODO: implement
// communication cable, exchanging control signals with adjacent vehicle
struct jumper_cable {
// types
using flag_pair = std::pair<bool, bool>;
// members
// booleans
// std::array<bool, 1> flags {};
// boolean pairs, exchanged data is swapped when connected to a matching end (front to front or back to back)
// TBD, TODO: convert to regular bool array for efficiency once it's working?
std::array<flag_pair, 1> flag_pairs {};
// integers
// std::array<int, 1> values {};
};
*/
// basic approximation of a generic device
// TBD: inheritance or composition?
struct basic_device
{
// config
start_t start_type{start_t::manual};
// ld inputs
bool is_enabled{false}; // device is allowed/requested to operate
bool is_disabled{false}; // device is requested to stop
// TODO: add remaining inputs; start conditions and potential breakers
// ld outputs
bool is_active{false}; // device is working
};
struct basic_light : public basic_device
{
// config
float dimming{1.0f}; // light strength multiplier
// ld outputs
float intensity{0.0f}; // current light strength
};
struct cooling_fan : public basic_device
{
// config
float speed{0.f}; // cooling fan rpm; either fraction of parent rpm, or absolute value if negative
float sustain_time{0.f}; // time of sustaining work of cooling fans after stop
float min_start_velocity{-1.f}; // minimal velocity of vehicle, when cooling fans activate
// ld outputs
float revolutions{0.f}; // current fan rpm
float stop_timer{0.f}; // current time, when shut off condition is active
};
// basic approximation of a fuel pump
struct fuel_pump : public basic_device
{
// TODO: fuel consumption, optional automatic engine start after activation
};
// basic approximation of an oil pump
struct oil_pump : public basic_device
{
// config
float pressure_minimum{0.f}; // lowest acceptable working pressure
float pressure_maximum{0.65f}; // oil pressure at maximum engine revolutions
// ld inputs
float resource_amount{1.f}; // amount of affected resource, compared to nominal value
// internal data
float pressure_target{0.f};
// ld outputs
float pressure{0.f}; // current pressure
};
// the diesel generator set of a dual-mode vehicle: a second source of the traction circuit, next to the
// pantographs (eu07/maszyna#536). none unless the .fiz gives GensetPower
struct genset_device : public basic_device
{
// config (Power: Genset*), revolutions in rev/s, the .fiz gives rpm
double power{0.0}; // GensetPower, electric output at full revolutions [kW]; 0 = no genset
double voltage_nominal{0.0}; // GensetVoltage, regulated DC voltage from the idle revolutions up [V]
double revolutions_idle{0.0}; // GensetIdleRPM
double revolutions_max{0.0}; // GensetMaxRPM
double start_time{8.0}; // GensetStartTime, from the start request to running at idle [s]
double spinup_time{3.0}; // GensetSpinUpTime, time constant of the revolutions [s]
double traction_share{1.0}; // GensetPmaxRatio, part of the power the traction may take
// state
double timer{0.0}; // of the start [s]
bool is_cranking{false};
// ld outputs
double revolutions{0.0}; // [rev/s]
double voltage{0.0}; // [V]
bool fitted() const { return power > 0.0; }
// the power the genset gives at its present revolutions [kW]
double available_power() const { return revolutions_max > 0.0 ? power * std::clamp(revolutions / revolutions_max, 0.0, 1.0) : 0.0; }
};
// basic approximation of a water pump
struct water_pump : public basic_device
{
// ld inputs
// TODO: move to breaker list in the basic device once implemented
bool breaker{false}; // device is allowed to operate
};
// basic approximation of a solenoid valve
struct basic_valve : basic_device
{
// config
bool solenoid{true}; // requires electric power to operate
bool spring{true}; // spring return or double acting actuator
};
// basic approximation of a pantograph
struct basic_pantograph
{
// ld inputs
basic_valve valve; // associated pneumatic valve
// ld outputs
bool is_active{false}; // device is working
double voltage{0.0};
};
// basic approximation of doors
struct basic_door
{
// config
// ld inputs
bool open_permit{false}; // door can be opened
bool local_open{false}; // local attempt to open the door
bool local_close{false}; // local attempt to close the door
bool remote_open{false}; // received remote signal to open the door
bool remote_close{false}; // received remote signal to close the door
// internal data
float auto_timer{-1.f}; // delay between activation of open state and closing state for automatic doors
float close_delay{0.f}; // delay between activation of closing state and actual closing
float open_delay{0.f}; // delay between activation of opening state and actual opening
float position{0.f}; // current shift of the door from the closed position
float step_position{0.f}; // current shift of the movable step from the retracted position
// ld outputs
bool is_closed{true}; // the door is fully closed
bool is_door_closed{true}; // the door is fully closed, step doesn't matter
bool is_closing{false}; // the door is currently closing
bool is_opening{false}; // the door is currently opening
bool is_open{false}; // the door is fully open
bool step_folding{false}; // the doorstep is currently closing
bool step_unfolding{false}; // the doorstep is currently opening
};
struct door_data
{
// config
control_t open_control{control_t::passenger};
float open_rate{1.f};
float open_delay{0.f};
control_t close_control{control_t::passenger};
float close_rate{1.f};
float close_delay{0.f};
int type{2};
float range{0.f}; // extent of primary move/rotation
float range_out{0.f}; // extent of shift outward, applicable for plug doors
int step_type{2};
float step_rate{0.5f};
float step_range{0.f};
bool has_lock{false};
bool has_warning{false};
bool has_autowarning{false};
float auto_duration{-1.f}; // automatic door closure delay period
float auto_velocity{-1.f}; // automatic door closure velocity threshold
bool auto_include_remote{false}; // automatic door closure applies also to remote control
bool permit_needed{false};
bool closure_signal{false}; // the door closure lamp (SOD) of the cab signals the doors of the whole consist in three states
std::vector<int> permit_presets; // permit presets selectable with preset switch
float voltage{0.f}; // power type required for door movement
// ld inputs
bool lock_enabled{true};
bool step_enabled{true};
bool remote_only{false}; // door ignores local control signals
// internal data
int permit_preset{-1}; // curent position of preset selection switch
// vehicle parts
BySide<basic_door> instances; // door on the right and left side of the vehicle
// ld outputs
bool is_locked{false};
double doorLockSpeed = 10.0; // predkosc przy ktorej wyzwalana jest blokada drzwi
// what the doors need to know of the vehicle in the step
struct StepInputs
{
double velocity{0.0}; // [km/h]
bool powered{false}; // the doors have the voltage they work on
bool multipleUnit{false}; // the steps fold only once the door has closed
bool exchangingLoad{false}; // the passengers get in or out: the doors that close after a while stay open
};
// the step of the doors: the lock, the requests, the movement of the doors and their steps, the timers
// (physics/components/doors.cpp)
void Update(StepInputs const &Inputs, double Deltatime);
// the state of the door closure signalling (SOD) of the vehicle
door_closure_t Closure() const;
private:
// the permit, the state and the requests of a door, and whether it and its step open or close
void UpdateRequests(basic_door &door, StepInputs const &Inputs, bool localopencontrol, bool remoteopencontrol, bool localclosecontrol, bool remoteclosecontrol);
bool OpenRequest(basic_door const &door, bool localopencontrol, bool remoteopencontrol) const;
bool CloseRequest(basic_door const &door, StepInputs const &Inputs, bool localclosecontrol, bool remoteclosecontrol) const;
bool StepFolding(basic_door const &door) const;
float OpenDuration(basic_door const &door, bool localopencontrol, bool remoteopencontrol) const;
void Move(basic_door &door, StepInputs const &Inputs, double Deltatime);
void UpdateTimers(StepInputs const &Inputs, double Deltatime);
};
struct water_heater
{
// config
struct heater_config_t
{
float temp_min{-1}; // lowest accepted temperature
float temp_max{-1}; // highest accepted temperature
};
heater_config_t config;
// ld inputs
bool breaker{false}; // device is allowed to operate
bool is_enabled{false}; // device is requested to operate
// ld outputs
bool is_active{false}; // device is working
bool is_damaged{false}; // device is damaged
};
} // namespace physics