mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-27 21:45:16 +01:00
* feat(physics): the motion of a derailed vehicle on the ground With physics.derailment new a vehicle off the rails gets a motion of its own on the ground (vehicle/derailmotion.h, in eu07_core): it runs on along its heading, turned out of the curve by the sideways speed it left the rail with, slides across it down slopes steeper than the friction holds, follows the height and the slope of the ground under its supports, and tips over about the wheels of one side (while still guided by the curve, or on a slope, or sliding sideways) until it lies on its side. The vehicle holds the motion and what derailed it (the cause, the lateral acceleration out of the curve, the side a coupling pulled it to). While the motion runs, its friction (0.1 tipping on the outer wheels, 0.3 upright, up to 0.5 on its side) and the grade under it go into the longitudinal force. Off the end of the track the vehicle now slides on with the friction of the ballast instead of stopping within g, and a coupling can pull a vehicle off the rails (pull_off). Nothing of it with physics.derailment monitor, old or off. * feat(physics): a derailed vehicle leaves the track in the scenery TDynamicObject begins the motion of vehicle/derailmotion.h once its vehicle derails with physics.derailment new, and from then on places the model by it: off the axis of the track, pitched and rolled by the ground, on its side once it falls over, the bogies straight under the body. The ground is the scenery's terrain around the place (its opaque shapes and the heightmap terrain), with the ballast bed of the track over it; level ground at the top of the ballast where the scenery has none. The axles keep going along the track by the projection of the move, so the vehicle stays on the track nearest to it for its neighbours, the events and the drawing. A coupled vehicle still on the rails is pulled off when the sideways part of the coupler force puts its leading wheel over the climbing limit over 2 m. An uncoupled vehicle on the track and one off it run into each other only when in line. The derail sound loops while the vehicle scrapes along, and the log tells where it is every second and where it came to rest. Move() is split into move_axles() and place_by_axles(), the code of both unchanged. * feat(blackbox): a vehicle leaving the track and coming to rest off it A new record of the black box, 0x38 derailment, written when a vehicle leaves the track (physics.derailment new) and when it comes to rest off it: what derailed it, its position, heading, speed, offset from the axis of the track, roll, the distance it went and whether it lies on its side (blackbox_doc.md). The scenario runner reads it with the leaves_track check, and seven cases run it on td.scn: an EU07 with coaches into the buckled curve at 46 km/h (the AI) and at 133 km/h, over the overturning speed of the R 600 m curve at 190 km/h, off the end of a track, and overturning at 150 km/h on a curve of R 300 m on level ground, on an embankment and in a cutting. The runner also drops the cached geometry of a case's scenery (.sbt) once the case's fragment is newer than it, as it did for the base scenery: the curve cases carry their own terrain. * feat(physics): the yaw of a derailed body, and what differs between vehicles The body off the track (physics.derailment new) now turns about its vertical axis by itself, apart from the way it travels. Its heading is the way the vehicle goes, along which the Mover's speed runs; its axis is the way its front faces, with a yaw rate and the inertia of a box of its length and width. The friction of the ground holds it: under the two ends of its base while upright, along all of its length on its side, 0.3 to 0.5 along the body and 0.5 across it, each point against the way it slides there. Turning resists the yaw; a body going askew slides harder (mu along cos^2 + mu across sin^2 of the slip, which the Mover takes), its heading is drawn to the body and the sideways scrubbing trips it over. At a standstill it doesn't turn while the friction holds. The forces of the couplings at its ends turn it: two ends meet along the bisector of the bend between the bodies, the push goes through the inner buffer of the bend, off the middle of the beam by up to half the buffer spacing, as far as the buffers meet in height (a derailed body is lower than one on the rails, a rolled one misses them) and as much as a buffer takes (1 MN). Pushed from behind past what the buffers hold, a train of bodies bends further at each joint, the next one the other way: the zigzag of a train folding up. The gap of two ends is taken where they are, not from the distance between the middles, which would press the buffers of every bent pair. Past a right angle the heading turns about with the speed, so the Mover's front stays the body's front. Each vehicle draws its own scatter from the seed of the run and its name: the departure angle +-0.01 rad, yaw +-0.02 rad and +-0.02 rad/s, the friction under each half of it 0.85..1.15, and in two vehicles of three its leading end digging in 0.2..1.5 s after it left the rails, for 0.3..0.8 s, two to four times the friction under that half at one wheel or corner. The same seed gives the same outcome. * feat(physics): a derailed train folds up, and the derailment watches its own cost TDynamicObject gives the body off the track the forces of its couplings as vectors: the gap of a coupling with a vehicle off the track (coupled or meeting it) is that of the two ends as they are, and the force of each end goes to the body at the buffer it pushes through, or towards the other beam it is pulled to. A vehicle still on the rails coupled to one off it is taken off by the part of that force across its axis on its leading wheels (Y/Q over 1.2 over 2 m), pushed by the buffers as well as pulled by the coupling, to the side the force goes. Each vehicle off the track draws its scatter from the seed of the run and its name, and the model and the coupling points follow the yaw of the body. What a derailment costs is watched: the terrain is gathered again at most once a second per vehicle and kept to the nearest 400 000 triangles, the axles of a vehicle off the track follow it along the track by 10 cm steps (a body rocking in place moved them to and fro over the ends of tracks, firing their events every frame), and the gathering, a frame of the motion and the whole update of a vehicle off the track write a warning to the log when they take over 20 ms. The scenario runner gets the consist_folds check: the headings of a train's vehicles at rest off the track differ by a given angle at a given number of joints, optionally alternating, optionally on both sides of the track. eu07_td_off_track_buckle_fast checks the folding, eu07_td_off_track_buckle the coupled coach pulled off at an angle to the locomotive, and the bounds of the other cases are narrowed to the new outcomes. * feat(physics): derailed bodies run into each other instead of through With physics.derailment new the bodies of the vehicles off the track no longer go into each other, nor into the vehicles near them: once a frame, before the vehicles update, every vehicle off the track is checked against those around it (its own train coupled or not, a vehicle still on the rails, another train), by bounding circles and then by the footprints of their bodies: the box of each, less its buffers, rolled and pitched as it lies, seen from above, with the height it reaches. Two footprints in each other are separated along the axis they overlap least across. A hit is an impulse at the point of contact, which takes away the speed the two close in with there (they part with a fifth of it) with the mass, the vertical inertia and the arm of each, and the friction of their sides sliding along each other (0.3). It goes into the velocity and the yaw rate of a body off the track, which then goes the way it is thrown, and into the speed of a vehicle on the rails along them; across the rails it pushes on the leading wheels of that vehicle, which is pushed off when the Y/Q passes 1.2 over 2 m of sliding, or three times that at once. What the bodies still overlap by is taken out by moving them apart. The buffers of two ends keep meeting through meet() and force_on(); the bodies, shorter by the buffers, touch only once the ends are pressed past them or folded corner to corner. The log has the most any two bodies overlapped by every second, and the runner checks it with no_overlap in all off-track cases: before this the coaches went up to 1.64 m into each other at 190 km/h and 0.68 m stayed in each other at rest at 133 km/h; now at most 0.10 m on the way and none at rest. * fix(sonar): the reliability and security issues of the derailment SonarCloud failed the quality gate of the pull request on the new reliability and security ratings: - cpp:S836 (dereference of an undefined pointer value) in the timing watch of TDynamicObject::Update: the analyser lost the reference held in a std::optional. The watch is now always made, with a null vehicle when it is on the track, and does nothing then; copying it is deleted. Only the timing of the update off the track and its warning use it, the physics is the same. - cpp:S2245 (pseudorandom number generator) on the std::mt19937 of draw_scatter: it is seeded on purpose so that a derailment repeats, and nothing secret is drawn; marked NOSONAR like the seeded generators of the editor self tests. - cpp:S2193 (a for loop counter of floating type) in three loops of tests/unit/test_derail_motion.cpp: they count integer steps now. * fix(physics): the scraping of a derailed vehicle stops when it is put back on the rails The derail: sound loops while a vehicle off the track slides, and it was stopped only while the vehicle was still off the track, once it came to rest. rerail() (resetconsist, SetDamage taking dtrain_out off) ends the motion off the track at once, also while the vehicle still slides, and the scraping then went on for good. The vehicle now remembers that it plays the loop and stops it as soon as it isn't sliding off the track any more, at rest or back on the rails. The one-shot derail: sound of the other derailment models is not touched. * fix(physics): a vehicle put back on the rails forgets what derailed it rerail() reset only the side a coupling pulled the vehicle off to, and kept the cause and the lateral acceleration of the derailment. A vehicle that is put back on the rails and later leaves them in a way which doesn't set those (as the fork derailment of #496 does now) would leave the track with the cause and the acceleration of the earlier derailment. rerail() resets both now; the unit tests check it after repair_damage(). * fix(physics): the neighbour scan goes on past a derailed vehicle beside the line update_neighbours() took the nearest vehicle the scan of the track found, and when one of the two was off the track and the other not in line with it, gave up on that end. A vehicle lying beside the line so hid the vehicles beyond it: in a pile-up a wagon still on the rails had no front neighbour while running into a wagon in line further on, until the bodies were already deep in each other. The scan now passes such a vehicle and goes on to the next one (ABuFindObject() with InLine, only from update_neighbours(); the obstacle scan of the AI is as it was). * fix(physics): the moves out of other bodies go into the axles of a derailed vehicle The axles of a vehicle off the track follow it along the track by the displacement of the body, which move_off_track() measured from where the body was at the start of its own step. The contacts of the bodies move it out of the others between the frames, after that, so those moves never reached the axles, and the axles drifted along the track away from the body (the track it is registered on, the events it fires). The displacement is now measured from where the body was when its move went into the axles last. * perf(physics): derailed vehicles share the terrain and let it go at rest Each vehicle off the track gathered its own copy of the terrain, up to 600 m around it and 400 000 triangles (some 30-50 MB with the cell index), and kept it until the scenery unloaded: not let go at rest nor when put back on the rails, and gathered again for every vehicle of a pile-up, with a stall of tens of ms each. - The terrain gathered for a vehicle is kept in vehicle_table as a weak reference. A vehicle leaving the track (or gathering again near the edge) takes one which covers the way it may slide - around it and around where it stops going straight on, by its length and the margin the terrain is gathered again at - instead of gathering its own. A terrain cut down to the nearest triangles of a dense scenery is not shared. - At rest a vehicle keeps only the triangles under it (half its length and 40 m around, mesh_ground::cropped()); the big terrain goes once no vehicle holds it. Moving again, it gathers the terrain anew as before. - Back on the rails (rerail()) the vehicle lets its terrain go. The ground under a vehicle is the same as before: a shared terrain holds every triangle of the scenery reaching into its area. Unit tests: mesh_ground::covers() of an area and cropped().
1088 lines
55 KiB
C++
1088 lines
55 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/.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
#include <functional>
|
|
|
|
#include "utilities/Classes.h"
|
|
#include "interfaces/IMaterial.h"
|
|
#include "MOVER.h"
|
|
#include "world/TrkFoll.h"
|
|
#include "vehicle/Button.h"
|
|
#include "vehicle/AirCoupler.h"
|
|
#include "interfaces/ITexture.h"
|
|
#include "audio/sound.h"
|
|
#include "world/Spring.h"
|
|
#include "vehicle/mirrors.h"
|
|
#include "vehicle/doorwings.h"
|
|
#include "scripting/scriptscreenrules.h"
|
|
|
|
#include <array>
|
|
#include <vector>
|
|
#include <memory>
|
|
|
|
class script_screen; // scripting/scriptscreens.h
|
|
enum class script_language; // scripting/scriptscreens.h
|
|
|
|
#define EU07_SOUND_BOGIESOUNDS
|
|
|
|
//---------------------------------------------------------------------------
|
|
//---------------------------------------------------------------------------
|
|
//---------------------------------------------------------------------------
|
|
int const ANIM_WHEELS = 0; // koła
|
|
int const ANIM_DOORS = 1; // drzwi
|
|
int const ANIM_LEVERS = 2; // elementy obracane (wycieraczki, koła skrętne, przestawiacze, klocki ham.)
|
|
int const ANIM_BUFFERS = 3; // elementy przesuwane (zderzaki)
|
|
int const ANIM_BOOGIES = 4; // wózki (są skręcane w dwóch osiach)
|
|
int const ANIM_PANTS = 5; // pantografy
|
|
int const ANIM_STEAMS = 6; // napęd parowozu
|
|
int const ANIM_DOORSTEPS = 7;
|
|
int const ANIM_MIRRORS = 8;
|
|
int const ANIM_WIPERS = 9;
|
|
int const ANIM_TYPES = 10; // Ra: ilość typów animacji
|
|
|
|
class TAnim;
|
|
//typedef void(__closure *TUpdate)(TAnim *pAnim); // typ funkcji aktualizującej położenie submodeli
|
|
typedef std::function<void(TAnim *)> TUpdate; // __closure is Borland-specific extension
|
|
|
|
// McZapkie-250202
|
|
int const MaxAxles = 16; // ABu 280105: zmienione z 8 na 16
|
|
// const MaxAnimatedAxles=16; //i to tez.
|
|
// const MaxAnimatedDoors=16; //NBMX wrzesien 2003
|
|
/*
|
|
Ra: Utworzyć klasę wyposażenia opcjonalnego, z której będą dziedziczyć klasy drzwi,
|
|
pantografów, napędu parowozu i innych ruchomych części pojazdów. Klasy powinny być
|
|
pseudo-wirtualne, bo wirtualne mogą obniżać wydajnosść.
|
|
Przy wczytywaniu MMD utworzyć tabelę wskaźnikow na te dodatki. Przy wyświetlaniu
|
|
pojazdu wykonywać Update() na kolejnych obiektach wyposażenia.
|
|
Rozważyć użycie oddzielnych modeli dla niektórych pojazdów (np. lokomotywy), co
|
|
zaoszczędziło by czas ustawiania animacji na modelu wspólnym dla kilku pojazdów,
|
|
szczególnie dla pojazdów w danej chwili nieruchomych (przy dużym zagęszczeniu
|
|
modeli na stacjach na ogół przewaga jest tych nieruchomych).
|
|
*/
|
|
class TAnimValveGear
|
|
{ // współczynniki do animacji parowozu (wartości przykładowe dla Pt47)
|
|
int iValues; // ilość liczb (wersja):
|
|
float fKorbowodR; // długość korby (pół skoku tłoka) [m]: 0.35
|
|
float fKorbowodL; // długość korbowodu [m]: 3.8
|
|
float fDrazekR; // promień mimośrodu (drążka) [m]: 0.18
|
|
float fDrazekL; // dł. drążka mimośrodowego [m]: 2.55889
|
|
float fJarzmoV; // wysokość w pionie osi jarzma od osi koła [m]: 0.751
|
|
float fJarzmoH; // odległość w poziomie osi jarzma od osi koła [m]: 2.550
|
|
float fJarzmoR; // promień jarzma do styku z drążkiem [m]: 0.450
|
|
float fJarzmoA; // kąt mimośrodu względem kąta koła [°]: -96.77416667
|
|
float fWdzidloL; // długość wodzidła [m]: 2.0
|
|
float fWahaczH; // długość wahacza (góra) [m]: 0.14
|
|
float fSuwakH; // wysokość osi suwaka ponad osią koła [m]: 0.62
|
|
float fWahaczL; // długość wahacza (dół) [m]: 0.84
|
|
float fLacznikL; // długość łącznika wahacza [m]: 0.75072
|
|
float fRamieL; // odległość ramienia krzyżulca od osi koła [m]: 0.192
|
|
float fSuwakL; // odległość środka tłoka/suwaka od osi koła [m]: 5.650
|
|
// dołożyć parametry drążka nastawnicy
|
|
// albo nawet zrobić dynamiczną tablicę float[] i w nią pakować wszelkie współczynniki, potem
|
|
// używać indeksów
|
|
// współczynniki mogą być wspólne dla 2-4 tłoków, albo każdy tłok może mieć odrębne
|
|
};
|
|
|
|
class TAnimPant
|
|
{ // współczynniki do animacji pantografu
|
|
public:
|
|
glm::dvec3 vPos; // Ra: współrzędne punktu zerowego pantografu (X dodatnie dla przedniego)
|
|
double fLenL1; // długość dolnego ramienia 1, odczytana z modelu
|
|
double fLenU1; // długość górnego ramienia 1, odczytana z modelu
|
|
double fLenL2; // długość dolnego ramienia 2, odczytana z modelu
|
|
double fLenU2; // długość górnego ramienia 2, odczytana z modelu
|
|
double fHoriz; // przesunięcie ślizgu w długości pojazdu względem osi obrotu dolnego ramienia
|
|
double fHeight; // wysokość ślizgu ponad oś obrotu, odejmowana od wysokości drutu
|
|
double fWidth; // połowa szerokości roboczej ślizgu, do wykrycia ześlizgnięcia się drutu
|
|
double fAngleL0; // Ra: początkowy kąt dolnego ramienia (odejmowany przy animacji)
|
|
double fAngleU0; // Ra: początkowy kąt górnego ramienia (odejmowany przy animacji)
|
|
double PantTraction; // Winger 170204: wysokość drutu ponad punktem na wysokości vPos.y p.g.s.
|
|
double PantWys; // Ra: aktualna wysokość uniesienia ślizgu do porównania z wysokością drutu
|
|
double fAngleL; // Winger 160204: aktualny kąt ramienia dolnego
|
|
double fAngleU; // Ra: aktualny kąt ramienia górnego
|
|
double NoVoltTime; // czas od utraty kontaktu z drutem
|
|
TTraction *hvPowerWire; // aktualnie podczepione druty, na razie tu
|
|
float fWidthExtra; // dodatkowy rozmiar poziomy poza część roboczą (fWidth)
|
|
float fHeightExtra[5]; //łamana symulująca kształt nabieżnika
|
|
// double fHorizontal; //Ra 2015-01: położenie drutu względem osi pantografu
|
|
|
|
// factory ktore mozna nadpisac z fiza
|
|
float rd1rf{1.f}; // mnoznik obrotu ramienia dolnego 1
|
|
float rd2rf{1.f}; // mnoznik obrotu ramienia dolnego 2
|
|
float rg1rf{1.f}; // mnoznik obrotu ramienia gornego 1
|
|
float rg2rf{1.f}; // mnoznik obrotu ramienia gornego 2
|
|
float slizgrf{1.f}; // mnoznik obrotu slizgacza
|
|
void common_pantograph_settings();
|
|
void AKP_4E();
|
|
void WBL85();
|
|
void DSAx();
|
|
void EC160_200();
|
|
};
|
|
|
|
class TAnim
|
|
{ // klasa animowanej części pojazdu (koła, drzwi, pantografy, burty, napęd parowozu, siłowniki
|
|
// itd.)
|
|
public:
|
|
// constructor
|
|
TAnim() = default;
|
|
// destructor
|
|
~TAnim();
|
|
// methods
|
|
int TypeSet(int i, TMoverParameters currentMover, int fl = 0); // ustawienie typu
|
|
// members
|
|
union
|
|
{
|
|
TSubModel *smAnimated; // animowany submodel (jeśli tylko jeden, np. oś)
|
|
TSubModel **smElement; // jeśli animowanych elementów jest więcej (pantograf, napęd
|
|
// parowozu)
|
|
int iShift; // przesunięcie przed przydzieleniem wskaźnika
|
|
};
|
|
union
|
|
{ // parametry animacji
|
|
TAnimValveGear *pValveGear; // współczynniki do animacji parowozu
|
|
int dWheelAngle; // wskaźnik na kąt obrotu osi
|
|
float *fParam; // różne parametry dla animacji
|
|
TAnimPant *fParamPants; // różne parametry dla animacji
|
|
};
|
|
union
|
|
{ // wskaźnik na obiekt odniesienia
|
|
double *fDoubleBase; // jakiś double w fizyce
|
|
float *fFloatBase; // jakiś float w fizyce
|
|
int *iIntBase; // jakiś int w fizyce
|
|
};
|
|
// void _fastcall Update(); //wskaźnik do funkcji aktualizacji animacji
|
|
int iFlags{ 0 }; // flagi animacji
|
|
float fMaxDist; // do jakiej odległości wykonywana jest animacja NOTE: square of actual distance
|
|
float fSpeed; // parametr szybkości animacji
|
|
int iNumber; // numer kolejny obiektu
|
|
// door wings only: the submodel of the same name in the low poly interior, if it has one, posed along with
|
|
// smAnimated, so the inside of the door can be part of the interior and lit with it
|
|
TSubModel *smInterior { nullptr };
|
|
|
|
TUpdate yUpdate; // metoda TDynamicObject aktualizująca animację
|
|
/*
|
|
void Parovoz(); // wykonanie obliczeń animacji
|
|
*/
|
|
};
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
enum class announcement_t : int {
|
|
idle = 0,
|
|
approaching,
|
|
current,
|
|
next,
|
|
destination,
|
|
chime,
|
|
end
|
|
};
|
|
|
|
// parameters for the material object, as currently used by various simulator models
|
|
struct material_data {
|
|
|
|
int textures_alpha{ 0x30300030 }; // maska przezroczystości tekstur. default: tekstury wymienne nie mają przezroczystości
|
|
material_handle replacable_skins[ 5 ] = { null_handle, null_handle, null_handle, null_handle, null_handle }; // McZapkie:zmienialne nadwozie
|
|
int multi_textures{ 0 }; //<0 tekstury wskazane wpisem, >0 tekstury z przecinkami, =0 jedna
|
|
|
|
// assigns specified texture or a group of textures to replacable texture slots
|
|
void assign( std::string const &Replacableskin );
|
|
};
|
|
|
|
class TDynamicObject { // klasa pojazdu
|
|
|
|
friend opengl_renderer;
|
|
friend opengl33_renderer;
|
|
friend class vehicle_table;
|
|
|
|
public:
|
|
static bool bDynamicRemove; // moved from ground
|
|
|
|
//private: // położenie pojazdu w świecie oraz parametry ruchu
|
|
glm::dvec3 vPosition; // Ra: pozycja pojazdu liczona zaraz po przesunięciu
|
|
glm::dvec3 vCoulpler[2]; // współrzędne sprzęgów do liczenia zderzeń czołowych
|
|
glm::dvec3 vUp, vFront, vLeft; // wektory jednostkowe ustawienia pojazdu
|
|
int iDirection; // kierunek pojazdu względem czoła składu (1=zgodny,0=przeciwny)
|
|
TTrackShape ts; // parametry toru przekazywane do fizyki
|
|
TTrackParam tp; // parametry toru przekazywane do fizyki
|
|
TTrackFollower Axle0; // oś z przodu (od sprzęgu 0)
|
|
TTrackFollower Axle1; // oś z tyłu (od sprzęgu 1)
|
|
int iAxleFirst; // numer pierwszej osi w kierunku ruchu (oś wiążąca pojazd z torem i wyzwalająca eventy)
|
|
float fAxleDist; // rozstaw wózków albo osi do liczenia proporcji zacienienia
|
|
glm::vec3 modelRot; // obrot pudła względem świata - do przeanalizowania, czy potrzebne!!!
|
|
TDynamicObject * ABuFindNearestObject(glm::vec3 pos, TTrack *Track, TDynamicObject *MyPointer, int &CouplNr );
|
|
|
|
glm::dvec3 m_future_movement;
|
|
glm::dvec3 m_future_wheels_angle;
|
|
|
|
public:
|
|
// parametry położenia pojazdu dostępne publicznie
|
|
std::string asTrack; // nazwa toru początkowego; wywalić?
|
|
std::string asDestination; // dokąd pojazd ma być kierowany "(stacja):(tor)"
|
|
glm::dmat4 mMatrix; // macierz przekształcenia do renderowania modeli
|
|
TMoverParameters *MoverParameters; // parametry fizyki ruchu oraz przeliczanie
|
|
inline TDynamicObject *NextConnected() { return MoverParameters->Neighbours[ end::rear ].vehicle; }; // pojazd podłączony od strony sprzęgu 1 (kabina -1)
|
|
inline TDynamicObject *PrevConnected() { return MoverParameters->Neighbours[ end::front ].vehicle; }; // pojazd podłączony od strony sprzęgu 0 (kabina 1)
|
|
inline TDynamicObject *NextConnected() const { return MoverParameters->Neighbours[ end::rear ].vehicle; }; // pojazd podłączony od strony sprzęgu 1 (kabina -1)
|
|
inline TDynamicObject *PrevConnected() const { return MoverParameters->Neighbours[ end::front ].vehicle; }; // pojazd podłączony od strony sprzęgu 0 (kabina 1)
|
|
inline int NextConnectedNo() const { return MoverParameters->Neighbours[ end::rear ].vehicle_end; }
|
|
inline int PrevConnectedNo() const { return MoverParameters->Neighbours[ end::front ].vehicle_end; }
|
|
|
|
// Dev tools
|
|
void Reload();
|
|
|
|
// double fTrackBlock; // odległość do przeszkody do dalszego ruchu (wykrywanie kolizji z innym pojazdem)
|
|
|
|
// modele składowe pojazdu
|
|
TModel3d *mdModel; // model pudła
|
|
TModel3d *mdLoad; // model zmiennego ładunku
|
|
TModel3d *mdKabina; // model kabiny dla użytkownika; McZapkie-030303: to z train.h
|
|
TModel3d *mdLowPolyInt; // ABu 010305: wnetrze lowpoly
|
|
std::array<TSubModel *, 3> LowPolyIntCabs {}; // pointers to low fidelity version of individual driver cabs
|
|
bool JointCabs{ false }; // flag for vehicles with multiple virtual 'cabs' sharing location and 3d model(s)
|
|
std::vector<TModel3d *> mdAttachments; // additional models attached to main body
|
|
struct destination_data {
|
|
TSubModel *sign { nullptr }; // submodel mapped with replacable texture -4
|
|
bool has_light { false }; // the submodel was originally configured with self-illumination attribute
|
|
material_handle destination { null_handle }; // most recently assigned non-blank destination texture
|
|
material_handle destination_off { null_handle }; // blank destination sign
|
|
std::string background; // potential default background texture override
|
|
std::string script; // potential python script used to generate texture data
|
|
int update_rate { 0 }; // -1: per stop, 0: none, >0: fps // TBD, TODO: implement?
|
|
std::string instancing; // potential method to generate more than one texture per timetable
|
|
std::string parameters; // potential extra parameters supplied by mmd file
|
|
script_screens::screen_config lua; // potential Lua sign (luadestinationsign:), used in place of the python one while the Lua screens are on
|
|
script_screens::screen_config wasm; // potential WebAssembly sign (wasmdestinationsign:), likewise, when there's no Lua one
|
|
std::shared_ptr<script_screen> script_sign; // the script screen drawing the current destination
|
|
std::string script_request; // its input: the key=value pairs a python sign gets for its texture
|
|
std::shared_ptr<script_screen> background_sign; // the script screen which drew the blank sign, when a script draws it
|
|
// methods
|
|
void deserialize( cParser &Input );
|
|
private:
|
|
bool deserialize_mapping( cParser &Input );
|
|
} DestinationSign;
|
|
float fShade; // zacienienie: 0:normalnie, -1:w ciemności, +1:dodatkowe światło (brak koloru?)
|
|
float LoadOffset { 0.f };
|
|
std::unordered_map<std::string, std::string> LoadModelOverrides; // potential overrides of default load visualization models
|
|
glm::vec3 InteriorLight { 0.9f * 255.f / 255.f, 0.9f * 216.f / 255.f, 0.9f * 176.f / 255.f }; // tungsten light. TODO: allow definition of light type?
|
|
float InteriorLightLevel { 0.0f }; // current level of interior lighting
|
|
struct vehicle_section {
|
|
TSubModel *compartment;
|
|
TSubModel *load;
|
|
int load_chunks_visible;
|
|
float light_level;
|
|
};
|
|
std::vector<vehicle_section> Sections; // table of recognized vehicle sections
|
|
bool SectionLightsActive { false }; // flag indicating whether section lights were set.
|
|
std::vector<vehicle_section *> SectionLoadOrder; // helper, activation/deactivation load chunk sequence
|
|
|
|
private:
|
|
// zmienne i metody do animacji submodeli; Ra: sprzatam animacje w pojeździe
|
|
material_data m_materialdata;
|
|
|
|
public:
|
|
inline
|
|
material_data const
|
|
*Material() const {
|
|
return &m_materialdata; }
|
|
// tymczasowo udostępnione do wyszukiwania drutu
|
|
std::array<int, ANIM_TYPES> iAnimType{ 0 }; // 0-osie,1-drzwi,2-obracane,3-zderzaki,4-wózki,5-pantografy,6-tłoki
|
|
private:
|
|
int iAnimations; // liczba obiektów animujących
|
|
std::vector<TAnim> pAnimations;
|
|
TSubModel ** pAnimated; // lista animowanych submodeli (może być ich więcej niż obiektów animujących)
|
|
double dWheelAngle[3]; // kąty obrotu kół: 0=przednie toczne, 1=napędzające i wiązary, 2=tylne toczne
|
|
/*
|
|
void UpdateNone(TAnim *pAnim){}; // animacja pusta (funkcje ustawiania submodeli, gdy blisko kamery)
|
|
*/
|
|
void UpdateAxle(TAnim *pAnim); // animacja osi
|
|
void UpdateDoorTranslate(TAnim *pAnim); // animacja drzwi - przesuw
|
|
void UpdateDoorRotate(TAnim *pAnim); // animacja drzwi - obrót
|
|
void UpdateDoorFold(TAnim *pAnim); // animacja drzwi - składanie
|
|
void UpdateDoorPlug(TAnim *pAnim); // animacja drzwi - odskokowo-przesuwne
|
|
// a wing with its own kind of animation, given in the .mmd (animdoor:), in place of the one of the .fiz
|
|
void UpdateDoorWing( TAnim *pAnim, door_wings::wing_spec const &Spec );
|
|
// sets the update of a door wing animation, for its own kind if the .mmd gives one, otherwise for the .fiz
|
|
void bind_door_animation( TAnim &Animation );
|
|
// door wings animated in their own way, from the .mmd (eu07/maszyna#70)
|
|
std::vector<door_wings::wing_spec> m_doorwings;
|
|
void UpdatePant(TAnim *pAnim); // animacja pantografu
|
|
void UpdatePlatformTranslate(TAnim *pAnim); // doorstep animation, shift
|
|
void UpdatePlatformRotate(TAnim *pAnim); // doorstep animation, rotate
|
|
void UpdateMirror(TAnim *pAnim); // mirror animation
|
|
void UpdateWiper(TAnim *pAnim); // wiper animation
|
|
/*
|
|
void UpdateLeverDouble(TAnim *pAnim); // animacja gałki zależna od double
|
|
void UpdateLeverFloat(TAnim *pAnim); // animacja gałki zależna od float
|
|
void UpdateLeverInt(TAnim *pAnim); // animacja gałki zależna od int (wartość)
|
|
void UpdateLeverEnum(TAnim *pAnim); // animacja gałki zależna od int (lista kątów)
|
|
*/
|
|
void toggle_lights(); // switch light levels for registered interior sections
|
|
private: // Ra: ciąg dalszy animacji, dopiero do ogarnięcia
|
|
// ABuWozki 060504
|
|
glm::vec3 bogieRot[2]; // Obroty wozkow w/m korpusu
|
|
TSubModel *smBogie[2]; // Wyszukiwanie max 2 wozkow
|
|
TSubModel *smWahacze[4]; // wahacze (np. nogi, dźwignia w drezynie)
|
|
TSubModel *smBrakeMode; // Ra 15-01: nastawa hamulca też
|
|
TSubModel *smLoadMode; // Ra 15-01: nastawa próżny/ładowny
|
|
TSubModel *sm_winter_variant {}; // submodel zimowego wariantu
|
|
TSubModel *sm_spring_variant {}; // submodel wiosennego wariantu
|
|
TSubModel *sm_summer_variant {}; // submodel letniego wariantu
|
|
TSubModel *sm_autumn_variant {}; // submodel jesiennego wariantu
|
|
double fWahaczeAmp;
|
|
// levers with a slot, turned by a pin on the coupling rod sliding in the slot (e.g. speedometer drive of 401Da)
|
|
struct slottedlever_data {
|
|
TSubModel *submodel { nullptr }; // lever, turned around its local X axis like the wheels
|
|
int axle { 0 }; // index of the axle animation, whose crank drives the coupling rod
|
|
glm::dvec2 pin { 0.0 }; // pin position relative to the lever axis for wheel angle 0, in local (Y, Z) plane [m]
|
|
glm::dvec2 crank { 0.0 }; // crank vector for wheel angle 0, in local (Y, Z) plane [m]
|
|
};
|
|
std::vector<slottedlever_data> m_slottedlevers;
|
|
static double slottedlever_angle( slottedlever_data const &Lever, double const Wheelangle );
|
|
void update_slottedlevers();
|
|
// Winger 160204 - pantografy
|
|
double pantspeedfactor;
|
|
// animacje typu przesuw
|
|
TSubModel *smBuforLewy[2];
|
|
TSubModel *smBuforPrawy[2];
|
|
TAnimValveGear *pValveGear;
|
|
glm::dvec3 vFloor; // podłoga dla ładunku
|
|
public:
|
|
TAnim *pants; // indeks obiektu animującego dla pantografu 0
|
|
TAnim *wipers; // wycieraczki
|
|
std::vector<double> wiperOutTimer = std::vector<double>(8, 0.0);
|
|
std::vector<double> wiperParkTimer = std::vector<double>(8, 0.0);
|
|
std::vector<int> workingSwitchPos = std::vector<int>(8, 0); // working switch position (to not break wipers when switching modes)
|
|
std::vector<double> dWiperPos; // timing na osi czasu animacji wycieraczki
|
|
std::vector<bool> wiperDirection = std::vector<bool>(8, false); // false - return direction; true - out direction
|
|
std::vector<bool> wiper_playSoundFromStart = std::vector<bool>(8, false);
|
|
std::vector<bool> wiper_playSoundToStart = std::vector<bool>(8, false);
|
|
double NoVoltTime; // czas od utraty zasilania
|
|
double dMirrorMoveL{ 0.0 };
|
|
double dMirrorMoveR{ 0.0 };
|
|
TSubModel *smBrakeSet; // nastawa hamulca (wajcha)
|
|
TSubModel *smLoadSet; // nastawa ładunku (wajcha)
|
|
TSubModel *smWiper; // wycieraczka (poniekąd też wajcha)
|
|
// Ra: koneic animacji do ogarnięcia
|
|
|
|
//private:
|
|
// types
|
|
struct exchange_data {
|
|
float unload_count { 0.f }; // amount to unload
|
|
float load_count { 0.f }; // amount to load
|
|
int platforms { 0 }; // platforms which may take part in the exchange
|
|
float time { 0.f }; // time spent on the operation
|
|
};
|
|
|
|
struct coupleradapter_data {
|
|
glm::vec2 position; // adapter placement; offset from vehicle end and height
|
|
std::string model; // 3d model of the adapter
|
|
};
|
|
|
|
struct coupler_sounds {
|
|
// TBD: change to an array with index-based access for easier initialization?
|
|
sound_source attach_coupler { sound_placement::external };
|
|
sound_source attach_brakehose { sound_placement::external };
|
|
sound_source attach_mainhose { sound_placement::external };
|
|
sound_source attach_control { sound_placement::external };
|
|
sound_source attach_gangway { sound_placement::external };
|
|
sound_source attach_heating { sound_placement::external };
|
|
sound_source detach_coupler { sound_placement::external };
|
|
sound_source detach_brakehose { sound_placement::external };
|
|
sound_source detach_mainhose { sound_placement::external };
|
|
sound_source detach_control { sound_placement::external };
|
|
sound_source detach_gangway { sound_placement::external };
|
|
sound_source detach_heating { sound_placement::external };
|
|
sound_source dsbCouplerStretch { sound_placement::external }; // moved from cab
|
|
sound_source dsbCouplerStretch_loud { sound_placement::external };
|
|
sound_source dsbBufferClamp { sound_placement::external }; // moved from cab
|
|
sound_source dsbBufferClamp_loud { sound_placement::external };
|
|
sound_source dsbAdapterAttach { sound_placement::external };
|
|
sound_source dsbAdapterRemove { sound_placement::external };
|
|
};
|
|
|
|
struct pantograph_sounds {
|
|
// TODO: split pantograph sound into one for contact of arm with the wire, and electric arc sound
|
|
sound_source sPantUp { sound_placement::external };
|
|
sound_source sPantDown { sound_placement::external };
|
|
};
|
|
|
|
struct door_sounds {
|
|
sound_source rsDoorOpen { sound_placement::general }; // Ra: przeniesione z kabiny
|
|
sound_source rsDoorClose { sound_placement::general };
|
|
sound_source lock { sound_placement::general };
|
|
sound_source unlock { sound_placement::general };
|
|
sound_source step_open { sound_placement::general };
|
|
sound_source step_close { sound_placement::general };
|
|
sound_source permit_granted { sound_placement::general };
|
|
side placement {};
|
|
};
|
|
|
|
struct mirror_sounds {
|
|
sound_source unfold { sound_placement::general };
|
|
sound_source fold { sound_placement::general };
|
|
side placement {};
|
|
int end {}; // of the vehicle, the mirror moves with the cab at this end occupied
|
|
};
|
|
|
|
struct exchange_sounds {
|
|
sound_source loading { sound_placement::general };
|
|
sound_source unloading { sound_placement::general };
|
|
};
|
|
|
|
struct axle_sounds {
|
|
double distance; // distance to rail joint
|
|
double offset; // axle offset from centre of the vehicle
|
|
sound_source clatter; // clatter emitter
|
|
bool atjoints { false }; // distance comes from TTrack::rail_phase
|
|
};
|
|
// whether the axle has just passed a rail joint. On a track with dipping joints it goes by them, elsewhere the axle counts a rail off itself
|
|
bool axle_passed_joint( axle_sounds &Axle, double const Move, int const Direction ) const;
|
|
|
|
struct powertrain_sounds {
|
|
sound_source inverter { sound_placement::engine };
|
|
std::vector<sound_source> motorblowers;
|
|
std::vector<sound_source> motors; // generic traction motor sounds
|
|
std::vector<sound_source> acmotors; // inverter-specific traction motor sounds
|
|
// bool dcmotors { true }; // traction dc motor(s)
|
|
double motor_volume { 0.0 }; // MC: pomocnicze zeby gladziej silnik buczal
|
|
float motor_momentum { 0.f }; // recent change in motor revolutions
|
|
sound_source motor_relay { sound_placement::engine };
|
|
sound_source dsbWejscie_na_bezoporow { sound_placement::engine }; // moved from cab
|
|
sound_source motor_parallel { sound_placement::engine }; // moved from cab
|
|
sound_source motor_shuntfield { sound_placement::engine };
|
|
sound_source linebreaker_close { sound_placement::engine };
|
|
sound_source linebreaker_open { sound_placement::engine };
|
|
sound_source rsWentylator { sound_placement::engine }; // McZapkie-030302
|
|
sound_source engine { sound_placement::engine }; // generally diesel engine
|
|
sound_source fake_engine { sound_placement::engine };
|
|
sound_source engine_ignition { sound_placement::engine }; // moved from cab
|
|
sound_source engine_shutdown { sound_placement::engine };
|
|
bool engine_state_last { false }; // helper, cached previous state of the engine
|
|
double engine_volume { 0.0 }; // MC: pomocnicze zeby gladziej silnik buczal
|
|
sound_source engine_revving { sound_placement::engine }; // youBy
|
|
float engine_revs_last { -1.f }; // helper, cached rpm of the engine
|
|
float engine_revs_change { 0.f }; // recent change in engine revolutions
|
|
sound_source engine_turbo { sound_placement::engine };
|
|
double engine_turbo_pitch { 1.0 };
|
|
sound_source oil_pump { sound_placement::engine };
|
|
sound_source fuel_pump { sound_placement::engine };
|
|
sound_source water_pump { sound_placement::engine };
|
|
sound_source water_heater { sound_placement::engine };
|
|
sound_source radiator_fan { sound_placement::engine };
|
|
sound_source radiator_fan_aux { sound_placement::engine };
|
|
sound_source transmission { sound_placement::engine };
|
|
sound_source rsEngageSlippery { sound_placement::engine }; // moved from cab
|
|
sound_source retarder { sound_placement::engine };
|
|
|
|
void position( glm::vec3 const Location );
|
|
void render( TMoverParameters const &Vehicle, double const Deltatime );
|
|
};
|
|
// single source per door (pair) on the centreline
|
|
struct doorspeaker_sounds {
|
|
glm::vec3 offset;
|
|
sound_source departure_signal;
|
|
};
|
|
// single source per vehicle
|
|
struct pasystem_sounds {
|
|
std::array<sound_source, static_cast<int>( announcement_t::end )> announcements;
|
|
std::optional< std::array<float, 6> > soundproofing;
|
|
sound_source announcement;
|
|
std::deque<sound_source> announcement_queue; // fifo queue
|
|
};
|
|
struct springbrake_sounds {
|
|
sound_source activate { sound_placement::external };
|
|
sound_source release { sound_placement::external };
|
|
bool state { false };
|
|
};
|
|
|
|
|
|
// methods
|
|
void ABuLittleUpdate(double ObjSqrDist);
|
|
void ABuBogies();
|
|
void ABuModelRoll();
|
|
void on_season_update();
|
|
void TurnOff();
|
|
// update state of load exchange operation
|
|
void update_exchange( double const Deltatime );
|
|
|
|
// members
|
|
AirCoupler btCoupler1; // sprzegi
|
|
AirCoupler btCoupler2;
|
|
std::array<TModel3d *, 2> m_coupleradapters = { nullptr, nullptr };
|
|
AirCoupler btCPneumatic1; // sprzegi powietrzne //yB - zmienione z Button na AirCoupler - krzyzyki
|
|
AirCoupler btCPneumatic2;
|
|
AirCoupler btCPneumatic1r; // ABu: to zeby nie bylo problemow przy laczeniu wagonow,
|
|
AirCoupler btCPneumatic2r; // jesli beda polaczone sprzegami 1<->1 lub 0<->0
|
|
AirCoupler btPneumatic1; // ABu: sprzegi powietrzne zolte
|
|
AirCoupler btPneumatic2;
|
|
AirCoupler btPneumatic1r; // ABu: analogicznie jak 4 linijki wyzej
|
|
AirCoupler btPneumatic2r;
|
|
|
|
TButton btCCtrl1; // sprzegi sterowania
|
|
TButton btCCtrl2;
|
|
TButton btCPass1; // mostki przejsciowe
|
|
TButton btCPass2;
|
|
char cp1, sp1, cp2, sp2; // ustawienia węży
|
|
|
|
TButton m_endsignal12; // sygnalu konca pociagu
|
|
TButton m_endsignal13;
|
|
TButton m_endsignal22;
|
|
TButton m_endsignal23;
|
|
TButton m_endsignals1; // zeby bylo kompatybilne ze starymi modelami...
|
|
TButton m_endsignals2;
|
|
TButton m_endtab1; // sygnaly konca pociagu (blachy)
|
|
TButton m_endtab2;
|
|
AirCoupler m_headlamp11; // oswietlenie czolowe - przod
|
|
AirCoupler m_headlamp12;
|
|
AirCoupler m_headlamp13;
|
|
AirCoupler m_highbeam12; // dlugie
|
|
AirCoupler m_highbeam13;
|
|
AirCoupler m_headlamp21; // oswietlenie czolowe - tyl
|
|
AirCoupler m_headlamp22;
|
|
AirCoupler m_headlamp23;
|
|
AirCoupler m_highbeam22;
|
|
AirCoupler m_highbeam23;
|
|
AirCoupler m_headsignal12;
|
|
AirCoupler m_headsignal13;
|
|
AirCoupler m_headsignal22;
|
|
AirCoupler m_headsignal23;
|
|
TButton btExteriorOnly;
|
|
TButton btMechanik1;
|
|
TButton btMechanik2;
|
|
TButton btShutters1; // cooling shutters for primary water circuit
|
|
TButton btShutters2; // cooling shutters for auxiliary water circuit
|
|
|
|
double dRailLength { 0.0 };
|
|
std::vector<axle_sounds> m_axlesounds;
|
|
// engine sounds
|
|
powertrain_sounds m_powertrainsounds;
|
|
sound_source sDirectionRelayD { sound_placement::engine }; // przekaznik kierunkowy do przodu
|
|
sound_source sDirectionRelayN { sound_placement::engine }; // przekaznik kierunkowy neutral
|
|
sound_source sDirectionRelayR { sound_placement::engine }; // przekaznik kierunkowy wstecz
|
|
sound_source sConverter { sound_placement::engine };
|
|
sound_source sBRVent {sound_placement::engine};
|
|
sound_source sCompressor { sound_placement::engine }; // NBMX wrzesien 2003
|
|
sound_source sCompressorIdle { sound_placement::engine };
|
|
sound_source sSmallCompressor { sound_placement::engine };
|
|
sound_source sHeater { sound_placement::engine };
|
|
sound_source m_batterysound { sound_placement::engine };
|
|
// braking sounds
|
|
sound_source dsbPneumaticRelay { sound_placement::external };
|
|
sound_source rsBrake { sound_placement::external, EU07_SOUND_BRAKINGCUTOFFRANGE }; // moved from cab
|
|
sound_source sBrakeAcc { sound_placement::external };
|
|
bool bBrakeAcc { false };
|
|
sound_source rsPisk { sound_placement::external, EU07_SOUND_BRAKINGCUTOFFRANGE }; // McZapkie-260302
|
|
sound_source rsUnbrake { sound_placement::external }; // yB - odglos luzowania
|
|
sound_source m_brakecylinderpistonadvance { sound_placement::external };
|
|
sound_source m_brakecylinderpistonrecede { sound_placement::external };
|
|
float m_lastbrakepressure { -1.f }; // helper, cached level of pressure in the brake cylinder
|
|
float m_brakepressurechange { 0.f }; // recent change of pressure in the brake cylinder
|
|
sound_source m_epbrakepressureincrease{ sound_placement::external };
|
|
sound_source m_epbrakepressuredecrease{ sound_placement::external };
|
|
float m_lastepbrakepressure{ -1.f }; // helper, cached level of pressure in the brake cylinder
|
|
float m_epbrakepressurechange{ 0.f }; // recent change of pressure in the brake cylinder
|
|
float m_epbrakepressurechangeinctimer{ 0.f }; // last time of change of pressure in the brake cylinder - increase
|
|
float m_epbrakepressurechangedectimer{ 0.f }; // last time of change of pressure in the brake cylinder - decrease
|
|
sound_source m_emergencybrake { sound_placement::engine };
|
|
double m_emergencybrakeflow{ 0.f };
|
|
sound_source sReleaser { sound_placement::external };
|
|
springbrake_sounds m_springbrakesounds;
|
|
sound_source rsSlippery { sound_placement::external, EU07_SOUND_BRAKINGCUTOFFRANGE }; // moved from cab
|
|
sound_source sSand { sound_placement::external };
|
|
sound_source sWiperToPark { sound_placement::internal };
|
|
bool sWiperToParkPlayed{false};
|
|
sound_source sWiperFromPark { sound_placement::internal };
|
|
bool sWiperFromParkPlayed{false};
|
|
|
|
// moving part and other external sounds
|
|
sound_source m_startjolt { sound_placement::general }; // movement start jolt, played once on initial acceleration at slow enough speed
|
|
bool m_startjoltplayed { false };
|
|
std::array<coupler_sounds, 2> m_couplersounds; // always front and rear
|
|
std::vector<pantograph_sounds> m_pantographsounds; // typically 2 but can be less (or more?)
|
|
std::vector<door_sounds> m_doorsounds; // can expect symmetrical arrangement, but don't count on it
|
|
bool m_doorlocks { false }; // sound helper, current state of door locks
|
|
std::vector<mirror_sounds> m_mirrorsounds;
|
|
std::array<mirror_moves::motion, 2> m_mirrormotion; // indexed by side: right, left
|
|
sound_source sHorn1 { sound_placement::external, 5 * EU07_SOUND_RUNNINGNOISECUTOFFRANGE };
|
|
sound_source sHorn2 { sound_placement::external, 5 * EU07_SOUND_RUNNINGNOISECUTOFFRANGE };
|
|
sound_source sHorn3 { sound_placement::external, 5 * EU07_SOUND_RUNNINGNOISECUTOFFRANGE };
|
|
#ifdef EU07_SOUND_BOGIESOUNDS
|
|
std::vector<sound_source> m_bogiesounds; // TBD, TODO: wrapper for all bogie-related sounds (noise, brakes, squeal etc)
|
|
#else
|
|
sound_source m_outernoise { sound_placement::external, EU07_SOUND_RUNNINGNOISECUTOFFRANGE };
|
|
#endif
|
|
sound_source m_wheelflat { sound_placement::external, EU07_SOUND_RUNNINGNOISECUTOFFRANGE };
|
|
sound_source rscurve { sound_placement::external, EU07_SOUND_RUNNINGNOISECUTOFFRANGE }; // youBy
|
|
sound_source rsDerailment { sound_placement::external, 2 * EU07_SOUND_RUNNINGNOISECUTOFFRANGE }; // McZapkie-051202
|
|
|
|
exchange_data m_exchange; // state of active load exchange procedure, if any
|
|
exchange_sounds m_exchangesounds; // sounds associated with the load exchange
|
|
|
|
std::vector<doorspeaker_sounds> m_doorspeakers;
|
|
pasystem_sounds m_pasystem;
|
|
|
|
std::array<
|
|
std::array<float, 6> // listener: rear cab, engine, front cab, window, attached camera, free camera
|
|
, 5> m_soundproofing = {{
|
|
{{ EU07_SOUNDPROOFING_NONE, EU07_SOUNDPROOFING_STRONG, EU07_SOUNDPROOFING_NONE, EU07_SOUNDPROOFING_SOME, EU07_SOUNDPROOFING_STRONG, EU07_SOUNDPROOFING_STRONG }}, // internal sounds
|
|
{{ EU07_SOUNDPROOFING_STRONG, EU07_SOUNDPROOFING_NONE, EU07_SOUNDPROOFING_STRONG, EU07_SOUNDPROOFING_SOME, EU07_SOUNDPROOFING_SOME, EU07_SOUNDPROOFING_SOME }}, // engine sounds
|
|
{{ EU07_SOUNDPROOFING_STRONG, EU07_SOUNDPROOFING_STRONG, EU07_SOUNDPROOFING_STRONG, EU07_SOUNDPROOFING_SOME, EU07_SOUNDPROOFING_SOME, EU07_SOUNDPROOFING_NONE }}, // external sound
|
|
{{ EU07_SOUNDPROOFING_VERYSTRONG, EU07_SOUNDPROOFING_VERYSTRONG, EU07_SOUNDPROOFING_VERYSTRONG, EU07_SOUNDPROOFING_STRONG, EU07_SOUNDPROOFING_STRONG, EU07_SOUNDPROOFING_NONE }}, // external ambient sound
|
|
{{ EU07_SOUNDPROOFING_NONE, EU07_SOUNDPROOFING_NONE, EU07_SOUNDPROOFING_NONE, EU07_SOUNDPROOFING_NONE, EU07_SOUNDPROOFING_NONE, EU07_SOUNDPROOFING_NONE }}, // custom sounds
|
|
}};
|
|
|
|
coupleradapter_data m_coupleradapter;
|
|
|
|
bool renderme; // yB - czy renderowac
|
|
float ModCamRot;
|
|
int iInventory[ 2 ] { 0, 0 }; // flagi bitowe posiadanych submodeli (np. świateł)
|
|
bool btnOn; // ABu: czy byly uzywane buttony, jesli tak, to po renderingu wylacz
|
|
// bo ten sam model moze byc jeszcze wykorzystany przez inny obiekt!
|
|
|
|
public:
|
|
int iHornWarning; // numer syreny do użycia po otrzymaniu sygnału do jazdy
|
|
bool bEnabled; // Ra: wyjechał na portal i ma być usunięty
|
|
protected:
|
|
int iNumAxles; // ilość osi
|
|
std::string asModel;
|
|
|
|
private:
|
|
TDynamicObject *ABuFindObject( int &Foundcoupler, double &Distance, TTrack const *Track, int const Direction, int const Mycoupler, bool const InLine = false ) const;
|
|
void ABuCheckMyTrack();
|
|
|
|
std::string rTypeName; // nazwa typu pojazdu
|
|
std::string rReplacableSkin; // nazwa tekstury pojazdu
|
|
|
|
public:
|
|
bool DimHeadlights{ false }; // status of the headlight dimming toggle. NOTE: single toggle for all lights is a simplification. TODO: separate per-light switches
|
|
bool HighBeamLights { false }; // status of the highbeam toggle
|
|
bool HeadlightsAoff{false}; // wygaszone swiatelki A
|
|
bool HeadlightsBoff{false}; // wygaszone swiatelki B
|
|
// checks whether there's unbroken connection of specified type to specified vehicle
|
|
bool is_connected( TDynamicObject const *Vehicle, coupling const Coupling = coupling::coupler ) const;
|
|
TDynamicObject * PrevAny() const;
|
|
TDynamicObject * Prev(int C = -1) const;
|
|
TDynamicObject * Next(int C = -1) const;
|
|
void SetdMoveLen(double dMoveLen) {
|
|
MoverParameters->dMoveLen = dMoveLen; }
|
|
void ResetdMoveLen() {
|
|
MoverParameters->dMoveLen = 0; }
|
|
double GetdMoveLen() {
|
|
return MoverParameters->dMoveLen; }
|
|
|
|
int GetPneumatic(bool front, bool red);
|
|
void SetPneumatic(bool front, bool red);
|
|
std::string asName;
|
|
const std::string &name() const {
|
|
return asName; }
|
|
// seed for texture variants of materials used by this vehicle and its load
|
|
std::uint32_t m_variantseed { 0 };
|
|
std::uint32_t variant_seed() const {
|
|
return m_variantseed; }
|
|
std::string asBaseDir;
|
|
|
|
// std::ofstream PneuLogFile; //zapis parametrow pneumatycznych
|
|
// youBy - dym
|
|
// TSmoke Smog;
|
|
// float EmR;
|
|
// vector3 smokeoffset;
|
|
|
|
TDynamicObject * ABuScanNearestObject(glm::vec3 pos, TTrack *Track, double ScanDir, double ScanDist,
|
|
int &CouplNr);
|
|
TDynamicObject * GetFirstDynamic(int cpl_type, int cf = 1);
|
|
void ABuSetModelShake(glm::dvec3 mShake);
|
|
|
|
// McZapkie-010302
|
|
TController *Mechanik;
|
|
TController *ctOwner; // wskażnik na obiekt zarządzający składem
|
|
bool MechInside;
|
|
// McZapkie-270202
|
|
bool Controller;
|
|
bool bDisplayCab; // czy wyswietlac kabine w train.cpp
|
|
int iCabs; // maski bitowe modeli kabin
|
|
TTrack *MyTrack; // McZapkie-030303: tor na ktorym stoi, ABu
|
|
int iOverheadMask; // maska przydzielana przez AI pojazdom posiadającym pantograf, aby wymuszały jazdę bezprądową
|
|
TTractionParam tmpTraction;
|
|
double fAdjustment; // korekcja - docelowo przenieść do TrkFoll.cpp wraz z odległością od poprzedniego
|
|
|
|
TTrack *initial_track = nullptr;
|
|
|
|
TDynamicObject();
|
|
~TDynamicObject();
|
|
void place_on_track(TTrack *Track, double fDist, bool Reversed);
|
|
// zwraca długość pojazdu albo 0, jeśli błąd
|
|
double Init(
|
|
std::string Name, std::string BaseDir, std::string asReplacableSkin, std::string Type_Name,
|
|
TTrack *Track, double fDist, std::string DriverType, double fVel, std::string TrainName,
|
|
float Load, std::string LoadType, bool Reversed, std::string);
|
|
int init_sections( TModel3d const *Model, std::string const &Nameprefix, bool const Overrideselfillum );
|
|
bool init_destination( TModel3d *Model );
|
|
// pairs the animated door wings with their namesakes in the low poly interior
|
|
void init_interior_doors();
|
|
void create_controller( std::string const Type, bool const Trainset );
|
|
void AttachNext(TDynamicObject *Object, int iType = 1);
|
|
bool UpdateForce(double dt);
|
|
// initiates load change by specified amounts, with a platform on specified side
|
|
void LoadExchange( int const Disembark, int const Embark, int const Platforms );
|
|
// calculates time needed to complete current load change, using specified platforms
|
|
float LoadExchangeTime( int const Platforms );
|
|
// calculates time needed to complete current load change, using previously specified platforms
|
|
float LoadExchangeTime() const;
|
|
// calculates current load exchange factor, where 1 = nominal rate, higher = faster
|
|
float LoadExchangeSpeed() const; // TODO: make private when cleaning up
|
|
void LoadUpdate();
|
|
void update_load_sections();
|
|
void update_load_visibility();
|
|
void update_load_offset();
|
|
void shuffle_load_order();
|
|
void update_destinations();
|
|
// feeds the script destination sign with fresh data, when it is shown and due
|
|
void update_script_destination();
|
|
bool Update(double dt, double dt1);
|
|
bool FastUpdate(double dt);
|
|
void Move(double fDistance);
|
|
void FastMove(double fDistance);
|
|
// physics.derailment new, the vehicle off the track (vehicle/derailmotion.h): the offset of its body from the axis of
|
|
// the track at the place nearest to it, to the left of its front positive [m]; 0 while it's on the track
|
|
double off_track_offset() const;
|
|
// the gap between the ends of the vehicle and the one at its End, as they meet off the track [m]: negative the
|
|
// buffers pressed in
|
|
double off_track_gap( int End ) const;
|
|
private:
|
|
// the axles moved along their tracks by the distance
|
|
void move_axles( double Distance );
|
|
// the vehicle placed on the track by its axles
|
|
void place_by_axles();
|
|
// the vehicle leaves the track: its motion on the ground begun, with the terrain around it
|
|
void begin_off_track();
|
|
// the vehicle off the track moved on the ground, by the distance along its heading, in the time of the frame
|
|
void move_off_track( double Distance );
|
|
// the terrain of the scenery around the vehicle off the track, as far as it may slide, for the ground under it: the
|
|
// one gathered for another vehicle where it covers that, gathered anew where it doesn't
|
|
void gather_off_track_terrain();
|
|
// at rest it keeps only the terrain under it, the rest of what was gathered (shared with others, perhaps) let go
|
|
void crop_off_track_terrain();
|
|
// the bed of the track at the axles, the level direction of the track there, and the side the derailment throws the
|
|
// vehicle to (1 the left of the front, -1 the right, 0 none): out of the curve of the track as designed, into it
|
|
// where a buckle bends the line the other way more (McZapkie/derailment.h); on a straight track out of the turn of
|
|
// the path as it lies, a buckle on it
|
|
derail_motion::formation track_bed() const;
|
|
glm::dvec3 track_front() const;
|
|
int outward_side() const;
|
|
// the couplings of this vehicle off the track pull the vehicles coupled to it off the rails sideways, the step
|
|
// having travelled the distance
|
|
void pull_neighbours( double Distance );
|
|
// the scraping of the vehicle off the track, until it stops, and its state to the log every second
|
|
void update_off_track( double Deltatime );
|
|
|
|
std::shared_ptr<derail_motion::mesh_ground const> m_offtrackterrain; // none in a scenery without terrain
|
|
glm::dvec2 m_offtrackmin { 0.0 }; // what the terrain was gathered for
|
|
glm::dvec2 m_offtrackmax { 0.0 };
|
|
bool m_offtrackcropped { false }; // the terrain cut down to the one under it at rest
|
|
derail_motion::site m_offtracksite;
|
|
double m_offtracktime { 0.0 }; // of the frame, for the motion
|
|
double m_offtracklogdue { 0.0 };
|
|
double m_offtracktotal { 0.0 }; // the time off the track [s]
|
|
double m_offtrackgathered { 0.0 }; // the time the terrain was gathered at [s]
|
|
double m_offtrackslowdue { 0.0 }; // till another warning of a slow frame [s]
|
|
double m_offtrackupdatedue { 0.0 }; // and of a slow update
|
|
double m_offtrackaxles { 0.0 }; // the move along the track the axles didn't make yet [m]
|
|
glm::dvec3 m_offtrackfrom { 0.0 }; // where the body was when its move went into the axles last
|
|
bool m_offtrackscraping { false }; // the scraping of the vehicle off the track plays, looped
|
|
// the most triangles of terrain taken around the vehicle off the track
|
|
static constexpr std::size_t off_track_triangles { 400000 };
|
|
bool m_offtrackplaced { false }; // placed off the track: placed on it again once it's back on the rails
|
|
std::array<derailment::stretch, 2> m_pulledoff; // the distance the coupling of an end pulled the vehicle coupled there over the climbing limit
|
|
derailment::stretch m_struck; // on the rails: the distance a body off the track pushed it sideways over the climbing limit
|
|
// the model, the axes and the coupling points placed by the motion off the track
|
|
void place_off_track();
|
|
public:
|
|
void RenderSounds();
|
|
// plays the sounds of the mirrors on the Side, of the occupied cab, starting the Event
|
|
void play_mirror_sounds( side const Side, mirror_moves::event const Event );
|
|
inline glm::dvec3 GetPosition() const {
|
|
return vPosition; };
|
|
// converts location from vehicle coordinates frame to world frame
|
|
inline glm::dvec3 GetWorldPosition( glm::dvec3 const &Location ) const {
|
|
return vPosition + glm::dvec3(mMatrix * glm::dvec4(Location, 1.0)); }
|
|
// pobranie współrzędnych czoła
|
|
inline glm::dvec3 HeadPosition() const {
|
|
return vCoulpler[iDirection ^ 1]; };
|
|
// pobranie współrzędnych tyłu
|
|
inline glm::dvec3 RearPosition() const {
|
|
return vCoulpler[iDirection]; };
|
|
inline glm::dvec3 CouplerPosition( end const End ) const {
|
|
return vCoulpler[ End ]; }
|
|
inline glm::dvec3 AxlePositionGet() {
|
|
return iAxleFirst ?
|
|
Axle1.pPosition :
|
|
Axle0.pPosition; };
|
|
inline double Roll() {
|
|
return Axle1.GetRoll() + Axle0.GetRoll(); }
|
|
/*
|
|
// TODO: check if scanning takes into account direction when selecting axle
|
|
// if it does, replace the version above
|
|
// if it doesn't, fix it so it does
|
|
inline glm::dvec3 AxlePositionGet() {
|
|
return (
|
|
iDirection ?
|
|
( iAxleFirst ? Axle1.pPosition : Axle0.pPosition ) :
|
|
( iAxleFirst ? Axle0.pPosition : Axle1.pPosition ) ); }
|
|
*/
|
|
inline glm::dvec3 VectorFront() const {
|
|
return vFront; };
|
|
inline glm::dvec3 VectorUp() const {
|
|
return vUp; };
|
|
inline glm::dvec3 VectorLeft() const {
|
|
return vLeft; };
|
|
inline double const * Matrix() const {
|
|
return glm::value_ptr(mMatrix); };
|
|
inline double * Matrix() {
|
|
return glm::value_ptr(mMatrix); };
|
|
inline double GetVelocity() const {
|
|
return MoverParameters->Vel; };
|
|
inline double GetLength() const {
|
|
return MoverParameters->Dim.L; };
|
|
inline double GetWidth() const {
|
|
return MoverParameters->Dim.W; };
|
|
double radius() const;
|
|
// calculates distance between event-starting axle and front of the vehicle
|
|
double tracing_offset() const;
|
|
inline TTrack * GetTrack() {
|
|
return iAxleFirst ? Axle1.GetTrack() : Axle0.GetTrack(); };
|
|
|
|
// McZapkie-260202
|
|
void LoadMMediaFile(std::string const &TypeName, std::string const &ReplacableSkin);
|
|
TModel3d *LoadMMediaFile_mdload( std::string const &Name ) const;
|
|
|
|
inline double ABuGetDirection() const { // ABu.
|
|
return Axle1.GetTrack() == MyTrack ? Axle1.GetDirection() : Axle0.GetDirection(); };
|
|
// zwraca kierunek pojazdu na torze z aktywną osą
|
|
inline double RaDirectionGet() const {
|
|
return iAxleFirst ?
|
|
Axle1.GetDirection() :
|
|
Axle0.GetDirection(); };
|
|
// zwraca przesunięcie wózka względem Point1 toru z aktywną osią
|
|
inline double RaTranslationGet() const {
|
|
return iAxleFirst ?
|
|
Axle1.GetTranslation() :
|
|
Axle0.GetTranslation(); };
|
|
// zwraca tor z aktywną osią
|
|
inline TTrack const * RaTrackGet() const {
|
|
return iAxleFirst ?
|
|
Axle1.GetTrack() :
|
|
Axle0.GetTrack(); };
|
|
|
|
void couple( int const Side );
|
|
int uncouple( int const Side );
|
|
bool attach_coupler_adapter( int const Side, bool const Enforce = false );
|
|
bool remove_coupler_adapter( int const Side );
|
|
void RadioStop();
|
|
void Damage(char flag);
|
|
void pants_up();
|
|
void SetLights();
|
|
void SetLightDimmings();
|
|
void RaLightsSet(int head, int rear);
|
|
int LightList( end const Side ) const { return iInventory[ Side ]; }
|
|
bool has_signal_pc1_on() const;
|
|
bool has_signal_pc2_on() const;
|
|
bool has_signal_pc5_on() const;
|
|
bool has_signal_on( int const Side, int const Pattern ) const;
|
|
void set_cab_lights( int const Cab, float const Level );
|
|
TDynamicObject * FirstFind(int &coupler_nr, int cf = 1);
|
|
float GetEPP(); // wyliczanie sredniego cisnienia w PG
|
|
int DirectionSet(int d); // ustawienie kierunku w składzie
|
|
// odczyt kierunku w składzie; returns 1 if true, -1 otherwise
|
|
int DirectionGet() const {
|
|
return iDirection + iDirection - 1; };
|
|
int DettachStatus(int dir);
|
|
int Dettach(int dir);
|
|
TDynamicObject * Neighbour(int &dir);
|
|
// updates potential collision sources
|
|
void update_neighbours();
|
|
// physics.derailment new: the vehicle and the other one, one of them off the track, are in line, close enough
|
|
// across to run into each other
|
|
bool in_line_with( TDynamicObject const &Other ) const;
|
|
// locates potential collision source within specified range, scanning its route in specified direction. InLine:
|
|
// physics.derailment new, the scan goes on past a vehicle off the track beside the line (or beside this one off it)
|
|
auto find_vehicle( int const Direction, double const Range, bool const InLine = false ) const -> std::tuple<TDynamicObject *, int, double, bool>;
|
|
// locates potential vehicle connected with specific coupling type and satisfying supplied predicate
|
|
template <typename Predicate_>
|
|
auto find_vehicle( coupling const Coupling, Predicate_ const Predicate ) -> TDynamicObject *;
|
|
TDynamicObject * FindPowered();
|
|
TDynamicObject * FindPantographCarrier();
|
|
template <typename UnaryFunction_>
|
|
void for_each( coupling const Coupling, UnaryFunction_ const Function );
|
|
void ParamSet(int what, int into);
|
|
// zapytanie do AI, po którym segmencie skrzyżowania jechać
|
|
int RouteWish(TTrack *tr);
|
|
void DestinationSet(std::string const &to, std::string const &numer);
|
|
// blanks electronic destination sign at the end of the service; physical signs stay until changed
|
|
void DestinationClear();
|
|
material_handle DestinationFind( std::string Destination );
|
|
// the name of a generated destination sign texture: the script, the timetable, the instancing and the parameters
|
|
std::string destination_request( std::string const &Script, std::string const &Instancing, std::string const &Parameters ) const;
|
|
// the script sign of the vehicle the game can run: the Lua one, else the WebAssembly one; nullptr for none
|
|
script_screens::screen_config const *script_destination( script_language &Language ) const;
|
|
// makes the destination sign a script screen, when the vehicle has one the game can run. returns true when it did
|
|
bool destination_set_script( std::string const &Numer );
|
|
// draws a texture named make:<script>.lua?<parameters> (or .wasm) once with its script; nullptr for other textures
|
|
std::shared_ptr<script_screen> draw_script_texture( std::string const &Name, material_handle Material );
|
|
void OverheadTrack(float o);
|
|
glm::dvec3 get_future_movement() const;
|
|
void move_set(double distance);
|
|
// playes specified announcement, potentially preceding it with a chime
|
|
void announce( announcement_t const Announcement, bool const Chime = true );
|
|
// returns soundproofing for specified sound type and listener location
|
|
float soundproofing( int const Placement, int const Listener ) const {
|
|
return m_soundproofing[ Placement - 1 ][ Listener + 1 ]; }
|
|
|
|
double MED[9][8]; // lista zmiennych do debugowania hamulca ED
|
|
static std::string const MED_labels[ 8 ];
|
|
std::ofstream MEDLogFile; // zapis parametrów hamowania
|
|
double MEDLogTime = 0;
|
|
double MEDLogInactiveTime = 0;
|
|
int MEDLogCount = 0;
|
|
double MED_oldFED = 0;
|
|
|
|
// vehicle shaking calculations
|
|
// TBD, TODO: make an object out of it
|
|
public:
|
|
// methods
|
|
void update_shake( double const Timedelta );
|
|
std::pair<double, double> shake_angles() const;
|
|
// members
|
|
struct baseshake_config {
|
|
glm::vec3 angle_scale { 0.05, 0.0, 0.1 }; // roll, yaw, pitch
|
|
glm::vec3 jolt_scale{0.2, 0.2, 0.1};
|
|
double jolt_limit { 2.0f };
|
|
} BaseShake;
|
|
struct engineshake_config {
|
|
float scale { 2.f };
|
|
float fadein_offset { 1.5f }; // 90 rpm
|
|
float fadein_factor { 0.3f };
|
|
float fadeout_offset { 10.f }; // 600 rpm
|
|
float fadeout_factor { 0.5f };
|
|
} EngineShake;
|
|
struct huntingshake_config {
|
|
float scale { 1.f };
|
|
float frequency { 1.f };
|
|
float fadein_begin { 0.f }; // effect start speed in km/h
|
|
float fadein_end { 0.f }; // full effect speed in km/h
|
|
} HuntingShake;
|
|
float HuntingAngle { 0.f }; // crude approximation of hunting oscillation; current angle of sine wave
|
|
bool IsHunting { false };
|
|
TSpring ShakeSpring;
|
|
struct shake_state {
|
|
glm::dvec3 velocity{}; // current shaking vector
|
|
glm::dvec3 offset{}; // overall shake-driven offset from base position
|
|
} ShakeState;
|
|
shake_state ShakeStateBefore; // the state before the last step of update_shake
|
|
// the shake between the last two steps of update_shake: 0 the state before the last step, 1 the state after it.
|
|
// the steps are fixed and the frames aren't, so the camera takes the state at its own moment between the two
|
|
shake_state shake_between( double const Fraction ) const;
|
|
std::pair<double, double> shake_angles( shake_state const &State ) const;
|
|
|
|
glm::dvec3 modelShake;
|
|
};
|
|
|
|
|
|
|
|
class vehicle_table : public basic_table<TDynamicObject> {
|
|
|
|
public:
|
|
// legacy method, calculates changes in simulation state over specified time
|
|
void
|
|
update( double dt, int iter );
|
|
// legacy method, checks for presence and height of traction wire for specified vehicle
|
|
void
|
|
update_traction( TDynamicObject *Vehicle );
|
|
// legacy method, sends list of vehicles over network
|
|
void
|
|
DynamicList( bool const Onlycontrolled = false ) const;
|
|
// records the odometer states of the vehicles and saves them for the next sessions
|
|
void
|
|
save_odometers();
|
|
// physics.derailment new: the terrain gathered for a vehicle off the track which covers the rectangle from Min to Max
|
|
// (x, z), shared by the vehicles which slide over it; none where no vehicle has one. it lives as long as one of them
|
|
// keeps it
|
|
std::shared_ptr<derail_motion::mesh_ground const>
|
|
off_track_terrain( glm::dvec2 const &Min, glm::dvec2 const &Max );
|
|
void
|
|
share_off_track_terrain( std::shared_ptr<derail_motion::mesh_ground const> const &Terrain );
|
|
|
|
private:
|
|
// maintenance; removes from tracks consists with vehicles marked as disabled
|
|
bool
|
|
erase_disabled();
|
|
// marks the vehicles the physical coupler model covers (couplerphysics yes in eu07.ini): the player's train and
|
|
// the trains it closes in on
|
|
void
|
|
update_coupler_physics() const;
|
|
// the air exchange through the brake and main reservoir hoses of the vehicles which stepped their physics, after all of them did
|
|
void
|
|
update_brake_pipes( double const Deltatime );
|
|
// physics.derailment new: the bodies of the vehicles off the track and those near them run into each other instead
|
|
// of into one another: the impulses of the hits, the bodies moved apart, a vehicle on the rails pushed off them;
|
|
// what the bodies overlap by goes to the log every second
|
|
void
|
|
update_off_track_contacts( double const Deltatime );
|
|
|
|
double m_odometersavetimer { 0.0 }; // simulation time since the odometers were last saved
|
|
// the most the bodies overlapped by, of the vehicles of update_off_track_contacts(), since it was logged last [m], and
|
|
// which ones; till the next line in the log [s]; once all of them came to rest it is logged no more
|
|
double m_overlapmost { 0.0 };
|
|
std::string m_overlappair;
|
|
double m_overlapdue { 1.0 };
|
|
bool m_overlaplogged { false };
|
|
std::vector<TMoverParameters *> m_brakepipes; // the vehicles of update_brake_pipes(), kept for the memory
|
|
std::vector<std::weak_ptr<derail_motion::mesh_ground const>> m_offtrackterrains; // of off_track_terrain()
|
|
};
|
|
|
|
|
|
template <typename Predicate_>
|
|
auto
|
|
TDynamicObject::find_vehicle( coupling const Coupling, Predicate_ const Predicate ) -> TDynamicObject * {
|
|
|
|
if( Predicate( this ) ) {
|
|
return this; }
|
|
// try first to look towards the rear
|
|
auto *vehicle { this };
|
|
while( ( vehicle = vehicle->Next( Coupling ) ) != nullptr ) {
|
|
if( Predicate( vehicle ) ) {
|
|
return vehicle; } }
|
|
// if we didn't yet find a suitable vehicle try in the other direction
|
|
vehicle = this;
|
|
while( ( vehicle = vehicle->Prev( Coupling ) ) != nullptr ) {
|
|
if( Predicate( vehicle ) ) {
|
|
return vehicle; } }
|
|
// if we still don't have a match give up
|
|
return nullptr;
|
|
}
|
|
|
|
template <typename UnaryFunction_>
|
|
void
|
|
TDynamicObject::for_each( coupling const Coupling, UnaryFunction_ const Function ) {
|
|
|
|
Function( this );
|
|
// walk first towards the rear
|
|
auto *vehicle { this };
|
|
while( ( vehicle = vehicle->Next( Coupling ) ) != nullptr ) {
|
|
Function( vehicle ); }
|
|
// then towards the front
|
|
vehicle = this;
|
|
while( ( vehicle = vehicle->Prev( Coupling ) ) != nullptr ) {
|
|
Function( vehicle ); }
|
|
}
|
|
|
|
//---------------------------------------------------------------------------
|