From 3c3c773ff46080b697c7b788c7a7b62503c5d8df Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 05:11:07 +0100 Subject: [PATCH 01/27] test(scenarios): the buckle cases run with physics.derailment new (#423) * test(scenarios): the buckle cases run with physics.derailment new eu07_td_buckle_derails waits for the "derailed on buckled track" line, which only the criteria of physics.derailment new write. It was written with new as the default; since monitor is the default (0645096e) the criteria only log "derailment monitor: ... overturned at 46 km/h on track tdo_n222" and the train runs on to Przystanek, so the case failed. The case sets the mode itself now. eu07_td_buckle_event sets it too: under monitor its "no Bad driving" check said nothing about the criteria. * docs(scenarios): the buckle cases and the derailment mode they set --- tests/scenarios/README.md | 9 +++++++++ tests/scenarios/cases/eu07_td_buckle_derails.json | 4 ++-- tests/scenarios/cases/eu07_td_buckle_event.json | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/scenarios/README.md b/tests/scenarios/README.md index 7e9ceef7c..f65d96fb2 100644 --- a/tests/scenarios/README.md +++ b/tests/scenarios/README.md @@ -278,6 +278,15 @@ pushed, runs onto `tor1k` (`eventall2`), with the train still moving, and the bl locomotive coupled to the coaches (it couples about 70 s after the start). A driver that leaves its hand brake on under Connect pulls against it for good and the case ends as a standstill after 300 s. +The `eu07_td_buckle_*` cases (fragment `td_buckle_event.scn`) run the timetable train of +`td_timetable.scn` and buckle the curve `tdo_n222`, about 950 m ahead of it, with a `trackbuckle` +event of `vars.amplitude` at 10:35. Both have `physics.derailment new` in `ini`: the default, +`monitor`, leaves the decision to the legacy draw and only logs what the criteria would do +(`derailment monitor: ... overturned at 46 km/h on track tdo_n222`), so the train runs on to +Przystanek whatever the buckle. With 600 mm over a main lobe of 8 m the locomotive overturns on +the buckle at 46 km/h, 1036 m from the start (`Bad driving: ... derailed on buckled track`); with +30 mm it keeps on the rails and stops at Przystanek after 1400 m. + The `*_td_crew_*` cases (eu07/maszyna#510, fragment `td_crew.scn`) are about the crew command of a `putvalues` event, `Crew: `: cab 1 or -1 puts an AI driver in cab A or B of the vehicle named, 0 takes its AI driver off. The vehicle is named in the text, so the events are diff --git a/tests/scenarios/cases/eu07_td_buckle_derails.json b/tests/scenarios/cases/eu07_td_buckle_derails.json index 5caaa60b6..8506736a5 100644 --- a/tests/scenarios/cases/eu07_td_buckle_derails.json +++ b/tests/scenarios/cases/eu07_td_buckle_derails.json @@ -1,5 +1,5 @@ { - "description": "EU07 on td.scn on the td/rozklad timetable; at 10:35, as it leaves, the curve tdo_n222 about 950 m ahead buckles hard with a trackbuckle event: 600 mm out of the curve over a main lobe of 8 m (an equivalent radius of 9 m, about 30 m for the body on axles 11 m apart). The AI doesn't see it and runs into it at the 46 km/h it has there: the locomotive leaves the rails on the buckle and stops short of Przystanek.", + "description": "EU07 on td.scn on the td/rozklad timetable; at 10:35, as it leaves, the curve tdo_n222 about 950 m ahead buckles hard with a trackbuckle event: 600 mm out of the curve over a main lobe of 8 m (an equivalent radius of 9 m, about 30 m for the body on axles 11 m apart). The AI doesn't see it and runs into it at the 46 km/h it has there: with physics.derailment new (the default, monitor, only logs what the criteria would do and the train runs on) the locomotive leaves the rails on the buckle and stops short of Przystanek.", "base_scenery": "td.scn", "time": "10:34", "fragment": "td_buckle_event.scn", @@ -7,7 +7,7 @@ "consist": "node -1 0 {{vehicle}} dynamic pkp\\4e_v1 4e-004 4e 0 headdriver 0 0 enddynamic", "amplitude": "600 8" }, - "ini": ["gfxrenderer null"], + "ini": ["gfxrenderer null", "physics.derailment new"], "duration": 240, "timeout": 600, "checks": [ diff --git a/tests/scenarios/cases/eu07_td_buckle_event.json b/tests/scenarios/cases/eu07_td_buckle_event.json index 192fa9b5a..13e0da7bc 100644 --- a/tests/scenarios/cases/eu07_td_buckle_event.json +++ b/tests/scenarios/cases/eu07_td_buckle_event.json @@ -1,5 +1,5 @@ { - "description": "EU07 on td.scn on the td/rozklad timetable; at 10:35, as it leaves, the curve tdo_n222 about 950 m ahead buckles with a trackbuckle event (30 mm out of the curve, as the heat does: an equivalent radius of 330 m, too little to derail it). The track is laid again during the game and the train keeps on it to Przystanek.", + "description": "EU07 on td.scn on the td/rozklad timetable; at 10:35, as it leaves, the curve tdo_n222 about 950 m ahead buckles with a trackbuckle event (30 mm out of the curve, as the heat does: an equivalent radius of 330 m, too little to derail it). The track is laid again during the game and the train keeps on it to Przystanek, with physics.derailment new: the criteria decide, as in eu07_td_buckle_derails.", "base_scenery": "td.scn", "time": "10:34", "fragment": "td_buckle_event.scn", @@ -7,7 +7,7 @@ "consist": "node -1 0 {{vehicle}} dynamic pkp\\4e_v1 4e-004 4e 0 headdriver 0 0 enddynamic", "amplitude": "30" }, - "ini": ["gfxrenderer null"], + "ini": ["gfxrenderer null", "physics.derailment new"], "duration": 240, "timeout": 600, "checks": [ From 677795e595ba45f7d13b8c26ea0014f4a3518a6e Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 05:11:51 +0100 Subject: [PATCH 02/27] test(scenarios): brakes cut out once a train formed by coupling stands (#282) (#436) An EU07 couples on the run to a cut of 16 coaches with P alone and 8 wagons with G, 541 m, and runs it on as a train: a train on G, whose coaches have their brakes cut out (Cw-1 19.9). The inspector looks at the train at 4 km/h as it couples and leaves the cut-outs to reinspect_brakes(), which makes them as the train stands just after. Taking the driver off at 38 km/h shows it: the train stops at 0.27 m/s2 over 211 m, against 0.57 m/s2 over 99 m with every brake working (the second case, with ai.brakesetting.cw1 no). stops_driverless takes optional min_deceleration and max_deceleration. --- tests/scenarios/README.md | 22 +++++- ...07_td_reinspect_brakes_after_coupling.json | 69 ++++++++++++++++++ ..._td_reinspect_brakes_legacy_inspector.json | 71 +++++++++++++++++++ tests/scenarios/cases/td_reinspect_brakes.scn | 33 +++++++++ tests/scenarios/run.py | 17 +++-- 5 files changed, 207 insertions(+), 5 deletions(-) create mode 100644 tests/scenarios/cases/eu07_td_reinspect_brakes_after_coupling.json create mode 100644 tests/scenarios/cases/eu07_td_reinspect_brakes_legacy_inspector.json create mode 100644 tests/scenarios/cases/td_reinspect_brakes.scn diff --git a/tests/scenarios/README.md b/tests/scenarios/README.md index f65d96fb2..b85f0f8cf 100644 --- a/tests/scenarios/README.md +++ b/tests/scenarios/README.md @@ -341,6 +341,23 @@ brake of the Vectron switched on), and `event0` of the track gives the driver `O starts up, charges the brake pipe and leaves on time (the stop after 209 s and 1393 m); without the `H` the pipe stays below 1 bar and the case ends as a standstill after 300 s. +`eu07_td_reinspect_brakes_after_coupling` (fragment `td_reinspect_brakes.scn`, eu07/maszyna#350 and #282) is about the +wagon inspector of the AI (`TController::AutoRewident()`) on a train formed by coupling. An EU07 stands cold on the line +from Stacja1 (`koniec`) and a cut stands 45 m ahead of it, braked, with nobody in it: 16 coaches with P alone (BDhpumn) +and next to the locomotive 8 empty wagons with G and P (401W), 541 m of wagons. `event0` of the locomotive's track gives +the driver `Shunt -3 3`, once: couple to the cut with the coupler and the brake hose and run it on as a train +(`Obey_train`), waiting for the way, which `event2` of `tdo_n231`, in front of the cut, gives as a `SetVelocity 40 40` +(no signal of the line is in sight). Over 500 m of wagons make it a train on G (Cw-1 §19.1), where the brake of a wagon +without G is cut out (§19.9). The inspector looks at the train as the AI couples, at 4 km/h (t=69 s), too fast for it to +cut a brake out, and leaves that for the next standstill: `reinspect_brakes()` cuts the 16 coaches out as the train stands +a moment later, its brakes applied by the empty pipe of the cut. Neither the physicslog nor the black box has the brakes +of the wagons, so the case tells by how the train brakes: `event2` of `tdo_n240` takes the driver off at 38 km/h, which +leaves the brake valve in the emergency position, and braked by the locomotive and the 8 wagons alone the train stops 29 s +and 211 m later, a mean deceleration of 0.27 m/s² (`stops_driverless` with `max_deceleration` 0.40). With every brake +working it stops at 0.57 m/s², 99 m: that is `eu07_td_reinspect_brakes_legacy_inspector`, the same run with the inspector +of the earlier releases (`ai.brakesetting.cw1 no`), which cuts no brake out, and also what a build whose +`reinspect_brakes()` does nothing gives for the first case, which then fails. The test passes 150 s after the driver goes. + ### Cases on a mission of a scenery The cases made from players' reports (eu07/maszyna#421, #506, #524, #525) run a whole mission @@ -433,7 +450,10 @@ the row instead, logged by builds from this branch on. (1 m), `hold` (60 s): the black box has the vehicle lose its driver at `min_speed` or faster, stand `within` seconds later and stay within `max_creep` of where it stopped for the rest of the recording, or until it gets a driver again, at least `hold` seconds. The physicslog can't - tell: the driver writes it, so it ends when the driver goes. + tell: the driver writes it, so it ends when the driver goes. Optional `min_deceleration`, + `max_deceleration` (m/s²): the mean deceleration of that stop, from the speed the driver left at + and the way to the stop (v²/2s), has to be within them, e.g. a train some of whose brakes are + cut out stops slower. - `moves` `vehicle`, `min_speed`, optional `direction` (`front`, or `rear`): the black box has the vehicle reach `min_speed` with that end leading (the physicslog speed has no direction). diff --git a/tests/scenarios/cases/eu07_td_reinspect_brakes_after_coupling.json b/tests/scenarios/cases/eu07_td_reinspect_brakes_after_coupling.json new file mode 100644 index 000000000..be4b96feb --- /dev/null +++ b/tests/scenarios/cases/eu07_td_reinspect_brakes_after_coupling.json @@ -0,0 +1,69 @@ +{ + "description": "eu07/maszyna#350, #282: an EU07 on td.scn couples on the run (Shunt -3 3) to a cut standing on the line, 16 coaches with P alone and 8 empty wagons with G and P, 541 m of wagons, and runs it on as a train (Obey_train): a train on G (Cw-1 19.1), so the brakes of the coaches are to be cut out (19.9). The inspector looks at the train as it couples, at 4 km/h, and leaves the cut-outs for the standstill; reinspect_brakes() makes them as the train stands just after. The driver taken off at 38 km/h leaves the brake valve in the emergency position: braked by the locomotive and the 8 wagons alone the train stops at some 0.27 m/s2, over 210 m (with every brake working, 0.57 m/s2 over 99 m).", + "base_scenery": "td.scn", + "fragment": "td_reinspect_brakes.scn", + "vars": { + "locomotive": "pkp\\4e_v1 4e-004 4e", + "cut": [ + "node -1 0 {{vehicle}}_c01 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c02 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c03 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c04 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c05 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c06 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c07 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c08 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c09 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c10 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c11 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c12 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c13 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c14 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c15 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c16 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_w1 dynamic pkp\\401w_v2 82515314470-4 401w_w_d 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_w2 dynamic pkp\\401w_v2 82515314470-4 401w_w_d 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_w3 dynamic pkp\\401w_v2 82515314470-4 401w_w_d 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_w4 dynamic pkp\\401w_v2 82515314470-4 401w_w_d 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_w5 dynamic pkp\\401w_v2 82515314470-4 401w_w_d 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_w6 dynamic pkp\\401w_v2 82515314470-4 401w_w_d 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_w7 dynamic pkp\\401w_v2 82515314470-4 401w_w_d 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_w8 dynamic pkp\\401w_v2 82515314470-4 401w_w_d 0 nobody 0 0 enddynamic" + ] + }, + "track_events": { + "koniec": "event0 autotest_wake", + "tdo_n231": "event2 autotest_way", + "tdo_n240": "event2 autotest_crew_off" + }, + "test_config": [ + "test.timeout 1200", + "test.standstill 600" + ], + "expect": "pass", + "timeout": 600, + "checks": [ + { + "type": "couples", + "vehicle": "{{vehicle}}", + "other": "{{vehicle}}_w8" + }, + { + "type": "stops_driverless", + "vehicle": "{{vehicle}}", + "min_speed": 30, + "within": 90, + "hold": 60, + "min_deceleration": 0.15, + "max_deceleration": 0.4 + }, + { + "type": "log_lacks", + "pattern": "derailed" + }, + { + "type": "log_lacks", + "pattern": "collided" + } + ] +} diff --git a/tests/scenarios/cases/eu07_td_reinspect_brakes_legacy_inspector.json b/tests/scenarios/cases/eu07_td_reinspect_brakes_legacy_inspector.json new file mode 100644 index 000000000..e3a03c2da --- /dev/null +++ b/tests/scenarios/cases/eu07_td_reinspect_brakes_legacy_inspector.json @@ -0,0 +1,71 @@ +{ + "description": "The train of eu07_td_reinspect_brakes_after_coupling with the inspector of the releases before eu07/maszyna#350 (ai.brakesetting.cw1 no), which cuts no brake out: every brake of the train works, and the emergency stop after the driver is taken off at 38 km/h comes at some 0.57 m/s2, over 99 m. It shows what the deceleration check of that case tells apart.", + "base_scenery": "td.scn", + "fragment": "td_reinspect_brakes.scn", + "vars": { + "locomotive": "pkp\\4e_v1 4e-004 4e", + "cut": [ + "node -1 0 {{vehicle}}_c01 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c02 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c03 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c04 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c05 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c06 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c07 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c08 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c09 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c10 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c11 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c12 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c13 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c14 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c15 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c16 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_w1 dynamic pkp\\401w_v2 82515314470-4 401w_w_d 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_w2 dynamic pkp\\401w_v2 82515314470-4 401w_w_d 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_w3 dynamic pkp\\401w_v2 82515314470-4 401w_w_d 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_w4 dynamic pkp\\401w_v2 82515314470-4 401w_w_d 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_w5 dynamic pkp\\401w_v2 82515314470-4 401w_w_d 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_w6 dynamic pkp\\401w_v2 82515314470-4 401w_w_d 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_w7 dynamic pkp\\401w_v2 82515314470-4 401w_w_d 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_w8 dynamic pkp\\401w_v2 82515314470-4 401w_w_d 0 nobody 0 0 enddynamic" + ] + }, + "track_events": { + "koniec": "event0 autotest_wake", + "tdo_n231": "event2 autotest_way", + "tdo_n240": "event2 autotest_crew_off" + }, + "test_config": [ + "test.timeout 1200", + "test.standstill 600" + ], + "expect": "pass", + "timeout": 600, + "checks": [ + { + "type": "couples", + "vehicle": "{{vehicle}}", + "other": "{{vehicle}}_w8" + }, + { + "type": "stops_driverless", + "vehicle": "{{vehicle}}", + "min_speed": 30, + "within": 60, + "hold": 60, + "min_deceleration": 0.45 + }, + { + "type": "log_lacks", + "pattern": "derailed" + }, + { + "type": "log_lacks", + "pattern": "collided" + } + ], + "ini": [ + "ai.brakesetting.cw1 no" + ] +} diff --git a/tests/scenarios/cases/td_reinspect_brakes.scn b/tests/scenarios/cases/td_reinspect_brakes.scn new file mode 100644 index 000000000..37c76550a --- /dev/null +++ b/tests/scenarios/cases/td_reinspect_brakes.scn @@ -0,0 +1,33 @@ +// added by tests/scenarios/run.py to td.scn, whose own trainsets were removed. +// on the line from Stacja1 to Stacja2 (flat, curves of 600 m): a locomotive with an AI driver stands cold +// (trainset velocity 0) on koniec, its front 35 m past point 1 of the track, facing point 2, towards Stacja2; +// a cut of wagons (vars.cut) stands, braked as well and with nobody in it, ahead of it, its front 56 m past +// point 1 of tdo_n222, some 45 m in front of the locomotive. +trainset none koniec 35.0 0.0 +node -1 0 {{vehicle}} dynamic {{locomotive}} 0 headdriver 0 0 enddynamic +endtrainset + +trainset none tdo_n222 56.0 0.0 +{{cut}} +endtrainset + +// event0 of the locomotive's track (the case's track_events) runs while the locomotive stands there. it wakes +// the driver and gives it, once, the order to couple to the cut ahead and run it on as a train: Shunt -3 3, +// Connect (with the coupler and the brake hose) then Obey_train, which waits for the way to be given. the AI +// couples on the run, at some 4 km/h, and the wagon inspector of the train run looks at the new train then, +// before it stands. +node -1 0 autotest_ordered memcell 0 0 0 ordered 0 0 none endmemcell +event autotest_wake multiple 0 autotest_ordered autotest_order autotest_order_given condition memcompare * 0 * endevent +event autotest_order PutValues 0 none 0 0 0 Shunt -3 3 endevent +event autotest_order_given UpdateValues 0 autotest_ordered * 1 * endevent + +// the way: no signal of the line is in sight, so event2 of tdo_n231 (the case's track_events), 40 m in front of +// the cut, gives the speed a signal at proceed would, 40 km/h, which the AI reads as it scans the track ahead +event autotest_way PutValues 0 none 0 0 0 SetVelocity 40 40 endevent + +// event2 of tdo_n240 (the case's track_events), some 700 m on, as the locomotive runs over it pushing the train: +// the driver is taken off (Crew: 0 0), which leaves the brake valve in the emergency position, so the +// train stops on the brakes it has. the pass comes 150 s later, with the train standing. +event autotest_crew_off multiple 0 none autotest_driver_off autotest_pass endevent +event autotest_driver_off putvalues 0 none 0 0 0 Crew:{{vehicle}} 0 0 endevent +event autotest_pass UpdateValues 150 __test.result the_train_was_stopped_with_the_brakes_it_has 1 * endevent diff --git a/tests/scenarios/run.py b/tests/scenarios/run.py index fd1941577..35e923bee 100644 --- a/tests/scenarios/run.py +++ b/tests/scenarios/run.py @@ -705,9 +705,11 @@ def check_driver_changes(box, vehicle, to, after=0.0, before=None): return True, f"{vehicle} has driver {to} from t={change.time:.1f}s to the end (t={box.end_time:.1f}s)" -def check_stops_driverless(box, vehicle, min_speed, within, stop_speed=0.5, max_creep=1.0, hold=60.0): +def check_stops_driverless(box, vehicle, min_speed, within, stop_speed=0.5, max_creep=1.0, hold=60.0, + min_deceleration=None, max_deceleration=None): """The vehicle loses its driver at `min_speed` or faster, stands `within` seconds later and stays where it - stopped, to the end of the recording or until it gets a driver again.""" + stopped, to the end of the recording or until it gets a driver again. With the decelerations, the mean one of + that stop (from the speed and the way to the stop, m/s²) has to be within them: how well the train brakes.""" states, why = _vehicle_states(box, vehicle) if states is None: return False, why @@ -734,8 +736,15 @@ def check_stops_driverless(box, vehicle, min_speed, within, stop_speed=0.5, max_ if fastest > stop_speed or creep > max_creep: return False, f"{vehicle} stood at t={stop.time:.1f}s, then moved {creep:.1f} m at up to {fastest:.1f} km/h with no driver" way = sum(math.dist(a.position, b.position) for a, b in zip(after, after[1:]) if b.time <= stop.time) - return True, (f"{vehicle} lost its driver at t={left.time:.1f}s at {abs(left.speed):.1f} km/h, stood {stop.time - left.time:.0f}s " - f"and {way:.0f} m later, moved {creep:.2f} m in the {until - stop.time:.0f}s {alone}") + stopped = (f"{vehicle} lost its driver at t={left.time:.1f}s at {abs(left.speed):.1f} km/h, stood {stop.time - left.time:.0f}s " + f"and {way:.0f} m later") + # v² / 2s: the black box lists a vehicle once a second, so the way is closer to the truth than the time + deceleration = (abs(left.speed) / 3.6) ** 2 / (2 * way) if way > 0 else math.inf + if ((min_deceleration is not None and deceleration < min_deceleration) + or (max_deceleration is not None and deceleration > max_deceleration)): + bounds = f"{min_deceleration if min_deceleration is not None else 0:g}..{max_deceleration if max_deceleration is not None else 'any'}" + return False, f"{stopped}: a mean deceleration of {deceleration:.2f} m/s², outside {bounds}" + return True, f"{stopped} ({deceleration:.2f} m/s²), moved {creep:.2f} m in the {until - stop.time:.0f}s {alone}" def check_moves(box, vehicle, min_speed, direction="front"): From 57a0a71f4825bf5717f7c31d6599209b5986b67c Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 05:12:15 +0100 Subject: [PATCH 03/27] fix(ci): build and run the shader validator again (#437) * fix(ci): build and run the shader validator again - gl/glsl_common.h and gl/shader.cpp include utilities/Globals.h and utilities/Logs.h now, so the stand-in headers of the validator move to ci_shadervalidator/utilities/. - gl/ubo.h needs std::span and gl/shader.cpp uses contains(), so the script builds with -std=c++20. The stand-in stdafx.h gives , and , which the precompiled header of the simulator gives otherwise. - build.sh runs from any directory and stops on the first error. - glslang defines the GL_ARB_gpu_shader5 macro without the #extension directive, so light_common.glsl took its textureGather() path without the extension enabled and 25 material shaders failed on desktop GL with the shadows on. The validator adds the directive which the simulator gives on the drivers with the extension. - The shader goes to the temporary directory of the system instead of a fixed /tmp, a shader which can't be preprocessed fails instead of ending the run, the shaders go in name order and the failed ones are listed at the end. * fix(ci): write the validated shader to a unique temporary file The shader validator wrote every preprocessed shader to a file with a fixed name in the temporary directory (/tmp/shader on Linux) and opened it with std::ofstream. In a shared /tmp anyone can create that name in advance, as a file or a link to another file, and the validator would then write through it (Sonar rule S5443, publicly writable directories). The shader now goes to a file with a unique name which is created exclusively: mkstemp() on Linux, and on Windows, which has no mkstemp(), a random name opened with fopen_s(..., "wx"), which fails when the file exists. The file is removed after glslangValidator has checked it, and when it cannot be written completely. glslangValidator gets the stage with -S, so the file still needs no extension. * docs(ci): the standalone validator no longer checks the PCF fallback path The comment of has_gl_extension() said the validator compiles the 16-tap PCF fallback of light_common.glsl. Since the validator adds the GL_ARB_gpu_shader5 directive itself, it checks the textureGather() path. --- ci_shadervalidator/build.sh | 7 +- ci_shadervalidator/main.cpp | 99 +++++++++++++++++--- ci_shadervalidator/stdafx.h | 5 + ci_shadervalidator/{ => utilities}/Globals.h | 0 ci_shadervalidator/{ => utilities}/Logs.h | 0 gl/shader.cpp | 6 +- 6 files changed, 101 insertions(+), 16 deletions(-) rename ci_shadervalidator/{ => utilities}/Globals.h (100%) rename ci_shadervalidator/{ => utilities}/Logs.h (100%) diff --git a/ci_shadervalidator/build.sh b/ci_shadervalidator/build.sh index b0207f6ed..fe13b9c63 100755 --- a/ci_shadervalidator/build.sh +++ b/ci_shadervalidator/build.sh @@ -1,2 +1,7 @@ #!/bin/sh -g++ -std=c++17 -O2 -DSHADERVALIDATOR_STANDALONE ../ref/glad/src/glad.c ../gl/glsl_common.cpp ../gl/shader.cpp main.cpp -I../ref/glad/include -I../ref/glm -I. -o validateshaders +# builds the shader validator next to this script. it compiles gl/shader.cpp and gl/glsl_common.cpp of the +# simulator against the stand-in headers of this directory (stdafx.h, utilities/Globals.h, utilities/Logs.h) +# and needs glslangValidator on PATH to run. run validateshaders from this directory +set -e +cd "$(dirname "$0")" +${CXX:-g++} -std=c++20 -O2 -DSHADERVALIDATOR_STANDALONE ../ref/glad/src/glad.c ../gl/glsl_common.cpp ../gl/shader.cpp main.cpp -I../ref/glad/include -I../ref/glm -I. -o validateshaders diff --git a/ci_shadervalidator/main.cpp b/ci_shadervalidator/main.cpp index 65ad54b2a..bd7db0523 100644 --- a/ci_shadervalidator/main.cpp +++ b/ci_shadervalidator/main.cpp @@ -1,20 +1,70 @@ #include "stdafx.h" #include "../gl/shader.h" #include "../gl/glsl_common.h" -#include "Globals.h" +#include "utilities/Globals.h" #include -#include +#include #include #include +#include +#include +#ifdef _WIN32 +#include +#else +#include +#endif _global Global; +// writes the text to a new file with a unique name in the temporary directory of the system and returns its path, +// or an empty string when it cannot be written. the file is created exclusively, so nothing put in a shared /tmp +// under a name known in advance (a file or a link) is written through +std::string write_temp_file(std::string const &text) +{ + std::string path = (std::filesystem::temp_directory_path() / "maszyna-shader-XXXXXX").string(); + std::FILE *file = nullptr; +#ifdef _WIN32 + // no mkstemp() in the CRT; a random name, opened with "x", which fails when the file is there already + std::random_device random; + for (int attempt = 0; attempt < 100 && file == nullptr; ++attempt) { + path.replace(path.size() - 6, 6, std::to_string(100000 + random() % 900000)); + if (fopen_s(&file, path.c_str(), "wx") != 0) + file = nullptr; + } +#else + int const descriptor = mkstemp(path.data()); + if (descriptor != -1) { + file = fdopen(descriptor, "w"); + if (file == nullptr) { + close(descriptor); + std::remove(path.c_str()); + } + } +#endif + if (file == nullptr) + return {}; + + bool const written = std::fwrite(text.data(), 1, text.size(), file) == text.size(); + if (std::fclose(file) != 0 || !written) { + std::remove(path.c_str()); + return {}; + } + return path; +} + bool check_shader(std::string filename) { gl::shader shader_processor; gl::glsl_common_setup(); - std::pair source = shader_processor.process_source(filename, "../shaders/"); + std::pair source; + try { + source = shader_processor.process_source(filename, "../shaders/"); + } + catch (gl::shader_exception const &e) { + std::cout << "failed to preprocess: " << e.what() << std::endl; + return false; + } std::string stage; if (source.first == GL_VERTEX_SHADER) @@ -26,11 +76,26 @@ bool check_shader(std::string filename) else return false; - std::ofstream file("/tmp/shader"); - file << source.second; - file.close(); + // glslang defines the GL_ARB_gpu_shader5 macro without the #extension directive, so light_common.glsl + // takes its textureGather() path, which needs the extension enabled on desktop GL 3.30. has_gl_extension() + // of gl/shader.cpp has no GL context here and says no, so the directive which the simulator gives on the + // drivers with the extension is added here + std::string const gpu_shader5 = "#extension GL_ARB_gpu_shader5 : enable\n"; + if (!Global.gfx_usegles && source.second.find(gpu_shader5) == std::string::npos) { + std::size_t const version_end = source.second.find('\n'); + if (version_end != std::string::npos) + source.second.insert(version_end + 1, gpu_shader5); + } - int ret = system(("glslangValidator -S " + stage + " /tmp/shader").c_str()); + // the stage is given with -S, so the file needs no extension + std::string const path = write_temp_file(source.second); + if (path.empty()) { + std::cout << "cannot write the shader to the temporary directory" << std::endl; + return false; + } + + int ret = system(("glslangValidator -S " + stage + " \"" + path + "\"").c_str()); + std::remove(path.c_str()); return ret == 0; } @@ -90,24 +155,32 @@ bool check_shader_confs(std::string filename) int main() { - bool suc = true; + // in name order, so the runs can be compared + std::vector shaders; for (auto &f : std::filesystem::recursive_directory_iterator("../shaders/")) { if (!f.is_regular_file()) continue; - std::string relative = std::filesystem::relative(f.path(), "../shaders/").string(); if (f.path().extension() != ".frag" && f.path().extension() != ".geom" && f.path().extension() != ".vert") continue; + shaders.push_back(std::filesystem::relative(f.path(), "../shaders/").generic_string()); + } + std::sort(shaders.begin(), shaders.end()); + + std::vector failed; + for (auto const &relative : shaders) { std::cout << "== validating shader " << relative << ": " << std::flush; if (!check_shader_confs(relative)) - suc = false; + failed.push_back(relative); } - if (suc) - std::cout << "==== all checks ok" << std::endl; + if (failed.empty()) + std::cout << "==== all checks ok (" << shaders.size() << " shaders)" << std::endl; else { - std::cout << "==== checks failed" << std::endl; + std::cout << "==== checks failed for " << failed.size() << " of " << shaders.size() << " shaders:" << std::endl; + for (auto const &relative : failed) + std::cout << relative << std::endl; return 1; } diff --git a/ci_shadervalidator/stdafx.h b/ci_shadervalidator/stdafx.h index 5e0560889..093baa4d2 100644 --- a/ci_shadervalidator/stdafx.h +++ b/ci_shadervalidator/stdafx.h @@ -1,6 +1,11 @@ #pragma once +// stands in for the precompiled header of the simulator, with what gl/shader.cpp, gl/glsl_common.cpp and the +// headers they include take from it #define GLM_ENABLE_EXPERIMENTAL #define GLM_FORCE_CTOR_INIT #include +#include +#include #include +#include #include diff --git a/ci_shadervalidator/Globals.h b/ci_shadervalidator/utilities/Globals.h similarity index 100% rename from ci_shadervalidator/Globals.h rename to ci_shadervalidator/utilities/Globals.h diff --git a/ci_shadervalidator/Logs.h b/ci_shadervalidator/utilities/Logs.h similarity index 100% rename from ci_shadervalidator/Logs.h rename to ci_shadervalidator/utilities/Logs.h diff --git a/gl/shader.cpp b/gl/shader.cpp index c276cdef8..feb5d95dc 100644 --- a/gl/shader.cpp +++ b/gl/shader.cpp @@ -30,8 +30,10 @@ namespace { // SHADERVALIDATOR_STANDALONE gates out the GL queries because the offline // shader validator tool links glad.c but never calls gladLoadGL(); the // function pointers stay null and a real call would crash. Returning -// false there means the standalone validator simply compiles the original -// 16-tap PCF fallback path in light_common.glsl, which is what we want. +// false there adds no #extension directive. For desktop GL the validator +// adds GL_ARB_gpu_shader5 itself (ci_shadervalidator/main.cpp), since +// glslang defines that macro anyway, so light_common.glsl is validated on +// its textureGather() path, not on the 16-tap PCF fallback. bool has_gl_extension(char const *name) { #ifdef SHADERVALIDATOR_STANDALONE (void)name; From 7059644209d48157bdfd9748677cfbafd87e2dc0 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 05:13:18 +0100 Subject: [PATCH 04/27] fix(editor): a model file named outside the code page no longer crashes the first track selection (#470) * fix(editor): a model file named outside the code page no longer crashes the first track selection The first selection of a track builds the track property list, and with it the sleeper and timber model choices. pack_models() walked the whole models/ tree and turned the name of every .t3d/.e3d into a narrow string before looking at whether it was a sleeper at all. On Windows that goes through the ANSI code page, so a single model file anywhere under models/ named with a character the code page lacks threw std::system_error "No mapping for the Unicode character exists in the target multi-byte code page" out of the editor frame and the editor stopped (GE#560). The conversions are now in a try, as in the editor's other folder scans: a file whose name can't be converted is left out (the game couldn't load it by that name anyway) and the scan goes on. Names that convert give the same list as before. The scan itself moved to world/SleeperPack.cpp in the core library as pack_models(root), which pack_models() calls once with models/, so the unit tests can run it on a folder of their own. * fix(launcher): a vehicle folder named outside the code page is skipped by the skin scan scan_textures() keeps the folder of each textures.txt as a wide path and get_vehicle() turns it into a narrow name with no try. On Windows a folder under dynamic/ named with a character the code page lacks threw the same std::system_error out of the editor's vehicle tool, the launcher and the vehicle picker. Such a folder is now left out of the scan, as the model scan does with such a file. --- CMakeLists.txt | 1 + launcher/textures_scanner.cpp | 12 +++- tests/unit/test_sleeper_models.cpp | 67 ++++++++++++++++++++++ world/SleeperModels.cpp | 55 +----------------- world/SleeperPack.cpp | 91 ++++++++++++++++++++++++++++++ world/TrackSleepers.h | 4 ++ 6 files changed, 175 insertions(+), 55 deletions(-) create mode 100644 tests/unit/test_sleeper_models.cpp create mode 100644 world/SleeperPack.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 294128b87..ddffc7402 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -550,6 +550,7 @@ set(CORE_SOURCES "McZapkie/derailment.cpp" "McZapkie/collision.cpp" "world/TrackCheck.cpp" +"world/SleeperPack.cpp" "McZapkie/Oerlikon_ESt.cpp" "utilities/parser.cpp" "utilities/utilities.cpp" diff --git a/launcher/textures_scanner.cpp b/launcher/textures_scanner.cpp index 741f978ca..480bd5671 100644 --- a/launcher/textures_scanner.cpp +++ b/launcher/textures_scanner.cpp @@ -9,8 +9,18 @@ void ui::vehicles_bank::scan_textures() if (f->path().filename() != "textures.txt") continue; + auto const folder{std::filesystem::relative(f->path().parent_path(), "dynamic/", error)}; + try { + // the vehicles are kept by narrow names. on Windows a folder named with a character the code page lacks + // can't be given one and would throw at the first vehicle; the game couldn't load it by that name anyway + [[maybe_unused]] auto const name{folder.generic_string()}; + } + catch (std::system_error const &) { + continue; + } + ctx_path = folder; + std::fstream stream(f->path(), std::ios_base::binary | std::ios_base::in); - ctx_path = std::filesystem::relative(f->path().parent_path(), "dynamic/", error); std::string line; while (std::getline(stream, line)) diff --git a/tests/unit/test_sleeper_models.cpp b/tests/unit/test_sleeper_models.cpp new file mode 100644 index 000000000..05d90ab32 --- /dev/null +++ b/tests/unit/test_sleeper_models.cpp @@ -0,0 +1,67 @@ +#include "stdafx.h" +#include "doctest.h" +#include "scratch.h" + +#include "world/TrackSleepers.h" + +#include +#include +#include + +// the models of sleepers and timbers the track editor lists (world/TrackSleepers.h), found by the names of the files in a +// folder. a file named with a character the code page lacks is left out, rather than throwing out of the scan (GE#560) + +namespace { + +void write_model(std::filesystem::path const &Path, std::string const &Content) { + std::filesystem::create_directories(Path.parent_path()); + std::ofstream file{Path, std::ios::binary}; + file << Content; +} + +// whether the name can be turned into the narrow names of the code page: on Windows a Chinese character can't be with any +// of the single byte pages, where the narrow names are UTF-8 it can +bool narrow_name(std::filesystem::path const &Path) { + try { + static_cast(Path.generic_string()); + return true; + } catch (std::exception const &) { + return false; + } +} + +} // namespace + +TEST_CASE("sleeper models: a file named outside of the code page is left out, the rest is listed") { + test::scratch_folder const folder{"sleeper_models"}; + auto const root{folder.root()}; + write_model(root / "pkp" / "podklad_a.t3d", "Name: podklad\n"); + write_model(root / "pkp" / "podrozjazd_b.t3d", "Name: begin\nName: main\nName: end\n"); + auto const odd{root / "pkp" / std::filesystem::path{u8"podklad_\u4e2d.t3d"}}; + write_model(odd, "Name: podklad\n"); + // nor any other model of the folder named so, looked at before its name tells it's no sleeper + write_model(root / "drzewa" / std::filesystem::path{u8"drzewo_\u4e2d.e3d"}, ""); + write_model(root / "drzewa" / "drzewo.e3d", ""); + REQUIRE(std::filesystem::exists(odd)); + + std::vector models; + REQUIRE_NOTHROW(models = track_sleepers::pack_models(root)); + + auto const listed{narrow_name(odd)}; + REQUIRE(models.size() == (listed ? 3u : 2u)); + // the timbers first, then by the name + CHECK(models[0].name == "pkp/podrozjazd_b"); + CHECK(models[0].timber); + CHECK(models[1].name == "pkp/podklad_a"); + CHECK_FALSE(models[1].timber); + if (listed) { + CHECK(models[2].name.find("pkp/podklad_") == 0); + } +} + +TEST_CASE("sleeper models: a folder missing lists none") { + test::scratch_folder const folder{"sleeper_models_missing"}; + std::vector models; + REQUIRE_NOTHROW(models = track_sleepers::pack_models(folder.root() / "missing")); + CHECK(models.empty()); +} diff --git a/world/SleeperModels.cpp b/world/SleeperModels.cpp index ad3c791c8..ada63d3a6 100644 --- a/world/SleeperModels.cpp +++ b/world/SleeperModels.cpp @@ -23,8 +23,6 @@ http://mozilla.org/MPL/2.0/. #include #include -#include -#include #include namespace track_sleepers { @@ -237,44 +235,6 @@ double plain_length( TTrack const &Track ) { return 2.0 * ( 0.5 * std::abs( Track.fTrackWidth ) + rail_reach + beam_overhang ); } -namespace { - -// the model of sleepers or timbers of the file added to those found, once by its name, what goes wrong left in the error -void add_pack_model( std::filesystem::directory_entry const &Entry, std::filesystem::path const &Root, std::error_code &Error, std::vector &Models ) { - - namespace fs = std::filesystem; - if( false == Entry.is_regular_file( Error ) ) { - return; - } - auto const extension { ToLower( Entry.path().extension().string() ) }; - if( extension != ".t3d" && extension != ".e3d" ) { - return; - } - auto name { ToLower( fs::relative( Entry.path(), Root, Error ).replace_extension().generic_string() ) }; - if( Error || name.empty() ) { - return; - } - if( name.find( "podklad" ) == std::string::npos && name.find( "podrozjazd" ) == std::string::npos - && name.find( "sleeper" ) == std::string::npos && name.find( "timber" ) == std::string::npos ) { - return; - } - // a timber model has the parts it's put together from, told by their names in the file - std::ifstream file { Entry.path(), std::ios::binary }; - std::string const content { std::istreambuf_iterator( file ), std::istreambuf_iterator() }; - auto const has = [ &extension, &content ]( std::string const &Part ) { - return ( - extension == ".t3d" ? - content.find( "Name: " + Part + "\n" ) != std::string::npos || content.find( "Name: " + Part + " " ) != std::string::npos - || content.find( "Name: " + Part + "\r" ) != std::string::npos : - content.find( std::string { '\0' } + Part + '\0' ) != std::string::npos ); }; - auto const timber { has( "begin" ) && has( "main" ) && has( "end" ) }; - if( std::ranges::none_of( Models, [ &name ]( pack_model const &Model ) { return Model.name == name; } ) ) { - Models.emplace_back( std::move( name ), timber ); - } -} - -} // namespace - std::vector const &pack_models() { static std::vector models; @@ -283,20 +243,7 @@ std::vector const &pack_models() { return models; } scanned = true; - namespace fs = std::filesystem; - std::error_code error; - auto const root { fs::path { paths::models } }; - fs::recursive_directory_iterator entry { root, fs::directory_options::follow_directory_symlink | fs::directory_options::skip_permission_denied, error }; - fs::recursive_directory_iterator const end; - while( entry != end ) { - if( error ) { - break; - } - add_pack_model( *entry, root, error, models ); - entry.increment( error ); - } - std::ranges::sort( models, []( pack_model const &Left, pack_model const &Right ) { - return ( Left.timber != Right.timber ? Left.timber : Left.name < Right.name ); } ); + models = pack_models( std::filesystem::path { paths::models } ); return models; } diff --git a/world/SleeperPack.cpp b/world/SleeperPack.cpp new file mode 100644 index 000000000..b04c573bb --- /dev/null +++ b/world/SleeperPack.cpp @@ -0,0 +1,91 @@ +/* +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/. +*/ + +#include "stdafx.h" + +#include "world/TrackSleepers.h" +#include "utilities/utilities.h" + +#include +#include +#include +#include + +// the models of sleepers and timbers found among the files of a folder, by their names; apart from the models drawn, so the +// unit tests can look through a folder of their own + +namespace track_sleepers { + +namespace { + +// the model of sleepers or timbers of the file added to those found, once by its name, what goes wrong left in the error +void add_pack_model( std::filesystem::directory_entry const &Entry, std::filesystem::path const &Root, std::error_code &Error, std::vector &Models ) { + + namespace fs = std::filesystem; + if( false == Entry.is_regular_file( Error ) ) { + return; + } + // a name with a character the code page lacks throws as it's turned into the narrow names the models are loaded by, which + // couldn't open the file anyway: the file is left out, not the rest of the folder with it + std::string extension; + std::string name; + try { + extension = ToLower( Entry.path().extension().string() ); + if( extension != ".t3d" && extension != ".e3d" ) { + return; + } + name = ToLower( fs::relative( Entry.path(), Root, Error ).replace_extension().generic_string() ); + } + catch( std::exception const & ) { + return; + } + if( Error || name.empty() ) { + return; + } + if( name.find( "podklad" ) == std::string::npos && name.find( "podrozjazd" ) == std::string::npos + && name.find( "sleeper" ) == std::string::npos && name.find( "timber" ) == std::string::npos ) { + return; + } + // a timber model has the parts it's put together from, told by their names in the file + std::ifstream file { Entry.path(), std::ios::binary }; + std::string const content { std::istreambuf_iterator( file ), std::istreambuf_iterator() }; + auto const has = [ &extension, &content ]( std::string const &Part ) { + return ( + extension == ".t3d" ? + content.find( "Name: " + Part + "\n" ) != std::string::npos || content.find( "Name: " + Part + " " ) != std::string::npos + || content.find( "Name: " + Part + "\r" ) != std::string::npos : + content.find( std::string { '\0' } + Part + '\0' ) != std::string::npos ); }; + auto const timber { has( "begin" ) && has( "main" ) && has( "end" ) }; + if( std::ranges::none_of( Models, [ &name ]( pack_model const &Model ) { return Model.name == name; } ) ) { + Models.emplace_back( std::move( name ), timber ); + } +} + +} // namespace + +std::vector pack_models( std::filesystem::path const &Root ) { + + namespace fs = std::filesystem; + std::vector models; + std::error_code error; + fs::recursive_directory_iterator entry { Root, fs::directory_options::follow_directory_symlink | fs::directory_options::skip_permission_denied, error }; + fs::recursive_directory_iterator const end; + while( entry != end ) { + if( error ) { + break; + } + add_pack_model( *entry, Root, error, models ); + entry.increment( error ); + } + std::ranges::sort( models, []( pack_model const &Left, pack_model const &Right ) { + return ( Left.timber != Right.timber ? Left.timber : Left.name < Right.name ); } ); + return models; +} + +} // namespace track_sleepers diff --git a/world/TrackSleepers.h b/world/TrackSleepers.h index a22bcb94a..9acd9dc25 100644 --- a/world/TrackSleepers.h +++ b/world/TrackSleepers.h @@ -11,6 +11,7 @@ http://mozilla.org/MPL/2.0/. #include #include +#include #include #include #include @@ -123,6 +124,9 @@ struct pack_model { // the models of sleepers and timbers in the scenery data, found once in models/ by the names of their files telling sleepers // or timbers: podklad, podrozjazd, sleeper, timber. the timber ones first, then by the name std::vector const &pack_models(); +// the models of sleepers and timbers among the files under the folder given, named relative to it, in the same order; a file +// named with a character the code page lacks is left out +std::vector pack_models( std::filesystem::path const &Root ); // the beams of the track placed anew, as instances of the parts of the model void lay( TTrack &Track ); // the beams of the tracks around the track to be placed again, as they depend on where it runs From a3f4bd4f0d952f7912bbe3c5044194e2f350d4dc Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 05:13:37 +0100 Subject: [PATCH 05/27] fix(ai): a train standing past a signal when its speed table is traced hasn't passed it (#473) * fix(ai): a train standing past a signal when its speed table is traced hasn't passed it Since #409 a point of the speed table found behind the head counts as passed only when the head had it ahead once, but a point found up to 5 m behind the head still counted as seen ahead (SeenAheadTolerance), whether the train moved or stood. A train set at a stand 0.5-4.5 m past a signal at stop therefore found the signal behind its head at its first look ahead, the next update marked it elapsed, and the test mode ended with "signal passed at danger" at 13.6 s with the train at 0 km/h (EU07 on td.scn at stacja1_j; set 6 m or 20 m past, no report). The tolerance is kept for a moving train, which may be just passing a point found at its head. A standing train passes nothing: a point found behind its head counts as seen ahead only once an update finds it ahead. The rule moves out of TSpeedPos into vehicle/signalpassing.{h,cpp}, so it is unit tested; the blackbox record of passed signals follows it as before. Measured with the head set 0.5-6 m past and 0.5-2 m short of the signal on tor1k: the distance the scan finds is the head's own distance from the memory cell (to the micrometre there), so a train standing 0.5 m short still gets the signal ahead and passes it if it goes on. Tests: tests/unit/test_signal_passing.cpp (6 cases), and the scenario cases test_mode_standing_1m_past_signal and test_mode_standing_4m_past_signal (fragment td_past_red_signal.scn), which ended as signals passed at danger before and run into their timeout now. * test(scenarios): the shunting AI stops before a signal at stop on td.scn Two cases for the shunting fix of #409, left out of it: an EU07 with no timetable (its AI shunts) starting at 30 km/h about 150 m before the exit signal stacja1_j at stop, alone (eu07_td_shunt_red_signal) and pushing three coaches (eu07_td_shunt_push_red_signal), has to stop before the signal and stay there. They come from #340, whose braking was sharper; run on the code of #409 they stop after 145 m and 141 m, with the signal 151 m from the start, so the checks of #340 (no more than 150 m, below 40 km/h) hold as they were. * fix(sonar): count the metres of the signal passing test in an integer SonarCloud rule cpp:S2193 (a for loop counter of floating type) flagged the loop that moves the head a metre at a time in tests/unit/test_signal_passing.cpp and made the new reliability rating of the pull request fail the quality gate. The counter is now an int; it took whole values only, so every case runs the same number of steps as before. * fix(ai): the gap of a standing train a few decimetres short of a signal noted at seen_ahead_when_found --- CMakeLists.txt | 1 + tests/scenarios/README.md | 14 +- .../cases/eu07_td_shunt_push_red_signal.json | 24 ++++ .../cases/eu07_td_shunt_red_signal.json | 19 +++ tests/scenarios/cases/td_past_red_signal.scn | 7 + tests/scenarios/cases/td_shunt_red_signal.scn | 7 + .../test_mode_standing_1m_past_signal.json | 16 +++ .../test_mode_standing_4m_past_signal.json | 16 +++ tests/unit/test_signal_passing.cpp | 128 ++++++++++++++++++ vehicle/Driver.cpp | 28 ++-- vehicle/Driver.h | 3 +- vehicle/signalpassing.cpp | 30 ++++ vehicle/signalpassing.h | 38 ++++++ 13 files changed, 312 insertions(+), 19 deletions(-) create mode 100644 tests/scenarios/cases/eu07_td_shunt_push_red_signal.json create mode 100644 tests/scenarios/cases/eu07_td_shunt_red_signal.json create mode 100644 tests/scenarios/cases/td_past_red_signal.scn create mode 100644 tests/scenarios/cases/td_shunt_red_signal.scn create mode 100644 tests/scenarios/cases/test_mode_standing_1m_past_signal.json create mode 100644 tests/scenarios/cases/test_mode_standing_4m_past_signal.json create mode 100644 tests/unit/test_signal_passing.cpp create mode 100644 vehicle/signalpassing.cpp create mode 100644 vehicle/signalpassing.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ddffc7402..200adcf30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -571,6 +571,7 @@ set(CORE_SOURCES "vehicle/gaugewrap.cpp" "vehicle/drivingaid.cpp" "vehicle/brakingcurve.cpp" +"vehicle/signalpassing.cpp" "vehicle/handover.cpp" "vehicle/crew.cpp" "vehicle/horn.cpp" diff --git a/tests/scenarios/README.md b/tests/scenarios/README.md index b85f0f8cf..321b65479 100644 --- a/tests/scenarios/README.md +++ b/tests/scenarios/README.md @@ -135,7 +135,7 @@ Python 3.10+, no extra packages. Options: `cmake-build-*/bin/Release/eu07*.exe`. The build needs the `--test` and `-ini` command line options. - name one or more cases to run only those, e.g. `run.py ... eu07_td_timetable`. -- `-j N` runs N cases at once. Each case prints its results when it is done. The 22 cases +- `-j N` runs N cases at once. Each case prints its results when it is done. The 42 cases that aren't `slow` take about 30 s with `-j 4` and 2 minutes one at a time, loading included. - `--watch` runs a case the old way, in a visible window in real time (or faster with `--timespeed N`), closed after the case's `duration`; the exit code isn't checked then. For @@ -236,6 +236,11 @@ starting at `vars.velocity` km/h; with `track_friction` 0.03 it locks the wheels and slides past the signal, so those cases set `test.fail_if_stop_overran no`. `td_red_signal_pass.scn` adds the `test_pass` event, which `test_mode_pass` puts as `event0` on `tor1k`, the track in front of the signal. +`td_shunt_red_signal.scn` is the same with no timetable, so the AI shunts (Shunt) towards the signal at +stop, starting `vars.offset` m into `tdo_n1734`: `eu07_td_shunt_red_signal` alone and +`eu07_td_shunt_push_red_signal` pushing three coaches, both from 30 km/h, have to stop before the signal, +151 m from the start (the shunting AI used to coast up to it and pass it at about 28 km/h, fixed +by #409). They stop after 145 m and 141 m. `eu07_td_departure_station_capitals` runs an EU07 from where `td_timetable.scn` puts it, with the W4 of Stacja1 about 35 m ahead, on a timetable of its own (`td_departure_station_capitals.txt`, fragment `td_departure_station.scn`): @@ -259,6 +264,13 @@ standstill of 100 s ends the test although the traffic runs on (counting every v into the test timeout). `test_mode_pass_while_moving` reports the pass from `event2` of `tor1k` (the direction the train runs), as the train runs onto it, with `test.no_movement_before_pass no`, so the test ends with the train still moving. +`test_mode_standing_1m_past_signal` and `test_mode_standing_4m_past_signal` (fragment `td_past_red_signal.scn`) set +the td/rozklad train at a stand with its head 1 m and 4 m past the exit signal at stop (the memory cell of the +signal is 51 m into `tor1k`). The driver finds the signal behind the head at its first look ahead, 13.6 s in, and a +standing train passes nothing, so both run into their timeout. When a signal found up to 5 m behind the head +still counted as one the head had ahead, standing or not, both ended as signals passed at danger at 13.6 s (a +train set 6 m or 20 m past didn't). Starting at 0 km/h the driver doesn't wake up within the case, so they start at +0.1 km/h, as `td_red_signal.scn` does. The `en57_2000_automatic_coupler_*` cases (issue #86) share `td_automatic_coupler_hit.scn`: an EN57-2000 unit without a driver runs at `vars.velocity` km/h into a standing one, from diff --git a/tests/scenarios/cases/eu07_td_shunt_push_red_signal.json b/tests/scenarios/cases/eu07_td_shunt_push_red_signal.json new file mode 100644 index 000000000..243d37641 --- /dev/null +++ b/tests/scenarios/cases/eu07_td_shunt_push_red_signal.json @@ -0,0 +1,24 @@ +{ + "description": "EU07 shunting on td.scn (no timetable, so its AI drives under Shunt), pushing three coaches with no route set, the first coach starting at 30 km/h about 150 m before the exit signal stacja1_j at stop: stops before the signal and stays there.", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_shunt_red_signal.scn", + "vars": { + "offset": "0.0", + "velocity": "30", + "consist": [ + "node -1 0 {{vehicle}}_w1 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 115 0 enddynamic", + "node -1 0 {{vehicle}}_w2 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608011-6 BDHPUMN_NG_1 0 nobody 115 0 enddynamic", + "node -1 0 {{vehicle}}_w3 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 115 0 enddynamic", + "node -1 0 {{vehicle}} dynamic pkp\\4e_v1 4e-004 4e 0 headdriver 0 0 enddynamic" + ] + }, + "duration": 240, + "timeout": 600, + "checks": [ + { "type": "max_speed", "limit": 40 }, + { "type": "stops", "moving_speed": 5, "stop_speed": 0.5, "hold": 5 }, + { "type": "stays_stopped", "moving_speed": 5, "stop_speed": 0.5 }, + { "type": "distance", "max": 150 } + ] +} diff --git a/tests/scenarios/cases/eu07_td_shunt_red_signal.json b/tests/scenarios/cases/eu07_td_shunt_red_signal.json new file mode 100644 index 000000000..bc23046cd --- /dev/null +++ b/tests/scenarios/cases/eu07_td_shunt_red_signal.json @@ -0,0 +1,19 @@ +{ + "description": "EU07 shunting on td.scn (no timetable, so its AI drives under Shunt) with no route set, starting at 30 km/h about 150 m before the exit signal stacja1_j at stop: stops before the signal and stays there.", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_shunt_red_signal.scn", + "vars": { + "offset": "0.0", + "velocity": "30", + "consist": "node -1 0 {{vehicle}} dynamic pkp\\4e_v1 4e-004 4e 0 headdriver 0 0 enddynamic" + }, + "duration": 240, + "timeout": 600, + "checks": [ + { "type": "max_speed", "limit": 40 }, + { "type": "stops", "moving_speed": 5, "stop_speed": 0.5, "hold": 5 }, + { "type": "stays_stopped", "moving_speed": 5, "stop_speed": 0.5 }, + { "type": "distance", "max": 150 } + ] +} diff --git a/tests/scenarios/cases/td_past_red_signal.scn b/tests/scenarios/cases/td_past_red_signal.scn new file mode 100644 index 000000000..e5e68da5f --- /dev/null +++ b/tests/scenarios/cases/td_past_red_signal.scn @@ -0,0 +1,7 @@ +// added by tests/scenarios/run.py to td.scn, whose own trainsets were removed. +// the timetable train of td.scn (td/rozklad) set at a stand past the exit signal stacja1_j, which stays at stop +// (no route): the head {{offset}} m into tor1k, whose memory cell of the signal is 51 m into the track. the train +// starts at 0.1 km/h, as in td_red_signal.scn: set at 0 its AI driver doesn't wake up within the case +trainset td/rozklad tor1k {{offset}} 0.1 +{{consist}} +endtrainset diff --git a/tests/scenarios/cases/td_shunt_red_signal.scn b/tests/scenarios/cases/td_shunt_red_signal.scn new file mode 100644 index 000000000..649427247 --- /dev/null +++ b/tests/scenarios/cases/td_shunt_red_signal.scn @@ -0,0 +1,7 @@ +// added by tests/scenarios/run.py to td.scn, whose own trainsets were removed. +// like td_red_signal_moving.scn (no route, the exit signal stacja1_j about 150 m ahead of the start of +// tdo_n1734 stays at stop), but the train has no timetable, so its AI driver shunts (Shunt), and it +// starts {{offset}} m into tdo_n1734, already moving at {{velocity}} km/h. +trainset none tdo_n1734 {{offset}} {{velocity}} +{{consist}} +endtrainset diff --git a/tests/scenarios/cases/test_mode_standing_1m_past_signal.json b/tests/scenarios/cases/test_mode_standing_1m_past_signal.json new file mode 100644 index 000000000..4157dc52d --- /dev/null +++ b/tests/scenarios/cases/test_mode_standing_1m_past_signal.json @@ -0,0 +1,16 @@ +{ + "description": "Test mode, no signal passed at danger for a train set past a signal: EU07 on td.scn standing with its head 1 m past the exit signal stacja1_j at stop (no route). Its driver finds the signal behind the head at its first look ahead, about 13 s in; a standing train passes nothing, so it isn't a signal passed at danger, and the case runs into its timeout.", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_past_red_signal.scn", + "vars": { + "offset": "52.0", + "consist": "node -1 0 {{vehicle}} dynamic pkp\\4e_v1 4e-004 4e 0 headdriver 0 0 enddynamic" + }, + "duration": 60, + "timeout": 600, + "checks": [ + { "type": "max_speed", "limit": 1 }, + { "type": "distance", "max": 1 } + ] +} diff --git a/tests/scenarios/cases/test_mode_standing_4m_past_signal.json b/tests/scenarios/cases/test_mode_standing_4m_past_signal.json new file mode 100644 index 000000000..b0b668873 --- /dev/null +++ b/tests/scenarios/cases/test_mode_standing_4m_past_signal.json @@ -0,0 +1,16 @@ +{ + "description": "Test mode, no signal passed at danger for a train set past a signal: EU07 on td.scn standing with its head 4 m past the exit signal stacja1_j at stop (no route). Its driver finds the signal behind the head at its first look ahead, about 13 s in; a standing train passes nothing, so it isn't a signal passed at danger, and the case runs into its timeout.", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_past_red_signal.scn", + "vars": { + "offset": "55.0", + "consist": "node -1 0 {{vehicle}} dynamic pkp\\4e_v1 4e-004 4e 0 headdriver 0 0 enddynamic" + }, + "duration": 60, + "timeout": 600, + "checks": [ + { "type": "max_speed", "limit": 1 }, + { "type": "distance", "max": 1 } + ] +} diff --git a/tests/unit/test_signal_passing.cpp b/tests/unit/test_signal_passing.cpp new file mode 100644 index 000000000..16d3cd9eb --- /dev/null +++ b/tests/unit/test_signal_passing.cpp @@ -0,0 +1,128 @@ +#include "stdafx.h" +#include "doctest.h" + +#include "vehicle/signalpassing.h" + +// when a signal in the AI's speed table counts as passed by the train (TController::CheckSignalPassed): the test +// mode reports a signal at stop passed that way as "passed at danger", the blackbox records every passed signal. a +// train set or standing past a signal at the start of a scenario didn't pass it; within 5 m of the signal the test +// mode used to report it all the same. + +namespace { + +// a point of the speed table the way TSpeedPos keeps it: found by the scan of the route, then updated as the head +// moves on (TController::TableCheck: UpdateDistance, Update, CheckSignalPassed) +struct table_point { + double distance; // ahead of the head [m], negative behind it + bool seen_ahead; + bool elapsed{false}; + int passes{0}; // reports of the point passed + + table_point(double const Distance, bool const Standing) + : distance(Distance), seen_ahead(signal_passing::seen_ahead_when_found(Distance, Standing)) { + move(0.0); // the first update comes with the next check of the table, the train hasn't moved yet + } + + // the head moves Metres on, and the table updates the point + void move(double const Metres) { + distance -= Metres; + auto const elapsedbefore{elapsed}; + elapsed = elapsed || distance < 0.0; + seen_ahead = signal_passing::seen_ahead_on_update(distance, seen_ahead); + if (signal_passing::passed_now(elapsedbefore, elapsed, seen_ahead)) { + ++passes; + } + } + + // the head moves Metres on in steps of a metre + void run(double const Metres) { + for (int moved{0}; moved < Metres; ++moved) { + move(1.0); + } + } +}; + +auto constexpr standing{true}; +auto constexpr moving{false}; + +} // namespace + +TEST_CASE("signal passing: a train standing past a signal when its table is traced hasn't passed it") { + auto behind{0.0}; + // 1-4.5 m: reported as passed at danger before; 20 m: the train standing across the signal of #409 + SUBCASE("0.5 m") { behind = 0.5; } + SUBCASE("1 m") { behind = 1.0; } + SUBCASE("2 m") { behind = 2.0; } + SUBCASE("3 m") { behind = 3.0; } + SUBCASE("4 m") { behind = 4.0; } + SUBCASE("4.9 m") { behind = 4.9; } + SUBCASE("20 m") { behind = 20.0; } + CAPTURE(behind); + + table_point signal{-behind, standing}; + CHECK_FALSE(signal.seen_ahead); + // standing there a while, then pulling away from it + for (auto check{0}; check < 10; ++check) { + signal.move(0.0); + } + signal.run(200.0); + CHECK(signal.passes == 0); +} + +TEST_CASE("signal passing: a train standing short of a signal passes it when it moves on") { + auto ahead{0.0}; + SUBCASE("at the signal") { ahead = 0.0; } + SUBCASE("0.5 m") { ahead = 0.5; } + SUBCASE("10 m") { ahead = 10.0; } + SUBCASE("150 m") { ahead = 150.0; } + CAPTURE(ahead); + + table_point signal{ahead, standing}; + CHECK(signal.seen_ahead); + signal.move(0.0); + CHECK(signal.passes == 0); + signal.run(ahead + 50.0); + CHECK(signal.passes == 1); +} + +TEST_CASE("signal passing: a moving train passing a signal its table finds just behind the head passes it") { + // the table traced anew in motion, the head right at the signal: the distance is found in steps of a metre, + // so a signal just ahead may come out a little behind + auto behind{0.0}; + SUBCASE("0.5 m") { behind = 0.5; } + SUBCASE("3 m") { behind = 3.0; } + SUBCASE("at the tolerance") { behind = signal_passing::moving_tolerance; } + CAPTURE(behind); + + table_point signal{-behind, moving}; + CHECK(signal.seen_ahead); + CHECK(signal.passes == 1); + signal.run(100.0); + CHECK(signal.passes == 1); +} + +TEST_CASE("signal passing: a signal found further behind a moving train than the tolerance wasn't passed by it") { + table_point signal{-(signal_passing::moving_tolerance + 0.5), moving}; + CHECK_FALSE(signal.seen_ahead); + signal.run(100.0); + CHECK(signal.passes == 0); +} + +TEST_CASE("signal passing: a train that overruns a signal and stops past it passes it once") { + // the overrun counts while the train moves; a table traced again with the train standing 3 m past the signal + // (a change of direction and back, a new order) doesn't count it again + table_point approach{150.0, moving}; + approach.run(153.0); + CHECK(approach.passes == 1); + + table_point traced_again{-3.0, standing}; + traced_again.run(50.0); + CHECK(traced_again.passes == 0); +} + +TEST_CASE("signal passing: the report of a pass needs the point to become elapsed in this very update") { + CHECK(signal_passing::passed_now(false, true, true)); + CHECK_FALSE(signal_passing::passed_now(true, true, true)); // elapsed before + CHECK_FALSE(signal_passing::passed_now(false, false, true)); // still ahead + CHECK_FALSE(signal_passing::passed_now(false, true, false)); // the head never had it ahead +} diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index 99c6a951e..a25ed392c 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -23,6 +23,7 @@ http://mozilla.org/MPL/2.0/. #include "vehicle/brakesetting.h" #include "vehicle/brakingcurve.h" #include "vehicle/handover.h" +#include "vehicle/signalpassing.h" #include "vehicle/timetableservice.h" #include "world/mtable.h" #include "world/stationnames.h" @@ -330,9 +331,7 @@ bool TSpeedPos::Update() // trzeba zazanaczyć, że minięty iFlags |= spElapsed; } - else { - bSeenAhead = true; - } + bSeenAhead = signal_passing::seen_ahead_on_update( fDist, bSeenAhead ); if (iFlags & spTrack) { // road/track if (trTrack) { @@ -418,18 +417,14 @@ bool TSpeedPos::IsProperSemaphor(TOrders order) return false; // true gdy zatrzymanie, wtedy nie ma po co skanować dalej } -// how far behind the head an event found in the scan may lie and still count as one the head had ahead [m] -constexpr double SeenAheadTolerance { 5.0 }; - -bool TSpeedPos::Set(basic_event *event, double dist, double length, TOrders order) +bool TSpeedPos::Set(basic_event *event, double dist, double length, TOrders order, bool const Standing) { // zapamiętanie zdarzenia fDist = dist; - // an event already behind the head when found (under a train set across a signal) wasn't passed by it. the - // distance is found in steps of a metre from the position of the memory cell, so a signal just ahead of the head - // may come out a few metres behind it: those still count as seen ahead. the price is that a train set less than - // the tolerance past a signal at stop is still reported to pass it; a train standing that close to a signal can't - // be told from one stopped just short of it, which really passes the signal if it goes on - bSeenAhead = ( dist >= -SeenAheadTolerance ); + // an event already behind the head when found (under a train set across a signal) wasn't passed by it. a moving + // train may be just passing it, and the distance is found in steps of a metre, so for a moving train an event a + // little behind the head still counts as seen ahead. a standing train passes nothing: an event found behind its + // head counts only once an update finds it ahead + bSeenAhead = signal_passing::seen_ahead_when_found( dist, Standing ); iFlags = spEvent; evEvent = event; vPos = event->input_location(); // współrzędne eventu albo komórki pamięci (zrzutować na tor?) @@ -646,7 +641,7 @@ void TController::TableTraceRoute(double fDistance, TDynamicObject *pVehicle) fCurrentDistance + ProjectEventOnTrack( pEvent, pTrack, fLastDir ), OrderCurrentGet() ) ) { */ - if (newspeedpoint.Set(pEvent, GetDistanceToEvent(pTrack, pEvent, fLastDir, fCurrentDistance), fLength, OrderCurrentGet())) + if (newspeedpoint.Set(pEvent, GetDistanceToEvent(pTrack, pEvent, fLastDir, fCurrentDistance), fLength, OrderCurrentGet(), mvOccupied->Vel < EU07_AI_NOMOVEMENT)) { fDistance = newspeedpoint.fDist; // jeśli sygnał stop, to nie ma potrzeby dalej skanować @@ -922,9 +917,8 @@ std::uint8_t passing_flags_of( TSpeedPos const &Point, double const Speedatsigna void TController::CheckSignalPassed( TSpeedPos const &Point, bool const Passedbefore ) const { - if( Passedbefore - || false == TestFlag( Point.iFlags, spElapsed ) - || false == Point.bSeenAhead // found already behind the head: the train stood across it, it didn't pass it + // not bSeenAhead: found already behind the head, the train stood across it or past it, it didn't pass it + if( false == signal_passing::passed_now( Passedbefore, TestFlag( Point.iFlags, spElapsed ), Point.bSeenAhead ) || ( mvOccupied->CategoryFlag & 1 ) == 0 ) { // railway only return; } diff --git a/vehicle/Driver.h b/vehicle/Driver.h index 0aaf70707..87dccd030 100644 --- a/vehicle/Driver.h +++ b/vehicle/Driver.h @@ -184,7 +184,8 @@ class TSpeedPos void UpdateDistance( double dist ) { fDist -= dist; } - bool Set(basic_event *e, double d, double length, TOrders order = Wait_for_orders); + // Standing: the train stands, so an event found behind its head wasn't passed by it + bool Set(basic_event *e, double d, double length, TOrders order = Wait_for_orders, bool Standing = false); void Set(TTrack *t, double d, int f); std::string TableText() const; std::string GetName() const; diff --git a/vehicle/signalpassing.cpp b/vehicle/signalpassing.cpp new file mode 100644 index 000000000..58d691760 --- /dev/null +++ b/vehicle/signalpassing.cpp @@ -0,0 +1,30 @@ +/* +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/. +*/ + +#include "stdafx.h" +#include "vehicle/signalpassing.h" + +namespace signal_passing { + +bool seen_ahead_when_found( double const Distance, bool const Standing ) { + + return Distance >= ( Standing ? 0.0 : -moving_tolerance ); +} + +bool seen_ahead_on_update( double const Distance, bool const Seenahead ) { + + return Seenahead || Distance >= 0.0; +} + +bool passed_now( bool const Elapsedbefore, bool const Elapsed, bool const Seenahead ) { + + return Elapsed && !Elapsedbefore && Seenahead; +} + +} // namespace signal_passing diff --git a/vehicle/signalpassing.h b/vehicle/signalpassing.h new file mode 100644 index 000000000..33f2e5265 --- /dev/null +++ b/vehicle/signalpassing.h @@ -0,0 +1,38 @@ +/* +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/. +*/ + +#pragma once + +// when a point of the AI's speed table (a signal above all) counts as passed by the train: the test mode's +// "signal passed at danger" and the blackbox record of passed signals (TController::CheckSignalPassed) +namespace signal_passing { + +// how far behind the head a point found by the scan of a moving train may lie and still count as one the head +// had ahead [m]. GetDistanceToEvent() finds the distance in steps of a metre from the position of the memory +// cell, so a signal just ahead of the head may come out a little behind it +inline constexpr double moving_tolerance { 5.0 }; + +// whether a point the scan finds Distance [m] ahead of the head (negative: behind it) counts as one the head had +// ahead. a moving train may be just passing it, so a point up to moving_tolerance behind counts. a standing train +// isn't passing anything: a point found behind its head was passed before (a train set or stopped past a signal), +// and counts only once an update finds it ahead. +// known gap: the distance can be off by about half a metre (GetDistanceToEvent() takes the nearest of samples a +// metre apart), so a train standing a few decimetres short of a signal may find it just behind the head, and if it +// then runs past it at stop, that isn't reported. a tolerance for a standing train wouldn't close it: the first +// update marks a point behind the head elapsed (TSpeedPos::Update()), so such a train would be reported as passing +// the signal at once, while it stands short of it. the AI stops 8-15 m short of a signal +bool seen_ahead_when_found( double Distance, bool Standing ); + +// whether the head had the point ahead, after an update finds it Distance [m] ahead of the head +bool seen_ahead_on_update( double Distance, bool Seenahead ); + +// whether an update of a point reports it as passed: it became elapsed in this update, and the head had it ahead +bool passed_now( bool Elapsedbefore, bool Elapsed, bool Seenahead ); + +} // namespace signal_passing From 419bec12853e3b9930bd067b1b942acbd0fccfe4 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 05:13:46 +0100 Subject: [PATCH 06/27] test(camera): pin the order of the rotations of TCamera::SetMatrix (#414) (#474) The roll of the camera is multiplied in first, so it turns the view about the line of sight. 623c4f82 once moved it last, which nodded the view up and down when looking out of a side window with the cab swaying; #414 put it back. The new tests check the axes of the view matrix for several pitch, yaw and roll values: the line of sight follows the pitch and the yaw whatever the roll, the roll turns the up and right axes about the line of sight, and in the cab the view out of a side window stays level. With the roll moved back last, all three test cases fail. The test binary now compiles vehicle/Camera.cpp itself, with stubs for the command queue and the clock. The smoke colour of a cold diesel (#413) stays untested: it lives in rendering/particles.cpp, which needs the world environment and a whole vehicle to link. --- tests/unit/CMakeLists.txt | 2 + tests/unit/COVERAGE.md | 2 + tests/unit/test_camera.cpp | 156 +++++++++++++++++++++++++++++++++++++ 3 files changed, 160 insertions(+) create mode 100644 tests/unit/test_camera.cpp diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index d06c83445..180285912 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -34,6 +34,8 @@ add_executable(${UNIT_TESTS_NAME} "${CMAKE_SOURCE_DIR}/editor/editorFouling.cpp" # and the http client the editor fetches its aids with "${CMAKE_SOURCE_DIR}/editor/editorHttp.cpp" + # the camera, for the order of its rotations (test_camera.cpp) + "${CMAKE_SOURCE_DIR}/vehicle/Camera.cpp" ${UNIT_TEST_CASES}) # the core library brings the game's build settings along diff --git a/tests/unit/COVERAGE.md b/tests/unit/COVERAGE.md index 9b677fbed..4f7f4d657 100644 --- a/tests/unit/COVERAGE.md +++ b/tests/unit/COVERAGE.md @@ -124,6 +124,8 @@ Notes to the table: - The small headers with the logic of a single part are all run in full: `vehicle/doorwings.h`, `gaugeduplicates.h`, `gaugepositions.h`, `holdcoillever.h`, `lightsprogrammer.h`, `mainctrlact.h`, `mirrors.h`, `scripting/scriptscreendrawing.h`, `scriptscreenkernels.h`, `scriptscreenprogram.h`, `scriptscreens.h`, `utilities/dictionary.h` and `vehicle/blackbox.h`. - `vehicle/brakesetting.cpp` and `vehicle/odometer.cpp` (the brake setting of the wagons, the odometer store) joined the library on master after that run. In the run of `bac9954a` their tests (`test_brake_setting.cpp`, `test_odometer.cpp`) run 94.1% (144 of 153) and 87.9% (189 of 215) of their lines, and all 14 and 26 of 28 of their functions. - The script hosts (`scriptscreens.cpp`, `luaprogram.cpp`, `wasmprogram.cpp`) aren't in the library. The test binary compiles them itself, with the real runtimes. +- `vehicle/Camera.cpp` isn't in the library either. The test binary compiles it for the order of the camera's rotations (`test_camera.cpp`, #414), with stubs for the command queue and the clock that `TCamera::Update()` reaches for. +- The colour of the smoke of a cold diesel (#413) isn't tested: the fix is in `smoke_source::update()` (`rendering/particles.cpp`), which needs the world environment (sky, sun, precipitation, sounds) and a whole `TDynamicObject` to link. - `scene/scenelayers.h`, `scene/scenenode.h` and `scene/scenenodegroups.h` are in the report with a few lines each: the parser reports the files it includes to the scenery, which the tests replace with stubs (`engine_stubs.cpp`). ### The parser, the helpers and the PLC diff --git a/tests/unit/test_camera.cpp b/tests/unit/test_camera.cpp new file mode 100644 index 000000000..684fadb56 --- /dev/null +++ b/tests/unit/test_camera.cpp @@ -0,0 +1,156 @@ +#include "stdafx.h" +#include "doctest.h" + +#include +#include +#include +#include + +#include "input/command.h" +#include "utilities/Timer.h" +#include "vehicle/Camera.h" + +// the view matrix of the camera (TCamera::SetMatrix): the pitch (Angle.x) and the yaw (Angle.y) give the line of sight, +// the roll (Angle.z) turns the view about that line, wherever the camera looks. The roll comes from the sway of the cab +// (drivermode.cpp) or the angles of a camera entry of the scenery. Multiplied in last, it once acted about the world's z +// axis instead, and nodded the view up and down when looking out of a side window (623c4f82, put back in #414). +// vehicle/Camera.cpp isn't in the core library; the test binary compiles it itself (tests/unit/CMakeLists.txt) + +// the parts of the engine TCamera::Update() reaches for, which no test here runs: the command queue and the clock +// (simulation::Commands itself is in test_script_screen_host.cpp) +bool command_queue::pop(command_data &, uint32_t const) { // NOSONAR signature from input/command.h + return false; +} + +double Timer::GetDeltaRenderTime() { // NOSONAR signature from utilities/Timer.h + return 0.0; +} + +namespace { + +// the axes of the view in the world, from the view matrix +struct view_axes { + glm::dvec3 eye; + glm::dvec3 forward; // the line of sight + glm::dvec3 up; + glm::dvec3 right; +}; + +view_axes axes(TCamera const &Camera) { + glm::dmat4 matrix{1.0}; + REQUIRE(Camera.SetMatrix(matrix)); + auto const toworld{glm::inverse(matrix)}; + return { + glm::dvec3{toworld * glm::dvec4{0.0, 0.0, 0.0, 1.0}}, + glm::dvec3{toworld * glm::dvec4{0.0, 0.0, -1.0, 0.0}}, + glm::dvec3{toworld * glm::dvec4{0.0, 1.0, 0.0, 0.0}}, + glm::dvec3{toworld * glm::dvec4{1.0, 0.0, 0.0, 0.0}}}; +} + +void check_equal(glm::dvec3 const &Actual, glm::dvec3 const &Expected) { + CAPTURE(Actual.x); + CAPTURE(Actual.y); + CAPTURE(Actual.z); + CHECK(Actual.x == doctest::Approx(Expected.x).epsilon(1e-9)); + CHECK(Actual.y == doctest::Approx(Expected.y).epsilon(1e-9)); + CHECK(Actual.z == doctest::Approx(Expected.z).epsilon(1e-9)); +} + +// the free camera, at Position, turned by Angle (pitch, yaw, roll) +TCamera free_camera(glm::dvec3 const &Position, glm::vec3 const &Angle) { + TCamera camera; + camera.Init(Position, glm::dvec3{Angle}, nullptr); + return camera; +} + +struct turn { + float pitch; + float yaw; +}; + +// the camera looking ahead (-z), out of the left and the right side window, back, up and down at an angle +std::vector const turns{ + {0.f, 0.f}, + {0.f, static_cast(std::numbers::pi / 2)}, + {0.3f, static_cast(-std::numbers::pi / 2)}, + {-0.4f, static_cast(std::numbers::pi)}, + {0.2f, 0.7f}, + {-0.6f, -2.1f}, +}; + +std::vector const rolls{0.1f, -0.2f, 0.5f}; + +} // namespace + +TEST_CASE("camera: the pitch and the yaw give the line of sight, the roll leaves it as it is (#414)") { + glm::dvec3 const position{120.0, 4.5, -300.0}; + for (auto const &turn : turns) { + auto const pitch{static_cast(turn.pitch)}; + auto const yaw{static_cast(turn.yaw)}; + // the yaw from -z towards -x, the pitch up from the ground, as TCamera::RaLook() works them out + glm::dvec3 const sight{-std::sin(yaw) * std::cos(pitch), std::sin(pitch), -std::cos(yaw) * std::cos(pitch)}; + for (auto const roll : {0.f, rolls[0], rolls[1], rolls[2]}) { + CAPTURE(turn.pitch); + CAPTURE(turn.yaw); + CAPTURE(roll); + auto const view{axes(free_camera(position, {turn.pitch, turn.yaw, roll}))}; + check_equal(view.eye, position); + check_equal(view.forward, sight); + } + } +} + +TEST_CASE("camera: the roll turns the view about the line of sight, wherever the camera looks (#414)") { + for (auto const &turn : turns) { + auto const level{axes(free_camera({}, {turn.pitch, turn.yaw, 0.f}))}; + for (auto const roll : rolls) { + CAPTURE(turn.pitch); + CAPTURE(turn.yaw); + CAPTURE(roll); + auto const rolled{axes(free_camera({}, {turn.pitch, turn.yaw, roll}))}; + auto const angle{static_cast(roll)}; + // the up of the view leans towards the left by the roll, and stays square to the line of sight + check_equal(rolled.up, std::cos(angle) * level.up - std::sin(angle) * level.right); + check_equal(rolled.right, std::cos(angle) * level.right + std::sin(angle) * level.up); + CHECK(glm::dot(rolled.up, rolled.forward) == doctest::Approx(0.0).epsilon(1e-9)); + } + } +} + +// the camera in the cab: the eye in the cab, looking at a point ahead of the vehicle (TCamera::LookAt), the head turned +// by the yaw and the pitch, the sway of the cab given as the roll. The camera needs no more of the vehicle than that it +// has one, so the vehicle is a zeroed block of its size, never used as an object (as the neighbours in vehicle.cpp) +static_assert(alignof(TDynamicObject) <= __STDCPP_DEFAULT_NEW_ALIGNMENT__); + +TEST_CASE("camera: in the cab, the sway leaves the view out of a side window level (#414)") { + std::vector vehicle(sizeof(TDynamicObject)); // zeroed + + glm::dvec3 const eye{10.0, 2.0, -5.0}; + // the vehicle heading north-east on level track + auto const ahead{glm::normalize(glm::dvec3{1.0, 0.0, -1.0})}; + glm::dvec3 const left{ahead.z, 0.0, -ahead.x}; // the vehicle's left, flat + + for (auto const head : {-1, 1}) { // turned to the right, to the left + for (auto const roll : {0.1f, -0.15f}) { + CAPTURE(head); + CAPTURE(roll); + + TCamera camera; + camera.Init(eye, {}, reinterpret_cast(vehicle.data())); // NOSONAR see above + camera.LookAt = eye + ahead; + camera.vUp = {0.f, 1.f, 0.f}; + camera.Angle = {0.f, static_cast(head * std::numbers::pi / 2), roll}; + + auto const view{axes(camera)}; + check_equal(view.eye, eye); + // out of the window to the left or the right, still level, whatever the sway (the yaw is a float, a hair + // off a right angle) + auto const yaw{static_cast(camera.Angle.y)}; + check_equal(view.forward, std::sin(yaw) * left + std::cos(yaw) * ahead); + CHECK(glm::dot(view.forward, static_cast(head) * left) == doctest::Approx(1.0).epsilon(1e-6)); + // the sway tilts the view about that line by its angle + CHECK(glm::dot(view.up, view.forward) == doctest::Approx(0.0).epsilon(1e-9)); + CHECK(view.up.y == doctest::Approx(std::cos(static_cast(roll))).epsilon(1e-9)); + } + } +} From d7b4238bb84b8980fd4b4bd4b640746df36bc9e8 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 05:14:41 +0100 Subject: [PATCH 07/27] test(scenarios): the L053 poranek cases now fail on the station's SM42 (#477) * test(scenarios): the L053 poranek cases now fail on the station's SM42 #409 fixed what both l053_poranek_tme222158_debica cases were marked xfail for: the EP07 on Tm4 stops at the checkpoint, and the ET21 no longer stands off the wire at Debica Towarowa. Run on staging f15ea405, neither passes yet: TME222158 gets to Debica and reports there, but the station's SM42-1096, ordered to uncouple at step 10 of deb_sm42_stat, pushes its cut past debica_k_sem_info at danger and never gets the coupler off, so the station never gives TME222158 step 1 and both runs end as a standstill (4347 s and 4576 s of simulation time). The xfail marks stay, with that reason. * test(scenarios): the README table names the staging run of the L053 poranek rows --- tests/scenarios/README.md | 7 ++++--- tests/scenarios/cases/l053_poranek_tme222158_debica.json | 2 +- .../cases/l053_poranek_tme222158_debica_et21.json | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/scenarios/README.md b/tests/scenarios/README.md index 321b65479..2638272c7 100644 --- a/tests/scenarios/README.md +++ b/tests/scenarios/README.md @@ -399,15 +399,16 @@ track it stands on). The first of them may be the one to couple (`Shunt -2 -3`): first order is `Connect` releases the hand brake a cold locomotive starts with (`eu07_td_cold_connect`). The mission trains of velocity 0.1 wait for their signal and need nothing. -The cases and what they showed on master of 2026-11-11: +The cases and what they showed on master of 2026-11-11 (the two L053 poranek rows also on +staging f15ea405 of 2026-11-23): | case | report | result | | --- | --- | --- | | `wrzosy_pxe336080_couples` | #524 | passes: ordered to, the locomotive couples to the rake (`couples`, 262 s) and takes it out of the depot (696 s). The scenery itself gives no such order | | `baltyk_skm1_roj55324_shunting_signal` | #525 | passes, with four seeds: the unit on the siding is let into the platforms 4 minutes after the start, once the shunter beside it has done its first moves, and leaves at 10:42 | | `baltyk_skm1_roj55321_departure` | #525 | passes, with three seeds: the unit in the platform leaves at 10:34 | -| `l053_poranek_tme222158_debica` | #421 | `xfail`: the train is never let into Debica, the station jams 4 minutes after the start: the AI of EP07-338'16 passes the shunting signal Tm4 at stop at 29 km/h and stops 20 m beyond the checkpoint the station waits for it at | -| `l053_poranek_tme222158_debica_et21` | #421 | `xfail`: with an ET21, as in the report, the locomotive stops for good at Debica Towarowa: running round the wagons it stands on the headshunt 20 m past the end of the overhead wire, and its driver never gets out of `Prepare_engine` | +| `l053_poranek_tme222158_debica` | #421 | `xfail`: on master of 2026-11-11 the station jammed 4 minutes after the start, the AI of EP07-338'16 passed the shunting signal Tm4 at stop at 29 km/h. Since #409 (staging f15ea405, 2026-11-23) the EP07 stops at the checkpoint and TME222158 gets to Debica, but the station's SM42-1096 jams it: ordered to uncouple at step 10 of `deb_sm42_stat` it pushes its cut past `debica_k_sem_info` at danger and never gets the coupler off, so the station never sends TME222158 on | +| `l053_poranek_tme222158_debica_et21` | #421 | `xfail`: on master of 2026-11-11, with an ET21 as in the report, the locomotive stopped for good at Debica Towarowa, on the headshunt 20 m past the end of the overhead wire, and its driver never got out of `Prepare_engine`. Since #409 (staging f15ea405) the ET21 gets through Debica Towarowa (steps 1-5 of `dt_tme222158_stat`) to Debica, then fails on the SM42 as `l053_poranek_tme222158_debica` does | | `l053_poludnie_roj32134_debica` | #506 | passes: both trains run and the unit ends at Debica after 6134 s; no train in its way | In the L053 sceneries the test mode logs a signal passed at danger for several shunting diff --git a/tests/scenarios/cases/l053_poranek_tme222158_debica.json b/tests/scenarios/cases/l053_poranek_tme222158_debica.json index 6fbc141e7..cba4a9830 100644 --- a/tests/scenarios/cases/l053_poranek_tme222158_debica.json +++ b/tests/scenarios/cases/l053_poranek_tme222158_debica.json @@ -10,7 +10,7 @@ "reason": "tme222158_got_the_exit_signal_at_debica" }, "slow": true, - "xfail": "eu07/maszyna#421 is not reached: with every train driven by AI Debica jams 4 minutes after the start, the AI of EP07-338'16 passes the shunting signal Tm4 at stop at 29 km/h and stops 20 m beyond the checkpoint before it (tor1834:event0), so RPE23113 never reports there and TME222158 is never let into the station", + "xfail": "eu07/maszyna#421 is not reached, the station's SM42 jams Debica: since #409 EP07-338'16 stops at the checkpoint before Tm4 (tor1834:event0) and TME222158 is let in and reports at Debica (deb_tme222158_stat c 0), but SM42-1096, ordered to uncouple at step 10 of deb_sm42_stat, pushes its cut past debica_k_sem_info at danger and never gets the coupler off (\"Uncoupling [sm42-1096]: actuating and compressing buffers... from front\" for the rest of the run), so it never does step 11 and the station never gives TME222158 step 1: standstill after 4347 s", "physicslog": false, "ini": [ "file.binary.terrain no" diff --git a/tests/scenarios/cases/l053_poranek_tme222158_debica_et21.json b/tests/scenarios/cases/l053_poranek_tme222158_debica_et21.json index 4f169fea7..62785a518 100644 --- a/tests/scenarios/cases/l053_poranek_tme222158_debica_et21.json +++ b/tests/scenarios/cases/l053_poranek_tme222158_debica_et21.json @@ -16,7 +16,7 @@ "reason": "tme222158_got_the_exit_signal_at_debica" }, "slow": true, - "xfail": "eu07/maszyna#421: the ET21 stands for good at Debica Towarowa with the shunting signal at Ms2. Running round the wagons it stops on the headshunt 20 m past the end of the overhead wire (the wire ends at z 4804 over tor2466, the locomotive stands at z 4786), loses power, and its driver never gets out of Prepare_engine; the ET22 the scenery has there now gets through", + "xfail": "eu07/maszyna#421 is not reached, the station's SM42 jams Debica, as in l053_poranek_tme222158_debica: since #409 the ET21 no longer stands off the wire at Debica Towarowa, it gets through steps 1-5 of dt_tme222158_stat, takes the wagons to Debica and reports there (deb_tme222158_stat c 0), but SM42-1096, ordered to uncouple at step 10 of deb_sm42_stat, pushes its cut past debica_k_sem_info at danger and never gets the coupler off (\"Uncoupling [sm42-1096]: actuating and compressing buffers... from front\" for the rest of the run), so it never does step 11 and the station never gives TME222158 step 1: standstill after 4576 s", "physicslog": false, "ini": [ "file.binary.terrain no" From 02c4c8169493dd5f0aabc96fc3cff47898c2daee Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 05:14:50 +0100 Subject: [PATCH 08/27] refactor: the line breaker state as an enum class, fcfuH without the text round trip (L16) (#478) * refactor(cab): the cab's state of the line breaker is an enum class TTrain::m_linebreakerstate kept 0, 1 and 2 for open, closed and closing (the closing control held long enough). It is linebreaker::state now, which linebreaker::pressed() takes too; every comparison and assignment names the state. Nothing writes the state out: it isn't in the Python dictionary of the cab, the black box, the physics log or the network. No change in behaviour (eu07/maszyna#148). * refactor(physics): fcfuH takes fcfu without writing it out and reading it back A definition of an induction motor drive without fcfuH gave the dynamic brake fcfu through text: std::to_string() of the value as the default of extract_value(). The loader assigns it now. For any figure of up to six decimals the value is the same to the bit (the test compares both ways over more than 70000 figures, and through the loader); the game's definitions have one or two. Only a figure of more than six decimals, which the text rounded to six, or one past the largest value, which read back as 0 from "inf", gives another; the test pins both (eu07/maszyna#99). --- McZapkie/Mover.cpp | 6 +- tests/unit/test_fcfuh_default.cpp | 153 ++++++++++++++++++++++++++++++ tests/unit/test_linebreaker.cpp | 37 ++++---- vehicle/Train.cpp | 42 ++++---- vehicle/Train.h | 3 +- vehicle/linebreaker.cpp | 6 +- vehicle/linebreaker.h | 17 +++- 7 files changed, 215 insertions(+), 49 deletions(-) create mode 100644 tests/unit/test_fcfuh_default.cpp diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index b1735d0c5..5143b359a 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -13759,7 +13759,11 @@ void TMoverParameters::LoadFIZ_EngineInductionMotor(std::string const &Input) extract_value(eimc[eimc_f_DU], "DU", Input, ""); extract_value(eimc[eimc_f_I0], "I0", Input, ""); extract_value(eimc[eimc_f_cfu], "fcfu", Input, ""); - extract_value(eimc[eimc_f_cfuH], "fcfuH", Input, std::to_string(eimc[eimc_f_cfu])); + if (false == extract_value(eimc[eimc_f_cfuH], "fcfuH", Input, "")) + { + // without its own figure the dynamic brake takes the one of the traction + eimc[eimc_f_cfuH] = eimc[eimc_f_cfu]; + } extract_value(eimc[eimc_p_F0], "F0", Input, ""); extract_value(eimc[eimc_p_a1], "a1", Input, ""); extract_value(eimc[eimc_p_Pmax], "Pmax", Input, ""); diff --git a/tests/unit/test_fcfuh_default.cpp b/tests/unit/test_fcfuh_default.cpp new file mode 100644 index 000000000..437164060 --- /dev/null +++ b/tests/unit/test_fcfuh_default.cpp @@ -0,0 +1,153 @@ +#include "stdafx.h" +#include "doctest.h" +#include "vehicle.h" +#include "utilities/utilities.h" + +#include +#include +#include +#include +#include +#include + +using test::definition; +using test::vehicle; + +// the figure of the voltage by the frequency of an induction motor drive in the dynamic brake (fcfuH) takes the +// one of the traction (fcfu) when the definition has none. the loader took it by writing fcfu out with +// std::to_string() and reading the text back as the default of fcfuH (eu07/maszyna#99); it assigns it now + +namespace { + +// a figure read from a line the way TMoverParameters::LoadFIZ_EngineInductionMotor() reads fcfu +double read_fcfu(std::string const &Text) { + double fcfu{0.0}; + extract_value(fcfu, "fcfu", "fcfu=" + Text, ""); + return fcfu; +} + +// fcfuH missing, the way the loader took it before: the figure written out with six decimals in the C locale +// (the game never sets another) and read back +double fcfuh_before(double const Fcfu) { + double fcfuh{-1.0}; + extract_value(fcfuh, "fcfuH", "", std::to_string(Fcfu)); + return fcfuh; +} + +// the bits of the value, which tell -0.0 from 0.0 too +std::uint64_t bits(double const Value) { + std::uint64_t result; + std::memcpy(&result, &Value, sizeof(result)); + return result; +} + +// the value with all its digits, for the message +std::string exact(double const Value) { + char text[64]; + std::snprintf(text, sizeof(text), "%.17g", Value); + return text; +} + +// a generator of its own (splitmix64), for the same numbers on every platform +struct numbers { + std::uint64_t state{0x2545f4914f6cdd1dull}; + std::uint64_t next() { + auto value{state += 0x9e3779b97f4a7c15ull}; + value = (value ^ (value >> 30)) * 0xbf58476d1ce4e5b9ull; + value = (value ^ (value >> 27)) * 0x94d049bb133111ebull; + return value ^ (value >> 31); + } +}; + +// the decimal text of Integer / 10^Decimals, as a definition could hold it +std::string decimal(std::uint64_t const Integer, int const Decimals, bool const Negative) { + auto digits{std::to_string(Integer)}; + if (Decimals > 0) { + if (digits.size() <= static_cast(Decimals)) { + digits.insert(0, Decimals + 1 - digits.size(), '0'); + } + digits.insert(digits.size() - Decimals, "."); + } + return (Negative ? "-" : "") + digits; +} + +} // namespace + +TEST_CASE("fcfuH: the figure of the traction is the same, assigned or written out and read back, for every figure of up to six decimals") { + // any decimal figure of up to six decimals: the value read from it lies within half a millionth of it, so + // std::to_string() writes the figure itself and the text reads back to the very same value. checked over the + // figures the game's definitions use (33.5 to 81.5) and the ones around them, and over many others, of up + // to six decimals and up to 18 digits, of either sign + auto compared{0}; + auto const check{[&](std::string const &Text) { + auto const fcfu{read_fcfu(Text)}; + auto const before{fcfuh_before(fcfu)}; + if (bits(before) != bits(fcfu)) { + FAIL_CHECK("fcfu=" << Text << " was " << exact(before) << " as fcfuH, now " << exact(fcfu)); + } + ++compared; + }}; + // every figure of up to two decimals, from -10 to 200 + for (auto hundredths{-1000}; hundredths <= 20000; ++hundredths) { + check(decimal(static_cast(std::abs(hundredths)), 2, hundredths < 0)); + } + // every figure of up to six decimals around the ones of the game's definitions + for (auto const figure : {33.5, 40.1, 43.7, 45.18, 46.8, 47.6, 48.9, 49.0, 81.5}) { + auto const millionths{static_cast(figure * 1e6 + 0.5)}; + for (auto offset{-2000}; offset <= 2000; ++offset) { + check(decimal(static_cast(millionths + offset), 6, false)); + } + } + // figures of 0 to 6 decimals and 1 to 18 digits + numbers random; + for (auto decimals{0}; decimals <= 6; ++decimals) { + for (auto digits{1}; digits <= 18; ++digits) { + std::uint64_t limit{1}; + for (auto digit{0}; digit < digits; ++digit) { + limit *= 10; + } + for (auto sample{0}; sample < 400; ++sample) { + check(decimal(random.next() % limit, decimals, (sample & 1) != 0)); + } + } + } + // the way of writing it doesn't matter, only the value + for (auto const text : {"4.76e1", "47.60", "+47.6", "0047.6", "476e-1", "0", "-0", "1e15", "-1e-6", "1e300"}) { + check(text); + } + // nor does a figure the stream can't read, which reads as 0 + for (auto const text : {"abc", "-", "x47.6"}) { + check(text); + } + CHECK(compared > 70000); +} + +TEST_CASE("fcfuH: where the two ways part, figures no definition has") { + // no definition of the game has such a figure (they have one or two decimals, from 33.5 to 81.5). more than + // six decimals: std::to_string() rounded the value to six, the figure is taken as it's written now + CHECK(fcfuh_before(read_fcfu("0.1234567")) == read_fcfu("0.123457")); + CHECK(fcfuh_before(read_fcfu("1e-7")) == 0.0); + CHECK(read_fcfu("1e-7") == 1e-7); + // a figure past the largest value reads as infinite (with MSVC; the largest value with GCC): written out it + // was "inf", which the stream doesn't read, so the dynamic brake got 0 where it gets the traction's figure now + auto const huge{read_fcfu("1e999")}; + CHECK(huge > 1e300); + if (std::isinf(huge)) { + CHECK(fcfuh_before(huge) == 0.0); + } +} + +TEST_CASE("fcfuH: the loader gives the dynamic brake the traction's figure when the definition has none") { + for (auto const fcfu : {"43.7", "45.18", "49", "0.000001", "1e2"}) { + CAPTURE(fcfu); + // the EU47's definition has fcfu only + vehicle eu47{definition::fiz("e186_v2/eu47").set("Engine", "fcfu", fcfu)}; + CHECK(eu47->eimc[eimc_f_cfu] == read_fcfu(fcfu)); + CHECK(bits(eu47->eimc[eimc_f_cfuH]) == bits(eu47->eimc[eimc_f_cfu])); + CHECK(bits(eu47->eimc[eimc_f_cfuH]) == bits(fcfuh_before(read_fcfu(fcfu)))); + // its own figure is kept + vehicle own{definition::fiz("e186_v2/eu47").set("Engine", "fcfu", fcfu).set("Engine", "fcfuH", "40.1")}; + CHECK(own->eimc[eimc_f_cfu] == read_fcfu(fcfu)); + CHECK(own->eimc[eimc_f_cfuH] == read_fcfu("40.1")); + } +} diff --git a/tests/unit/test_linebreaker.cpp b/tests/unit/test_linebreaker.cpp index 126e3307c..9b36b817f 100644 --- a/tests/unit/test_linebreaker.cpp +++ b/tests/unit/test_linebreaker.cpp @@ -9,6 +9,7 @@ using test::consist; using test::definition; +using linebreaker::state; namespace { @@ -16,7 +17,7 @@ namespace { // the cab keeps of the line breaker follows the vehicle, the breaker closes while the lever is on and can close struct lever { TMoverParameters &mover; - int breaker{0}; // as TTrain::m_linebreakerstate: 0 open, 1 closed + state breaker{state::open}; // as TTrain::m_linebreakerstate bool on{false}; void press() { @@ -26,8 +27,8 @@ struct lever { break; case linebreaker::toggle::open: on = false; - if (breaker == 1 && mover.MainSwitch(false)) { - breaker = 0; + if (breaker == state::closed && mover.MainSwitch(false)) { + breaker = state::open; } break; default: @@ -36,14 +37,14 @@ struct lever { } // TTrain::Update() void update() { - if (breaker == 0 && mover.Mains) { - breaker = 1; + if (breaker == state::open && mover.Mains) { + breaker = state::closed; } - if (breaker == 1 && false == mover.Mains) { - breaker = 0; + if (breaker == state::closed && false == mover.Mains) { + breaker = state::open; } - if (on && breaker == 0 && mover.MainSwitchCheck()) { - breaker = mover.MainSwitch(true) ? 1 : 0; + if (on && breaker == state::open && mover.MainSwitchCheck()) { + breaker = mover.MainSwitch(true) ? state::closed : state::open; } } }; @@ -53,15 +54,15 @@ struct lever { TEST_CASE("line breaker: a press of the toggle closes an open breaker and opens a closed one") { using enum linebreaker::toggle; for (auto const latching : {false, true}) { - CHECK(linebreaker::pressed(0, latching, false) == close); - CHECK(linebreaker::pressed(1, latching, true) == open); - CHECK(linebreaker::pressed(1, latching, false) == open); + CHECK(linebreaker::pressed(state::open, latching, false) == close); + CHECK(linebreaker::pressed(state::closed, latching, true) == open); + CHECK(linebreaker::pressed(state::closed, latching, false) == open); // freshly closed, the cab finishes closing it first - CHECK(linebreaker::pressed(2, latching, true) == none); + CHECK(linebreaker::pressed(state::closing, latching, true) == none); } // a lever left on over an open breaker goes off; push buttons have no position to keep - CHECK(linebreaker::pressed(0, true, true) == open); - CHECK(linebreaker::pressed(0, false, true) == close); + CHECK(linebreaker::pressed(state::open, true, true) == open); + CHECK(linebreaker::pressed(state::open, false, true) == close); } TEST_CASE("line breaker: the EP05's lever goes off with the converter overload relay tripped (eu07/maszyna#394)") { @@ -72,7 +73,7 @@ TEST_CASE("line breaker: the EP05's lever goes off with the converter overload r REQUIRE(test::start_up(driver, line)); REQUIRE(ep05.Mains); REQUIRE(ep05.ConverterFlag); - lever ws{ep05, 1, true}; + lever ws{ep05, state::closed, true}; // the converter overload relay knocks the line breaker out, as the cab does it when the converter is // switched on together with the compressor; the lever stays on @@ -80,7 +81,7 @@ TEST_CASE("line breaker: the EP05's lever goes off with the converter overload r ep05.MainSwitch(false, range_t::local); ws.update(); REQUIRE_FALSE(ep05.Mains); - REQUIRE(ws.breaker == 0); + REQUIRE(ws.breaker == state::open); CHECK(ws.on); // with the relay tripped the breaker doesn't close test::drive(driver, line, 5.0); @@ -106,7 +107,7 @@ TEST_CASE("line breaker: the EP05's lever goes off with the converter overload r ws.press(); ws.update(); CHECK(ep05.Mains); - CHECK(ws.breaker == 1); + CHECK(ws.breaker == state::closed); // and the next press opens it ws.press(); CHECK_FALSE(ws.on); diff --git a/vehicle/Train.cpp b/vehicle/Train.cpp index 8bf948096..3f2cbebae 100644 --- a/vehicle/Train.cpp +++ b/vehicle/Train.cpp @@ -3748,7 +3748,7 @@ void TTrain::OnCommand_linebreakertoggle(TTrain *Train, command_data const &Comm { // only impulse switches react to release events // NOTE: we presume dedicated state switch is of impulse type - if (Train->m_linebreakerstate == 0) + if (Train->m_linebreakerstate == linebreaker::state::open) { // ...after opening circuit, or holding for too short time to close it OnCommand_linebreakeropen(Train, Command); @@ -3801,14 +3801,14 @@ void TTrain::OnCommand_linebreakeropen(TTrain *Train, command_data const &Comman // play sound immediately when the switch is hit, not after release Train->fMainRelayTimer = 0.0f; - if (Train->m_linebreakerstate == 0) + if (Train->m_linebreakerstate == linebreaker::state::open) { return; } // already in the desired state if (true == Train->mvControlled->MainSwitch(false, Train->mvControlled->MainSwitchRange())) { - Train->m_linebreakerstate = 0; + Train->m_linebreakerstate = linebreaker::state::open; if (Train->mvControlled->MainSwitchRange() != range_t::local) { // the engines of the vehicles in multiple stopped along: their two-state switches go off too, left on @@ -3883,7 +3883,7 @@ void TTrain::OnCommand_linebreakerclose(TTrain *Train, command_data const &Comma Train->ggMainButton.UpdateValue(0.5, Train->dsbSwitch); } - if (Train->m_linebreakerstate == 1) + if (Train->m_linebreakerstate == linebreaker::state::closed) { return; } // already in the desired state @@ -3891,10 +3891,10 @@ void TTrain::OnCommand_linebreakerclose(TTrain *Train, command_data const &Comma // we don't need to start the diesel twice, but the other types (with impulse switch setup) still need to be launched // NOTE: this behaviour should depend on MainOnButton presence and type_delayed // TODO: change it when/if vehicle definition files get their proper switch types - if (Train->m_linebreakerstate == 2 && Train->mvControlled->EngineType == TEngineType::ElectricSeriesMotor) + if (Train->m_linebreakerstate == linebreaker::state::closing && Train->mvControlled->EngineType == TEngineType::ElectricSeriesMotor) { // try to finalize state change of the line breaker, set the state based on the outcome - Train->m_linebreakerstate = Train->mvControlled->MainSwitch(true, Train->mvControlled->MainSwitchRange()) ? 1 : 0; + Train->m_linebreakerstate = Train->mvControlled->MainSwitch(true, Train->mvControlled->MainSwitchRange()) ? linebreaker::state::closed : linebreaker::state::open; } // on button release reset the closing timer Train->fMainRelayTimer = 0.0f; @@ -8762,16 +8762,16 @@ bool TTrain::Update(double const Deltatime) { // train state update // line breaker: - if (m_linebreakerstate == 0 && true == mvControlled->Mains) + if (m_linebreakerstate == linebreaker::state::open && true == mvControlled->Mains) { // crude way to sync state of the linebreaker with ai-issued commands - m_linebreakerstate = 1; + m_linebreakerstate = linebreaker::state::closed; } - if (m_linebreakerstate == 1 && false == (mvControlled->Mains || mvControlled->dizel_startup)) + if (m_linebreakerstate == linebreaker::state::closed && false == (mvControlled->Mains || mvControlled->dizel_startup)) { // crude way to catch cases where the main was knocked out // because the state of the line breaker isn't changed to match, we need to do it here manually - m_linebreakerstate = 0; + m_linebreakerstate = linebreaker::state::open; } if (is_hold_coil_lever(ggMainOffButton) && hold_coil_lever::cuts_off(ggMainOffButton.GetDesiredValue())) { @@ -8781,10 +8781,10 @@ bool TTrain::Update(double const Deltatime) // put the lever back on to match, like the line breaker state above ggMainOffButton.UpdateValue(0.0); } - else if (m_linebreakerstate == 2) + else if (m_linebreakerstate == linebreaker::state::closing) { // the hold coil was cut off while the closing button was held, the line breaker won't close on its release - m_linebreakerstate = 0; + m_linebreakerstate = linebreaker::state::open; } } @@ -8808,18 +8808,18 @@ bool TTrain::Update(double const Deltatime) // if the button disconnecting the line breaker is down prevent the timer from accumulating fMainRelayTimer = 0.0f; } - if (m_linebreakerstate == 0 && fMainRelayTimer > mvControlled->InitialCtrlDelay) + if (m_linebreakerstate == linebreaker::state::open && fMainRelayTimer > mvControlled->InitialCtrlDelay) { // wlaczanie WSa z opoznieniem // mark the line breaker as ready to close; for electric series vehicles with impulse switch the setup is completed on button release - m_linebreakerstate = 2; + m_linebreakerstate = linebreaker::state::closing; } // for diesels and/or vehicles with toggle switch setup we complete the engine start here // TODO: make it a test for main_on_bt of type push_delayed instead - if (m_linebreakerstate == 2 && (ggMainOnButton.SubModel == nullptr || mvControlled->EngineType != TEngineType::ElectricSeriesMotor)) + if (m_linebreakerstate == linebreaker::state::closing && (ggMainOnButton.SubModel == nullptr || mvControlled->EngineType != TEngineType::ElectricSeriesMotor)) { // try to finalize state change of the line breaker, set the state based on the outcome - m_linebreakerstate = mvControlled->MainSwitch(true, mvControlled->MainSwitchRange()) ? 1 : 0; + m_linebreakerstate = mvControlled->MainSwitch(true, mvControlled->MainSwitchRange()) ? linebreaker::state::closed : linebreaker::state::open; } // the switches of the other vehicles in multiple update_remote_linebreakers(Deltatime); @@ -9393,10 +9393,10 @@ bool TTrain::Update(double const Deltatime) btLampkaSHP.Turn(mvOccupied->SecuritySystem.is_cabsignal_blinking()); btLampkaCzuwakaSHP.Turn(btLampkaSHP.GetValue() || btLampkaCzuwaka.GetValue()); - btLampkaWylSzybki.Turn(m_linebreakerstate == 2 || mvControlled->Mains); - btLampkaWylSzybkiOff.Turn(m_linebreakerstate != 2 && !mvControlled->Mains); - btLampkaMainBreakerReady.Turn(mvControlled->MainsInitTimeCountdown <= 0.0 && m_linebreakerstate != 2 && !mvControlled->Mains); - btLampkaMainBreakerBlinkingIfReady.Turn(m_linebreakerstate == 2 || mvControlled->Mains || mvControlled->MainsInitTimeCountdown < 0.0 && simulation::Time.data().wMilliseconds > 500); + btLampkaWylSzybki.Turn(m_linebreakerstate == linebreaker::state::closing || mvControlled->Mains); + btLampkaWylSzybkiOff.Turn(m_linebreakerstate != linebreaker::state::closing && !mvControlled->Mains); + btLampkaMainBreakerReady.Turn(mvControlled->MainsInitTimeCountdown <= 0.0 && m_linebreakerstate != linebreaker::state::closing && !mvControlled->Mains); + btLampkaMainBreakerBlinkingIfReady.Turn(m_linebreakerstate == linebreaker::state::closing || mvControlled->Mains || mvControlled->MainsInitTimeCountdown < 0.0 && simulation::Time.data().wMilliseconds > 500); btLampkaPrzetw.Turn(mvOccupied->Power110vIsAvailable); btLampkaPrzetwOff.Turn(!mvOccupied->Power110vIsAvailable); @@ -11808,7 +11808,7 @@ void TTrain::set_cab_controls(int const Cab) // line breaker if (ggMainButton.SubModel != nullptr) { // instead of single main button there can be on/off pair - ggMainButton.PutValue(ggMainButton.type() == TGaugeType::push ? 0.5f : m_linebreakerstate > 0 ? 1.f : 0.f); + ggMainButton.PutValue(ggMainButton.type() == TGaugeType::push ? 0.5f : m_linebreakerstate != linebreaker::state::open ? 1.f : 0.f); } // line breakers of the other vehicles in multiple for (std::size_t index = 0; index < m_remotelinebreakers.size(); ++index) diff --git a/vehicle/Train.h b/vehicle/Train.h index e6cc0f3ba..c079c3f18 100644 --- a/vehicle/Train.h +++ b/vehicle/Train.h @@ -15,6 +15,7 @@ http://mozilla.org/MPL/2.0/. #include "vehicle/Button.h" #include "vehicle/Gauge.h" #include "vehicle/enginestart.h" +#include "vehicle/linebreaker.h" #include "audio/sound.h" #include "scripting/PyInt.h" #include "input/command.h" @@ -553,7 +554,7 @@ class TTrain { TMoverParameters *mvThird { nullptr }; // trzeci człon (SN61) TMoverParameters *mvPantographUnit { nullptr }; // nearest pantograph equipped unit // helper variable, to prevent immediate switch between closing and opening line breaker circuit - int m_linebreakerstate { 0 }; // 0: open, 1: closed, 2: freshly closed (and yes this is awful way to go about it) + linebreaker::state m_linebreakerstate { linebreaker::state::open }; static const commandhandler_map m_commandhandlers; control_mapper m_controlmapper; diff --git a/vehicle/linebreaker.cpp b/vehicle/linebreaker.cpp index 97eae0325..cc9b2f008 100644 --- a/vehicle/linebreaker.cpp +++ b/vehicle/linebreaker.cpp @@ -12,11 +12,11 @@ http://mozilla.org/MPL/2.0/. namespace linebreaker { -toggle pressed(int const Breakerstate, bool const Latchinglever, bool const Leveron) { - if (Breakerstate == 1) { +toggle pressed(state const Breakerstate, bool const Latchinglever, bool const Leveron) { + if (Breakerstate == state::closed) { return toggle::open; } - if (Breakerstate != 0) { + if (Breakerstate != state::open) { return toggle::none; } // the line breaker is open; a lever left on goes off first diff --git a/vehicle/linebreaker.h b/vehicle/linebreaker.h index 370e992cc..e87312dd1 100644 --- a/vehicle/linebreaker.h +++ b/vehicle/linebreaker.h @@ -12,6 +12,13 @@ http://mozilla.org/MPL/2.0/. // the line breaker (main switch, WS) controls of the cab namespace linebreaker { +// the state the cab keeps of the line breaker, besides the vehicle's own (TMoverParameters::Mains) +enum class state : int { + open, + closed, + closing // the closing control was held long enough; the line breaker closes when it's released, or right away +}; + enum class toggle : int { none, // the press does nothing close, // the control goes to its on position, and the line breaker closes if it can @@ -19,10 +26,10 @@ enum class toggle : int { }; // what a press of the line breaker toggle does. Breakerstate is the state the cab keeps of the line -// breaker (0: open, 1: closed, 2: freshly closed). Latchinglever is a single two-state switch which -// stays where it was put, Leveron that it stands in its on position. such a lever doesn't follow the -// line breaker: knocked out (by the converter overload relay, say) the breaker opens with the lever -// left on, and the lever has to go off before it can be put on again (eu07/maszyna#394) -toggle pressed(int Breakerstate, bool Latchinglever, bool Leveron); +// breaker. Latchinglever is a single two-state switch which stays where it was put, Leveron that it +// stands in its on position. such a lever doesn't follow the line breaker: knocked out (by the converter +// overload relay, say) the breaker opens with the lever left on, and the lever has to go off before it +// can be put on again (eu07/maszyna#394) +toggle pressed(state Breakerstate, bool Latchinglever, bool Leveron); } // namespace linebreaker From d3e6736f788918e0cfc0f4124aa6a2bf0c0df11d Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 05:15:02 +0100 Subject: [PATCH 09/27] fix(ai): the braking margin ends once the independent brake is on (#479) * fix(ai): the braking margin ends once the independent brake is on The braking curve outside the final approach keeps the room the brake takes to fill only while the brake is still to be applied. It took the train brake handle past running as the only sign that the brake was on. A vehicle that runs alone, a light locomotive or a railcar such as the SN61, brakes with its independent brake and leaves the handle in running, so the margin never ended for it: on every look it planned to stop short by the distance the brake takes to fill, slowed down too early, released, braked again, and crawled the last tens of metres to a W4 or a signal at stop. This followed #264 and #297. The independent brake now counts as well (braking_curve::brake_acting, LocalBrakePosA above 0). On td.scn the light EU07 reaches the W4 of Przystanek 6.6 s sooner and covers the last 100 m in 20.3 s instead of 26.3 s; on a 20 per mille downgrade it reaches a signal at stop 11.7 s sooner (last 100 m in 20.6 s instead of 31.7 s), with 3 applications of the independent brake in the last 300 m instead of 5. A train braking with the train brake runs as before (its physicslog is the same byte for byte). * test(scenarios): light locomotive, railcar and train stopping down a 20 per mille gradient The *_td_downgrade_w4_signal cases run on a line the fragment adds beside td.scn: 300 m level, then 3000 m down a gradient of 20 per mille under a wire fed by a substation of its own. The train stops at the W4 of Dol 1500 m down the gradient and then before a signal at stop 1100 m further down. They run with a light EU07 and an SN61 alone, which brake with the independent brake, and with an EU07 and three coaches, which brakes with the train brake. eu07_coaches_td_timetable is that train on the td/rozklad timetable to Przystanek. They show the approach to a stop: before the previous commit the light EU07 needed 31.7 s for the last 100 m to the signal, now 20.6 s; the train with coaches runs the same in both. * fix(ai): the braking margin counts the independent brake only on a vehicle that has one * test(scenarios): the light EU07 and the SN61 stop at the signal down the gradient in time --- tests/scenarios/README.md | 18 +- .../eu07_coaches_td_downgrade_w4_signal.json | 42 ++ .../cases/eu07_coaches_td_timetable.json | 40 ++ .../cases/eu07_td_downgrade_w4_signal.json | 47 ++ .../cases/sn61_td_downgrade_w4_signal.json | 47 ++ tests/scenarios/cases/td_downgrade.txt | 20 + .../cases/td_downgrade_w4_signal.scn | 518 ++++++++++++++++++ tests/scenarios/run.py | 21 +- tests/unit/test_braking_curve.cpp | 35 ++ vehicle/Driver.cpp | 10 +- vehicle/brakingcurve.cpp | 4 + vehicle/brakingcurve.h | 8 +- 12 files changed, 803 insertions(+), 7 deletions(-) create mode 100644 tests/scenarios/cases/eu07_coaches_td_downgrade_w4_signal.json create mode 100644 tests/scenarios/cases/eu07_coaches_td_timetable.json create mode 100644 tests/scenarios/cases/eu07_td_downgrade_w4_signal.json create mode 100644 tests/scenarios/cases/sn61_td_downgrade_w4_signal.json create mode 100644 tests/scenarios/cases/td_downgrade.txt create mode 100644 tests/scenarios/cases/td_downgrade_w4_signal.scn diff --git a/tests/scenarios/README.md b/tests/scenarios/README.md index 2638272c7..bf5467018 100644 --- a/tests/scenarios/README.md +++ b/tests/scenarios/README.md @@ -254,6 +254,16 @@ the td/rozklad train, an EU07 with three coaches, with its head 80 m past the W4 under the consist, behind the head, and the driver still counts Stacja1 and leaves at 10:35, since the scan of the route begins at the last vehicle and keeps a W4 behind the head. +`eu07_coaches_td_timetable` is the timetable case with the EU07 and three coaches, a train that brakes with the train +brake, beside the light EU07 and the SN61 alone, which brake with the independent brake. The `*_td_downgrade_w4_signal` +cases (fragment `td_downgrade_w4_signal.scn`, timetable `td_downgrade.txt`) run on a line the fragment adds beside the +tracks of td.scn, at x = -3000: 300 m level, then 3000 m down a gradient of 20 per mille, under an overhead wire fed +by a substation of its own (`gr_pwr`; the wire on the section `pwr01` of td.scn gave the EU07 no voltage). The train +starts on the level at the W4 of Gora, stops at the W4 of Dol 1500 m down the gradient, leaves at 10:38 and stops before +`gr_sem`, a signal at stop 1100 m further down (a memory cell with `SetVelocity 0 0` and the event that reads it, no +model), about 1590 m and 2690 m from the start. The three trains are the light EU07, the SN61 alone and the EU07 with +three coaches. + The `test_mode_*` cases show the ends of the test mode: `test_mode_pass` (exit 0, the pass event), `test_mode_signal_passed_at_danger` (exit 11), `test_mode_timeout` (exit 12, from `test.timeout`), `test_mode_standstill` (exit 13, from `test.standstill`) and @@ -428,9 +438,11 @@ the row instead, logged by builds from this branch on. - `max_speed` `limit`, `tolerance`: never goes faster than `limit + tolerance`. - `brakes` `min_pressure`: after moving off, brake cylinder pressure reaches `min_pressure` bar (physicslog pressures are in bar whatever its header says; the brake pipe runs at 5.0). -- `stops` `moving_speed`, `stop_speed`, `hold`, optional `min_distance`, `max_distance`: after - reaching `moving_speed`, stays at or below `stop_speed` for `hold` seconds; with the distances, - that stop has to be between them (metres travelled, as in `distance`). +- `stops` `moving_speed`, `stop_speed`, `hold`, optional `min_distance`, `max_distance`, `max_time`, + `nth`: after reaching `moving_speed`, stays at or below `stop_speed` for `hold` seconds; with the + distances, that stop has to be between them (metres travelled, as in `distance`), with `max_time` + it has to begin by then (seconds of the physicslog). `nth` (default 1) takes a later stop: each + stop after the first counts once the train has reached `moving_speed` again. - `stays_stopped` `moving_speed`, `stop_speed`: after moving off and stopping, never goes above `stop_speed` again. - `distance` `min`, `max`: total distance travelled. The physicslog has no position, so the diff --git a/tests/scenarios/cases/eu07_coaches_td_downgrade_w4_signal.json b/tests/scenarios/cases/eu07_coaches_td_downgrade_w4_signal.json new file mode 100644 index 000000000..1faae73ff --- /dev/null +++ b/tests/scenarios/cases/eu07_coaches_td_downgrade_w4_signal.json @@ -0,0 +1,42 @@ +{ + "description": "An EU07 with three coaches on the line of eu07_td_downgrade_w4_signal, down a gradient of 20 per mille: stops at the W4 of Dol, then before the signal at stop. A train braking with the train brake, the control of the light EU07 and SN61 cases.", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_downgrade_w4_signal.scn", + "timetable": "td_downgrade.txt", + "vars": { + "consist": [ + "node -1 0 {{vehicle}} dynamic pkp\\4e_v1 4e-004 4e 0 headdriver 3 0 enddynamic", + "node -1 0 {{vehicle}}_c1 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c2 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c3 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 0 0 enddynamic" + ] + }, + "duration": 540, + "timeout": 900, + "checks": [ + { + "type": "starts", + "min_speed": 20, + "within": 150 + }, + { + "type": "max_speed", + "limit": 80, + "tolerance": 3 + }, + { + "type": "stops", + "moving_speed": 20, + "stop_speed": 1.0, + "hold": 20, + "min_distance": 1500, + "max_distance": 1700 + }, + { + "type": "distance", + "min": 2550, + "max": 2750 + } + ] +} diff --git a/tests/scenarios/cases/eu07_coaches_td_timetable.json b/tests/scenarios/cases/eu07_coaches_td_timetable.json new file mode 100644 index 000000000..c8621c3b0 --- /dev/null +++ b/tests/scenarios/cases/eu07_coaches_td_timetable.json @@ -0,0 +1,40 @@ +{ + "description": "EU07 with three coaches on td.scn, AI driver on the td/rozklad timetable: starts from Stacja1, keeps to the speed limit, brakes to a stop at Przystanek with the train brake.", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_timetable.scn", + "vars": { + "consist": [ + "node -1 0 {{vehicle}} dynamic pkp\\4e_v1 4e-004 4e 0 headdriver 3 0 enddynamic", + "node -1 0 {{vehicle}}_c1 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c2 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c3 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 0 0 enddynamic" + ] + }, + "duration": 360, + "timeout": 600, + "checks": [ + { + "type": "starts", + "min_speed": 20, + "within": 150 + }, + { + "type": "max_speed", + "limit": 90, + "tolerance": 3 + }, + { + "type": "brakes", + "min_pressure": 0.5 + }, + { + "type": "stops", + "moving_speed": 20, + "stop_speed": 1.0, + "hold": 0, + "min_distance": 1380, + "max_distance": 1420 + } + ] +} diff --git a/tests/scenarios/cases/eu07_td_downgrade_w4_signal.json b/tests/scenarios/cases/eu07_td_downgrade_w4_signal.json new file mode 100644 index 000000000..e26f6180d --- /dev/null +++ b/tests/scenarios/cases/eu07_td_downgrade_w4_signal.json @@ -0,0 +1,47 @@ +{ + "description": "A light EU07 on a line of its own beside td.scn, down a gradient of 20 per mille on a timetable: stops at the W4 of Dol 1500 m down the gradient, leaves at 10:38 and stops before the signal gr_sem at stop 1100 m further down. The EU07 alone brakes with its independent brake.", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_downgrade_w4_signal.scn", + "timetable": "td_downgrade.txt", + "vars": { + "consist": "node -1 0 {{vehicle}} dynamic pkp\\4e_v1 4e-004 4e 0 headdriver 0 0 enddynamic" + }, + "duration": 540, + "timeout": 900, + "checks": [ + { + "type": "starts", + "min_speed": 20, + "within": 150 + }, + { + "type": "max_speed", + "limit": 80, + "tolerance": 3 + }, + { + "type": "stops", + "moving_speed": 20, + "stop_speed": 1.0, + "hold": 20, + "min_distance": 1500, + "max_distance": 1700 + }, + { + "type": "stops", + "moving_speed": 20, + "stop_speed": 1.0, + "hold": 20, + "min_distance": 2550, + "max_distance": 2750, + "max_time": 355, + "nth": 2 + }, + { + "type": "distance", + "min": 2550, + "max": 2750 + } + ] +} diff --git a/tests/scenarios/cases/sn61_td_downgrade_w4_signal.json b/tests/scenarios/cases/sn61_td_downgrade_w4_signal.json new file mode 100644 index 000000000..033313dc0 --- /dev/null +++ b/tests/scenarios/cases/sn61_td_downgrade_w4_signal.json @@ -0,0 +1,47 @@ +{ + "description": "An SN61 railcar alone on the line of eu07_td_downgrade_w4_signal, down a gradient of 20 per mille: stops at the W4 of Dol, then before the signal at stop. The SN61 alone brakes with its independent brake.", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_downgrade_w4_signal.scn", + "timetable": "td_downgrade.txt", + "vars": { + "consist": "node -1 0 {{vehicle}} dynamic pkp\\sn61_v2 SN61-13 SN61_v1 0 headdriver 0 0 enddynamic" + }, + "duration": 540, + "timeout": 900, + "checks": [ + { + "type": "starts", + "min_speed": 20, + "within": 150 + }, + { + "type": "max_speed", + "limit": 80, + "tolerance": 3 + }, + { + "type": "stops", + "moving_speed": 20, + "stop_speed": 1.0, + "hold": 20, + "min_distance": 1500, + "max_distance": 1700 + }, + { + "type": "stops", + "moving_speed": 20, + "stop_speed": 1.0, + "hold": 20, + "min_distance": 2550, + "max_distance": 2750, + "max_time": 366, + "nth": 2 + }, + { + "type": "distance", + "min": 2550, + "max": 2750 + } + ] +} diff --git a/tests/scenarios/cases/td_downgrade.txt b/tests/scenarios/cases/td_downgrade.txt new file mode 100644 index 000000000..ddc50d031 --- /dev/null +++ b/tests/scenarios/cases/td_downgrade.txt @@ -0,0 +1,20 @@ +________________________________________________________________ +[ Rodzaj i numer pociagu | TEST26 ] +[ Kategoria | RO ] +[________________________________________________|______________] +[ | Gora ] +[ Relacja pociagu | Koniec ] +[________________________________________________|______________] +[ Wymagany % ciezaru hamujacego | 88% ] +[________________________________________________|______________] +[ Seria i obciazenie lokomotywy | EU07 210 ] +[________________________________________________|______________] +[ | | Gora 2 | | ] +[ | 80 | R1,L,H,RT,PP 2 10.35 | ] +[ | |----------------------------------1----------|---] +[ | | Dol 1 10.37 | 4 ] +[ |_____| R1,+,L,H,PP 1 10.38 | ] +[ | 80 |----------------------------------1----------|---] +[ | | Koniec 1 10.45 | 7 ] +[ | | R1 1 10.46 | ] +[_______|_____|__________________________________1__________|___] diff --git a/tests/scenarios/cases/td_downgrade_w4_signal.scn b/tests/scenarios/cases/td_downgrade_w4_signal.scn new file mode 100644 index 000000000..ffa43ecc3 --- /dev/null +++ b/tests/scenarios/cases/td_downgrade_w4_signal.scn @@ -0,0 +1,518 @@ +// added by tests/scenarios/run.py to td.scn, whose own trainsets were removed. +// a line of its own, away from the tracks of td.scn: 300 m level, then 3000 m down a gradient of 20 per mille, +// under an overhead wire. +// the train starts on the level, with the W4 of Gora about 40 m ahead, and runs on the timetable {{timetable}}: +// Gora 10:35 -> Dol, a W4 1500 m down the gradient (stop, leaves at 10:38) -> the signal gr_sem, 1100 m further +// down, which stays at stop. the line goes on 400 m past the signal +node -1 0 gr_00 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -200.0 0.0 +0 +endtrack +node -1 0 gr_01 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -100.0 0.0 +0 +endtrack +node -1 0 gr_02 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 0.0 0.0 +0 +event2 gora#1_stopinfo +endtrack +node -1 0 gr_03 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 58.00 100.0 0.0 +0 +endtrack +node -1 0 gr_04 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 58.00 100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 56.00 200.0 0.0 +0 +endtrack +node -1 0 gr_05 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 56.00 200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 54.00 300.0 0.0 +0 +endtrack +node -1 0 gr_06 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 54.00 300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 52.00 400.0 0.0 +0 +endtrack +node -1 0 gr_07 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 52.00 400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 50.00 500.0 0.0 +0 +endtrack +node -1 0 gr_08 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 50.00 500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 48.00 600.0 0.0 +0 +endtrack +node -1 0 gr_09 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 48.00 600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 46.00 700.0 0.0 +0 +endtrack +node -1 0 gr_10 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 46.00 700.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 44.00 800.0 0.0 +0 +endtrack +node -1 0 gr_11 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 44.00 800.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 42.00 900.0 0.0 +0 +endtrack +node -1 0 gr_12 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 42.00 900.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 40.00 1000.0 0.0 +0 +endtrack +node -1 0 gr_13 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 40.00 1000.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 38.00 1100.0 0.0 +0 +endtrack +node -1 0 gr_14 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 38.00 1100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 36.00 1200.0 0.0 +0 +endtrack +node -1 0 gr_15 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 36.00 1200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 34.00 1300.0 0.0 +0 +endtrack +node -1 0 gr_16 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 34.00 1300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 32.00 1400.0 0.0 +0 +endtrack +node -1 0 gr_17 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 32.00 1400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 30.00 1500.0 0.0 +0 +event2 dol#1_stopinfo +endtrack +node -1 0 gr_18 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 30.00 1500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 28.00 1600.0 0.0 +0 +endtrack +node -1 0 gr_19 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 28.00 1600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 26.00 1700.0 0.0 +0 +endtrack +node -1 0 gr_20 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 26.00 1700.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 24.00 1800.0 0.0 +0 +endtrack +node -1 0 gr_21 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 24.00 1800.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 22.00 1900.0 0.0 +0 +endtrack +node -1 0 gr_22 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 22.00 1900.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 20.00 2000.0 0.0 +0 +endtrack +node -1 0 gr_23 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 20.00 2000.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 18.00 2100.0 0.0 +0 +endtrack +node -1 0 gr_24 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 18.00 2100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 16.00 2200.0 0.0 +0 +endtrack +node -1 0 gr_25 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 16.00 2200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 14.00 2300.0 0.0 +0 +endtrack +node -1 0 gr_26 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 14.00 2300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 12.00 2400.0 0.0 +0 +endtrack +node -1 0 gr_27 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 12.00 2400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 10.00 2500.0 0.0 +0 +endtrack +node -1 0 gr_28 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 10.00 2500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 8.00 2600.0 0.0 +0 +event2 gr_sem_info +endtrack +node -1 0 gr_29 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 8.00 2600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 6.00 2700.0 0.0 +0 +endtrack +node -1 0 gr_30 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 6.00 2700.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 4.00 2800.0 0.0 +0 +endtrack +node -1 0 gr_31 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 4.00 2800.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 2.00 2900.0 0.0 +0 +endtrack +node -1 0 gr_32 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 2.00 2900.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 0.00 3000.0 0.0 +0 +endtrack +// the overhead wire along the whole line, as td.scn has it: 5.6 m above the rail, the carrier 1.7 m higher, fed by +// a substation of its own +node -1 0 gr_pwr tractionpowersource -3000.0 60.00 0.0 3400 0 0.01 2000 1.0 3 60.0 end +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -300.0 +-3000.0 65.60 -200.0 +-3000.0 67.30 -300.0 +-3000.0 67.30 -200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -200.0 +-3000.0 65.60 -100.0 +-3000.0 67.30 -200.0 +-3000.0 67.30 -100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -100.0 +-3000.0 65.60 0.0 +-3000.0 67.30 -100.0 +-3000.0 67.30 0.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 0.0 +-3000.0 63.60 100.0 +-3000.0 67.30 0.0 +-3000.0 65.30 100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 63.60 100.0 +-3000.0 61.60 200.0 +-3000.0 65.30 100.0 +-3000.0 63.30 200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 61.60 200.0 +-3000.0 59.60 300.0 +-3000.0 63.30 200.0 +-3000.0 61.30 300.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 59.60 300.0 +-3000.0 57.60 400.0 +-3000.0 61.30 300.0 +-3000.0 59.30 400.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 57.60 400.0 +-3000.0 55.60 500.0 +-3000.0 59.30 400.0 +-3000.0 57.30 500.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 55.60 500.0 +-3000.0 53.60 600.0 +-3000.0 57.30 500.0 +-3000.0 55.30 600.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 53.60 600.0 +-3000.0 51.60 700.0 +-3000.0 55.30 600.0 +-3000.0 53.30 700.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 51.60 700.0 +-3000.0 49.60 800.0 +-3000.0 53.30 700.0 +-3000.0 51.30 800.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 49.60 800.0 +-3000.0 47.60 900.0 +-3000.0 51.30 800.0 +-3000.0 49.30 900.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 47.60 900.0 +-3000.0 45.60 1000.0 +-3000.0 49.30 900.0 +-3000.0 47.30 1000.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 45.60 1000.0 +-3000.0 43.60 1100.0 +-3000.0 47.30 1000.0 +-3000.0 45.30 1100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 43.60 1100.0 +-3000.0 41.60 1200.0 +-3000.0 45.30 1100.0 +-3000.0 43.30 1200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 41.60 1200.0 +-3000.0 39.60 1300.0 +-3000.0 43.30 1200.0 +-3000.0 41.30 1300.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 39.60 1300.0 +-3000.0 37.60 1400.0 +-3000.0 41.30 1300.0 +-3000.0 39.30 1400.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 37.60 1400.0 +-3000.0 35.60 1500.0 +-3000.0 39.30 1400.0 +-3000.0 37.30 1500.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 35.60 1500.0 +-3000.0 33.60 1600.0 +-3000.0 37.30 1500.0 +-3000.0 35.30 1600.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 33.60 1600.0 +-3000.0 31.60 1700.0 +-3000.0 35.30 1600.0 +-3000.0 33.30 1700.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 31.60 1700.0 +-3000.0 29.60 1800.0 +-3000.0 33.30 1700.0 +-3000.0 31.30 1800.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 29.60 1800.0 +-3000.0 27.60 1900.0 +-3000.0 31.30 1800.0 +-3000.0 29.30 1900.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 27.60 1900.0 +-3000.0 25.60 2000.0 +-3000.0 29.30 1900.0 +-3000.0 27.30 2000.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 25.60 2000.0 +-3000.0 23.60 2100.0 +-3000.0 27.30 2000.0 +-3000.0 25.30 2100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 23.60 2100.0 +-3000.0 21.60 2200.0 +-3000.0 25.30 2100.0 +-3000.0 23.30 2200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 21.60 2200.0 +-3000.0 19.60 2300.0 +-3000.0 23.30 2200.0 +-3000.0 21.30 2300.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 19.60 2300.0 +-3000.0 17.60 2400.0 +-3000.0 21.30 2300.0 +-3000.0 19.30 2400.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 17.60 2400.0 +-3000.0 15.60 2500.0 +-3000.0 19.30 2400.0 +-3000.0 17.30 2500.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 15.60 2500.0 +-3000.0 13.60 2600.0 +-3000.0 17.30 2500.0 +-3000.0 15.30 2600.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 13.60 2600.0 +-3000.0 11.60 2700.0 +-3000.0 15.30 2600.0 +-3000.0 13.30 2700.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 11.60 2700.0 +-3000.0 9.60 2800.0 +-3000.0 13.30 2700.0 +-3000.0 11.30 2800.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 9.60 2800.0 +-3000.0 7.60 2900.0 +-3000.0 11.30 2800.0 +-3000.0 9.30 2900.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 7.60 2900.0 +-3000.0 5.60 3000.0 +-3000.0 9.30 2900.0 +-3000.0 7.30 3000.0 +0.4 4.0 3 0.04 vis +endtraction + +// the W4 of the two stations of the timetable; the middle of the consist 2 m before it, leaves on time +include ip/pkp/w4n.inc gora#1 -2997.3 60.00 -60.0 180 0 0 2 202 end +include ip/pkp/w4n.inc dol#1 -2997.3 30.00 1500.0 180 0 0 2 202 end +// a signal at stop: what the AI reads of one, a memory cell with SetVelocity 0 0 and the event that reads it +node -1 0 gr_sem_mem memcell -2997.3 8.00 2600.0 SetVelocity 0.0 0.0 none endmemcell +event gr_sem_info getvalues 5.0 gr_sem_mem endevent + +trainset {{timetable}} gr_02 0.0 0.1 +{{consist}} +endtrainset diff --git a/tests/scenarios/run.py b/tests/scenarios/run.py index 35e923bee..2dcec6f0d 100644 --- a/tests/scenarios/run.py +++ b/tests/scenarios/run.py @@ -482,25 +482,42 @@ def check_brakes(rows, min_pressure, moving_speed=20): return False, f"brake cylinder pressure never reached {min_pressure} bar after moving off" -def check_stops(rows, moving_speed, stop_speed, hold, min_distance=None, max_distance=None): +def check_stops(rows, moving_speed, stop_speed, hold, min_distance=None, max_distance=None, max_time=None, nth=1): + """The nth stop of `hold` seconds after moving off at `moving_speed` (each stop after the first counts once the + train is moving at `moving_speed` again).""" start = _first_moving(rows, moving_speed) if start is None: return False, f"never reached {moving_speed} km/h" dist = _distances(rows) stopped_at = None + held = 0 + moving = True for i in range(start, len(rows)): r = rows[i] + if not moving: + moving = r[COL_VELOCITY] >= moving_speed + continue if r[COL_VELOCITY] <= stop_speed: if stopped_at is None: stopped_at = i if r[COL_TIME] - rows[stopped_at][COL_TIME] >= hold: + held += 1 + if held < nth: + stopped_at = None + moving = False + continue where = dist[stopped_at] - detail = f"came to a stop at t={rows[stopped_at][COL_TIME]:.1f}s after {where:.0f} m" + when = rows[stopped_at][COL_TIME] + detail = f"came to a stop at t={when:.1f}s after {where:.0f} m" if (min_distance is not None and where < min_distance) or (max_distance is not None and where > max_distance): return False, f"{detail}, wanted between {min_distance} and {max_distance} m" + if max_time is not None and when > max_time: + return False, f"{detail}, wanted by t={max_time}s" return True, detail else: stopped_at = None + if held: + return False, f"stopped {held} times for {hold}s after moving off, wanted stop {nth}" return False, f"did not stay below {stop_speed} km/h for {hold}s after moving off" diff --git a/tests/unit/test_braking_curve.cpp b/tests/unit/test_braking_curve.cpp index 7102d06e0..6bcf92fc7 100644 --- a/tests/unit/test_braking_curve.cpp +++ b/tests/unit/test_braking_curve.cpp @@ -154,6 +154,41 @@ TEST_CASE("braking curve: a train with a worked out brake table plans along the } } +TEST_CASE("braking curve: the train brake handle or the independent brake counts as braking") { + CHECK_FALSE(braking_curve::brake_acting(0.0, 0.0)); + // the handle in its release or filling positions is below running + CHECK_FALSE(braking_curve::brake_acting(-1.0, 0.0)); + CHECK(braking_curve::brake_acting(1.0, 0.0)); + CHECK(braking_curve::brake_acting(0.5, 0.0)); + // a light locomotive or a railcar alone brakes with the independent brake, the handle stays in running + CHECK(braking_curve::brake_acting(0.0, 0.25)); + CHECK(braking_curve::brake_acting(-1.0, 1.0)); + CHECK(braking_curve::brake_acting(2.0, 0.5)); +} + +TEST_CASE("braking curve: a vehicle braking with its independent brake uses the whole distance, as with the train brake") { + // before, only the train brake handle counted: a light locomotive that had put its independent brake on still + // planned, on every look, to stop short by the distance the brake takes to fill, so it slowed down too early + // and crawled the last tens of metres to the stop + flat_table const light; + auto const table{light.table()}; + auto approach{stop_at(60.0, 300.0)}; + approach.offset = 20.0; + approach.fill_horizon = 8.0; + approach.brake_applied = braking_curve::brake_acting(0.0, 0.3); + + auto const demand{braking_curve::demand(approach, &table)}; + + CHECK(demand == doctest::Approx(braking_curve::shaped_demand(60.0, 0.0, 280.0 + 0.1 / 25.92, 0.0, table))); + auto trainbrake{approach}; + trainbrake.brake_applied = braking_curve::brake_acting(1.0, 0.0); + CHECK(demand == doctest::Approx(braking_curve::demand(trainbrake, &table))); + auto released{approach}; + released.brake_applied = braking_curve::brake_acting(0.0, 0.0); + // with no brake on, the room to fill is kept, and more is asked for + CHECK(braking_curve::demand(released, &table) < demand); +} + TEST_CASE("braking curve: a train gets the demand it got before the curve moved out of the AI") { // a table that grips harder as the train slows, on a gradient; the demands were worked out with the // code of TController::adjust_desired_speed_for_braking_curve before the move (origin/master 80fd5aad) diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index a25ed392c..5630cdea1 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -8256,8 +8256,16 @@ TController::adjust_desired_speed_for_braking_curve( double const Vel ) { // independent brake, which leaves the train brake handle where it is, kept braking earlier // and earlier the whole way in, to crawl the last tens of metres to the stop point auto const fillbrakea0 { bStopTargetIsPassengerStop ? 1.0 : fBrake_a0[ 0 ] }; + // once the brake is on, the room it takes to fill is behind; a vehicle running alone brakes with its + // independent brake and leaves the train brake handle in running, so that brake counts as well braking_curve::approach const approach { - Vel, VelNext, ActualProximityDist, brakingpointoffset, fAccGravity, AbsAccS, BrakeCtrlPosition > 0.0, + Vel, VelNext, ActualProximityDist, brakingpointoffset, fAccGravity, AbsAccS, + braking_curve::brake_acting( + BrakeCtrlPosition, + // IncLocalBrakeLevel() moves the independent brake handle on a vehicle without one too + ( mvOccupied->LocalBrake == TLocalBrake::PneumaticBrake || mvOccupied->LocalBrake == TLocalBrake::HydraulicBrake ) ? + mvOccupied->LocalBrakePosA : + 0.0 ), brake_response_horizon( mvOccupied, BrakeSystem, AbsAccS, fBrake_a0[ 0 ] ), brake_response_horizon( mvOccupied, BrakeSystem, 1.0, fillbrakea0 ) }; auto const deceleration { braking_curve::demand( approach, BrakeSystem == TBrakeSystem::Pneumatic ? &braketable : nullptr ) }; diff --git a/vehicle/brakingcurve.cpp b/vehicle/brakingcurve.cpp index d39ee2868..1cd1397aa 100644 --- a/vehicle/brakingcurve.cpp +++ b/vehicle/brakingcurve.cpp @@ -25,6 +25,10 @@ bool brake_table::known() const { return a0[size] > 0.0; } +bool brake_acting(double const Trainbrakeposition, double const Localbrakeposition) { + return (Trainbrakeposition > 0.0) || (Localbrakeposition > 0.0); +} + double shaped_demand(double const Velocity, double const Target, double const Distance, double const Gravity, brake_table const &Table) { auto const travel = [Velocity, Target, Gravity, &Table](double const Ratio) { diff --git a/vehicle/brakingcurve.h b/vehicle/brakingcurve.h index 6ed40d9bb..3b49597e5 100644 --- a/vehicle/brakingcurve.h +++ b/vehicle/brakingcurve.h @@ -40,11 +40,17 @@ struct approach { double offset; // the braking point that far short of it [m] double gravity; // tangential acceleration of the gradient [m/s2], negative uphill double acceleration; // present acceleration of the train [m/s2] - bool brake_applied; // the train brake handle is past running + bool brake_applied; // the brake the train slows down with is applied (brake_acting) double speedup_horizon; // how long the present acceleration lasts while speeding up [s] double fill_horizon; // how long the brake takes to fill once applied [s] }; +// whether the train is braking already, for approach::brake_applied: the train brake handle is past running +// (Trainbrakeposition above 0), or the independent brake is applied (Localbrakeposition above 0). a vehicle that +// runs alone, a light locomotive or a railcar, brakes with the independent brake and leaves the train brake +// handle in running +bool brake_acting(double Trainbrakeposition, double Localbrakeposition); + // acceleration [m/s2] to ask for now, negative to brake. with the worked out table of a pneumatic brake // (Pneumatictable) the demand follows the brake: planned from the state the train is in once the brake has // responded, along the shape of its force over speed. without one (nullptr for another brake, or a table left at From 3ccd4fe73ff4a9cdd2f5fe12c1b6854e9d9fd03a Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 05:15:27 +0100 Subject: [PATCH 10/27] fix(ai): read the motor parameters of ESMVelocity() within the table (#486) * fix(ai): read the motor parameters of ESMVelocity() within the table TController::ESMVelocity() indexed MotorParam with the field shunting step of the next master controller position. For a position with a step of its own that index is RList[].ScndAct, the sixth column of the RList rows of the .fiz, which readRList() takes as it is. A step of 11 or more read past the 11 entries of MotorParam. The pole flux is now read through motor_param(), which keeps the index inside the table, as MomentumF() in the same loop and Momentum() already do. Nothing changes for a .fiz with valid steps. The unit tests show the loader keeping an out-of-range ScndAct and motor_param() clamping it; ESMVelocity() itself is in Driver.cpp, which the unit tests don't build. * test(scenarios): a Traxx, with a brake handle with a time chamber, starting up None of the cases had a driver's brake handle with a time chamber (MHZ_K5P, MHZ_6P, M394, Knorr, St113, FVel6, FVE408), for which the AI getting the vehicle ready has a rule of its own for releasing the train brake (5775493b2). Three cases run a Traxx (E186, MHZ_6P) on td.scn: the timetable run from a trainset ready to depart, the same from a cold start, and the locomotive standing ready to depart with nobody in it until a driver is put in. In each the driver puts the handle to running and leaves. * test: read the EP09 definition into a json with '=', not braces GCC takes nlohmann::ordered_json in braces for an initializer list and makes an array holding the parsed object, so at("RList") threw on the Linux build (type_error 304); MSVC kept the object. --- tests/scenarios/README.md | 10 ++++ tests/scenarios/cases/traxx_td_crew_add.json | 31 ++++++++++ tests/scenarios/cases/traxx_td_timetable.json | 17 ++++++ .../cases/traxx_td_timetable_cold.json | 20 +++++++ tests/unit/test_motor_param_bounds.cpp | 57 +++++++++++++++++++ vehicle/Driver.cpp | 6 +- 6 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 tests/scenarios/cases/traxx_td_crew_add.json create mode 100644 tests/scenarios/cases/traxx_td_timetable.json create mode 100644 tests/scenarios/cases/traxx_td_timetable_cold.json create mode 100644 tests/unit/test_motor_param_bounds.cpp diff --git a/tests/scenarios/README.md b/tests/scenarios/README.md index bf5467018..5ddc77dca 100644 --- a/tests/scenarios/README.md +++ b/tests/scenarios/README.md @@ -242,6 +242,16 @@ stop, starting `vars.offset` m into `tdo_n1734`: `eu07_td_shunt_red_signal` alon 151 m from the start (the shunting AI used to coast up to it and pass it at about 28 km/h, fixed by #409). They stop after 145 m and 141 m. +The `traxx_*` cases run a Traxx (E186, `p160dc`), whose driver's brake handle (MHZ_6P) has a time +chamber, like the MHZ_K5P, M394, Knorr, St113, FVel6 and FVE408 handles, which no other case has: the +AI getting such a locomotive ready has a rule of its own for releasing the train brake (5775493b2, +#444). `traxx_td_timetable` is the timetable run from a trainset ready to depart, +`traxx_td_timetable_cold` the same from a cold start (`td_cold_timetable.scn`, the handle in its +holding position, the brake pipe low), and `traxx_td_crew_add` the locomotive standing ready to depart +with nobody in it, the handle in its holding position and the brake pipe charged, until a driver is +put in (`td_crew.scn`, as `eu07_td_crew_add`). In all three the driver puts the handle to running +within a second of starting and leaves. + `eu07_td_departure_station_capitals` runs an EU07 from where `td_timetable.scn` puts it, with the W4 of Stacja1 about 35 m ahead, on a timetable of its own (`td_departure_station_capitals.txt`, fragment `td_departure_station.scn`): its first row, the station of departure, gives no arrival time and is written in capitals (`STACJA1`), the relation diff --git a/tests/scenarios/cases/traxx_td_crew_add.json b/tests/scenarios/cases/traxx_td_crew_add.json new file mode 100644 index 000000000..9d6200a1b --- /dev/null +++ b/tests/scenarios/cases/traxx_td_crew_add.json @@ -0,0 +1,31 @@ +{ + "description": "As eu07_td_crew_add, with a Traxx (E186, p160dc) standing ready to depart (trainset velocity 0.1) with nobody in it: its brake handle, one with a time chamber (MHZ_6P), in the holding position and the brake pipe and the control reservoir at running pressure. The AI driver put in cab A 20 s after the start gets the locomotive ready, puts the handle to running and leaves through the exit signal.", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_crew.scn", + "vars": { + "trainsets": [ + "trainset none tdo_n1734 0.0 0.1", + "node -1 0 {{vehicle}} dynamic pkp/e186_v2 146_226-6 p160dc 0 nobody 0 0 enddynamic", + "endtrainset" + ], + "crew": [ + "event autotest_crew_put putvalues 0 none 0 0 0 Crew:{{vehicle}} 1 0 endevent", + "event autotest_crew_on multiple 20 none autotest_crew_put autotest_crew_waits endevent", + "node -1 0 autotest_crew_on_launcher eventlauncher 0 0 0 -1 none 1034 autotest_crew_on end" + ] + }, + "track_events": { + "tdo_n1734": "event0 autotest_wake" + }, + "duration": 300, + "timeout": 600, + "checks": [ + { "type": "log_contains", "pattern": "Crew: \\[autotest_traxx_td_crew_add\\] an AI driver takes cab A" }, + { "type": "driver_changes", "vehicle": "{{vehicle}}", "to": "ai", "after": 15, "before": 30 }, + { "type": "starts", "min_speed": 20, "within": 240 }, + { "type": "moves", "vehicle": "{{vehicle}}", "direction": "front", "min_speed": 20 }, + { "type": "log_lacks", "pattern": "derailed" }, + { "type": "log_lacks", "pattern": "collided" } + ] +} diff --git a/tests/scenarios/cases/traxx_td_timetable.json b/tests/scenarios/cases/traxx_td_timetable.json new file mode 100644 index 000000000..51d84860b --- /dev/null +++ b/tests/scenarios/cases/traxx_td_timetable.json @@ -0,0 +1,17 @@ +{ + "description": "Traxx (E186, p160dc) on td.scn, AI driver on the td/rozklad timetable: a driver's brake handle with a time chamber (MHZ_6P), for which the AI getting the locomotive ready has a rule of its own for releasing the train brake (5775493b2, #444). Starts from Stacja1, keeps to the speed limit, brakes to a stop at Przystanek.", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_timetable.scn", + "vars": { + "consist": "node -1 0 {{vehicle}} dynamic pkp/e186_v2 146_226-6 p160dc 0 headdriver 0 0 enddynamic" + }, + "duration": 240, + "timeout": 600, + "checks": [ + { "type": "starts", "min_speed": 20, "within": 150 }, + { "type": "max_speed", "limit": 90, "tolerance": 3 }, + { "type": "brakes", "min_pressure": 0.5 }, + { "type": "stops", "moving_speed": 20, "stop_speed": 1.0, "hold": 0, "min_distance": 1380, "max_distance": 1420 } + ] +} diff --git a/tests/scenarios/cases/traxx_td_timetable_cold.json b/tests/scenarios/cases/traxx_td_timetable_cold.json new file mode 100644 index 000000000..bfdb833a2 --- /dev/null +++ b/tests/scenarios/cases/traxx_td_timetable_cold.json @@ -0,0 +1,20 @@ +{ + "description": "As traxx_td_timetable, from a cold start: the trainset stands with velocity 0, so the locomotive starts braked, its brake handle (MHZ_6P, with a time chamber) in the holding position and the brake pipe below running pressure. The driver gets the order to run as a train, starts the locomotive, puts the handle to running, charges the brake pipe and leaves on time.", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_cold_timetable.scn", + "vars": { + "consist": "node -1 0 {{vehicle}} dynamic pkp/e186_v2 146_226-6 p160dc 0 headdriver 0 0 enddynamic" + }, + "track_events": { + "tdo_n1734": "event0 autotest_wake" + }, + "duration": 300, + "timeout": 600, + "checks": [ + { "type": "starts", "min_speed": 20, "within": 150 }, + { "type": "max_speed", "limit": 90, "tolerance": 3 }, + { "type": "brakes", "min_pressure": 0.5 }, + { "type": "stops", "moving_speed": 20, "stop_speed": 1.0, "hold": 0, "min_distance": 1380, "max_distance": 1420 } + ] +} diff --git a/tests/unit/test_motor_param_bounds.cpp b/tests/unit/test_motor_param_bounds.cpp new file mode 100644 index 000000000..5d44c7331 --- /dev/null +++ b/tests/unit/test_motor_param_bounds.cpp @@ -0,0 +1,57 @@ +#include "stdafx.h" +#include "doctest.h" +#include "vehicle.h" + +#include + +#include + +using test::definition; +using test::vehicle; + +// the field shunting step a position of the master controller selects (RList, its sixth column ScndAct) indexes the +// motor parameter table, MotorParam, which has MotorParametersArraySize + 1 entries. The loader takes ScndAct from the +// .fiz as it is, so the readers of the table (TMoverParameters::Momentum(), MomentumF(), TController::ESMVelocity()) +// go through motor_param(), which keeps the index inside the table + +namespace { + +// the RList rows of the EP09 with the ScndAct of the first position replaced +nlohmann::ordered_json ep09_rlist_with_scndact(std::string const &Scndact) { + std::ifstream file{std::string{EU07_UNIT_TESTS_DATA} + "/fiz/ep09_v2/104e.json"}; + REQUIRE(file.good()); + // '=' rather than braces: GCC takes a json in braces for an initializer list, an array holding it + auto const ep09 = nlohmann::ordered_json::parse(file); + auto rows = ep09.at("RList").at("rows"); + REQUIRE(rows.size() > 1); + rows[1][5] = Scndact; + return rows; +} + +} // namespace + +TEST_CASE("motor parameters: the ScndAct of an RList row is read from the .fiz as it is") { + vehicle ep09{definition::fiz("ep09_v2/104e")}; + // the first position of the EP09 runs on field shunting step 2 + CHECK(ep09->RList[1].ScndAct == 2); + CHECK(&ep09->motor_param(ep09->RList[1].ScndAct) == &ep09->MotorParam[2]); + + // a .fiz giving a step beyond the table: nothing checks it on loading + vehicle broken{definition::fiz("ep09_v2/104e").set("RList", "rows", ep09_rlist_with_scndact("20"))}; + CHECK(broken->RList[1].ScndAct == 20); + CHECK(broken->RList[1].ScndAct > MotorParametersArraySize); +} + +TEST_CASE("motor parameters: motor_param() keeps a step from the .fiz inside the table") { + vehicle broken{definition::fiz("ep09_v2/104e").set("RList", "rows", ep09_rlist_with_scndact("20"))}; + auto const &table{broken->MotorParam}; + // past the end: the last entry, rather than memory beyond the table + CHECK(&broken->motor_param(broken->RList[1].ScndAct) == &table[MotorParametersArraySize]); + CHECK(&broken->motor_param(MotorParametersArraySize + 1) == &table[MotorParametersArraySize]); + // below the start: the first entry + CHECK(&broken->motor_param(-1) == &table[0]); + // inside the table: the entry itself + for (int step = 0; step <= MotorParametersArraySize; ++step) { + CHECK(&broken->motor_param(step) == &table[step]); + } +} diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index 5630cdea1..086ff43ad 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -2726,8 +2726,10 @@ double TController::ESMVelocity(bool Main) } IF = std::min(IF, mvControlling->Imax*fCurrentCoeff); double R = mvControlling->RList[MCPN].R + mvControlling->CircuitRes + mvControlling->RList[MCPN].Mn*mvControlling->WindingRes; - double pole = mvControlling->MotorParam[SCPN].fi * - std::max(abs(IF) / (abs(IF) + mvControlling->MotorParam[SCPN].Isat) - mvControlling->MotorParam[SCPN].fi0, 0.0); + // SCPN may come from the .fiz (RList ScndAct) unchecked: read it with the bounds-safe accessor, as MomentumF() does + auto const &motorparam{mvControlling->motor_param(SCPN)}; + double pole = motorparam.fi * + std::max(abs(IF) / (abs(IF) + motorparam.Isat) - motorparam.fi0, 0.0); double Us = abs(mvControlling->EngineVoltage) - IF*R; double ns = std::max(0.0, Us / (pole*mvControlling->RList[MCPN].Mn)); ESMVel = ns * mvControlling->WheelDiameter*M_PI*3.6/mvControlling->Transmision.Ratio; From fa13d4b4a25084e515a93f77f35b45c4c7344460 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 05:15:40 +0100 Subject: [PATCH 11/27] fix(editor): Esc in the road window goes back to the select tool when nothing is being drawn (#487) Esc in the road window only called road_cancel(), which gives up the road being drawn but never changes the tool, so with the build or place tool chosen every Esc left that tool in use and the next click started another road. Now the first Esc still gives up the road being drawn (or led out of a road or a junction, or the Alt+drag of the heights) and keeps the tool; with nothing going on Esc switches to the select tool, the way the first and the next Esc work in the track field of work. The decision is editor_road::tool_after_escape(), covered by unit tests. Fixes #348 --- application/editormode.cpp | 5 ++++ editor/editorRoad.hpp | 7 ++++++ tests/unit/test_road_escape.cpp | 44 +++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 tests/unit/test_road_escape.cpp diff --git a/application/editormode.cpp b/application/editormode.cpp index a40c6e081..cfc0287c6 100644 --- a/application/editormode.cpp +++ b/application/editormode.cpp @@ -7454,7 +7454,12 @@ void editor_mode::on_key(int const Key, int const Scancode, int const Action, in } if (is_press(Action)) { + // in the road window the first Esc gives up the road being drawn, the next one goes back to the selection + auto const &road{m_roadtool}; + auto const next{editor_road::tool_after_escape(road.tool, road.chain || road.branchroad != nullptr || road.branchjunction != nullptr, road.lifting)}; road_cancel(); + if (road.window && ui()->mode() != nodebank_panel::TRACK) + road_choose_tool(next); } // the first Esc drops what is going on in the track mode, the next one goes back to the selection if (is_press(Action) && ui()->mode() == nodebank_panel::TRACK) diff --git a/editor/editorRoad.hpp b/editor/editorRoad.hpp index c1b23433f..51498b143 100644 --- a/editor/editorRoad.hpp +++ b/editor/editorRoad.hpp @@ -173,6 +173,13 @@ class editor_road // Radius: of the axis of that road; Layout: what the road is like. the lanes it has along its axis are the ones the roundabout gets. // Island: what the middle is covered with, "none" to leave the ground showing static std::vector roundabout(glm::dvec3 const &Centre, double const Radius, road_node::state const &Layout, std::string const &Island); + // the tool of the road window (0 select, 1 build, 2 place) Esc leaves. while a road is being drawn, or led out of the side of + // a road or a junction, or the selected points are dragged up or down, the tool in use stays and Esc gives that up; with + // nothing going on Esc goes back to the selection + static constexpr int tool_after_escape(int const Tool, bool const Drawing, bool const Lifting) + { + return (Drawing || Lifting) ? Tool : 0; + } private: // takes down what depends on the listed pieces and junctions, lets the caller change them, then builds it all again diff --git a/tests/unit/test_road_escape.cpp b/tests/unit/test_road_escape.cpp new file mode 100644 index 000000000..31fbc1a21 --- /dev/null +++ b/tests/unit/test_road_escape.cpp @@ -0,0 +1,44 @@ +// Esc in the road window (GH#348): the first one gives up what is going on, the next one goes back to the selection + +#include "stdafx.h" +#include "doctest.h" +#include "editor/editorRoad.hpp" + +namespace { + +constexpr int select_tool{0}; +constexpr int build_tool{1}; +constexpr int place_tool{2}; + +} // namespace + +TEST_CASE("Esc with the build tool and no road being drawn goes back to the selection") { + CHECK(editor_road::tool_after_escape(build_tool, false, false) == select_tool); +} + +TEST_CASE("Esc while a road is being drawn or led out of a road or a junction keeps the build tool") { + CHECK(editor_road::tool_after_escape(build_tool, true, false) == build_tool); +} + +TEST_CASE("Esc with the place tool goes back to the selection, the tool has nothing being drawn") { + CHECK(editor_road::tool_after_escape(place_tool, false, false) == select_tool); +} + +TEST_CASE("Esc while the selected points are dragged up or down keeps the tool, the drag is given up") { + CHECK(editor_road::tool_after_escape(select_tool, false, true) == select_tool); + CHECK(editor_road::tool_after_escape(build_tool, false, true) == build_tool); +} + +TEST_CASE("Esc with the selection tool stays with it") { + CHECK(editor_road::tool_after_escape(select_tool, false, false) == select_tool); +} + +TEST_CASE("two Esc presses from the build tool in the middle of a road: the road given up, then the selection") { + auto tool{build_tool}; + bool drawing{true}; + tool = editor_road::tool_after_escape(tool, drawing, false); + drawing = false; // what the first Esc gives up + CHECK(tool == build_tool); + tool = editor_road::tool_after_escape(tool, drawing, false); + CHECK(tool == select_tool); +} From 0c01d660f64fbd1b75028f00eaf03cd816f27b9c Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 05:23:37 +0100 Subject: [PATCH 12/27] fix(editor): roads joined to a roundabout take only the room they need (#485) * fix(editor): a road joined to a roundabout takes only the room it needs A road led into the side of a roundabout gets a junction that cuts the ring on both sides of it. The cut was measured as on a straight road: where the edge of the road leaving meets the edge of the road it leaves, plus the corner, and with the value of the acute corner used on both sides. The ring bends away from a road leaving it to the outside, so the edges meet sooner, and a road leaving at a slant meets the ring much sooner on the side it leans away from. Each junction took too much of the ring, and the next road was refused with "Too close to a junction": with roads joined at a slant only two fitted on a roundabout of 12-15 m. On a roundabout the room on each side is now measured on the circle of the ring's outer edge, never more than before. In the editor, five roads at 45 degrees now join a roundabout of 15 m and four at 30 degrees one of 12 m (two before); roads joined straight out gain less: two instead of one on the smallest roundabout (8 m), four of six on one of 16 m instead of three. Saved roundabouts load as before; only junctions made from now on are laid out differently. Fixes #349 * fix(editor): junctions on a roundabout leave shorter pieces of the ring A junction cut into a road leaves at least 2 m of the piece it cuts. When less would be left, it takes the rest of the piece, so a junction next to the end of one of the ring's arcs grew by up to 2 m, and the next junction had to stay 2 m further away. On a roundabout of 8-10 m, where each road joined straight out takes about 14 m of the ring, that was the difference between two roads and three or four. The ring goes on round past such a piece, so on a roundabout the shortest piece is now 0.5 m (editor_ring::shortest_piece). Roads of their own keep the 2 m. In the editor, three roads joined straight out now fit on the smallest roundabout (8 m) and four on one of 9.6 m or more, wherever they join the ring; six fit on 15 and 16 m. Four roads on the 8 m one would take smaller corners, and are still refused. Saved roundabouts load as before. * fix(editor): the reaches of a junction on a roundabout in a std::array --- editor/editorRingRoom.hpp | 63 +++++++++++++++ editor/editorRoad.cpp | 44 ++++++++++- tests/unit/test_ring_room.cpp | 143 ++++++++++++++++++++++++++++++++++ 3 files changed, 248 insertions(+), 2 deletions(-) create mode 100644 editor/editorRingRoom.hpp create mode 100644 tests/unit/test_ring_room.cpp diff --git a/editor/editorRingRoom.hpp b/editor/editorRingRoom.hpp new file mode 100644 index 000000000..9051da616 --- /dev/null +++ b/editor/editorRingRoom.hpp @@ -0,0 +1,63 @@ +/* +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/. +*/ + +#pragma once + +#include +#include +#include + +// the room a road leaving the side of a roundabout takes of the ring, seen from above. on a straight road the edge of the road +// leaving meets the edge of the road it leaves where the two straight lines cross; the ring bends away from the road leaving it +// to the outside, so there the edges meet sooner; and a road leaving at a slant meets the edge of the ring sooner on the side +// it leans away from than on the side it leans towards +namespace editor_ring +{ + +// the shortest piece of the ring a junction leaves before the next junction, or before the end of the arc it's cut from. +// the ring goes on past it, so it can be much shorter than a road of its own; a junction which would leave less takes +// the rest of the arc, and the shorter this is the less a junction grows next to the end of an arc +double constexpr shortest_piece{0.5}; + +// how far along the axis of the ring, from the point a road leaves it, the edge of that road meets the outer edge of the ring. +// Centre: of the ring, Radius: of its axis, Point: where the axis of the road leaving meets the axis of the ring, +// Direction: the way the road leaves, Along: the way along the ring the room is measured, Halfwidth: of the ring, +// Branchhalfwidth: of the road leaving. returns: the distance along the axis of the ring, 0 if the edges cross before they get +// past the point the road leaves, or a negative value if there's no such point: the road doesn't leave towards the outside, +// or it leans so far that the edge on that side stays outside the ring all along +inline double edge_room(glm::dvec2 const &Centre, double const Radius, glm::dvec2 const &Point, glm::dvec2 const &Direction, glm::dvec2 const &Along, double const Halfwidth, + double const Branchhalfwidth) +{ + if (Radius <= 0.0 || glm::length(Direction) < 1e-9 || glm::length(Point - Centre) < 1e-9) + return -1.0; + auto const direction{glm::normalize(Direction)}; + auto const outwards{glm::normalize(Point - Centre)}; + if (glm::dot(direction, outwards) < 1e-6) + return -1.0; + // the edge of the road leaving on the side the room is measured for + glm::dvec2 side{-direction.y, direction.x}; + if (glm::dot(side, Along) < 0.0) + side = -side; + auto const start{Point - Centre + side * Branchhalfwidth}; + auto const edge{Radius + Halfwidth}; + // start + direction * t on the circle of the outer edge, where the edge leaves it going out. a road wide enough, or leaning + // far enough, has the start of that edge outside the circle already: the edges crossed before it + auto const b{glm::dot(start, direction)}; + auto const discriminant{b * b + edge * edge - glm::dot(start, start)}; + if (discriminant < 0.0) + return -1.0; + auto const t{-b + std::sqrt(discriminant)}; + auto const meet{start + direction * t}; + // the angle from the point the road leaves to that point, around the centre and the way the room is measured, carried onto the axis + auto const turn{outwards.x * Along.y - outwards.y * Along.x < 0.0 ? -1.0 : 1.0}; + auto const angle{std::atan2(turn * (outwards.x * meet.y - outwards.y * meet.x), glm::dot(outwards, meet))}; + return std::max(0.0, Radius * angle); +} + +} // namespace editor_ring diff --git a/editor/editorRoad.cpp b/editor/editorRoad.cpp index 51aa495f3..b803416a8 100644 --- a/editor/editorRoad.cpp +++ b/editor/editorRoad.cpp @@ -10,6 +10,7 @@ http://mozilla.org/MPL/2.0/. #include "stdafx.h" #include "editor/editorRoad.hpp" #include "editor/editorFormat.hpp" +#include "editor/editorRingRoom.hpp" #include "editor/editorTrack.hpp" #include "world/Track.h" @@ -274,7 +275,9 @@ bool follow(road_node &Road, double const T, bool const Forward, double const Di auto const lengths{stations(state)}; auto const here{station_at(lengths, from)}; auto const available{forward ? lengths.back() - here : here}; - if (remaining <= 0.0 || available >= remaining + kShortestRoad) + // what's left of a piece of a roundabout carries on round, so it can be shorter than a road of its own + auto const shortest{state.roundabout ? editor_ring::shortest_piece : kShortestRoad}; + if (remaining <= 0.0 || available >= remaining + shortest) { // the cut is put here; with nothing left to go the piece is kept whole Cut.road = piece; @@ -339,6 +342,27 @@ double edge_reach(double const Halfwidth, double const Otherhalfwidth, double co return (Otherhalfwidth + Halfwidth * std::cos(Angle)) / std::sin(Angle); } +// the circle the axis of a piece bends along at specified value of its curve parameter, seen from above. returns: false if it's straight there +bool ring_circle(road_node::state const &State, double const T, glm::dvec2 &Centre, double &Radius) +{ + auto const points{curve_points(State.axis)}; + auto const u{1.0 - T}; + auto const first{3.0 * u * u * (points[1] - points[0]) + 6.0 * u * T * (points[2] - points[1]) + 3.0 * T * T * (points[3] - points[2])}; + auto const second{6.0 * u * (points[2] - 2.0 * points[1] + points[0]) + 6.0 * T * (points[3] - 2.0 * points[2] + points[1])}; + glm::dvec2 const velocity{first.x, first.z}; + auto const speed{glm::length(velocity)}; + if (speed < 1e-9) + return false; + auto const curvature{(velocity.x * second.z - velocity.y * second.x) / (speed * speed * speed)}; + if (std::abs(curvature) < 1e-5) + return false; + auto const point{curve_point(points, T)}; + auto const tangent{velocity / speed}; + Centre = glm::dvec2{point.x, point.z} + glm::dvec2{-tangent.y, tangent.x} / curvature; + Radius = 1.0 / std::abs(curvature); + return true; +} + // the look of a junction goes after the road it's made on void dress(junction_node::state &Junction, road_node::state const &Road) { @@ -1852,11 +1876,27 @@ bool editor_road::branch_from(road_node &Road, double const T, glm::dvec2 const auto const branchhalfwidth{0.5 * (Incoming + Outgoing) * Width}; auto const reach{edge_reach(halfwidth, branchhalfwidth, angle) + kCornerRoom}; auto const branchreach{edge_reach(branchhalfwidth, halfwidth, angle) + kCornerRoom}; + // how far the junction takes the road back along it and ahead of the centre + std::array reaches{reach, reach}; + glm::dvec2 ringcentre{0.0}; + double ringradius{0.0}; + if (layout.roundabout && ring_circle(layout, T, ringcentre, ringradius)) + { + // the ring bends away from a road leaving it to the outside, so their edges meet sooner than on a straight road; and a road + // leaving at a slant meets the edge of the ring sooner on the side it leans away from. the room of a straight road, measured + // on the side the road leans towards, is the most a side takes + for (int side = 0; side < 2; ++side) + { + auto const room{editor_ring::edge_room(ringcentre, ringradius, glm::dvec2{centre.x, centre.z}, direction, side == 0 ? -along : along, halfwidth, branchhalfwidth)}; + if (room >= 0.0) + reaches[side] = std::min(reach, room + kCornerRoom); + } + } // where the road is cut on both sides of the centre road_cut cuts[2]; std::vector consumed; - if (false == follow(Road, T, false, reach, cuts[0], consumed, Error) || false == follow(Road, T, true, reach, cuts[1], consumed, Error)) + if (false == follow(Road, T, false, reaches[0], cuts[0], consumed, Error) || false == follow(Road, T, true, reaches[1], cuts[1], consumed, Error)) return false; if (cuts[0].road == cuts[1].road && cuts[0].road != &Road) { diff --git a/tests/unit/test_ring_room.cpp b/tests/unit/test_ring_room.cpp new file mode 100644 index 000000000..835072f75 --- /dev/null +++ b/tests/unit/test_ring_room.cpp @@ -0,0 +1,143 @@ +#include "stdafx.h" +#include "doctest.h" +#include "editor/editorRingRoom.hpp" + +#include + +// the room a road leaving the side of a roundabout takes of the ring (eu07/maszyna GH#349): with the ring's bend +// counted, as many roads fit on a small roundabout as there's room for between their edges +namespace { + +double constexpr pi{3.14159265358979323846}; +// as the road editor has them: a junction takes the road it's made on past where the edges meet by the corner room, +// and between two junctions there's at least the shortest road left +double constexpr kCornerRoom{4.0}; +double constexpr kShortestRoad{2.0}; +// the roads the editor builds unless told otherwise: a lane each way, 3.5 m each, and a roundabout of a single lane +double constexpr kRoadHalfwidth{3.5}; +double constexpr kRingHalfwidth{1.75}; + +glm::dvec2 at(double const Radius, double const Angle) { return glm::dvec2{std::cos(Angle), std::sin(Angle)} * Radius; } +glm::dvec2 ahead(double const Angle) { return {-std::sin(Angle), std::cos(Angle)}; } + +// room of a road leaving the ring of the radius at the angle, turned from the way straight out by the slant (to the way ahead) +double room(double const Radius, double const Slant, bool const Ahead, double const Halfwidth = kRingHalfwidth, double const Branchhalfwidth = kRoadHalfwidth) { + double const angle{0.3}; + auto const outwards{at(1.0, angle)}; + auto const direction{outwards * std::cos(Slant) + ahead(angle) * std::sin(Slant)}; + return editor_ring::edge_room(glm::dvec2{0.0}, Radius, at(Radius, angle), direction, Ahead ? ahead(angle) : -ahead(angle), Halfwidth, Branchhalfwidth); +} + +// where the edges of two straight roads meet, measured along the first one, as the editor has it for a road leaving a straight road. +// Lean: the second one leans towards the side measured (the angle between them there is the acute one) +double straight_reach(double const Halfwidth, double const Branchhalfwidth, double const Angle, bool const Lean) { + return (Branchhalfwidth + (Lean ? 1.0 : -1.0) * Halfwidth * std::cos(Angle)) / std::sin(Angle); +} + +// whether the roads leaving straight out, evenly all around the ring, each get a junction: the junctions with what's left between them. +// Bend: the room measured on the ring, rather than as on a straight road; Shortest: the shortest piece left between two junctions. +// Arcs: a junction next to the end of an arc of the ring takes the rest of the arc when less than the shortest piece would be left +// of it, so in the worst case it grows by as much +bool fit(double const Radius, int const Roads, bool const Bend, double const Shortest, bool const Arcs) { + auto const side{Bend ? room(Radius, 0.0, true) : straight_reach(kRingHalfwidth, kRoadHalfwidth, pi / 2.0, true)}; + auto const junction{2.0 * (side + kCornerRoom)}; + return Roads * (junction + Shortest + (Arcs ? Shortest : 0.0)) <= 2.0 * pi * Radius; +} +bool fit(double const Radius, int const Roads, bool const Bend) { return fit(Radius, Roads, Bend, kShortestRoad, false); } +// as the editor has it now, wherever the roads join the ring +bool fits(double const Radius, int const Roads) { return fit(Radius, Roads, true, editor_ring::shortest_piece, true); } + +} // namespace + +TEST_CASE("ring room: on a very large ring the room is the one of a straight road") { + for (double const slant : {0.0, pi / 12.0, pi / 6.0, pi / 4.0, pi / 3.0}) { + CAPTURE(slant); + double const angle{pi / 2.0 - slant}; + CHECK(room(1.0e6, slant, true) == doctest::Approx(straight_reach(kRingHalfwidth, kRoadHalfwidth, angle, true)).epsilon(1e-4)); + CHECK(room(1.0e6, slant, false) == doctest::Approx(straight_reach(kRingHalfwidth, kRoadHalfwidth, angle, false)).epsilon(1e-4)); + } +} + +TEST_CASE("ring room: a road leaving straight out meets the outer edge where the circle reaches its edge") { + for (double const radius : {8.0, 15.0, 40.0}) { + CAPTURE(radius); + double const expected{radius * std::asin(kRoadHalfwidth / (radius + kRingHalfwidth))}; + CHECK(room(radius, 0.0, true) == doctest::Approx(expected)); + CHECK(room(radius, 0.0, false) == doctest::Approx(expected)); + // never more than on a straight road + CHECK(room(radius, 0.0, true) < kRoadHalfwidth); + } +} + +TEST_CASE("ring room: a slanted road takes less on the side it leans away from") { + for (double const radius : {8.0, 15.0, 50.0}) { + for (double const slant : {pi / 6.0, pi / 4.0}) { + CAPTURE(radius); + CAPTURE(slant); + auto const towards{room(radius, slant, true)}; + auto const away{room(radius, slant, false)}; + CHECK(away >= 0.0); + CHECK(away < towards); + // the editor took the room of the acute corner on both sides + CHECK(towards < straight_reach(kRingHalfwidth, kRoadHalfwidth, pi / 2.0 - slant, true)); + } + } + // on a straight road the obtuse corner takes less than the acute one too + CHECK(room(1.0e6, pi / 4.0, false) < room(1.0e6, pi / 4.0, true)); + // leaving the smallest ring as sharply as the editor allows, 30 degrees off it, the edge on the side the road leans away from + // is outside the ring all along: there's no point to measure to, and the editor keeps the room it took before + CHECK(room(8.0, pi / 3.0, false) < 0.0); + CHECK(room(8.0, pi / 3.0, true) > 0.0); + CHECK(room(15.0, pi / 3.0, false) >= 0.0); +} + +TEST_CASE("ring room: none for a road going inwards") { + CHECK(room(15.0, pi * 0.75, true) < 0.0); + CHECK(room(15.0, pi, true) < 0.0); + CHECK(editor_ring::edge_room(glm::dvec2{0.0}, 0.0, glm::dvec2{1.0, 0.0}, glm::dvec2{1.0, 0.0}, glm::dvec2{0.0, 1.0}, 1.0, 1.0) < 0.0); +} + +TEST_CASE("ring room: a road wider than the ring is round still meets its edge, sooner than on a straight road") { + // two lanes each way on the smallest roundabout: the edge of the road starts outside the ring + double const halfwidth{7.0}; + double const radius{8.0}; + double const expected{radius * std::atan2(halfwidth, std::sqrt((radius + kRingHalfwidth) * (radius + kRingHalfwidth) - halfwidth * halfwidth))}; + CHECK(room(radius, 0.0, true, kRingHalfwidth, halfwidth) == doctest::Approx(expected)); + CHECK(room(radius, 0.0, true, kRingHalfwidth, halfwidth) < halfwidth); +} + +TEST_CASE("ring room: roads joined to roundabouts of the radii the editor allows") { + // the smallest roundabout took two roads; three were too many for it + CHECK(fit(8.0, 2, false)); + CHECK_FALSE(fit(8.0, 3, false)); + CHECK(fit(8.0, 3, true)); + // four roads from 11 m + CHECK(fit(11.0, 4, true)); + CHECK(fit(15.0, 4, true)); + // six from 16 m, where they took 17 m before + CHECK_FALSE(fit(16.0, 6, false)); + CHECK(fit(16.0, 6, true)); + CHECK(fit(25.0, 6, true)); + // and more on the large ones + CHECK(fit(50.0, 8, true)); + CHECK(fit(200.0, 30, true)); +} + +TEST_CASE("ring room: a short piece of the ring is left between junctions, so small roundabouts take three or four roads") { + // the ring goes on past a piece of it, which can be much shorter than a road of its own + CHECK(editor_ring::shortest_piece < kShortestRoad); + CHECK(editor_ring::shortest_piece > 0.25); // further apart than ends taken for joined + // with the shortest road left between them, and a junction growing by as much next to the end of an arc, three roads + // didn't always fit on the smallest roundabout, nor four on one of 10 m + CHECK_FALSE(fit(8.0, 3, true, kShortestRoad, true)); + CHECK_FALSE(fit(10.0, 4, true, kShortestRoad, false)); + // they do now, wherever they join the ring + CHECK(fits(8.0, 3)); + CHECK(fits(10.0, 4)); + CHECK(fits(9.6, 4)); + // four on the smallest one would take smaller corners + CHECK_FALSE(fits(8.0, 4)); + // and the larger ones take more + CHECK(fits(15.0, 6)); + CHECK(fits(25.0, 8)); +} From 236a25eacbb41d287b51172e45bdc470468f92c7 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 05:23:53 +0100 Subject: [PATCH 13/27] Speed table: report a signal index that points past the end of the table (#489) * fix(ai): report a signal index past the end of the speed table TableTraceRoute() drops SemNextIndex / SemNextStopIndex when they point past the end of the speed table. This used to catch the indices TablePurger() and TableCheck() left behind; #178 fixed both, and nothing else shrinks the table without resetting them, so the check should never fire. It stays as a safety net, but now writes to errors.txt when it does fire (vehicle, index, table size, last track and its distance, scan range), so a new way of getting there is noticed instead of being hidden. Not seen in the scenario suite (37 cases) nor in two runs of the whole L053 poranek scenery with every train driven by AI (about 75 min of simulation each). * fix(ai): the stale index report captures what it uses and is built with std::format --- vehicle/Driver.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index 086ff43ad..0c2568ad3 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -575,15 +575,21 @@ void TController::TableTraceRoute(double fDistance, TDynamicObject *pVehicle) } else { if( iTableDirection == 0 ) { return; } - // NOTE: belt and braces; TablePurger() used to leave these pointing past the end of the table - if( SemNextIndex != npos - && SemNextIndex >= sSpeedTable.size() ) { - SemNextIndex = npos; - } - if( SemNextStopIndex != npos - && SemNextStopIndex >= sSpeedTable.size() ) { - SemNextStopIndex = npos; - } + // NOTE: belt and braces; TablePurger() used to leave these pointing past the end of the table. + // nothing is known to do that any more, so say so when it happens + auto const dropstaleindex = [this, fDistance]( std::size_t &Index, std::string_view const Name ) { + if( Index == npos + || Index < sSpeedTable.size() ) { + return; + } + ErrorLog( std::format( + "Speed table for {}: {} {} points past the end of the table ({} records), last track {} at {:.1f} m, scan range {:.1f} m; reset", + OwnerName(), Name, Index, sSpeedTable.size(), + ( iLast >= 0 && sSpeedTable[ iLast ].trTrack != nullptr ? sSpeedTable[ iLast ].trTrack->name() : "none" ), + ( iLast >= 0 ? sSpeedTable[ iLast ].fDist : 0.0 ), fDistance ) ); + Index = npos; }; + dropstaleindex( SemNextIndex, "SemNextIndex" ); + dropstaleindex( SemNextStopIndex, "SemNextStopIndex" ); // kontynuacja skanowania od ostatnio sprawdzonego toru (w ostatniej pozycji zawsze jest tor) if( SemNextStopIndex != npos && sSpeedTable[SemNextStopIndex].fVelNext == 0.0 ) { From 781278463215b21300a9c72cc9c7d91cf7ea8903 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 05:24:12 +0100 Subject: [PATCH 14/27] fix(scripting): hold the Lua screen heap at each allocation on 64-bit Windows too (#490) * fix(scripting): hold the Lua screen heap at each allocation on 64-bit Windows too LuaJIT 2.0 on x64, the game's runtime on Windows, makes no state with an allocator of the game's, so a Lua screen's memory was checked only by the instruction hook every 1000 instructions. A loop doubling a string (s = s .. s, about 50 instructions) went on to LuaJIT's own heap limit: the unit test binary peaked at 1271 MB. The state is now made with luaL_newstate() and the screen's counting allocator is put in front of LuaJIT's own with lua_setallocf, which LuaJIT 2.0 has. LuaJIT's allocator still makes every block, so its heap stays where 2.0 on x64 needs it; the screen's allocator refuses a block that would take the screen over twice its limit during a script call, and LuaJIT raises "not enough memory" before the string is made. The same path now runs with every LuaJIT, so the lua_newstate probe is gone. LuaJIT's allocator is put back before lua_close, which frees its arena only then. The same loop now peaks at 310 MB with the game's 128 MB limit. The limit is read per screen, so the unit tests use 32 MB: a new test runs the doubling loop, and the one-concatenation test, skipped on Windows until now, runs everywhere. Follows up remark 4 of the review of #356. * fix(lua): the two memory globals behind functions, and the default order SonarCloud: the limit setting and the peak were mutable globals (S5421), the peak loop used relaxed order (S8417) and had an empty body (S108). They are function-local statics now, the loop uses the default order and says why it loops. --- script_screens_doc.md | 11 +- scripting/luaprogram.cpp | 162 ++++++++++++++----------- scripting/scriptscreenprogram.h | 14 +-- tests/unit/test_script_screen_host.cpp | 52 ++++++-- 4 files changed, 146 insertions(+), 93 deletions(-) diff --git a/script_screens_doc.md b/script_screens_doc.md index 723de28ea..3e9248d11 100644 --- a/script_screens_doc.md +++ b/script_screens_doc.md @@ -144,12 +144,11 @@ Besides the 200 million instructions of a call, a Lua screen is held to what run - memory: a screen holds at most 128 MB: its Lua heap and the pixels of its images, fonts and sprites (4 bytes a pixel of an image, 1 of a font or a sprite). An object that would take the screen over is refused (`memory limit exceeded`), and a screen found holding more stops with that error. Garbage doesn't count: the check collects it - first. Where LuaJIT takes an allocator of the game's (2.1 in its GC64 mode), anything over twice the limit is refused - as it is asked for (`not enough memory`); the game's LuaJIT 2.0 on 64-bit Windows takes none, and there the heap is - checked every thousand instructions and before the calls below, and whatever a script makes between two checks is - made whole first: every concatenation (`a .. b`) within one interval of a thousand instructions, so a loop doubling a - string (`for i = 1, 11 do s = s .. s end` on a 1 MB `s`) gets to LuaJIT's own heap limit of about 2 GB before the - check sees it; + first, every thousand instructions and before the calls below. Between the checks the screen's heap goes through a + counter of the game's, in front of LuaJIT's own allocator, which refuses a block that would take the screen over + twice the limit as it is asked for (`not enough memory`, an error the script may catch). So what one instruction + makes is held as well: a loop doubling a string (`for i = 1, 11 do s = s .. s end` on a 1 MB `s`) stops at the + concatenation that would go over 256 MB, not at LuaJIT's own heap limit of about 2 GB; - `string.rep` makes no string over 1 MB; `string.format`, `table.concat` and `string.gsub` (with a string or a table to replace with) refuse a result that may be over the memory of a screen, counted from the lengths of what they are given; diff --git a/scripting/luaprogram.cpp b/scripting/luaprogram.cpp index a490a9814..a79018a3d 100644 --- a/scripting/luaprogram.cpp +++ b/scripting/luaprogram.cpp @@ -32,7 +32,7 @@ http://mozilla.org/MPL/2.0/. #include #include -#include +#include #include #include #include @@ -57,22 +57,61 @@ constexpr char sprite_metatable[]{"eu07.sprite"}; // the address is the key of the program in the registry of its state constexpr char program_key{0}; -// the memory of a screen: what its Lua heap holds, when the allocator counts it, and the pixels of its images, fonts -// and sprites, which the objects keep outside the heap +// what set_lua_screen_memory_limit() set +std::atomic &memory_limit_setting() +{ + static std::atomic setting{max_screen_memory}; + return setting; +} + +// what lua_screen_memory_peak() gives +std::atomic &memory_peak() +{ + static std::atomic peak{0}; + return peak; +} + +// the memory of a screen: what its Lua heap holds and the pixels of its images, fonts and sprites, which the objects +// keep outside the heap struct screen_memory { + std::size_t limit{max_screen_memory}; // what the screen may hold, read when its state is made std::size_t heap{0}; std::size_t objects{0}; - bool counted{false}; // the state was made with limited_alloc + std::size_t peak{0}; // the most the screen held bool enforced{false}; // a call into the script is in progress: the allocator refuses what goes over the limit // what the screen holds when it is checked next (lua_program::over_memory) with a full collection std::size_t collect_at{max_screen_memory}; + // LuaJIT's own allocator of the state, which limited_alloc gives the blocks to + lua_Alloc base{nullptr}; + void *base_data{nullptr}; }; -// the allocator of a screen's state (lua_newstate), which refuses a block that would take the screen over twice -// max_screen_memory (what it holds, and its garbage between the collections) while a call into the script is in -// progress: LuaJIT raises "not enough memory" there, in the protected call. the game's own work between the calls isn't -// refused, as it isn't protected +// keeps the most the screen held +void note_peak(screen_memory &Memory) +{ + auto const held{Memory.heap + Memory.objects}; + if (held <= Memory.peak) + { + return; + } + Memory.peak = held; + auto &peak{memory_peak()}; + auto seen{peak.load()}; + while (held > seen && false == peak.compare_exchange_weak(seen, held)) + { + // a failed exchange put the value another screen stored in seen; try again while held is still more + } +} + +// the allocator of a screen's state, put in front of LuaJIT's own (lua_setallocf) once the state is made: LuaJIT 2.0 +// on x64 (the game's on Windows) and 2.1 on x64 without GC64 make no state with an allocator of the game's +// (lua_newstate gives nullptr), as their heap has to stay in the low addresses only their own allocator keeps to. so +// LuaJIT's allocator still makes every block; this one counts them, and refuses a block that would take the screen over +// twice its limit (what it holds, and its garbage between the collections) while a call into the script is in +// progress: LuaJIT raises "not enough memory" there, in the protected call, before the block is made. that holds what +// one instruction makes, which the instruction hook sees only once it is made (a concatenation, a .. b). the game's own +// work between the calls isn't refused, as it isn't protected void *limited_alloc(void *Data, void *Block, std::size_t Old, std::size_t New) { auto &memory{*static_cast(Data)}; @@ -80,20 +119,15 @@ void *limited_alloc(void *Data, void *Block, std::size_t Old, std::size_t New) { Old = 0; } - if (New == 0) - { - std::free(Block); - memory.heap -= Old; - return nullptr; - } - if (New > Old && memory.enforced && memory.heap - Old + New + memory.objects > 2 * max_screen_memory) + if (New > Old && memory.enforced && memory.heap - std::min(Old, memory.heap) + New + memory.objects > 2 * memory.limit) { return nullptr; } - auto *result{std::realloc(Block, New)}; - if (result != nullptr) + auto *result{memory.base(memory.base_data, Block, Old, New)}; + if (New == 0 || result != nullptr) { - memory.heap = memory.heap - Old + New; + memory.heap = memory.heap - std::min(Old, memory.heap) + New; + note_peak(memory); } return result; } @@ -111,6 +145,12 @@ class lua_program final : public program { // the finalizers lua_close runs aren't counted: the budget of the last call may be spent lua_sethook(m_state, nullptr, 0, 0); + // LuaJIT's own allocator back: lua_close frees the whole heap of its allocator only when the state has it, + // and otherwise leaves the heap's own bookkeeping behind + if (memory.base != nullptr) + { + lua_setallocf(m_state, memory.base, memory.base_data); + } lua_close(m_state); } } @@ -130,7 +170,7 @@ class lua_program final : public program char const *stopped{nullptr}; // why the call in progress is being stopped: the hook raises it at every instruction screen_memory memory; - // true when the screen would hold more than max_screen_memory with Adding bytes more. checked with a full collection + // true when the screen would hold more than its limit with Adding bytes more. checked with a full collection // once it has made a quarter of the limit since the last one, so a screen near its limit isn't collected over and // over bool over_memory(lua_State *L, std::size_t Adding); @@ -156,20 +196,15 @@ lua_program *program_of(lua_State *L) bool lua_program::over_memory(lua_State *L, std::size_t const Adding) { - auto const used{[this, L] { - auto const heap{memory.counted ? memory.heap - : static_cast(lua_gc(L, LUA_GCCOUNT, 0)) * 1024 + static_cast(lua_gc(L, LUA_GCCOUNTB, 0))}; - return heap + memory.objects; - }}; - if (used() + Adding <= memory.collect_at) + if (memory.heap + memory.objects + Adding <= memory.collect_at) { return false; } // what is garbage doesn't count lua_gc(L, LUA_GCCOLLECT, 0); - auto const held{used()}; - memory.collect_at = std::max(max_screen_memory, held + max_screen_memory / 4); - return held + Adding > max_screen_memory; + auto const held{memory.heap + memory.objects}; + memory.collect_at = std::max(memory.limit, held + memory.limit / 4); + return held + Adding > memory.limit; } void count_hook(lua_State *L, lua_Debug * /*Debug*/) @@ -188,7 +223,7 @@ void count_hook(lua_State *L, lua_Debug * /*Debug*/) } else if (self->over_memory(L, 0)) { - // what the allocator doesn't refuse (where the screen has none of its own) is caught here + // what the allocator lets through, up to twice the limit with the garbage, is caught here self->stopped = "memory limit exceeded"; } } @@ -208,10 +243,17 @@ void reserve_memory(lua_State *L, std::size_t const Bytes) { if (auto *self{program_of(L)}; self != nullptr && self->over_memory(L, Bytes)) { - luaL_error(L, "memory limit exceeded (%d MB)", static_cast(max_screen_memory / (1024 * 1024))); + luaL_error(L, "memory limit exceeded (%d MB)", static_cast(self->memory.limit / (1024 * 1024))); } } +// the memory the screen of the state may hold +std::size_t memory_limit(lua_State *L) +{ + auto const *self{program_of(L)}; + return self != nullptr ? self->memory.limit : max_screen_memory; +} + // objects of the api ------------------------------------------------------------------------------------------------- // where the userdata of an object keeps the bytes it counts in the screen's memory, after the object @@ -230,6 +272,7 @@ template std::remove_cvref_t *push_object(lua_State *L, if (auto *self{program_of(L)}; self != nullptr) { self->memory.objects += Bytes; + note_peak(self->memory); } luaL_getmetatable(L, Metatable); lua_setmetatable(L, -2); @@ -855,7 +898,7 @@ int api_repeat(lua_State *L) // the result may be over the memory of a screen. what they make otherwise is counted with the rest of the heap int too_large(lua_State *L, char const *Function) { - return luaL_error(L, "%s: the result may be over the memory of a screen (%d MB)", Function, static_cast(max_screen_memory / (1024 * 1024))); + return luaL_error(L, "%s: the result may be over the memory of a screen (%d MB)", Function, static_cast(memory_limit(L) / (1024 * 1024))); } // calls the library's own function, the upvalue, with the arguments, and returns what it returns @@ -878,7 +921,7 @@ int api_format(lua_State *L) { total += lua_type(L, idx) == LUA_TSTRING ? 4.0 * static_cast(lua_objlen(L, idx)) : 512.0; } - if (total > static_cast(max_screen_memory)) + if (total > static_cast(memory_limit(L))) { return too_large(L, "string.format"); } @@ -894,6 +937,7 @@ int api_concat(lua_State *L) luaL_optlstring(L, 2, "", &separator); auto const first{luaL_optinteger(L, 3, 1)}; auto const last{lua_isnoneornil(L, 4) ? static_cast(lua_objlen(L, 1)) : luaL_checkinteger(L, 4)}; + auto const limit{static_cast(memory_limit(L))}; auto total{0.0}; for (auto idx = first; idx <= last; ++idx) { @@ -906,7 +950,7 @@ int api_concat(lua_State *L) { break; } - if (total > static_cast(max_screen_memory)) + if (total > limit) { return too_large(L, "table.concat"); } @@ -978,7 +1022,7 @@ int api_pattern(lua_State *L) { auto const size{static_cast(subject)}; auto const matches{lua_isnumber(L, 4) ? std::clamp(static_cast(lua_tonumber(L, 4)), 0.0, size + 1.0) : size + 1.0}; - if (auto const replaced{replacement_length(L, 3, size, matches)}; replaced.has_value() && size + *replaced > static_cast(max_screen_memory)) + if (auto const replaced{replacement_length(L, 3, size, matches)}; replaced.has_value() && size + *replaced > static_cast(memory_limit(L))) { return too_large(L, name); } @@ -1195,46 +1239,20 @@ int call_render(lua_State *L) return 1; } -// true when a screen's state can be made with an allocator of its own: LuaJIT 2.0 on x64, and 2.1 on x64 without GC64, -// refuse one (lua_newstate gives nullptr, and writes so to stderr: 2.0 isn't asked) -bool custom_allocator_works() -{ -#if LUAJIT_VERSION_NUM < 20100 - if constexpr (sizeof(void *) == 8) - { - return false; - } -#endif - static bool const works{[] { - screen_memory probe; - auto *state{lua_newstate(limited_alloc, &probe)}; - if (state == nullptr) - { - return false; - } - lua_close(state); - return true; - }()}; - return works; -} - bool lua_program::start() { - // the screen's own allocator counts its memory, where LuaJIT takes one - if (custom_allocator_works()) - { - m_state = lua_newstate(limited_alloc, &memory); - memory.counted = m_state != nullptr; - } - if (m_state == nullptr) - { - m_state = luaL_newstate(); - } + m_state = luaL_newstate(); if (m_state == nullptr) { ErrorLog(std::format("Lua screen \"{}\": failed to create the state", script)); return false; } + // the screen's allocator in front of LuaJIT's own, counting from what the state holds already + memory.limit = memory_limit_setting().load(); + memory.collect_at = memory.limit; + memory.heap = static_cast(lua_gc(m_state, LUA_GCCOUNT, 0)) * 1024 + static_cast(lua_gc(m_state, LUA_GCCOUNTB, 0)); + memory.base = lua_getallocf(m_state, &memory.base_data); + lua_setallocf(m_state, limited_alloc, &memory); // no compiled code: LuaJIT calls no hooks in it, and the hook is what stops a script stuck in a loop luaJIT_setmode(m_state, 0, LUAJIT_MODE_ENGINE | LUAJIT_MODE_OFF); open_libraries(); @@ -1340,9 +1358,15 @@ class lua_runtime_host final : public runtime } // namespace -bool lua_screen_memory_allocator() +void set_lua_screen_memory_limit(std::size_t const Bytes) { - return custom_allocator_works(); + memory_limit_setting().store(Bytes); + memory_peak().store(0); +} + +std::size_t lua_screen_memory_peak() +{ + return memory_peak().load(); } std::unique_ptr make_lua_runtime() diff --git a/scripting/scriptscreenprogram.h b/scripting/scriptscreenprogram.h index 32fd493ef..10bed2124 100644 --- a/scripting/scriptscreenprogram.h +++ b/scripting/scriptscreenprogram.h @@ -39,16 +39,14 @@ constexpr std::size_t max_log_line{1024}; // bytes of the text, a longer one is // the largest file a screen reads: its script or module, a file below its folder constexpr std::uintmax_t max_screen_file{16 * 1024 * 1024}; // the memory a Lua screen may hold: its Lua heap, and the pixels of its images, fonts and sprites. checked with a full -// collection, so its garbage doesn't count; between the collections it may take the screen up to twice this +// collection, so its garbage doesn't count; between the collections it may take the screen up to twice this, which +// the screen's allocator refuses to go over as each block is asked for constexpr std::size_t max_screen_memory{128 * 1024 * 1024}; -// true when the Lua screens count their memory in an allocator of their own, which refuses what goes over -// max_screen_memory as it is asked for: LuaJIT 2.1 in its GC64 mode, a 32-bit build. LuaJIT 2.0 on x64 (the game's on -// Windows) and 2.1 on x64 without GC64 take no allocator; there the memory is checked by the instruction hook every -// so many instructions, and before what makes images and large strings in one call (string.rep, string.format, -// table.concat, string.gsub), but not at the concatenation operator: one concatenation of large strings is made -// whole, as far as LuaJIT's own heap goes (2 GB on x64), and the screen is stopped at the next check -bool lua_screen_memory_allocator(); +// for the unit tests, which fill the memory of a screen and stay small: the memory a Lua screen made from now on may +// hold in place of max_screen_memory, and the most any Lua screen held since it was set (its heap and its objects) +void set_lua_screen_memory_limit(std::size_t Bytes); +std::size_t lua_screen_memory_peak(); struct pending_command { diff --git a/tests/unit/test_script_screen_host.cpp b/tests/unit/test_script_screen_host.cpp index dc1cfa2f8..519e928de 100644 --- a/tests/unit/test_script_screen_host.cpp +++ b/tests/unit/test_script_screen_host.cpp @@ -1267,13 +1267,25 @@ for i = 1, 10000000 do kept[i] = ("x"):rep(1000) .. i end return { render = function(state) return eu07.image(1, 1, { 255, 255, 255 }) end } )"}; -// a concatenation of 320 MB in one operation, from a string of 64 MB: only an allocator of the screen's own refuses -// it as it is made +// the memory limit of the Lua screens made while it lives, in place of max_screen_memory: a test that fills the memory +// of a screen stays small +class screen_memory_limit { + public: + explicit screen_memory_limit(std::size_t const Bytes) { script_screens::set_lua_screen_memory_limit(Bytes); } + ~screen_memory_limit() { script_screens::set_lua_screen_memory_limit(script_screens::max_screen_memory); } + screen_memory_limit(screen_memory_limit const &) = delete; + screen_memory_limit &operator=(screen_memory_limit const &) = delete; +}; + +constexpr std::size_t small_screen_memory{32 * 1024 * 1024}; + +// with small_screen_memory: a concatenation of 80 MB in one operation, from a string of 8 MB, refused as it is made, in +// the pcall, as the instruction hook would see it only once it is made constexpr std::string_view one_concatenation_script{R"( local a = ("x"):rep(1024 * 1024) -for i = 1, 6 do a = a .. a end -local ok, message = pcall(function() return #(a .. a .. a .. a .. a) end) -local refused = #a == 64 * 1024 * 1024 and not ok and message:find("not enough memory", 1, true) ~= nil +for i = 1, 3 do a = a .. a end +local ok, message = pcall(function() return #(a .. a .. a .. a .. a .. a .. a .. a .. a .. a) end) +local refused = #a == 8 * 1024 * 1024 and not ok and message:find("not enough memory", 1, true) ~= nil a = nil return { render = function(state) @@ -1282,6 +1294,14 @@ return { } )"}; +// doubles a string to 2 GB, 64 times small_screen_memory, in some fifty instructions: fewer than the thousand after +// which the instruction hook looks at the heap +constexpr std::string_view doubling_script{R"( +local s = ("x"):rep(1024 * 1024) +for i = 1, 11 do s = s .. s end +return { render = function(state) return eu07.image(1, 1, { 255, 255, 255 }) end } +)"}; + // white when a coroutine yields across xpcall, and xpcall without a handler is an error constexpr std::string_view xpcall_yield_script{R"( local resume = coroutine.wrap(function() @@ -1390,13 +1410,25 @@ TEST_CASE("lua screens: a screen holding more than its memory is switched off") CHECK(log.lines_with("memory limit exceeded").size() + log.lines_with("not enough memory").size() > 0); } -TEST_CASE("lua screens: with an allocator of the screen's own, a string made over the memory in one operation is refused") { - if (false == script_screens::lua_screen_memory_allocator()) { - MESSAGE("LuaJIT takes no allocator of the game's here (2.0, or 2.1 without GC64 on x64): not tested"); - return; - } +TEST_CASE("lua screens: a string made over the memory in one operation is refused") { + screen_memory_limit const limit{small_screen_memory}; script_folder const folder{"lua_one_concatenation"}; CHECK(first_pixel(folder.write("concatenation.lua", one_concatenation_script), "concatenation") == 255); + CHECK(script_screens::lua_screen_memory_peak() <= 2 * small_screen_memory); +} + +TEST_CASE("lua screens: a string doubled in a loop stops at the memory of the screen, not at LuaJIT's own limit") { + log_capture const log; + screen_memory_limit const limit{small_screen_memory}; + script_folder const folder{"lua_doubling"}; + check_switched_off(folder, "doubling.lua", doubling_script); + CHECK(log.lines_with("not enough memory").size() + log.lines_with("memory limit exceeded").size() > 0); + // past the limit between two checks of the hook, but refused before twice the limit (its garbage included). with + // LuaJIT 2.0 on x64 and no allocator in front of LuaJIT's own, this went on to its own limit, over 1 GB + auto const peak{script_screens::lua_screen_memory_peak()}; + CAPTURE(peak); + CHECK(peak > small_screen_memory); + CHECK(peak <= 2 * small_screen_memory); } TEST_CASE("lua screens: a coroutine yields across xpcall") { From ee14cefcb5be898b37195aa9d01d20e32c06dfae Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 05:24:38 +0100 Subject: [PATCH 15/27] fix(parser): an include at the very end of a text leaves the end of the data to the included file (#492) A file which ends right after the end of an include directive, with no line break after it, had the parser report its end as soon as the directive was read: eof() looked only at the text being read, not at the included file it still had to go through. A reader which stops at the end of the data, like deserialize_map() (the sound overrides), then read only the first line of the included file. eof() now also waits for the included file to end. The tokens themselves don't change, and a file with a line break after the end of its last include reports the end as before. The .fiz files of the wagons which broke the change of #100 (pkp/yb_v1, the directive at the very end without a line break) are read through on staging already; a test now keeps them that way. --- tests/unit/test_parser.cpp | 64 ++++++++++++++++++++++++++++++++++++++ utilities/parser.h | 6 ++-- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_parser.cpp b/tests/unit/test_parser.cpp index 2584218d0..ee82aca9a 100644 --- a/tests/unit/test_parser.cpp +++ b/tests/unit/test_parser.cpp @@ -696,6 +696,70 @@ TEST_CASE("parser: read line by line, a line starting with include is the direct CHECK(rest(word, false, "\n\r") == "one|two"); } +namespace { + +// the lines of a file, read the way the vehicle's .fiz is (TMoverParameters::LoadFIZ_Parse): line by line while the +// parser is ok +std::string fiz_lines(cParser &Parser) { + std::string joined; + while (Parser.ok()) { + auto const line{Parser.getToken(false, "\n\r")}; + if (line.empty()) { + continue; + } + if (false == joined.empty()) { + joined += '|'; + } + joined += line; + } + return joined; +} + +} // namespace + +TEST_CASE("parser: a file which ends right after the end of an include is read through, the included file too") { + // the shape of the .fiz files of the wagons (pkp/yb_v1/b84_pl_1.fiz): the directive, the file and its parameters + // each on a line of their own, and no line break after the end. the change of MaSzyna-EU07/maszyna#100 broke on these + test::scratch_folder const folder{"parser_include_at_end"}; + folder.write("yb.fiz.inc", "Mass=(p1)\r\nVmax=(p2)\r\nLength=20\r\n"); + folder.write("ended.fiz", "include\r\nyb.fiz.inc\r\n160\r\n80\r\nend"); + folder.write("newline.fiz", "include\r\nyb.fiz.inc\r\n160\r\n80\r\nend\r\n"); + + cParser ended("ended.fiz", cParser::buffer_FILE, folder.path()); + CHECK(fiz_lines(ended) == "Mass=160|Vmax=80|Length=20"); + cParser newline("newline.fiz", cParser::buffer_FILE, folder.path()); + CHECK(fiz_lines(newline) == "Mass=160|Vmax=80|Length=20"); + + SUBCASE("the end of the data shows once the included file is read through, not when its directive is") { + folder.write("pair.inc", "x y"); + cParser parser("include pair.inc end", cParser::buffer_TEXT, folder.path()); + CHECK(parser.getToken() == "x"); + CHECK_FALSE(parser.eof()); + CHECK(parser.getToken() == "y"); + CHECK(parser.eof()); + CHECK(parser.ok()); + CHECK(parser.getToken().empty()); + CHECK_FALSE(parser.ok()); + // the same as for a text with the included tokens in place of the directive + cParser same("x y", cParser::buffer_TEXT); + CHECK(same.getToken() == "x"); + CHECK_FALSE(same.eof()); + CHECK(same.getToken() == "y"); + CHECK(same.eof()); + } + SUBCASE("a reader which stops at the end of the data reads the whole included file") { + folder.write("map.inc", "alpha One\nbeta Two"); + for (auto const *const text : {"include map.inc end", "include map.inc end\n"}) { + CAPTURE(text); + cParser parser(text, cParser::buffer_TEXT, folder.path()); + std::map map; + deserialize_map(map, parser); + CHECK(map["alpha"] == "One"); + CHECK(map["beta"] == "Two"); + } + } +} + TEST_CASE("parser: an include can name several files to pick one from at random") { test::scratch_folder const folder{"parser_random_include"}; folder.write("only.inc", "chosen"); diff --git a/utilities/parser.h b/utilities/parser.h index 19fc34f18..fa4c2c597 100644 --- a/utilities/parser.h +++ b/utilities/parser.h @@ -62,10 +62,12 @@ class cParser //: public std::stringstream std::string out; readToken(out); return out == Value; }; + // the end of the data: of this text, and of the file included last in it, which an include directive at the very + // end of the text leaves to be read inline bool - eof() { - return mEofBit; }; + eof() const { + return mEofBit && ( mIncludeParser == nullptr || mIncludeParser->eof() ); }; inline bool ok() { From c65ba4f39aaeacb01cca47f298306375e830fb6c Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 05:24:45 +0100 Subject: [PATCH 16/27] fix(blackbox): a signal passed is told by its memory cell, not by the cell's position (#493) The record of a signal passed (0x32) took the number of the first signal of the map whose memory cell stands within a centimetre of the cell the train read. Two signals with their cells at one point (back to back, or a signal and a shunting signal on one post) both got the number of whichever came first on the map, so a pass of one could be written as a pass of the other. The number is now that of the signal with the very cell the event reads; basic_event::input_cell() gives it, for a getvalues event. The format doesn't change. A pass of a signal which isn't on the map is still written with 0xFFFFFFFF. --- simulation/blackboxrecorder.cpp | 7 ++++--- simulation/blackboxrecorder.h | 3 ++- world/Event.cpp | 12 ++++++++++++ world/Event.h | 3 +++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/simulation/blackboxrecorder.cpp b/simulation/blackboxrecorder.cpp index 5b224b666..345bae36c 100644 --- a/simulation/blackboxrecorder.cpp +++ b/simulation/blackboxrecorder.cpp @@ -722,8 +722,9 @@ std::uint32_t blackbox_recorder::known_id(TDynamicObject const *Vehicle) { return Vehicle != nullptr && Vehicle->bEnabled ? vehicle_id(Vehicle) : blackbox::no_vehicle; } -std::uint32_t blackbox_recorder::signal_at(glm::dvec3 const &Location) const { - auto const found{std::ranges::find_if(m_signals, [&Location](signal_entry const &Signal) { return glm::distance(Signal.location, Location) < 0.01; })}; +std::uint32_t blackbox_recorder::signal_of(TMemCell const *Cell) const { + // by the memory cell, not by its position: two signals can have their cells at one point + auto const found{std::ranges::find(m_signals, Cell, &signal_entry::cell)}; if (found == m_signals.end()) return blackbox::no_signal; return static_cast(std::distance(m_signals.begin(), found)); @@ -752,7 +753,7 @@ void blackbox_recorder::signal_passed(TDynamicObject const *Vehicle, basic_event if (m_writer == nullptr || Vehicle == nullptr) return; auto const location{Event.input_location()}; - m_writer->signal_passed({m_time, vehicle_id(Vehicle), signal_at(location), text_of(Event.name()), location, static_cast(Speed1), static_cast(Speed2), + m_writer->signal_passed({m_time, vehicle_id(Vehicle), signal_of(Event.input_cell()), text_of(Event.name()), location, static_cast(Speed1), static_cast(Speed2), static_cast(Trainspeed), static_cast(Overrun), Flags}); } diff --git a/simulation/blackboxrecorder.h b/simulation/blackboxrecorder.h index a3aaf5d0f..140503e39 100644 --- a/simulation/blackboxrecorder.h +++ b/simulation/blackboxrecorder.h @@ -106,7 +106,8 @@ private: std::uint32_t vehicle_id(TDynamicObject const *Vehicle); // the number of a vehicle still on the scenery, no_vehicle for none or one taken off it std::uint32_t known_id(TDynamicObject const *Vehicle); - std::uint32_t signal_at(glm::dvec3 const &Location) const; + // the number of the signal whose aspect the memory cell tells, no_signal for one which isn't on the map + std::uint32_t signal_of(TMemCell const *Cell) const; std::mutex m_mutex; std::array m_filebuffer{}; diff --git a/world/Event.cpp b/world/Event.cpp index c007b91dd..628e38ea7 100644 --- a/world/Event.cpp +++ b/world/Event.cpp @@ -440,6 +440,12 @@ basic_event::input_location() const { return glm::dvec3( 0, 0, 0 ); }; +TMemCell const * +basic_event::input_cell() const { + + return nullptr; +} + bool basic_event::is_keyword( std::string const &Token ) { // TODO: convert to array lookup if keyword list gets longer @@ -677,6 +683,12 @@ getvalues_event::input_location() const { return m_input.data_cell()->location(); // współrzędne podłączonej komórki pamięci } +TMemCell const * +getvalues_event::input_cell() const { + + return m_input.data_cell(); +} + // prepares event for use diff --git a/world/Event.h b/world/Event.h index 090d165d6..c86fb8275 100644 --- a/world/Event.h +++ b/world/Event.h @@ -85,6 +85,8 @@ public: virtual TCommandType input_command() const; virtual double input_value( int Index ) const; virtual glm::dvec3 input_location() const; + // the memory cell the data comes from, null if the event doesn't read one + virtual TMemCell const *input_cell() const; void group( scene::group_handle Group ); scene::group_handle group() const; std::string const &name() const { return m_name; } @@ -243,6 +245,7 @@ public: TCommandType input_command() const override; double input_value( int Index ) const override; glm::dvec3 input_location() const override; + TMemCell const *input_cell() const override; private: // methods From df95395dedea27147633a92d231ae7f99c47cc5d Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 05:24:58 +0100 Subject: [PATCH 17/27] docs/build: track_uneven_doc.md to docs/, the local ImGui changes listed, the audio license texts kept in ref/licenses (#495) * docs: track_uneven_doc.md from the root of the repository to docs/ (#237) The tool that grades the tracks points to its new place; directoryDescription.md names docs/. * docs: the local changes of the bundled ImGui (#236) docs/imgui_patches.md lists what imgui/ changes against upstream v1.91.9b-docking (io.ConfigViewportsNoAutoDetach, io.ConfigTooltipsWrapWidth, BufferingBar/Spinner, the glad loader, the main-window origin of the GLFW backend, the gamma of the OpenGL 3 backend) and in ImGuizmo, with the commits that brought them, so an update of ImGui carries them over. * build: the license texts of the audio DLLs from ref/licenses instead of downloads (#405) The Windows build downloaded 14 license texts on every run without a cache hit, from raw.githubusercontent.com, scm.orgis.org (mpg123) and sources.debian.org (LAME). They are now in ref/licenses, byte for byte as at the pinned URLs (-text in .gitattributes, so a checkout with CRLF doesn't change them), and the step copies them from there, still checked by their SHA-256. ref/licenses/README.md names the URL of each. The two release zips are still downloaded and cached as before. * docs: the ImAbs shim of ImGuizmo listed, stale comments of the DLL step, a plain docs/ row --- .gitattributes | 2 + .github/workflows/build_bin.yml | 63 +- directoryDescription.md | 1 + docs/imgui_patches.md | 52 ++ .../track_uneven_doc.md | 0 ref/licenses/README.md | 29 + ref/licenses/flac-COPYING.Xiph.txt | 29 + ref/licenses/lame-COPYING.txt | 481 +++++++++++ ref/licenses/libogg-COPYING.txt | 28 + ref/licenses/libsndfile-ALAC-LICENSE.txt | 170 ++++ ref/licenses/libsndfile-COPYING.txt | 503 ++++++++++++ ref/licenses/libsndfile-GSM610-COPYRIGHT.txt | 16 + ref/licenses/libvorbis-COPYING.txt | 28 + ref/licenses/mpg123-COPYING.txt | 772 ++++++++++++++++++ ref/licenses/openal-soft-BSD-3Clause.txt | 31 + ref/licenses/openal-soft-gsl-LICENSE.txt | 21 + .../openal-soft-mingw-w64-runtime.txt | 240 ++++++ ref/licenses/openal-soft-pffft-LICENSE.txt | 38 + .../openal-soft-winpthreads-COPYING.txt | 57 ++ ref/licenses/opus-COPYING.txt | 44 + tools/track_uneven_grade.py | 2 +- 21 files changed, 2570 insertions(+), 37 deletions(-) create mode 100644 docs/imgui_patches.md rename track_uneven_doc.md => docs/track_uneven_doc.md (100%) create mode 100644 ref/licenses/README.md create mode 100644 ref/licenses/flac-COPYING.Xiph.txt create mode 100644 ref/licenses/lame-COPYING.txt create mode 100644 ref/licenses/libogg-COPYING.txt create mode 100644 ref/licenses/libsndfile-ALAC-LICENSE.txt create mode 100644 ref/licenses/libsndfile-COPYING.txt create mode 100644 ref/licenses/libsndfile-GSM610-COPYRIGHT.txt create mode 100644 ref/licenses/libvorbis-COPYING.txt create mode 100644 ref/licenses/mpg123-COPYING.txt create mode 100644 ref/licenses/openal-soft-BSD-3Clause.txt create mode 100644 ref/licenses/openal-soft-gsl-LICENSE.txt create mode 100644 ref/licenses/openal-soft-mingw-w64-runtime.txt create mode 100644 ref/licenses/openal-soft-pffft-LICENSE.txt create mode 100644 ref/licenses/openal-soft-winpthreads-COPYING.txt create mode 100644 ref/licenses/opus-COPYING.txt diff --git a/.gitattributes b/.gitattributes index d2b789541..488a40d4b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,3 +4,5 @@ text=auto *.h text README text LICENSE text +# the license texts the Windows build ships, checked by their SHA-256: byte for byte as upstream, LF on every checkout +ref/licenses/*.txt -text diff --git a/.github/workflows/build_bin.yml b/.github/workflows/build_bin.yml index 230e814cf..13f36b0c7 100644 --- a/.github/workflows/build_bin.yml +++ b/.github/workflows/build_bin.yml @@ -180,9 +180,9 @@ jobs: -Recurse ` -Force - # The downloads of the next step, kept between the runs: a release or raw.githubusercontent.com out of reach then - # doesn't fail the build. The key is this file, which pins them; a cache of an older one is taken too, as the next - # step checks every file by its SHA-256 and downloads only those it doesn't have. + # The downloads of the next step, kept between the runs: a release out of reach then doesn't fail the build. The + # key is this file, which pins them; a cache of an older one is taken too, as the next step checks every file by + # its SHA-256 and downloads only those it doesn't have. - name: Restore the audio library downloads uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: @@ -199,7 +199,8 @@ jobs: # go with both variants. The exe links them by name: soft_oal.dll is shipped as OpenAL32.dll (as its readme says, # without the router), sndfile.dll as libsndfile-1.dll. Both are LGPL, so their license texts go with them, in # licenses/, with those of what the DLLs have built in (below); the libsndfile zip has none, its COPYING is taken - # from the source tree of the same tag. + # from the source tree of the same tag. Those texts are kept in ref/licenses (with where each comes from), so the + # build doesn't depend on the servers they come from. - name: Add the OpenAL Soft and libsndfile DLLs shell: pwsh timeout-minutes: 10 @@ -214,7 +215,7 @@ jobs: $pinned = [System.Collections.Generic.List[string]]::new() # the file of the URL with the given SHA-256: the one kept by a run before, else downloaded. named by its - # SHA-256 and the last part of its path, without the query: several license texts are named the same + # SHA-256 and the last part of its path, without the query function Get-Pinned([string] $Url, [string] $Sha256) { $name = "$Sha256-$([uri]::new($Url).Segments[-1])" $pinned.Add($name) @@ -223,7 +224,6 @@ jobs: Write-Host "$Url kept by a run before" return $file } - # not a browser's user agent, which Debian's server answers with a challenge page Invoke-WebRequest -Uri $Url -OutFile $file -UserAgent 'ci-download' -MaximumRetryCount 3 -RetryIntervalSec 10 -TimeoutSec 120 $hash = (Get-FileHash -Algorithm SHA256 -Path $file).Hash.ToLowerInvariant() if ($hash -ne $Sha256) { @@ -262,39 +262,30 @@ jobs: # The versions in sndfile.dll: those it names (libopus 1.4, libFLAC 1.4.2, libVorbis 1.3.7), mpg123 1.31.3 by # the SHA-512 of its source archive in the build paths it keeps, and libogg 1.3.5 and LAME 3.100 of the vcpkg # ports of the time (mid 2023). LAME's from Debian's copy of the 3.100 source, the same file as in LAME's own - # repository on SourceForge, which may answer a script with a challenge page + # repository on SourceForge. The texts are in ref/licenses, whose README names the URL of each; each is + # checked by its SHA-256, so an edit or a line ending changed on the way doesn't go out unnoticed $texts = [ordered]@{ - 'libsndfile-COPYING.txt' = @('https://raw.githubusercontent.com/libsndfile/libsndfile/1.2.2/COPYING' - 'ad01ea5cd2755f6048383c8d54c88459cd6fcb17757c5c8892f8c5ea060f6140') - 'libsndfile-ALAC-LICENSE.txt' = @('https://raw.githubusercontent.com/libsndfile/libsndfile/1.2.2/src/ALAC/LICENSE' - '232efbd83786e157286b0b96c68ebb673541b69b33036287bf1e5ec5067a49d9') - 'libsndfile-GSM610-COPYRIGHT.txt' = @('https://raw.githubusercontent.com/libsndfile/libsndfile/1.2.2/src/GSM610/COPYRIGHT' - '1bbe7119b1bcd1489e0f36cb95b8902f7f0ceec9a2f3a67394bc9f4709a4e0a7') - 'libogg-COPYING.txt' = @('https://raw.githubusercontent.com/xiph/ogg/v1.3.5/COPYING' - 'd2ab5758336489da61c12cc5bb757da5339c4ae9001f9bb0562b4370249af814') - 'libvorbis-COPYING.txt' = @('https://raw.githubusercontent.com/xiph/vorbis/v1.3.7/COPYING' - 'ec1815db59fcd302846df949d7424876cb2e2dc5ed1606c5fb0b36787b1cf43a') - 'flac-COPYING.Xiph.txt' = @('https://raw.githubusercontent.com/xiph/flac/1.4.2/COPYING.Xiph' - '6e58d3036f05e2a0d58af854c12a505ddbe75011d71a598a2170987f3b15408d') - 'opus-COPYING.txt' = @('https://raw.githubusercontent.com/xiph/opus/v1.4/COPYING' - '8338ce8d922bb4416ce3dd1e5680173332435e3f0755007ac7801ccd674fe682') - 'mpg123-COPYING.txt' = @('https://scm.orgis.org/view/mpg123/tags/1.31.3/COPYING?view=co' - 'c22482728a634a8dfdb4ff72a96d4c1ed64cd8f3e79335c401751ac591609366') - 'lame-COPYING.txt' = @('https://sources.debian.org/data/main/l/lame/3.100-6/COPYING' - 'bfe4a52dc4645385f356a8e83cc54216a293e3b6f1cb4f79f5fc0277abf937fd') - 'openal-soft-pffft-LICENSE.txt' = @('https://raw.githubusercontent.com/kcat/openal-soft/1.25.2/LICENSE-pffft' - '64056328b3e7bc104e24ef96accc1a7abead156f0c02d1b87c97e3f3a28030de') - 'openal-soft-gsl-LICENSE.txt' = @('https://raw.githubusercontent.com/kcat/openal-soft/1.25.2/gsl/LICENSE' - '4c21dc82a1c7186ea754fd59d504c00947953a3401fe8e24eaa44109ef8e2555') - 'openal-soft-BSD-3Clause.txt' = @('https://raw.githubusercontent.com/kcat/openal-soft/1.25.2/BSD-3Clause' - 'b5a08cf98996dd83aa906a72c163600f6cb17a65ce546a553815a1267abd43ff') - 'openal-soft-winpthreads-COPYING.txt' = @('https://raw.githubusercontent.com/mingw-w64/mingw-w64/v13.0.0/mingw-w64-libraries/winpthreads/COPYING' - '63263614cdd29f2f93cba85e992f041b31f9fc7b4033692f31269489a8a1b177') - 'openal-soft-mingw-w64-runtime.txt' = @('https://raw.githubusercontent.com/mingw-w64/mingw-w64/v13.0.0/COPYING.MinGW-w64-runtime/COPYING.MinGW-w64-runtime.txt' - 'e9b2dc02451ea29092a1f25fa0f3c07207ed421f1807dffb0c4e6dce69dee7bd') + 'libsndfile-COPYING.txt' = 'ad01ea5cd2755f6048383c8d54c88459cd6fcb17757c5c8892f8c5ea060f6140' + 'libsndfile-ALAC-LICENSE.txt' = '232efbd83786e157286b0b96c68ebb673541b69b33036287bf1e5ec5067a49d9' + 'libsndfile-GSM610-COPYRIGHT.txt' = '1bbe7119b1bcd1489e0f36cb95b8902f7f0ceec9a2f3a67394bc9f4709a4e0a7' + 'libogg-COPYING.txt' = 'd2ab5758336489da61c12cc5bb757da5339c4ae9001f9bb0562b4370249af814' + 'libvorbis-COPYING.txt' = 'ec1815db59fcd302846df949d7424876cb2e2dc5ed1606c5fb0b36787b1cf43a' + 'flac-COPYING.Xiph.txt' = '6e58d3036f05e2a0d58af854c12a505ddbe75011d71a598a2170987f3b15408d' + 'opus-COPYING.txt' = '8338ce8d922bb4416ce3dd1e5680173332435e3f0755007ac7801ccd674fe682' + 'mpg123-COPYING.txt' = 'c22482728a634a8dfdb4ff72a96d4c1ed64cd8f3e79335c401751ac591609366' + 'lame-COPYING.txt' = 'bfe4a52dc4645385f356a8e83cc54216a293e3b6f1cb4f79f5fc0277abf937fd' + 'openal-soft-pffft-LICENSE.txt' = '64056328b3e7bc104e24ef96accc1a7abead156f0c02d1b87c97e3f3a28030de' + 'openal-soft-gsl-LICENSE.txt' = '4c21dc82a1c7186ea754fd59d504c00947953a3401fe8e24eaa44109ef8e2555' + 'openal-soft-BSD-3Clause.txt' = 'b5a08cf98996dd83aa906a72c163600f6cb17a65ce546a553815a1267abd43ff' + 'openal-soft-winpthreads-COPYING.txt' = '63263614cdd29f2f93cba85e992f041b31f9fc7b4033692f31269489a8a1b177' + 'openal-soft-mingw-w64-runtime.txt' = 'e9b2dc02451ea29092a1f25fa0f3c07207ed421f1807dffb0c4e6dce69dee7bd' } foreach ($text in $texts.GetEnumerator()) { - $file = Get-Pinned $text.Value[0] $text.Value[1] + $file = Join-Path 'ref/licenses' $text.Key + $hash = (Get-FileHash -Algorithm SHA256 -Path $file).Hash.ToLowerInvariant() + if ($hash -ne $text.Value) { + throw "${file}: SHA-256 $hash, expected $($text.Value)" + } Copy-Item -Path $file -Destination (Join-Path $licenses $text.Key) -Force } diff --git a/directoryDescription.md b/directoryDescription.md index eb943fb95..9db4a248f 100644 --- a/directoryDescription.md +++ b/directoryDescription.md @@ -21,3 +21,4 @@ | utilities/ | Logging, timing, parsing, math, globals, crash reporter | | world/ | Tracks, traction, events, memory cells, stations | | vehicle/ | Train, dynamic objects, driver, gauges, camera | +| docs/ | Documentation | diff --git a/docs/imgui_patches.md b/docs/imgui_patches.md new file mode 100644 index 000000000..3266158b5 --- /dev/null +++ b/docs/imgui_patches.md @@ -0,0 +1,52 @@ +# Local changes of the bundled ImGui + +`imgui/` holds Dear ImGui **v1.91.9b-docking** (`IMGUI_VERSION "1.91.9b"`, the docking branch: upstream tag +[`v1.91.9b-docking`](https://github.com/ocornut/imgui/tree/v1.91.9b-docking)), the GLFW, OpenGL 2 and OpenGL 3 backends +of the same tag, and ImGuizmo. The changes below are ours: an update of ImGui has to carry them over, or drop them on +purpose. Most of them are marked in the code with a `MaSzyna` comment (`grep -n MaSzyna imgui/*`), but not every +changed line is. + +Compared with the upstream tag, these files are unchanged: `imgui_demo.cpp`, `imgui_draw.cpp`, `imgui_internal.h`, +`imgui_tables.cpp`, `imstb_rectpack.h`, `imstb_textedit.h`, `imstb_truetype.h`, `LICENSE.txt` and the backend headers +(`imgui_impl_glfw.h`, `imgui_impl_opengl2.h`, `imgui_impl_opengl3.h`). The backends are in `backends/` upstream, here +next to the rest. + +## ImGui itself + +| Change | Files | Since | Used by | +|--------|-------|-------|---------| +| `io.ConfigViewportsNoAutoDetach` (default `false`): a floating window stays inside its host viewport. A resize stops at the viewport's edge, a window left past the edge or too big for it is moved back and shrunk, and it gets a viewport (an OS window) of its own only when dragged with the cursor outside the host viewport. Tooltips and popups over the main viewport, or begun outside any window, stay in the main viewport. Upstream has no such option ([#236](https://github.com/MaSzyna-EU07/maszyna/pull/236); the closest upstream report is [ocornut/imgui#9594](https://github.com/ocornut/imgui/issues/9594)) | `imgui.h` (`ImGuiIO` field), `imgui.cpp`: its default in `ImGuiIO::ImGuiIO()`; `WindowStaysInHostViewport()`, `IsWindowBeingMoved()`, `KeepWindowInsideRect()`; the resize limit in `UpdateWindowManualResize()`; two places in `Begin()` (no late viewport, window kept inside the work rect); the fallback and `ViewportAllowPlatformMonitorExtend` in `UpdateSelectWindowViewport()` | 5fa03304e (#236), be4000880, d0ca44cd6 | `application/uilayer.cpp`, with the viewports on | +| `io.ConfigTooltipsWrapWidth` (default `0`, no wrapping): the text of `SetTooltip()` / `SetItemTooltip()` wraps at that width. `BeginTooltip()` is not affected | `imgui.h` (`ImGuiIO` field), `imgui.cpp` (default, `SetTooltipV()`) | be4000880 | `application/uilayer.cpp` (40 font sizes) | +| `ImGui::BufferingBar()` and `ImGui::Spinner()`, by zfedoran from [ocornut/imgui#1901](https://github.com/ocornut/imgui/issues/1901) | `imgui.h`, end of `imgui_widgets.cpp` | ae3cecfa4 (2019, for the progress bar of the loading screen of the time), carried over in 344034ec7 | nothing at present: can be dropped | +| `#define IMGUI_IMPL_OPENGL_LOADER_CUSTOM`: the OpenGL 3 backend uses glad, loaded by the simulator, instead of its own loader | `imconfig.h` | 344034ec7 | the OpenGL 3 backend | + +## Backends + +| Change | File | Since | +|--------|------|-------| +| With multi-viewports, ImGui positions are relative to the simulator's main window instead of the desktop, so the main viewport stays at (0,0) and the overlays, picking and editor gizmo work in window coordinates as without viewports. `MainWindowOrigin` in the backend data, `ImGui_ImplGlfw_UpdateMainWindowOrigin()` called from `NewFrame()`; the origin is subtracted from the mouse position (callback and `UpdateMouseData()`), the monitors' `MainPos` / `WorkPos` and `GetWindowPos()`, and added back in `CreateWindow()` and `SetWindowPos()` | `imgui_impl_glfw.cpp` | 476f3bf1b | +| GL functions from glad (``) instead of the system's `GL/gl.h` | `imgui_impl_opengl2.cpp` | 344034ec7 | +| GL functions from glad, with `stdafx.h` and `utilities/Globals.h` included for the renderer's settings | `imgui_impl_opengl3.cpp` | 344034ec7 | +| `GlslVersionString` is 128 bytes instead of 32, for the longer GLES version string the simulator passes | `imgui_impl_opengl3.cpp` | 344034ec7 | +| Gamma of the UI follows the renderer: the vertex shaders linearise the vertex colour (`pow(Color.rgb, 2.2)`); each fragment shader's output goes through `FBOUT()`, which applies `1/2.2` when `Global.gfx_shadergamma` is set and passes it through otherwise; with desktop GL and no shader gamma `GL_FRAMEBUFFER_SRGB` is enabled while the UI is drawn and restored after | `imgui_impl_opengl3.cpp` (`RenderDrawData()`, the shader sources, `CreateDeviceObjects()`) | 344034ec7 | + +## ImGuizmo + +From [CedricGuillemet/ImGuizmo](https://github.com/CedricGuillemet/ImGuizmo), added in 5a39ed519; the upstream commit +it was taken from isn't recorded. Changed in 344034ec7 for the ImGui API of 1.91: + +- `IMGUI_DEFINE_MATH_OPERATORS` is defined before the first `#include "imgui.h"` (ImGui 1.86 and later want it so). +- `ImGui::CaptureMouseFromApp()` is replaced by `ImGui::SetNextFrameWantCaptureMouse(true)` (six places). + +And since 5a39ed519, for the ImGui of the time: + +- A compatibility shim, `#define ImAbs(X)` when `ImAbs` isn't a macro (`ImGuizmo.cpp:42-44`). ImGui 1.91 has `ImAbs` + as an inline function in `imgui_internal.h`, so the macro is always defined now and hides that function in + `ImGuizmo.cpp`. It can be dropped. + +## Checking an update + +Download the files of the new tag (`imgui*.cpp`, `imgui*.h`, `imstb_*.h`, `imconfig.h`, and from `backends/` +`imgui_impl_glfw.*`, `imgui_impl_opengl2.*`, `imgui_impl_opengl3.*`), diff the files here against the tag listed at the +top, and apply that diff to the new files. The diff of the files here against `v1.91.9b-docking` is exactly the list +above. diff --git a/track_uneven_doc.md b/docs/track_uneven_doc.md similarity index 100% rename from track_uneven_doc.md rename to docs/track_uneven_doc.md diff --git a/ref/licenses/README.md b/ref/licenses/README.md new file mode 100644 index 000000000..10ff550eb --- /dev/null +++ b/ref/licenses/README.md @@ -0,0 +1,29 @@ +# License texts of the Windows audio DLLs + +The Windows build ships `OpenAL32.dll` (OpenAL Soft 1.25.2) and `libsndfile-1.dll` (libsndfile 1.2.2), and in +`licenses/` next to them the texts of those libraries and of what they have built in. The DLLs and OpenAL Soft's own +`COPYING` come from the release zips, which CI downloads; the texts below are kept here, so a build doesn't depend on +the servers they come from. CI copies them into `licenses/` and checks each one by the SHA-256 in +`.github/workflows/build_bin.yml` (step "Add the OpenAL Soft and libsndfile DLLs"). `.gitattributes` keeps them byte +for byte as upstream (`-text`), whatever the line ending settings of a checkout. What each text covers is in +`audio-libraries.txt`, which that step writes. + +| File | Taken from | SHA-256 | +|------|------------|---------| +| `libsndfile-COPYING.txt` | https://raw.githubusercontent.com/libsndfile/libsndfile/1.2.2/COPYING | `ad01ea5cd2755f6048383c8d54c88459cd6fcb17757c5c8892f8c5ea060f6140` | +| `libsndfile-ALAC-LICENSE.txt` | https://raw.githubusercontent.com/libsndfile/libsndfile/1.2.2/src/ALAC/LICENSE | `232efbd83786e157286b0b96c68ebb673541b69b33036287bf1e5ec5067a49d9` | +| `libsndfile-GSM610-COPYRIGHT.txt` | https://raw.githubusercontent.com/libsndfile/libsndfile/1.2.2/src/GSM610/COPYRIGHT | `1bbe7119b1bcd1489e0f36cb95b8902f7f0ceec9a2f3a67394bc9f4709a4e0a7` | +| `libogg-COPYING.txt` | https://raw.githubusercontent.com/xiph/ogg/v1.3.5/COPYING | `d2ab5758336489da61c12cc5bb757da5339c4ae9001f9bb0562b4370249af814` | +| `libvorbis-COPYING.txt` | https://raw.githubusercontent.com/xiph/vorbis/v1.3.7/COPYING | `ec1815db59fcd302846df949d7424876cb2e2dc5ed1606c5fb0b36787b1cf43a` | +| `flac-COPYING.Xiph.txt` | https://raw.githubusercontent.com/xiph/flac/1.4.2/COPYING.Xiph | `6e58d3036f05e2a0d58af854c12a505ddbe75011d71a598a2170987f3b15408d` | +| `opus-COPYING.txt` | https://raw.githubusercontent.com/xiph/opus/v1.4/COPYING | `8338ce8d922bb4416ce3dd1e5680173332435e3f0755007ac7801ccd674fe682` | +| `mpg123-COPYING.txt` | https://scm.orgis.org/view/mpg123/tags/1.31.3/COPYING?view=co | `c22482728a634a8dfdb4ff72a96d4c1ed64cd8f3e79335c401751ac591609366` | +| `lame-COPYING.txt` | https://sources.debian.org/data/main/l/lame/3.100-6/COPYING (the same file as in LAME 3.100) | `bfe4a52dc4645385f356a8e83cc54216a293e3b6f1cb4f79f5fc0277abf937fd` | +| `openal-soft-pffft-LICENSE.txt` | https://raw.githubusercontent.com/kcat/openal-soft/1.25.2/LICENSE-pffft | `64056328b3e7bc104e24ef96accc1a7abead156f0c02d1b87c97e3f3a28030de` | +| `openal-soft-gsl-LICENSE.txt` | https://raw.githubusercontent.com/kcat/openal-soft/1.25.2/gsl/LICENSE | `4c21dc82a1c7186ea754fd59d504c00947953a3401fe8e24eaa44109ef8e2555` | +| `openal-soft-BSD-3Clause.txt` | https://raw.githubusercontent.com/kcat/openal-soft/1.25.2/BSD-3Clause | `b5a08cf98996dd83aa906a72c163600f6cb17a65ce546a553815a1267abd43ff` | +| `openal-soft-winpthreads-COPYING.txt` | https://raw.githubusercontent.com/mingw-w64/mingw-w64/v13.0.0/mingw-w64-libraries/winpthreads/COPYING | `63263614cdd29f2f93cba85e992f041b31f9fc7b4033692f31269489a8a1b177` | +| `openal-soft-mingw-w64-runtime.txt` | https://raw.githubusercontent.com/mingw-w64/mingw-w64/v13.0.0/COPYING.MinGW-w64-runtime/COPYING.MinGW-w64-runtime.txt | `e9b2dc02451ea29092a1f25fa0f3c07207ed421f1807dffb0c4e6dce69dee7bd` | + +When a DLL is updated to another version, its texts here are replaced by those of the new version's source tree, and +their SHA-256 in the workflow with them. diff --git a/ref/licenses/flac-COPYING.Xiph.txt b/ref/licenses/flac-COPYING.Xiph.txt new file mode 100644 index 000000000..edd24f719 --- /dev/null +++ b/ref/licenses/flac-COPYING.Xiph.txt @@ -0,0 +1,29 @@ +Copyright (C) 2000-2009 Josh Coalson +Copyright (C) 2011-2022 Xiph.Org Foundation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +- Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +- Neither the name of the Xiph.Org Foundation nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/ref/licenses/lame-COPYING.txt b/ref/licenses/lame-COPYING.txt new file mode 100644 index 000000000..f5030495b --- /dev/null +++ b/ref/licenses/lame-COPYING.txt @@ -0,0 +1,481 @@ + GNU LIBRARY GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the library GPL. It is + numbered 2 because it goes with version 2 of the ordinary GPL.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Library General Public License, applies to some +specially designated Free Software Foundation software, and to any +other libraries whose authors decide to use it. You can use it for +your libraries, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if +you distribute copies of the library, or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link a program with the library, you must provide +complete object files to the recipients so that they can relink them +with the library, after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + Our method of protecting your rights has two steps: (1) copyright +the library, and (2) offer you this license which gives you legal +permission to copy, distribute and/or modify the library. + + Also, for each distributor's protection, we want to make certain +that everyone understands that there is no warranty for this free +library. If the library is modified by someone else and passed on, we +want its recipients to know that what they have is not the original +version, so that any problems introduced by others will not reflect on +the original authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that companies distributing free +software will individually obtain patent licenses, thus in effect +transforming the program into proprietary software. To prevent this, +we have made it clear that any patent must be licensed for everyone's +free use or not licensed at all. + + Most GNU software, including some libraries, is covered by the ordinary +GNU General Public License, which was designed for utility programs. This +license, the GNU Library General Public License, applies to certain +designated libraries. This license is quite different from the ordinary +one; be sure to read it in full, and don't assume that anything in it is +the same as in the ordinary license. + + The reason we have a separate public license for some libraries is that +they blur the distinction we usually make between modifying or adding to a +program and simply using it. Linking a program with a library, without +changing the library, is in some sense simply using the library, and is +analogous to running a utility program or application program. However, in +a textual and legal sense, the linked executable is a combined work, a +derivative of the original library, and the ordinary General Public License +treats it as such. + + Because of this blurred distinction, using the ordinary General +Public License for libraries did not effectively promote software +sharing, because most developers did not use the libraries. We +concluded that weaker conditions might promote sharing better. + + However, unrestricted linking of non-free programs would deprive the +users of those programs of all benefit from the free status of the +libraries themselves. This Library General Public License is intended to +permit developers of non-free programs to use free libraries, while +preserving your freedom as a user of such programs to change the free +libraries that are incorporated in them. (We have not seen how to achieve +this as regards changes in header files, but we have achieved it as regards +changes in the actual functions of the Library.) The hope is that this +will lead to faster development of free libraries. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, while the latter only +works together with the library. + + Note that it is possible for a library to be covered by the ordinary +General Public License rather than by this special one. + + GNU LIBRARY GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library which +contains a notice placed by the copyright holder or other authorized +party saying it may be distributed under the terms of this Library +General Public License (also called "this License"). Each licensee is +addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also compile or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + c) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + d) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the source code distributed need not include anything that is normally +distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Library General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/ref/licenses/libogg-COPYING.txt b/ref/licenses/libogg-COPYING.txt new file mode 100644 index 000000000..6111c6c5a --- /dev/null +++ b/ref/licenses/libogg-COPYING.txt @@ -0,0 +1,28 @@ +Copyright (c) 2002, Xiph.org Foundation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +- Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +- Neither the name of the Xiph.org Foundation nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/ref/licenses/libsndfile-ALAC-LICENSE.txt b/ref/licenses/libsndfile-ALAC-LICENSE.txt new file mode 100644 index 000000000..7d8595490 --- /dev/null +++ b/ref/licenses/libsndfile-ALAC-LICENSE.txt @@ -0,0 +1,170 @@ +Apache License + +Version 2.0, January 2004 + +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and +distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the +copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other +entities that control, are controlled by, or are under common control +with that entity. For the purposes of this definition, "control" means +(i) the power, direct or indirect, to cause the direction or management +of such entity, whether by contract or otherwise, or (ii) ownership +of fifty percent (50%) or more of the outstanding shares, or (iii) +beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising +permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, +including but not limited to software source code, documentation source, +and configuration files. + +"Object" form shall mean any form resulting from mechanical +transformation or translation of a Source form, including but not +limited to compiled object code, generated documentation, and +conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object +form, made available under the License, as indicated by a copyright +notice that is included in or attached to the work (an example is +provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object +form, that is based on (or derived from) the Work and for which the +editorial revisions, annotations, elaborations, or other modifications +represent, as a whole, an original work of authorship. For the purposes +of this License, Derivative Works shall not include works that remain +separable from, or merely link (or bind by name) to the interfaces of, +the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original +version of the Work and any modifications or additions to that Work or +Derivative Works thereof, that is intentionally submitted to Licensor +for inclusion in the Work by the copyright owner or by an individual +or Legal Entity authorized to submit on behalf of the copyright owner. +For the purposes of this definition, "submitted" means any form of +electronic, verbal, or written communication sent to the Licensor +or its representatives, including but not limited to communication +on electronic mailing lists, source code control systems, and issue +tracking systems that are managed by, or on behalf of, the Licensor +for the purpose of discussing and improving the Work, but excluding +communication that is conspicuously marked or otherwise designated in +writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity +on behalf of whom a Contribution has been received by Licensor and +subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions +of this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +copyright license to reproduce, prepare Derivative Works of, publicly +display, publicly perform, sublicense, and distribute the Work and such +Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except +as stated in this section) patent license to make, have made, use, +offer to sell, sell, import, and otherwise transfer the Work, where +such license applies only to those patent claims licensable by such +Contributor that are necessarily infringed by their Contribution(s) +alone or by combination of their Contribution(s) with the Work to which +such Contribution(s) was submitted. If You institute patent litigation +against any entity (including a cross-claim or counterclaim in a +lawsuit) alleging that the Work or a Contribution incorporated within +the Work constitutes direct or contributory patent infringement, then +any patent licenses granted to You under this License for that Work +shall terminate as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the +Work or Derivative Works thereof in any medium, with or without +modifications, and in Source or Object form, provided that You meet the +following conditions: + +You must give any other recipients of the Work or Derivative Works a +copy of this License; and + +You must cause any modified files to carry prominent notices stating +that You changed the files; and + +You must retain, in the Source form of any Derivative Works that You +distribute, all copyright, patent, trademark, and attribution notices +from the Source form of the Work, excluding those notices that do not +pertain to any part of the Derivative Works; and + +If the Work includes a "NOTICE" text file as part of its distribution, +then any Derivative Works that You distribute must include a readable +copy of the attribution notices contained within such NOTICE file, +excluding those notices that do not pertain to any part of the +Derivative Works, in at least one of the following places: within a +NOTICE text file distributed as part of the Derivative Works; within +the Source form or documentation, if provided along with the Derivative +Works; or, within a display generated by the Derivative Works, if and +wherever such third-party notices normally appear. The contents of the +NOTICE file are for informational purposes only and do not modify the +License. You may add Your own attribution notices within Derivative +Works that You distribute, alongside or as an addendum to the NOTICE +text from the Work, provided that such additional attribution notices +cannot be construed as modifying the License. You may add Your own +copyright statement to Your modifications and may provide additional +or different license terms and conditions for use, reproduction, or +distribution of Your modifications, or for any such Derivative Works as +a whole, provided Your use, reproduction, and distribution of the Work +otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, +any Contribution intentionally submitted for inclusion in the Work by +You to the Licensor shall be under the terms and conditions of this +License, without any additional terms or conditions. Notwithstanding +the above, nothing herein shall supersede or modify the terms of any +separate license agreement you may have executed with Licensor regarding +such Contributions. + +6. Trademarks. This License does not grant permission to use the trade +names, trademarks, service marks, or product names of the Licensor, +except as required for reasonable and customary use in describing the +origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or agreed +to in writing, Licensor provides the Work (and each Contributor +provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR +CONDITIONS OF ANY KIND, either express or implied, including, without +limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, +MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are +solely responsible for determining the appropriateness of using or +redistributing the Work and assume any risks associated with Your +exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, +whether in tort (including negligence), contract, or otherwise, unless +required by applicable law (such as deliberate and grossly negligent +acts) or agreed to in writing, shall any Contributor be liable to You +for damages, including any direct, indirect, special, incidental, or +consequential damages of any character arising as a result of this +License or out of the use or inability to use the Work (including but +not limited to damages for loss of goodwill, work stoppage, computer +failure or malfunction, or any and all other commercial damages or +losses), even if such Contributor has been advised of the possibility of +such damages. + +9. Accepting Warranty or Additional Liability. While redistributing the +Work or Derivative Works thereof, You may choose to offer, and charge a +fee for, acceptance of support, warranty, indemnity, or other liability +obligations and/or rights consistent with this License. However, in +accepting such obligations, You may act only on Your own behalf and +on Your sole responsibility, not on behalf of any other Contributor, +and only if You agree to indemnify, defend, and hold each Contributor +harmless for any liability incurred by, or claims asserted against, such +Contributor by reason of your accepting any such warranty or additional +liability. diff --git a/ref/licenses/libsndfile-COPYING.txt b/ref/licenses/libsndfile-COPYING.txt new file mode 100644 index 000000000..c396169ee --- /dev/null +++ b/ref/licenses/libsndfile-COPYING.txt @@ -0,0 +1,503 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + diff --git a/ref/licenses/libsndfile-GSM610-COPYRIGHT.txt b/ref/licenses/libsndfile-GSM610-COPYRIGHT.txt new file mode 100644 index 000000000..eba0e523b --- /dev/null +++ b/ref/licenses/libsndfile-GSM610-COPYRIGHT.txt @@ -0,0 +1,16 @@ +Copyright 1992, 1993, 1994 by Jutta Degener and Carsten Bormann, +Technische Universitaet Berlin + +Any use of this software is permitted provided that this notice is not +removed and that neither the authors nor the Technische Universitaet Berlin +are deemed to have made any representations as to the suitability of this +software for any purpose nor are held responsible for any defects of +this software. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. + +As a matter of courtesy, the authors request to be informed about uses +this software has found, about bugs in this software, and about any +improvements that may be of general interest. + +Berlin, 28.11.1994 +Jutta Degener +Carsten Bormann diff --git a/ref/licenses/libvorbis-COPYING.txt b/ref/licenses/libvorbis-COPYING.txt new file mode 100644 index 000000000..fb456a87b --- /dev/null +++ b/ref/licenses/libvorbis-COPYING.txt @@ -0,0 +1,28 @@ +Copyright (c) 2002-2020 Xiph.org Foundation + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +- Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +- Neither the name of the Xiph.org Foundation nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/ref/licenses/mpg123-COPYING.txt b/ref/licenses/mpg123-COPYING.txt new file mode 100644 index 000000000..14e14f01c --- /dev/null +++ b/ref/licenses/mpg123-COPYING.txt @@ -0,0 +1,772 @@ +This is the file that contains the terms of use, copying, etc. for the mpg123 distribution package. + +Main message, to include in "About ..." boxes, etc: + + Copyright (c) 1995-2020 by Michael Hipp and others, + free software under the terms of the LGPL v2.1 + +There is an attempt to cover the actual list of authors in the AUTHORS file. +Project maintainer since 2006 is Thomas Orgis and many people have contributed +since the Michael Hipp era, but he stays the initial source and it would +be impractical to count them all individually, so it's "and others". +Source files contain the phrase "the mpg123 project" to the same effect +in their license boilerplate; especially those that were added after +maintainership changed. The person mainly responsible for the first version +is usually named in the phrase "initially written by ...". + +All files in the distribution that don't carry a license note on their own are +licensed under the terms of the LGPL 2.1; exceptions may apply, especially to +files not in the official distribution but in the revision control repository. + +The formal license text follows. + +======================= +1. The LGPL version 2.1 +======================= + + + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + +==================== +2. The GPL version 2 +==================== + + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS diff --git a/ref/licenses/openal-soft-BSD-3Clause.txt b/ref/licenses/openal-soft-BSD-3Clause.txt new file mode 100644 index 000000000..b1c2dbd76 --- /dev/null +++ b/ref/licenses/openal-soft-BSD-3Clause.txt @@ -0,0 +1,31 @@ +Portions of this software are licensed under the BSD 3-Clause license. + +Copyright (c) 2015, Archontis Politis +Copyright (c) 2019, Anis A. Hireche +Copyright (c) 2019, Christopher Robinson +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of Spherical-Harmonic-Transform nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/ref/licenses/openal-soft-gsl-LICENSE.txt b/ref/licenses/openal-soft-gsl-LICENSE.txt new file mode 100644 index 000000000..aa58667a3 --- /dev/null +++ b/ref/licenses/openal-soft-gsl-LICENSE.txt @@ -0,0 +1,21 @@ +Copyright (c) 2015 Microsoft Corporation. All rights reserved. + +This code is licensed under the MIT License (MIT). + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/ref/licenses/openal-soft-mingw-w64-runtime.txt b/ref/licenses/openal-soft-mingw-w64-runtime.txt new file mode 100644 index 000000000..ca6a077e2 --- /dev/null +++ b/ref/licenses/openal-soft-mingw-w64-runtime.txt @@ -0,0 +1,240 @@ +MinGW-w64 runtime licensing +*************************** + +This program or library was built using MinGW-w64 and statically +linked against the MinGW-w64 runtime. Some parts of the runtime +are under licenses which require that the copyright and license +notices are included when distributing the code in binary form. +These notices are listed below. + + +======================== +Overall copyright notice +======================== + +Copyright (c) 2009, 2010, 2011, 2012, 2013 by the mingw-w64 project + +This license has been certified as open source. It has also been designated +as GPL compatible by the Free Software Foundation (FSF). + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + 1. Redistributions in source code must retain the accompanying copyright + notice, this list of conditions, and the following disclaimer. + 2. Redistributions in binary form must reproduce the accompanying + copyright notice, this list of conditions, and the following disclaimer + in the documentation and/or other materials provided with the + distribution. + 3. Names of the copyright holders must not be used to endorse or promote + products derived from this software without prior written permission + from the copyright holders. + 4. The right to distribute this software or to use it for any purpose does + not give you the right to use Servicemarks (sm) or Trademarks (tm) of + the copyright holders. Use of them is covered by separate agreement + with the copyright holders. + 5. If any files are modified, you must cause the modified files to carry + prominent notices stating that you changed the files and the date of + any change. + +Disclaimer + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED +OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +======================================== +getopt, getopt_long, and getop_long_only +======================================== + +Copyright (c) 2002 Todd C. Miller + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +Sponsored in part by the Defense Advanced Research Projects +Agency (DARPA) and Air Force Research Laboratory, Air Force +Materiel Command, USAF, under agreement number F39502-99-1-0512. + + * * * * * * * + +Copyright (c) 2000 The NetBSD Foundation, Inc. +All rights reserved. + +This code is derived from software contributed to The NetBSD Foundation +by Dieter Baron and Thomas Klausner. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + + +=============================================================== +gdtoa: Converting between IEEE floating point numbers and ASCII +=============================================================== + +The author of this software is David M. Gay. + +Copyright (C) 1997, 1998, 1999, 2000, 2001 by Lucent Technologies +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + + * * * * * * * + +The author of this software is David M. Gay. + +Copyright (C) 2005 by David M. Gay +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that the copyright notice and this permission notice and warranty +disclaimer appear in supporting documentation, and that the name of +the author or any of his current or former employers not be used in +advertising or publicity pertaining to distribution of the software +without specific, written prior permission. + +THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN +NO EVENT SHALL THE AUTHOR OR ANY OF HIS CURRENT OR FORMER EMPLOYERS BE +LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY +DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +SOFTWARE. + + * * * * * * * + +The author of this software is David M. Gay. + +Copyright (C) 2004 by David M. Gay. +All Rights Reserved +Based on material in the rest of /netlib/fp/gdota.tar.gz, +which is copyright (C) 1998, 2000 by Lucent Technologies. + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby +granted, provided that the above copyright notice appear in all +copies and that both that the copyright notice and this +permission notice and warranty disclaimer appear in supporting +documentation, and that the name of Lucent or any of its entities +not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER +IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. + + +========================= +Parts of the math library +========================= + +Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + +Developed at SunSoft, a Sun Microsystems, Inc. business. +Permission to use, copy, modify, and distribute this +software is freely granted, provided that this notice +is preserved. + + * * * * * * * + +Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + +Developed at SunPro, a Sun Microsystems, Inc. business. +Permission to use, copy, modify, and distribute this +software is freely granted, provided that this notice +is preserved. + + * * * * * * * + +FIXME: Cephes math lib +Copyright (C) 1984-1998 Stephen L. Moshier + +It sounds vague, but as to be found at +, it gives an +impression that the author could be willing to give an explicit +permission to distribute those files e.g. under a BSD style license. So +probably there is no problem here, although it could be good to get a +permission from the author and then add a license into the Cephes files +in MinGW runtime. At least on follow-up it is marked that debian sees the +version a-like BSD one. As MinGW.org (where those cephes parts are coming +from) distributes them now over 6 years, it should be fine. + +=================================== +Headers and IDLs imported from Wine +=================================== + +Some header and IDL files were imported from the Wine project. These files +are prominent maked in source. Their copyright belongs to contributors and +they are distributed under LGPL license. + +Disclaimer + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. diff --git a/ref/licenses/openal-soft-pffft-LICENSE.txt b/ref/licenses/openal-soft-pffft-LICENSE.txt new file mode 100644 index 000000000..5f1a8493f --- /dev/null +++ b/ref/licenses/openal-soft-pffft-LICENSE.txt @@ -0,0 +1,38 @@ +A modified PFFFT is included, with the following license. + +Copyright (c) 2023 Christopher Robinson + +Copyright (c) 2013 Julien Pommier ( pommier@modartt.com ) + +Copyright (c) 2004 the University Corporation for Atmospheric +Research ("UCAR"). All rights reserved. Developed by NCAR's +Computational and Information Systems Laboratory, UCAR, +www.cisl.ucar.edu. + +Redistribution and use of the Software in source and binary forms, +with or without modification, is permitted provided that the +following conditions are met: + +- Neither the names of NCAR's Computational and Information Systems +Laboratory, the University Corporation for Atmospheric Research, +nor the names of its sponsors or contributors may be used to +endorse or promote products derived from this Software without +specific prior written permission. + +- Redistributions of source code must retain the above copyright +notices, this list of conditions, and the disclaimer below. + +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions, and the disclaimer below in the +documentation and/or other materials provided with the +distribution. + +THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY, WHETHER IN AN +ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE +SOFTWARE. diff --git a/ref/licenses/openal-soft-winpthreads-COPYING.txt b/ref/licenses/openal-soft-winpthreads-COPYING.txt new file mode 100644 index 000000000..350770123 --- /dev/null +++ b/ref/licenses/openal-soft-winpthreads-COPYING.txt @@ -0,0 +1,57 @@ +Copyright (c) 2011 mingw-w64 project + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + + +/* + * Parts of this library are derived by: + * + * Posix Threads library for Microsoft Windows + * + * Use at own risk, there is no implied warranty to this code. + * It uses undocumented features of Microsoft Windows that can change + * at any time in the future. + * + * (C) 2010 Lockless Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of Lockless Inc. nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AN + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ diff --git a/ref/licenses/opus-COPYING.txt b/ref/licenses/opus-COPYING.txt new file mode 100644 index 000000000..9c739c34a --- /dev/null +++ b/ref/licenses/opus-COPYING.txt @@ -0,0 +1,44 @@ +Copyright 2001-2011 Xiph.Org, Skype Limited, Octasic, + Jean-Marc Valin, Timothy B. Terriberry, + CSIRO, Gregory Maxwell, Mark Borgerding, + Erik de Castro Lopo + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +- Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + +- Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +- Neither the name of Internet Society, IETF or IETF Trust, nor the +names of specific contributors, may be used to endorse or promote +products derived from this software without specific prior written +permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Opus is subject to the royalty-free patent licenses which are +specified at: + +Xiph.Org Foundation: +https://datatracker.ietf.org/ipr/1524/ + +Microsoft Corporation: +https://datatracker.ietf.org/ipr/1914/ + +Broadcom Corporation: +https://datatracker.ietf.org/ipr/1526/ diff --git a/tools/track_uneven_grade.py b/tools/track_uneven_grade.py index ba60be900..889e0ad0f 100644 --- a/tools/track_uneven_grade.py +++ b/tools/track_uneven_grade.py @@ -7,7 +7,7 @@ curves, speed and road crossings. The originals stay as they are, graded copies python track_uneven_grade.py scenery/baltyk_skm1.scn --out graded --route -107,2300 -4120,2491 --straight tor0290,tor0906 python track_uneven_grade.py scenery/mytracks.scm --root scenery --out graded --gain 1.2 -With no --out it only reports. See track_uneven_doc.md for the attribute. Python 3.8 or later, no other packages. +With no --out it only reports. See docs/track_uneven_doc.md for the attribute. Python 3.8 or later, no other packages. """ import argparse import collections From 92bd7066d4521d6f427858ce44ff332a04b22fb0 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 05:41:39 +0100 Subject: [PATCH 18/27] ci: cache the apt packages of the Linux jobs, install only the X11 headers GLFW needs (#497) * ci: cache the apt packages of the Linux jobs, install only the X11 headers GLFW needs The "Install Linux dependencies" step timed out after 15 minutes in many runs: the runners' Ubuntu mirror delivered about 150 kB/s, with 30 s stalls on single files, and the step downloaded 136 packages (32.4 MB) every time. - a local action, .github/actions/apt-install, keeps the downloaded .deb files in the Actions cache, keyed by the runner image and the package list. With the same image and list it installs the cached files without apt-get update and without the mirror; otherwise it runs apt-get update and downloads only what the cache lacks - --no-install-recommends, and Acquire::Languages "none" for apt-get update - xorg-dev (about 45 packages nothing used) is replaced by the X11 headers GLFW 3.4 checks for: libx11-dev, libxcursor-dev, libxext-dev, libxi-dev, libxinerama-dev, libxrandr-dev; pkg-config is listed, as it is only a recommendation of libsndfile1-dev - Build, Build binaries and Coverage use it; Coverage gets the 15-minute step timeout and the apt retries too - Dependabot also updates the actions pinned in .github/actions * ci: a repaired apt cache is saved under a key of its own run, and the newest one is restored --- .github/actions/apt-install/action.yml | 137 +++++++++++++++++++++++++ .github/dependabot.yml | 10 +- .github/workflows/build.yml | 27 +++-- .github/workflows/build_bin.yml | 60 +++++------ .github/workflows/coverage.yml | 19 ++-- 5 files changed, 198 insertions(+), 55 deletions(-) create mode 100644 .github/actions/apt-install/action.yml diff --git a/.github/actions/apt-install/action.yml b/.github/actions/apt-install/action.yml new file mode 100644 index 000000000..0495b07ac --- /dev/null +++ b/.github/actions/apt-install/action.yml @@ -0,0 +1,137 @@ +# Installs Ubuntu packages, with the downloaded .deb files kept in the Actions cache. +# +# The Ubuntu mirror of the hosted runners has been slow: about 150 kB/s, with stalls of 30 s on single files, +# so 130 small packages took over 13 minutes to download. The .deb files of the last install are kept in the +# cache, under a key of the runner image and the package list: +# - the same image and list (the usual case): the cached files are installed as they are, without the mirror +# and without `apt-get update`; should that fail, the next way is taken +# - otherwise: `apt-get update`, then `apt-get install`, which takes the cached files of the same version +# (checked against the index) and downloads the rest; the files of this install are cached for the next run +# +# A cache entry can't be overwritten, so each one is saved under the key with the run appended, and the newest +# entry of a key is restored by its prefix. Cached files that failed to install are then replaced by the next +# save rather than restored again on every run of that image. +# +# Caches of a pull request are seen only by that pull request; the pushes to staging and master (Build binaries) +# fill the ones every pull request starts from. + +name: Install apt packages +description: apt-get install, with the downloaded packages kept in the Actions cache + +inputs: + packages: + description: The packages to install, separated by spaces or new lines + required: true + +runs: + using: composite + steps: + # the key: the runner image (its packages are what the cached files were resolved against) and the list, + # sorted, so neither its order nor its line breaks change it. Without ImageVersion (not a GitHub-hosted + # runner) the image isn't known, so the cached files are never installed as they are + - name: Cache key of the packages + id: key + shell: bash + env: + PACKAGES: ${{ inputs.packages }} + run: | + set -euo pipefail + printf '%s\n' "$PACKAGES" | tr -s '[:space:]' '\n' | sed '/^$/d' | sort -u > "$RUNNER_TEMP/apt-packages.txt" + os="${ImageOS:-$(. /etc/os-release && echo "${ID}${VERSION_ID}")}" + image="${ImageVersion:-unknown}" + prefix="apt-v2-${os}-$(dpkg --print-architecture)-" + list_hash="$(sha256sum < "$RUNNER_TEMP/apt-packages.txt" | cut -c1-16)" + { + echo "key=${prefix}${image}-${list_hash}" + echo "save-key=${prefix}${image}-${list_hash}-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}" + echo "image-prefix=${prefix}${image}-" + echo "prefix=${prefix}" + echo "known-image=$([ -n "${ImageVersion:-}" ] && echo true || echo false)" + } >> "$GITHUB_OUTPUT" + cat "$RUNNER_TEMP/apt-packages.txt" + + # no entry is saved under the key itself, so this restores the newest entry of the key (by its prefix), else + # a cache of another list (another workflow) or of an older image: the files apt finds there in the version + # it wants aren't downloaded again + - name: Restore the downloaded packages + id: restore + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: /tmp/apt-archives + key: ${{ steps.key.outputs.key }} + restore-keys: | + ${{ steps.key.outputs.image-prefix }} + ${{ steps.key.outputs.prefix }} + + # /tmp rather than the runner's temp folder: apt downloads as the user _apt, who has to reach the folder. + # Recommended packages are left out: the build needs the headers and libraries the packages depend on + - name: Install the packages + id: install + shell: bash + env: + EXACT_HIT: ${{ startsWith(steps.restore.outputs.cache-matched-key, format('{0}-', steps.key.outputs.key)) && steps.key.outputs.known-image == 'true' }} + run: | + set -euo pipefail + archives=/tmp/apt-archives + mkdir -p "$archives/partial" + + # a mirror that stops answering used to hold this step for over an hour: time out each download and + # retry it. The translations of the package descriptions aren't needed + printf '%s\n' \ + 'Acquire::Retries "3";' \ + 'Acquire::http::Timeout "60";' \ + 'Acquire::https::Timeout "60";' \ + 'Acquire::Languages "none";' \ + | sudo tee /etc/apt/apt.conf.d/80-ci-retries > /dev/null + + mapfile -t packages < "$RUNNER_TEMP/apt-packages.txt" + apt=(sudo apt-get -y --no-install-recommends -o "Dir::Cache::Archives=$archives/") + + all_installed() { + local package + for package in "${packages[@]}"; do + [[ "$(dpkg-query -W -f '${db:Status-Abbrev}' "$package" 2> /dev/null)" == ii* ]] || return 1 + done + } + + done=false + fix=() + if [ "$EXACT_HIT" = true ] && compgen -G "$archives/*.deb" > /dev/null; then + echo "::group::Install the $(ls "$archives"/*.deb | wc -l) cached packages" + if "${apt[@]}" install "$archives"/*.deb && all_installed; then + done=true + echo "from-cache=true" >> "$GITHUB_OUTPUT" + else + echo "::warning::The cached packages didn't install; installing from the mirror" + fix=(--fix-broken) + fi + echo "::endgroup::" + fi + + if [ "$done" != true ]; then + sudo apt-get update + "${apt[@]}" "${fix[@]}" install "${packages[@]}" + all_installed + fi + + # only the files of the packages now installed are kept, in the version installed: the cached files then + # are exactly this install, and the next run on this image can install them as they are + sudo rm -rf "$archives/partial" "$archives/lock" + sudo chown -R "$(id -u):$(id -g)" "$archives" + installed="$(dpkg-query -W -f '${db:Status-Abbrev}|${Package}|${Version}|${Architecture}\n' \ + | awk -F'|' '$1 ~ /^ii/ { print $2 "|" $3 "|" $4 }')" + for deb in "$archives"/*.deb; do + [ -e "$deb" ] || continue + id="$(dpkg-deb --show --showformat='${Package}|${Version}|${Architecture}' "$deb")" + grep -qxF -- "$id" <<< "$installed" || rm -f "$deb" + done + echo "Cached packages: $(find "$archives" -maxdepth 1 -name '*.deb' | wc -l), $(du -sh "$archives" | cut -f1)" + + # saved unless the cached files of this image and list installed as they are: after a miss, and after cached + # files that failed to install and were replaced from the mirror + - name: Save the downloaded packages + if: steps.install.outputs.from-cache != 'true' + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: /tmp/apt-archives + key: ${{ steps.key.outputs.save-key }} diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 0a520876d..23c5f7c9d 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,10 +1,12 @@ -# Keeps the GitHub Actions used by the workflows up to date. The actions are pinned by commit hash, with the -# version in a comment; Dependabot updates both. One pull request a week for all of them, so the workflows -# stay on the same versions. +# Keeps the GitHub Actions used by the workflows and by the local actions (.github/actions) up to date. The actions +# are pinned by commit hash, with the version in a comment; Dependabot updates both. One pull request a week for all +# of them, so the workflows stay on the same versions. version: 2 updates: - package-ecosystem: github-actions - directory: / + directories: + - / + - /.github/actions/* schedule: interval: weekly groups: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7eaf891fe..3b279bbb0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,23 +41,20 @@ jobs: with: python-version: '3.14' - # A mirror that stops answering used to hold this step for over an hour. - # Time out each download, retry it, and give up on the whole step early. + # The packages are kept in the Actions cache (.github/actions/apt-install): the mirror of the + # runners has been too slow to download them every time. The timeout is a safety net. + # The X11 packages are the ones GLFW (ref/glfw, 3.4) looks for; xorg-dev brought ~45 more. - name: Install build dependencies timeout-minutes: 15 - run: | - printf '%s\n' \ - 'Acquire::Retries "3";' \ - 'Acquire::http::Timeout "60";' \ - 'Acquire::https::Timeout "60";' \ - | sudo tee /etc/apt/apt.conf.d/80-ci-retries > /dev/null - sudo apt-get update -y - sudo apt-get install -y \ - build-essential \ - libgl1-mesa-dev libglew-dev libglfw3-dev \ - libpng-dev libopenal-dev libluajit-5.1-dev \ - libserialport-dev libsndfile1-dev \ - xorg-dev libxkbcommon-dev libwayland-dev wayland-protocols + uses: ./.github/actions/apt-install + with: + packages: >- + build-essential pkg-config + libgl1-mesa-dev libglew-dev libglfw3-dev + libpng-dev libopenal-dev libluajit-5.1-dev + libserialport-dev libsndfile1-dev + libx11-dev libxcursor-dev libxext-dev libxi-dev libxinerama-dev libxrandr-dev + libxkbcommon-dev libwayland-dev wayland-protocols - name: Build current OpenAL Soft run: | diff --git a/.github/workflows/build_bin.yml b/.github/workflows/build_bin.yml index 13f36b0c7..91ad66978 100644 --- a/.github/workflows/build_bin.yml +++ b/.github/workflows/build_bin.yml @@ -400,37 +400,39 @@ jobs: with: python-version: "3.14" - # A mirror that stops answering used to hold this step for over an hour. - # Time out each download, retry it, and give up on the whole step early. + # The packages are kept in the Actions cache (.github/actions/apt-install): the mirror of the runners has been + # too slow to download them every time. The timeout is a safety net. + # libasound2-dev, libpulse-dev and libpipewire-0.3-dev: the headers of OpenAL Soft's audio backends (built below). + # Without them it builds with OSS only, which modern distributions and the Steam Linux Runtime don't have: no sound. + # The X11 packages are the ones GLFW (ref/glfw, 3.4) looks for; xorg-dev brought ~45 more. The game loads the + # X11 and Wayland libraries of the system, none of them is bundled (CMake_modules/bundle_runtime_libs.cmake). - name: Install Linux dependencies timeout-minutes: 15 - run: | - printf '%s\n' \ - 'Acquire::Retries "3";' \ - 'Acquire::http::Timeout "60";' \ - 'Acquire::https::Timeout "60";' \ - | sudo tee /etc/apt/apt.conf.d/80-ci-retries > /dev/null - sudo apt-get update - - # libasound2-dev, libpulse-dev and libpipewire-0.3-dev: the headers of OpenAL Soft's audio backends (built below). - # Without them it builds with OSS only, which modern distributions and the Steam Linux Runtime don't have: no sound. - sudo apt-get install -y \ - build-essential \ - libasound2-dev \ - libpulse-dev \ - libpipewire-0.3-dev \ - libgl1-mesa-dev \ - libglew-dev \ - libglfw3-dev \ - libpng-dev \ - libopenal-dev \ - libluajit-5.1-dev \ - libserialport-dev \ - libsndfile1-dev \ - libcurl4-openssl-dev \ - xorg-dev \ - libxkbcommon-dev \ - libwayland-dev \ + uses: ./.github/actions/apt-install + with: + packages: >- + build-essential + pkg-config + libasound2-dev + libpulse-dev + libpipewire-0.3-dev + libgl1-mesa-dev + libglew-dev + libglfw3-dev + libpng-dev + libopenal-dev + libluajit-5.1-dev + libserialport-dev + libsndfile1-dev + libcurl4-openssl-dev + libx11-dev + libxcursor-dev + libxext-dev + libxi-dev + libxinerama-dev + libxrandr-dev + libxkbcommon-dev + libwayland-dev wayland-protocols # diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index d2f00bccd..27fa64bc2 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -47,14 +47,19 @@ jobs: # the same packages as the Build workflow: the game is configured as a whole, # though only the unit tests and the core library they link are built - name: Install build dependencies + timeout-minutes: 15 + uses: ./.github/actions/apt-install + with: + packages: >- + build-essential pkg-config + libgl1-mesa-dev libglew-dev libglfw3-dev + libpng-dev libopenal-dev libluajit-5.1-dev + libserialport-dev libsndfile1-dev + libx11-dev libxcursor-dev libxext-dev libxi-dev libxinerama-dev libxrandr-dev + libxkbcommon-dev libwayland-dev wayland-protocols + + - name: Install gcovr run: | - sudo apt-get update -y - sudo apt-get install -y \ - build-essential \ - libgl1-mesa-dev libglew-dev libglfw3-dev \ - libpng-dev libopenal-dev libluajit-5.1-dev \ - libserialport-dev libsndfile1-dev \ - xorg-dev libxkbcommon-dev libwayland-dev wayland-protocols python3 -m pip install --no-cache-dir --only-binary :all: gcovr==8.3 - name: Build current OpenAL Soft From be28108b9132795ca2dc83bf52261952f6682084 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 05:41:50 +0100 Subject: [PATCH 19/27] fix(events): write memcompareex conditions back in the order they are read (#498) The editor wrote a memory cell comparison as memcompareex , without the pass word and with each value before its operator. The parser and the sceneries use memcompareex . A saved scenery read its conditions shifted by one token, and the last value took the next word of the event. The writer now puts out the pass and the operator before each value. The >= operator was written as >; it is written as >= now. The text side of the conditions moves unchanged to the core file world/eventconditions.cpp, so a unit test can check that what is written reads back the same. --- CMakeLists.txt | 1 + tests/unit/test_event_conditions.cpp | 130 +++++++++++++++++++++++++++ utilities/comparison.h | 14 ++- world/Event.cpp | 112 ----------------------- world/eventconditions.cpp | 129 ++++++++++++++++++++++++++ 5 files changed, 273 insertions(+), 113 deletions(-) create mode 100644 tests/unit/test_event_conditions.cpp create mode 100644 world/eventconditions.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 200adcf30..12a5ca1ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -584,6 +584,7 @@ set(CORE_SOURCES "world/timetableflags.cpp" "world/timetablereader.cpp" "world/stationnames.cpp" +"world/eventconditions.cpp" ) add_library(eu07_core STATIC ${CORE_SOURCES}) target_link_libraries(eu07_core PUBLIC eu07_settings) diff --git a/tests/unit/test_event_conditions.cpp b/tests/unit/test_event_conditions.cpp new file mode 100644 index 000000000..81a55201b --- /dev/null +++ b/tests/unit/test_event_conditions.cpp @@ -0,0 +1,130 @@ +#include "stdafx.h" +#include "doctest.h" + +#include "utilities/comparison.h" +#include "utilities/parser.h" +#include "world/Event.h" + +#include + +// the condition block of the multiple and updatevalues events (world/eventconditions.cpp): the scenery editor writes +// the conditions of the events back with export_as_text(), and what it writes has to read back as the same conditions + +namespace { + +// the conditions are a part of the event, open to its kinds only +struct event_kind : basic_event { + using basic_event::event_conditions; +}; +using conditions = event_kind::event_conditions; + +// the conditions of an event text, read the way the events read them: the parser stands on the word 'condition' +conditions read(std::string const &Text) { + cParser parser(Text, cParser::buffer_TEXT); + parser.getTokens(); + REQUIRE(parser.peek() == "condition"); + conditions result; + result.deserialize(parser); + // the reading stops at the next keyword of the event and leaves it for the event + CHECK(parser.peek() == "endevent"); + return result; +} + +std::string write(conditions const &Conditions) { + std::ostringstream output; + Conditions.export_as_text(output); + return output.str(); +} + +// the conditions written and read again +conditions write_and_read(conditions const &Conditions) { + return read(write(Conditions) + "endevent"); +} + +void check_same(conditions const &Read, conditions const &Expected) { + CHECK(Read.flags == Expected.flags); + CHECK(Read.probability == Expected.probability); + CHECK(Read.memcompare_pass == Expected.memcompare_pass); + CHECK(Read.memcompare_text == Expected.memcompare_text); + CHECK(Read.memcompare_text_operator == Expected.memcompare_text_operator); + CHECK(Read.memcompare_value1 == Expected.memcompare_value1); + CHECK(Read.memcompare_value1_operator == Expected.memcompare_value1_operator); + CHECK(Read.memcompare_value2 == Expected.memcompare_value2); + CHECK(Read.memcompare_value2_operator == Expected.memcompare_value2_operator); +} + +comparison_operator const operators[]{comparison_operator::equal, comparison_operator::not_equal, comparison_operator::lt, + comparison_operator::gt, comparison_operator::lt_eq, comparison_operator::gt_eq}; +comparison_pass const passes[]{comparison_pass::all, comparison_pass::any, comparison_pass::none}; + +} // namespace + +TEST_CASE("event conditions: each comparison operator and pass is written as the word that reads back as it") { + for (auto const op : operators) { + CAPTURE(to_string(op)); + CHECK(comparison_operator_from_string(to_string(op)) == op); + } + CHECK(to_string(comparison_operator::gt_eq) == ">="); + for (auto const pass : passes) { + CAPTURE(to_string(pass)); + CHECK(comparison_pass_from_string(to_string(pass)) == pass); + } +} + +TEST_CASE("event conditions: memcompareex is written as the pass, then the operator before each compared value") { + auto const conditions{read("condition memcompareex any != Blokada >= 1 < 2.5 endevent")}; + CHECK(conditions.memcompare_pass == comparison_pass::any); + CHECK(conditions.memcompare_text == "Blokada"); + CHECK(conditions.memcompare_text_operator == comparison_operator::not_equal); + CHECK(conditions.memcompare_value1_operator == comparison_operator::gt_eq); + CHECK(conditions.memcompare_value2_operator == comparison_operator::lt); + CHECK(write(conditions) == "condition memcompareex any != Blokada >= 1.000000 < 2.500000 "); + check_same(write_and_read(conditions), conditions); +} + +TEST_CASE("event conditions: memcompareex reads back the same for every pass, operator and left out value") { + for (auto const pass : passes) { + for (auto const op : operators) { + for (unsigned int used{0}; used < 8; ++used) { + std::string text{"condition memcompareex " + to_string(pass)}; + text += (used & 1) ? " " + to_string(op) + " Zajety_tor" : std::string{" *"}; + text += (used & 2) ? " " + to_string(op) + " -3.25" : std::string{" *"}; + text += (used & 4) ? " " + to_string(op) + " 1250" : std::string{" *"}; + text += " endevent"; + CAPTURE(text); + auto const conditions{read(text)}; + CHECK(conditions.flags == used); + if (used == 0) { + // nothing compared is no condition, and no condition is written + CHECK(write(conditions).empty()); + continue; + } + check_same(write_and_read(conditions), conditions); + } + } + } +} + +TEST_CASE("event conditions: the old memcompare is written as memcompareex all with == and reads back the same") { + auto const conditions{read("condition memcompare Wolny * 3 endevent")}; + CHECK(write(conditions) == "condition memcompareex all == Wolny * == 3.000000 "); + check_same(write_and_read(conditions), conditions); + + auto const all{read("condition memcompare Wolny 1 0 endevent")}; + check_same(write_and_read(all), all); +} + +TEST_CASE("event conditions: the track and probability conditions read back along with the comparison") { + auto const conditions{read("condition trackoccupied trackfree probability 0.25 memcompareex none <= 3 * > -1.5 endevent")}; + CHECK(conditions.flags == (basic_event::flags::track_busy | basic_event::flags::track_free | basic_event::flags::probability | + basic_event::flags::text | basic_event::flags::value2)); + check_same(write_and_read(conditions), conditions); + + auto const probability{read("condition probability 0.5 endevent")}; + CHECK(write(probability) == "condition probability 0.5 "); + check_same(write_and_read(probability), probability); +} + +TEST_CASE("event conditions: an event without conditions writes none") { + CHECK(write(conditions{}).empty()); +} diff --git a/utilities/comparison.h b/utilities/comparison.h index f0fc5d0af..1345e690b 100644 --- a/utilities/comparison.h +++ b/utilities/comparison.h @@ -48,11 +48,23 @@ to_string( comparison_operator const Operator ) { case lt: { return "<"; } case gt: { return ">"; } case lt_eq: { return "<="; } - case gt_eq: { return ">"; } + case gt_eq: { return ">="; } default: { return "??"; } } } +inline +std::string +to_string( comparison_pass const Pass ) { + switch( Pass ) { + using enum comparison_pass; + case all: { return "all"; } + case any: { return "any"; } + case none: { return "none"; } + default: { return "all"; } + } +} + inline comparison_pass comparison_pass_from_string( std::string const &Input ) { diff --git a/world/Event.cpp b/world/Event.cpp index 628e38ea7..814cd9918 100644 --- a/world/Event.cpp +++ b/world/Event.cpp @@ -178,110 +178,6 @@ basic_event::event_conditions::test() const { return true; } -void -basic_event::event_conditions::deserialize( cParser &Input ) { - // przetwarzanie warunków, wspólne dla Multiple i UpdateValues - - std::string token; - while( true == Input.getTokens() - && false == (token = Input.peek()).empty() - && false == basic_event::is_keyword(token) ) { - - if( token == "trackoccupied" ) { - flags |= flags::track_busy; - } - else if( token == "trackfree" ) { - flags |= flags::track_free; - } - else if( token == "propability" || token == "probability") { //remove propability in few years after changing old scenery scripts 01.2021 - flags |= flags::probability; - Input.getTokens(); - Input >> probability; - } - else if( token == "memcompare" ) { - Input.getTokens( 1, false ); // case sensitive - if( Input.peek() != "*" ) //"*" - nie brac command pod uwage - { // zapamiętanie łańcucha do porównania - Input >> memcompare_text; - flags |= flags::text; - } - Input.getTokens(); - if( Input.peek() != "*" ) //"*" - nie brac val1 pod uwage - { - Input >> memcompare_value1; - flags |= flags::value1; - } - Input.getTokens(); - if( Input.peek() != "*" ) //"*" - nie brac val2 pod uwage - { - Input >> memcompare_value2; - flags |= flags::value2; - } - } - else if( token == "memcompareex" ) { - memcompare_pass = comparison_pass_from_string( Input.getToken() ); - Input.getTokens(); - if( Input.peek() != "*" ) //"*" - nie brac pod uwage - { // two tokens, operator followed by comparison value - std::string operatorstring; - Input >> operatorstring; - memcompare_text_operator = comparison_operator_from_string( operatorstring ); - Input.getTokens( 1, false ); // case sensitive - Input >> memcompare_text; - flags |= flags::text; - } - Input.getTokens(); - if( Input.peek() != "*" ) //"*" - nie brac pod uwage - { // two tokens, operator followed by comparison value - std::string operatorstring; - Input >> operatorstring; - memcompare_value1_operator = comparison_operator_from_string( operatorstring ); - Input.getTokens(); - Input >> memcompare_value1; - flags |= flags::value1; - } - Input.getTokens(); - if( Input.peek() != "*" ) //"*" - nie brac pod uwage - { // two tokens, operator followed by comparison value - std::string operatorstring; - Input >> operatorstring; - memcompare_value2_operator = comparison_operator_from_string( operatorstring ); - Input.getTokens(); - Input >> memcompare_value2; - flags |= flags::value2; - } - } - } -} - -// sends basic content of the class in legacy (text) format to provided stream -void -basic_event::event_conditions::export_as_text( std::ostream &Output ) const { - - if( flags != 0 ) { - Output << "condition "; - if( ( flags & flags::track_busy ) != 0 ) { - Output << "trackoccupied "; - } - if( ( flags & flags::track_free ) != 0 ) { - Output << "trackfree "; - } - if( ( flags & flags::probability ) != 0 ) { - Output - << "probability " - << probability << ' '; - } - if( ( flags & ( flags::text | flags::value1 | flags::value2 ) ) != 0 ) { - // NOTE: export doesn't preserve original memcompare condition, these are all upgraded to memcompareex format for simplicity - Output - << "memcompareex " - << ( ( flags & flags::text ) == 0 ? "*" : memcompare_text + ' ' + to_string( memcompare_text_operator ) ) << ' ' - << ( ( flags & flags::value1 ) == 0 ? "*" : std::to_string( memcompare_value1 ) + ' ' + to_string( memcompare_value1_operator ) ) << ' ' - << ( ( flags & flags::value2 ) == 0 ? "*" : std::to_string( memcompare_value2 ) + ' ' + to_string( memcompare_value2_operator ) ) << ' '; - } - } -} - basic_event::~basic_event() { m_sibling = nullptr; // nie usuwać podczepionych tutaj @@ -446,14 +342,6 @@ basic_event::input_cell() const { return nullptr; } -bool -basic_event::is_keyword( std::string const &Token ) { - // TODO: convert to array lookup if keyword list gets longer - return Token == "endevent" - || Token == "randomdelay" - || Token == "departuredelay"; -} - TMemCell const * diff --git a/world/eventconditions.cpp b/world/eventconditions.cpp new file mode 100644 index 000000000..a091746e6 --- /dev/null +++ b/world/eventconditions.cpp @@ -0,0 +1,129 @@ +/* +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 text of the event conditions: read from the scenery and written back by the editor. kept apart from +// Event.cpp so the unit tests can check that what is written reads back the same + +#include "stdafx.h" +#include "world/Event.h" + +bool +basic_event::is_keyword( std::string const &Token ) { + // TODO: convert to array lookup if keyword list gets longer + return Token == "endevent" + || Token == "randomdelay" + || Token == "departuredelay"; +} + +void +basic_event::event_conditions::deserialize( cParser &Input ) { + // przetwarzanie warunków, wspólne dla Multiple i UpdateValues + + std::string token; + while( true == Input.getTokens() + && false == (token = Input.peek()).empty() + && false == basic_event::is_keyword(token) ) { + + if( token == "trackoccupied" ) { + flags |= flags::track_busy; + } + else if( token == "trackfree" ) { + flags |= flags::track_free; + } + else if( token == "propability" || token == "probability") { //remove propability in few years after changing old scenery scripts 01.2021 + flags |= flags::probability; + Input.getTokens(); + Input >> probability; + } + else if( token == "memcompare" ) { + Input.getTokens( 1, false ); // case sensitive + if( Input.peek() != "*" ) //"*" - nie brac command pod uwage + { // zapamiętanie łańcucha do porównania + Input >> memcompare_text; + flags |= flags::text; + } + Input.getTokens(); + if( Input.peek() != "*" ) //"*" - nie brac val1 pod uwage + { + Input >> memcompare_value1; + flags |= flags::value1; + } + Input.getTokens(); + if( Input.peek() != "*" ) //"*" - nie brac val2 pod uwage + { + Input >> memcompare_value2; + flags |= flags::value2; + } + } + else if( token == "memcompareex" ) { + memcompare_pass = comparison_pass_from_string( Input.getToken() ); + Input.getTokens(); + if( Input.peek() != "*" ) //"*" - nie brac pod uwage + { // two tokens, operator followed by comparison value + std::string operatorstring; + Input >> operatorstring; + memcompare_text_operator = comparison_operator_from_string( operatorstring ); + Input.getTokens( 1, false ); // case sensitive + Input >> memcompare_text; + flags |= flags::text; + } + Input.getTokens(); + if( Input.peek() != "*" ) //"*" - nie brac pod uwage + { // two tokens, operator followed by comparison value + std::string operatorstring; + Input >> operatorstring; + memcompare_value1_operator = comparison_operator_from_string( operatorstring ); + Input.getTokens(); + Input >> memcompare_value1; + flags |= flags::value1; + } + Input.getTokens(); + if( Input.peek() != "*" ) //"*" - nie brac pod uwage + { // two tokens, operator followed by comparison value + std::string operatorstring; + Input >> operatorstring; + memcompare_value2_operator = comparison_operator_from_string( operatorstring ); + Input.getTokens(); + Input >> memcompare_value2; + flags |= flags::value2; + } + } + } +} + +// sends basic content of the class in legacy (text) format to provided stream +void +basic_event::event_conditions::export_as_text( std::ostream &Output ) const { + + if( flags != 0 ) { + Output << "condition "; + if( ( flags & flags::track_busy ) != 0 ) { + Output << "trackoccupied "; + } + if( ( flags & flags::track_free ) != 0 ) { + Output << "trackfree "; + } + if( ( flags & flags::probability ) != 0 ) { + Output + << "probability " + << probability << ' '; + } + if( ( flags & ( flags::text | flags::value1 | flags::value2 ) ) != 0 ) { + // NOTE: export doesn't preserve original memcompare condition, these are all upgraded to memcompareex format for simplicity + // memcompareex then for the text and both values either * or the operator followed by the compared value, + // the order deserialize() reads them in. a legacy memcompare is the same as memcompareex all with all operators == + Output + << "memcompareex " + << to_string( memcompare_pass ) << ' ' + << ( ( flags & flags::text ) == 0 ? "*" : to_string( memcompare_text_operator ) + ' ' + memcompare_text ) << ' ' + << ( ( flags & flags::value1 ) == 0 ? "*" : to_string( memcompare_value1_operator ) + ' ' + std::to_string( memcompare_value1 ) ) << ' ' + << ( ( flags & flags::value2 ) == 0 ? "*" : to_string( memcompare_value2_operator ) + ' ' + std::to_string( memcompare_value2 ) ) << ' '; + } + } +} From 5551a5308e98770c798cfbc7e4133447a5245f79 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 05:57:38 +0100 Subject: [PATCH 20/27] perf(models): read the .e3d file with one unbuffered fread instead of a file stream (#499) * perf(models): read the .e3d file with one unbuffered fread The model loader read the whole .e3d file with std::ifstream::read. With MSVC that reads a file not in the system cache from a hard disk at about 24 MB/s, against about 38 MB/s for one unbuffered fread, and a cached file at less than half the speed. The new core helper read_whole_file() opens the file without a stream buffer and reads it with one fread. The loader parses the same bytes from memory as before; a missing, empty or short file gives the same result as with the file stream. * perf(models): the comment of read_whole_file quotes the measured read speeds --- CMakeLists.txt | 1 + model/Model3d.cpp | 17 ++-------- tests/unit/test_whole_file.cpp | 59 ++++++++++++++++++++++++++++++++++ utilities/wholefile.cpp | 43 +++++++++++++++++++++++++ utilities/wholefile.h | 26 +++++++++++++++ 5 files changed, 132 insertions(+), 14 deletions(-) create mode 100644 tests/unit/test_whole_file.cpp create mode 100644 utilities/wholefile.cpp create mode 100644 utilities/wholefile.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 12a5ca1ad..9097a57c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -585,6 +585,7 @@ set(CORE_SOURCES "world/timetablereader.cpp" "world/stationnames.cpp" "world/eventconditions.cpp" +"utilities/wholefile.cpp" ) add_library(eu07_core STATIC ${CORE_SOURCES}) target_link_libraries(eu07_core PUBLIC eu07_settings) diff --git a/model/Model3d.cpp b/model/Model3d.cpp index e3507e216..f836d7177 100644 --- a/model/Model3d.cpp +++ b/model/Model3d.cpp @@ -24,6 +24,7 @@ Copyright (C) 2001-2004 Marcin Wozniak, Maciej Czapkiewicz and others #include "simulation/simulationtime.h" #include "world/mtable.h" #include "scene/sn_utils.h" +#include "utilities/wholefile.h" #include @@ -2653,20 +2654,8 @@ void TModel3d::LoadFromBinFile(std::string const &FileName, bool dynamic) WriteLog("Loading binary format 3d model data from \"" + FileName + "\"...", logtype::model); // the file is read whole in one go and parsed from memory - std::unique_ptr filedata; - std::size_t filesize{0}; - { - std::ifstream input(FileName, std::ios::binary | std::ios::ate); - auto const length{input.tellg()}; - if (length > 0) - { - filedata.reset(new char[static_cast(length)]); - input.seekg(0); - input.read(filedata.get(), length); - filesize = static_cast(input.gcount()); - } - } - e3d_memorybuffer buffer(filedata.get(), filedata.get() + filesize); + auto const filedata{read_whole_file(FileName)}; + e3d_memorybuffer buffer(filedata.data.get(), filedata.data.get() + filedata.size); std::istream file(&buffer); uint32_t type = sn_utils::ld_uint32(file); diff --git a/tests/unit/test_whole_file.cpp b/tests/unit/test_whole_file.cpp new file mode 100644 index 000000000..f1cd98b5c --- /dev/null +++ b/tests/unit/test_whole_file.cpp @@ -0,0 +1,59 @@ +#include "stdafx.h" +#include "doctest.h" +#include "scratch.h" + +#include "utilities/wholefile.h" + +#include +#include + +// the read of a whole file in one go (utilities/wholefile.cpp), which the loader of the binary models (.e3d) parses +// from memory: the bytes come as they are in the file, whatever they are + +using namespace std::string_view_literals; + +namespace { + +std::string_view content(whole_file const &File) { + return {File.data.get(), File.size}; +} + +} // namespace + +TEST_CASE("whole file: the bytes come as they are in the file, the line ends and the text end marks too") { + test::scratch_folder const folder{"whole_file"}; + // all the byte values, then a size which isn't a multiple of any buffer, so the end of the file is read as well + std::string bytes; + for (int i{0}; i < 256; ++i) { + bytes += static_cast(i); + } + bytes += "\r\n\n\r\x1a\x00\xff"sv; + std::string text; + while (text.size() < 70000) { + text += bytes; + } + text += "end"; + auto const path{folder.write("model.e3d", text)}; + + auto const file{read_whole_file(path)}; + REQUIRE(file.size == text.size()); + CHECK(content(file) == text); +} + +TEST_CASE("whole file: a small file is read whole") { + test::scratch_folder const folder{"whole_file_small"}; + auto const path{folder.write("e3d0.e3d", "E3D0")}; + auto const file{read_whole_file(path)}; + CHECK(content(file) == "E3D0"); +} + +TEST_CASE("whole file: an empty file and a file which isn't there give no data") { + test::scratch_folder const folder{"whole_file_none"}; + auto const empty{read_whole_file(folder.write("empty.e3d", ""))}; + CHECK(empty.size == 0); + CHECK(empty.data == nullptr); + + auto const missing{read_whole_file(folder.path("missing.e3d"))}; + CHECK(missing.size == 0); + CHECK(missing.data == nullptr); +} diff --git a/utilities/wholefile.cpp b/utilities/wholefile.cpp new file mode 100644 index 000000000..573f0f1ab --- /dev/null +++ b/utilities/wholefile.cpp @@ -0,0 +1,43 @@ +/* +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/. +*/ + +#include "stdafx.h" +#include "utilities/wholefile.h" + +#include + +whole_file read_whole_file(std::string const &Path) +{ + whole_file result; + + auto *const file{std::fopen(Path.c_str(), "rb")}; + if (file == nullptr) + { + return result; + } + // without a buffer of its own the stream hands the read to the system in one piece, straight into the memory + std::setvbuf(file, nullptr, _IONBF, 0); +#ifdef _WIN32 + _fseeki64(file, 0, SEEK_END); + auto const length{_ftelli64(file)}; + _fseeki64(file, 0, SEEK_SET); +#else + fseeko(file, 0, SEEK_END); + auto const length{ftello(file)}; + fseeko(file, 0, SEEK_SET); +#endif + if (length > 0) + { + result.data.reset(new char[static_cast(length)]); + result.size = std::fread(result.data.get(), 1, static_cast(length), file); + } + std::fclose(file); + + return result; +} diff --git a/utilities/wholefile.h b/utilities/wholefile.h new file mode 100644 index 000000000..992ea8086 --- /dev/null +++ b/utilities/wholefile.h @@ -0,0 +1,26 @@ +/* +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/. +*/ + +#pragma once + +#include +#include +#include + +// the content of a whole file, kept in memory +struct whole_file +{ + std::unique_ptr data; + std::size_t size{0}; +}; + +// reads the whole file with one large read. a file stream reads a file which isn't in the system's cache yet from a +// hard disk in small pieces, slower (2026-11, .e3d files of a scenario: about 24 MB/s against 38 MB/s for one read). +// a file which can't be opened or is empty gives no data; a read which stops early gives what was read +whole_file read_whole_file(std::string const &Path); From cd60d0abc1f8ade5afa29ef4642efafdcedfd8aa Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 06:14:11 +0100 Subject: [PATCH 21/27] fix(cab): the converter switches follow a change made by the AI (#480) * fix(cab): the converter switches follow a change made by the AI The converter switch (converter_sw) and the local converter switch (converterlocal_sw) were set from the vehicle only when the cab was entered (set_cab_controls()). When the AI driver switched the converter on or off, or the local converter back on (since #276), the lever in the cab stayed where it was until the cab was loaded again. Each frame the two switches now take the state of the vehicle, the way the cab activation switch and the shunt mode lever already do. The main switch follows only where it is a two-state switch (not "impulse") and the converter is started by hand, so a converter started by the line breaker or the reverser does not drag the lever along. The state is read from the occupied vehicle, the one the switch commands of the cab change. * fix(cab): the converter switches are set on entering the cab from the occupied vehicle too --- vehicle/Train.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/vehicle/Train.cpp b/vehicle/Train.cpp index 3f2cbebae..f28f11d3b 100644 --- a/vehicle/Train.cpp +++ b/vehicle/Train.cpp @@ -10004,7 +10004,17 @@ bool TTrain::Update(double const Deltatime) ggDimHeadlightsButton.Update(); ggDimHeadlightsButton.Update(); //------------ + // the converter switches follow the vehicle when something else flips them (the AI driver, the other cab, + // the pressure switch of an EMU), not only when the cab is entered (set_cab_controls()) + if (ggConverterButton.SubModel != nullptr && mvOccupied->ConvSwitchType != "impulse" && mvOccupied->ConverterStart == start_t::manual) + { + ggConverterButton.UpdateValue(mvOccupied->ConverterAllow ? 1.f : 0.f, dsbSwitch); + } ggConverterButton.Update(); + if (ggConverterLocalButton.SubModel != nullptr) + { + ggConverterLocalButton.UpdateValue(mvOccupied->ConverterAllowLocal ? 1.f : 0.f, dsbSwitch); + } ggConverterLocalButton.Update(); ggConverterOffButton.Update(); ggTrainHeatingButton.Update(); @@ -11905,9 +11915,9 @@ void TTrain::set_cab_controls(int const Cab) // converter if (mvOccupied->ConvSwitchType != "impulse") { - ggConverterButton.PutValue(mvControlled->ConverterAllow ? 1.f : 0.f); + ggConverterButton.PutValue(mvOccupied->ConverterAllow ? 1.f : 0.f); } - ggConverterLocalButton.PutValue(mvControlled->ConverterAllowLocal ? 1.f : 0.f); + ggConverterLocalButton.PutValue(mvOccupied->ConverterAllowLocal ? 1.f : 0.f); // compressor ggCompressorButton.PutValue(mvControlled->CompressorAllow ? 1.f : 0.f); ggCompressorLocalButton.PutValue(mvControlled->CompressorAllowLocal ? 1.f : 0.f); From 8c8d5ff5cccce5266aa96d40b85d6427cb9181ca Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 06:14:43 +0100 Subject: [PATCH 22/27] Keep the shared log.txt and errors.txt when the run writes its own logs (multiplelogs) (#341) * fix: keep the shared log.txt and errors.txt when the run writes multiplelogs Every start deleted log.txt and errors.txt in the game folder before the settings were read, so a run with multiplelogs (each scenario test) wiped the logs of the player's last ordinary game although it writes its own files in logs/. The shared files are now deleted after the settings, and only without multiplelogs, where the run is about to write them (an errors.txt of an earlier run must still not stay behind a run without errors). The log service keeps what is logged until then, so an early message can't open and empty log.txt before multiplelogs is known. The file names come from one place (utilities/logfiles), covered by unit tests. * refactor(log): the wait for the log file names without Sonar issues The log service skips a pass with an early continue instead of wrapping the writing in an if, so the writing keeps its nesting. No change in behaviour. * fix(log): the node bank preview tool opens its log files after the settings The log service holds every message until OpenLogFiles() is called, and only the game called it. The preview tool kept its whole log in memory and wrote it only at the end, so a crash or a killed run lost it. --- CMakeLists.txt | 1 + application/application.cpp | 18 ++++++++++------ nodebank_previews_standalone.cpp | 2 ++ tests/unit/test_log_files.cpp | 35 ++++++++++++++++++++++++++++++++ utilities/Logs.cpp | 24 +++++++++++++++++++--- utilities/Logs.h | 3 +++ utilities/logfiles.cpp | 26 ++++++++++++++++++++++++ utilities/logfiles.h | 29 ++++++++++++++++++++++++++ 8 files changed, 129 insertions(+), 9 deletions(-) create mode 100644 tests/unit/test_log_files.cpp create mode 100644 utilities/logfiles.cpp create mode 100644 utilities/logfiles.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9097a57c9..a6504301f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -552,6 +552,7 @@ set(CORE_SOURCES "world/TrackCheck.cpp" "world/SleeperPack.cpp" "McZapkie/Oerlikon_ESt.cpp" +"utilities/logfiles.cpp" "utilities/parser.cpp" "utilities/utilities.cpp" "scene/sn_utils.cpp" diff --git a/application/application.cpp b/application/application.cpp index bc4b7dc1d..25f620766 100644 --- a/application/application.cpp +++ b/application/application.cpp @@ -25,6 +25,7 @@ http://mozilla.org/MPL/2.0/. #include "rendering/renderer.h" #include "application/uilayer.h" #include "utilities/Logs.h" +#include "utilities/logfiles.h" #include "world/SleeperWorker.h" #include "rendering/screenshot.h" #include "utilities/translation.h" @@ -403,8 +404,10 @@ int eu07_application::init(int Argc, char *Argv[]) Global.threads.emplace("LogService", std::move(sLoggingService)); init_debug(); + result = init_settings(Argc, Argv); + // the log files are named by the settings (multiplelogs), so they are cleared and opened once those are read init_files(); - if ((result = init_settings(Argc, Argv)) != 0) + if (result != 0) { ErrorLog("Failed to initialize settings! Maybe you're missing eu07.ini file?"); return result; @@ -1262,16 +1265,19 @@ void eu07_application::init_console() void eu07_application::init_files() { - + // without multiplelogs the run writes the shared log.txt / errors.txt, and those of the run before go. with it the + // run writes files of its own in logs/, and the shared ones are left to whoever ran the game last without it + for (auto const &file : stale_log_files(Global.MultipleLogs)) + { + std::error_code error; // not there is fine + std::filesystem::remove(file, error); + } #ifdef _WIN32 - DeleteFile("log.txt"); - DeleteFile("errors.txt"); CreateDirectory("logs", nullptr); #elif __unix__ - unlink("log.txt"); - unlink("errors.txt"); mkdir("logs", 0750); #endif + OpenLogFiles(); } namespace fs = std::filesystem; diff --git a/nodebank_previews_standalone.cpp b/nodebank_previews_standalone.cpp index 65c5e07f3..93fc39732 100644 --- a/nodebank_previews_standalone.cpp +++ b/nodebank_previews_standalone.cpp @@ -287,6 +287,8 @@ int generate_nodebank_previews(int Argc, char *Argv[]) { Global.LoadIniFile("eu07.ini"); } + // the settings are read, so the log service writes as it goes instead of holding everything until it stops + OpenLogFiles(); // the progress goes to the console, the log keeps the details Global.iWriteLogEnabled &= ~2; std::thread logservice(LogService); diff --git a/tests/unit/test_log_files.cpp b/tests/unit/test_log_files.cpp new file mode 100644 index 000000000..8a0aac6f3 --- /dev/null +++ b/tests/unit/test_log_files.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" +#include "doctest.h" + +#include "utilities/logfiles.h" + +#include + +// the files the log is written to, and which of them a run deletes when it starts + +TEST_CASE("log files: without multiplelogs the run writes the shared log.txt and errors.txt") +{ + CHECK(log_file_name(log_file::log, false, "td", "20261112_1200123") == "log.txt"); + CHECK(log_file_name(log_file::errors, false, "td", "20261112_1200123") == "errors.txt"); +} + +TEST_CASE("log files: with multiplelogs the run writes its own in logs/, named after the scenery and the time") +{ + CHECK(log_file_name(log_file::log, true, "autotest_case", "20261112_1200123") == "logs/log (autotest_case) 20261112_1200123.txt"); + CHECK(log_file_name(log_file::errors, true, "autotest_case", "20261112_1200123") == "logs/errors (autotest_case) 20261112_1200123.txt"); +} + +TEST_CASE("log files: without multiplelogs the start deletes the shared files it is going to write") +{ + // errors.txt is made at the first error only: one of the run before must not stay behind a run without errors + auto const stale{stale_log_files(false)}; + CHECK(stale.size() == 2); + for (auto const kind : {log_file::log, log_file::errors}) + CHECK(std::ranges::count(stale, log_file_name(kind, false, "td", "20261112_1200123")) == 1); +} + +TEST_CASE("log files: with multiplelogs the start keeps the shared log.txt and errors.txt of the last ordinary run") +{ + // the scenario tests run with multiplelogs; the logs of the player's last game in the game folder stay + CHECK(stale_log_files(true).empty()); +} diff --git a/utilities/Logs.cpp b/utilities/Logs.cpp index f4032d808..1b122535d 100644 --- a/utilities/Logs.cpp +++ b/utilities/Logs.cpp @@ -9,6 +9,7 @@ http://mozilla.org/MPL/2.0/. #include "stdafx.h" #include "utilities/Logs.h" +#include "utilities/logfiles.h" #include "utilities/crashsignals.h" #include @@ -82,6 +83,12 @@ std::atomic &log_stopped() static std::atomic stopped{false}; return stopped; } +// set once the settings are read: the files are named by them (multiplelogs, the scenery) +std::atomic &log_files_open() +{ + static std::atomic open{false}; + return open; +} } // namespace void StopLogService() @@ -89,6 +96,11 @@ void StopLogService() log_stopped() = true; } +void OpenLogFiles() +{ + log_files_open() = true; +} + void LogService() { @@ -96,6 +108,13 @@ void LogService() for (bool last{false}; false == last;) { last = log_stopped(); + // what is logged before the settings are read waits for them, or it would open (and empty) the shared log.txt + // of a run that writes its own files in logs/. a start that stops before that writes it anyway + if (false == log_files_open() && false == last) + { + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + continue; + } { // --- Obsługa InfoStack --- while (!InfoStack.empty()) @@ -114,7 +133,7 @@ void LogService() { if (!output.is_open()) { - std::string filename = Global.MultipleLogs ? "logs/log (" + filename_scenery() + ") " + filename_date() + ".txt" : "log.txt"; + std::string const filename { log_file_name(log_file::log, Global.MultipleLogs, filename_scenery(), filename_date()) }; output.open(filename, std::ios::trunc); // the stack of a crash on Linux goes to the end of this file crash_signals::set_log_path(filename); @@ -153,8 +172,7 @@ void LogService() if (!errors.is_open()) { - std::string filename = Global.MultipleLogs ? "logs/errors (" + filename_scenery() + ") " + filename_date() + ".txt" : "errors.txt"; - errors.open(filename, std::ios::trunc); + errors.open(log_file_name(log_file::errors, Global.MultipleLogs, filename_scenery(), filename_date()), std::ios::trunc); errors << "EU07.EXE " + Global.asVersion << "\n"; } diff --git a/utilities/Logs.h b/utilities/Logs.h index 63727de9c..5fd5d4a56 100644 --- a/utilities/Logs.h +++ b/utilities/Logs.h @@ -26,6 +26,9 @@ enum class logtype : unsigned int { // writes the log until StopLogService(), and all of it that came before void LogService(); void StopLogService(); +// the settings are read: the log files can be named and written from now on; until then the log service keeps what +// is logged +void OpenLogFiles(); void WriteLog( const char *str, logtype const Type = logtype::generic, bool isError = false ); void Error( const std::string &asMessage, bool box = false ); void Error( const char* &asMessage, bool box = false ); diff --git a/utilities/logfiles.cpp b/utilities/logfiles.cpp new file mode 100644 index 000000000..7dd9a6745 --- /dev/null +++ b/utilities/logfiles.cpp @@ -0,0 +1,26 @@ +/* +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/. +*/ + +#include "stdafx.h" +#include "utilities/logfiles.h" + +#include + +std::string log_file_name(log_file const Kind, bool const MultipleLogs, std::string_view const Scenery, std::string_view const Date) +{ + std::string_view const name{Kind == log_file::errors ? "errors" : "log"}; + return MultipleLogs ? std::format("logs/{} ({}) {}.txt", name, Scenery, Date) : std::format("{}.txt", name); +} + +std::vector stale_log_files(bool const MultipleLogs) +{ + if (MultipleLogs) + return {}; + return {log_file_name(log_file::log, false, {}, {}), log_file_name(log_file::errors, false, {}, {})}; +} diff --git a/utilities/logfiles.h b/utilities/logfiles.h new file mode 100644 index 000000000..7c88ea436 --- /dev/null +++ b/utilities/logfiles.h @@ -0,0 +1,29 @@ +/* +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/. +*/ + +#pragma once + +#include +#include +#include + +// the files the log is written to, and which of them a run clears when it starts. kept apart from the log service so +// the unit tests can check them + +// the log of everything, and the list of the errors (made at the first error) +enum class log_file { log, errors }; + +// the name of a log file: the shared one in the game folder, or with multiplelogs the run's own in logs/, named after +// the scenery and the time +std::string log_file_name(log_file Kind, bool MultipleLogs, std::string_view Scenery, std::string_view Date); + +// the shared log files a run deletes when it starts: the ones it writes itself, that is without multiplelogs, so an +// errors.txt of an earlier run doesn't stay behind when this one logs no error. with multiplelogs the run writes files +// of its own in logs/, and the log.txt / errors.txt of the last ordinary run are kept +std::vector stale_log_files(bool MultipleLogs); From 4d12693376be848fbc65d230aced581a7258112d Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 06:15:09 +0100 Subject: [PATCH 23/27] AI: say so when standing with the pantographs up and no voltage (#344) * fix(ai): the driver tells of standing with its pantographs up and no voltage An AI driver of an electric vehicle standing past the end of the overhead wire, or under a wire switched off, never gets out of Prepare_engine: the voltage PrepareEngine() waits for doesn't come. It waited without a word (eu07/maszyna#421, L053 poranek with an ET21 on TME222158). Now it says so in the log, once per episode, with the vehicle's name and position, telling a missing wire (no raised pantograph found one) from a wire without voltage. It keeps trying, so towed back under the wire or with the power switched on the vehicle still gets prepared. The decision is ai_power (vehicle/aipower), in the core library with unit tests; scenario case et21_td_no_wire_reports puts an ET21 on a track of its own with no wire next to td.scn. * refactor(ai): the power stall report without Sonar issues stall::none becomes stall::not_stalled (none shadowed a global enumerator), using enum in check(), and an explicit cast of the pantograph count. No change in behaviour. * fix(ai): the power stall report is a traction log line It went out as a generic error, so a scenery that keeps its wire off on purpose couldn't mute it with logs.filter like the other traction lines. --- CMakeLists.txt | 1 + tests/scenarios/README.md | 6 + .../cases/et21_td_no_wire_reports.json | 27 +++++ tests/scenarios/cases/td_no_wire.scn | 18 +++ tests/unit/test_ai_power.cpp | 105 ++++++++++++++++++ vehicle/Driver.cpp | 48 +++++++- vehicle/Driver.h | 4 + vehicle/aipower.cpp | 56 ++++++++++ vehicle/aipower.h | 61 ++++++++++ 9 files changed, 320 insertions(+), 6 deletions(-) create mode 100644 tests/scenarios/cases/et21_td_no_wire_reports.json create mode 100644 tests/scenarios/cases/td_no_wire.scn create mode 100644 tests/unit/test_ai_power.cpp create mode 100644 vehicle/aipower.cpp create mode 100644 vehicle/aipower.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a6504301f..ff27c20e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -564,6 +564,7 @@ set(CORE_SOURCES "scripting/scriptscreenkernels.cpp" "scripting/scriptscreendrawing.cpp" "simulation/simulationtestrules.cpp" +"vehicle/aipower.cpp" "vehicle/aiwire.cpp" "vehicle/blackbox.cpp" "utilities/physicslog.cpp" diff --git a/tests/scenarios/README.md b/tests/scenarios/README.md index 5ddc77dca..d85bd15e9 100644 --- a/tests/scenarios/README.md +++ b/tests/scenarios/README.md @@ -301,6 +301,12 @@ couple and neither shows up: the black box has to have the last car of the stand writes nothing to the log when couplers catch). Nothing reports a result, so both end on the 60 s test timeout. +`et21_td_no_wire_reports` (issue #421, fragment `td_no_wire.scn`) adds a 200 m track of its own, +with no overhead wire, 400 m off the line of td.scn (every track of td.scn is under the wire), with +an ET21 and its AI driver on it. The pantographs go up and find no wire, so the locomotive can't +start: the driver has to say so in the log, once, naming the locomotive and where it stands, and +not mistake it for a wire without voltage. It ends on the standstill. + `eu07_td_cold_connect` (fragment `td_cold_connect.scn`) has an EU07 with a hand brake (`4E-ZEZ_GREY`; the plain `4e` has none) standing cold on track 1 of Stacja1 (trainset velocity 0, so it starts with the hand brake on) and two coaches standing 45 m ahead of it. Its driver sleeps diff --git a/tests/scenarios/cases/et21_td_no_wire_reports.json b/tests/scenarios/cases/et21_td_no_wire_reports.json new file mode 100644 index 000000000..3aeaeecde --- /dev/null +++ b/tests/scenarios/cases/et21_td_no_wire_reports.json @@ -0,0 +1,27 @@ +{ + "description": "ET21 with an AI driver on a track of td.scn's own with no overhead wire: it raises the pantographs, finds no wire and can't start; the driver tells of it in the log, once, and keeps waiting for the voltage (eu07/maszyna#421). The test ends on the standstill.", + "base_scenery": "td.scn", + "fragment": "td_no_wire.scn", + "vars": { + "consist": "node -1 0 {{vehicle}} dynamic pkp\\et21_v2 ET21-367 3e2 0 headdriver 0 0 enddynamic" + }, + "test_config": [ + "test.standstill 300" + ], + "expect": "standstill", + "timeout": 900, + "checks": [ + { + "type": "log_contains", + "pattern": "AI \\[autotest_et21_td_no_wire_reports\\]: can't start, no overhead wire above its raised pantographs \\(at -?[\\d.]+, -?[\\d.]+, -?[\\d.]+\\)" + }, + { + "type": "log_lacks", + "pattern": "no voltage in the overhead wire at its raised pantographs" + }, + { + "type": "distance", + "max": 1 + } + ] +} diff --git a/tests/scenarios/cases/td_no_wire.scn b/tests/scenarios/cases/td_no_wire.scn new file mode 100644 index 000000000..edca73c0b --- /dev/null +++ b/tests/scenarios/cases/td_no_wire.scn @@ -0,0 +1,18 @@ +// added by tests/scenarios/run.py to td.scn, whose own trainsets were removed. +// a piece of track of its own, 200 m long and with no overhead wire above it, 400 m off the line of td.scn +// (all of whose tracks are under the wire), and an electric locomotive with an AI driver standing on it. +// the driver raises the pantographs, which find no wire, and waits in Prepare_engine for the voltage for good +// (eu07/maszyna#421); it tells of it in the log once. +node -1 0 autotest_no_wire track normal 200.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-400.0 0.2 0.0 0.0 //point 1 +0.0 0.0 0.0 //control vector 1 +0.0 0.0 0.0 //control vector 2 +-400.0 0.2 200.0 0.0 //point 2 +0 +endtrack + +// no timetable: the driver goes shunting; 0.01 km/h has it prepare the vehicle and wait for a signal (at 0 it sleeps) +trainset none autotest_no_wire 100.0 0.01 +{{consist}} +endtrainset diff --git a/tests/unit/test_ai_power.cpp b/tests/unit/test_ai_power.cpp new file mode 100644 index 000000000..330f09e0a --- /dev/null +++ b/tests/unit/test_ai_power.cpp @@ -0,0 +1,105 @@ +#include "stdafx.h" +#include "doctest.h" + +#include "vehicle/aipower.h" + +// the AI driver of an electric vehicle standing with its pantographs up and no voltage at them: what it makes of +// it, and when it tells of it in the log (eu07/maszyna#421) + +namespace { + +using ai_power::stall; + +// standing with the pantographs up, past the end of the overhead wire +ai_power::state past_the_wire() { + ai_power::state state; + state.collector = true; + state.power = false; + state.standing = true; + state.pantographs_up = true; + state.wire = false; + return state; +} + +} // namespace + +TEST_CASE("ai power: standing with the pantographs up and no wire above them is a stall") { + CHECK(ai_power::check(past_the_wire()) == stall::no_wire); +} + +TEST_CASE("ai power: a wire above the raised pantographs which carries no voltage is told apart") { + auto state{past_the_wire()}; + state.wire = true; + + CHECK(ai_power::check(state) == stall::no_voltage); +} + +TEST_CASE("ai power: with the voltage there, or without a pantograph to take it, there is nothing to tell") { + auto powered{past_the_wire()}; + powered.power = true; // at the pantographs, or from the rest of the train through its high voltage cable + auto diesel{past_the_wire()}; + diesel.collector = false; + + CHECK(ai_power::check(powered) == stall::not_stalled); + CHECK(ai_power::check(diesel) == stall::not_stalled); +} + +TEST_CASE("ai power: moving, or the pantographs not up yet, it only waits") { + auto moving{past_the_wire()}; + moving.standing = false; // coasting through a gap of the wire, say + auto rising{past_the_wire()}; + rising.pantographs_up = false; // the air for the pantographs still being pumped up + + CHECK(ai_power::check(moving) == stall::waiting); + CHECK(ai_power::check(rising) == stall::waiting); +} + +TEST_CASE("ai power: a stall is reported once it lasted report_delay, and only once") { + ai_power::reporter reporter; + + CHECK_FALSE(reporter.update(stall::no_wire, 100.0).has_value()); + CHECK_FALSE(reporter.update(stall::no_wire, 100.0 + ai_power::report_delay - 0.5).has_value()); + auto const report{reporter.update(stall::no_wire, 100.0 + ai_power::report_delay)}; + REQUIRE(report.has_value()); + CHECK(*report == stall::no_wire); + // the driver keeps trying to prepare the vehicle, without telling of it again + CHECK_FALSE(reporter.update(stall::no_wire, 100.0 + ai_power::report_delay + 1.0).has_value()); + CHECK_FALSE(reporter.update(stall::no_wire, 1000.0).has_value()); +} + +TEST_CASE("ai power: the voltage coming back ends the stall, the next one is reported again") { + ai_power::reporter reporter; + reporter.update(stall::no_wire, 0.0); + REQUIRE(reporter.update(stall::no_wire, ai_power::report_delay).has_value()); + + // towed back under the wire: the vehicle gets prepared + CHECK_FALSE(reporter.update(stall::not_stalled, 100.0).has_value()); + // and later stands without voltage again, under a wire switched off this time + CHECK_FALSE(reporter.update(stall::no_voltage, 200.0).has_value()); + auto const report{reporter.update(stall::no_voltage, 200.0 + ai_power::report_delay)}; + REQUIRE(report.has_value()); + CHECK(*report == stall::no_voltage); +} + +TEST_CASE("ai power: moving or lowering the pantographs restarts the count but doesn't end a reported stall") { + ai_power::reporter reporter; + reporter.update(stall::no_wire, 0.0); + // the vehicle moves before the stall is reported: the count starts again once it stands + CHECK_FALSE(reporter.update(stall::waiting, 20.0).has_value()); + CHECK_FALSE(reporter.update(stall::no_wire, 25.0).has_value()); + CHECK_FALSE(reporter.update(stall::no_wire, 25.0 + ai_power::report_delay - 1.0).has_value()); + REQUIRE(reporter.update(stall::no_wire, 25.0 + ai_power::report_delay).has_value()); + // still with no voltage, the vehicle moved (pushed a bit) and stands again: no second report + CHECK_FALSE(reporter.update(stall::waiting, 100.0).has_value()); + CHECK_FALSE(reporter.update(stall::no_wire, 110.0).has_value()); + CHECK_FALSE(reporter.update(stall::no_wire, 110.0 + 2.0 * ai_power::report_delay).has_value()); +} + +TEST_CASE("ai power: the report names the vehicle, where it stands and why") { + auto const nowire{ai_power::message(stall::no_wire, "et21-367", {1817.4, 0.38, 4785.94})}; + auto const novoltage{ai_power::message(stall::no_voltage, "et21-367", {1817.4, 0.38, 4785.94})}; + + CHECK(nowire == "AI [et21-367]: can't start, no overhead wire above its raised pantographs (at 1817.40, 0.38, 4785.94); it waits for the voltage"); + CHECK(novoltage.find("no voltage in the overhead wire") != std::string::npos); + CHECK(novoltage.find("et21-367") != std::string::npos); +} diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index 0c2568ad3..cba35b68a 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -3248,15 +3248,15 @@ bool TController::PrepareEngine() close_line_breaker(); } + auto const sufficientpantographpressure { ( + is_emu() ? + 2.5 : // Ra 2013-12: Niebugocław mówi, że w EZT podnoszą się przy 2.5 + 3.5 ) + + 0.1 }; // leeway margin + if( mvPantographUnit->EnginePowerSource.SourceType == TPowerSource::CurrentCollector && mvPantographUnit->EnginePowerSource.CollectorParameters.CollectorsNo > 0 ) { // if our pantograph unit isn't a pantograph-devoid fallback - auto const sufficientpantographpressure { ( - is_emu() ? - 2.5 : // Ra 2013-12: Niebugocław mówi, że w EZT podnoszą się przy 2.5 - 3.5 ) - + 0.1 }; // leeway margin - if (mvPantographUnit->PantPress < sufficientpantographpressure) { // załączenie małej sprężarki if( false == mvPantographUnit->PantAutoValve ) { @@ -3286,6 +3286,9 @@ bool TController::PrepareEngine() auto const ispoweravailable = mvControlling->EnginePowerSource.SourceType != TPowerSource::CurrentCollector || std::max(mvControlling->GetTrainsetHighVoltage(), mvControlling->PantographVoltage) > mvControlling->EnginePowerSource.CollectorParameters.MinV; + // standing with the pantographs up and no voltage, nothing the driver does starts the vehicle. it says so, and keeps + // trying: towed back under the wire, or with the power switched on, the vehicle gets prepared after all + report_power_stall( ispoweravailable, sufficientpantographpressure ); bool isready = false; @@ -3372,6 +3375,39 @@ bool TController::PrepareEngine() return iEngineActive; } +// tells in the log, once, of standing with the pantographs up and no voltage at them, past the end of the overhead +// wire or under a wire switched off (eu07/maszyna#421). Poweravailable is what PrepareEngine() found, Pantographpressure +// the air the pantographs need to rise +void +TController::report_power_stall( bool const Poweravailable, double const Pantographpressure ) { + + ai_power::state state; + state.collector = mvControlling->EnginePowerSource.SourceType == TPowerSource::CurrentCollector; + state.power = Poweravailable; + state.standing = mvOccupied->Vel < EU07_AI_NOMOVEMENT; + if( mvPantographUnit->PantPress >= Pantographpressure ) { + state.pantographs_up = + mvPantographUnit->Pantographs[ end::front ].is_active + || mvPantographUnit->Pantographs[ end::rear ].is_active; + } + // the pantographs of the vehicle carrying them hold the wire they found above them + if( auto const *carrier { pVehicle->FindPantographCarrier() }; + carrier != nullptr && carrier->MoverParameters == mvPantographUnit ) { + auto const pantographcount { std::min( carrier->iAnimType[ ANIM_PANTS ], static_cast( carrier->MoverParameters->Pantographs.size() ) ) }; + for( auto index { 0 }; index < pantographcount; ++index ) { + if( true == carrier->MoverParameters->Pantographs[ index ].is_active + && carrier->pants[ index ].fParamPants->hvPowerWire != nullptr ) { + state.wire = true; + } + } + } + // a user driving the vehicle sees the voltmeters for themselves + if( auto const stall { m_powerstall.update( AIControllFlag ? ai_power::check( state ) : ai_power::stall::waiting, ElapsedTime ) }; + stall.has_value() ) { + ErrorLog( ai_power::message( *stall, pVehicle->asName, pVehicle->GetPosition() ), logtype::traction ); + } +} + // wyłączanie silnika (test wyłączenia, a część wykonawcza tylko jeśli steruje komputer) bool TController::ReleaseEngine() { /* diff --git a/vehicle/Driver.h b/vehicle/Driver.h index 87dccd030..b8eb4ec94 100644 --- a/vehicle/Driver.h +++ b/vehicle/Driver.h @@ -20,6 +20,7 @@ http://mozilla.org/MPL/2.0/. #include "utilities/translation.h" #include "application/driverhints.h" #include "vehicle/blackbox.h" +#include "vehicle/aipower.h" auto const EU07_AI_ACCELERATION = 0.05; auto const EU07_AI_NOACCELERATION = -0.05; @@ -683,6 +684,9 @@ public: bool CheckVehicles( TOrders user = Wait_for_orders ); private: bool PrepareEngine(); + // tells in the log, once, of standing with the pantographs up and no voltage (eu07/maszyna#421) + void report_power_stall( bool const Poweravailable, double const Pantographpressure ); + ai_power::reporter m_powerstall; // the reports of report_power_stall() void close_line_breaker(); bool ReleaseEngine(); void Doors( bool const Open, int const Side = 0 ); diff --git a/vehicle/aipower.cpp b/vehicle/aipower.cpp new file mode 100644 index 000000000..8418d5fe1 --- /dev/null +++ b/vehicle/aipower.cpp @@ -0,0 +1,56 @@ +/* +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/. +*/ + +#include "stdafx.h" +#include "vehicle/aipower.h" + +#include + +namespace ai_power { + +stall check(state const &State) { + using enum stall; + if (false == State.collector || true == State.power) { + return not_stalled; + } + if (false == State.standing || false == State.pantographs_up) { + return waiting; + } + return State.wire ? no_voltage : no_wire; +} + +std::optional reporter::update(stall const Stall, double const Now) { + if (Stall == stall::not_stalled) { + m_since.reset(); + m_reported = false; + return std::nullopt; + } + if (Stall == stall::waiting) { + m_since.reset(); + return std::nullopt; + } + if (false == m_since.has_value()) { + m_since = Now; + } + if (true == m_reported || Now - *m_since < report_delay) { + return std::nullopt; + } + m_reported = true; + return Stall; +} + +std::string message(stall const Stall, std::string const &Name, glm::dvec3 const &Position) { + auto const reason{ + Stall == stall::no_wire ? + "no overhead wire above its raised pantographs" : + "no voltage in the overhead wire at its raised pantographs"}; + return std::format("AI [{}]: can't start, {} (at {:.2f}, {:.2f}, {:.2f}); it waits for the voltage", Name, reason, Position.x, Position.y, Position.z); +} + +} // namespace ai_power diff --git a/vehicle/aipower.h b/vehicle/aipower.h new file mode 100644 index 000000000..4d822980a --- /dev/null +++ b/vehicle/aipower.h @@ -0,0 +1,61 @@ +/* +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/. +*/ + +#pragma once + +#include +#include + +#include + +// an AI driver of an electric vehicle standing with its pantographs up and no voltage at them: past the end of the +// overhead wire, or under a wire which is switched off. no driver can start such a vehicle, it waits in +// TController::PrepareEngine() until the voltage comes, towed back under the wire or the power switched on. the +// driver tells of it in the log, once, instead of waiting without a word (eu07/maszyna#421) +namespace ai_power { + +// what the driver knows of the power of the vehicle when it prepares it +struct state { + bool collector{false}; // the vehicle takes its power from the overhead wire + bool power{false}; // there is the voltage the vehicle needs, at its pantographs or from the rest of the train + bool standing{false}; // the vehicle stands + bool pantographs_up{false}; // a pantograph is raised, with the air to hold it up + bool wire{false}; // a raised pantograph found a wire above it +}; + +enum class stall { + not_stalled, // the voltage is there, or the vehicle doesn't take it from the wire + waiting, // no voltage, but nothing to tell yet: the vehicle moves, or its pantographs aren't up + no_wire, // standing with the pantographs up and no wire above them + no_voltage // standing with a pantograph up at a wire which carries no voltage +}; + +stall check(state const &State); + +// how long [s] the vehicle stands with its pantographs up and no voltage before the driver tells of it. the +// pantographs need a few seconds to rise and the voltage a moment to come, a gap under a section insulator is +// shorter still +inline constexpr double report_delay{30.0}; + +// tells of a stall once: one report while it lasts. the voltage coming back ends it, and the next one is reported +// again; moving, or the pantographs going down, only restarts the count of report_delay +class reporter { +public: + // one look at the vehicle at the time Now [s]: the stall to report now, if any + std::optional update(stall Stall, double Now); + +private: + std::optional m_since; // when the vehicle began to stand with the pantographs up and no voltage + bool m_reported{false}; // the stall has been reported +}; + +// the line of the log telling of the stall of the vehicle Name standing at Position +std::string message(stall Stall, std::string const &Name, glm::dvec3 const &Position); + +} // namespace ai_power From dadc3905bac9865040c695c0e8cdf8c47e7d86d7 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 06:15:33 +0100 Subject: [PATCH 24/27] feat(log): the cpu, the memory and the GPUs at startup, with a warning for an integrated GPU (#389) * feat: log the cpu, the memory and the GPUs at startup Bug reports can't tell from log.txt whether the game ran on the integrated GPU of a laptop instead of the dedicated one: it names only GL_RENDERER, GL_VENDOR and the GL version. The exe asks for the dedicated GPU (NvOptimusEnablement, AmdPowerXpressRequestHighPerformance), but the Windows graphics settings, the driver panel or the socket the monitor is plugged into can override that. At startup the log now gets, every line starting with "hardware: ": - the cpu (cpuid brand string, the registry on Windows as a fallback, /proc/cpuinfo on Linux), its cores and threads, and AVX2 support (with a warning when the build needs AVX2 and the cpu has none) - the total and the available memory - on Windows every adapter DXGI lists (description, vendor and device id, dedicated and shared memory, monitors connected, integrated or discrete), the software adapter left out; dxgi.dll is loaded with LoadLibrary, so the game gets no new link dependency - right after the OpenGL context is made, the GPU it runs on and its memory where the driver tells it (GL_NVX_gpu_memory_info, GL_ATI_meminfo) - a warning when OpenGL runs on an integrated GPU while the system has a discrete one, or draws on the cpu (GDI Generic, llvmpipe) Integrated or discrete is told from the vendor and the name, and only when sure (utilities/hardwareinfo.h): NVIDIA is discrete; Intel is integrated except the Arc cards and Iris Xe MAX; AMD is discrete for RX/Pro/VII/FirePro, integrated for the APU names ending in "Graphics", unknown otherwise. An unknown GPU never raises the warning. The rules and the text are in utilities/hardwareinfo.cpp (core library, unit tested); the probing in utilities/hardwareprobe.cpp, called from application.cpp. No renderer file is touched. README.md: the minimum cpu now matches the package readme, 4 cores with AVX2 (Core i5-4430 / Ryzen 3 1200), instead of 2 cores (Core i3-2100, which has no AVX2 the release needs). * refactor(log): the hardware info without Sonar issues using enum for gpu_kind, the ranges algorithms, a reader struct for /proc/cpuinfo instead of a long lambda, explicit captures, cpuid returning a std::array, the adapter list behind a function rather than a mutable global, and uppercase literal suffixes in the test. No change in behaviour. * fix(log): load dxgi.dll from System32 only, cap the GL error drain LoadLibraryW searched the game folder first, so a proxy dxgi.dll left there by ReShade or ENB was loaded at every start just to list the adapters. The loop that clears the GL errors after the memory queries could spin forever on a lost context that keeps reporting one; it now stops after 32. A comment says when the AVX2 warning can be reached. * fix(log): Raven Ridge RX Vega and Panther Lake Arc B3xx are integrated "Radeon RX Vega 11 Graphics" (Ryzen 2400G) and "RX Vega 10 Graphics" (2700U) hit the "rx" card rule before the "ends with Graphics" APU one, and "Arc B390 GPU" / "B370" of Panther Lake looked like an Arc card by the letter and number. Both came out discrete, so the integrated-GPU warning never showed on such a machine. An RX Vega with a number and "Graphics" is now an APU (RX Vega 56 and Vega M of Kaby Lake G stay discrete), and Arc B3xx is integrated (A310, A380, B570, B580 stay cards). --- CMakeLists.txt | 2 + README.md | 2 +- application/application.cpp | 7 + tests/unit/test_hardware_info.cpp | 236 ++++++++++++++++ utilities/hardwareinfo.cpp | 441 ++++++++++++++++++++++++++++++ utilities/hardwareinfo.h | 114 ++++++++ utilities/hardwareprobe.cpp | 336 +++++++++++++++++++++++ utilities/hardwareprobe.h | 22 ++ 8 files changed, 1159 insertions(+), 1 deletion(-) create mode 100644 tests/unit/test_hardware_info.cpp create mode 100644 utilities/hardwareinfo.cpp create mode 100644 utilities/hardwareinfo.h create mode 100644 utilities/hardwareprobe.cpp create mode 100644 utilities/hardwareprobe.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ff27c20e6..3627ef518 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -289,6 +289,7 @@ set(SOURCES "utilities/dictionary.cpp" "rendering/particles.cpp" "utilities/headtrack.cpp" +"utilities/hardwareprobe.cpp" "rendering/geometrybank.cpp" "rendering/openglcolor.cpp" "simulation/simulationsounds.cpp" @@ -555,6 +556,7 @@ set(CORE_SOURCES "utilities/logfiles.cpp" "utilities/parser.cpp" "utilities/utilities.cpp" +"utilities/hardwareinfo.cpp" "scene/sn_utils.cpp" "scene/regionfile.cpp" "utilities/inionlysettings.cpp" diff --git a/README.md b/README.md index f0c7ac3cd..9f607f704 100644 --- a/README.md +++ b/README.md @@ -231,7 +231,7 @@ If detection still fails, padding the file (with comments) up to ~1 MB may hel ## Minimum requirements - OS: **Windows 10 64-bit** -- Processor: **2 core at least 2 GHz (e.g. Intel Core i3-2100 / AMD Athlon II X2)** +- Processor: **4 cores with AVX2 support (e.g. Intel Core i5-4430 / AMD Ryzen 3 1200)** - RAM: **6 GB RAM** - Graphics Card: **supporting OpenGL 3.3 with at least 1GB VRAM** - **150 GB of free disk space** diff --git a/application/application.cpp b/application/application.cpp index 25f620766..0ac02c4fe 100644 --- a/application/application.cpp +++ b/application/application.cpp @@ -32,6 +32,7 @@ http://mozilla.org/MPL/2.0/. #include "vehicle/Train.h" #include "utilities/Timer.h" #include "utilities/framepacer.h" +#include "utilities/hardwareprobe.h" #include "utilities/dictionary.h" #include "version_info.h" #include "simulation/simulationtest.h" @@ -448,6 +449,9 @@ int eu07_application::init(int Argc, char *Argv[]) if (Global.NvRenderer) Global.python_threadedupload = false; + // the cpu, the memory and the graphics adapters, for the bug reports + hardware::log_system(); + WriteLog("// startup"); if ((result = init_glfw()) != 0) @@ -1632,6 +1636,9 @@ int eu07_application::init_ogl() } } + // which of the GPUs the context runs on, and its memory + hardware::log_gl_context(); + return 0; } diff --git a/tests/unit/test_hardware_info.cpp b/tests/unit/test_hardware_info.cpp new file mode 100644 index 000000000..73023ca23 --- /dev/null +++ b/tests/unit/test_hardware_info.cpp @@ -0,0 +1,236 @@ +#include "stdafx.h" +#include "doctest.h" +#include "utilities/hardwareinfo.h" + +// what the log says of the machine at startup (utilities/hardwareinfo.h): the names of real GPUs, as DXGI and the +// OpenGL drivers give them, and the text of /proc on Linux +using namespace hardware; + +TEST_CASE("hardware info: NVIDIA GPUs are discrete") +{ + CHECK(classify_gpu(vendor_nvidia, "NVIDIA GeForce RTX 3060") == gpu_kind::discrete); + CHECK(classify_gpu(vendor_nvidia, "NVIDIA GeForce MX150") == gpu_kind::discrete); + CHECK(classify_gpu(vendor_nvidia, "NVIDIA RTX A2000 Laptop GPU") == gpu_kind::discrete); +} + +TEST_CASE("hardware info: Intel GPUs are integrated, except the Arc cards and Iris Xe MAX") +{ + CHECK(classify_gpu(vendor_intel, "Intel(R) UHD Graphics 630") == gpu_kind::integrated); + CHECK(classify_gpu(vendor_intel, "Intel(R) HD Graphics 4600") == gpu_kind::integrated); + CHECK(classify_gpu(vendor_intel, "Intel(R) Iris(R) Xe Graphics") == gpu_kind::integrated); + CHECK(classify_gpu(vendor_intel, "Intel(R) Arc(TM) Graphics") == gpu_kind::integrated); // Meteor Lake + CHECK(classify_gpu(vendor_intel, "Intel(R) Arc(TM) 140V GPU (16GB)") == gpu_kind::integrated); // Lunar Lake + CHECK(classify_gpu(vendor_intel, "Intel(R) Arc(TM) B390 GPU") == gpu_kind::integrated); // Panther Lake + CHECK(classify_gpu(vendor_intel, "Intel(R) Arc(TM) B370 GPU") == gpu_kind::integrated); + CHECK(classify_gpu(vendor_intel, "Intel(R) Arc(TM) A310 Graphics") == gpu_kind::discrete); + CHECK(classify_gpu(vendor_intel, "Intel(R) Arc(TM) A380 Graphics") == gpu_kind::discrete); + CHECK(classify_gpu(vendor_intel, "Intel(R) Arc(TM) A370M Graphics") == gpu_kind::discrete); + CHECK(classify_gpu(vendor_intel, "Intel(R) Arc(TM) B570 Graphics") == gpu_kind::discrete); + CHECK(classify_gpu(vendor_intel, "Intel(R) Arc(TM) A770 Graphics") == gpu_kind::discrete); + CHECK(classify_gpu(vendor_intel, "Intel(R) Arc(TM) B580 Graphics") == gpu_kind::discrete); + CHECK(classify_gpu(vendor_intel, "Intel(R) Arc(TM) Pro A60 Graphics") == gpu_kind::discrete); + CHECK(classify_gpu(vendor_intel, "Intel(R) Iris(R) Xe MAX Graphics") == gpu_kind::discrete); +} + +TEST_CASE("hardware info: AMD cards are discrete, the APUs integrated, the rest unknown") +{ + CHECK(classify_gpu(vendor_amd, "AMD Radeon RX 6600") == gpu_kind::discrete); + CHECK(classify_gpu(vendor_amd, "Radeon RX 580 Series") == gpu_kind::discrete); + CHECK(classify_gpu(vendor_amd, "AMD Radeon Pro W6600") == gpu_kind::discrete); + CHECK(classify_gpu(vendor_amd, "AMD Radeon VII") == gpu_kind::discrete); + CHECK(classify_gpu(vendor_amd, "AMD FirePro W5100") == gpu_kind::discrete); + CHECK(classify_gpu(vendor_amd, "AMD Radeon(TM) Graphics") == gpu_kind::integrated); + CHECK(classify_gpu(vendor_amd, "AMD Radeon(TM) Vega 8 Graphics") == gpu_kind::integrated); + CHECK(classify_gpu(vendor_amd, "AMD Radeon 780M Graphics") == gpu_kind::integrated); + CHECK(classify_gpu(vendor_amd, "AMD Radeon(TM) R7 Graphics") == gpu_kind::integrated); + CHECK(classify_gpu(vendor_amd, "AMD Radeon(TM) RX Vega 11 Graphics") == gpu_kind::integrated); // Raven Ridge + CHECK(classify_gpu(vendor_amd, "AMD Radeon(TM) RX Vega 10 Graphics") == gpu_kind::integrated); + CHECK(classify_gpu(vendor_amd, "Radeon RX Vega") == gpu_kind::discrete); + CHECK(classify_gpu(vendor_amd, "AMD Radeon RX Vega 56") == gpu_kind::discrete); + CHECK(classify_gpu(vendor_amd, "Radeon RX Vega M GH Graphics") == gpu_kind::discrete); // Kaby Lake G, own memory + CHECK(classify_gpu(vendor_amd, "AMD Radeon R7 370") == gpu_kind::unknown); + CHECK(classify_gpu(vendor_amd, "AMD Radeon HD 7850") == gpu_kind::unknown); + CHECK(classify_gpu(vendor_amd_alt, "AMD Radeon(TM) Graphics") == gpu_kind::integrated); +} + +TEST_CASE("hardware info: other vendors are unknown, software renderers software") +{ + CHECK(classify_gpu(0x15ad, "VMware SVGA 3D") == gpu_kind::unknown); + CHECK(classify_gpu(0x5143, "Qualcomm(R) Adreno(TM) X1-85 GPU") == gpu_kind::unknown); + CHECK(classify_gpu(vendor_microsoft, "Microsoft Basic Render Driver") == gpu_kind::software); +} + +TEST_CASE("hardware info: the OpenGL vendor and renderer strings") +{ + // Windows drivers + CHECK(vendor_from_gl("NVIDIA Corporation", "NVIDIA GeForce RTX 3060/PCIe/SSE2") == vendor_nvidia); + CHECK(vendor_from_gl("ATI Technologies Inc.", "AMD Radeon RX 6600") == vendor_amd); + CHECK(vendor_from_gl("Intel", "Intel(R) UHD Graphics 630") == vendor_intel); + // Mesa names the maker in the renderer + CHECK(vendor_from_gl("Mesa", "Mesa Intel(R) UHD Graphics 620 (KBL GT2)") == vendor_intel); + CHECK(vendor_from_gl("X.Org", "AMD Radeon Graphics (radeonsi, renoir, LLVM 15.0.7, DRM 3.49)") == vendor_amd); + CHECK(vendor_from_gl("Mesa", "llvmpipe (LLVM 15.0.7, 256 bits)") == 0); + + CHECK(classify_gl("NVIDIA Corporation", "NVIDIA GeForce RTX 3060/PCIe/SSE2") == gpu_kind::discrete); + CHECK(classify_gl("Intel", "Intel(R) UHD Graphics 630") == gpu_kind::integrated); + CHECK(classify_gl("ATI Technologies Inc.", "AMD Radeon(TM) Graphics") == gpu_kind::integrated); + CHECK(classify_gl("X.Org", "AMD Radeon Graphics (radeonsi, renoir, LLVM 15.0.7, DRM 3.49)") == gpu_kind::integrated); + CHECK(classify_gl("AMD", "AMD Radeon RX 6600 (radeonsi, navi23, LLVM 17.0.6, DRM 3.57)") == gpu_kind::discrete); + CHECK(classify_gl("Intel", "Mesa Intel(R) Arc(tm) A770 Graphics (DG2)") == gpu_kind::discrete); + CHECK(classify_gl("Mesa", "llvmpipe (LLVM 15.0.7, 256 bits)") == gpu_kind::software); + CHECK(classify_gl("Microsoft Corporation", "GDI Generic") == gpu_kind::software); + CHECK(classify_gl("nouveau", "NV138") == gpu_kind::unknown); +} + +namespace { +gpu_adapter adapter(std::string Description, std::uint32_t const VendorId, bool const Software = false) +{ + gpu_adapter result; + result.description = std::move(Description); + result.vendor_id = VendorId; + result.software = Software; + return result; +} +} // namespace + +TEST_CASE("hardware info: a warning when OpenGL runs on the integrated GPU beside a dedicated one") +{ + std::vector const laptop{adapter("Intel(R) UHD Graphics 630", vendor_intel), adapter("NVIDIA GeForce GTX 1650", vendor_nvidia)}; + + auto const warnings{gl_warnings(laptop, "Intel", "Intel(R) UHD Graphics 630")}; + REQUIRE(warnings.size() == 1); + CHECK(warnings.front().starts_with("hardware: warning: ")); + CHECK(warnings.front().find("Intel(R) UHD Graphics 630") != std::string::npos); + CHECK(warnings.front().find("NVIDIA GeForce GTX 1650") != std::string::npos); + + // on the dedicated one all is well + CHECK(gl_warnings(laptop, "NVIDIA Corporation", "NVIDIA GeForce GTX 1650/PCIe/SSE2").empty()); + // a desktop with the integrated GPU only, or a GPU that can't be told, says nothing + CHECK(gl_warnings({adapter("Intel(R) UHD Graphics 630", vendor_intel)}, "Intel", "Intel(R) UHD Graphics 630").empty()); + CHECK(gl_warnings({adapter("AMD Radeon HD 7850", vendor_amd), adapter("Intel(R) HD Graphics 4600", vendor_intel)}, "Intel", "Intel(R) HD Graphics 4600").empty()); + // Linux lists no adapters + CHECK(gl_warnings({}, "Intel", "Mesa Intel(R) UHD Graphics 620 (KBL GT2)").empty()); + // an AMD APU beside an AMD card + CHECK(gl_warnings({adapter("AMD Radeon(TM) Graphics", vendor_amd), adapter("AMD Radeon RX 6600M", vendor_amd)}, "ATI Technologies Inc.", "AMD Radeon(TM) Graphics").size() == 1); + // a Ryzen 2400G with the monitor on the motherboard beside a GeForce, a Panther Lake laptop running GL on the B390 + CHECK(gl_warnings({adapter("AMD Radeon(TM) RX Vega 11 Graphics", vendor_amd), adapter("NVIDIA GeForce GTX 1650", vendor_nvidia)}, "ATI Technologies Inc.", "AMD Radeon(TM) RX Vega 11 Graphics").size() == 1); + CHECK(gl_warnings({adapter("Intel(R) Arc(TM) B390 GPU", vendor_intel), adapter("NVIDIA GeForce RTX 5060 Laptop GPU", vendor_nvidia)}, "Intel", "Intel(R) Arc(TM) B390 GPU").size() == 1); +} + +TEST_CASE("hardware info: a warning when OpenGL draws on the cpu") +{ + auto const warnings{gl_warnings({adapter("NVIDIA GeForce GTX 1650", vendor_nvidia)}, "Microsoft Corporation", "GDI Generic")}; + REQUIRE(warnings.size() == 1); + CHECK(warnings.front().find("GDI Generic") != std::string::npos); +} + +TEST_CASE("hardware info: a warning for a cpu without AVX2 only when the build needs it") +{ + cpu_info cpu; + cpu.avx2 = 0; + CHECK(cpu_warnings(cpu, true).size() == 1); + CHECK(cpu_warnings(cpu, false).empty()); + cpu.avx2 = 1; + CHECK(cpu_warnings(cpu, true).empty()); + cpu.avx2 = -1; // can't tell: no warning + CHECK(cpu_warnings(cpu, true).empty()); +} + +TEST_CASE("hardware info: sizes") +{ + CHECK(format_size(0) == "0 MiB"); + CHECK(format_size(128ULL * 1024 * 1024) == "128 MiB"); + CHECK(format_size(1023ULL * 1024 * 1024) == "1023 MiB"); + CHECK(format_size(1024ULL * 1024 * 1024) == "1.0 GiB"); + CHECK(format_size(12ULL * 1024 * 1024 * 1024) == "12.0 GiB"); + CHECK(format_size(17'058'000'000ULL) == "15.9 GiB"); +} + +TEST_CASE("hardware info: names") +{ + CHECK(tidy_name(" Intel(R) Core(TM) i5-4430 CPU @ 3.00GHz") == "Intel(R) Core(TM) i5-4430 CPU @ 3.00GHz"); + CHECK(tidy_name("AMD Ryzen 5 5600X 6-Core Processor ") == "AMD Ryzen 5 5600X 6-Core Processor"); + CHECK(tidy_name("") == ""); +} + +TEST_CASE("hardware info: /proc/cpuinfo") +{ + // two cores with two threads each, one package; the flags of the first processor count + auto const cpu{parse_cpuinfo("processor\t: 0\n" + "model name\t: Intel(R) Core(TM) i3-7100U CPU @ 2.40GHz\n" + "physical id\t: 0\n" + "core id\t\t: 0\n" + "cpu cores\t: 2\n" + "flags\t\t: fpu vme sse sse2 avx avx2 bmi2\n" + "\n" + "processor\t: 1\n" + "model name\t: Intel(R) Core(TM) i3-7100U CPU @ 2.40GHz\n" + "physical id\t: 0\n" + "core id\t\t: 1\n" + "\n" + "processor\t: 2\n" + "physical id\t: 0\n" + "core id\t\t: 0\n" + "\n" + "processor\t: 3\n" + "physical id\t: 0\n" + "core id\t\t: 1\n")}; + CHECK(cpu.model == "Intel(R) Core(TM) i3-7100U CPU @ 2.40GHz"); + CHECK(cpu.logical_cores == 4); + CHECK(cpu.physical_cores == 2); + CHECK(cpu.avx2 == 1); + + // no core ids (some virtual machines): the cores of the package; no avx2 in the flags + auto const vm{parse_cpuinfo("processor : 0\nmodel name : Some CPU\ncpu cores : 4\nflags : sse sse2 avx\n")}; + CHECK(vm.physical_cores == 4); + CHECK(vm.avx2 == 0); + + // nothing known + auto const empty{parse_cpuinfo("")}; + CHECK(empty.model.empty()); + CHECK(empty.logical_cores == 0); + CHECK(empty.physical_cores == 0); + CHECK(empty.avx2 == -1); +} + +TEST_CASE("hardware info: /proc/meminfo") +{ + auto const memory{parse_meminfo("MemTotal: 16303064 kB\nMemFree: 1234567 kB\nMemAvailable: 8151532 kB\n")}; + CHECK(memory.total == 16303064ULL * 1024); + CHECK(memory.available == 8151532ULL * 1024); + CHECK(parse_meminfo("").total == 0); +} + +TEST_CASE("hardware info: the lines of the log") +{ + cpu_info cpu; + cpu.model = "AMD Ryzen 5 5600X 6-Core Processor"; + cpu.physical_cores = 6; + cpu.logical_cores = 12; + cpu.avx2 = 1; + CHECK(format_cpu(cpu) == "hardware: cpu: AMD Ryzen 5 5600X 6-Core Processor, 6 cores, 12 threads, avx2 yes"); + CHECK(format_cpu(cpu_info{}) == "hardware: cpu: unknown, avx2 unknown"); + + memory_info memory; + memory.total = 16ULL * 1024 * 1024 * 1024; + memory.available = 7ULL * 1024 * 1024 * 1024; + CHECK(format_memory(memory) == "hardware: ram: 16.0 GiB total, 7.0 GiB available"); + CHECK(format_memory(memory_info{}) == "hardware: ram: unknown total"); + + gpu_adapter gpu{adapter("NVIDIA GeForce GTX 1650", vendor_nvidia)}; + gpu.device_id = 0x1f82; + gpu.dedicated_video_memory = 4ULL * 1024 * 1024 * 1024; + gpu.shared_system_memory = 8ULL * 1024 * 1024 * 1024; + gpu.outputs = 1; + CHECK(format_adapter(1, gpu) == "hardware: gpu 1: NVIDIA GeForce GTX 1650 (vendor 0x10de, device 0x1f82), 4.0 GiB dedicated, 8.0 GiB shared, 1 outputs, discrete"); + + CHECK(format_gl("Intel", "Intel(R) UHD Graphics 630") == "hardware: opengl gpu: Intel(R) UHD Graphics 630 (Intel), integrated"); + + gl_memory_info gl; + gl.dedicated = 4ULL * 1024 * 1024 * 1024; + gl.available = 3ULL * 1024 * 1024 * 1024; + CHECK(format_gl_memory(gl) == "hardware: opengl gpu memory: 4.0 GiB dedicated, 3.0 GiB free"); + gl.dedicated = 0; + CHECK(format_gl_memory(gl) == "hardware: opengl gpu memory: 3.0 GiB free"); + CHECK(format_gl_memory(gl_memory_info{}) == "hardware: opengl gpu memory: unknown"); +} diff --git a/utilities/hardwareinfo.cpp b/utilities/hardwareinfo.cpp new file mode 100644 index 000000000..3124307ba --- /dev/null +++ b/utilities/hardwareinfo.cpp @@ -0,0 +1,441 @@ +/* +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/. +*/ + +#include "stdafx.h" +#include "utilities/hardwareinfo.h" + +#include +#include +#include +#include +#include + +namespace hardware { + +namespace { + +std::string lowercase(std::string_view Text) +{ + std::string result{Text}; + for (auto &c : result) + c = static_cast(std::tolower(static_cast(c))); + return result; +} + +bool contains(std::string_view Text, std::string_view What) +{ + return Text.find(What) != std::string_view::npos; +} + +void erase_all(std::string &Text, std::string_view What) +{ + auto at = Text.find(What); + while (at != std::string::npos) + { + Text.erase(at, What.size()); + at = Text.find(What, at); + } +} + +// the words of a GPU name, lowercase: without the (TM) and (R) marks, and without what follows them in parentheses +// (Mesa adds the driver and the chip: "AMD Radeon Graphics (radeonsi, renoir, LLVM 15.0.7)") +std::vector name_words(std::string_view Name) +{ + auto name{lowercase(Name)}; + erase_all(name, "(tm)"); + erase_all(name, "(r)"); + if (auto const parenthesis = name.find('('); parenthesis != std::string::npos) + name.erase(parenthesis); + std::vector words; + std::string word; + for (auto const c : name) + { + if (std::isalnum(static_cast(c))) + { + word += c; + } + else if (!word.empty()) + { + words.push_back(std::move(word)); + word.clear(); + } + } + if (!word.empty()) + words.push_back(std::move(word)); + return words; +} + +// whether the words hold First directly followed by Second +bool has_pair(std::vector const &Words, std::string_view First, std::string_view Second) +{ + for (std::size_t i = 0; i + 1 < Words.size(); ++i) + if (Words[i] == First && Words[i + 1] == Second) + return true; + return false; +} + +bool has_word(std::vector const &Words, std::string_view What) +{ + return std::ranges::find(Words, What) != Words.end(); +} + +bool is_number(std::string_view Word) +{ + return !Word.empty() && std::ranges::all_of(Word, [](char const c) { return std::isdigit(static_cast(c)) != 0; }); +} + +bool is_software_name(std::string_view Name) +{ + constexpr std::array markers{"llvmpipe", "softpipe", "swiftshader", "gdi generic", "software rasterizer", "basic render driver"}; + auto const name{lowercase(Name)}; + return std::ranges::any_of(markers, [&name](std::string_view const Marker) { return contains(name, Marker); }); +} + +gpu_kind classify_intel(std::vector const &Words) +{ + using enum gpu_kind; + // Iris Xe MAX (DG1) is a laptop card + for (std::size_t i = 0; i + 2 < Words.size(); ++i) + if (Words[i] == "iris" && Words[i + 1] == "xe" && Words[i + 2] == "max") + return discrete; + // the Arc cards have a letter and a number after "Arc" (A310, A770, B580) or are the Pro ones; the integrated Arc + // are "Arc Graphics" (Meteor Lake), "Arc 140V" (Lunar Lake) and "Arc B370", "Arc B390" (Panther Lake), the B3xx + // range, below the B570 and B580 cards + for (std::size_t i = 0; i + 1 < Words.size(); ++i) + { + if (Words[i] != "arc") + continue; + auto const &model{Words[i + 1]}; + if (model == "pro") + return discrete; + if (model.size() >= 2 && model[0] == 'b' && model[1] == '3') + return integrated; + if (model.size() >= 2 && std::isalpha(static_cast(model[0])) && std::isdigit(static_cast(model[1]))) + return discrete; + } + return integrated; +} + +// Raven Ridge and Picasso APUs: "Radeon RX Vega 11 Graphics", "Radeon RX Vega 10 Graphics". the RX Vega cards have +// no "Graphics" ("Radeon RX Vega 56"), and Kaby Lake G's own-memory chip has a letter ("Radeon RX Vega M GH Graphics") +bool is_rx_vega_apu(std::vector const &Words) +{ + if (Words.empty() || Words.back() != "graphics") + return false; + for (std::size_t i = 0; i + 2 < Words.size(); ++i) + if (Words[i] == "rx" && Words[i + 1] == "vega" && is_number(Words[i + 2])) + return true; + return false; +} + +gpu_kind classify_amd(std::vector const &Words) +{ + using enum gpu_kind; + if (is_rx_vega_apu(Words)) + return integrated; + if (has_word(Words, "rx") || has_word(Words, "firepro") || has_word(Words, "instinct") || has_pair(Words, "radeon", "pro") || has_pair(Words, "radeon", "vii")) + return discrete; + // the APUs are "Radeon Graphics", "Radeon Vega 8 Graphics", "Radeon R7 Graphics", "Radeon 780M Graphics"; the + // cards are named by their model ("Radeon RX 580 Series", "Radeon R7 370") + if (!Words.empty() && Words.back() == "graphics") + return integrated; + return unknown; +} + +std::string_view yes_no(int const Value) +{ + if (Value > 0) + return "yes"; + if (Value == 0) + return "no"; + return "unknown"; +} + +// "Key: value" of /proc/cpuinfo and /proc/meminfo +std::pair split_entry(std::string_view Line) +{ + auto const colon = Line.find(':'); + if (colon == std::string_view::npos) + return {}; + auto key{Line.substr(0, colon)}; + auto value{Line.substr(colon + 1)}; + while (!key.empty() && std::isspace(static_cast(key.back()))) + key.remove_suffix(1); + while (!value.empty() && std::isspace(static_cast(value.front()))) + value.remove_prefix(1); + while (!value.empty() && std::isspace(static_cast(value.back()))) + value.remove_suffix(1); + return {key, value}; +} + +template void for_each_line(std::string_view Text, Function &&Each) +{ + while (!Text.empty()) + { + auto const end = Text.find('\n'); + Each(Text.substr(0, end)); + if (end == std::string_view::npos) + break; + Text.remove_prefix(end + 1); + } +} + +std::uint64_t to_number(std::string_view Text) +{ + std::uint64_t result{0}; + for (auto const c : Text) + { + if (!std::isdigit(static_cast(c))) + break; + result = result * 10 + static_cast(c - '0'); + } + return result; +} + +// the state of reading /proc/cpuinfo, line by line +struct cpuinfo_reader +{ + cpu_info cpu; + std::set> cores; // (physical id, core id) + std::set> packages; + int cores_per_package{0}; + std::string package; + + void read(std::string_view Line); +}; + +void cpuinfo_reader::read(std::string_view const Line) +{ + auto const [key, value] = split_entry(Line); + if (key == "processor") + { + ++cpu.logical_cores; + package.clear(); + } + else if ((key == "model name" || key == "Model") && cpu.model.empty()) + { + cpu.model = tidy_name(value); + } + else if (key == "physical id") + { + package = value; + packages.emplace(value); + } + else if (key == "core id") + { + cores.emplace(package, value); + } + else if (key == "cpu cores" && cores_per_package == 0) + { + cores_per_package = static_cast(to_number(value)); + } + else if (key == "flags" && cpu.avx2 < 0) + { + auto const flags{name_words(value)}; + cpu.avx2 = has_word(flags, "avx2") ? 1 : 0; + } +} + +} // namespace + +std::string_view to_string(gpu_kind const Kind) +{ + using enum gpu_kind; + switch (Kind) + { + case integrated: + return "integrated"; + case discrete: + return "discrete"; + case software: + return "software"; + default: + return "unknown"; + } +} + +gpu_kind classify_gpu(std::uint32_t const VendorId, std::string_view const Name) +{ + using enum gpu_kind; + if (is_software_name(Name)) + return software; + auto const words{name_words(Name)}; + switch (VendorId) + { + case vendor_nvidia: + return discrete; + case vendor_intel: + return classify_intel(words); + case vendor_amd: + case vendor_amd_alt: + return classify_amd(words); + default: + return unknown; + } +} + +std::uint32_t vendor_from_gl(std::string_view const GlVendor, std::string_view const GlRenderer) +{ + // the vendor first; Mesa ("Mesa", "X.Org", "Collabora Ltd") and the D3D12 layer ("Microsoft Corporation") name + // the maker of the chip in the renderer + for (auto const &text : {lowercase(GlVendor), lowercase(GlRenderer)}) + { + if (contains(text, "nvidia") || contains(text, "geforce") || contains(text, "quadro")) + return vendor_nvidia; + if (contains(text, "ati technologies") || contains(text, "advanced micro devices") || contains(text, "radeon") || has_word(name_words(text), "amd")) + return vendor_amd; + if (contains(text, "intel")) + return vendor_intel; + } + return 0; +} + +bool is_software_gl(std::string_view const GlVendor, std::string_view const GlRenderer) +{ + return is_software_name(GlRenderer) || is_software_name(GlVendor); +} + +gpu_kind classify_gl(std::string_view const GlVendor, std::string_view const GlRenderer) +{ + if (is_software_gl(GlVendor, GlRenderer)) + return gpu_kind::software; + return classify_gpu(vendor_from_gl(GlVendor, GlRenderer), GlRenderer); +} + +std::string format_size(std::uint64_t const Bytes) +{ + constexpr std::uint64_t mebibyte{1024 * 1024}; + constexpr std::uint64_t gibibyte{1024 * mebibyte}; + if (Bytes < gibibyte) + return std::format("{} MiB", (Bytes + mebibyte / 2) / mebibyte); + return std::format("{:.1f} GiB", static_cast(Bytes) / static_cast(gibibyte)); +} + +std::string tidy_name(std::string_view const Name) +{ + std::string result; + for (auto const c : Name) + { + if (c == '\0') + break; + if (std::isspace(static_cast(c))) + { + if (!result.empty() && result.back() != ' ') + result += ' '; + continue; + } + result += c; + } + if (!result.empty() && result.back() == ' ') + result.pop_back(); + return result; +} + +cpu_info parse_cpuinfo(std::string_view const Text) +{ + cpuinfo_reader reader; + for_each_line(Text, [&reader](std::string_view const Line) { reader.read(Line); }); + auto cpu{std::move(reader.cpu)}; + if (!reader.cores.empty()) + cpu.physical_cores = static_cast(reader.cores.size()); + else if (reader.cores_per_package > 0) + cpu.physical_cores = reader.cores_per_package * static_cast(std::max(reader.packages.size(), 1)); + return cpu; +} + +memory_info parse_meminfo(std::string_view const Text) +{ + memory_info memory; + for_each_line(Text, [&memory](std::string_view const Line) { + auto const [key, value] = split_entry(Line); + // the values are in kB (kibibytes, whatever the unit says) + if (key == "MemTotal") + memory.total = to_number(value) * 1024; + else if (key == "MemAvailable") + memory.available = to_number(value) * 1024; + }); + return memory; +} + +std::string format_cpu(cpu_info const &Cpu) +{ + auto line{std::format("hardware: cpu: {}", Cpu.model.empty() ? std::string{"unknown"} : Cpu.model)}; + if (Cpu.physical_cores > 0) + line += std::format(", {} cores", Cpu.physical_cores); + if (Cpu.logical_cores > 0) + line += std::format(", {} threads", Cpu.logical_cores); + line += std::format(", avx2 {}", yes_no(Cpu.avx2)); + return line; +} + +std::string format_memory(memory_info const &Memory) +{ + auto line{std::format("hardware: ram: {} total", Memory.total > 0 ? format_size(Memory.total) : std::string{"unknown"})}; + if (Memory.available > 0) + line += std::format(", {} available", format_size(Memory.available)); + return line; +} + +std::string format_adapter(int const Index, gpu_adapter const &Adapter) +{ + return std::format("hardware: gpu {}: {} (vendor 0x{:04x}, device 0x{:04x}), {} dedicated, {} shared, {} outputs, {}", Index, Adapter.description, Adapter.vendor_id, Adapter.device_id, + format_size(Adapter.dedicated_video_memory), format_size(Adapter.shared_system_memory), Adapter.outputs, + Adapter.software ? to_string(gpu_kind::software) : to_string(classify_gpu(Adapter.vendor_id, Adapter.description))); +} + +std::string format_gl(std::string_view const GlVendor, std::string_view const GlRenderer) +{ + return std::format("hardware: opengl gpu: {} ({}), {}", GlRenderer, GlVendor, to_string(classify_gl(GlVendor, GlRenderer))); +} + +std::string format_gl_memory(gl_memory_info const &Memory) +{ + std::string line{"hardware: opengl gpu memory:"}; + if (Memory.dedicated > 0) + line += std::format(" {} dedicated", format_size(Memory.dedicated)); + if (Memory.available > 0) + line += std::format("{} {} free", Memory.dedicated > 0 ? "," : "", format_size(Memory.available)); + if (Memory.dedicated == 0 && Memory.available == 0) + line += " unknown"; + return line; +} + +std::vector gl_warnings(std::vector const &Adapters, std::string_view const GlVendor, std::string_view const GlRenderer) +{ + std::vector warnings; + auto const kind{classify_gl(GlVendor, GlRenderer)}; + if (kind == gpu_kind::software) + { + warnings.push_back(std::format("hardware: warning: OpenGL draws on the cpu ({}), the graphics driver is missing or not used", GlRenderer)); + return warnings; + } + if (kind != gpu_kind::integrated) + return warnings; + if (auto const discrete = std::ranges::find_if(Adapters, [](gpu_adapter const &Adapter) { + return !Adapter.software && classify_gpu(Adapter.vendor_id, Adapter.description) == gpu_kind::discrete; + }); + discrete != Adapters.end()) + { + warnings.push_back(std::format("hardware: warning: OpenGL runs on the integrated GPU ({}) though there is a dedicated one ({}); " + "choose High performance for the game in the Windows graphics settings or the GPU control panel, " + "and connect the monitor to the dedicated GPU", + GlRenderer, discrete->description)); + } + return warnings; +} + +std::vector cpu_warnings(cpu_info const &Cpu, bool const BuildNeedsAvx2) +{ + std::vector warnings; + if (BuildNeedsAvx2 && Cpu.avx2 == 0) + warnings.emplace_back("hardware: warning: the cpu has no AVX2, which this build of the game needs"); + return warnings; +} + +} // namespace hardware diff --git a/utilities/hardwareinfo.h b/utilities/hardwareinfo.h new file mode 100644 index 000000000..54fdbd02d --- /dev/null +++ b/utilities/hardwareinfo.h @@ -0,0 +1,114 @@ +/* +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/. +*/ + +#pragma once + +#include +#include +#include +#include + +// what the log says about the machine at startup: the cpu, the memory, the graphics adapters and the one OpenGL runs +// on. a bug report then shows whether the game ran on the integrated GPU of a laptop instead of the dedicated one. +// this part holds the rules and the text, which need nothing of the machine; the probing is in hardwareprobe.cpp +namespace hardware { + +// the PCI vendor ids of the graphics adapters +constexpr std::uint32_t vendor_nvidia{0x10de}; +constexpr std::uint32_t vendor_amd{0x1002}; +constexpr std::uint32_t vendor_amd_alt{0x1022}; // AMD's cpu id, shown by some APUs +constexpr std::uint32_t vendor_intel{0x8086}; +constexpr std::uint32_t vendor_microsoft{0x1414}; // Microsoft Basic Render Driver, the software adapter + +enum class gpu_kind { + unknown, // can't tell from the name; never taken for either of the other two + integrated, // part of the cpu, shares the system memory + discrete, // a card (or a chip) with its own memory + software, // drawn by the cpu (Microsoft Basic Render Driver, GDI Generic, llvmpipe) +}; + +std::string_view to_string(gpu_kind Kind); + +// whether a GPU is integrated or discrete, from its vendor and its name (the DXGI description or GL_RENDERER). +// conservative, by the names the vendors give their chips: +// - NVIDIA: discrete (PC NVIDIA graphics have been cards or laptop chips with their own memory since the nForce days) +// - Intel: discrete only for the Arc cards (Arc A380/A770/B580, Arc Pro A60) and Iris Xe MAX; the rest (HD, UHD, +// Iris, Arc Graphics, Arc 140V and Arc B370/B390 of Meteor/Lunar/Panther Lake) is integrated +// - AMD: discrete for Radeon RX/Pro/VII, FirePro and Instinct; integrated for the APU names, which have no model +// number before "Graphics" (Radeon(TM) Graphics, Radeon Vega 8 Graphics, Radeon 780M Graphics, Radeon 8060S +// Graphics), and Radeon RX Vega 11 Graphics of Raven Ridge; anything else (an old Radeon HD, R7 ...) is unknown, as +// both cards and APUs were named so +// - software renderers are software; any other vendor (virtual machines, Qualcomm) is unknown +gpu_kind classify_gpu(std::uint32_t VendorId, std::string_view Name); + +// the PCI vendor id behind the GL_VENDOR and GL_RENDERER strings (Mesa names the vendor in the renderer); 0 if none +std::uint32_t vendor_from_gl(std::string_view GlVendor, std::string_view GlRenderer); + +// whether GL_VENDOR and GL_RENDERER name a renderer that draws on the cpu +bool is_software_gl(std::string_view GlVendor, std::string_view GlRenderer); + +// the kind of the GPU an OpenGL context runs on +gpu_kind classify_gl(std::string_view GlVendor, std::string_view GlRenderer); + +// a graphics adapter of the system (on Windows, as DXGI lists it) +struct gpu_adapter { + std::string description; + std::uint32_t vendor_id{0}; + std::uint32_t device_id{0}; + std::uint64_t dedicated_video_memory{0}; // bytes + std::uint64_t shared_system_memory{0}; // bytes + int outputs{0}; // the monitors connected to it + bool software{false}; +}; + +struct cpu_info { + std::string model; + int logical_cores{0}; // 0: unknown + int physical_cores{0}; // 0: unknown + int avx2{-1}; // 1 yes, 0 no, -1 unknown +}; + +struct memory_info { + std::uint64_t total{0}; // bytes, 0: unknown + std::uint64_t available{0}; // bytes, 0: unknown +}; + +// what the context's driver says of its memory (GL_NVX_gpu_memory_info, GL_ATI_meminfo), in bytes, 0: not told +struct gl_memory_info { + std::uint64_t dedicated{0}; + std::uint64_t available{0}; +}; + +// a size for a person to read: "512 MiB", "7.9 GiB" +std::string format_size(std::uint64_t Bytes); + +// trims the padding cpuid and the registry leave in the cpu brand string, squeezes the runs of spaces +std::string tidy_name(std::string_view Name); + +// what /proc/cpuinfo says of the cpu: the model name, the processors (logical cores) and the distinct cores +cpu_info parse_cpuinfo(std::string_view Text); + +// what /proc/meminfo says of the memory: MemTotal and MemAvailable +memory_info parse_meminfo(std::string_view Text); + +// the lines of the log, every one starting with "hardware: " so a single grep finds them all +std::string format_cpu(cpu_info const &Cpu); +std::string format_memory(memory_info const &Memory); +std::string format_adapter(int Index, gpu_adapter const &Adapter); +std::string format_gl(std::string_view GlVendor, std::string_view GlRenderer); +std::string format_gl_memory(gl_memory_info const &Memory); + +// the warnings of the log about the GPU OpenGL runs on: on the cpu, or on an integrated GPU while the system has a +// discrete one (Adapters: as the system lists them; the software ones are passed over). nothing if all is well +std::vector gl_warnings(std::vector const &Adapters, std::string_view GlVendor, std::string_view GlRenderer); + +// the warning of the log about a cpu without AVX2 when the build needs it. nothing if all is well +std::vector cpu_warnings(cpu_info const &Cpu, bool BuildNeedsAvx2); + +} // namespace hardware diff --git a/utilities/hardwareprobe.cpp b/utilities/hardwareprobe.cpp new file mode 100644 index 000000000..b7574281b --- /dev/null +++ b/utilities/hardwareprobe.cpp @@ -0,0 +1,336 @@ +/* +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/. +*/ + +#include "stdafx.h" +#include "utilities/hardwareprobe.h" + +#include "utilities/hardwareinfo.h" +#include "utilities/Logs.h" + +#include +#include + +#if defined(_M_X64) || defined(_M_IX86) || defined(__x86_64__) || defined(__i386__) +#define EU07_HARDWARE_X86 1 +#ifdef _MSC_VER +#include +#else +#include +#endif +#endif + +#ifdef _WIN32 +#include +#endif + +namespace hardware { + +namespace { + +// the adapters log_system() found, for the warning of log_gl_context() +std::vector &system_adapters() +{ + static std::vector adapters; + return adapters; +} + +#ifdef EU07_HARDWARE_X86 +// the eax, ebx, ecx and edx the cpuid instruction gives for the provided leaf and subleaf +std::array cpuid(unsigned int const Leaf, unsigned int const Subleaf) +{ + std::array result{}; +#ifdef _MSC_VER + std::array registers{}; + __cpuidex(registers.data(), static_cast(Leaf), static_cast(Subleaf)); + for (std::size_t i = 0; i < result.size(); ++i) + result[i] = static_cast(registers[i]); +#else + __cpuid_count(Leaf, Subleaf, result[0], result[1], result[2], result[3]); +#endif + return result; +} + +// the brand string of the cpu ("AMD Ryzen 5 5600X 6-Core Processor"); empty if the cpu has none +std::string cpu_brand() +{ + if (cpuid(0x80000000u, 0)[0] < 0x80000004u) + return {}; + std::array brand{}; + for (unsigned int leaf = 0; leaf < 3; ++leaf) + { + auto const registers{cpuid(0x80000002u + leaf, 0)}; + std::memcpy(brand.data() + leaf * 16, registers.data(), 16); + } + return tidy_name(brand.data()); +} + +// whether the cpu has AVX2 and the system saves the AVX registers +int cpu_avx2() +{ +#ifdef _MSC_VER + if (cpuid(0, 0)[0] < 7) + return 0; + auto const features{cpuid(1, 0)}; + auto const osxsave{(features[2] & (1u << 27)) != 0}; + auto const avx{(features[2] & (1u << 28)) != 0}; + if (!osxsave || !avx) + return 0; + if ((_xgetbv(0) & 0x6) != 0x6) // the system saves xmm and ymm + return 0; + return (cpuid(7, 0)[1] & (1u << 5)) != 0 ? 1 : 0; +#else + // checks the system's support as well + __builtin_cpu_init(); + return __builtin_cpu_supports("avx2") ? 1 : 0; +#endif +} +#endif + +#ifdef _WIN32 +std::string narrow(wchar_t const *Text) +{ + auto const length{WideCharToMultiByte(CP_UTF8, 0, Text, -1, nullptr, 0, nullptr, nullptr)}; + if (length <= 1) + return {}; + std::string result(static_cast(length - 1), '\0'); + WideCharToMultiByte(CP_UTF8, 0, Text, -1, result.data(), length, nullptr, nullptr); + return result; +} + +std::string registry_cpu_name() +{ + char name[256]{}; + DWORD size{sizeof(name)}; + if (RegGetValueA(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", "ProcessorNameString", RRF_RT_REG_SZ, nullptr, name, &size) != ERROR_SUCCESS) + return {}; + return tidy_name(name); +} + +int physical_cores() +{ + DWORD length{0}; + GetLogicalProcessorInformationEx(RelationProcessorCore, nullptr, &length); + if (length == 0) + return 0; + std::vector buffer(length); + auto *records{reinterpret_cast(buffer.data())}; + if (!GetLogicalProcessorInformationEx(RelationProcessorCore, records, &length)) + return 0; + int cores{0}; + for (DWORD offset = 0; offset < length;) + { + auto const *record{reinterpret_cast(buffer.data() + offset)}; + if (record->Size == 0) + break; + ++cores; + offset += record->Size; + } + return cores; +} + +cpu_info probe_cpu() +{ + cpu_info cpu; +#ifdef EU07_HARDWARE_X86 + cpu.model = cpu_brand(); + cpu.avx2 = cpu_avx2(); +#endif + if (cpu.model.empty()) + cpu.model = registry_cpu_name(); + cpu.logical_cores = static_cast(GetActiveProcessorCount(ALL_PROCESSOR_GROUPS)); + cpu.physical_cores = physical_cores(); + return cpu; +} + +memory_info probe_memory() +{ + memory_info memory; + MEMORYSTATUSEX status{}; + status.dwLength = sizeof(status); + if (GlobalMemoryStatusEx(&status)) + { + memory.total = status.ullTotalPhys; + memory.available = status.ullAvailPhys; + } + return memory; +} + +// the adapters DXGI lists, the software one left out. dxgi.dll is loaded only for this, so the game doesn't link it; +// from System32 only, so a proxy dxgi.dll left in the game folder (ReShade, ENB) isn't loaded with it +std::vector probe_adapters() +{ + std::vector adapters; + auto *library{LoadLibraryExW(L"dxgi.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32)}; + if (library == nullptr) + { + WriteLog("hardware: gpus: dxgi.dll not found"); + return adapters; + } + using create_factory = HRESULT(WINAPI *)(REFIID, void **); + auto const create{reinterpret_cast(reinterpret_cast(GetProcAddress(library, "CreateDXGIFactory1")))}; + IDXGIFactory1 *factory{nullptr}; + if (create == nullptr || FAILED(create(__uuidof(IDXGIFactory1), reinterpret_cast(&factory))) || factory == nullptr) + { + WriteLog("hardware: gpus: can't create a DXGI factory"); + FreeLibrary(library); + return adapters; + } + IDXGIAdapter1 *adapter{nullptr}; + for (UINT index = 0; SUCCEEDED(factory->EnumAdapters1(index, &adapter)); ++index) + { + DXGI_ADAPTER_DESC1 description{}; + if (SUCCEEDED(adapter->GetDesc1(&description))) + { + gpu_adapter entry; + entry.description = tidy_name(narrow(description.Description)); + entry.vendor_id = description.VendorId; + entry.device_id = description.DeviceId; + entry.dedicated_video_memory = description.DedicatedVideoMemory; + entry.shared_system_memory = description.SharedSystemMemory; + entry.software = (description.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) != 0 || description.VendorId == vendor_microsoft; + IDXGIOutput *output{nullptr}; + while (SUCCEEDED(adapter->EnumOutputs(static_cast(entry.outputs), &output))) + { + output->Release(); + ++entry.outputs; + } + if (!entry.software) + adapters.push_back(std::move(entry)); + } + adapter->Release(); + } + factory->Release(); + FreeLibrary(library); + return adapters; +} +#else +std::string read_file(char const *Path) +{ + std::ifstream file{Path}; + if (!file) + return {}; + std::stringstream text; + text << file.rdbuf(); + return text.str(); +} + +cpu_info probe_cpu() +{ + auto cpu{parse_cpuinfo(read_file("/proc/cpuinfo"))}; +#ifdef EU07_HARDWARE_X86 + if (cpu.model.empty()) + cpu.model = cpu_brand(); + cpu.avx2 = cpu_avx2(); +#endif + if (cpu.logical_cores == 0) + cpu.logical_cores = static_cast(std::thread::hardware_concurrency()); + return cpu; +} + +memory_info probe_memory() +{ + return parse_meminfo(read_file("/proc/meminfo")); +} +#endif + +std::string gl_string(GLenum const Name) +{ + auto const *text{reinterpret_cast(glGetString(Name))}; + return text != nullptr ? std::string{text} : std::string{"unknown"}; +} + +bool has_gl_extension(std::string_view const Name) +{ + if (glGetStringi != nullptr) + { + GLint count{0}; + glGetIntegerv(GL_NUM_EXTENSIONS, &count); + for (GLint i = 0; i < count; ++i) + { + auto const *extension{reinterpret_cast(glGetStringi(GL_EXTENSIONS, static_cast(i)))}; + if (extension != nullptr && Name == extension) + return true; + } + return false; + } + // OpenGL ES 2: one string of them all + auto const *extensions{reinterpret_cast(glGetString(GL_EXTENSIONS))}; + return extensions != nullptr && std::string_view{extensions}.find(Name) != std::string_view::npos; +} + +gl_memory_info probe_gl_memory() +{ + // GL_NVX_gpu_memory_info and GL_ATI_meminfo tokens, in kilobytes + constexpr GLenum gpu_memory_info_dedicated_vidmem_nvx{0x9047}; + constexpr GLenum gpu_memory_info_current_available_vidmem_nvx{0x9049}; + constexpr GLenum texture_free_memory_ati{0x87fc}; + + gl_memory_info memory; + if (has_gl_extension("GL_NVX_gpu_memory_info")) + { + GLint kilobytes{0}; + glGetIntegerv(gpu_memory_info_dedicated_vidmem_nvx, &kilobytes); + memory.dedicated = static_cast(std::max(kilobytes, 0)) * 1024; + kilobytes = 0; + glGetIntegerv(gpu_memory_info_current_available_vidmem_nvx, &kilobytes); + memory.available = static_cast(std::max(kilobytes, 0)) * 1024; + } + else if (has_gl_extension("GL_ATI_meminfo")) + { + // the free memory of the texture pool, the largest free block, and the same of the auxiliary memory + std::array kilobytes{}; + glGetIntegerv(texture_free_memory_ati, kilobytes.data()); + memory.available = static_cast(std::max(kilobytes[0], 0)) * 1024; + } + // a driver that takes the queries amiss leaves an error the renderer would report as its own. each call takes one + // error off; a lost context may keep reporting one, hence the limit + constexpr int max_errors{32}; + for (int i = 0; i < max_errors && glGetError() != GL_NO_ERROR; ++i) + { + // nothing else to do + } + return memory; +} + +} // namespace + +void log_system() +{ + auto const cpu{probe_cpu()}; + WriteLog(format_cpu(cpu)); + // an AVX2 build on a cpu without it may die on an illegal instruction before this line; when it gets here (the + // start so far ran without an AVX2 or FMA instruction), the line names the cause of the crash that comes later +#ifdef __AVX2__ + constexpr bool build_needs_avx2{true}; +#else + constexpr bool build_needs_avx2{false}; +#endif + for (auto const &warning : cpu_warnings(cpu, build_needs_avx2)) + WriteLog(warning); + WriteLog(format_memory(probe_memory())); +#ifdef _WIN32 + auto &adapters{system_adapters()}; + adapters = probe_adapters(); + for (std::size_t index = 0; index < adapters.size(); ++index) + WriteLog(format_adapter(static_cast(index), adapters[index])); +#endif +} + +void log_gl_context() +{ + auto const vendor{gl_string(GL_VENDOR)}; + auto const renderer{gl_string(GL_RENDERER)}; + WriteLog(format_gl(vendor, renderer)); + if (auto const memory{probe_gl_memory()}; memory.dedicated > 0 || memory.available > 0) + WriteLog(format_gl_memory(memory)); + for (auto const &warning : gl_warnings(system_adapters(), vendor, renderer)) + WriteLog(warning); +} + +} // namespace hardware diff --git a/utilities/hardwareprobe.h b/utilities/hardwareprobe.h new file mode 100644 index 000000000..75cb1e405 --- /dev/null +++ b/utilities/hardwareprobe.h @@ -0,0 +1,22 @@ +/* +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/. +*/ + +#pragma once + +// writes the machine to the log at startup, every line starting with "hardware: " (see hardwareinfo.h) +namespace hardware { + +// the cpu, the memory and, on Windows, the graphics adapters DXGI lists +void log_system(); + +// the GPU the current OpenGL context runs on, its memory where the driver tells it, and a warning when it's the +// integrated GPU while the system has a dedicated one. after log_system(), with the context current +void log_gl_context(); + +} // namespace hardware From dc9e1b2ebd1c54f93cb3131b349b6a27ddebc655 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 06:16:08 +0100 Subject: [PATCH 25/27] test(scenarios): AI through a section without voltage and with interlocked line contactors (#272, #276) (#467) * test(scenarios): AI through a section without voltage and with interlocked line contactors Scenario cases for the parts of #272 (line breaker ahead of the pantographs, PantRequiresMain) and #276 (line contactors interlocked with the vehicle's own converter, LineContactorsInterlock) that had not been run in the simulator before. They all run the AI on the timetable run of td.scn. - ep05_td_dead_section: an EP05 runs under power into a 61 m span of overhead wire that has no voltage. Its line breaker stays closed, the traction force drops to 0, and behind the span the AI takes power again and stops at Przystanek. eu07_td_dead_section is the same run with an EU07, as a reference for the old behaviour: its line breaker opens after 0.2 s and the AI closes it again. - ep05_td_neutral_section: the same span, with the track under it marked overhead 0. The AI coasts from before the dead wire. - ep05_td_section_insulator: a 1 m section insulator, run under power. The 0.2 s voltage hold keeps the traction force up past it. - et42_td_converter_interlock(_cold): an ET42 with the interlock starts up and runs its timetable. - ep05_td_interlock_dead_section_cold: both keys on one EP05, starting cold, with the dead span on its way. - ep05_td_timetable: the plain timetable run of the EP05, as a reference. The runner gets vehicle_variants, a vehicle of the case's own made from one of the game's with .fiz replacements. The game's ET42 data doesn't have the interlock key yet. The runner also gets two new checks: traction (the traction force between two distances travelled) and master_controller. The local converter switch of #276 can't be covered: only the cab can set it, and in test mode nobody sits in a cab. * test(scenarios): the ET42 interlock case that fails without the interlock The ET42 interlock cases checked only that the AI gets the train going, which a plain ET42 does too. A case with a converter that starts 60 s after it is switched on shows the interlock taking effect: the train reaches 20 km/h at 80.0 s with it and at 73.8 s without it, and the starts check gets an optional lower bound, after, to fail the early one. The runner also checks the case's expect and --watch before it writes anything into the game folder, and builds the scenery inside the try that removes the case's files, so an exit or Ctrl+C there leaves none. --- tests/scenarios/README.md | 62 ++++++++- .../scenarios/cases/ep05_td_dead_section.json | 22 +++ .../ep05_td_interlock_dead_section_cold.json | 28 ++++ .../cases/ep05_td_neutral_section.json | 26 ++++ .../cases/ep05_td_section_insulator.json | 21 +++ tests/scenarios/cases/ep05_td_timetable.json | 17 +++ .../cases/et42_td_converter_interlock.json | 24 ++++ .../et42_td_converter_interlock_cold.json | 27 ++++ ...td_converter_interlock_slow_converter.json | 27 ++++ .../scenarios/cases/eu07_td_dead_section.json | 22 +++ tests/scenarios/run.py | 129 +++++++++++++++--- 11 files changed, 388 insertions(+), 17 deletions(-) create mode 100644 tests/scenarios/cases/ep05_td_dead_section.json create mode 100644 tests/scenarios/cases/ep05_td_interlock_dead_section_cold.json create mode 100644 tests/scenarios/cases/ep05_td_neutral_section.json create mode 100644 tests/scenarios/cases/ep05_td_section_insulator.json create mode 100644 tests/scenarios/cases/ep05_td_timetable.json create mode 100644 tests/scenarios/cases/et42_td_converter_interlock.json create mode 100644 tests/scenarios/cases/et42_td_converter_interlock_cold.json create mode 100644 tests/scenarios/cases/et42_td_converter_interlock_slow_converter.json create mode 100644 tests/scenarios/cases/eu07_td_dead_section.json diff --git a/tests/scenarios/README.md b/tests/scenarios/README.md index d85bd15e9..e021bb398 100644 --- a/tests/scenarios/README.md +++ b/tests/scenarios/README.md @@ -215,6 +215,7 @@ to `logs/`. | `fragment` | `.scn` file in `cases/` added to the scenery: trainsets after `FirstInit` (before it they derail on unlinked track), the rest before it (launchers read after it never fire). Optional when the case keeps the scenery's trainsets | | `vars` | values for `{{name}}` in the fragment; a list becomes one line per item | | `timetable` | a timetable file in `cases/` for a trainset of the fragment, for a train whose timetable no scenery of the game has: copied to the game's `scenery/` dir as `autotest_.txt` for the run and removed after it; the fragment names it `{{timetable}}` | +| `vehicle_variants` | vehicles of the case's own, made from those of the game, e.g. with a `.fiz` key the game's data doesn't have yet: a list of `{ "name": ..., "from": "/", "replace": [[old, new], ...] }`. For the run the vehicle's `.fiz`, with the literal replacements (an `old` it doesn't have is an error), and its `.mmd` are copied beside it in the game's `dynamic/` dir as `autotest__` and removed after it; the fragment names the type `{{variant_}}`, e.g. `dynamic pkp/et42_v2 112e-014-a {{variant_a}} ...`. The copy of the `.mmd` has the name of the vehicle it is made from in place of `(p2)`, the type name the simulator hands it, which some pass on to the include that names the model | | `expect` | the result the test mode should end with: `pass`, `fail`, `signal_passed_at_danger`, `timeout`, `standstill` or `error`, or `wall_timeout` for the timeout of the real time watchdog (the timeout code with a verdict saying it was the real time; a case expecting `timeout` fails on it). Default `timeout` for a case with `duration`, else `pass` | | `duration` | seconds of simulation to record: the test timeout of the run (`--test-timeout`) | | `timeout` | wall-clock seconds before giving up, loading included: the simulator's `--test-wall-timeout` (default 600) | @@ -396,6 +397,57 @@ working it stops at 0.57 m/s², 99 m: that is `eu07_td_reinspect_brakes_legacy_i of the earlier releases (`ai.brakesetting.cw1 no`), which cuts no brake out, and also what a build whose `reinspect_brakes()` does nothing gives for the first case, which then fails. The test passes 150 s after the driver goes. +The `*_section*` and `*_converter_interlock*` cases are about the line breaker closed ahead of the pantographs +(`PantRequiresMain=Yes` in `Cntrl.`, MaSzyna-EU07/maszyna#272) and the line contactors that wait for the +converter of their own vehicle (`LineContactorsInterlock=Converter`, #276), driven by the AI on the timetable +run of td.scn. The overhead wire of td.scn is changed with `replace`: one span of it, 61 m some 400 m from +the start (`0.7764 5.845 1561.2417` onwards, over the way out of Stacja1, which the train runs under power at +50-55 km/h), gets no supply and 0 V (`traction none 0`), and in `ep05_td_section_insulator` the span before +it is split around a section insulator 1 m long (`traction * 0`, as sceneries hang insulators). The EP05 has +`PantRequiresMain=Yes` in the game's data; the ET42 has no `LineContactorsInterlock` yet (SVN data of #276), +so those cases run variants of the vehicles made for the run (`vehicle_variants`). + +- `ep05_td_timetable`: the EP05 on the plain timetable run, the reference: 20 km/h after 73 s, the stop + after 205 s and 1400 m. +- `ep05_td_dead_section`: the EP05 runs into the span without voltage under power, nothing on the track + telling its driver to coast. The traction force drops to nothing at once and the AI puts the master + controller to 0; the line breaker stays closed (the log + says the vehicle lost power for 4.05 s, which it says only while the line breaker is closed). Behind the + section the AI takes power again (535 m, 36 kN by 595 m) and stops at Przystanek (1399 m). +- `ep05_td_neutral_section`: the same with the track under that span, `koniec`, marked as one to coast + through (`overhead 0`, which `track_events` adds as it adds events): the AI puts the master controller to + 0 as the locomotive runs onto it, 25 m ahead of the dead wire, and takes power again behind it. +- `eu07_td_dead_section`: the old behaviour for reference, an EU07 (pantographs first) into the same span: + its line breaker opens after 0.2 s (`lost power for 0.21 sec`, no longer), and behind the section the AI + closes it again and takes power (493 m). +- `ep05_td_section_insulator`: the EP05 runs under the insulator under power at 50 km/h. The pantograph is + without voltage for some 0.07 s, which the vehicle bridges by holding the last voltage for 0.2 s + (`TDynamicObject::Update`): the traction force stays between 50 and 58 kN past it and nothing is logged. + Without the hold the undervoltage relay of a `PantRequiresMain` vehicle would open the line contactors, + which close again only with the master controller back at its first position. With the insulator 15 m long + instead (a trial run) the vehicle does lose power there (logged, the force drops to 0), which shows the + pantograph runs under the piece of wire. +- `et42_td_converter_interlock_cold`: an ET42 with `LineContactorsInterlock=Converter` in both sections + stands cold (`td_cold_timetable.scn`) and is ordered to run the timetable: the AI starts the converters, + leaves (20 km/h after 74 s) and stops at Przystanek (1393 m). It and `et42_td_converter_interlock`, the + same from the timetable start, check that the AI gets such a train going; a plain ET42 passes them too. +- `et42_td_converter_interlock_slow_converter`: the check that the interlock takes effect. The same cold ET42 + with a converter that starts 60 s after it is switched on (`ConverterStartDelay=60`): the line contactors + wait for it, and the train reaches 20 km/h at 80.0 s; `starts` with `after: 77` fails it earlier. With the + same converter and no interlock it gets there at 73.8 s, as fast as without the slow converter (a copy of + the case without the key, run once, not kept). +- `ep05_td_interlock_dead_section_cold`: #272 and #276 together, an EP05 with `LineContactorsInterlock=Converter` + added, standing cold, with the span without voltage on its way: the pantographs can go up only through the + closed line breaker, so the AI has to close it first, then start the converter; it leaves (20 km/h after + 77 s). Under the dead wire the converter stops with the main circuit, behind it the converter starts again + and the AI takes power (573 m, 4 s later than the EP05 without the interlock) and stops at Przystanek + (1393 m). + +What these can't reach: the local converter switch of the ET42 (`converterlocal_sw:`), which the AI has to put +back on (`LineContactorsHeldByLocalConverterSwitch()`, the part of #276 in `determine_consist_state()` and +the `converteron` hint), is in the cab only: no command of a scenery or of the train's cables sets +`ConverterAllowLocal`, and nobody sits in a cab in the test mode, so the switch is always on in a case. + ### Cases on a mission of a scenery The cases made from players' reports (eu07/maszyna#421, #506, #524, #525) run a whole mission @@ -450,7 +502,8 @@ the physicslog Velocity column, which is the wheel speed: it stays at 0 while th locked in a skid. The ones marked *vehicle speed* use the vehicle speed column at the end of the row instead, logged by builds from this branch on. -- `starts` `min_speed`, `within`: reaches `min_speed` within `within` seconds. +- `starts` `min_speed`, `within` (`after`): reaches `min_speed` within `within` seconds (and not before `after` seconds, + when given). - `max_speed` `limit`, `tolerance`: never goes faster than `limit + tolerance`. - `brakes` `min_pressure`: after moving off, brake cylinder pressure reaches `min_pressure` bar (physicslog pressures are in bar whatever its header says; the brake pipe runs at 5.0). @@ -497,6 +550,13 @@ the row instead, logged by builds from this branch on. cut out stops slower. - `moves` `vehicle`, `min_speed`, optional `direction` (`front`, or `rear`): the black box has the vehicle reach `min_speed` with that end leading (the physicslog speed has no direction). +- `traction` `from_distance`, `to_distance`, and one or more of `reaches`, `at_most`, `at_least`: the + traction force in kN (the physicslog has it in N, whatever its header says) while the vehicle runs between + the two distances (metres travelled, as in `distance`): its highest there reaches `reaches`, e.g. the power + taken again behind a section without voltage; it stays at or below `at_most`, e.g. none under a dead wire; + it stays at or above `at_least`, e.g. no power lost under an insulator. +- `master_controller` `from_distance`, `to_distance`, `at_most`: the master controller stays at or below the + position between the two distances, e.g. at 0 where the scenery tells the driver to coast. New check types go in `CHECKS` in `run.py`; each gets the physicslog rows and the check's parameters and returns `(passed, detail)`. Checks on the log go in `LOG_CHECKS` and get the diff --git a/tests/scenarios/cases/ep05_td_dead_section.json b/tests/scenarios/cases/ep05_td_dead_section.json new file mode 100644 index 000000000..d6bfe2c49 --- /dev/null +++ b/tests/scenarios/cases/ep05_td_dead_section.json @@ -0,0 +1,22 @@ +{ + "description": "#272: an EP05 (PantRequiresMain=Yes: its line breaker closes ahead of the pantographs and holds without voltage) runs the td/rozklad timetable of td.scn with one span of the overhead wire on its way, 61 m some 400 m from the start, left without voltage, and nothing on the track to tell the driver to coast. The AI runs into it under power: the line breaker stays closed (the log keeps saying the vehicle lost power, which it says only while the line breaker is closed), the traction force drops to nothing and the AI puts the master controller to 0; behind the section the AI takes power again and stops at Przystanek.", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_timetable.scn", + "vars": { + "consist": "node -1 0 {{vehicle}} dynamic pkp/ep05_v2 ep05-23 ep05 0 headdriver 0 0 enddynamic" + }, + "replace": [ + ["node -1 0 none traction pwr01 3500 4500 0.01 cu 3.0 1\r\n0.7764 5.845 1561.2417", "node -1 0 none traction none 0 4500 0.01 cu 3.0 1\r\n0.7764 5.845 1561.2417"] + ], + "duration": 240, + "timeout": 600, + "checks": [ + {"type": "starts", "min_speed": 20, "within": 150}, + {"type": "max_speed", "limit": 90, "tolerance": 3}, + {"type": "traction", "from_distance": 420, "to_distance": 455, "at_most": 1}, + {"type": "traction", "from_distance": 460, "to_distance": 620, "reaches": 25}, + {"type": "log_contains", "pattern": "lost power for [3-9]\\.\\d\\d sec"}, + {"type": "stops", "moving_speed": 20, "stop_speed": 1.0, "hold": 0, "min_distance": 1380, "max_distance": 1420} + ] +} diff --git a/tests/scenarios/cases/ep05_td_interlock_dead_section_cold.json b/tests/scenarios/cases/ep05_td_interlock_dead_section_cold.json new file mode 100644 index 000000000..4cccc94f5 --- /dev/null +++ b/tests/scenarios/cases/ep05_td_interlock_dead_section_cold.json @@ -0,0 +1,28 @@ +{ + "description": "#272 with #276: an EP05 whose line breaker closes ahead of the pantographs (PantRequiresMain=Yes) and whose line contactors close only with its own converter running (LineContactorsInterlock=Converter, a variant of the .fiz made for the run) stands cold on track 1 of Stacja1 and gets the order to run the td/rozklad timetable, with the span without voltage of ep05_td_dead_section on its way. The pantographs go up only through the closed line breaker, so the AI has to close it first, then start the converter, and leave; under the dead wire the main circuit, and with it the converter, has no voltage; behind it the AI takes power again and stops at Przystanek.", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_cold_timetable.scn", + "vars": { + "consist": "node -1 0 {{vehicle}} dynamic pkp/ep05_v2 ep05-23 {{variant_ep05}} 0 headdriver 0 0 enddynamic" + }, + "vehicle_variants": [ + {"name": "ep05", "from": "pkp/ep05_v2/ep05", "replace": [["Camshaft=Yes PantRequiresMain=Yes", "Camshaft=Yes PantRequiresMain=Yes LineContactorsInterlock=Converter"]]} + ], + "replace": [ + ["node -1 0 none traction pwr01 3500 4500 0.01 cu 3.0 1\r\n0.7764 5.845 1561.2417", "node -1 0 none traction none 0 4500 0.01 cu 3.0 1\r\n0.7764 5.845 1561.2417"] + ], + "track_events": { + "tdo_n1734": "event0 autotest_wake" + }, + "duration": 300, + "timeout": 600, + "checks": [ + {"type": "starts", "min_speed": 20, "within": 150}, + {"type": "max_speed", "limit": 90, "tolerance": 3}, + {"type": "traction", "from_distance": 420, "to_distance": 455, "at_most": 1}, + {"type": "traction", "from_distance": 460, "to_distance": 620, "reaches": 25}, + {"type": "log_contains", "pattern": "lost power for [3-9]\\.\\d\\d sec"}, + {"type": "stops", "moving_speed": 20, "stop_speed": 1.0, "hold": 0, "min_distance": 1380, "max_distance": 1420} + ] +} diff --git a/tests/scenarios/cases/ep05_td_neutral_section.json b/tests/scenarios/cases/ep05_td_neutral_section.json new file mode 100644 index 000000000..ea261b0b7 --- /dev/null +++ b/tests/scenarios/cases/ep05_td_neutral_section.json @@ -0,0 +1,26 @@ +{ + "description": "#272: as ep05_td_dead_section, with the track under the span without voltage (koniec, 371-466 m) marked as a section to coast through (overhead 0), as a scenery marks a neutral section: the AI puts the master controller to zero when the locomotive runs onto that track, coasts under the dead wire with the line breaker closed, and takes power again behind it.", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_timetable.scn", + "vars": { + "consist": "node -1 0 {{vehicle}} dynamic pkp/ep05_v2 ep05-23 ep05 0 headdriver 0 0 enddynamic" + }, + "replace": [ + ["node -1 0 none traction pwr01 3500 4500 0.01 cu 3.0 1\r\n0.7764 5.845 1561.2417", "node -1 0 none traction none 0 4500 0.01 cu 3.0 1\r\n0.7764 5.845 1561.2417"] + ], + "track_events": { + "koniec": "overhead 0" + }, + "duration": 240, + "timeout": 600, + "checks": [ + {"type": "starts", "min_speed": 20, "within": 150}, + {"type": "max_speed", "limit": 90, "tolerance": 3}, + {"type": "master_controller", "from_distance": 395, "to_distance": 455, "at_most": 0}, + {"type": "traction", "from_distance": 415, "to_distance": 455, "at_most": 1}, + {"type": "traction", "from_distance": 470, "to_distance": 640, "reaches": 25}, + {"type": "log_contains", "pattern": "lost power for [3-9]\\.\\d\\d sec"}, + {"type": "stops", "moving_speed": 20, "stop_speed": 1.0, "hold": 0, "min_distance": 1380, "max_distance": 1420} + ] +} diff --git a/tests/scenarios/cases/ep05_td_section_insulator.json b/tests/scenarios/cases/ep05_td_section_insulator.json new file mode 100644 index 000000000..2490bcf9b --- /dev/null +++ b/tests/scenarios/cases/ep05_td_section_insulator.json @@ -0,0 +1,21 @@ +{ + "description": "#272: the EP05 of ep05_td_timetable runs under power under a section insulator: a piece of the overhead wire 1 m long with no supply (\"*\", 0 V), some 375 m from the start. The pantograph is without voltage for a few hundredths of a second, which the vehicle bridges by holding the last voltage for 0.2 s (TDynamicObject::Update). Without the hold the undervoltage relay would open the line contactors, which on a PantRequiresMain vehicle close again only with the master controller back at its first position: the traction force stays up all the way past the insulator.", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_timetable.scn", + "vars": { + "consist": "node -1 0 {{vehicle}} dynamic pkp/ep05_v2 ep05-23 ep05 0 headdriver 0 0 enddynamic" + }, + "replace": [ + ["node -1 0 none traction pwr01 3500 4500 0.01 cu 3.0 1\r\n0.687223 5.8 1500.25\r\n0.7764 5.845 1561.2417\r\n0.687223 7.5 1500.25\r\n0.7764 7.545 1561.2417\r\n0.4 4.0 3 0.04 vis\r\nendtraction", "node -1 0 none traction pwr01 3500 4500 0.01 cu 3.0 1\r\n0.687223 5.8 1500.25\r\n0.7457 5.8295 1540.2499\r\n0.687223 7.5 1500.25\r\n0.7457 7.5295 1540.2499\r\n0.4 4.0 3 0.04 vis\r\nendtraction\r\nnode -1 0 none traction * 0 4500 0.01 cu 3.0 1\r\n0.7457 5.8295 1540.2499\r\n0.7472 5.8302 1541.2499\r\n0.7457 7.5295 1540.2499\r\n0.7472 7.5302 1541.2499\r\n0.4 4.0 3 0.04 vis\r\nendtraction\r\nnode -1 0 none traction pwr01 3500 4500 0.01 cu 3.0 1\r\n0.7472 5.8302 1541.2499\r\n0.7764 5.845 1561.2417\r\n0.7472 7.5302 1541.2499\r\n0.7764 7.545 1561.2417\r\n0.4 4.0 3 0.04 vis\r\nendtraction"] + ], + "duration": 240, + "timeout": 600, + "checks": [ + {"type": "starts", "min_speed": 20, "within": 150}, + {"type": "max_speed", "limit": 90, "tolerance": 3}, + {"type": "traction", "from_distance": 345, "to_distance": 395, "at_least": 30}, + {"type": "log_lacks", "pattern": "lost power"}, + {"type": "stops", "moving_speed": 20, "stop_speed": 1.0, "hold": 0, "min_distance": 1380, "max_distance": 1420} + ] +} diff --git a/tests/scenarios/cases/ep05_td_timetable.json b/tests/scenarios/cases/ep05_td_timetable.json new file mode 100644 index 000000000..4291cdb72 --- /dev/null +++ b/tests/scenarios/cases/ep05_td_timetable.json @@ -0,0 +1,17 @@ +{ + "description": "EP05 (PantRequiresMain=Yes) on td.scn, AI driver on the td/rozklad timetable: starts from Stacja1, keeps to the speed limit, brakes to a stop at Przystanek. The reference run of the ep05_td_*_section cases, with the overhead wire live all the way.", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_timetable.scn", + "vars": { + "consist": "node -1 0 {{vehicle}} dynamic pkp/ep05_v2 ep05-23 ep05 0 headdriver 0 0 enddynamic" + }, + "duration": 240, + "timeout": 600, + "checks": [ + {"type": "starts", "min_speed": 20, "within": 150}, + {"type": "max_speed", "limit": 90, "tolerance": 3}, + {"type": "brakes", "min_pressure": 0.5}, + {"type": "stops", "moving_speed": 20, "stop_speed": 1.0, "hold": 0, "min_distance": 1380, "max_distance": 1420} + ] +} diff --git a/tests/scenarios/cases/et42_td_converter_interlock.json b/tests/scenarios/cases/et42_td_converter_interlock.json new file mode 100644 index 000000000..35d78a4f4 --- /dev/null +++ b/tests/scenarios/cases/et42_td_converter_interlock.json @@ -0,0 +1,24 @@ +{ + "description": "#276: as et42_td_converter_interlock_cold, from the timetable start (trainset velocity 0.1, the locomotive ready to go).", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_timetable.scn", + "vars": { + "consist": [ + "node -1 0 {{vehicle}} dynamic pkp/et42_v2 112e-014-a {{variant_a}} 0 headdriver 255 0 enddynamic", + "node -1 0 {{vehicle}}_b dynamic pkp/et42_v2 112e-014-b {{variant_b}} 0 nobody 3 0 enddynamic" + ] + }, + "vehicle_variants": [ + {"name": "a", "from": "pkp/et42_v2/112e-a", "replace": [["IniCDelay=0.5 SCDelay=0.1", "IniCDelay=0.5 SCDelay=0.1 LineContactorsInterlock=Converter"]]}, + {"name": "b", "from": "pkp/et42_v2/112e-b", "replace": [["IniCDelay=0.5 SCDelay=0.1", "IniCDelay=0.5 SCDelay=0.1 LineContactorsInterlock=Converter"]]} + ], + "duration": 240, + "timeout": 600, + "checks": [ + {"type": "starts", "min_speed": 20, "within": 150}, + {"type": "max_speed", "limit": 90, "tolerance": 3}, + {"type": "brakes", "min_pressure": 0.5}, + {"type": "stops", "moving_speed": 20, "stop_speed": 1.0, "hold": 0, "min_distance": 1380, "max_distance": 1420} + ] +} diff --git a/tests/scenarios/cases/et42_td_converter_interlock_cold.json b/tests/scenarios/cases/et42_td_converter_interlock_cold.json new file mode 100644 index 000000000..f8dfdff56 --- /dev/null +++ b/tests/scenarios/cases/et42_td_converter_interlock_cold.json @@ -0,0 +1,27 @@ +{ + "description": "#276: an ET42 whose sections take power only with their own converter running (LineContactorsInterlock=Converter in Cntrl., the .fiz key the shipped et42_v2 doesn't have yet: a variant of both sections made for the run) stands cold on track 1 of Stacja1 on td.scn and gets the order to run the td/rozklad timetable. The AI has to start the converters before the line contactors close: it leaves, keeps to the speed limit and stops at Przystanek.", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_cold_timetable.scn", + "vars": { + "consist": [ + "node -1 0 {{vehicle}} dynamic pkp/et42_v2 112e-014-a {{variant_a}} 0 headdriver 255 0 enddynamic", + "node -1 0 {{vehicle}}_b dynamic pkp/et42_v2 112e-014-b {{variant_b}} 0 nobody 3 0 enddynamic" + ] + }, + "vehicle_variants": [ + {"name": "a", "from": "pkp/et42_v2/112e-a", "replace": [["IniCDelay=0.5 SCDelay=0.1", "IniCDelay=0.5 SCDelay=0.1 LineContactorsInterlock=Converter"]]}, + {"name": "b", "from": "pkp/et42_v2/112e-b", "replace": [["IniCDelay=0.5 SCDelay=0.1", "IniCDelay=0.5 SCDelay=0.1 LineContactorsInterlock=Converter"]]} + ], + "track_events": { + "tdo_n1734": "event0 autotest_wake" + }, + "duration": 300, + "timeout": 600, + "checks": [ + {"type": "starts", "min_speed": 20, "within": 150}, + {"type": "max_speed", "limit": 90, "tolerance": 3}, + {"type": "brakes", "min_pressure": 0.5}, + {"type": "stops", "moving_speed": 20, "stop_speed": 1.0, "hold": 0, "min_distance": 1380, "max_distance": 1420} + ] +} diff --git a/tests/scenarios/cases/et42_td_converter_interlock_slow_converter.json b/tests/scenarios/cases/et42_td_converter_interlock_slow_converter.json new file mode 100644 index 000000000..d492aa671 --- /dev/null +++ b/tests/scenarios/cases/et42_td_converter_interlock_slow_converter.json @@ -0,0 +1,27 @@ +{ + "description": "#276, the check that the interlock takes effect: the ET42 of et42_td_converter_interlock_cold, with ConverterStartDelay=60 added to both sections, so the converters need a minute to start. With LineContactorsInterlock=Converter the line contactors wait for them and the train leaves later than it does with the same converter delay and no interlock (20 km/h at 80.0 s with it, at 73.8 s without it, measured with this case and a copy without the interlock key). Then it runs the timetable to Przystanek.", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_cold_timetable.scn", + "vars": { + "consist": [ + "node -1 0 {{vehicle}} dynamic pkp/et42_v2 112e-014-a {{variant_a}} 0 headdriver 255 0 enddynamic", + "node -1 0 {{vehicle}}_b dynamic pkp/et42_v2 112e-014-b {{variant_b}} 0 nobody 3 0 enddynamic" + ] + }, + "vehicle_variants": [ + {"name": "a", "from": "pkp/et42_v2/112e-a", "replace": [["IniCDelay=0.5 SCDelay=0.1", "IniCDelay=0.5 SCDelay=0.1 LineContactorsInterlock=Converter ConverterStartDelay=60"]]}, + {"name": "b", "from": "pkp/et42_v2/112e-b", "replace": [["IniCDelay=0.5 SCDelay=0.1", "IniCDelay=0.5 SCDelay=0.1 LineContactorsInterlock=Converter ConverterStartDelay=60"]]} + ], + "track_events": { + "tdo_n1734": "event0 autotest_wake" + }, + "duration": 300, + "timeout": 600, + "checks": [ + {"type": "starts", "min_speed": 20, "after": 77, "within": 150}, + {"type": "max_speed", "limit": 90, "tolerance": 3}, + {"type": "brakes", "min_pressure": 0.5}, + {"type": "stops", "moving_speed": 20, "stop_speed": 1, "hold": 0, "min_distance": 1380, "max_distance": 1420} + ] +} diff --git a/tests/scenarios/cases/eu07_td_dead_section.json b/tests/scenarios/cases/eu07_td_dead_section.json new file mode 100644 index 000000000..44c4c38f5 --- /dev/null +++ b/tests/scenarios/cases/eu07_td_dead_section.json @@ -0,0 +1,22 @@ +{ + "description": "The reference of ep05_td_dead_section: an EU07, whose pantographs come first and whose line breaker opens without voltage (no PantRequiresMain), runs into the same span without voltage under power. Its line breaker opens 0.2 s into the section (the log says it lost power for 0.2x s, no longer: it says so only while the line breaker is closed), and behind it the AI closes the line breaker again, takes power and stops at Przystanek.", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_timetable.scn", + "vars": { + "consist": "node -1 0 {{vehicle}} dynamic pkp/4e_v1 4e-004 4e 0 headdriver 0 0 enddynamic" + }, + "replace": [ + ["node -1 0 none traction pwr01 3500 4500 0.01 cu 3.0 1\r\n0.7764 5.845 1561.2417", "node -1 0 none traction none 0 4500 0.01 cu 3.0 1\r\n0.7764 5.845 1561.2417"] + ], + "duration": 240, + "timeout": 600, + "checks": [ + {"type": "starts", "min_speed": 20, "within": 150}, + {"type": "max_speed", "limit": 90, "tolerance": 3}, + {"type": "log_contains", "pattern": "lost power for 0\\.2\\d sec"}, + {"type": "log_lacks", "pattern": "lost power for (0\\.[3-9]|[1-9])"}, + {"type": "traction", "from_distance": 460, "to_distance": 700, "reaches": 25}, + {"type": "stops", "moving_speed": 20, "stop_speed": 1.0, "hold": 0, "min_distance": 1380, "max_distance": 1420} + ] +} diff --git a/tests/scenarios/run.py b/tests/scenarios/run.py index 2dcec6f0d..fef87c4f3 100644 --- a/tests/scenarios/run.py +++ b/tests/scenarios/run.py @@ -49,7 +49,9 @@ OUT_DIR = HERE / "out" # Velocity is in km/h and pressures in bar, despite the header saying m/s and MPa. COL_TIME = 0 COL_VELOCITY = 1 # wheel speed: stays at 0 while the wheels are locked in a skid +COL_TRACTION_FORCE = 5 # N, despite the header saying kN COL_BRAKE_PRESS = 8 +COL_MASTER_CONTROLLER = 11 # the position of the master controller COL_COMMAND = 16 # text, read as None COL_WHEELSLIP = 20 COL_VEHICLE_VELOCITY = 25 # signed vehicle speed, km/h; only in builds which log it @@ -155,6 +157,46 @@ def timetable_path(game_dir: Path, case_name: str) -> Path: return game_dir / "scenery" / f"{timetable_name(case_name)}.txt" +def variant_name(case_name: str, name: str) -> str: + """A vehicle variant of the case as a trainset names it: {{variant_}} in the fragment.""" + return f"autotest_{case_name}_{name}" + + +def variant_paths(game_dir: Path, case_name: str, variant: dict) -> list[Path]: + """The .fiz and .mmd of a vehicle variant of the case, beside those of the vehicle it is made from.""" + folder = (game_dir / "dynamic" / variant["from"]).parent + return [folder / f"{variant_name(case_name, variant['name'])}{suffix}" for suffix in (".fiz", ".mmd")] + + +def write_vehicle_variants(case: dict, game_dir: Path, case_name: str) -> None: + """Writes the case's vehicle variants into the game's dynamic/ dir: a copy of a vehicle's .fiz with the + case's replacements, e.g. a .fiz key the shipped data doesn't have yet, and a copy of its .mmd. The + simulator hands the .mmd its type name as (p2), which some pass on to the include that names the + model (et42_v2: `include 112e-a.mmd.inc (p2) end`, `models: (p1).t3d`), so the copy has the name of + the vehicle it is made from in place of (p2) and looks and loads as that one does.""" + files = {} + for variant in case.get("vehicle_variants", []): + source = game_dir / "dynamic" / variant["from"] + # .fiz files are cp1250 like the sceneries; latin-1 round-trips every byte + fiz = source.with_name(source.name + ".fiz").read_bytes().decode("latin-1") + for old, new in variant.get("replace", []): + if old not in fiz: + sys.exit(f"vehicle_variants: {variant['from']}.fiz has no {old!r}") + fiz = fiz.replace(old, new) + mmd = source.with_name(source.name + ".mmd").read_bytes().decode("latin-1").replace("(p2)", source.name) + fiz_path, mmd_path = variant_paths(game_dir, case_name, variant) + files[fiz_path], files[mmd_path] = fiz, mmd + # written once every variant is made, so a case with a wrong replacement leaves nothing in the game dir + for path, text in files.items(): + path.write_bytes(text.encode("latin-1")) + + +def remove_vehicle_variants(case: dict, game_dir: Path, case_name: str) -> None: + for variant in case.get("vehicle_variants", []): + for path in variant_paths(game_dir, case_name, variant): + path.unlink(missing_ok=True) + + def build_scenery(case: dict, game_dir: Path, case_name: str, vehicle: str) -> str: """Writes the case scenery into the game's scenery dir and returns its file name.""" scenery_dir = game_dir / "scenery" @@ -175,8 +217,9 @@ def build_scenery(case: dict, game_dir: Path, case_name: str, vehicle: str) -> s # a case on a mission of the base scenery may have nothing to add but its test_config fragment = (CASES_DIR / case["fragment"]).read_bytes().decode("latin-1") if "fragment" in case else "" # vars first: {{vehicle}} and {{timetable}} inside a var's value get filled in the second pass - fragment = fill_vars(fragment, case.get("vars", {}), keep={"vehicle", "timetable"}) - fragment = fill_vars(fragment, {"vehicle": vehicle, "timetable": timetable_name(case_name)}) + variants = {f"variant_{v['name']}": variant_name(case_name, v["name"]) for v in case.get("vehicle_variants", [])} + fragment = fill_vars(fragment, case.get("vars", {}), keep={"vehicle", "timetable", *variants}) + fragment = fill_vars(fragment, {"vehicle": vehicle, "timetable": timetable_name(case_name), **variants}) # FirstInit binds event launchers to their events and links the tracks. so launchers and # events of the case go in before it (read after it they never fire), trainsets after it # (placed before it they stand on unlinked track and derail at once) @@ -192,6 +235,8 @@ def build_scenery(case: dict, game_dir: Path, case_name: str, vehicle: str) -> s else: text += header + before + "\n" text += header + trainsets + "\n" + # vehicles of the case's own, made from those of the game + write_vehicle_variants(case, game_dir, case_name) name = f"autotest_{case_name}.scn" (scenery_dir / name).write_bytes(text.encode("latin-1")) # a timetable of the case's own, for a train whose timetable the sceneries of the game have none like @@ -442,11 +487,14 @@ def run_simulator(exe: Path, game_dir: Path, scenery: str, ini: Path, physicslog # ---------------------------------------------------------------- checks -def check_starts(rows, min_speed, within): +def check_starts(rows, min_speed, within, after=None): for r in rows: if r[COL_TIME] > within: break if r[COL_VELOCITY] >= min_speed: + # a case can also say the train mustn't leave before something it waits for (a converter starting) + if after is not None and r[COL_TIME] < after: + return False, f"reached {min_speed} km/h at t={r[COL_TIME]:.1f}s, before {after}s" return True, f"reached {min_speed} km/h at t={r[COL_TIME]:.1f}s" top = max((r[COL_VELOCITY] for r in rows if r[COL_TIME] <= within), default=0.0) return False, f"top speed in the first {within}s was {top:.1f} km/h, wanted {min_speed}" @@ -602,7 +650,51 @@ def check_slip_clears(rows, moving_speed, stop_speed, within): return True, f"stopped at t={rows[stop][COL_TIME]:.1f}s, no slipping after t={deadline:.1f}s" +def check_traction(rows, from_distance, to_distance, reaches=None, at_most=None, at_least=None): + """The traction force of the vehicle in kN (the physicslog has it in N, whatever its header says) while it + runs between two points of its way, in metres travelled as in `distance`: the highest there `reaches` a + force, e.g. the power taken again behind a section without voltage; it stays `at_most` a force, e.g. none + taken where there is no voltage; it stays `at_least` a force, e.g. no power lost under an insulator.""" + dist = _distances(rows) + window = [(d, r) for d, r in zip(dist, rows) if from_distance <= d <= to_distance] + if not window: + return False, f"never got between {from_distance} and {to_distance} m (travelled {dist[-1] if dist else 0:.0f} m)" + + def describe(item): + d, r = item + return f"{r[COL_TRACTION_FORCE] / 1000:.1f} kN at {d:.0f} m, t={r[COL_TIME]:.1f}s, v={r[COL_VELOCITY]:.1f} km/h" + + top = max(window, key=lambda item: item[1][COL_TRACTION_FORCE]) + low = min(window, key=lambda item: item[1][COL_TRACTION_FORCE]) + detail = (f"between {from_distance} and {to_distance} m (t={window[0][1][COL_TIME]:.1f}-{window[-1][1][COL_TIME]:.1f}s) " + f"the traction force was {describe(low)} at its lowest, {describe(top)} at its highest") + if reaches is not None and top[1][COL_TRACTION_FORCE] / 1000 < reaches: + return False, f"{detail}; wanted it to reach {reaches} kN" + if at_most is not None and top[1][COL_TRACTION_FORCE] / 1000 > at_most: + return False, f"{detail}; wanted at most {at_most} kN" + if at_least is not None and low[1][COL_TRACTION_FORCE] / 1000 < at_least: + return False, f"{detail}; wanted at least {at_least} kN" + return True, detail + + +def check_master_controller(rows, from_distance, to_distance, at_most): + """The master controller of the vehicle stays at or below a position while it runs between two points of its + way (metres travelled, as in `distance`), e.g. at 0 where the scenery tells the driver to coast.""" + dist = _distances(rows) + window = [(d, r) for d, r in zip(dist, rows) if from_distance <= d <= to_distance] + if not window: + return False, f"never got between {from_distance} and {to_distance} m (travelled {dist[-1] if dist else 0:.0f} m)" + d, top = max(window, key=lambda item: item[1][COL_MASTER_CONTROLLER]) + detail = (f"between {from_distance} and {to_distance} m (t={window[0][1][COL_TIME]:.1f}-{window[-1][1][COL_TIME]:.1f}s) " + f"the master controller was at {top[COL_MASTER_CONTROLLER]:.0f} at most, at {d:.0f} m, t={top[COL_TIME]:.1f}s") + if top[COL_MASTER_CONTROLLER] > at_most: + return False, f"{detail}; wanted at most {at_most}" + return True, detail + + CHECKS = { + "master_controller": check_master_controller, + "traction": check_traction, "slips": check_slips, "slip_clears": check_slip_clears, "holds_still": check_holds_still, @@ -856,15 +948,6 @@ def _run_case(name: str, case: dict, exe: Path, game_dir: Path, timespeed: float if not with_physicslog and (watch or needs_physicslog): sys.exit(f"{name}: with physicslog off a case can have log checks only ({', '.join(LOG_CHECKS)}), " "and can't run with --watch") - scenery = build_scenery(case, game_dir, name, vehicle) - ini = out / "autotest.ini" - # the case's own settings go last, over the common ones; then the seed of this run of the suite, if any - settings = [*case.get("ini", []), *([f"randomseed {seed}"] if seed else [])] - ini.write_text(TEST_INI.format(timespeed=timespeed, physicslog="yes" if with_physicslog else "no") - + "".join(line + "\n" for line in settings), encoding="ascii") - physicslog = game_dir / "physicslog" / f"{vehicle}.dat" - started = time.time() - 1 - duration = float(case["duration"]) if "duration" in case else None # a case that only records `duration` seconds ends on the test timeout; one that says # how the test ends (a pass event, a signal passed at danger...) expects that result @@ -873,10 +956,24 @@ def _run_case(name: str, case: dict, exe: Path, game_dir: Path, timespeed: float sys.exit(f"{name}: expect must be one of {', '.join(RESULTS)}") if watch and duration is None: sys.exit(f"{name}: --watch needs a case with duration") - result = run_simulator(exe, game_dir, scenery, ini, physicslog, - duration, float(case.get("timeout", 600)), watch, say, - expect_rows=with_physicslog and not own_vehicle) - timetable_path(game_dir, name).unlink(missing_ok=True) + + ini = out / "autotest.ini" + # the case's own settings go last, over the common ones; then the seed of this run of the suite, if any + settings = [*case.get("ini", []), *([f"randomseed {seed}"] if seed else [])] + ini.write_text(TEST_INI.format(timespeed=timespeed, physicslog="yes" if with_physicslog else "no") + + "".join(line + "\n" for line in settings), encoding="ascii") + physicslog = game_dir / "physicslog" / f"{vehicle}.dat" + started = time.time() - 1 + # from here on the case has files of its own in the game dir (the vehicle variants, the timetable) + try: + scenery = build_scenery(case, game_dir, name, vehicle) + result = run_simulator(exe, game_dir, scenery, ini, physicslog, + duration, float(case.get("timeout", 600)), watch, say, + expect_rows=with_physicslog and not own_vehicle) + finally: + # the case's own files go from the game dir also when the run is broken off (ctrl+c) + timetable_path(game_dir, name).unlink(missing_ok=True) + remove_vehicle_variants(case, game_dir, name) # a case that asked for no geometry cache (file.binary.terrain no) leaves none of an earlier run behind if any(line.split()[:2] == ["file.binary.terrain", "no"] for line in case.get("ini", [])): scenery_cache(game_dir, name).unlink(missing_ok=True) From 2d16657c2e313e2aad0e69a5fe0f521161f266db Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 06:16:59 +0100 Subject: [PATCH 26/27] fix(ai): keep the locomotive released while it pushes the buffers in to uncouple (#482) * test(scenarios): the L053 poranek cases now fail on the station's SM42 #409 fixed what both l053_poranek_tme222158_debica cases were marked xfail for: the EP07 on Tm4 stops at the checkpoint, and the ET21 no longer stands off the wire at Debica Towarowa. Run on staging f15ea405, neither passes yet: TME222158 gets to Debica and reports there, but the station's SM42-1096, ordered to uncouple at step 10 of deb_sm42_stat, pushes its cut past debica_k_sem_info at danger and never gets the coupler off, so the station never gives TME222158 step 1 and both runs end as a standstill (4347 s and 4576 s of simulation time). The xfail marks stay, with that reason. * fix(ai): keep the locomotive released while it pushes the buffers in to uncouple Stage 3 of uncoupling (TController::UpdateDisconnect) ends only when the locomotive has pushed the buffers together: a screw coupler is let go with the buffers under 0.01 m apart (or over 0.2 m). Nothing else ends the stage. The consist brakes applied in stage 2 hold the locomotive as well, and only its brake releaser lets it go. The AI worked the releaser in that stage only while it wanted to speed up (AccDesired above -0.05), together with the start-off rules of control_releaser. When the cut stands across a signal at stop for the direction the locomotive pushes in, the driver counts the signal as passed at its first move after the direction change, VelSignalLast becomes 0 and AccDesired stays at -0.05 or -0.85. The releaser then went off, the brake cylinder filled again from the brake pipe, the pressure switch cut the power, and the locomotive stood for good with the buffers 0.018 m apart. The station's SM42-1096 at Debica on L053 poranek did that at step 10 of deb_sm42_stat and logged "actuating and compressing buffers..." for the rest of the run (a temporary log line showed the brake cylinder going from 1.25 to 3.69 bar with the releaser off, and the gap staying at 0.0184 m). In stage 3 the releaser now stays on while the locomotive's brake cylinder holds more than 0.1 bar, whatever AccDesired is. The push asks for 2 km/h at most and the cut stays braked, so this changes nothing else. Everything else, including the rest of the uncoupling (the direction changes before and after it) and coupling, keeps the old rule. The overcharge guard (pipe above 5.2 bar) still turns the releaser off. The decision moves into vehicle/brakereleaser.{h,cpp} so it is unit tested; control_releaser does the same cues in the same order as before. On L053 poranek the SM42 now uncouples at step 10 in 0.2 s (gap 0.021 -> 0.0096 m) and the mission goes on. * test(scenarios): a shunter uncouples with its wagons standing across a signal at stop sm42_td_uncouple_past_signal (fragment td_uncouple_past_signal.scn) rebuilds the uncoupling of the SM42 at Debica on L053 poranek on td.scn. An SM42 pulls three loaded wagons back along tor1k, stops in front of a closed track with the far end of the last wagon 2 m past the exit signal stacja1_j at stop, and gets Shunt 0 0 at once. The pull leaves the screw coupler 0.019 m apart at the buffers. Before the fix of the releaser the locomotive stayed braked and the case ran into its timeout with no "uncoupled" in the log; now it uncouples within a second. * test(scenarios): the L053 poranek cases pass again With the station's SM42-1096 uncoupling at step 10 of deb_sm42_stat again (the releaser fix before this commit), both l053_poranek_tme222158_debica cases pass: TME222158 gets its exit signal at Debica after 4086.2 s of simulation, and with the ET21 after 4131.6 s. The xfail marks go, so that the runner doesn't fail on XPASS, and the README rows say so. --- CMakeLists.txt | 1 + tests/scenarios/README.md | 19 ++- .../cases/l053_poranek_tme222158_debica.json | 1 - .../l053_poranek_tme222158_debica_et21.json | 1 - .../cases/sm42_td_uncouple_past_signal.json | 25 ++++ .../cases/td_uncouple_past_signal.scn | 31 +++++ tests/unit/test_brake_releaser.cpp | 114 ++++++++++++++++++ vehicle/Driver.cpp | 50 +++----- vehicle/brakereleaser.cpp | 60 +++++++++ vehicle/brakereleaser.h | 39 ++++++ 10 files changed, 306 insertions(+), 35 deletions(-) create mode 100644 tests/scenarios/cases/sm42_td_uncouple_past_signal.json create mode 100644 tests/scenarios/cases/td_uncouple_past_signal.scn create mode 100644 tests/unit/test_brake_releaser.cpp create mode 100644 vehicle/brakereleaser.cpp create mode 100644 vehicle/brakereleaser.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 3627ef518..34be53811 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -576,6 +576,7 @@ set(CORE_SOURCES "vehicle/drivingaid.cpp" "vehicle/brakingcurve.cpp" "vehicle/signalpassing.cpp" +"vehicle/brakereleaser.cpp" "vehicle/handover.cpp" "vehicle/crew.cpp" "vehicle/horn.cpp" diff --git a/tests/scenarios/README.md b/tests/scenarios/README.md index e021bb398..6d6317bd7 100644 --- a/tests/scenarios/README.md +++ b/tests/scenarios/README.md @@ -326,6 +326,21 @@ Przystanek whatever the buckle. With 600 mm over a main lobe of 8 m the locomoti the buckle at 46 km/h, 1036 m from the start (`Bad driving: ... derailed on buckled track`); with 30 mm it keeps on the rails and stops at Przystanek after 1400 m. +`sm42_td_uncouple_past_signal` (fragment `td_uncouple_past_signal.scn`) is the uncoupling of the SM42 at Debica on +L053 poranek (step 10 of `deb_sm42_stat`) on td.scn. An SM42 with no timetable stands turned at the far end of `tor1k`, +three wagons loaded with gravel (51 m of train) behind it towards the exit signal `stacja1_j`, which stays at stop (no +route). `tdo_n1734`, the track behind `tor1k`, is closed (`trackvel 0`) from the start. `event0` of `tor1k` gives the +driver `Shunt -1 0`: it pulls the wagons back for 47 m and stops in front of the closed track, with the far end of the +last wagon 2 m past the signal's memory cell (the `distance` check keeps it 0-4 m past). The pull leaves the screw +coupler stretched, 0.019 m apart at the buffers, and a screw coupler is let go only with the buffers pressed together +(under 0.01 m). At the first stand `event0` gives `Shunt 0 0`: brake the wagons, change direction, push the buffers in, +uncouple. After the direction change the driver counts `stacja1_j` as passed at its first move, so its speed is capped +at 0. The driver used to work the brake releaser only while it wanted to speed up, so the locomotive stayed braked by +the wagons' brake application and never closed the gap: no `uncoupled` in the log, and the case ran into its timeout. +Now the locomotive is released, eases into the wagons and uncouples within a second. The wagons are loaded so that the +stop leaves the gap above 0.01 m: with a coach and an empty wagon the buffers came to rest 0.009 m apart and the +coupler let go at once. + The `*_td_crew_*` cases (eu07/maszyna#510, fragment `td_crew.scn`) are about the crew command of a `putvalues` event, `Crew: `: cab 1 or -1 puts an AI driver in cab A or B of the vehicle named, 0 takes its AI driver off. The vehicle is named in the text, so the events are @@ -485,8 +500,8 @@ staging f15ea405 of 2026-11-23): | `wrzosy_pxe336080_couples` | #524 | passes: ordered to, the locomotive couples to the rake (`couples`, 262 s) and takes it out of the depot (696 s). The scenery itself gives no such order | | `baltyk_skm1_roj55324_shunting_signal` | #525 | passes, with four seeds: the unit on the siding is let into the platforms 4 minutes after the start, once the shunter beside it has done its first moves, and leaves at 10:42 | | `baltyk_skm1_roj55321_departure` | #525 | passes, with three seeds: the unit in the platform leaves at 10:34 | -| `l053_poranek_tme222158_debica` | #421 | `xfail`: on master of 2026-11-11 the station jammed 4 minutes after the start, the AI of EP07-338'16 passed the shunting signal Tm4 at stop at 29 km/h. Since #409 (staging f15ea405, 2026-11-23) the EP07 stops at the checkpoint and TME222158 gets to Debica, but the station's SM42-1096 jams it: ordered to uncouple at step 10 of `deb_sm42_stat` it pushes its cut past `debica_k_sem_info` at danger and never gets the coupler off, so the station never sends TME222158 on | -| `l053_poranek_tme222158_debica_et21` | #421 | `xfail`: on master of 2026-11-11, with an ET21 as in the report, the locomotive stopped for good at Debica Towarowa, on the headshunt 20 m past the end of the overhead wire, and its driver never got out of `Prepare_engine`. Since #409 (staging f15ea405) the ET21 gets through Debica Towarowa (steps 1-5 of `dt_tme222158_stat`) to Debica, then fails on the SM42 as `l053_poranek_tme222158_debica` does | +| `l053_poranek_tme222158_debica` | #421 | passes: TME222158 gets the exit signal to Sandomierz (step 6 of `deb_tme222158_stat`) after 4086.2 s. On master of 2026-11-11 the station jammed 4 minutes after the start, the AI of EP07-338'16 passed the shunting signal Tm4 at stop at 29 km/h; #409 fixed that. On staging f15ea405 (2026-11-23) the station's SM42-1096 jammed it next: ordered to uncouple at step 10 of `deb_sm42_stat`, with its cut standing across `debica_k_sem_info` at stop, it stayed braked and never got the coupler off (standstill after 4347 s), until the AI kept the locomotive released while it pushes the buffers in to uncouple (`sm42_td_uncouple_past_signal`) | +| `l053_poranek_tme222158_debica_et21` | #421 | passes after 4131.6 s. On master of 2026-11-11, with an ET21 as in the report, the locomotive stopped for good at Debica Towarowa, on the headshunt 20 m past the end of the overhead wire, and its driver never got out of `Prepare_engine`. Since #409 the ET21 gets through Debica Towarowa (steps 1-5 of `dt_tme222158_stat`) to Debica; there it waited for the SM42 as `l053_poranek_tme222158_debica` did, until the same fix | | `l053_poludnie_roj32134_debica` | #506 | passes: both trains run and the unit ends at Debica after 6134 s; no train in its way | In the L053 sceneries the test mode logs a signal passed at danger for several shunting diff --git a/tests/scenarios/cases/l053_poranek_tme222158_debica.json b/tests/scenarios/cases/l053_poranek_tme222158_debica.json index cba4a9830..dde90e86a 100644 --- a/tests/scenarios/cases/l053_poranek_tme222158_debica.json +++ b/tests/scenarios/cases/l053_poranek_tme222158_debica.json @@ -10,7 +10,6 @@ "reason": "tme222158_got_the_exit_signal_at_debica" }, "slow": true, - "xfail": "eu07/maszyna#421 is not reached, the station's SM42 jams Debica: since #409 EP07-338'16 stops at the checkpoint before Tm4 (tor1834:event0) and TME222158 is let in and reports at Debica (deb_tme222158_stat c 0), but SM42-1096, ordered to uncouple at step 10 of deb_sm42_stat, pushes its cut past debica_k_sem_info at danger and never gets the coupler off (\"Uncoupling [sm42-1096]: actuating and compressing buffers... from front\" for the rest of the run), so it never does step 11 and the station never gives TME222158 step 1: standstill after 4347 s", "physicslog": false, "ini": [ "file.binary.terrain no" diff --git a/tests/scenarios/cases/l053_poranek_tme222158_debica_et21.json b/tests/scenarios/cases/l053_poranek_tme222158_debica_et21.json index 62785a518..7ad5a1a78 100644 --- a/tests/scenarios/cases/l053_poranek_tme222158_debica_et21.json +++ b/tests/scenarios/cases/l053_poranek_tme222158_debica_et21.json @@ -16,7 +16,6 @@ "reason": "tme222158_got_the_exit_signal_at_debica" }, "slow": true, - "xfail": "eu07/maszyna#421 is not reached, the station's SM42 jams Debica, as in l053_poranek_tme222158_debica: since #409 the ET21 no longer stands off the wire at Debica Towarowa, it gets through steps 1-5 of dt_tme222158_stat, takes the wagons to Debica and reports there (deb_tme222158_stat c 0), but SM42-1096, ordered to uncouple at step 10 of deb_sm42_stat, pushes its cut past debica_k_sem_info at danger and never gets the coupler off (\"Uncoupling [sm42-1096]: actuating and compressing buffers... from front\" for the rest of the run), so it never does step 11 and the station never gives TME222158 step 1: standstill after 4576 s", "physicslog": false, "ini": [ "file.binary.terrain no" diff --git a/tests/scenarios/cases/sm42_td_uncouple_past_signal.json b/tests/scenarios/cases/sm42_td_uncouple_past_signal.json new file mode 100644 index 000000000..f1ae7b835 --- /dev/null +++ b/tests/scenarios/cases/sm42_td_uncouple_past_signal.json @@ -0,0 +1,25 @@ +{ + "description": "SM42 shunter on td.scn pulls three loaded wagons back along tor1k and stops with the far end of the last one a few metres past the exit signal stacja1_j at stop, then gets Shunt 0 0 (uncouple): after the direction change the signal lies at stop over that wagon, behind the new head, and the AI has to push the buffers in all the same and let the coupler go.", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_uncouple_past_signal.scn", + "vars": { + "wagons": [ + "node -1 0 {{vehicle}}_w3 dynamic pkp\\401z_v2 82515940087-8 401zp_2 0 nobody 3 60 gravel enddynamic", + "node -1 0 {{vehicle}}_w2 dynamic pkp\\401z_v2 82515942691-5 401zp_1 0 nobody 3 60 gravel enddynamic", + "node -1 0 {{vehicle}}_w1 dynamic pkp\\401z_v2 82515993043-7 401zl_2 0 nobody 3 60 gravel enddynamic" + ] + }, + "track_events": { + "tor1k": "event0 autotest_wake" + }, + "test_config": [ + "test.fail_if_stop_overran no" + ], + "duration": 180, + "timeout": 600, + "checks": [ + { "type": "log_contains", "pattern": "Uncoupling \\[autotest_sm42_td_uncouple_past_signal\\]: uncoupled" }, + { "type": "distance", "min": 45, "max": 49 } + ] +} diff --git a/tests/scenarios/cases/td_uncouple_past_signal.scn b/tests/scenarios/cases/td_uncouple_past_signal.scn new file mode 100644 index 000000000..98ab9033e --- /dev/null +++ b/tests/scenarios/cases/td_uncouple_past_signal.scn @@ -0,0 +1,31 @@ +// added by tests/scenarios/run.py to td.scn, whose own trainsets were removed. +// a shunter with no timetable stands at the far end of tor1k (point 2), turned (offset -1) to face back towards +// track 1 of Stacja1, with its wagons (vars.wagons) behind it, towards the exit signal stacja1_j (at stop, no route; +// its memory cell is 51 m into tor1k). the trainset's velocity is negative, so its driver takes the direction of the +// locomotive's cab and pulls. tdo_n1734, the track behind tor1k, is closed (speed 0) from the start, so the shunter +// pulls the wagons back along tor1k and stops in front of it, with the far end of the last wagon a few metres past +// the signal: the signal stands at stop over that wagon for the direction the shunter pushes in when it uncouples. +// the pull leaves the screw coupler stretched, as at a real stop. +trainset none tor1k 100.0 -0.1 +{{wagons}} +node -1 0 {{vehicle}} dynamic pkp\sm42_v1 6DA-1096 6da -1 headdriver 0 0 enddynamic +endtrainset + +node -1 0 autotest_closed eventlauncher 0 0 0 -1 none 1034 autotest_close end +event autotest_close trackvel 0 tdo_n1734 0 endevent + +// a standing shunter waits for the scenery's orders. event0 of tor1k (the case's track_events) runs while it stands +// there. the first time it gives the order to go (Shunt -1 0). 25 s later the shunter is on its way, and the first +// time it stands again, in front of tdo_n1734, it gets the order a scenery gives to leave the wagons: Shunt 0 0, +// uncouple everything behind the locomotive and stay. it brakes the wagons, changes direction, pushes the buffers in +// and lets the coupler go. the order comes at once: standing for long, the wagons' brakes release and the coupler +// draws the buffers together, which leaves nothing to push +node -1 0 autotest_ordered memcell 0 0 0 ordered 0 0 none endmemcell +event autotest_wake multiple 0 none autotest_go autotest_uncouple endevent +event autotest_go multiple 0 autotest_ordered autotest_go_order autotest_go_given autotest_go_done condition memcompare * 0 * endevent +event autotest_go_order PutValues 0 none 0 0 0 Shunt -1 0 endevent +event autotest_go_given UpdateValues 0 autotest_ordered * 1 * endevent +event autotest_go_done UpdateValues 25 autotest_ordered * 2 * endevent +event autotest_uncouple multiple 0 autotest_ordered autotest_uncouple_order autotest_uncouple_given condition memcompare * 2 * endevent +event autotest_uncouple_order PutValues 0 none 0 0 0 Shunt 0 0 endevent +event autotest_uncouple_given UpdateValues 0 autotest_ordered * 3 * endevent diff --git a/tests/unit/test_brake_releaser.cpp b/tests/unit/test_brake_releaser.cpp new file mode 100644 index 000000000..0e32552b3 --- /dev/null +++ b/tests/unit/test_brake_releaser.cpp @@ -0,0 +1,114 @@ +#include "stdafx.h" +#include "doctest.h" + +#include "vehicle/brakereleaser.h" + +// when the AI works the brake releaser of its locomotive (TController::control_releaser). in stage 3 of uncoupling +// the locomotive pushes towards the cut it leaves, until the screw coupler slackens enough to be let go +// (TController::UpdateDisconnect). the consist brakes applied in stage 2 hold the locomotive too, and only the +// releaser lets it go. the releaser was worked only while the driver wanted to speed up (AccDesired above +// -0.05), so a signal at stop the cut stood across after the direction change, which caps the speed at 0, left the +// locomotive braked and the uncoupling went on for good (SM42 at Debica on L053). + +namespace { + +// a locomotive standing in stage 3 of uncoupling, braked by the consist's brake application of stage 2 +brake_releaser::conditions compressing_buffers(double const Acceleration) { + brake_releaser::conditions state; + state.acceleration_desired = Acceleration; + state.pipe_pressure = 3.8; + state.cylinder_pressure = 1.5; + state.control_pressure = 5.0; + state.velocity = 0.0; + state.pressing = true; + state.compressing_buffers = true; + return state; +} + +// a locomotive standing braked at the head of a train with a charged brake pipe, about to start off +brake_releaser::conditions standing_braked(double const Acceleration) { + brake_releaser::conditions state; + state.acceleration_desired = Acceleration; + state.pipe_pressure = 5.0; + state.cylinder_pressure = 1.0; + state.control_pressure = 5.0; + state.velocity = 0.0; + return state; +} + +} // namespace + +TEST_CASE("brake releaser: stage 3 of uncoupling releases the locomotive whatever the driver's acceleration") { + for (auto const acceleration : {0.3, 0.0, -0.05, -0.2, -0.9}) { + CAPTURE(acceleration); + auto const wanted{brake_releaser::decide(compressing_buffers(acceleration))}; + CHECK(wanted.actuate); + CHECK_FALSE(wanted.fill_pipe); + } +} + +TEST_CASE("brake releaser: stage 3 of uncoupling leaves a released locomotive alone") { + for (auto const acceleration : {0.3, -0.9}) { + CAPTURE(acceleration); + auto state{compressing_buffers(acceleration)}; + state.cylinder_pressure = 0.05; + CHECK_FALSE(brake_releaser::decide(state).actuate); + } +} + +TEST_CASE("brake releaser: pressing outside stage 3 still needs the driver to want to speed up") { + // the direction changes of stages 2 and 4, and coupling, are as before: the releaser goes on only with + // AccDesired above -0.05 + auto state{compressing_buffers(0.3)}; + state.compressing_buffers = false; + CHECK(brake_releaser::decide(state).actuate); + state.acceleration_desired = -0.05; + CHECK_FALSE(brake_releaser::decide(state).actuate); + state.acceleration_desired = -0.9; + CHECK_FALSE(brake_releaser::decide(state).actuate); +} + +TEST_CASE("brake releaser: starting off releases a braked locomotive below 1 km/h") { + CHECK(brake_releaser::decide(standing_braked(0.3)).actuate); + CHECK_FALSE(brake_releaser::decide(standing_braked(-0.05)).actuate); + + auto moving{standing_braked(0.3)}; + moving.velocity = 1.0; + CHECK_FALSE(brake_releaser::decide(moving).actuate); + + auto lightly{standing_braked(0.3)}; + lightly.cylinder_pressure = 0.4; + CHECK_FALSE(brake_releaser::decide(lightly).actuate); + + // the control reservoir not charged: releasing would vent it + auto uncharged{standing_braked(0.3)}; + uncharged.control_pressure = 4.9; + CHECK_FALSE(brake_releaser::decide(uncharged).actuate); + // unless the train brake is held on purpose to start uphill + uncharged.uphill_start = true; + CHECK(brake_releaser::decide(uncharged).actuate); +} + +TEST_CASE("brake releaser: an empty brake pipe is filled up when the driver wants to speed up") { + auto state{standing_braked(0.3)}; + state.pipe_pressure = 2.9; + state.cylinder_pressure = 0.0; + auto const wanted{brake_releaser::decide(state)}; + CHECK(wanted.actuate); + CHECK(wanted.fill_pipe); + + state.acceleration_desired = -0.2; + auto const braking{brake_releaser::decide(state)}; + CHECK_FALSE(braking.actuate); + CHECK_FALSE(braking.fill_pipe); +} + +TEST_CASE("brake releaser: an overcharged brake pipe turns the releaser off, in stage 3 of uncoupling too") { + auto starting{standing_braked(0.3)}; + starting.pipe_pressure = 5.3; + CHECK_FALSE(brake_releaser::decide(starting).actuate); + + auto uncoupling{compressing_buffers(-0.9)}; + uncoupling.pipe_pressure = 5.3; + CHECK_FALSE(brake_releaser::decide(uncoupling).actuate); +} diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index cba35b68a..675c1ef8e 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -20,6 +20,7 @@ http://mozilla.org/MPL/2.0/. #include "utilities/Logs.h" #include "utilities/physicslog.h" #include "vehicle/Train.h" +#include "vehicle/brakereleaser.h" #include "vehicle/brakesetting.h" #include "vehicle/brakingcurve.h" #include "vehicle/handover.h" @@ -9117,39 +9118,26 @@ void TController::control_releaser() { if( false == hasreleaser ) { return; } - auto actuate { false }; + brake_releaser::conditions state; + state.acceleration_desired = AccDesired; + state.pipe_pressure = mvOccupied->PipePress; + state.cylinder_pressure = mvOccupied->BrakePress; + state.control_pressure = mvOccupied->Hamulec->GetCRP(); + state.velocity = mvOccupied->Vel; + state.uphill_start = bUphillStart; + state.pressing = TestFlag( iDrivigFlags, movePress ); + // stage 3 of uncoupling (UpdateDisconnect), from the direction change until the coupler lets go + state.compressing_buffers = + state.pressing && ( OrderCurrentGet() & Disconnect ) != 0 && iVehicleCount >= 0 && iDirection == iDirectionOrder; + auto const wanted { brake_releaser::decide( state ) }; + auto const actuate { wanted.actuate }; auto isbrakehandleinrightposition { true }; - if( AccDesired > EU07_AI_NOACCELERATION ) { - // fill up brake pipe if needed - if( mvOccupied->PipePress < 3.0 ) { - actuate = true; - // some vehicles require brake handle to be moved to specific position - if( mvOccupied->HandleUnlock != -3 ) { - cue_action( driver_hint::trainbrakesetpipeunlock ); - isbrakehandleinrightposition &= BrakeCtrlPosition == mvOccupied->HandleUnlock; - } - } - // wyluzuj lokomotywę, to szybciej ruszymy - // this rule is for starting off, so only below 1 km/h: at speed, just after an application, it would vent - // the control reservoir of a locomotive that may have to brake again before the pipe has refilled it - if( mvOccupied->BrakePress > 0.4 - && ( mvOccupied->Hamulec->GetCRP() > 4.9 - // starting uphill the train brake stays applied on purpose, and the locomotive's own share of it has to go - // for the power to come on (asynchronous drives and the pressure switch cut the power while it is applied) - || bUphillStart ) - && mvOccupied->Vel < 1.0 ) { - actuate = true; - } - // keep engine brakes released during coupling/uncoupling - if( true == TestFlag(iDrivigFlags, movePress) - && mvOccupied->BrakePress > 0.1 ) { - actuate = true; - } - } - // don't overcharge train brake pipe - if( mvOccupied->PipePress > 5.2 ) { - actuate = false; + // some vehicles require brake handle to be moved to specific position to fill up the brake pipe + if( wanted.fill_pipe + && mvOccupied->HandleUnlock != -3 ) { + cue_action( driver_hint::trainbrakesetpipeunlock ); + isbrakehandleinrightposition = ( BrakeCtrlPosition == mvOccupied->HandleUnlock ); } if( actuate ) { diff --git a/vehicle/brakereleaser.cpp b/vehicle/brakereleaser.cpp new file mode 100644 index 000000000..0a51c9a62 --- /dev/null +++ b/vehicle/brakereleaser.cpp @@ -0,0 +1,60 @@ +/* +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/. +*/ + +#include "stdafx.h" +#include "vehicle/brakereleaser.h" + +namespace brake_releaser { + +namespace { + +// the rules for a driver that wants to speed up +bool wanted_to_start(conditions const &State) { + // fill up the brake pipe if needed + if (State.pipe_pressure < 3.0) { + return true; + } + // wyluzuj lokomotywę, to szybciej ruszymy + // this rule is for starting off, so only below 1 km/h: at speed, just after an application, it would vent + // the control reservoir of a locomotive that may have to brake again before the pipe has refilled it + if (State.cylinder_pressure > 0.4 + && (State.control_pressure > 4.9 + // starting uphill the train brake stays applied on purpose, and the locomotive's own share of it has to go + // for the power to come on (asynchronous drives and the pressure switch cut the power while it is applied) + || State.uphill_start) + && State.velocity < 1.0) { + return true; + } + // keep engine brakes released during coupling/uncoupling + return State.pressing && State.cylinder_pressure > 0.1; +} + +} // namespace + +decision decide(conditions const &State) { + decision result; + if (State.acceleration_desired > no_acceleration) { + result.fill_pipe = State.pipe_pressure < 3.0; + result.actuate = wanted_to_start(State); + } + // uncoupling, stage 3: the locomotive has to push the slack of the coupler out whatever its speed table says. + // the consist stays held by its own brakes, applied in stage 2, and the push asks for 2 km/h at most. a signal + // at stop that the consist stands across after the direction change caps the speed at 0 and so AccDesired + // below no_acceleration, and a locomotive left braked by the consist's brake application never closes the gap + if (State.compressing_buffers && State.cylinder_pressure > 0.1) { + result.actuate = true; + } + // don't overcharge train brake pipe + if (State.pipe_pressure > 5.2) { + result.actuate = false; + } + return result; +} + +} // namespace brake_releaser diff --git a/vehicle/brakereleaser.h b/vehicle/brakereleaser.h new file mode 100644 index 000000000..62bc2e7c1 --- /dev/null +++ b/vehicle/brakereleaser.h @@ -0,0 +1,39 @@ +/* +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/. +*/ + +#pragma once + +// when the AI driver works the brake releaser of its locomotive (TController::control_releaser): it vents the +// locomotive's own train brake cylinders, to start off sooner, to fill up an empty brake pipe, and to let the +// locomotive press the buffers while it (un)couples +namespace brake_releaser { + +// the state of the locomotive and of its driver the decision depends on +struct conditions { + double acceleration_desired{0.0}; // AccDesired of the driver [m/s2]; above no_acceleration it wants to speed up + double pipe_pressure{0.0}; // brake pipe [bar] + double cylinder_pressure{0.0}; // the locomotive's brake cylinders [bar] + double control_pressure{0.0}; // the control reservoir of the locomotive's distributor [bar] + double velocity{0.0}; // [km/h] + bool uphill_start{false}; // starting uphill with the train brake held on purpose + bool pressing{false}; // (un)coupling: the driver presses the buffers (movePress) + bool compressing_buffers{false}; // uncoupling, stage 3: pushing towards the cut to slacken the coupler +}; + +struct decision { + bool actuate{false}; // the releaser goes on (else off) + bool fill_pipe{false}; // the brake pipe is to be filled up: the brake handle goes to its unlock position +}; + +// AccDesired at or below this asks for no speeding up (EU07_AI_NOACCELERATION of Driver.h) +inline constexpr double no_acceleration{-0.05}; + +decision decide(conditions const &State); + +} // namespace brake_releaser From e2abe0384fc5f223224e0c7d1bdaf9eb5c56c4ac Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 06:17:22 +0100 Subject: [PATCH 27/27] fix(ai): a heavy train starting on poor rails keeps sanding and takes the power down a step at a time (#494) * test(scenarios): heavy trains on gradients, the limits #187, #199, #263 and #265 left Cases on lines of their own beside td.scn, built the way the downgrade fragment of #479 is (x = -3000, a substation of their own, signals that are a memory cell with SetVelocity 0 0), with level track long enough for a whole heavy consist at the start: - et41_coal_td_downgrade_restriction: ET41 + 25 coal wagons (1670 t) down 20 per mille into a 20 km/h restriction. Staging: 10.5 km/h at the lowest, stops at the signal. #263 saw it stop before the restriction; it no longer does. - et22_764_td_downgrade_restriction: ET22 + 20 loaded 764 (2650 t) on the same line. xfail: it dips to 8.5 km/h in the restriction, as the AI applies and releases the train brake in turn and the release of a G train takes 10-15 s. - st43_steel_td_downgrade12_long: ST43 + 45 425S, 6.5 km down 12 per mille at 40 km/h (#199): 35-37.5 km/h all the way. - et41_coal_td_upgrade_start: the ET41 train stops at a signal on 10 per mille and starts when it clears (#265): moves off 4.7 s later, rolls back 0.04 m. - eu07a_coaches_td_upgrade_long: EU07A + 8 coaches up 10 per mille at 80 km/h (#187): never below 73.8 km/h. run.py gets two checks: keeps_moving (the lowest vehicle speed between two distances) and starts_again (a start from a signal that clears at a given time, with the rollback). The README lists the cases and what the AI still does with heavy trains. * fix(ai): a heavy train starting on poor rails keeps sanding and takes the power down a step at a time An ET41 with 25 loaded coal wagons (2170 t) starting on level track with friction 0.3 (#187: heavy trains often don't get going on such rails) moved 75 m in 1500 s, never above 1 km/h, with 395 slips. Each slip made control_wheelslip() take the power down on every update while the wheels spun (DecSpeed(), two notches each: 3 to 0 within half a second) and press the anti-slip brake (1.1 bar on the locomotive), which braked the train, just moving, to a stand. Once the wheels gripped, the sand went off at once, as it stays on ahead of a slip only at a high motor current, and the start began anew from notch 1. A slip under power below 15 km/h now makes the start a sanded one until the train is at 15 km/h, or stands with no speed asked for: the sand stays on while there is power, a slip takes the power down one step at most once a second, and the anti-slip brake isn't used. A slip at speed, or one without power, is handled as before. The same train now gets going and stops at the signal 1000 m ahead (392 s, 85 slips). New case et41_coal_td_slippery_start (td_level_signal.scn); it fails on staging. * fix(ai): a sanded start only on a vehicle with sand --- tests/scenarios/README.md | 42 + .../et22_764_td_downgrade_restriction.json | 62 ++ .../et41_coal_td_downgrade_restriction.json | 67 ++ .../cases/et41_coal_td_slippery_start.json | 66 ++ .../cases/et41_coal_td_upgrade_start.json | 73 ++ .../cases/eu07a_coaches_td_upgrade_long.json | 50 + .../cases/st43_steel_td_downgrade12_long.json | 86 ++ tests/scenarios/cases/td_downgrade12_long.scn | 608 ++++++++++++ .../cases/td_downgrade_restriction.scn | 638 ++++++++++++ .../scenarios/cases/td_freight_downgrade.txt | 17 + .../cases/td_freight_downgrade12.txt | 17 + tests/scenarios/cases/td_level_signal.scn | 333 +++++++ .../scenarios/cases/td_passenger_upgrade.txt | 17 + tests/scenarios/cases/td_upgrade_long.scn | 934 ++++++++++++++++++ .../cases/td_upgrade_signal_start.scn | 492 +++++++++ tests/scenarios/run.py | 54 + vehicle/Driver.cpp | 29 +- vehicle/Driver.h | 3 + 18 files changed, 3585 insertions(+), 3 deletions(-) create mode 100644 tests/scenarios/cases/et22_764_td_downgrade_restriction.json create mode 100644 tests/scenarios/cases/et41_coal_td_downgrade_restriction.json create mode 100644 tests/scenarios/cases/et41_coal_td_slippery_start.json create mode 100644 tests/scenarios/cases/et41_coal_td_upgrade_start.json create mode 100644 tests/scenarios/cases/eu07a_coaches_td_upgrade_long.json create mode 100644 tests/scenarios/cases/st43_steel_td_downgrade12_long.json create mode 100644 tests/scenarios/cases/td_downgrade12_long.scn create mode 100644 tests/scenarios/cases/td_downgrade_restriction.scn create mode 100644 tests/scenarios/cases/td_freight_downgrade.txt create mode 100644 tests/scenarios/cases/td_freight_downgrade12.txt create mode 100644 tests/scenarios/cases/td_level_signal.scn create mode 100644 tests/scenarios/cases/td_passenger_upgrade.txt create mode 100644 tests/scenarios/cases/td_upgrade_long.scn create mode 100644 tests/scenarios/cases/td_upgrade_signal_start.scn diff --git a/tests/scenarios/README.md b/tests/scenarios/README.md index 6d6317bd7..2af439ed5 100644 --- a/tests/scenarios/README.md +++ b/tests/scenarios/README.md @@ -275,6 +275,42 @@ starts on the level at the W4 of Gora, stops at the W4 of Dol 1500 m down the gr model), about 1590 m and 2690 m from the start. The three trains are the light EU07, the SN61 alone and the EU07 with three coaches. +### Heavy trains + +The heavy train cases (#187, #199, #263, #265) run on lines of their own beside the tracks of td.scn, at x = -3000, as +the `*_td_downgrade_w4_signal` cases of #479 do: 100 m tracks, an overhead wire fed by a substation of its own (none for +the diesel case) and signals at stop that are a memory cell with `SetVelocity 0 0` and the event that reads it, with no +model. Each train starts on a level stretch long enough for the whole consist, with its head 10 m before the W4 of Gora, +which is where the distances in the checks start from. A freight train leaves a station of its timetable as soon as it +stands there (`IsCargoTrain` in `TController`), so the freight trains leave Gora at once, not at 10:35. The checks that +look for a train that comes to a stand use the vehicle speed (`keeps_moving`), as the wheels of a heavy train starting +on poor rails spin while it stands; `starts_again` checks a start from a signal that clears at a given time, and how far +the train rolls back meanwhile. + +| case | fragment | train | what it shows | +| --- | --- | --- | --- | +| `et41_coal_td_downgrade_restriction` | `td_downgrade_restriction.scn`: 600 m level, 3500 m down 20 per mille, 20 km/h from 1500 to 1900 m down, the signal 3000 m down | ET41, 25 coal wagons 412W with 40 t each, G (about 1670 t) | passes: through the restriction at 10.5 km/h at the lowest, stops at the signal (3078 m) | +| `et22_764_td_downgrade_restriction` | the same | ET22, 20 heavy wagons 764 with 84 t each (about 2650 t) | `xfail`: dips to 8.5 km/h in the 20 km/h restriction (below the 10 km/h #263 counts as a defect); it doesn't stop | +| `st43_steel_td_downgrade12_long` | `td_downgrade12_long.scn`: 900 m level, 6500 m down 12 per mille, no wire, the signal 6000 m down | ST43, 45 coil wagons 425S, G | passes: holds 35-37.5 km/h of the 40 all the way down, never below 20 km/h, stops at the signal | +| `et41_coal_td_upgrade_start` | `td_upgrade_signal_start.scn`: 600 m level, 2500 m up 10 per mille, a signal 1000 m up that clears at 10:42, another 2300 m up | the ET41 with 25 coal wagons | passes: stops at the first signal with the whole train on the gradient, moves off 4.7 s after it clears, 10 km/h after 52 s, rolls back 0.04 m | +| `eu07a_coaches_td_upgrade_long` | `td_upgrade_long.scn`: 600 m level, 5500 m up 10 per mille, the signal 5300 m up | EU07A (303E), 8 coaches (about 360 t), passenger timetable at 80 km/h | passes: 80 km/h at 1430 m, never below 73.8 km/h on the climb | +| `et41_coal_td_slippery_start` | `td_level_signal.scn`: 2100 m level, the signal 1000 m ahead | ET41, 25 coal wagons with 60 t each (about 2170 t), `friction 0.3` | passes with the fix of this branch: gets going and stops at the signal (1082 m, at 392 s); before it, 395 slips in 1500 s and 75 m | + +What the AI still does with heavy trains, without a case that fails on it: + +- On a steep descent into a restriction a heavy G train holds the speed by applying and releasing the train brake in + turn. Its brake takes 10-15 s to release, so it falls well below the limit before the brake lets go: 10.5-12 km/h + for the ET41 with coal wagons, 8.5 km/h for the ET22 with the 764 wagons (the `xfail` above), in a 20 km/h + restriction. #263 reported this train stopping before the restriction in 10 of 12 runs; on staging it no longer + does, also with `friction 0.5` and with the wagons fully loaded. +- Starting uphill, a heavy train pulls against its train brake while the brake releases (#265): in + `et41_coal_td_upgrade_start` about 13 s at about 200 kN with the head moving by the slack of the couplers alone. It + starts at full power, without taking up the slack first. +- The AI doesn't know the adhesion of the rails: it plans braking with `Global.FrictionWeatherFactor` alone, and the + result of its running brake test (`adjust_desired_speed_for_braking_test`) is shown in the debug panel only. It sands + ahead of a slip only at a high motor current, and, since the fix of `et41_coal_td_slippery_start`, through the rest of + a start that has slipped (`control_wheelslip()`); not before a hard brake, nor before the first slip of a start. + The `test_mode_*` cases show the ends of the test mode: `test_mode_pass` (exit 0, the pass event), `test_mode_signal_passed_at_danger` (exit 11), `test_mode_timeout` (exit 12, from `test.timeout`), `test_mode_standstill` (exit 13, from `test.standstill`) and @@ -540,6 +576,12 @@ the row instead, logged by builds from this branch on. after moving off, moves no more than `max_distance` metres, e.g. no creeping on locked wheels. - `ends_moving` `min_speed`: the last row of the physicslog is at `min_speed` or faster, e.g. the test ended without waiting for the train to stop. +- `keeps_moving` `moving_speed`, `min_speed`, `until_distance`, optional `from_distance` (*vehicle speed*): once at + `moving_speed`, the speed stays at or above `min_speed` between the two distances (metres travelled, from the vehicle + speed), e.g. a heavy train doesn't come to a stand on a descent before a restriction. Reports the lowest speed. +- `starts_again` `after`, `min_speed`, `within`, optional `max_rollback` (*vehicle speed* for the rollback): standing + at the time `after` (a signal that clears then), the train reaches `min_speed` within `within` seconds, and rolls back + no more than `max_rollback` metres meanwhile. - `log_contains` `pattern`: a line of the run's `log.txt` matches the regex, e.g. the `Bad driving: ... collided` message of a collision. - `log_lacks` `pattern`: no line of the run's `log.txt` matches the regex. diff --git a/tests/scenarios/cases/et22_764_td_downgrade_restriction.json b/tests/scenarios/cases/et22_764_td_downgrade_restriction.json new file mode 100644 index 000000000..b53a23411 --- /dev/null +++ b/tests/scenarios/cases/et22_764_td_downgrade_restriction.json @@ -0,0 +1,62 @@ +{ + "description": "An ET22 with 20 loaded heavy wagons 764 (Uaai, 84 t of machinery each, KE, G; about 2650 t) on the line of et41_coal_td_downgrade_restriction: down 20 per mille into a 20 km/h restriction 400 m long, then to the signal at stop. The train is to keep above 10 km/h through the restriction (#187: it almost stops).", + "xfail": "#187, #263: down 20 per mille the AI holds the 20 km/h restriction by applying and releasing the train brake in turn (handle 0, then 1.25-2.75, then 0 again); the release of this G train takes 10-15 s, so each one comes late and the train dips to 8.5 km/h, below the 10 km/h #263 counts as a defect. It doesn't stop. Known limitation of the AI, not fixed here", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_downgrade_restriction.scn", + "timetable": "td_freight_downgrade.txt", + "vars": { + "consist": [ + "node -1 0 {{vehicle}} dynamic pkp\\et22_v3 201E-1150 201E 0 headdriver 3 0 enddynamic", + "node -1 0 {{vehicle}}_w01 dynamic db\\uaaikks_v1 993_6_221-5 764 0 nobody 3 84 hmachinnery1 enddynamic", + "node -1 0 {{vehicle}}_w02 dynamic db\\uaaikks_v1 993_6_221-5 764 0 nobody 3 84 hmachinnery1 enddynamic", + "node -1 0 {{vehicle}}_w03 dynamic db\\uaaikks_v1 993_6_221-5 764 0 nobody 3 84 hmachinnery1 enddynamic", + "node -1 0 {{vehicle}}_w04 dynamic db\\uaaikks_v1 993_6_221-5 764 0 nobody 3 84 hmachinnery1 enddynamic", + "node -1 0 {{vehicle}}_w05 dynamic db\\uaaikks_v1 993_6_221-5 764 0 nobody 3 84 hmachinnery1 enddynamic", + "node -1 0 {{vehicle}}_w06 dynamic db\\uaaikks_v1 993_6_221-5 764 0 nobody 3 84 hmachinnery1 enddynamic", + "node -1 0 {{vehicle}}_w07 dynamic db\\uaaikks_v1 993_6_221-5 764 0 nobody 3 84 hmachinnery1 enddynamic", + "node -1 0 {{vehicle}}_w08 dynamic db\\uaaikks_v1 993_6_221-5 764 0 nobody 3 84 hmachinnery1 enddynamic", + "node -1 0 {{vehicle}}_w09 dynamic db\\uaaikks_v1 993_6_221-5 764 0 nobody 3 84 hmachinnery1 enddynamic", + "node -1 0 {{vehicle}}_w10 dynamic db\\uaaikks_v1 993_6_221-5 764 0 nobody 3 84 hmachinnery1 enddynamic", + "node -1 0 {{vehicle}}_w11 dynamic db\\uaaikks_v1 993_6_221-5 764 0 nobody 3 84 hmachinnery1 enddynamic", + "node -1 0 {{vehicle}}_w12 dynamic db\\uaaikks_v1 993_6_221-5 764 0 nobody 3 84 hmachinnery1 enddynamic", + "node -1 0 {{vehicle}}_w13 dynamic db\\uaaikks_v1 993_6_221-5 764 0 nobody 3 84 hmachinnery1 enddynamic", + "node -1 0 {{vehicle}}_w14 dynamic db\\uaaikks_v1 993_6_221-5 764 0 nobody 3 84 hmachinnery1 enddynamic", + "node -1 0 {{vehicle}}_w15 dynamic db\\uaaikks_v1 993_6_221-5 764 0 nobody 3 84 hmachinnery1 enddynamic", + "node -1 0 {{vehicle}}_w16 dynamic db\\uaaikks_v1 993_6_221-5 764 0 nobody 3 84 hmachinnery1 enddynamic", + "node -1 0 {{vehicle}}_w17 dynamic db\\uaaikks_v1 993_6_221-5 764 0 nobody 3 84 hmachinnery1 enddynamic", + "node -1 0 {{vehicle}}_w18 dynamic db\\uaaikks_v1 993_6_221-5 764 0 nobody 3 84 hmachinnery1 enddynamic", + "node -1 0 {{vehicle}}_w19 dynamic db\\uaaikks_v1 993_6_221-5 764 0 nobody 3 84 hmachinnery1 enddynamic", + "node -1 0 {{vehicle}}_w20 dynamic db\\uaaikks_v1 993_6_221-5 764 0 nobody 3 84 hmachinnery1 enddynamic" + ] + }, + "expect": "standstill", + "duration": 1200, + "timeout": 1500, + "checks": [ + { + "type": "starts", + "min_speed": 20, + "within": 300 + }, + { + "type": "max_speed", + "limit": 60, + "tolerance": 5 + }, + { + "type": "keeps_moving", + "moving_speed": 20, + "min_speed": 10, + "until_distance": 2450 + }, + { + "type": "stops", + "moving_speed": 15, + "stop_speed": 1.0, + "hold": 20, + "min_distance": 2950, + "max_distance": 3110 + } + ] +} diff --git a/tests/scenarios/cases/et41_coal_td_downgrade_restriction.json b/tests/scenarios/cases/et41_coal_td_downgrade_restriction.json new file mode 100644 index 000000000..966c6b0a8 --- /dev/null +++ b/tests/scenarios/cases/et41_coal_td_downgrade_restriction.json @@ -0,0 +1,67 @@ +{ + "description": "An ET41 with 25 loaded coal wagons (412W, 60 t each, cast-iron blocks, G; about 1670 t) on a line of its own beside td.scn: from the level down a gradient of 20 per mille at the 60 km/h of its timetable, into a 20 km/h restriction 400 m long 1500 m down the gradient, then to the signal at stop 3000 m down. The train is to pass through the restriction without coming to a stand, and stop at the signal (#263, #187).", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_downgrade_restriction.scn", + "timetable": "td_freight_downgrade.txt", + "vars": { + "consist": [ + "node -1 0 {{vehicle}} dynamic pkp\\et41_v2 41-045-a 203e-a 0 headdriver 55 0 enddynamic", + "node -1 0 {{vehicle}}_b dynamic pkp\\et41_v2 41-045-b 203e-b 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_w01 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w02 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w03 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w04 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w05 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w06 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w07 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w08 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w09 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w10 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w11 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w12 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w13 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w14 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w15 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w16 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w17 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w18 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w19 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w20 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w21 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w22 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w23 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w24 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w25 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic" + ] + }, + "expect": "standstill", + "duration": 1200, + "timeout": 1500, + "checks": [ + { + "type": "starts", + "min_speed": 20, + "within": 300 + }, + { + "type": "max_speed", + "limit": 60, + "tolerance": 5 + }, + { + "type": "keeps_moving", + "moving_speed": 20, + "min_speed": 10, + "until_distance": 2400 + }, + { + "type": "stops", + "moving_speed": 15, + "stop_speed": 1.0, + "hold": 20, + "min_distance": 2950, + "max_distance": 3110 + } + ] +} diff --git a/tests/scenarios/cases/et41_coal_td_slippery_start.json b/tests/scenarios/cases/et41_coal_td_slippery_start.json new file mode 100644 index 000000000..34696d422 --- /dev/null +++ b/tests/scenarios/cases/et41_coal_td_slippery_start.json @@ -0,0 +1,66 @@ +{ + "description": "An ET41 with 25 fully loaded coal wagons (412W, 80 t each, G; about 2170 t) starts on level track with the rail friction at 0.3 of its normal (eu07.ini friction 0.3, as on wet leaves), and runs to the signal at stop 1000 m ahead. The train is to get going, keep moving and stop at the signal (#187: heavy trains slip, grip and snatch over and over and often don't get going).", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_level_signal.scn", + "timetable": "td_freight_downgrade.txt", + "ini": [ + "friction 0.3" + ], + "vars": { + "consist": [ + "node -1 0 {{vehicle}} dynamic pkp\\et41_v2 41-045-a 203e-a 0 headdriver 55 0 enddynamic", + "node -1 0 {{vehicle}}_b dynamic pkp\\et41_v2 41-045-b 203e-b 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_w01 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 60 coal enddynamic", + "node -1 0 {{vehicle}}_w02 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 60 coal enddynamic", + "node -1 0 {{vehicle}}_w03 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 60 coal enddynamic", + "node -1 0 {{vehicle}}_w04 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 60 coal enddynamic", + "node -1 0 {{vehicle}}_w05 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 60 coal enddynamic", + "node -1 0 {{vehicle}}_w06 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 60 coal enddynamic", + "node -1 0 {{vehicle}}_w07 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 60 coal enddynamic", + "node -1 0 {{vehicle}}_w08 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 60 coal enddynamic", + "node -1 0 {{vehicle}}_w09 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 60 coal enddynamic", + "node -1 0 {{vehicle}}_w10 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 60 coal enddynamic", + "node -1 0 {{vehicle}}_w11 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 60 coal enddynamic", + "node -1 0 {{vehicle}}_w12 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 60 coal enddynamic", + "node -1 0 {{vehicle}}_w13 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 60 coal enddynamic", + "node -1 0 {{vehicle}}_w14 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 60 coal enddynamic", + "node -1 0 {{vehicle}}_w15 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 60 coal enddynamic", + "node -1 0 {{vehicle}}_w16 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 60 coal enddynamic", + "node -1 0 {{vehicle}}_w17 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 60 coal enddynamic", + "node -1 0 {{vehicle}}_w18 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 60 coal enddynamic", + "node -1 0 {{vehicle}}_w19 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 60 coal enddynamic", + "node -1 0 {{vehicle}}_w20 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 60 coal enddynamic", + "node -1 0 {{vehicle}}_w21 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 60 coal enddynamic", + "node -1 0 {{vehicle}}_w22 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 60 coal enddynamic", + "node -1 0 {{vehicle}}_w23 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 60 coal enddynamic", + "node -1 0 {{vehicle}}_w24 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 60 coal enddynamic", + "node -1 0 {{vehicle}}_w25 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 60 coal enddynamic" + ] + }, + "expect": "standstill", + "duration": 1500, + "timeout": 1800, + "checks": [ + { + "type": "moves", + "vehicle": "{{vehicle}}", + "min_speed": 10 + }, + { + "type": "keeps_moving", + "moving_speed": 5, + "min_speed": 3, + "from_distance": 100, + "until_distance": 900 + }, + { + "type": "stops", + "moving_speed": 10, + "stop_speed": 1.0, + "hold": 20, + "min_distance": 1040, + "max_distance": 1150 + } + ] +} diff --git a/tests/scenarios/cases/et41_coal_td_upgrade_start.json b/tests/scenarios/cases/et41_coal_td_upgrade_start.json new file mode 100644 index 000000000..05d005919 --- /dev/null +++ b/tests/scenarios/cases/et41_coal_td_upgrade_start.json @@ -0,0 +1,73 @@ +{ + "description": "An ET41 with 25 loaded coal wagons (412W, 60 t each, G; about 1670 t) on a line of its own beside td.scn: up a gradient of 10 per mille to the signal hu_sem1 1000 m up, at stop until 10:42, where it stops with the whole train on the gradient; when the signal clears, it is to start without rolling back and get away, to the signal at stop 2300 m up (#265, #187).", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_upgrade_signal_start.scn", + "timetable": "td_freight_downgrade.txt", + "vars": { + "consist": [ + "node -1 0 {{vehicle}} dynamic pkp\\et41_v2 41-045-a 203e-a 0 headdriver 55 0 enddynamic", + "node -1 0 {{vehicle}}_b dynamic pkp\\et41_v2 41-045-b 203e-b 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_w01 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w02 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w03 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w04 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w05 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w06 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w07 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w08 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w09 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w10 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w11 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w12 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w13 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w14 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w15 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w16 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w17 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w18 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w19 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w20 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w21 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w22 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w23 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w24 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic", + "node -1 0 {{vehicle}}_w25 dynamic pkp\\412w_v2 31515362022-6 412W 0 nobody 3 40 coal enddynamic" + ] + }, + "expect": "standstill", + "duration": 1500, + "timeout": 1800, + "checks": [ + { + "type": "starts", + "min_speed": 20, + "within": 300 + }, + { + "type": "max_speed", + "limit": 60, + "tolerance": 5 + }, + { + "type": "stops", + "moving_speed": 15, + "stop_speed": 1.0, + "hold": 60, + "min_distance": 1040, + "max_distance": 1110 + }, + { + "type": "starts_again", + "after": 480, + "min_speed": 10, + "within": 120, + "max_rollback": 1.0 + }, + { + "type": "distance", + "min": 2340, + "max": 2410 + } + ] +} diff --git a/tests/scenarios/cases/eu07a_coaches_td_upgrade_long.json b/tests/scenarios/cases/eu07a_coaches_td_upgrade_long.json new file mode 100644 index 000000000..aa6fb0f86 --- /dev/null +++ b/tests/scenarios/cases/eu07a_coaches_td_upgrade_long.json @@ -0,0 +1,50 @@ +{ + "description": "An EU07A (303E) with 8 coaches (about 360 t) on a line of its own beside td.scn: up a gradient of 10 per mille, 5.5 km long, at the 80 km/h of its timetable, to the signal at stop 5300 m up. The train is to keep above 70 km/h on the climb (#187: an EU07A hung at 55-58 km/h on 10 per mille).", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_upgrade_long.scn", + "timetable": "td_passenger_upgrade.txt", + "vars": { + "consist": [ + "node -1 0 {{vehicle}} dynamic pkp\\303e_v1 303E-336'20 303E 0 headdriver 3 0 enddynamic", + "node -1 0 {{vehicle}}_c1 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c2 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c3 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c4 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c5 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c6 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c7 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c8 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic" + ] + }, + "expect": "standstill", + "duration": 1200, + "timeout": 1500, + "checks": [ + { + "type": "starts", + "min_speed": 20, + "within": 150 + }, + { + "type": "max_speed", + "limit": 80, + "tolerance": 3 + }, + { + "type": "keeps_moving", + "moving_speed": 20, + "min_speed": 70, + "from_distance": 2500, + "until_distance": 4800 + }, + { + "type": "stops", + "moving_speed": 15, + "stop_speed": 1.0, + "hold": 20, + "min_distance": 5330, + "max_distance": 5410 + } + ] +} diff --git a/tests/scenarios/cases/st43_steel_td_downgrade12_long.json b/tests/scenarios/cases/st43_steel_td_downgrade12_long.json new file mode 100644 index 000000000..371faa23c --- /dev/null +++ b/tests/scenarios/cases/st43_steel_td_downgrade12_long.json @@ -0,0 +1,86 @@ +{ + "description": "An ST43 with 45 loaded steel coil wagons (425S, G) on a line of its own beside td.scn: from the level down a gradient of 12 per mille, 6 km long, at the 40 km/h of its timetable, to the signal at stop 6000 m down. The train is not to come to a stand on the way down (#199).", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_downgrade12_long.scn", + "timetable": "td_freight_downgrade12.txt", + "vars": { + "consist": [ + "node -1 0 {{vehicle}} dynamic pkp\\st43_v1 st43-195 060Da 0 headdriver 3 0 enddynamic", + "node -1 0 {{vehicle}}_w01 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w02 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w03 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w04 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w05 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w06 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w07 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w08 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w09 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w10 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w11 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w12 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w13 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w14 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w15 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w16 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w17 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w18 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w19 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w20 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w21 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w22 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w23 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w24 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w25 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w26 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w27 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w28 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w29 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w30 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w31 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w32 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w33 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w34 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w35 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w36 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w37 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w38 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w39 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w40 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w41 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w42 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w43 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w44 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic", + "node -1 0 {{vehicle}}_w45 dynamic pkp\\425s_v1 31514644357-9 425S_1 0 nobody 3 3 steel_coils enddynamic" + ] + }, + "expect": "standstill", + "duration": 1500, + "timeout": 1800, + "checks": [ + { + "type": "starts", + "min_speed": 20, + "within": 400 + }, + { + "type": "max_speed", + "limit": 40, + "tolerance": 5 + }, + { + "type": "keeps_moving", + "moving_speed": 20, + "min_speed": 5, + "until_distance": 5800 + }, + { + "type": "stops", + "moving_speed": 15, + "stop_speed": 1.0, + "hold": 20, + "min_distance": 5950, + "max_distance": 6110 + } + ] +} diff --git a/tests/scenarios/cases/td_downgrade12_long.scn b/tests/scenarios/cases/td_downgrade12_long.scn new file mode 100644 index 000000000..37cf1eff3 --- /dev/null +++ b/tests/scenarios/cases/td_downgrade12_long.scn @@ -0,0 +1,608 @@ +// added by tests/scenarios/run.py to td.scn, whose own trainsets were removed. +// a line of its own, away from the tracks of td.scn: 900 m level, then 6500 m down a gradient of 12 per mille, +// with no overhead wire (diesel trains). the train starts on the level with its head 10 m before the W4 of Gora and runs on +// the timetable {{timetable}} (no stop; a freight train leaves Gora at once) at its line limit, down to the signal hl_sem +// at stop 6000 m down the gradient. the line goes on 500 m past the signal +node -1 0 hl_00 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -900.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -800.0 0.0 +0 +endtrack +node -1 0 hl_01 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -800.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -700.0 0.0 +0 +endtrack +node -1 0 hl_02 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -700.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -600.0 0.0 +0 +endtrack +node -1 0 hl_03 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -500.0 0.0 +0 +endtrack +node -1 0 hl_04 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -400.0 0.0 +0 +endtrack +node -1 0 hl_05 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -300.0 0.0 +0 +endtrack +node -1 0 hl_06 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -200.0 0.0 +0 +endtrack +node -1 0 hl_07 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -100.0 0.0 +0 +endtrack +node -1 0 hl_08 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 0.0 0.0 +0 +event2 gora#1_stopinfo +endtrack +node -1 0 hl_09 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 58.80 100.0 0.0 +0 +endtrack +node -1 0 hl_10 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 58.80 100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 57.60 200.0 0.0 +0 +endtrack +node -1 0 hl_11 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 57.60 200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 56.40 300.0 0.0 +0 +endtrack +node -1 0 hl_12 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 56.40 300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 55.20 400.0 0.0 +0 +endtrack +node -1 0 hl_13 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 55.20 400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 54.00 500.0 0.0 +0 +endtrack +node -1 0 hl_14 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 54.00 500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 52.80 600.0 0.0 +0 +endtrack +node -1 0 hl_15 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 52.80 600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 51.60 700.0 0.0 +0 +endtrack +node -1 0 hl_16 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 51.60 700.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 50.40 800.0 0.0 +0 +endtrack +node -1 0 hl_17 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 50.40 800.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 49.20 900.0 0.0 +0 +endtrack +node -1 0 hl_18 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 49.20 900.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 48.00 1000.0 0.0 +0 +endtrack +node -1 0 hl_19 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 48.00 1000.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 46.80 1100.0 0.0 +0 +endtrack +node -1 0 hl_20 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 46.80 1100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 45.60 1200.0 0.0 +0 +endtrack +node -1 0 hl_21 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 45.60 1200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 44.40 1300.0 0.0 +0 +endtrack +node -1 0 hl_22 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 44.40 1300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 43.20 1400.0 0.0 +0 +endtrack +node -1 0 hl_23 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 43.20 1400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 42.00 1500.0 0.0 +0 +endtrack +node -1 0 hl_24 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 42.00 1500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 40.80 1600.0 0.0 +0 +endtrack +node -1 0 hl_25 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 40.80 1600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 39.60 1700.0 0.0 +0 +endtrack +node -1 0 hl_26 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 39.60 1700.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 38.40 1800.0 0.0 +0 +endtrack +node -1 0 hl_27 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 38.40 1800.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 37.20 1900.0 0.0 +0 +endtrack +node -1 0 hl_28 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 37.20 1900.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 36.00 2000.0 0.0 +0 +endtrack +node -1 0 hl_29 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 36.00 2000.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 34.80 2100.0 0.0 +0 +endtrack +node -1 0 hl_30 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 34.80 2100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 33.60 2200.0 0.0 +0 +endtrack +node -1 0 hl_31 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 33.60 2200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 32.40 2300.0 0.0 +0 +endtrack +node -1 0 hl_32 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 32.40 2300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 31.20 2400.0 0.0 +0 +endtrack +node -1 0 hl_33 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 31.20 2400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 30.00 2500.0 0.0 +0 +endtrack +node -1 0 hl_34 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 30.00 2500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 28.80 2600.0 0.0 +0 +endtrack +node -1 0 hl_35 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 28.80 2600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 27.60 2700.0 0.0 +0 +endtrack +node -1 0 hl_36 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 27.60 2700.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 26.40 2800.0 0.0 +0 +endtrack +node -1 0 hl_37 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 26.40 2800.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 25.20 2900.0 0.0 +0 +endtrack +node -1 0 hl_38 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 25.20 2900.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 24.00 3000.0 0.0 +0 +endtrack +node -1 0 hl_39 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 24.00 3000.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 22.80 3100.0 0.0 +0 +endtrack +node -1 0 hl_40 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 22.80 3100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 21.60 3200.0 0.0 +0 +endtrack +node -1 0 hl_41 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 21.60 3200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 20.40 3300.0 0.0 +0 +endtrack +node -1 0 hl_42 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 20.40 3300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 19.20 3400.0 0.0 +0 +endtrack +node -1 0 hl_43 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 19.20 3400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 18.00 3500.0 0.0 +0 +endtrack +node -1 0 hl_44 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 18.00 3500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 16.80 3600.0 0.0 +0 +endtrack +node -1 0 hl_45 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 16.80 3600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 15.60 3700.0 0.0 +0 +endtrack +node -1 0 hl_46 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 15.60 3700.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 14.40 3800.0 0.0 +0 +endtrack +node -1 0 hl_47 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 14.40 3800.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 13.20 3900.0 0.0 +0 +endtrack +node -1 0 hl_48 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 13.20 3900.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 12.00 4000.0 0.0 +0 +endtrack +node -1 0 hl_49 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 12.00 4000.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 10.80 4100.0 0.0 +0 +endtrack +node -1 0 hl_50 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 10.80 4100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 9.60 4200.0 0.0 +0 +endtrack +node -1 0 hl_51 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 9.60 4200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 8.40 4300.0 0.0 +0 +endtrack +node -1 0 hl_52 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 8.40 4300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 7.20 4400.0 0.0 +0 +endtrack +node -1 0 hl_53 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 7.20 4400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 6.00 4500.0 0.0 +0 +endtrack +node -1 0 hl_54 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 6.00 4500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 4.80 4600.0 0.0 +0 +endtrack +node -1 0 hl_55 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 4.80 4600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 3.60 4700.0 0.0 +0 +endtrack +node -1 0 hl_56 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 3.60 4700.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 2.40 4800.0 0.0 +0 +endtrack +node -1 0 hl_57 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 2.40 4800.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 1.20 4900.0 0.0 +0 +endtrack +node -1 0 hl_58 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 1.20 4900.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 -0.00 5000.0 0.0 +0 +endtrack +node -1 0 hl_59 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 -0.00 5000.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 -1.20 5100.0 0.0 +0 +endtrack +node -1 0 hl_60 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 -1.20 5100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 -2.40 5200.0 0.0 +0 +endtrack +node -1 0 hl_61 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 -2.40 5200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 -3.60 5300.0 0.0 +0 +endtrack +node -1 0 hl_62 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 -3.60 5300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 -4.80 5400.0 0.0 +0 +endtrack +node -1 0 hl_63 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 -4.80 5400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 -6.00 5500.0 0.0 +0 +endtrack +node -1 0 hl_64 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 -6.00 5500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 -7.20 5600.0 0.0 +0 +endtrack +node -1 0 hl_65 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 -7.20 5600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 -8.40 5700.0 0.0 +0 +endtrack +node -1 0 hl_66 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 -8.40 5700.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 -9.60 5800.0 0.0 +0 +endtrack +node -1 0 hl_67 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 -9.60 5800.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 -10.80 5900.0 0.0 +0 +endtrack +node -1 0 hl_68 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 -10.80 5900.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 -12.00 6000.0 0.0 +0 +event2 hl_sem_info +endtrack +node -1 0 hl_69 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 -12.00 6000.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 -13.20 6100.0 0.0 +0 +endtrack +node -1 0 hl_70 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 -13.20 6100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 -14.40 6200.0 0.0 +0 +endtrack +node -1 0 hl_71 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 -14.40 6200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 -15.60 6300.0 0.0 +0 +endtrack +node -1 0 hl_72 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 -15.60 6300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 -16.80 6400.0 0.0 +0 +endtrack +node -1 0 hl_73 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 -16.80 6400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 -18.00 6500.0 0.0 +0 +endtrack +// the W4 of the stations of the timetable +include ip/pkp/w4n.inc gora#1 -2997.3 60.00 -90.0 180 0 0 -10 202 end +// a signal at stop: what the AI reads of one, a memory cell with SetVelocity 0 0 and the event that reads it +node -1 0 hl_sem_mem memcell -2997.3 -4.00 6000.0 SetVelocity 0.0 0.0 none endmemcell +event hl_sem_info getvalues 5.0 hl_sem_mem endevent + +trainset {{timetable}} hl_08 0.0 0.1 +{{consist}} +endtrainset diff --git a/tests/scenarios/cases/td_downgrade_restriction.scn b/tests/scenarios/cases/td_downgrade_restriction.scn new file mode 100644 index 000000000..42c7cf775 --- /dev/null +++ b/tests/scenarios/cases/td_downgrade_restriction.scn @@ -0,0 +1,638 @@ +// added by tests/scenarios/run.py to td.scn, whose own trainsets were removed. +// a line of its own, away from the tracks of td.scn: 600 m level, then 3500 m down a gradient of 20 per mille, +// under an overhead wire. the train starts on the level with its head 10 m before the W4 of Gora and runs on the timetable +// {{timetable}} (no stop; a freight train leaves Gora at once): its line limit, a 20 km/h restriction from 1500 to 1900 m +// down the gradient, then the signal hr_sem at stop 3000 m down the gradient. the line goes on 500 m past the signal +node -1 0 hr_00 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -500.0 0.0 +0 +endtrack +node -1 0 hr_01 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -400.0 0.0 +0 +endtrack +node -1 0 hr_02 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -300.0 0.0 +0 +endtrack +node -1 0 hr_03 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -200.0 0.0 +0 +endtrack +node -1 0 hr_04 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -100.0 0.0 +0 +endtrack +node -1 0 hr_05 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 0.0 0.0 +0 +event2 gora#1_stopinfo +endtrack +node -1 0 hr_06 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 58.00 100.0 0.0 +0 +endtrack +node -1 0 hr_07 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 58.00 100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 56.00 200.0 0.0 +0 +endtrack +node -1 0 hr_08 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 56.00 200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 54.00 300.0 0.0 +0 +endtrack +node -1 0 hr_09 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 54.00 300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 52.00 400.0 0.0 +0 +endtrack +node -1 0 hr_10 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 52.00 400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 50.00 500.0 0.0 +0 +endtrack +node -1 0 hr_11 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 50.00 500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 48.00 600.0 0.0 +0 +endtrack +node -1 0 hr_12 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 48.00 600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 46.00 700.0 0.0 +0 +endtrack +node -1 0 hr_13 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 46.00 700.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 44.00 800.0 0.0 +0 +endtrack +node -1 0 hr_14 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 44.00 800.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 42.00 900.0 0.0 +0 +endtrack +node -1 0 hr_15 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 42.00 900.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 40.00 1000.0 0.0 +0 +endtrack +node -1 0 hr_16 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 40.00 1000.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 38.00 1100.0 0.0 +0 +endtrack +node -1 0 hr_17 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 38.00 1100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 36.00 1200.0 0.0 +0 +endtrack +node -1 0 hr_18 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 36.00 1200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 34.00 1300.0 0.0 +0 +endtrack +node -1 0 hr_19 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 34.00 1300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 32.00 1400.0 0.0 +0 +endtrack +node -1 0 hr_20 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 32.00 1400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 30.00 1500.0 0.0 +0 +endtrack +node -1 0 hr_21 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 30.00 1500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 28.00 1600.0 0.0 +0 +velocity 20 +endtrack +node -1 0 hr_22 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 28.00 1600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 26.00 1700.0 0.0 +0 +velocity 20 +endtrack +node -1 0 hr_23 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 26.00 1700.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 24.00 1800.0 0.0 +0 +velocity 20 +endtrack +node -1 0 hr_24 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 24.00 1800.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 22.00 1900.0 0.0 +0 +velocity 20 +endtrack +node -1 0 hr_25 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 22.00 1900.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 20.00 2000.0 0.0 +0 +endtrack +node -1 0 hr_26 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 20.00 2000.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 18.00 2100.0 0.0 +0 +endtrack +node -1 0 hr_27 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 18.00 2100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 16.00 2200.0 0.0 +0 +endtrack +node -1 0 hr_28 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 16.00 2200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 14.00 2300.0 0.0 +0 +endtrack +node -1 0 hr_29 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 14.00 2300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 12.00 2400.0 0.0 +0 +endtrack +node -1 0 hr_30 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 12.00 2400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 10.00 2500.0 0.0 +0 +endtrack +node -1 0 hr_31 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 10.00 2500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 8.00 2600.0 0.0 +0 +endtrack +node -1 0 hr_32 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 8.00 2600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 6.00 2700.0 0.0 +0 +endtrack +node -1 0 hr_33 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 6.00 2700.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 4.00 2800.0 0.0 +0 +endtrack +node -1 0 hr_34 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 4.00 2800.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 2.00 2900.0 0.0 +0 +endtrack +node -1 0 hr_35 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 2.00 2900.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 0.00 3000.0 0.0 +0 +event2 hr_sem_info +endtrack +node -1 0 hr_36 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 0.00 3000.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 -2.00 3100.0 0.0 +0 +endtrack +node -1 0 hr_37 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 -2.00 3100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 -4.00 3200.0 0.0 +0 +endtrack +node -1 0 hr_38 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 -4.00 3200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 -6.00 3300.0 0.0 +0 +endtrack +node -1 0 hr_39 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 -6.00 3300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 -8.00 3400.0 0.0 +0 +endtrack +node -1 0 hr_40 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 -8.00 3400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 -10.00 3500.0 0.0 +0 +endtrack +// the overhead wire along the whole line, as td.scn has it: 5.6 m above the rail, the carrier 1.7 m higher, fed by +// a substation of its own +node -1 0 hr_pwr tractionpowersource -3000.0 60.00 0.0 3400 0 0.01 2000 1.0 3 60.0 end +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -600.0 +-3000.0 65.60 -500.0 +-3000.0 67.30 -600.0 +-3000.0 67.30 -500.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -500.0 +-3000.0 65.60 -400.0 +-3000.0 67.30 -500.0 +-3000.0 67.30 -400.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -400.0 +-3000.0 65.60 -300.0 +-3000.0 67.30 -400.0 +-3000.0 67.30 -300.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -300.0 +-3000.0 65.60 -200.0 +-3000.0 67.30 -300.0 +-3000.0 67.30 -200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -200.0 +-3000.0 65.60 -100.0 +-3000.0 67.30 -200.0 +-3000.0 67.30 -100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -100.0 +-3000.0 65.60 0.0 +-3000.0 67.30 -100.0 +-3000.0 67.30 0.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 0.0 +-3000.0 63.60 100.0 +-3000.0 67.30 0.0 +-3000.0 65.30 100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 63.60 100.0 +-3000.0 61.60 200.0 +-3000.0 65.30 100.0 +-3000.0 63.30 200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 61.60 200.0 +-3000.0 59.60 300.0 +-3000.0 63.30 200.0 +-3000.0 61.30 300.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 59.60 300.0 +-3000.0 57.60 400.0 +-3000.0 61.30 300.0 +-3000.0 59.30 400.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 57.60 400.0 +-3000.0 55.60 500.0 +-3000.0 59.30 400.0 +-3000.0 57.30 500.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 55.60 500.0 +-3000.0 53.60 600.0 +-3000.0 57.30 500.0 +-3000.0 55.30 600.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 53.60 600.0 +-3000.0 51.60 700.0 +-3000.0 55.30 600.0 +-3000.0 53.30 700.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 51.60 700.0 +-3000.0 49.60 800.0 +-3000.0 53.30 700.0 +-3000.0 51.30 800.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 49.60 800.0 +-3000.0 47.60 900.0 +-3000.0 51.30 800.0 +-3000.0 49.30 900.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 47.60 900.0 +-3000.0 45.60 1000.0 +-3000.0 49.30 900.0 +-3000.0 47.30 1000.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 45.60 1000.0 +-3000.0 43.60 1100.0 +-3000.0 47.30 1000.0 +-3000.0 45.30 1100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 43.60 1100.0 +-3000.0 41.60 1200.0 +-3000.0 45.30 1100.0 +-3000.0 43.30 1200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 41.60 1200.0 +-3000.0 39.60 1300.0 +-3000.0 43.30 1200.0 +-3000.0 41.30 1300.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 39.60 1300.0 +-3000.0 37.60 1400.0 +-3000.0 41.30 1300.0 +-3000.0 39.30 1400.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 37.60 1400.0 +-3000.0 35.60 1500.0 +-3000.0 39.30 1400.0 +-3000.0 37.30 1500.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 35.60 1500.0 +-3000.0 33.60 1600.0 +-3000.0 37.30 1500.0 +-3000.0 35.30 1600.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 33.60 1600.0 +-3000.0 31.60 1700.0 +-3000.0 35.30 1600.0 +-3000.0 33.30 1700.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 31.60 1700.0 +-3000.0 29.60 1800.0 +-3000.0 33.30 1700.0 +-3000.0 31.30 1800.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 29.60 1800.0 +-3000.0 27.60 1900.0 +-3000.0 31.30 1800.0 +-3000.0 29.30 1900.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 27.60 1900.0 +-3000.0 25.60 2000.0 +-3000.0 29.30 1900.0 +-3000.0 27.30 2000.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 25.60 2000.0 +-3000.0 23.60 2100.0 +-3000.0 27.30 2000.0 +-3000.0 25.30 2100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 23.60 2100.0 +-3000.0 21.60 2200.0 +-3000.0 25.30 2100.0 +-3000.0 23.30 2200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 21.60 2200.0 +-3000.0 19.60 2300.0 +-3000.0 23.30 2200.0 +-3000.0 21.30 2300.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 19.60 2300.0 +-3000.0 17.60 2400.0 +-3000.0 21.30 2300.0 +-3000.0 19.30 2400.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 17.60 2400.0 +-3000.0 15.60 2500.0 +-3000.0 19.30 2400.0 +-3000.0 17.30 2500.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 15.60 2500.0 +-3000.0 13.60 2600.0 +-3000.0 17.30 2500.0 +-3000.0 15.30 2600.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 13.60 2600.0 +-3000.0 11.60 2700.0 +-3000.0 15.30 2600.0 +-3000.0 13.30 2700.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 11.60 2700.0 +-3000.0 9.60 2800.0 +-3000.0 13.30 2700.0 +-3000.0 11.30 2800.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 9.60 2800.0 +-3000.0 7.60 2900.0 +-3000.0 11.30 2800.0 +-3000.0 9.30 2900.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 7.60 2900.0 +-3000.0 5.60 3000.0 +-3000.0 9.30 2900.0 +-3000.0 7.30 3000.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 5.60 3000.0 +-3000.0 3.60 3100.0 +-3000.0 7.30 3000.0 +-3000.0 5.30 3100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 3.60 3100.0 +-3000.0 1.60 3200.0 +-3000.0 5.30 3100.0 +-3000.0 3.30 3200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 1.60 3200.0 +-3000.0 -0.40 3300.0 +-3000.0 3.30 3200.0 +-3000.0 1.30 3300.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 -0.40 3300.0 +-3000.0 -2.40 3400.0 +-3000.0 1.30 3300.0 +-3000.0 -0.70 3400.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 -2.40 3400.0 +-3000.0 -4.40 3500.0 +-3000.0 -0.70 3400.0 +-3000.0 -2.70 3500.0 +0.4 4.0 3 0.04 vis +endtraction +// the W4 of the stations of the timetable +include ip/pkp/w4n.inc gora#1 -2997.3 60.00 -90.0 180 0 0 -10 202 end +// a signal at stop: what the AI reads of one, a memory cell with SetVelocity 0 0 and the event that reads it +node -1 0 hr_sem_mem memcell -2997.3 8.00 3000.0 SetVelocity 0.0 0.0 none endmemcell +event hr_sem_info getvalues 5.0 hr_sem_mem endevent + +trainset {{timetable}} hr_05 0.0 0.1 +{{consist}} +endtrainset diff --git a/tests/scenarios/cases/td_freight_downgrade.txt b/tests/scenarios/cases/td_freight_downgrade.txt new file mode 100644 index 000000000..1fd01f911 --- /dev/null +++ b/tests/scenarios/cases/td_freight_downgrade.txt @@ -0,0 +1,17 @@ +________________________________________________________________ +[ Rodzaj i numer pociagu | TEST44 ] +[ Kategoria | TME ] +[________________________________________________|______________] +[ | Gora ] +[ Relacja pociagu | Koniec ] +[________________________________________________|______________] +[ Wymagany % ciezaru hamujacego | 50% ] +[________________________________________________|______________] +[ Seria i obciazenie lokomotywy | ET41 1700 ] +[________________________________________________|______________] +[ | | Gora 2 | | ] +[ | 60 | R1,L,H,RT,PP 2 10.35 | ] +[ | |----------------------------------1----------|---] +[ | | Koniec 1 10.55 | 20] +[ | | R1 1 10.56 | ] +[_______|_____|__________________________________1__________|___] diff --git a/tests/scenarios/cases/td_freight_downgrade12.txt b/tests/scenarios/cases/td_freight_downgrade12.txt new file mode 100644 index 000000000..1fc503342 --- /dev/null +++ b/tests/scenarios/cases/td_freight_downgrade12.txt @@ -0,0 +1,17 @@ +________________________________________________________________ +[ Rodzaj i numer pociagu | TEST45 ] +[ Kategoria | TME ] +[________________________________________________|______________] +[ | Gora ] +[ Relacja pociagu | Koniec ] +[________________________________________________|______________] +[ Wymagany % ciezaru hamujacego | 50% ] +[________________________________________________|______________] +[ Seria i obciazenie lokomotywy | ST43 3000 ] +[________________________________________________|______________] +[ | | Gora 2 | | ] +[ | 40 | R1,L,H,RT,PP 2 10.35 | ] +[ | |----------------------------------1----------|---] +[ | | Koniec 1 11.10 | 35] +[ | | R1 1 11.11 | ] +[_______|_____|__________________________________1__________|___] diff --git a/tests/scenarios/cases/td_level_signal.scn b/tests/scenarios/cases/td_level_signal.scn new file mode 100644 index 000000000..c3d13eb87 --- /dev/null +++ b/tests/scenarios/cases/td_level_signal.scn @@ -0,0 +1,333 @@ +// added by tests/scenarios/run.py to td.scn, whose own trainsets were removed. +// a line of its own, away from the tracks of td.scn: 2100 m level, under an overhead wire. the train starts with +// its head 10 m before the W4 of Gora and runs on the timetable {{timetable}} (no stop; a freight train leaves Gora at once) to the signal +// lv_sem at stop 1000 m ahead. the line goes on 500 m past it +node -1 0 lv_00 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -500.0 0.0 +0 +endtrack +node -1 0 lv_01 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -400.0 0.0 +0 +endtrack +node -1 0 lv_02 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -300.0 0.0 +0 +endtrack +node -1 0 lv_03 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -200.0 0.0 +0 +endtrack +node -1 0 lv_04 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -100.0 0.0 +0 +endtrack +node -1 0 lv_05 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 0.0 0.0 +0 +event2 gora#1_stopinfo +endtrack +node -1 0 lv_06 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 100.0 0.0 +0 +endtrack +node -1 0 lv_07 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 200.0 0.0 +0 +endtrack +node -1 0 lv_08 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 300.0 0.0 +0 +endtrack +node -1 0 lv_09 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 400.0 0.0 +0 +endtrack +node -1 0 lv_10 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 500.0 0.0 +0 +endtrack +node -1 0 lv_11 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 600.0 0.0 +0 +endtrack +node -1 0 lv_12 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 700.0 0.0 +0 +endtrack +node -1 0 lv_13 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 700.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 800.0 0.0 +0 +endtrack +node -1 0 lv_14 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 800.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 900.0 0.0 +0 +endtrack +node -1 0 lv_15 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 900.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 1000.0 0.0 +0 +event2 lv_sem_info +endtrack +node -1 0 lv_16 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 1000.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 1100.0 0.0 +0 +endtrack +node -1 0 lv_17 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 1100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 1200.0 0.0 +0 +endtrack +node -1 0 lv_18 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 1200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 1300.0 0.0 +0 +endtrack +node -1 0 lv_19 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 1300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 1400.0 0.0 +0 +endtrack +node -1 0 lv_20 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 1400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 1500.0 0.0 +0 +endtrack +// the overhead wire along the whole line, as td.scn has it: 5.6 m above the rail, the carrier 1.7 m higher, fed by +// a substation of its own +node -1 0 lv_pwr tractionpowersource -3000.0 60.00 0.0 3400 0 0.01 2000 1.0 3 60.0 end +node -1 0 none traction lv_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -600.0 +-3000.0 65.60 -500.0 +-3000.0 67.30 -600.0 +-3000.0 67.30 -500.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction lv_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -500.0 +-3000.0 65.60 -400.0 +-3000.0 67.30 -500.0 +-3000.0 67.30 -400.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction lv_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -400.0 +-3000.0 65.60 -300.0 +-3000.0 67.30 -400.0 +-3000.0 67.30 -300.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction lv_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -300.0 +-3000.0 65.60 -200.0 +-3000.0 67.30 -300.0 +-3000.0 67.30 -200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction lv_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -200.0 +-3000.0 65.60 -100.0 +-3000.0 67.30 -200.0 +-3000.0 67.30 -100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction lv_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -100.0 +-3000.0 65.60 0.0 +-3000.0 67.30 -100.0 +-3000.0 67.30 0.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction lv_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 0.0 +-3000.0 65.60 100.0 +-3000.0 67.30 0.0 +-3000.0 67.30 100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction lv_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 100.0 +-3000.0 65.60 200.0 +-3000.0 67.30 100.0 +-3000.0 67.30 200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction lv_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 200.0 +-3000.0 65.60 300.0 +-3000.0 67.30 200.0 +-3000.0 67.30 300.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction lv_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 300.0 +-3000.0 65.60 400.0 +-3000.0 67.30 300.0 +-3000.0 67.30 400.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction lv_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 400.0 +-3000.0 65.60 500.0 +-3000.0 67.30 400.0 +-3000.0 67.30 500.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction lv_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 500.0 +-3000.0 65.60 600.0 +-3000.0 67.30 500.0 +-3000.0 67.30 600.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction lv_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 600.0 +-3000.0 65.60 700.0 +-3000.0 67.30 600.0 +-3000.0 67.30 700.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction lv_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 700.0 +-3000.0 65.60 800.0 +-3000.0 67.30 700.0 +-3000.0 67.30 800.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction lv_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 800.0 +-3000.0 65.60 900.0 +-3000.0 67.30 800.0 +-3000.0 67.30 900.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction lv_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 900.0 +-3000.0 65.60 1000.0 +-3000.0 67.30 900.0 +-3000.0 67.30 1000.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction lv_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 1000.0 +-3000.0 65.60 1100.0 +-3000.0 67.30 1000.0 +-3000.0 67.30 1100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction lv_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 1100.0 +-3000.0 65.60 1200.0 +-3000.0 67.30 1100.0 +-3000.0 67.30 1200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction lv_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 1200.0 +-3000.0 65.60 1300.0 +-3000.0 67.30 1200.0 +-3000.0 67.30 1300.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction lv_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 1300.0 +-3000.0 65.60 1400.0 +-3000.0 67.30 1300.0 +-3000.0 67.30 1400.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction lv_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 1400.0 +-3000.0 65.60 1500.0 +-3000.0 67.30 1400.0 +-3000.0 67.30 1500.0 +0.4 4.0 3 0.04 vis +endtraction +// the W4 of the stations of the timetable +include ip/pkp/w4n.inc gora#1 -2997.3 60.00 -90.0 180 0 0 -10 202 end +// a signal at stop: what the AI reads of one, a memory cell with SetVelocity 0 0 and the event that reads it +node -1 0 lv_sem_mem memcell -2997.3 68.00 1000.0 SetVelocity 0.0 0.0 none endmemcell +event lv_sem_info getvalues 5.0 lv_sem_mem endevent + +trainset {{timetable}} lv_05 0.0 0.1 +{{consist}} +endtrainset diff --git a/tests/scenarios/cases/td_passenger_upgrade.txt b/tests/scenarios/cases/td_passenger_upgrade.txt new file mode 100644 index 000000000..bc8e12087 --- /dev/null +++ b/tests/scenarios/cases/td_passenger_upgrade.txt @@ -0,0 +1,17 @@ +________________________________________________________________ +[ Rodzaj i numer pociagu | TEST28 ] +[ Kategoria | RO ] +[________________________________________________|______________] +[ | Gora ] +[ Relacja pociagu | Koniec ] +[________________________________________________|______________] +[ Wymagany % ciezaru hamujacego | 88% ] +[________________________________________________|______________] +[ Seria i obciazenie lokomotywy | EU07 400 ] +[________________________________________________|______________] +[ | | Gora 2 | | ] +[ | 80 | R1,L,H,RT,PP 2 10.35 | ] +[ | |----------------------------------1----------|---] +[ | | Koniec 1 10.45 | 10] +[ | | R1 1 10.46 | ] +[_______|_____|__________________________________1__________|___] diff --git a/tests/scenarios/cases/td_upgrade_long.scn b/tests/scenarios/cases/td_upgrade_long.scn new file mode 100644 index 000000000..12ff5c713 --- /dev/null +++ b/tests/scenarios/cases/td_upgrade_long.scn @@ -0,0 +1,934 @@ +// added by tests/scenarios/run.py to td.scn, whose own trainsets were removed. +// a line of its own, away from the tracks of td.scn: 600 m level, then 5500 m up a gradient of 10 per mille, +// under an overhead wire. the train starts on the level with its head 10 m before the W4 of Gora and runs on the +// timetable {{timetable}} (leaves Gora at 10:35, no other stop) at the line limit of the timetable, up to the signal ul_sem +// at stop 5300 m up the gradient. the line goes on 200 m past it +node -1 0 ul_00 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -500.0 0.0 +0 +endtrack +node -1 0 ul_01 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -400.0 0.0 +0 +endtrack +node -1 0 ul_02 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -300.0 0.0 +0 +endtrack +node -1 0 ul_03 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -200.0 0.0 +0 +endtrack +node -1 0 ul_04 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -100.0 0.0 +0 +endtrack +node -1 0 ul_05 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 0.0 0.0 +0 +event2 gora#1_stopinfo +endtrack +node -1 0 ul_06 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 61.00 100.0 0.0 +0 +endtrack +node -1 0 ul_07 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 61.00 100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 62.00 200.0 0.0 +0 +endtrack +node -1 0 ul_08 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 62.00 200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 63.00 300.0 0.0 +0 +endtrack +node -1 0 ul_09 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 63.00 300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 64.00 400.0 0.0 +0 +endtrack +node -1 0 ul_10 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 64.00 400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 65.00 500.0 0.0 +0 +endtrack +node -1 0 ul_11 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 65.00 500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 66.00 600.0 0.0 +0 +endtrack +node -1 0 ul_12 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 66.00 600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 67.00 700.0 0.0 +0 +endtrack +node -1 0 ul_13 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 67.00 700.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 68.00 800.0 0.0 +0 +endtrack +node -1 0 ul_14 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 68.00 800.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 69.00 900.0 0.0 +0 +endtrack +node -1 0 ul_15 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 69.00 900.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 70.00 1000.0 0.0 +0 +endtrack +node -1 0 ul_16 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 70.00 1000.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 71.00 1100.0 0.0 +0 +endtrack +node -1 0 ul_17 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 71.00 1100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 72.00 1200.0 0.0 +0 +endtrack +node -1 0 ul_18 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 72.00 1200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 73.00 1300.0 0.0 +0 +endtrack +node -1 0 ul_19 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 73.00 1300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 74.00 1400.0 0.0 +0 +endtrack +node -1 0 ul_20 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 74.00 1400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 75.00 1500.0 0.0 +0 +endtrack +node -1 0 ul_21 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 75.00 1500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 76.00 1600.0 0.0 +0 +endtrack +node -1 0 ul_22 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 76.00 1600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 77.00 1700.0 0.0 +0 +endtrack +node -1 0 ul_23 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 77.00 1700.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 78.00 1800.0 0.0 +0 +endtrack +node -1 0 ul_24 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 78.00 1800.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 79.00 1900.0 0.0 +0 +endtrack +node -1 0 ul_25 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 79.00 1900.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 80.00 2000.0 0.0 +0 +endtrack +node -1 0 ul_26 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 80.00 2000.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 81.00 2100.0 0.0 +0 +endtrack +node -1 0 ul_27 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 81.00 2100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 82.00 2200.0 0.0 +0 +endtrack +node -1 0 ul_28 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 82.00 2200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 83.00 2300.0 0.0 +0 +endtrack +node -1 0 ul_29 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 83.00 2300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 84.00 2400.0 0.0 +0 +endtrack +node -1 0 ul_30 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 84.00 2400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 85.00 2500.0 0.0 +0 +endtrack +node -1 0 ul_31 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 85.00 2500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 86.00 2600.0 0.0 +0 +endtrack +node -1 0 ul_32 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 86.00 2600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 87.00 2700.0 0.0 +0 +endtrack +node -1 0 ul_33 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 87.00 2700.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 88.00 2800.0 0.0 +0 +endtrack +node -1 0 ul_34 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 88.00 2800.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 89.00 2900.0 0.0 +0 +endtrack +node -1 0 ul_35 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 89.00 2900.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 90.00 3000.0 0.0 +0 +endtrack +node -1 0 ul_36 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 90.00 3000.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 91.00 3100.0 0.0 +0 +endtrack +node -1 0 ul_37 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 91.00 3100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 92.00 3200.0 0.0 +0 +endtrack +node -1 0 ul_38 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 92.00 3200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 93.00 3300.0 0.0 +0 +endtrack +node -1 0 ul_39 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 93.00 3300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 94.00 3400.0 0.0 +0 +endtrack +node -1 0 ul_40 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 94.00 3400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 95.00 3500.0 0.0 +0 +endtrack +node -1 0 ul_41 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 95.00 3500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 96.00 3600.0 0.0 +0 +endtrack +node -1 0 ul_42 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 96.00 3600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 97.00 3700.0 0.0 +0 +endtrack +node -1 0 ul_43 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 97.00 3700.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 98.00 3800.0 0.0 +0 +endtrack +node -1 0 ul_44 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 98.00 3800.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 99.00 3900.0 0.0 +0 +endtrack +node -1 0 ul_45 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 99.00 3900.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 100.00 4000.0 0.0 +0 +endtrack +node -1 0 ul_46 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 100.00 4000.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 101.00 4100.0 0.0 +0 +endtrack +node -1 0 ul_47 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 101.00 4100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 102.00 4200.0 0.0 +0 +endtrack +node -1 0 ul_48 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 102.00 4200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 103.00 4300.0 0.0 +0 +endtrack +node -1 0 ul_49 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 103.00 4300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 104.00 4400.0 0.0 +0 +endtrack +node -1 0 ul_50 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 104.00 4400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 105.00 4500.0 0.0 +0 +endtrack +node -1 0 ul_51 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 105.00 4500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 106.00 4600.0 0.0 +0 +endtrack +node -1 0 ul_52 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 106.00 4600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 107.00 4700.0 0.0 +0 +endtrack +node -1 0 ul_53 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 107.00 4700.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 108.00 4800.0 0.0 +0 +endtrack +node -1 0 ul_54 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 108.00 4800.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 109.00 4900.0 0.0 +0 +endtrack +node -1 0 ul_55 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 109.00 4900.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 110.00 5000.0 0.0 +0 +endtrack +node -1 0 ul_56 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 110.00 5000.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 111.00 5100.0 0.0 +0 +endtrack +node -1 0 ul_57 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 111.00 5100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 112.00 5200.0 0.0 +0 +endtrack +node -1 0 ul_58 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 112.00 5200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 113.00 5300.0 0.0 +0 +event2 ul_sem_info +endtrack +node -1 0 ul_59 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 113.00 5300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 114.00 5400.0 0.0 +0 +endtrack +node -1 0 ul_60 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 114.00 5400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 115.00 5500.0 0.0 +0 +endtrack +// the overhead wire along the whole line, as td.scn has it: 5.6 m above the rail, the carrier 1.7 m higher, fed by +// a substation of its own +node -1 0 ul_pwr tractionpowersource -3000.0 60.00 0.0 3400 0 0.01 2000 1.0 3 60.0 end +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -600.0 +-3000.0 65.60 -500.0 +-3000.0 67.30 -600.0 +-3000.0 67.30 -500.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -500.0 +-3000.0 65.60 -400.0 +-3000.0 67.30 -500.0 +-3000.0 67.30 -400.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -400.0 +-3000.0 65.60 -300.0 +-3000.0 67.30 -400.0 +-3000.0 67.30 -300.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -300.0 +-3000.0 65.60 -200.0 +-3000.0 67.30 -300.0 +-3000.0 67.30 -200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -200.0 +-3000.0 65.60 -100.0 +-3000.0 67.30 -200.0 +-3000.0 67.30 -100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -100.0 +-3000.0 65.60 0.0 +-3000.0 67.30 -100.0 +-3000.0 67.30 0.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 0.0 +-3000.0 66.60 100.0 +-3000.0 67.30 0.0 +-3000.0 68.30 100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 66.60 100.0 +-3000.0 67.60 200.0 +-3000.0 68.30 100.0 +-3000.0 69.30 200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 67.60 200.0 +-3000.0 68.60 300.0 +-3000.0 69.30 200.0 +-3000.0 70.30 300.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 68.60 300.0 +-3000.0 69.60 400.0 +-3000.0 70.30 300.0 +-3000.0 71.30 400.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 69.60 400.0 +-3000.0 70.60 500.0 +-3000.0 71.30 400.0 +-3000.0 72.30 500.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 70.60 500.0 +-3000.0 71.60 600.0 +-3000.0 72.30 500.0 +-3000.0 73.30 600.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 71.60 600.0 +-3000.0 72.60 700.0 +-3000.0 73.30 600.0 +-3000.0 74.30 700.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 72.60 700.0 +-3000.0 73.60 800.0 +-3000.0 74.30 700.0 +-3000.0 75.30 800.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 73.60 800.0 +-3000.0 74.60 900.0 +-3000.0 75.30 800.0 +-3000.0 76.30 900.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 74.60 900.0 +-3000.0 75.60 1000.0 +-3000.0 76.30 900.0 +-3000.0 77.30 1000.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 75.60 1000.0 +-3000.0 76.60 1100.0 +-3000.0 77.30 1000.0 +-3000.0 78.30 1100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 76.60 1100.0 +-3000.0 77.60 1200.0 +-3000.0 78.30 1100.0 +-3000.0 79.30 1200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 77.60 1200.0 +-3000.0 78.60 1300.0 +-3000.0 79.30 1200.0 +-3000.0 80.30 1300.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 78.60 1300.0 +-3000.0 79.60 1400.0 +-3000.0 80.30 1300.0 +-3000.0 81.30 1400.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 79.60 1400.0 +-3000.0 80.60 1500.0 +-3000.0 81.30 1400.0 +-3000.0 82.30 1500.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 80.60 1500.0 +-3000.0 81.60 1600.0 +-3000.0 82.30 1500.0 +-3000.0 83.30 1600.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 81.60 1600.0 +-3000.0 82.60 1700.0 +-3000.0 83.30 1600.0 +-3000.0 84.30 1700.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 82.60 1700.0 +-3000.0 83.60 1800.0 +-3000.0 84.30 1700.0 +-3000.0 85.30 1800.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 83.60 1800.0 +-3000.0 84.60 1900.0 +-3000.0 85.30 1800.0 +-3000.0 86.30 1900.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 84.60 1900.0 +-3000.0 85.60 2000.0 +-3000.0 86.30 1900.0 +-3000.0 87.30 2000.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 85.60 2000.0 +-3000.0 86.60 2100.0 +-3000.0 87.30 2000.0 +-3000.0 88.30 2100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 86.60 2100.0 +-3000.0 87.60 2200.0 +-3000.0 88.30 2100.0 +-3000.0 89.30 2200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 87.60 2200.0 +-3000.0 88.60 2300.0 +-3000.0 89.30 2200.0 +-3000.0 90.30 2300.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 88.60 2300.0 +-3000.0 89.60 2400.0 +-3000.0 90.30 2300.0 +-3000.0 91.30 2400.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 89.60 2400.0 +-3000.0 90.60 2500.0 +-3000.0 91.30 2400.0 +-3000.0 92.30 2500.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 90.60 2500.0 +-3000.0 91.60 2600.0 +-3000.0 92.30 2500.0 +-3000.0 93.30 2600.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 91.60 2600.0 +-3000.0 92.60 2700.0 +-3000.0 93.30 2600.0 +-3000.0 94.30 2700.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 92.60 2700.0 +-3000.0 93.60 2800.0 +-3000.0 94.30 2700.0 +-3000.0 95.30 2800.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 93.60 2800.0 +-3000.0 94.60 2900.0 +-3000.0 95.30 2800.0 +-3000.0 96.30 2900.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 94.60 2900.0 +-3000.0 95.60 3000.0 +-3000.0 96.30 2900.0 +-3000.0 97.30 3000.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 95.60 3000.0 +-3000.0 96.60 3100.0 +-3000.0 97.30 3000.0 +-3000.0 98.30 3100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 96.60 3100.0 +-3000.0 97.60 3200.0 +-3000.0 98.30 3100.0 +-3000.0 99.30 3200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 97.60 3200.0 +-3000.0 98.60 3300.0 +-3000.0 99.30 3200.0 +-3000.0 100.30 3300.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 98.60 3300.0 +-3000.0 99.60 3400.0 +-3000.0 100.30 3300.0 +-3000.0 101.30 3400.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 99.60 3400.0 +-3000.0 100.60 3500.0 +-3000.0 101.30 3400.0 +-3000.0 102.30 3500.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 100.60 3500.0 +-3000.0 101.60 3600.0 +-3000.0 102.30 3500.0 +-3000.0 103.30 3600.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 101.60 3600.0 +-3000.0 102.60 3700.0 +-3000.0 103.30 3600.0 +-3000.0 104.30 3700.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 102.60 3700.0 +-3000.0 103.60 3800.0 +-3000.0 104.30 3700.0 +-3000.0 105.30 3800.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 103.60 3800.0 +-3000.0 104.60 3900.0 +-3000.0 105.30 3800.0 +-3000.0 106.30 3900.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 104.60 3900.0 +-3000.0 105.60 4000.0 +-3000.0 106.30 3900.0 +-3000.0 107.30 4000.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 105.60 4000.0 +-3000.0 106.60 4100.0 +-3000.0 107.30 4000.0 +-3000.0 108.30 4100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 106.60 4100.0 +-3000.0 107.60 4200.0 +-3000.0 108.30 4100.0 +-3000.0 109.30 4200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 107.60 4200.0 +-3000.0 108.60 4300.0 +-3000.0 109.30 4200.0 +-3000.0 110.30 4300.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 108.60 4300.0 +-3000.0 109.60 4400.0 +-3000.0 110.30 4300.0 +-3000.0 111.30 4400.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 109.60 4400.0 +-3000.0 110.60 4500.0 +-3000.0 111.30 4400.0 +-3000.0 112.30 4500.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 110.60 4500.0 +-3000.0 111.60 4600.0 +-3000.0 112.30 4500.0 +-3000.0 113.30 4600.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 111.60 4600.0 +-3000.0 112.60 4700.0 +-3000.0 113.30 4600.0 +-3000.0 114.30 4700.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 112.60 4700.0 +-3000.0 113.60 4800.0 +-3000.0 114.30 4700.0 +-3000.0 115.30 4800.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 113.60 4800.0 +-3000.0 114.60 4900.0 +-3000.0 115.30 4800.0 +-3000.0 116.30 4900.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 114.60 4900.0 +-3000.0 115.60 5000.0 +-3000.0 116.30 4900.0 +-3000.0 117.30 5000.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 115.60 5000.0 +-3000.0 116.60 5100.0 +-3000.0 117.30 5000.0 +-3000.0 118.30 5100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 116.60 5100.0 +-3000.0 117.60 5200.0 +-3000.0 118.30 5100.0 +-3000.0 119.30 5200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 117.60 5200.0 +-3000.0 118.60 5300.0 +-3000.0 119.30 5200.0 +-3000.0 120.30 5300.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 118.60 5300.0 +-3000.0 119.60 5400.0 +-3000.0 120.30 5300.0 +-3000.0 121.30 5400.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction ul_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 119.60 5400.0 +-3000.0 120.60 5500.0 +-3000.0 121.30 5400.0 +-3000.0 122.30 5500.0 +0.4 4.0 3 0.04 vis +endtraction +// the W4 of the stations of the timetable +include ip/pkp/w4n.inc gora#1 -2997.3 60.00 -90.0 180 0 0 -10 202 end +// a signal at stop: what the AI reads of one, a memory cell with SetVelocity 0 0 and the event that reads it +node -1 0 ul_sem_mem memcell -2997.3 121.00 5300.0 SetVelocity 0.0 0.0 none endmemcell +event ul_sem_info getvalues 5.0 ul_sem_mem endevent + +trainset {{timetable}} ul_05 0.0 0.1 +{{consist}} +endtrainset diff --git a/tests/scenarios/cases/td_upgrade_signal_start.scn b/tests/scenarios/cases/td_upgrade_signal_start.scn new file mode 100644 index 000000000..3995d3a96 --- /dev/null +++ b/tests/scenarios/cases/td_upgrade_signal_start.scn @@ -0,0 +1,492 @@ +// added by tests/scenarios/run.py to td.scn, whose own trainsets were removed. +// a line of its own, away from the tracks of td.scn: 600 m level, then 2500 m up a gradient of 10 per mille, +// under an overhead wire. the train starts on the level with its head 10 m before the W4 of Gora and runs on the +// timetable {{timetable}} (no stop; a freight train leaves Gora at once) up to the signal hu_sem1 1000 m up the gradient, at stop until 10:42, +// where it stops with the whole train on the gradient, then on to the signal hu_sem2 at stop 2300 m up the +// gradient. the line goes on 200 m past it +node -1 0 hu_00 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -500.0 0.0 +0 +endtrack +node -1 0 hu_01 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -400.0 0.0 +0 +endtrack +node -1 0 hu_02 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -300.0 0.0 +0 +endtrack +node -1 0 hu_03 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -200.0 0.0 +0 +endtrack +node -1 0 hu_04 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -100.0 0.0 +0 +endtrack +node -1 0 hu_05 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 0.0 0.0 +0 +event2 gora#1_stopinfo +endtrack +node -1 0 hu_06 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 61.00 100.0 0.0 +0 +endtrack +node -1 0 hu_07 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 61.00 100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 62.00 200.0 0.0 +0 +endtrack +node -1 0 hu_08 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 62.00 200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 63.00 300.0 0.0 +0 +endtrack +node -1 0 hu_09 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 63.00 300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 64.00 400.0 0.0 +0 +endtrack +node -1 0 hu_10 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 64.00 400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 65.00 500.0 0.0 +0 +endtrack +node -1 0 hu_11 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 65.00 500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 66.00 600.0 0.0 +0 +endtrack +node -1 0 hu_12 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 66.00 600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 67.00 700.0 0.0 +0 +endtrack +node -1 0 hu_13 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 67.00 700.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 68.00 800.0 0.0 +0 +endtrack +node -1 0 hu_14 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 68.00 800.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 69.00 900.0 0.0 +0 +endtrack +node -1 0 hu_15 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 69.00 900.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 70.00 1000.0 0.0 +0 +event2 hu_sem1_info +endtrack +node -1 0 hu_16 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 70.00 1000.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 71.00 1100.0 0.0 +0 +endtrack +node -1 0 hu_17 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 71.00 1100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 72.00 1200.0 0.0 +0 +endtrack +node -1 0 hu_18 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 72.00 1200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 73.00 1300.0 0.0 +0 +endtrack +node -1 0 hu_19 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 73.00 1300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 74.00 1400.0 0.0 +0 +endtrack +node -1 0 hu_20 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 74.00 1400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 75.00 1500.0 0.0 +0 +endtrack +node -1 0 hu_21 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 75.00 1500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 76.00 1600.0 0.0 +0 +endtrack +node -1 0 hu_22 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 76.00 1600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 77.00 1700.0 0.0 +0 +endtrack +node -1 0 hu_23 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 77.00 1700.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 78.00 1800.0 0.0 +0 +endtrack +node -1 0 hu_24 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 78.00 1800.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 79.00 1900.0 0.0 +0 +endtrack +node -1 0 hu_25 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 79.00 1900.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 80.00 2000.0 0.0 +0 +endtrack +node -1 0 hu_26 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 80.00 2000.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 81.00 2100.0 0.0 +0 +endtrack +node -1 0 hu_27 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 81.00 2100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 82.00 2200.0 0.0 +0 +endtrack +node -1 0 hu_28 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 82.00 2200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 83.00 2300.0 0.0 +0 +event2 hu_sem2_info +endtrack +node -1 0 hu_29 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 83.00 2300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 84.00 2400.0 0.0 +0 +endtrack +node -1 0 hu_30 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 84.00 2400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 85.00 2500.0 0.0 +0 +endtrack +// the overhead wire along the whole line, as td.scn has it: 5.6 m above the rail, the carrier 1.7 m higher, fed by +// a substation of its own +node -1 0 hu_pwr tractionpowersource -3000.0 60.00 0.0 3400 0 0.01 2000 1.0 3 60.0 end +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -600.0 +-3000.0 65.60 -500.0 +-3000.0 67.30 -600.0 +-3000.0 67.30 -500.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -500.0 +-3000.0 65.60 -400.0 +-3000.0 67.30 -500.0 +-3000.0 67.30 -400.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -400.0 +-3000.0 65.60 -300.0 +-3000.0 67.30 -400.0 +-3000.0 67.30 -300.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -300.0 +-3000.0 65.60 -200.0 +-3000.0 67.30 -300.0 +-3000.0 67.30 -200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -200.0 +-3000.0 65.60 -100.0 +-3000.0 67.30 -200.0 +-3000.0 67.30 -100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -100.0 +-3000.0 65.60 0.0 +-3000.0 67.30 -100.0 +-3000.0 67.30 0.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 0.0 +-3000.0 66.60 100.0 +-3000.0 67.30 0.0 +-3000.0 68.30 100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 66.60 100.0 +-3000.0 67.60 200.0 +-3000.0 68.30 100.0 +-3000.0 69.30 200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 67.60 200.0 +-3000.0 68.60 300.0 +-3000.0 69.30 200.0 +-3000.0 70.30 300.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 68.60 300.0 +-3000.0 69.60 400.0 +-3000.0 70.30 300.0 +-3000.0 71.30 400.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 69.60 400.0 +-3000.0 70.60 500.0 +-3000.0 71.30 400.0 +-3000.0 72.30 500.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 70.60 500.0 +-3000.0 71.60 600.0 +-3000.0 72.30 500.0 +-3000.0 73.30 600.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 71.60 600.0 +-3000.0 72.60 700.0 +-3000.0 73.30 600.0 +-3000.0 74.30 700.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 72.60 700.0 +-3000.0 73.60 800.0 +-3000.0 74.30 700.0 +-3000.0 75.30 800.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 73.60 800.0 +-3000.0 74.60 900.0 +-3000.0 75.30 800.0 +-3000.0 76.30 900.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 74.60 900.0 +-3000.0 75.60 1000.0 +-3000.0 76.30 900.0 +-3000.0 77.30 1000.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 75.60 1000.0 +-3000.0 76.60 1100.0 +-3000.0 77.30 1000.0 +-3000.0 78.30 1100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 76.60 1100.0 +-3000.0 77.60 1200.0 +-3000.0 78.30 1100.0 +-3000.0 79.30 1200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 77.60 1200.0 +-3000.0 78.60 1300.0 +-3000.0 79.30 1200.0 +-3000.0 80.30 1300.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 78.60 1300.0 +-3000.0 79.60 1400.0 +-3000.0 80.30 1300.0 +-3000.0 81.30 1400.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 79.60 1400.0 +-3000.0 80.60 1500.0 +-3000.0 81.30 1400.0 +-3000.0 82.30 1500.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 80.60 1500.0 +-3000.0 81.60 1600.0 +-3000.0 82.30 1500.0 +-3000.0 83.30 1600.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 81.60 1600.0 +-3000.0 82.60 1700.0 +-3000.0 83.30 1600.0 +-3000.0 84.30 1700.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 82.60 1700.0 +-3000.0 83.60 1800.0 +-3000.0 84.30 1700.0 +-3000.0 85.30 1800.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 83.60 1800.0 +-3000.0 84.60 1900.0 +-3000.0 85.30 1800.0 +-3000.0 86.30 1900.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 84.60 1900.0 +-3000.0 85.60 2000.0 +-3000.0 86.30 1900.0 +-3000.0 87.30 2000.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 85.60 2000.0 +-3000.0 86.60 2100.0 +-3000.0 87.30 2000.0 +-3000.0 88.30 2100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 86.60 2100.0 +-3000.0 87.60 2200.0 +-3000.0 88.30 2100.0 +-3000.0 89.30 2200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 87.60 2200.0 +-3000.0 88.60 2300.0 +-3000.0 89.30 2200.0 +-3000.0 90.30 2300.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 88.60 2300.0 +-3000.0 89.60 2400.0 +-3000.0 90.30 2300.0 +-3000.0 91.30 2400.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction hu_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 89.60 2400.0 +-3000.0 90.60 2500.0 +-3000.0 91.30 2400.0 +-3000.0 92.30 2500.0 +0.4 4.0 3 0.04 vis +endtraction +// the W4 of the stations of the timetable +include ip/pkp/w4n.inc gora#1 -2997.3 60.00 -90.0 180 0 0 -10 202 end +// a signal at stop: what the AI reads of one, a memory cell with SetVelocity 0 0 and the event that reads it +node -1 0 hu_sem1_mem memcell -2997.3 78.00 1000.0 SetVelocity 0.0 0.0 none endmemcell +event hu_sem1_info getvalues 5.0 hu_sem1_mem endevent +// cleared at 10:42: the memory cell lets the train go at the line speed +event hu_sem1_go updatevalues 0.0 hu_sem1_mem SetVelocity 100 100 endevent +node -1 0 hu_sem1_launcher eventlauncher 0 0 0 -1 none 1042 hu_sem1_go end +// a signal at stop: what the AI reads of one, a memory cell with SetVelocity 0 0 and the event that reads it +node -1 0 hu_sem2_mem memcell -2997.3 91.00 2300.0 SetVelocity 0.0 0.0 none endmemcell +event hu_sem2_info getvalues 5.0 hu_sem2_mem endevent + +trainset {{timetable}} hu_05 0.0 0.1 +{{consist}} +endtrainset diff --git a/tests/scenarios/run.py b/tests/scenarios/run.py index fef87c4f3..fc5ab3397 100644 --- a/tests/scenarios/run.py +++ b/tests/scenarios/run.py @@ -632,6 +632,58 @@ def check_ends_moving(rows, min_speed): return ok, f"last row t={last[COL_TIME]:.1f}s, v={last[COL_VELOCITY]:.1f} km/h (wanted >= {min_speed})" +def check_keeps_moving(rows, moving_speed, min_speed, until_distance, from_distance=0.0): + """(*vehicle speed*) Once at moving_speed, the speed stays at or above min_speed between the two distances (metres + travelled, from the vehicle speed), e.g. a train doesn't come to a stand on a gradient before a restriction or in + it. The vehicle speed, as wheels slipping at the start would count as moving off.""" + if not rows or len(rows[0]) <= COL_VEHICLE_VELOCITY or rows[0][COL_VEHICLE_VELOCITY] is None: + return False, "the physicslog has no vehicle speed column, the build is too old" + speed = [abs(r[COL_VEHICLE_VELOCITY]) for r in rows] + start = next((i for i, v in enumerate(speed) if v >= moving_speed), None) + if start is None: + return False, f"never reached {moving_speed} km/h" + dist, d = [0.0], 0.0 + for i in range(1, len(rows)): + d += (speed[i - 1] + speed[i]) / 2 / 3.6 * (rows[i][COL_TIME] - rows[i - 1][COL_TIME]) + dist.append(d) + span = [i for i in range(start, len(rows)) if from_distance <= dist[i] <= until_distance] + if not span or dist[-1] < until_distance: + return False, f"travelled {dist[-1]:.0f} m only, wanted {until_distance} m" + low = min(span, key=lambda i: speed[i]) + r = rows[low] + detail = (f"lowest speed {speed[low]:.1f} km/h at t={r[COL_TIME]:.1f}s after {dist[low]:.0f} m " + f"(brake cylinder {r[COL_BRAKE_PRESS]:.2f} bar), wanted >= {min_speed} between {from_distance:.0f} and {until_distance} m") + return speed[low] >= min_speed, detail + + +def check_starts_again(rows, after, min_speed, within, max_rollback=None): + """Standing at the time `after` (e.g. at a signal that clears then), the vehicle reaches min_speed within `within` + seconds; with max_rollback (*vehicle speed*), it rolls back no more than that many metres meanwhile.""" + first = next((i for i, r in enumerate(rows) if r[COL_TIME] >= after), None) + if first is None: + return False, f"the physicslog ends before t={after}s" + if rows[first][COL_VELOCITY] > 1.0: + return False, f"moving at {rows[first][COL_VELOCITY]:.1f} km/h at t={after}s, wanted standing" + moved = next((r[COL_TIME] for r in rows[first:] if r[COL_VELOCITY] > 1.0), None) + reached = next((r[COL_TIME] for r in rows[first:] if r[COL_VELOCITY] >= min_speed), None) + rollback, back = 0.0, 0.0 + if max_rollback is not None: + if len(rows[0]) <= COL_VEHICLE_VELOCITY or rows[0][COL_VEHICLE_VELOCITY] is None: + return False, "the physicslog has no vehicle speed column, the build is too old" + end = reached if reached is not None else after + within + for a, b in zip(rows[first:], rows[first + 1:]): + if b[COL_TIME] > end: + break + back += (a[COL_VEHICLE_VELOCITY] + b[COL_VEHICLE_VELOCITY]) / 2 / 3.6 * (b[COL_TIME] - a[COL_TIME]) + rollback = max(rollback, -back) + detail = (f"moved off (1 km/h) {moved - after:.1f}s after t={after}s" if moved is not None else f"didn't move off after t={after}s") + detail += f", {min_speed} km/h after {reached - after:.1f}s" if reached is not None else f", never reached {min_speed} km/h" + if max_rollback is not None: + detail += f", rolled back {rollback:.2f} m (wanted <= {max_rollback})" + ok = reached is not None and reached - after <= within and (max_rollback is None or rollback <= max_rollback) + return ok, detail + f" (wanted {min_speed} km/h within {within}s)" + + def check_slip_clears(rows, moving_speed, stop_speed, within): """Once the vehicle has stopped after moving off, its wheels stop slipping within `within` seconds (a vehicle left skidding on locked wheels keeps its brakes capped by the sliding adhesion).""" @@ -705,6 +757,8 @@ CHECKS = { "stays_stopped": check_stays_stopped, "distance": check_distance, "ends_moving": check_ends_moving, + "keeps_moving": check_keeps_moving, + "starts_again": check_starts_again, } diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index 675c1ef8e..dfe4ed1c6 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -6781,15 +6781,38 @@ TController::determine_consist_state() { void TController::control_wheelslip() { + // a start that has slipped once keeps the sand on until the train is under way. with the sand off as soon as the + // wheels grip again, the next notch slips again, and a heavy train on poor rails slips, grips and snatches over + // and over, and may never get going (#187). a vehicle without sand starts as before + auto const velocity { std::abs( mvOccupied->Vel ) }; + if( mvControlling->SlippingWheels + && velocity < EU07_AI_SANDEDSTARTVELOCITY + && false == mvControlling->IsMainCtrlNoPowerPos() + && mvControlling->Sand > 0.0 ) { + bSandedStart = true; + } + else if( velocity >= EU07_AI_SANDEDSTARTVELOCITY + || ( velocity < EU07_AI_NOMOVEMENT && VelDesired == 0.0 ) ) { + bSandedStart = false; + } // wheel slip if( mvControlling->SlippingWheels ) { cue_action( driver_hint::sandingon ); // piasku! - cue_action( driver_hint::tractiveforcedecrease ); + if( false == bSandedStart ) { + cue_action( driver_hint::tractiveforcedecrease ); + cue_action( driver_hint::antislip ); + } + else if( ElapsedTime - fSandedStartDecreaseTime >= 1.0 ) { + // starting, a step down at a time, and no anti-slip brake: taking the power off at once and braking the + // locomotive brings a heavy train that has just got moving to a stand again, and the start begins anew + cue_action( driver_hint::tractiveforcedecrease ); + fSandedStartDecreaseTime = ElapsedTime; + } cue_action( driver_hint::brakingforcedecrease ); - cue_action( driver_hint::antislip ); ++iDriverFailCount; } - else if( std::fabs( mvControlling->Im ) > 0.75 * mvControlling->ImaxHi ) { + else if( ( std::fabs( mvControlling->Im ) > 0.75 * mvControlling->ImaxHi ) + || ( bSandedStart && false == mvControlling->IsMainCtrlNoPowerPos() ) ) { cue_action( driver_hint::sandingon ); // piaskujemy tory, coby się nie ślizgać } else { diff --git a/vehicle/Driver.h b/vehicle/Driver.h index b8eb4ec94..a00a3935f 100644 --- a/vehicle/Driver.h +++ b/vehicle/Driver.h @@ -29,6 +29,7 @@ auto const EU07_AI_NOMOVEMENT = 0.05; // standstill velocity threshold auto const EU07_AI_MOVEMENT = 1.0; // deliberate movement velocity threshold auto const EU07_AI_UPHILLGRAVITY = -0.025; // [m/s2] about 2.5 per mille up: the gradient that rolls a standing train back auto const EU07_AI_SPEEDLIMITEXTENDSBEYONDSCANRANGE = 10000.0; +auto const EU07_AI_SANDEDSTARTVELOCITY = 15.0; // [km/h] a start that slipped keeps the sand on up to this speed enum TOrders { // rozkazy dla AI @@ -442,6 +443,8 @@ private: double fShortfallTime = 0.0; // when that was checked int iShortfallGrowth = 0; // how many checks in a row the shortfall has grown bool bUphillStart = false; // starting uphill: the train brake holds the train until the power does + bool bSandedStart = false; // the wheels slipped while starting: sand while under power until the train is under way + double fSandedStartDecreaseTime = -1.0; // when the power was last taken down a step for a slip while starting double fUphillStartTime = 0.0; // when the uphill start began double fAccDesiredGravity = 0.0; // część AccDesired odjęta na spadku jako kompensacja pochylenia; AbsAccS zawiera ją już sam double VelforDriver = -1.0; // prędkość, używana przy zmianie kierunku (ograniczenie przy nieznajmości szlaku?)