Merge branch 'tmj-dev'

This commit is contained in:
milek7
2018-03-09 19:53:05 +01:00
16 changed files with 289 additions and 93 deletions

View File

@@ -1010,19 +1010,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;
@@ -3942,7 +3942,7 @@ void TDynamicObject::RenderSounds() {
}
// szum w czasie jazdy
if( ( GetVelocity() > 0.5 )
&& ( false == rsOuterNoise.empty() )
&& ( false == m_bogiesounds.empty() )
&& ( // compound test whether the vehicle belongs to user-driven consist (as these don't emit outer noise in cab view)
FreeFlyModeFlag ? true : // in external view all vehicles emit outer noise
// Global.pWorld->train() == nullptr ? true : // (can skip this check, with no player train the external view is a given)
@@ -3951,19 +3951,20 @@ void TDynamicObject::RenderSounds() {
Global.CabWindowOpen ? true : // sticking head out we get to hear outer noise
false ) ) {
// frequency calculation
auto const normalizer{ (
true == rsOuterNoise.is_combined() ?
auto const &bogiesound { m_bogiesounds.front() };
// frequency calculation
auto const normalizer { (
true == bogiesound.is_combined() ?
MoverParameters->Vmax * 0.01f :
1.f ) };
frequency =
rsOuterNoise.m_frequencyoffset
+ rsOuterNoise.m_frequencyfactor * MoverParameters->Vel * normalizer;
bogiesound.m_frequencyoffset
+ bogiesound.m_frequencyfactor * MoverParameters->Vel * normalizer;
// volume calculation
volume =
rsOuterNoise.m_amplitudeoffset +
rsOuterNoise.m_amplitudefactor * MoverParameters->Vel;
bogiesound.m_amplitudeoffset +
bogiesound.m_amplitudefactor * MoverParameters->Vel;
if( brakeforceratio > 0.0 ) {
// hamulce wzmagaja halas
volume *= 1 + 0.125 * brakeforceratio;
@@ -3980,18 +3981,26 @@ void TDynamicObject::RenderSounds() {
0.0, 1.0 ) );
if( volume > 0.05 ) {
rsOuterNoise
.pitch( frequency ) // arbitrary limits to prevent the pitch going out of whack
.gain( volume )
.play( sound_flags::exclusive | sound_flags::looping );
// apply calculated parameters to all motor instances
for( auto &bogiesound : m_bogiesounds ) {
bogiesound
.pitch( frequency ) // arbitrary limits to prevent the pitch going out of whack
.gain( volume )
.play( sound_flags::exclusive | sound_flags::looping );
}
}
else {
rsOuterNoise.stop();
// stop all noise instances
for( auto &bogiesound : m_bogiesounds ) {
bogiesound.stop();
}
}
}
else {
// don't play the optional ending sound if the listener switches views
rsOuterNoise.stop( false == FreeFlyModeFlag );
for( auto &bogiesound : m_bogiesounds ) {
bogiesound.stop( false == FreeFlyModeFlag );
}
}
// flat spot sound
if( MoverParameters->CategoryFlag == 1 ) {
@@ -4578,8 +4587,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;
}
@@ -4777,8 +4785,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();
}
}
@@ -4837,11 +4843,27 @@ 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 {
// apply configuration to all defined motors
for( auto &motor : m_powertrainsounds.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:" ) {
@@ -4976,20 +4998,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 );
}
}
@@ -5016,11 +5044,27 @@ void TDynamicObject::LoadMMediaFile( std::string BaseDir, std::string TypeName,
else if( token == "outernoise:" ) {
// szum podczas jazdy:
rsOuterNoise.deserialize( parser, sound_type::single, sound_parameters::amplitude | sound_parameters::frequency, MoverParameters->Vmax );
rsOuterNoise.owner( this );
sound_source noisetemplate { sound_placement::external, EU07_SOUND_RUNNINGNOISECUTOFFRANGE };
noisetemplate.deserialize( parser, sound_type::single, sound_parameters::amplitude | sound_parameters::frequency, MoverParameters->Vmax );
noisetemplate.owner( this );
rsOuterNoise.m_amplitudefactor /= ( 1 + MoverParameters->Vmax );
rsOuterNoise.m_frequencyfactor /= ( 1 + MoverParameters->Vmax );
noisetemplate.m_amplitudefactor /= ( 1 + MoverParameters->Vmax );
noisetemplate.m_frequencyfactor /= ( 1 + MoverParameters->Vmax );
if( true == m_bogiesounds.empty() ) {
// fallback for cases without specified noise locations, convert sound template to a single sound source
m_bogiesounds.emplace_back( noisetemplate );
}
else {
// apply configuration to all defined bogies
for( auto &bogie : m_bogiesounds ) {
// combine potential x- and y-axis offsets of the sound template with z-axis offsets of individual motors
auto bogieoffset { noisetemplate.offset() };
bogieoffset.z = bogie.offset().z;
bogie = noisetemplate;
bogie.offset( bogieoffset );
}
}
}
else if( token == "wheelflat:" ) {
@@ -5034,6 +5078,76 @@ 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->Dim.W * 0.5f, MoverParameters->Dim.H * 0.5f, 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->Dim.W * -0.5f, MoverParameters->Dim.H * 0.5f, 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 );
}
}
else if( token == "bogies:" ) {
// 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 bogie 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 bogienoise { sound_placement::external, EU07_SOUND_RUNNINGNOISECUTOFFRANGE };
// add entry to the list
auto const location { glm::vec3 { 0.f, 0.f, offset } };
bogienoise.offset( location );
m_bogiesounds.emplace_back( bogienoise );
}
}
} while( ( token != "" )
&& ( token != "endlocations" ) );
} // locations:
else if( token == "internaldata:" ) {
// dalej nie czytaj
do {
@@ -5247,25 +5361,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 } };
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->Dim.L * -0.5f } };
m_couplersounds[ side::rear ].dsbCouplerAttach.offset( rearcoupleroffset );
m_couplersounds[ side::rear ].dsbCouplerDetach.offset( rearcoupleroffset );
m_couplersounds[ side::rear ].dsbCouplerStretch.offset( rearcoupleroffset );
@@ -5961,10 +6063,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() ) {
@@ -6026,19 +6130,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 ) {