mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 09:36:48 +01:00
fbb9dc1e89
end and side were unscoped enums: front, rear, left and right sat in the
global namespace (the test PCH had to leave mover.h out for it), and an end
went into any int, a side into an end, without a word from the compiler. They
become enum class VehicleEnd and VehicleSide (physics/vehicletypes.h); the
names follow the rule for types, and leave "end" and "side" to the many
locals of that name. The numbers stay: front 0, rear 1, right 0, left 1.
- ByEnd<T> / BySide<T>: two values indexed by the enum, and by a number
where a loop or a format counts them. The arrays of the ends and the sides
are these now: Couplers, Neighbours, Pantographs, MotorBlowers, Lights,
iLights, Doors.instances, pVehicles, IsAnyDoor*, m_lighthints, vCoulpler,
m_couplersounds, m_mirrormotion, iInventory, and the voltages of the
couplers
- VehicleEnds / VehicleSides to go through them, Opposite() in place of
1 - end, NumberOf() where a number is needed
- the couplers and the collisions take the ends they work on as VehicleEnd:
CouplerForce, CouplerVelocityDifference, CollisionDetect, crush_hit,
CompatibleCoupling and the rest of their family, DirF, DirPatch, and of
the vehicle couple, uncouple, the adapters, off_track_gap, has_signal_on;
Attach, Dettach and DettachStatus have overloads by the ends
- neighbour_data::FacingEnd() and TCoupling::ConnectedEnd() give the end of
the other vehicle as VehicleEnd; the fields stay numbers, as they hold -1
and 2 for "none" in places
The walks along the consist (FirstFind, Neighbour, the AI's coupling and
uncoupling) still carry the ends as numbers; where one of them meets a typed
end, NumberOf() and EndOf() say so, and keep the number as it was.
Kept as it was, and worth a look: TDynamicObject::SetLights() switches the
headlights A/B off by CabActive with the cases end::front and end::rear, that
is CabActive 0 and 1, while CabActive is 1 or -1 for the cabs; the cases are
NumberOf(VehicleEnd::front / rear) now, the same numbers.
No change in behaviour: 1144/1144 tests, golden traces exact against staging
62f7a29b. betterRenderer/, not built, has had only end:: and side:: renamed.
110 lines
3.3 KiB
C++
110 lines
3.3 KiB
C++
/*
|
|
This Source Code Form is subject to the
|
|
terms of the Mozilla Public License, v.
|
|
2.0. If a copy of the MPL was not
|
|
distributed with this file, You can
|
|
obtain one at
|
|
http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
#include "vehicle/enginestart.h"
|
|
|
|
#include "physics/mover.h"
|
|
#include "utilities/utilities.h"
|
|
|
|
namespace engine_start {
|
|
|
|
namespace {
|
|
|
|
// whether the vehicle has an engine the cab can start, the same test the tachometers of the vehicles in multiple make
|
|
bool has_engine(TMoverParameters const &Vehicle) {
|
|
return Vehicle.Power > 0.01;
|
|
}
|
|
|
|
// walks from Start through its coupler Side along the control cable, and returns the Number-th vehicle with an engine
|
|
// other than Skipped it meets; Number is lowered by the ones it met when it doesn't get that far
|
|
TMoverParameters *find_along(TMoverParameters const &Start, int const Side, TMoverParameters const &Skipped, int &Number) {
|
|
auto const *vehicle{&Start};
|
|
auto side{Side};
|
|
// a train can't loop back on itself, the limit only guards against a broken chain of couplers
|
|
for (auto steps = 0; steps < 1000; ++steps) {
|
|
auto const &coupler{vehicle->Couplers[side]};
|
|
if (coupler.Connected == nullptr || false == coupler.CouplingFlag.HasAll(Coupling::control)) {
|
|
return nullptr;
|
|
}
|
|
// onwards through the other end of the next vehicle, whichever way round it stands
|
|
side = 1 - coupler.ConnectedNr;
|
|
vehicle = coupler.Connected;
|
|
if (vehicle == &Skipped || false == has_engine(*vehicle)) {
|
|
continue;
|
|
}
|
|
--Number;
|
|
if (Number == 0) {
|
|
return coupler.Connected;
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
TMoverParameters *engine(TMoverParameters const &Occupied, TMoverParameters &Controlled, int Number) {
|
|
if (Number < 1) {
|
|
return nullptr;
|
|
}
|
|
if (Number == 1) {
|
|
return &Controlled;
|
|
}
|
|
// the cab's own vehicle is the first one
|
|
auto others{Number - 1};
|
|
// behind the cab is the rear end of a vehicle driven from its front cab, and the other way round
|
|
int const behind{NumberOf(Occupied.CabOccupied < 0 ? VehicleEnd::front : VehicleEnd::rear)};
|
|
if (auto *found{find_along(Occupied, behind, Controlled, others)}; found != nullptr) {
|
|
return found;
|
|
}
|
|
return find_along(Occupied, 1 - behind, Controlled, others);
|
|
}
|
|
|
|
void remote_switch::update(TMoverParameters *Engine, bool const Closeheld, bool const Openheld, double const Deltatime, bool const Closesonrelease) {
|
|
if (Engine != m_engine) {
|
|
// another vehicle under the switch, after a change in the train
|
|
m_engine = Engine;
|
|
m_heldtime = 0.0;
|
|
m_ready = false;
|
|
}
|
|
if (Engine == nullptr) {
|
|
return;
|
|
}
|
|
if (Openheld || is_running(*Engine)) {
|
|
// the switch opening the circuit is held down, or there's nothing left to start
|
|
m_heldtime = 0.0;
|
|
m_ready = false;
|
|
return;
|
|
}
|
|
if (Closeheld && Engine->MainSwitchCheck()) {
|
|
m_heldtime += Deltatime;
|
|
}
|
|
if (m_heldtime > Engine->InitialCtrlDelay) {
|
|
m_ready = true;
|
|
}
|
|
if (m_ready && false == (Closesonrelease && Closeheld)) {
|
|
Engine->MainSwitch(true, range_t::local);
|
|
m_ready = false;
|
|
m_heldtime = 0.0;
|
|
}
|
|
if (false == Closeheld) {
|
|
m_heldtime = 0.0;
|
|
}
|
|
}
|
|
|
|
bool remote_switch::open(TMoverParameters &Engine) {
|
|
return Engine.MainSwitch(false, range_t::local);
|
|
}
|
|
|
|
bool remote_switch::is_running(TMoverParameters const &Engine) {
|
|
return Engine.Mains || Engine.diesel.startupRequested;
|
|
}
|
|
|
|
} // namespace engine_start
|