mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-27 22:55:16 +01:00
origin/staging7ac2472c3into feat/gl46-migrationdb26a33ed, so that #468 merges into staging. Merge base037158104. Staging carries master up to571487612(squashed in #514); this branch had merged master up to7c12b83ba. Conflicts, file by file: - README.md: WITH_BETTER_RENDERER row dropped (gl46), USE_SYSTEM_JSON row kept (staging) - CMakeLists.txt: gl46 lists, plus staging's new core sources (hardwareinfo, sn_utils, regionfile, inionlysettings, fieldshunting, gaugewrap, drivingaid, signalpassing, brakereleaser, crew, brakecharge); none listed twice - tests/unit/CMakeLists.txt: both (texturealpha, freecameramotion; editorSwitchDrives, Camera) - vehicle/brakingcurve.{h,cpp}, tests/unit/test_braking_curve.cpp (add/add): staging (#479 brake_acting on the same #409 code) - editor/editorHttp.cpp: staging (it has gl46's #432 and certificate fixes, plus #439 libcurl loaded at run time) - tests/unit/test_editor_http.cpp (add/add): staging (adds the available() case of #439) - utilities/Globals.h: gl46 crashdump_full (staging's CrashDumpFull is #425, replaced here by utilities/crashdump.cpp); fmradio and staging's OpenAL options both; gfx_headlights_beamwidth (#481) not taken - utilities/Globals.cpp: both (odometer.expiry, OpenAL keys, fmradio, gl46 gfx keys); gfx.headlights.beamwidth (#481) not taken - utilities/Logs.cpp: staging's log_file_name() for both files, with gl46's crashdump_set_log_file() for both - utilities/utilities.h: gl46 set_thread_random_engine(); Random(int, int) gone on both sides - tests/unit/test_utilities.cpp: staging's includes - simulation/simulationtest.cpp: gl46 (no NvRenderer, LegacyRenderer, BasicRenderer here) - ci_shadervalidator/* (incl. add/add utilities/Logs.h): gl46's validator of shaders/ogl46 and shaders/vk14; staging's #437 fixed the GL 3.3 one - gl/shader.cpp, gl/glsl_common.cpp: gl46 (shaders come from rendering/common/shadersource.cpp); HEADLIGHT_BEAM_WIDTH (#481) not taken - shaders/mat_wire.frag: gl46. Rename detection paired staging's mat_colored.frag (#481) with it - lang/editor_pl.po: union; the 12 camera speed / orthophoto entries staging adds are here already (master #312) - audio/audiorenderer.{h,cpp}: both (fmradio; startsample and the low-pass filter); the destructor releases the radio, then the filter - application/editormode.h, application/editormodeswitchdrive.cpp: staging (#509 on #330, which is all this side had) - application/application.cpp: gl46's start sequence (no init_ogl, ANGLE or NvRenderer; crash window after init_ui) with staging's hardware::log_system() (#389) - EU07.cpp: gl46 (crash reports of utilities/crashdump.cpp); staging's side was #425's handler, replaced here - model/Texture.{h,cpp}: gl46 (texture_source); staging's side is master #399/#411/#362/#386, merged here before - world/Track.h, world/TrackSleepers.h: both (TrackBlend, lay(Fastened)/fasten; TrackBuckle, pack_models) - world/Segment.cpp: staging's track buckling on the split stray factors both sides have - vehicle/Driver.h: staging's additions (#444, #494, #473, #346, timetable flags) - vehicle/Driver.cpp: staging's file, with this branch'sf4f8c75e4(road orders measured along the lane) and8fbf05674(a holding road order blocks the ones past it) applied again; #409's SeenAheadTolerance gives way to #473 - vehicle/DynObj.h: friend opengl46_renderer and friend class vehicle_table - vehicle/DynObj.cpp: gl46's vehicle_table::update() with staging's update_off_track_contacts() and update_brake_pipes() - McZapkie/Mover.cpp: staging's function splits (#239) and hose exchange (#388); every line this branch added to Mover.cpp/MOVER.h is kept - .github/workflows/build_bin.yml: staging's apt-install step (#497) and pinned download-artifact (#331) Modify/delete, kept deleted: - rendering/opengl33renderer.{cpp,h}, rendering/openglparticles.cpp, rendering/openglrenderer.{cpp,h}: staging's versions are master's, and every master change to them is in this branch's history already - shaders/light_common.glsl, shaders/mat_sunlessnormalmap_specgloss.frag: see below Carried into this branch's code: - the hose exchange after each sub-step (#387/#388) also in update_steps_parallel(), per group of vehicles, as update() does it single-threaded - physics.pipewake (pipe_wakes(), wake_cause::scndpipe) in staging's GetScndDVc(), where the main reservoir hose exchange went - hardware::log_gl_context() (#389) in after_window() of the GL 4.6 backend, init_ogl() being gone Taken back out of the auto-merge (renderers this branch removed): - shaders/vk14/tonemapping.glsl: #481's switch to ACES, applied there by rename detection - environment/skydome.cpp, simulation/simulationenvironment.cpp: #415, the sky of the legacy renderer - application/application.cpp: #384's fallback of an unknown gfxrenderer, which this branch had dropped Not carried from staging (renderer files removed here): - master #481 (571487612): old assets drawn as in 26.05 (metal diffuse, sun highlight tint, ACES, SUN_DIFFUSE_SCALE 2.5, untinted Diffuse, mat_colored base) and gfx.headlights.beamwidth. Made for the GL 3.3 shaders; the PBR shaders of shaders/ogl46 and vk14 (and their SPIR-V binaries) are the author's call - #437: the unique temporary file of the shader validator (Sonar S5443); gl46's validator still writes /tmp/shader* Unit tests: 1133 of 1137 cases pass. Four staging tests fail (derailment: a repaired vehicle is back on the rails; three pullee cases): the vehicle stands, and with physics.sleepheld (on by default here) its physics sleeps with the Fb / FStand of before. With physics.sleepheld off they pass. Left to the author.
406 lines
19 KiB
C++
406 lines
19 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 and others
|
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
#include "world/TrkFoll.h"
|
|
|
|
#include "simulation/simulation.h"
|
|
#include "utilities/Globals.h"
|
|
#include "vehicle/DynObj.h"
|
|
#include "vehicle/Driver.h"
|
|
#include "utilities/Logs.h"
|
|
|
|
namespace {
|
|
|
|
// how far the start of a way across a crossroads can be from the end of the path an axle leaves, to be where the axle gets on
|
|
constexpr double cross_reach { 1.0 };
|
|
|
|
// number of the ways across a crossroads; each can be taken either way
|
|
int cross_count( TTrack const &Cross ) {
|
|
|
|
return Cross.SwitchExtension->iRoads == 4 ? 6 : 3;
|
|
}
|
|
|
|
// where the way of specified code starts, and the direction it leads in there. the code is the number of the way, 1..6,
|
|
// negative if the way is taken against its points
|
|
bool cross_start( TTrack const &Cross, int const Code, glm::dvec3 &Point, glm::dvec3 &Direction ) {
|
|
|
|
if( Code == 0 || std::abs( Code ) > cross_count( Cross ) ) { return false; }
|
|
auto const &segment { Cross.SwitchExtension->Segments[ std::abs( Code ) - 1 ] };
|
|
if( segment == nullptr ) { return false; }
|
|
Point = ( Code > 0 ? segment->FastGetPoint_0() : segment->FastGetPoint_1() );
|
|
Direction = ( Code > 0 ? segment->FastGetPoint( 0.05 ) : segment->FastGetPoint( 0.95 ) ) - Point;
|
|
return true;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
TTrackFollower::~TTrackFollower()
|
|
{
|
|
}
|
|
|
|
bool TTrackFollower::Init(TTrack *pTrack, TDynamicObject *NewOwner, double fDir)
|
|
{
|
|
fDirection = fDir;
|
|
Owner = NewOwner;
|
|
// the axle is put on the track, it doesn't come from the one it was on before
|
|
pCurrentSegment = nullptr;
|
|
SetCurrentTrack(pTrack, 0);
|
|
iEventFlag = 3; // na torze startowym również wykonać eventy 1/2
|
|
iEventallFlag = 3;
|
|
if (pCurrentSegment) // && (pCurrentSegment->GetLength()<fFirstDistance))
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
void TTrackFollower::Reset()
|
|
{
|
|
fCurrentDistance = 0.0;
|
|
fDirection = 1.0;
|
|
}
|
|
|
|
TTrack * TTrackFollower::SetCurrentTrack(TTrack *pTrack, int end)
|
|
{ // przejechanie na inny odcinkek toru, z ewentualnym rozpruciem
|
|
if (pTrack)
|
|
switch (pTrack->eType)
|
|
{
|
|
case tt_Switch: // jeśli zwrotnica, to przekładamy ją, aby uzyskać dobry segment
|
|
{
|
|
if( pCurrentTrack == nullptr ) {
|
|
break;
|
|
}
|
|
int i = end ? pCurrentTrack->iNextDirection : pCurrentTrack->iPrevDirection;
|
|
if (i > 0) // jeżeli wjazd z ostrza
|
|
pTrack->SwitchForced(i >> 1, Owner); // to przełożenie zwrotnicy - rozprucie!
|
|
}
|
|
break;
|
|
case tt_Cross: // skrzyżowanie trzeba tymczasowo przełączyć, aby wjechać na właściwy tor
|
|
{
|
|
iSegment = Owner->RouteWish(pTrack); // nr segmentu został ustalony podczas skanowania
|
|
// Ra 2014-08: aby ustalić dalszą trasę, należy zapytać AI - trasa jest ustalana podczas
|
|
// skanowania
|
|
// Ra 15-01: zapytanie AI nie wybiera segmentu - kolejny skanujący może przestawić
|
|
// pTrack->CrossSegment(end?pCurrentTrack->iNextDirection:pCurrentTrack->iPrevDirection,i);
|
|
// //ustawienie właściwego wskaźnika
|
|
// powinno zwracać kierunek do zapamiętania, bo segmenty mogą mieć różny kierunek
|
|
// if fDirection=(iSegment>0)?1.0:-1.0; //kierunek na tym segmencie jest ustalany
|
|
// bezpośrednio
|
|
if (iSegment == 0)
|
|
{ // to jest błędna sytuacja - generuje pętle zawracające za skrzyżowaniem - ustalić,
|
|
// kiedy powstaje!
|
|
iSegment = 1; // doraźna poprawka
|
|
}
|
|
// the way has to start where the axle gets on. the one the driver picked may not: the driver may have looked
|
|
// again since the other axle got on, the vehicle may have no driver of its own, or it may be going backwards
|
|
iSegment = CrossEntry( *pTrack, iSegment, end );
|
|
if ((end ? iSegment : -iSegment) < 0)
|
|
fDirection = -fDirection; // wtórna zmiana
|
|
pTrack->SwitchForced(abs(iSegment) - 1, nullptr); // wybór zapamiętanego segmentu
|
|
}
|
|
break;
|
|
}
|
|
if (!pTrack) {
|
|
// gdy nie ma toru w kierunku jazdy tworzenie toru wykolejącego na przedłużeniu pCurrentTrack
|
|
pTrack = pCurrentTrack->NullCreate(end);
|
|
if (!end) // jeśli dodana od strony zero, to zmiana kierunku
|
|
fDirection = -fDirection; // wtórna zmiana
|
|
}
|
|
else
|
|
{ // najpierw +1, później -1, aby odcinek izolowany wspólny dla tych torów nie wykrył zera
|
|
pTrack->AxleCounter(+1, Owner); // zajęcie nowego toru
|
|
if (pCurrentTrack)
|
|
pCurrentTrack->AxleCounter(-1, Owner); // opuszczenie tamtego toru
|
|
}
|
|
pCurrentTrack = pTrack;
|
|
pCurrentSegment = pCurrentTrack != nullptr ? pCurrentTrack->CurrentSegment() : nullptr;
|
|
if (!pCurrentTrack)
|
|
Error(Owner->MoverParameters->Name + " at NULL track");
|
|
return pCurrentTrack;
|
|
};
|
|
|
|
// picks the way across the crossroads (Cross) for the axle which gets on it by specified end of the path it's on. it's the way
|
|
// taken by another axle of the vehicle, or of a vehicle coupled to it, which is on the crossroads already; or the one the driver
|
|
// picked (Wish); or, if neither starts where the axle gets on, the one leading the most straight on of the ways which start there
|
|
int TTrackFollower::CrossEntry( TTrack const &Cross, int const Wish, int const End ) const {
|
|
|
|
if( pCurrentSegment == nullptr || Cross.SwitchExtension == nullptr ) { return Wish; }
|
|
|
|
auto const joint { End ? pCurrentSegment->FastGetPoint_1() : pCurrentSegment->FastGetPoint_0() };
|
|
auto const starts_here = [&]( int const Code ) {
|
|
glm::dvec3 point, direction;
|
|
return cross_start( Cross, Code, point, direction ) && glm::distance( point, joint ) < cross_reach; };
|
|
|
|
if( Owner != nullptr ) {
|
|
for( auto const *vehicle : { Owner, Owner->Prev(), Owner->Next() } ) {
|
|
if( vehicle == nullptr ) { continue; }
|
|
for( auto const *axle : { &vehicle->Axle0, &vehicle->Axle1 } ) {
|
|
if( axle == this || axle->pCurrentTrack != &Cross || axle->iSegment == 0 ) { continue; }
|
|
if( starts_here( axle->iSegment ) ) { return axle->iSegment; }
|
|
// a vehicle going back over the crossroads gets on the way at its other end
|
|
if( starts_here( -axle->iSegment ) ) { return -axle->iSegment; }
|
|
}
|
|
}
|
|
}
|
|
if( starts_here( Wish ) ) { return Wish; }
|
|
|
|
auto const incoming { joint - ( End ? pCurrentSegment->FastGetPoint( 0.95 ) : pCurrentSegment->FastGetPoint( 0.05 ) ) };
|
|
auto nearest { cross_reach };
|
|
for( int way = 1; way <= cross_count( Cross ); ++way ) {
|
|
for( auto const code : { way, -way } ) {
|
|
glm::dvec3 point, direction;
|
|
if( cross_start( Cross, code, point, direction ) ) {
|
|
nearest = std::min( nearest, glm::distance( point, joint ) );
|
|
}
|
|
}
|
|
}
|
|
if( nearest >= cross_reach ) {
|
|
// no way starts there, the crossroads isn't joined with the path; it's left the way it was
|
|
return Wish;
|
|
}
|
|
auto result { Wish };
|
|
auto straightest { -2.0 };
|
|
for( int way = 1; way <= cross_count( Cross ); ++way ) {
|
|
for( auto const code : { way, -way } ) {
|
|
glm::dvec3 point, direction;
|
|
if( false == cross_start( Cross, code, point, direction )
|
|
|| glm::distance( point, joint ) > nearest + 0.05 ) {
|
|
continue;
|
|
}
|
|
auto const straight {
|
|
glm::length2( incoming ) > 0.0 && glm::length2( direction ) > 0.0 ?
|
|
glm::dot( glm::normalize( incoming ), glm::normalize( direction ) ) :
|
|
-1.0 };
|
|
if( straight > straightest ) {
|
|
straightest = straight;
|
|
result = code;
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
bool TTrackFollower::Move(double fDistance, bool bPrimary)
|
|
{ // przesuwanie wózka po torach o odległość (fDistance), z wyzwoleniem eventów
|
|
// bPrimary=true - jest pierwszą osią w pojeździe, czyli generuje eventy i przepisuje pojazd
|
|
// Ra: zwraca false, jeśli pojazd ma być usunięty
|
|
auto const ismoving { /* ( std::abs( fDistance ) > 0.01 ) && */ ( Owner->GetVelocity() > 0.01 ) };
|
|
fDistance *= fDirection; // dystans mnożnony przez kierunek
|
|
double s; // roboczy dystans
|
|
double dir; // zapamiętany kierunek do sprawdzenia, czy się zmienił
|
|
bool bCanSkip; // czy przemieścić pojazd na inny tor
|
|
while (true) // pętla wychodzi, gdy przesunięcie wyjdzie zerowe
|
|
{ // pętla przesuwająca wózek przez kolejne tory, aż do trafienia w jakiś
|
|
if( pCurrentTrack == nullptr ) { return false; } // nie ma toru, to nie ma przesuwania
|
|
// TODO: refactor following block as track method
|
|
if( pCurrentTrack->m_events ) { // sumaryczna informacja o eventach
|
|
// omijamy cały ten blok, gdy tor nie ma on żadnych eventów (większość nie ma)
|
|
int const eventfilter { (
|
|
false == ismoving ? 0 : // only moving vehicles activate events type 1/2
|
|
false == bPrimary ? 0 : // only primary axle activates events type 1/2
|
|
Owner->ctOwner == nullptr ?
|
|
( fDistance > 0 ? 1 : -1 ) : // loose vehicle has no means to determine 'intended' direction so the filter does effectively nothing in such case
|
|
( fDirection > 0 ? 1 : -1 ) * Owner->ctOwner->Direction() * ( Owner->ctOwner->Vehicle()->DirectionGet() == Owner->DirectionGet() ? 1 : -1 ) ) };
|
|
|
|
if( false == ismoving ) {
|
|
//McZapkie-140602: wyzwalanie zdarzenia gdy pojazd stoi
|
|
if( Owner->Mechanik != nullptr
|
|
&& Owner->Mechanik->primary() ) {
|
|
// tylko dla jednego członu
|
|
pCurrentTrack->QueueEvents( pCurrentTrack->m_events0, Owner );
|
|
}
|
|
pCurrentTrack->QueueEvents( pCurrentTrack->m_events0all, Owner );
|
|
}
|
|
else if( fDistance < 0 && eventfilter < 0 ) {
|
|
// event1, eventall1
|
|
if( SetFlag( iEventFlag, -1 ) ) {
|
|
// zawsze zeruje flagę sprawdzenia, jak mechanik dosiądzie, to się nie wykona
|
|
if( Owner->Mechanik != nullptr
|
|
&& Owner->Mechanik->primary() ) {
|
|
// tylko dla jednego członu
|
|
// McZapkie-280503: wyzwalanie event tylko dla pojazdow z obsada
|
|
pCurrentTrack->QueueEvents( pCurrentTrack->m_events1, Owner );
|
|
}
|
|
}
|
|
if( SetFlag( iEventallFlag, -1 ) ) {
|
|
// McZapkie-280503: wyzwalanie eventall dla wszystkich pojazdow
|
|
pCurrentTrack->QueueEvents( pCurrentTrack->m_events1all, Owner );
|
|
}
|
|
}
|
|
else if( fDistance > 0 && eventfilter > 0 ) {
|
|
// event2, eventall2
|
|
if( SetFlag( iEventFlag, -2 ) ) {
|
|
// zawsze ustawia flagę sprawdzenia, jak mechanik dosiądzie, to się nie wykona
|
|
if( Owner->Mechanik != nullptr
|
|
&& Owner->Mechanik->primary() ) {
|
|
// tylko dla jednego członu
|
|
pCurrentTrack->QueueEvents( pCurrentTrack->m_events2, Owner );
|
|
}
|
|
}
|
|
if( SetFlag( iEventallFlag, -2 ) ) {
|
|
// sprawdza i zeruje na przyszłość, true jeśli zmieni z 2 na 0
|
|
pCurrentTrack->QueueEvents( pCurrentTrack->m_events2all, Owner );
|
|
}
|
|
}
|
|
}
|
|
if (!pCurrentSegment) // jeżeli nie ma powiązanego segmentu toru?
|
|
return false;
|
|
// if (fDistance==0.0) return true; //Ra: jak stoi, to chyba dalej nie ma co kombinować?
|
|
s = fCurrentDistance + fDistance; // doliczenie przesunięcia
|
|
// Ra: W Point2 toru może znajdować się "dziura", która zamieni energię kinetyczną
|
|
// ruchu wzdłużnego na energię potencjalną, zamieniającą się potem na energię
|
|
// sprężystości na amortyzatorach. Należałoby we wpisie toru umieścić współczynnik
|
|
// podziału energii kinetycznej.
|
|
// Współczynnik normalnie 1, z dziurą np. 0.99, a -1 będzie oznaczało 100% odbicia (kozioł).
|
|
// Albo w postaci kąta: normalnie 0°, a 180° oznacza 100% odbicia (cosinus powyższego).
|
|
/*
|
|
if (pCurrentTrack->eType==tt_Cross)
|
|
{//zjazdu ze skrzyżowania nie da się określić przez (iPrevDirection) i (iNextDirection)
|
|
//int segment=Owner->RouteWish(pCurrentTrack); //numer segmentu dla skrzyżowań
|
|
//pCurrentTrack->SwitchForced(abs(segment)-1,NULL); //tymczasowo ustawienie tego segmentu
|
|
//pCurrentSegment=pCurrentTrack->CurrentSegment(); //odświeżyć sobie wskaźnik segmentu
|
|
(?)
|
|
}
|
|
*/
|
|
if (s < 0)
|
|
{ // jeśli przekroczenie toru od strony Point1
|
|
bCanSkip = bPrimary && pCurrentTrack->CheckDynamicObject(Owner);
|
|
if( bCanSkip ) {
|
|
// tylko główna oś przenosi pojazd do innego toru
|
|
// zdejmujemy pojazd z dotychczasowego toru
|
|
Owner->MyTrack->RemoveDynamicObject( Owner );
|
|
}
|
|
dir = fDirection;
|
|
if (pCurrentTrack->eType == tt_Cross)
|
|
{
|
|
if (!SetCurrentTrack(pCurrentTrack->Connected(iSegment, fDirection), 0))
|
|
return false; // wyjście z błędem
|
|
}
|
|
else if (!SetCurrentTrack(pCurrentTrack->Connected(-1, fDirection), 0)) // ustawia fDirection
|
|
return false; // wyjście z błędem
|
|
if (dir == fDirection) //(pCurrentTrack->iPrevDirection)
|
|
{ // gdy kierunek bez zmiany (Point1->Point2)
|
|
fCurrentDistance = pCurrentSegment->GetLength();
|
|
fDistance = s;
|
|
}
|
|
else
|
|
{ // gdy zmiana kierunku toru (Point1->Point1)
|
|
fCurrentDistance = 0;
|
|
fDistance = -s;
|
|
}
|
|
if (bCanSkip)
|
|
{ // jak główna oś, to dodanie pojazdu do nowego toru
|
|
pCurrentTrack->AddDynamicObject(Owner);
|
|
iEventFlag = 3; // McZapkie-020602: umozliwienie uruchamiania event1,2 po zmianie toru
|
|
iEventallFlag = 3; // McZapkie-280503: jw, dla eventall1,2
|
|
if (!Owner->MyTrack)
|
|
return false;
|
|
}
|
|
continue;
|
|
}
|
|
else if (s > pCurrentSegment->GetLength())
|
|
{ // jeśli przekroczenie toru od strony Point2
|
|
bCanSkip = bPrimary && pCurrentTrack->CheckDynamicObject(Owner);
|
|
if (bCanSkip) // tylko główna oś przenosi pojazd do innego toru
|
|
Owner->MyTrack->RemoveDynamicObject(Owner); // zdejmujemy pojazd z dotychczasowego toru
|
|
fDistance = s - pCurrentSegment->GetLength();
|
|
dir = fDirection;
|
|
if (pCurrentTrack->eType == tt_Cross)
|
|
{
|
|
if (!SetCurrentTrack(pCurrentTrack->Connected(iSegment, fDirection), 1))
|
|
return false; // wyjście z błędem
|
|
}
|
|
else if (!SetCurrentTrack(pCurrentTrack->Connected(1, fDirection), 1)) // ustawia fDirection
|
|
return false; // wyjście z błędem
|
|
if (dir != fDirection) //(pCurrentTrack->iNextDirection)
|
|
{ // gdy zmiana kierunku toru (Point2->Point2)
|
|
fDistance = -fDistance; //(s-pCurrentSegment->GetLength());
|
|
fCurrentDistance = pCurrentSegment->GetLength();
|
|
}
|
|
else // gdy kierunek bez zmiany (Point2->Point1)
|
|
fCurrentDistance = 0;
|
|
if (bCanSkip)
|
|
{ // jak główna oś, to dodanie pojazdu do nowego toru
|
|
pCurrentTrack->AddDynamicObject(Owner);
|
|
iEventFlag = 3; // McZapkie-020602: umozliwienie uruchamiania event1,2 po zmianie toru
|
|
iEventallFlag = 3;
|
|
if (!Owner->MyTrack)
|
|
return false;
|
|
}
|
|
continue;
|
|
}
|
|
else
|
|
{ // gdy zostaje na tym samym torze (przesuwanie już nie zmienia toru)
|
|
if (bPrimary)
|
|
{ // tylko gdy początkowe ustawienie, dodajemy eventy stania do kolejki
|
|
if (Owner->MoverParameters->CabOccupied != 0) {
|
|
|
|
pCurrentTrack->QueueEvents( pCurrentTrack->m_events1, Owner, -1.0 );
|
|
pCurrentTrack->QueueEvents( pCurrentTrack->m_events2, Owner, -1.0 );
|
|
}
|
|
pCurrentTrack->QueueEvents( pCurrentTrack->m_events1all, Owner, -1.0 );
|
|
pCurrentTrack->QueueEvents( pCurrentTrack->m_events2all, Owner, -1.0 );
|
|
}
|
|
fCurrentDistance = s;
|
|
return ComputatePosition(); // przeliczenie XYZ, true o ile nie wyjechał na NULL
|
|
}
|
|
}
|
|
};
|
|
|
|
double TTrackFollower::RailPhase( double const Offset ) const {
|
|
|
|
return pCurrentTrack != nullptr ? pCurrentTrack->rail_phase( fCurrentDistance + fDirection * Offset ) : -1.0;
|
|
}
|
|
|
|
double TTrackFollower::BuckleCurvature( double const Base ) const {
|
|
|
|
return pCurrentTrack != nullptr ? pCurrentTrack->buckle_curvature( fCurrentDistance, Base ) : 0.0;
|
|
}
|
|
|
|
glm::dvec3 TTrackFollower::PathDirection( double const Reach ) const {
|
|
|
|
if( pCurrentSegment == nullptr ) {
|
|
return glm::dvec3 { 0.0 };
|
|
}
|
|
auto const length { pCurrentSegment->GetLength() };
|
|
glm::dvec3 ahead;
|
|
glm::dvec3 behind;
|
|
glm::vec3 rotation;
|
|
pCurrentSegment->RaPositionGet( std::clamp( fCurrentDistance + Reach, 0.0, length ), ahead, rotation );
|
|
pCurrentSegment->RaPositionGet( std::clamp( fCurrentDistance - Reach, 0.0, length ), behind, rotation );
|
|
glm::dvec3 const direction { ( ahead.x - behind.x ) * fDirection, 0.0, ( ahead.z - behind.z ) * fDirection };
|
|
auto const size { glm::length( direction ) };
|
|
return size > 1e-6 ? direction / size : glm::dvec3 { 0.0 };
|
|
}
|
|
|
|
bool TTrackFollower::ComputatePosition()
|
|
{ // ustalenie współrzędnych XYZ
|
|
if (pCurrentSegment) // o ile jest tor
|
|
{
|
|
pCurrentSegment->RaPositionGet(fCurrentDistance, pPosition, vAngles);
|
|
if (fDirection < 0) // kąty zależą jeszcze od zwrotu na torze
|
|
{ // kąty są w przedziale <-M_PI;M_PI>
|
|
vAngles.x = -vAngles.x; // przechyłka jest w przecinwą stronę
|
|
vAngles.y = -vAngles.y; // pochylenie jest w przecinwą stronę
|
|
vAngles.z +=
|
|
vAngles.z >= M_PI ? -M_PI : M_PI; // ale kierunek w planie jest obrócony o 180°
|
|
}
|
|
if (fOffsetH != 0.0)
|
|
{ // jeśli przesunięcie względem osi toru, to je doliczyć
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|