mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 07:07:05 +01:00
Create vehicle-architecture.md
This commit is contained in:
@@ -0,0 +1,450 @@
|
||||
# The vehicle: physics, driving and dependencies
|
||||
|
||||
How, after the refactorings of `cleanup/mover` (as of 2026-11-29, at `969864f2`), the physics of a vehicle (`physics/`),
|
||||
the vehicle in the scenery (`vehicle/`, `vehicle/dynamic/`), the AI driver (`vehicle/ai/`) and the player's cab
|
||||
(`vehicle/cab/`) work together, and which files outside these folders use them. The rules this split follows are in
|
||||
`AGENTS.md` ("Naming and the vehicle code"); this is a picture of what came of them.
|
||||
|
||||
The diagrams are Mermaid (GitHub and most editors draw them).
|
||||
|
||||
## 1. Layers
|
||||
|
||||
```mermaid
|
||||
flowchart TB
|
||||
subgraph outside["The rest of the simulator"]
|
||||
app["application/<br/>drivermode, UI panels, editor"]
|
||||
input["input/<br/>command_relay, mouse, keyboard"]
|
||||
world["world/<br/>Track, TrkFoll, Event, MemCell"]
|
||||
sim["simulation/<br/>state_manager, serializer, blackbox"]
|
||||
script["scripting/<br/>lua, PyInt, Python screens"]
|
||||
render["rendering/, audio/, scene/"]
|
||||
end
|
||||
|
||||
subgraph veh["vehicle/ (the vehicle in the scenery)"]
|
||||
cab["vehicle/cab/<br/>TTrain: the player's cab"]
|
||||
ai["vehicle/ai/<br/>TController: the driver"]
|
||||
dyn["vehicle/dynamic/<br/>TDynamicObject, vehicle_table"]
|
||||
helpers["vehicle/*.h, *.cpp<br/>small modules without the scene<br/>(brakesetting, handover, horn, ...)"]
|
||||
end
|
||||
|
||||
subgraph phys["physics/ (the physics of the vehicle)"]
|
||||
pv["physics::Vehicle<br/>vehicle.h + components/*.cpp"]
|
||||
comp["components<br/>components/*.h"]
|
||||
models["standalone models<br/>brakes, friction, oerlikonest,<br/>couplerphysics, collision,<br/>derailment, consistbraking"]
|
||||
vocab["vocabulary<br/>vehicletypes.h, vehiclecommand.h"]
|
||||
end
|
||||
|
||||
app --> cab
|
||||
app --> dyn
|
||||
input -->|user_command| cab
|
||||
sim --> dyn
|
||||
world --> dyn
|
||||
world --> ai
|
||||
script --> ai
|
||||
render --> dyn
|
||||
|
||||
cab --> ai
|
||||
cab --> dyn
|
||||
ai --> dyn
|
||||
dyn --> ai
|
||||
cab --> pv
|
||||
ai --> pv
|
||||
dyn --> pv
|
||||
helpers --> pv
|
||||
|
||||
pv --> comp
|
||||
pv --> models
|
||||
comp --> vocab
|
||||
pv --> vocab
|
||||
```
|
||||
|
||||
An arrow means "knows / calls". The rule: `physics/` doesn't know the scene, `vehicle/` knows the physics, and the rest of
|
||||
the simulator reads a vehicle through `TDynamicObject` (its dimensions, speed, cab, lights), not through
|
||||
`physics/vehicle.h`. The exceptions to the rule that are still left are in section 7.
|
||||
|
||||
## 2. The objects at run time
|
||||
|
||||
```mermaid
|
||||
classDiagram
|
||||
direction LR
|
||||
class vehicle_table {
|
||||
simulation::Vehicles
|
||||
update(dt, iterations)
|
||||
update_brake_pipes()
|
||||
update_coupler_physics()
|
||||
}
|
||||
class train_table {
|
||||
simulation::Trains
|
||||
update(dt) / updateAsync(dt)
|
||||
}
|
||||
class TDynamicObject {
|
||||
physics : physics::Vehicle*
|
||||
Mechanik : TController*
|
||||
ctOwner : TController*
|
||||
Axle0, Axle1 : TTrackFollower
|
||||
Update() UpdateForce() FastUpdate()
|
||||
Prev() Next()
|
||||
}
|
||||
class TController {
|
||||
pVehicle : TDynamicObject*
|
||||
mvControlling : physics::Vehicle*
|
||||
occupied : physics::Vehicle*
|
||||
sSpeedTable : TSpeedPos[]
|
||||
Update(dt)
|
||||
PutCommand()
|
||||
}
|
||||
class TTrain {
|
||||
DynamicObject : TDynamicObject*
|
||||
controlled, occupied : physics::Vehicle*
|
||||
secondUnit, thirdUnit
|
||||
m_commandhandlers
|
||||
Update(dt)
|
||||
}
|
||||
class Vehicle["physics::Vehicle"] {
|
||||
Couplers : ByEnd~TCoupling~
|
||||
Neighbours
|
||||
ComputeTotalForce()
|
||||
FastComputeMovement()
|
||||
ComputeMovement()
|
||||
RunCommand() SendCtrlToNext()
|
||||
}
|
||||
|
||||
vehicle_table "1" o-- "*" TDynamicObject
|
||||
train_table "1" o-- "*" TTrain
|
||||
TDynamicObject "1" *-- "1" Vehicle : creates (lifecycle.cpp)
|
||||
TDynamicObject "1" *-- "0..1" TController : Mechanik (lifecycle.cpp)
|
||||
TDynamicObject --> TController : ctOwner (runs the consist)
|
||||
TController --> TDynamicObject : pVehicle, pVehicles
|
||||
TController --> Vehicle : mvControlling, occupied
|
||||
TTrain --> TDynamicObject : DynamicObject
|
||||
TTrain --> Vehicle : controlled, occupied
|
||||
Vehicle --> Vehicle : Couplers.Connected
|
||||
```
|
||||
|
||||
- `TDynamicObject` creates its `physics::Vehicle` (`vehicle/dynamic/lifecycle.cpp`) and, when it is manned, its
|
||||
`TController` (`Mechanik`). `ctOwner` points at the driver who runs the whole consist.
|
||||
- A `TTrain` exists for the vehicles the player can get into (`simulation::Trains`; `simulation::Train` is the one the
|
||||
player is in). It doesn't own its vehicle, it only points at it; when the player changes vehicles (`MoveToVehicle()`,
|
||||
F5) it moves its pointers.
|
||||
- `TController` works for the AI and for the player alike (`AIControllFlag()`): with the player it still keeps the speed
|
||||
table, the hints and the black box, it only leaves the controls alone.
|
||||
- The vehicles of a consist are linked in the physics (`physics::Vehicle::Couplers[].Connected`) and in the scene
|
||||
(`TDynamicObject::Prev()` / `Next()`).
|
||||
|
||||
## 3. A frame of the simulation
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
autonumber
|
||||
participant DM as driver_mode::update<br/>(application/drivermode.cpp)
|
||||
participant SM as state_manager::update<br/>(simulation/simulation.cpp)
|
||||
participant VT as vehicle_table::update<br/>(vehicle/dynamic/vehicletable.cpp)
|
||||
participant DO as TDynamicObject
|
||||
participant PV as physics::Vehicle
|
||||
participant AI as TController
|
||||
participant TR as TTrain::Update<br/>(vehicle/cab/update.cpp)
|
||||
|
||||
DM->>SM: update(dt, iterations)
|
||||
SM->>SM: animations, power grid, road junctions
|
||||
SM->>VT: update(dt, iterations)
|
||||
VT->>DO: update_traction() (overhead voltage), update_neighbours()
|
||||
VT->>VT: update_coupler_physics()
|
||||
loop iterations - 1 steps (optionally on threads)
|
||||
VT->>DO: UpdateForce(dt)
|
||||
DO->>PV: ComputeTotalForce(dt)
|
||||
VT->>DO: FastUpdate(dt)
|
||||
DO->>PV: FastComputeMovement(dt)
|
||||
VT->>VT: update_brake_pipes(dt)
|
||||
end
|
||||
VT->>DO: UpdateForce(dt)
|
||||
VT->>DO: Update(dt, dt1) (the full step)
|
||||
DO->>DO: updateTrackParameters, updateCouplingState, updateTractionVoltage
|
||||
DO->>AI: updateDriver: Mechanik->Update(dt1)
|
||||
AI->>PV: operations (IncMainCtrl, BrakeLevelSet, MainSwitch, ...)
|
||||
DO->>PV: ConsistBrakeBlending.Update(vehicles of the consist)
|
||||
DO->>PV: ComputeMovement(dt, dt1, track, overhead line)
|
||||
DO->>DO: animations, pantographs, wipers, mirrors, load
|
||||
VT->>VT: update_brake_pipes(dt)
|
||||
SM->>SM: TTrack::update_buckling
|
||||
DM->>TR: simulation::Trains.update(dt)
|
||||
TR->>TR: simulation::Commands.pop() -> OnCommand_*()
|
||||
TR->>PV: operations from the player's cab
|
||||
TR->>TR: UpdateCab: gauges, buttons, sounds, screens
|
||||
DM->>DM: Events.update, Lights.update, process_commands
|
||||
```
|
||||
|
||||
Inside `physics::Vehicle` the step goes like this (`physics/components/body.cpp`):
|
||||
|
||||
- `ComputeTotalForce()`: the tractive force (`TractionForce()`, `traction.cpp`, through `Drive()` for the kind of engine),
|
||||
the braking (`BrakeForce()`, `FrictionForce()`), adhesion and slipping, the forces in the couplers.
|
||||
- `FastComputeMovement()` / `ComputeMovement()`: the movement along the track, derailment (`check_derailment()`),
|
||||
collisions (`CollisionDetect()`), the odometer, and in their shared part `compute_movement_()`: the internal commands
|
||||
(`RunInternalCommand()`), the circuits (`MainsCheck`, `PantographsCheck`, `ConverterCheck`, `CompressorCheck`,
|
||||
`LowVoltagePowerCheck`, `HeatingCheck`, `LightsCheck`, ...), the air (`UpdatePipePressure`, `UpdateBrakePressure`,
|
||||
`air.UpdatePressure`), the engine (`UpdateEngine`), the doors, the PLC (`m_plc`).
|
||||
|
||||
## 4. Commands: who changes the state of a vehicle
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
subgraph sources["Sources"]
|
||||
kb["keyboard / mouse / UART / ZMQ<br/>input/"]
|
||||
events["scenery events, MemCell<br/>world/Event.cpp, MemCell.cpp"]
|
||||
lua["Lua<br/>scripting/lua.cpp"]
|
||||
scn["loading the scenery<br/>simulationstateserializer.cpp"]
|
||||
end
|
||||
|
||||
relay["command_relay<br/>simulation::Commands"]
|
||||
train["TTrain::Update<br/>m_commandhandlers<br/>(cab/commandtable.cpp)<br/>OnCommand_* in cab/*commands.cpp"]
|
||||
ctrl["TController<br/>PutCommand(), Update()<br/>(ai/orders.cpp, ai/*.cpp)"]
|
||||
pv["physics::Vehicle<br/>public operations"]
|
||||
next["neighbouring vehicles<br/>RunCommand()"]
|
||||
|
||||
kb -->|user_command| relay --> train
|
||||
train -->|"Set..., Inc..., Switch..."| pv
|
||||
train -->|"AI on/off, direction, doors of the consist"| ctrl
|
||||
events -->|"PutCommand, as text"| ctrl
|
||||
events -->|"PutCommand: load and the like"| pv
|
||||
lua --> ctrl
|
||||
lua --> pv
|
||||
scn -->|"first orders"| ctrl
|
||||
ctrl -->|"the same operations as the cab"| pv
|
||||
pv -->|"SendCtrlToNext: VehicleCommand"| next
|
||||
```
|
||||
|
||||
- The vehicles of a consist pass `VehicleCommand`s (`physics/vehiclecommand.h`) to each other through their couplings
|
||||
(`SendCtrlToNext()` → `RunCommand()` of the neighbour, carried out in `RunInternalCommand()` in a later step). The text
|
||||
names of the commands only matter where a command comes as text (events, Lua) or is shown (the log, the AI).
|
||||
- Outside `physics/` the state of a `physics::Vehicle` changes only through its operations (`SetMainCtrlPos()`,
|
||||
`SetLitLights()`, `UnloadStep()`, ...), never by writing its fields. The exception is the definition of the vehicle,
|
||||
which the scenery and the `.mmd` adjust as it loads.
|
||||
- The cab and the events read `TController` through its queries; only the debug, timetable, scenario and driving aid
|
||||
panels (`application/driveruipanels.cpp`) are its friends.
|
||||
|
||||
## 5. Inside `physics/`
|
||||
|
||||
```mermaid
|
||||
flowchart TB
|
||||
subgraph vehicle_h["physics/vehicle.h: class physics::Vehicle"]
|
||||
direction TB
|
||||
def["the definition from the .fiz<br/>(fizparser.cpp, fizsections.cpp, setup.cpp)"]
|
||||
state["state and steps<br/>body, traction, controllers, electrics,<br/>pneumatics, diesel, doors, couplers,<br/>collisions, commands, cab, securitysystem"]
|
||||
end
|
||||
|
||||
subgraph components["physics/components/*.h: the parts of the vehicle"]
|
||||
mc["maincircuit.h<br/>LineBreaker, LineContactors,<br/>ProtectionRelays, PowerConverter"]
|
||||
lv["lowvoltage.h<br/>LowVoltageSupply, TrainHeating"]
|
||||
pa["pantographs.h<br/>PantographCircuit, PantographAir"]
|
||||
as["airsupply.h<br/>AirCompressor, AirSupply, TrainPipe"]
|
||||
br["braking.h<br/>Braking: blending, holding,<br/>spring brake, ED"]
|
||||
de["dieselengine.h<br/>DieselEngine, TorqueConverter,<br/>Retarder, EngineHeat"]
|
||||
im["inductionmotor.h<br/>InductionMotor (inverters)"]
|
||||
dv["devices.h<br/>pumps, fans, valves,<br/>doors, genset, pantograph"]
|
||||
dr["drive.h<br/>TractionDrive: one class<br/>for each EngineType"]
|
||||
end
|
||||
|
||||
subgraph models["standalone models (without physics::Vehicle)"]
|
||||
brakes["brakes.h<br/>TReservoir, TBrake and the distributors<br/>(TWest, TESt*, TLSt, TEStED, TKE, ...),<br/>the driver's brake valves"]
|
||||
oer["oerlikonest.h<br/>TNESt3"]
|
||||
fr["friction.h<br/>brake block materials"]
|
||||
cp["couplerphysics.h<br/>coupler_physics::"]
|
||||
col["collision.h<br/>collision::"]
|
||||
der["derailment.h<br/>derailment::"]
|
||||
cb["consistbraking.h<br/>ConsistBrakeBlending"]
|
||||
end
|
||||
|
||||
vocab["vehicletypes.h, vehiclecommand.h"]
|
||||
|
||||
vehicle_h --> components
|
||||
vehicle_h --> brakes
|
||||
vehicle_h --> cp
|
||||
vehicle_h --> col
|
||||
vehicle_h --> der
|
||||
oer --> brakes
|
||||
brakes --> fr
|
||||
col --> cp
|
||||
col --> der
|
||||
cb -.->|"works on the vehicles of a consist"| vehicle_h
|
||||
components --> vocab
|
||||
vehicle_h --> vocab
|
||||
```
|
||||
|
||||
The pattern of a component (from `maincircuit.h`, `lowvoltage.h`, `pantographs.h`, `airsupply.h`):
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
fiz[".fiz"] -->|"written by the parser and the setup"| config["config (public)<br/>the definition, only read afterwards"]
|
||||
veh["physics::Vehicle<br/>decides WHEN the part acts"] -->|"plain values<br/>ConverterSupply, CompressorInputs, ..."| update["Update() / Close() /<br/>ResetGround() / Switch()"]
|
||||
update --> privstate["private state"]
|
||||
privstate -->|"queries: IsClosed(), ..."| veh
|
||||
update -->|"what the step reports<br/>CompressorStep, ..."| veh
|
||||
tests["tests/unit"] -->|"...ForTest()"| privstate
|
||||
```
|
||||
|
||||
| Field of `physics::Vehicle` | Type | File |
|
||||
|---|---|---|
|
||||
| `lowVoltage`, `trainHeating` | `LowVoltageSupply`, `TrainHeating` | `components/lowvoltage.h` |
|
||||
| `lineBreaker`, `lineContactors`, `protection`, `converter` | `LineBreaker`, `LineContactors`, `ProtectionRelays`, `PowerConverter` | `components/maincircuit.h` |
|
||||
| `pantographs`, `pantographCircuit`, `pantographAir` | `ByEnd<basic_pantograph>`, `PantographCircuit`, `PantographAir` | `components/devices.h`, `components/pantographs.h` |
|
||||
| `air`, `brakePipe`, `mainPipe` | `AirSupply`, `TrainPipe` | `components/airsupply.h` |
|
||||
| `brakes` | `Braking` (the distributor `TBrake`, the driver's valves `TDriverHandle`) | `components/braking.h`, `brakes.h` |
|
||||
| `diesel`, `torqueConverter`, `retarder` | `DieselEngine`, `TorqueConverter`, `Retarder` | `components/dieselengine.h` |
|
||||
| `inductionMotor` | `InductionMotor` | `components/inductionmotor.h` |
|
||||
| `Drive()` | `TractionDrive const &` (`DriveOf(EngineType)`) | `components/drive.h` |
|
||||
| `SecuritySystem` | `TSecuritySystem` | `vehicle.h`, `components/securitysystem.cpp` |
|
||||
| `Couplers`, `Neighbours` | `ByEnd<TCoupling>`, `ByEnd<neighbour_data>` | `vehicle.h`, `couplerphysics.h` |
|
||||
| `Doors`, `Genset` | `door_data`, `genset_device` | `components/devices.h` |
|
||||
| `OffTrack`, `Odometer`, `m_plc` | `derail_motion::body`, `odometer::reading`, `plc::basic_controller` | `vehicle/derailmotion.h`, `vehicle/odometerreading.h`, `scripting/ladderlogic.h` |
|
||||
|
||||
The files `physics/components/*.cpp` are the parts of the one class `physics::Vehicle`, cut by subsystem; the helpers
|
||||
they share are in `components/internal.h`, which only they include.
|
||||
|
||||
| File | What it computes |
|
||||
|---|---|
|
||||
| `body.cpp` | construction, the forces on the body, the movement along the track, adhesion, sand, the step (`ComputeTotalForce`, `ComputeMovement`) |
|
||||
| `traction.cpp` | the traction motors and their forces for each kind of drive, the relays, the fuses, the dynamic brake |
|
||||
| `controllers.cpp` | the master and the secondary controllers, the camshaft, the integrated controller, the speed control |
|
||||
| `electrics.cpp` | the batteries, the main switch, the pantographs, the converter, heating, lights, the genset |
|
||||
| `pneumatics.cpp` | the brake controls, the pipes, the valves, the compressor, the spring brake |
|
||||
| `diesel.cpp` | the revolutions of the diesel engine, the gearbox, the clutch, the hydraulic transmission, its heat, the pumps |
|
||||
| `drive.cpp` | the `TractionDrive` classes, one for each `EngineType` |
|
||||
| `couplers.cpp` | coupling, the forces in the couplers, automatic coupling |
|
||||
| `collisions.cpp` | collisions, crush, derailment and putting back on the rails |
|
||||
| `commands.cpp` | the `VehicleCommand`s between vehicles (`RunCommand`, `RunInternalCommand`, `SendCtrlToNext`) |
|
||||
| `cab.cpp` | activating the cab, the direction, the horns, the pullee mode |
|
||||
| `doors.cpp` | the doors and the exchange of the load |
|
||||
| `securitysystem.cpp` | vigilance, cab signalling, radio-stop |
|
||||
| `fizparser.cpp`, `fizsections.cpp` | reading the `.fiz` |
|
||||
| `setup.cpp` | setting the vehicle up after loading: the checks, the valves, the pipes |
|
||||
|
||||
## 6. `vehicle/`: the scene, the AI and the cab
|
||||
|
||||
```mermaid
|
||||
flowchart TB
|
||||
subgraph dynamic["vehicle/dynamic/ (TDynamicObject, vehicle_table)"]
|
||||
dlife["lifecycle.cpp, mmd.cpp, load.cpp<br/>creation, the .mmd, the load"]
|
||||
dupd["update.cpp, movement.cpp, vehicletable.cpp<br/>the step of a vehicle and of the whole table"]
|
||||
dcons["consist.cpp, couplers.cpp, neighbours.cpp<br/>the consist, the couplers, the neighbours"]
|
||||
dvis["visual.cpp, animations.cpp, lights.cpp,<br/>sounds.cpp, destinations.cpp, offtrack.cpp"]
|
||||
end
|
||||
|
||||
subgraph aidir["vehicle/ai/ (TController, Driver.h)"]
|
||||
adrv["driver.cpp, orders.cpp<br/>construction, Update, orders"]
|
||||
aroute["routescan.cpp, speedtable.cpp, speedpos.cpp,<br/>obstacles.cpp, situation.cpp<br/>the speed table, the signals, the obstacles"]
|
||||
acontrol["speed.cpp, force.cpp, controls.cpp,<br/>engine.cpp, doors.cpp, consist.cpp<br/>target speed, controllers, brakes, doors, consist"]
|
||||
alog["physicslog.cpp"]
|
||||
end
|
||||
|
||||
subgraph cabdir["vehicle/cab/ (TTrain, Train.h)"]
|
||||
ctrain["train.cpp, setup.cpp, cab.cpp<br/>the player's train, gauges, buttons"]
|
||||
cupd["update.cpp, sounds.cpp, screens.cpp<br/>the step of the cab, sounds, Python screens"]
|
||||
ccmd["commandtable.cpp + *commands.cpp<br/>handling user_command"]
|
||||
end
|
||||
|
||||
subgraph small["vehicle/*.h, *.cpp: modules testable without the scene"]
|
||||
sai["for the AI: brakesetting, brakecharge, brakereleaser,<br/>brakingcurve, uphillstart, aipower, aiwire,<br/>signalpassing, timetableservice, handover,<br/>driverorders, fieldshunting"]
|
||||
scab["for the cab: horn, linebreaker, holdcoillever,<br/>enginestart, mainctrlact, compartmentlightsswitch,<br/>gaugescale, gaugewrap, gaugepositions,<br/>gaugeduplicates, universaldrag, drivingaid"]
|
||||
sdyn["for the vehicle in the scene: derailmotion, doorwings,<br/>mirrors, lightsprogrammer, pulleemode, smoke,<br/>odometer, driverfigure, cameraviews"]
|
||||
sother["crew, crewchange, blackbox,<br/>Camera, Gauge, Button, AirCoupler"]
|
||||
end
|
||||
|
||||
dynamic --> aidir
|
||||
aidir --> dynamic
|
||||
cabdir --> dynamic
|
||||
cabdir --> aidir
|
||||
aidir --> sai
|
||||
cabdir --> scab
|
||||
dynamic --> sdyn
|
||||
```
|
||||
|
||||
- `Driver.h` (`TController`) includes `DynObj.h`; `Train.h` (`TTrain`) includes `DynObj.h` and `Driver.h`. The files of
|
||||
`vehicle/ai/`, `vehicle/cab/` and `vehicle/dynamic/` each share one `internal.h` with their list of includes.
|
||||
- The AI looks for a `TTrain` in two places only, through `simulation::Trains.find()`: when it changes cabs
|
||||
(`ai/consist.cpp`), and for the pantographs and lights of the player's train (`ai/situation.cpp`).
|
||||
- The cab uses `TController` to take over and hand back the controls (`TakeControl`, `AIControllFlag`), to change the
|
||||
direction, for the doors of the consist (`ConsistDoors*`) and to check the consist (`CheckVehicles`).
|
||||
- The modules of `vehicle/*.h` are mostly plain functions or small structures on plain values, tested in `tests/unit`
|
||||
without the scene. Some of them include `physics/vehicle.h` (`lightsprogrammer.h` and `mainctrlact.h` in the header;
|
||||
`brakesetting.cpp`, `drivingaid.cpp`, `enginestart.cpp`, `handover.cpp`, `crew.cpp`, `smoke.cpp` and
|
||||
`timetableservice.cpp` in the implementation).
|
||||
|
||||
## 7. Include dependencies
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
classDef up stroke:#d33,stroke-width:2px,color:#d33
|
||||
|
||||
vt["physics/vehicletypes.h"] --> vc["physics/vehiclecommand.h"]
|
||||
vt --> es["utilities/enumset.h"]
|
||||
vh["physics/vehicle.h"] --> vt
|
||||
vh --> comps["physics/components/*.h"]
|
||||
vh --> bh["physics/brakes.h"] --> fh["physics/friction.h"]
|
||||
vh --> colh["physics/collision.h"] --> cph["physics/couplerphysics.h"]
|
||||
colh --> dh["physics/derailment.h"]
|
||||
vh --> ll["scripting/ladderlogic.h"]:::up
|
||||
vh --> dm["vehicle/derailmotion.h"]:::up
|
||||
vh --> odo["vehicle/odometerreading.h"]:::up
|
||||
|
||||
ccpp["physics/components/*.cpp"] --> vh
|
||||
ccpp --> dynh["vehicle/DynObj.h"]:::up
|
||||
ccpp --> simh["simulation/simulation.h"]:::up
|
||||
ccpp --> fsh["vehicle/fieldshunting.h"]:::up
|
||||
ccpp --> glob["utilities/Globals.h"]
|
||||
|
||||
dynobj["vehicle/DynObj.h"] --> vt
|
||||
dynobj --> dh
|
||||
dynobj --> cbh["physics/consistbraking.h"]
|
||||
dynobj --> dm2["vehicle/derailmotion.h"]
|
||||
dynobj --> trk["world/TrkFoll.h"]
|
||||
driver["vehicle/Driver.h"] --> dynobj
|
||||
driver --> vt
|
||||
train["vehicle/Train.h"] --> dynobj
|
||||
train --> driver
|
||||
classes["utilities/Classes.h<br/>declares physics::Vehicle,<br/>TDynamicObject, TController, TTrain"]
|
||||
```
|
||||
|
||||
In red is what goes "up", against the layers of section 1. As it stands:
|
||||
|
||||
- `physics/vehicle.h` includes three headers from outside `physics/`, but all of them are data without the scene:
|
||||
`vehicle/derailmotion.h` (the movement of a vehicle off the track, the field `OffTrack`), `vehicle/odometerreading.h`
|
||||
(the field `Odometer`) and `scripting/ladderlogic.h` (the PLC, the field `m_plc`). The natural place for the first two is
|
||||
`physics/`.
|
||||
- `physics/components/*.cpp` share a block of includes with `vehicle/DynObj.h` and `simulation/simulation.h`. They don't
|
||||
use `TDynamicObject` (it appears only in comments); of `simulation/` they take only `simulation::Weights` (the unit
|
||||
weights of the loads, `body.cpp`). `vehicle/fieldshunting.h` (a plain function) is used by `controllers.cpp` and
|
||||
`diesel.cpp`. These are candidates for a cleanup: drop `DynObj.h` from the block, move `fieldshunting.h` to `physics/`,
|
||||
and hand the physics the `Weights` as a value.
|
||||
- The physics reads settings from `Global` (`utilities/Globals.h`): `collisions`, `derailment`, `crash_damage`,
|
||||
`coupler_physics*`, `physics_sleepheld`, `physics_pipewake`, `AirTemperature`; and `fizparser.cpp` sets
|
||||
`Global.iPause` while it loads.
|
||||
|
||||
## 8. Other files that use the vehicle
|
||||
|
||||
| File | Through | What for |
|
||||
|---|---|---|
|
||||
| `utilities/Classes.h` | declarations | `physics::Vehicle`, `TDynamicObject`, `TController`, `TTrain` for the headers that only point at them |
|
||||
| `application/drivermode.cpp` | `Train.h`, `DynObj.h`, `Driver.h` | the frame loop, getting in, changing vehicles, the camera |
|
||||
| `application/driveruipanels.cpp`, `consistviews.cpp`, `driverhints.cpp` | `Driver.h` (friend), `physics/vehicle.h` | the debug, timetable, scenario and driving aid panels, the hints |
|
||||
| `application/editormode*.cpp` | `DynObj.h` | the editor and its self-tests |
|
||||
| `input/command.cpp`, `drivermouseinput.cpp`, `zmq_input.cpp` | `Train.h` | `user_command`s for the cab, mapping clicks to the controls of the cab |
|
||||
| `input/messaging.cpp`, `utilities/uart.cpp`, `utilities/motiontelemetry.cpp` | `physics/vehicle.h`, `Train.h` | the state of the vehicle for external programs, desks, motion platforms |
|
||||
| `simulation/simulation.cpp` | `vehicle_table`, `train_table` | `state_manager::update()`, `process_commands()` |
|
||||
| `simulation/simulationstateserializer.cpp` | `DynObj.h`, `Driver.h` | loading the vehicles and consists of the `.scn`, the first orders |
|
||||
| `simulation/blackboxrecorder.cpp` | `physics/vehicle.h`, `Driver.h`, `Train.h` | recording the session (`vehicle/blackbox.h` is the format) |
|
||||
| `simulation/simulationtest.cpp` | `DynObj.h` | the test mode (`--test`) |
|
||||
| `world/TrkFoll.cpp` | `DynObj.h`, `Driver.h` | the axles of a vehicle on the track, the events it runs over |
|
||||
| `world/Track.cpp`, `TrackBuckle.cpp` | `DynObj.h`, `physics/vehicle.h` | the vehicles on a track, derailing on buckled track |
|
||||
| `world/Event.cpp`, `world/MemCell.cpp` | `PutCommand()` | the commands of the scenery for the driver and the vehicle |
|
||||
| `world/station.cpp`, `RoadPoint.cpp`, `Road.cpp`, `deer.cpp` | `DynObj.h` | the exchange of passengers, road traffic, animals |
|
||||
| `scripting/lua.cpp` | `Driver.h`, `physics/vehicle.h` | `PutCommand()` from Lua |
|
||||
| `scripting/PyInt.cpp`, `pythonscreenviewer`, `vehicle/cab/screens.cpp` | `Train.h` | the Python screens of the cab (the state dictionaries) |
|
||||
| `audio/sound.cpp`, `audio/audiorenderer.cpp` | `DynObj.h`, `Train.h` | the sounds of the vehicle and the cab |
|
||||
| `rendering/common/*`, `rendering/opengl46/*`, `rendering/vulkan14/*`, `rendering/particles.cpp`, `lightarray.cpp` | `DynObj.h`, `Train.h` | drawing the vehicles, the cab, the lights, the smoke |
|
||||
| `scene/scene.cpp`, `widgets/map*.cpp`, `widgets/vehicle*.cpp`, `widgets/trainingcard.cpp` | `DynObj.h`, `Driver.h` | the scenery, the map, the vehicle lists, the training card |
|
||||
| `utilities/Globals.cpp` | | the `eu07.ini` settings the physics and the AI read |
|
||||
| `tests/unit/*` | `physics/vehicle.h`, `physics/brakes.h`, `DynObj.h` | the tests: `vehicle.h` / `consist.h` (a vehicle and a consist without the scenery, stepped as `vehicle_table::update()` does), `golden.*` (against a recorded run), `fiz.*` (`.fiz` definitions in a test), `scenario.*` |
|
||||
|
||||
`physics/vehicletypes.h` (the vocabulary: ends, sides, couplings, lights, types of drive and brake) and
|
||||
`physics/vehiclecommand.h` (`VehicleCommand`) are what the rest of the simulator should include when it needs only these
|
||||
names; outside `physics/` and `vehicle/`, `application/consistviews.h`, `application/driveruipanels.h` and
|
||||
`rendering/common/scenewalk.h` do so today.
|
||||
Reference in New Issue
Block a user