16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-18 05:29:18 +02:00

build 180306. locations definiton support for door and traction motors

This commit is contained in:
tmj-fstate
2018-03-06 20:19:34 +01:00
parent 55ae503dbb
commit 24b25ec419
6 changed files with 133 additions and 55 deletions

View File

@@ -282,17 +282,18 @@ private:
int iOverheadZero = 0; // suma bitowa jezdy bezprądowej, bity ustawiane przez pojazdy z podniesionymi pantografami
int iOverheadDown = 0; // suma bitowa opuszczenia pantografów, bity ustawiane przez pojazdy z podniesionymi pantografami
double fVoltage = 0.0; // uśrednione napięcie sieci: przy spadku poniżej wartości minimalnej opóźnić rozruch o losowy czas
private:
private:
double fMaxProximityDist = 50.0; // stawanie między 30 a 60 m przed przeszkodą // akceptowalna odległość stanięcia przed przeszkodą
TStopReason eStopReason = stopSleep; // powód zatrzymania przy ustawieniu zerowej prędkości // na początku śpi
std::string VehicleName;
double fVelPlus = 0.0; // dopuszczalne przekroczenie prędkości na ograniczeniu bez hamowania
double fVelMinus = 0.0; // margines obniżenia prędkości, powodujący załączenie napędu
double fWarningDuration = 0.0; // ile czasu jeszcze trąbić
double fStopTime = 0.0; // czas postoju przed dalszą jazdą (np. na przystanku)
double WaitingTime = 0.0; // zliczany czas oczekiwania do samoistnego ruszenia
double WaitingExpireTime = 31.0; // tyle ma czekać, zanim się ruszy // maksymlany czas oczekiwania do samoistnego ruszenia
double IdleTime {}; // keeps track of time spent at a stop
public:
double fStopTime = 0.0; // czas postoju przed dalszą jazdą (np. na przystanku)
private: //---//---//---//---// koniec zmiennych, poniżej metody //---//---//---//---//
void SetDriverPsyche();

View File

@@ -1008,19 +1008,19 @@ TDynamicObject * TDynamicObject::ABuFindNearestObject(TTrack *Track, TDynamicObj
if( CouplNr == -2 ) {
// wektor [kamera-obiekt] - poszukiwanie obiektu
if( LengthSquared3( Global.pCameraPosition - dynamic->vPosition ) < 100.0 ) {
if( Math3D::LengthSquared3( Global.pCameraPosition - dynamic->vPosition ) < 100.0 ) {
// 10 metrów
return dynamic;
}
}
else {
// jeśli (CouplNr) inne niz -2, szukamy sprzęgu
if( LengthSquared3( Global.pCameraPosition - dynamic->vCoulpler[ 0 ] ) < 25.0 ) {
if( Math3D::LengthSquared3( Global.pCameraPosition - dynamic->vCoulpler[ 0 ] ) < 25.0 ) {
// 5 metrów
CouplNr = 0;
return dynamic;
}
if( LengthSquared3( Global.pCameraPosition - dynamic->vCoulpler[ 1 ] ) < 25.0 ) {
if( Math3D::LengthSquared3( Global.pCameraPosition - dynamic->vCoulpler[ 1 ] ) < 25.0 ) {
// 5 metrów
CouplNr = 1;
return dynamic;
@@ -4576,8 +4576,7 @@ void TDynamicObject::LoadMMediaFile( std::string BaseDir, std::string TypeName,
asAnimName = token + std::to_string( i + 1 );
pants[ i ].smElement[ 4 ] = mdModel->GetFromName( asAnimName );
pants[ i ].smElement[ 4 ]->WillBeAnimated();
/* pants[ i ].yUpdate = UpdatePant;
*/ pants[ i ].yUpdate = std::bind( &TDynamicObject::UpdatePant, this, std::placeholders::_1 );
pants[ i ].yUpdate = std::bind( &TDynamicObject::UpdatePant, this, std::placeholders::_1 );
pants[ i ].fMaxDist = 300 * 300; // nie podnosić w większej odległości
pants[ i ].iNumber = i;
}
@@ -4775,8 +4774,6 @@ void TDynamicObject::LoadMMediaFile( std::string BaseDir, std::string TypeName,
pAnimations[i + j].fSpeed = (pAnimations[i + j].fSpeed + 100) / 100;
// Ra: te współczynniki są bez sensu, bo modyfikują wektor przesunięcia
}
// create sound emitters for the door
m_doorsounds.emplace_back();
}
}
@@ -4835,11 +4832,28 @@ void TDynamicObject::LoadMMediaFile( std::string BaseDir, std::string TypeName,
else if( ( token == "tractionmotor:" )
&& ( MoverParameters->Power > 0 ) ) {
// plik z dzwiekiem silnika, mnozniki i ofsety amp. i czest.
m_powertrainsounds.motor.deserialize( parser, sound_type::single, sound_parameters::range | sound_parameters::amplitude | sound_parameters::frequency );
m_powertrainsounds.motor.owner( this );
sound_source motortemplate { sound_placement::external };
motortemplate.deserialize( parser, sound_type::single, sound_parameters::range | sound_parameters::amplitude | sound_parameters::frequency );
motortemplate.owner( this );
auto const amplitudedivisor = static_cast<float>( MoverParameters->nmax * 60 + MoverParameters->Power * 3 );
m_powertrainsounds.motor.m_amplitudefactor /= amplitudedivisor;
motortemplate.m_amplitudefactor /= amplitudedivisor;
if( true == m_powertrainsounds.motors.empty() ) {
// fallback for cases without specified motor locations, convert sound template to a single sound source
m_powertrainsounds.motors.emplace_back( motortemplate );
}
else {
//
for( auto &motor : m_powertrainsounds.motors ) {
// apply configuration to all defined motors
// combine potential x- and y-axis offsets of the sound template with z-axis offsets of individual motors
auto motoroffset { motortemplate.offset() };
motoroffset.z = motor.offset().z;
motor = motortemplate;
motor.offset( motoroffset );
}
}
}
else if( token == "inverter:" ) {
@@ -4974,20 +4988,26 @@ void TDynamicObject::LoadMMediaFile( std::string BaseDir, std::string TypeName,
}
else if( token == "dooropen:" ) {
sound_source dooropen { sound_placement::general };
dooropen.deserialize( parser, sound_type::single );
dooropen.owner( this );
sound_source doortemplate { sound_placement::general };
doortemplate.deserialize( parser, sound_type::single );
doortemplate.owner( this );
for( auto &door : m_doorsounds ) {
door.rsDoorOpen = dooropen;
// apply configuration to all defined doors, but preserve their individual offsets
auto const dooroffset { door.rsDoorOpen.offset() };
door.rsDoorOpen = doortemplate;
door.rsDoorOpen.offset( dooroffset );
}
}
else if( token == "doorclose:" ) {
sound_source doorclose { sound_placement::general };
doorclose.deserialize( parser, sound_type::single );
doorclose.owner( this );
sound_source doortemplate { sound_placement::general };
doortemplate.deserialize( parser, sound_type::single );
doortemplate.owner( this );
for( auto &door : m_doorsounds ) {
door.rsDoorClose = doorclose;
// apply configuration to all defined doors, but preserve their individual offsets
auto const dooroffset { door.rsDoorClose.offset() };
door.rsDoorClose = doortemplate;
door.rsDoorClose.offset( dooroffset );
}
}
@@ -5032,6 +5052,61 @@ void TDynamicObject::LoadMMediaFile( std::string BaseDir, std::string TypeName,
} // sounds:
else if( token == "locations:" ) {
do {
token = "";
parser.getTokens(); parser >> token;
if( token == "doors:" ) {
// a list of pairs: offset along vehicle's z-axis and sides on which the door is present; followed with "end"
while( ( ( token = parser.getToken<std::string>() ) != "" )
&& ( token != "end" ) ) {
// vehicle faces +Z in 'its' space, for door locations negative value means ahead of centre
auto const offset { std::atof( token.c_str() ) * -1.f };
// recognized side specifications are "right", "left" and "both"
auto const sides { parser.getToken<std::string>() };
// NOTE: we skip setting owner of the sounds, it'll be done during individual sound deserialization
door_sounds door;
// add entries to the list:
if( ( sides == "both" )
|| ( sides == "left" ) ) {
// left...
auto const location { glm::vec3 { MoverParameters->DimHalf.x, MoverParameters->DimHalf.y, offset } };
door.rsDoorClose.offset( location );
door.rsDoorOpen.offset( location );
m_doorsounds.emplace_back( door );
}
if( ( sides == "both" )
|| ( sides == "right" ) ) {
// ...and right
auto const location { glm::vec3 { -MoverParameters->DimHalf.x, MoverParameters->DimHalf.y, offset } };
door.rsDoorClose.offset( location );
door.rsDoorOpen.offset( location );
m_doorsounds.emplace_back( door );
}
}
}
else if( token == "tractionmotors:" ) {
// a list of offsets along vehicle's z-axis; followed with "end"
while( ( ( token = parser.getToken<std::string>() ) != "" )
&& ( token != "end" ) ) {
// vehicle faces +Z in 'its' space, for motor locations negative value means ahead of centre
auto const offset { std::atof( token.c_str() ) * -1.f };
// NOTE: we skip setting owner of the sounds, it'll be done during individual sound deserialization
sound_source motor { sound_placement::external }; // generally traction motor
// add entry to the list
auto const location { glm::vec3 { 0.f, 0.f, offset } };
motor.offset( location );
m_powertrainsounds.motors.emplace_back( motor );
}
}
} while( ( token != "" )
&& ( token != "endlocations" ) );
} // locations:
else if( token == "internaldata:" ) {
// dalej nie czytaj
do {
@@ -5245,25 +5320,13 @@ void TDynamicObject::LoadMMediaFile( std::string BaseDir, std::string TypeName,
// zliczanie wcześniejszych animacji
dooranimationfirstindex += iAnimType[ i ];
}
std::size_t doorindex { 0 };
for( auto &doorsounds : m_doorsounds ) {
auto submodel { pAnimations[ dooranimationfirstindex + doorindex ].smAnimated };
if( submodel == nullptr ) { continue; }
auto const dooroffset { pAnimations[ dooranimationfirstindex + doorindex ].smAnimated->offset( std::numeric_limits<float>::max() ) };
doorsounds.rsDoorClose.offset( dooroffset );
doorsounds.rsDoorOpen.offset( dooroffset );
++doorindex;
}
// couplers
auto const frontcoupleroffset { glm::vec3{ 0.f, 1.f, MoverParameters->Dim.L * 0.5f } };
auto const frontcoupleroffset { glm::vec3{ 0.f, 1.f, MoverParameters->DimHalf.z } };
m_couplersounds[ side::front ].dsbCouplerAttach.offset( frontcoupleroffset );
m_couplersounds[ side::front ].dsbCouplerDetach.offset( frontcoupleroffset );
m_couplersounds[ side::front ].dsbCouplerStretch.offset( frontcoupleroffset );
m_couplersounds[ side::front ].dsbBufferClamp.offset( frontcoupleroffset );
auto const rearcoupleroffset{ glm::vec3{ 0.f, 1.f, MoverParameters->Dim.L * -0.5f } };
auto const rearcoupleroffset{ glm::vec3{ 0.f, 1.f, MoverParameters->DimHalf.z * -1.f } };
m_couplersounds[ side::rear ].dsbCouplerAttach.offset( rearcoupleroffset );
m_couplersounds[ side::rear ].dsbCouplerDetach.offset( rearcoupleroffset );
m_couplersounds[ side::rear ].dsbCouplerStretch.offset( rearcoupleroffset );
@@ -5958,10 +6021,12 @@ TDynamicObject::powertrain_sounds::render( TMoverParameters const &Vehicle, doub
// motor sounds
volume = 0.0;
if( ( true == Vehicle.Mains )
&& ( false == Vehicle.dizel_enginestart ) ) {
&& ( false == Vehicle.dizel_enginestart )
&& ( false == motors.empty() ) ) {
if( std::fabs( Vehicle.enrot ) > 0.01 ) {
auto const &motor { motors.front() };
// frequency calculation
auto normalizer { 1.f };
if( true == motor.is_combined() ) {
@@ -6023,19 +6088,28 @@ TDynamicObject::powertrain_sounds::render( TMoverParameters const &Vehicle, doub
volume *= std::max( 0.25f, motor_momentum );
if( motor_volume >= 0.05 ) {
motor
.pitch( frequency )
.gain( motor_volume )
.play( sound_flags::exclusive | sound_flags::looping );
// apply calculated parameters to all motor instances
for( auto &motor : motors ) {
motor
.pitch( frequency )
.gain( motor_volume )
.play( sound_flags::exclusive | sound_flags::looping );
}
}
}
else {
motor.stop();
// stop all motor instances
for( auto &motor : motors ) {
motor.stop();
}
}
}
motor_volume = interpolate( motor_volume, volume, 0.25 );
if( motor_volume < 0.05 ) {
motor.stop();
// stop all motor instances
for( auto &motor : motors ) {
motor.stop();
}
}
// inverter sounds
if( Vehicle.EngineType == ElectricInductionMotor ) {

View File

@@ -302,7 +302,7 @@ private:
struct powertrain_sounds {
sound_source inverter { sound_placement::engine };
sound_source motor { sound_placement::external }; // generally traction motor
std::vector<sound_source> motors; // generally traction 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 };

View File

@@ -305,9 +305,6 @@ Name( NameInit )
WriteLog("init default physic values for " + NameInit + ", [" + TypeNameInit + "], [" +
LoadTypeInitial + "]");
Dim = TDimension();
DimHalf.x = 0.5 * Dim.W; // połowa szerokości, OX jest w bok?
DimHalf.y = 0.5 * Dim.L; // połowa długości, OY jest do przodu?
DimHalf.z = 0.5 * Dim.H; // połowa wysokości, OZ jest w górę?
// BrakeLevelSet(-2); //Pascal ustawia na 0, przestawimy na odcięcie (CHK jest jeszcze nie wczytane!)
iLights[ 0 ] = 0;
@@ -6240,17 +6237,12 @@ bool TMoverParameters::Physic_ReActivation(void) // DO PRZETLUMACZENIA NA KONCU
// *************************************************************************************************
// FUNKCJE PARSERA WCZYTYWANIA PLIKU FIZYKI POJAZDU
// *************************************************************************************************
std::string p0, p1, p2, p3, p4, p5, p6, p7;
std::string vS;
int vI;
double vD;
bool startBPT;
bool startMPT, startMPT0;
bool startRLIST;
bool startDLIST, startFFLIST, startWWLIST;
bool startLIGHTSLIST;
int LISTLINE;
std::vector<std::string> x;
// *************************************************************************************************
// Q: 20160717
@@ -7059,6 +7051,11 @@ void TMoverParameters::LoadFIZ_Dimensions( std::string const &line ) {
extract_value( Dim.L, "L", line, "" );
extract_value( Dim.H, "H", line, "" );
extract_value( Dim.W, "W", line, "" );
DimHalf.x = 0.5 * Dim.W; // połowa szerokości, OX jest w bok?
DimHalf.y = 0.5 * Dim.L; // połowa długości, OY jest do przodu?
DimHalf.z = 0.5 * Dim.H; // połowa wysokości, OZ jest w górę?
extract_value( Cx, "Cx", line, "0.3" );
if( Dim.H <= 2.0 ) {
//gdyby nie było parametru, lepsze to niż zero

View File

@@ -1186,9 +1186,15 @@ TWorld::Update_UI() {
" Pressure: " + to_string( mover->BrakePress * 100.0, 2 ) + " kPa"
+ " (train pipe: " + to_string( mover->PipePress * 100.0, 2 ) + " kPa)";
auto const trackblockdistance{ std::abs( Controlled->Mechanik->TrackBlock() ) };
if( trackblockdistance <= 75.0 ) {
uitextline4 += " Another vehicle ahead (distance: " + to_string( trackblockdistance, 1 ) + " m)";
auto const stoptime { static_cast<int>( -1.0 * Controlled->Mechanik->fStopTime ) };
if( stoptime > 0 ) {
uitextline4 += " Loading/unloading in progress (" + to_string( stoptime ) + ( stoptime > 1 ? " seconds" : " second" ) + " left)";
}
else {
auto const trackblockdistance{ std::abs( Controlled->Mechanik->TrackBlock() ) };
if( trackblockdistance <= 75.0 ) {
uitextline4 += " Another vehicle ahead (distance: " + to_string( trackblockdistance, 1 ) + " m)";
}
}
}
}
@@ -1342,7 +1348,7 @@ TWorld::Update_UI() {
if( ( vehicle->MoverParameters->BrakeDelayFlag & bdelay_M ) == bdelay_M )
uitextline2 += "+Mg";
uitextline2 += ", Load: " + to_string( vehicle->MoverParameters->LoadFlag, 0 ) + " (" + to_string( vehicle->MoverParameters->Load, 0 ) + ")";
uitextline2 += ", Load: " + to_string( vehicle->MoverParameters->Load, 0 ) + " (" + to_string( vehicle->MoverParameters->LoadFlag, 0 ) + ")";
uitextline2 +=
"; Pant: "

View File

@@ -1,5 +1,5 @@
#pragma once
#define VERSION_MAJOR 18
#define VERSION_MINOR 223
#define VERSION_MINOR 306
#define VERSION_REVISION 0