mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 23:17:56 +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.
231 lines
6.3 KiB
C++
231 lines
6.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/.
|
|
*/
|
|
/*
|
|
MaSzyna EU07 locomotive simulator
|
|
Copyright (C) 2001-2004 Marcin Wozniak, Maciej Czapkiewicz and others
|
|
|
|
*/
|
|
|
|
// the commands of the couplings and the departure
|
|
|
|
#include "stdafx.h"
|
|
#include "vehicle/Train.h"
|
|
#include "vehicle/horn.h"
|
|
#include "vehicle/linebreaker.h"
|
|
#include "vehicle/holdcoillever.h"
|
|
#include "vehicle/compartmentlightsswitch.h"
|
|
#include "vehicle/odometer.h"
|
|
#include "vehicle/mainctrlact.h"
|
|
#include "utilities/Globals.h"
|
|
#include "simulation/simulation.h"
|
|
#include "simulation/blackboxrecorder.h"
|
|
#include "world/Event.h"
|
|
#include "simulation/simulationtime.h"
|
|
#include "vehicle/Camera.h"
|
|
#include "utilities/Logs.h"
|
|
#include "model/MdlMngr.h"
|
|
#include "model/Model3d.h"
|
|
#include "utilities/Timer.h"
|
|
#include "vehicle/Driver.h"
|
|
#include "vehicle/DynObj.h"
|
|
#include "world/mtable.h"
|
|
#include "Console.h"
|
|
#include "application/application.h"
|
|
#include "rendering/renderer.h"
|
|
#include "physics/mover.h"
|
|
#include <future>
|
|
#include <thread>
|
|
#include <cmath>
|
|
#include <algorithm>
|
|
#include <format>
|
|
#include "vehicle/cab/internal.h"
|
|
|
|
|
|
void TTrain::OnCommand_nearestcarcouplingincrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (true == Command.freefly && Command.action == GLFW_PRESS)
|
|
{
|
|
// tryb freefly, press only
|
|
auto couplerindex{-1};
|
|
auto *vehicle{Train->DynamicObject->ABuScanNearestObject(Command.location, Train->DynamicObject->GetTrack(), 1, 1500, couplerindex)};
|
|
if (vehicle == nullptr)
|
|
vehicle = Train->DynamicObject->ABuScanNearestObject(Command.location, Train->DynamicObject->GetTrack(), -1, 1500, couplerindex);
|
|
|
|
if (couplerindex != -1 && vehicle != nullptr)
|
|
{
|
|
|
|
vehicle->couple(EndOf(couplerindex));
|
|
}
|
|
if (Train->DynamicObject->Mechanik)
|
|
{
|
|
// aktualizacja flag kierunku w składzie
|
|
Train->DynamicObject->Mechanik->CheckVehicles(DriverOrder::connect);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_nearestcarcouplingdisconnect(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (true == Command.freefly && Command.action == GLFW_PRESS)
|
|
{
|
|
// tryb freefly, press only
|
|
auto couplerindex{-1};
|
|
auto *vehicle{Train->DynamicObject->ABuScanNearestObject(Command.location, Train->DynamicObject->GetTrack(), 1, 1500, couplerindex)};
|
|
if (vehicle == nullptr)
|
|
vehicle = Train->DynamicObject->ABuScanNearestObject(Command.location, Train->DynamicObject->GetTrack(), -1, 1500, couplerindex);
|
|
|
|
if (couplerindex != -1 && vehicle != nullptr)
|
|
{
|
|
|
|
vehicle->uncouple(EndOf(couplerindex));
|
|
}
|
|
if (Train->DynamicObject->Mechanik)
|
|
{
|
|
// aktualizacja flag kierunku w składzie
|
|
Train->DynamicObject->Mechanik->CheckVehicles(DriverOrder::disconnect);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_nearestcarcoupleradapterattach(TTrain * /*Train*/, command_data const &Command)
|
|
{
|
|
|
|
if (true == Command.freefly && Command.action == GLFW_PRESS)
|
|
{
|
|
// tryb freefly, press only
|
|
auto *vehicle{std::get<TDynamicObject *>(simulation::Region->find_vehicle(Command.location, 50, false, true))};
|
|
if (vehicle == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
auto const couplerindex =
|
|
glm::length2(glm::vec3{vehicle->CouplerPosition(VehicleEnd::front)} - Command.location) < glm::length2(glm::vec3{vehicle->CouplerPosition(VehicleEnd::rear)} - Command.location) ? VehicleEnd::front : VehicleEnd::rear;
|
|
|
|
vehicle->attach_coupler_adapter(couplerindex);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_nearestcarcoupleradapterremove(TTrain * /*Train*/, command_data const &Command)
|
|
{
|
|
|
|
if (true == Command.freefly && Command.action == GLFW_PRESS)
|
|
{
|
|
// tryb freefly, press only
|
|
auto *vehicle{std::get<TDynamicObject *>(simulation::Region->find_vehicle(Command.location, 50, false, true))};
|
|
if (vehicle == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
auto const couplerindex =
|
|
glm::length2(glm::vec3{vehicle->CouplerPosition(VehicleEnd::front)} - Command.location) < glm::length2(glm::vec3{vehicle->CouplerPosition(VehicleEnd::rear)} - Command.location) ? VehicleEnd::front : VehicleEnd::rear;
|
|
|
|
vehicle->remove_coupler_adapter(couplerindex);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_occupiedcarcouplingdisconnect(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
// if( false == Train->m_controlmapper.contains( "couplingdisconnect_sw:" ) ) { return; }
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->m_couplingdisconnect = true;
|
|
|
|
if (Train->iCabn == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->DynamicObject)
|
|
{
|
|
Train->DynamicObject->uncouple(Train->cab_to_end());
|
|
if (Train->DynamicObject->Mechanik)
|
|
{
|
|
// aktualizacja flag kierunku w składzie
|
|
Train->DynamicObject->Mechanik->CheckVehicles(DriverOrder::disconnect);
|
|
}
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->m_couplingdisconnect = false;
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_occupiedcarcouplingdisconnectback(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
// if( false == Train->m_controlmapper.contains( "couplingdisconnect_sw:" ) ) { return; }
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->m_couplingdisconnectback = true;
|
|
|
|
if (Train->iCabn == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->DynamicObject)
|
|
{
|
|
Train->DynamicObject->uncouple(Opposite(Train->cab_to_end()));
|
|
if (Train->DynamicObject->Mechanik)
|
|
{
|
|
// aktualizacja flag kierunku w składzie
|
|
Train->DynamicObject->Mechanik->CheckVehicles(DriverOrder::disconnect);
|
|
}
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->m_couplingdisconnectback = false;
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_departureannounce(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->ggDepartureSignalButton.SubModel == nullptr)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
WriteLog("Departure Signal button is missing, or wasn't defined");
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the sound can loop uninterrupted
|
|
if (false == Train->mvOccupied->DepartureSignal)
|
|
{
|
|
// turn on
|
|
Train->mvOccupied->signal_departure(true);
|
|
// visual feedback
|
|
Train->ggDepartureSignalButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// turn off
|
|
Train->mvOccupied->signal_departure(false);
|
|
// visual feedback
|
|
Train->ggDepartureSignalButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|