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

build 180308. location definition for bogies, serial port output fixes

This commit is contained in:
tmj-fstate
2018-03-08 18:15:01 +01:00
parent 24b25ec419
commit 5d60080084
5 changed files with 85 additions and 35 deletions

View File

@@ -3940,7 +3940,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)
@@ -3949,19 +3949,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;
@@ -3978,18 +3979,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 ) {
@@ -4844,9 +4853,8 @@ void TDynamicObject::LoadMMediaFile( std::string BaseDir, std::string TypeName,
m_powertrainsounds.motors.emplace_back( motortemplate );
}
else {
//
// apply configuration to all defined motors
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;
@@ -5034,11 +5042,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:" ) {
@@ -5102,6 +5126,21 @@ void TDynamicObject::LoadMMediaFile( std::string BaseDir, std::string TypeName,
}
}
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" ) );

View File

@@ -394,7 +394,7 @@ private:
sound_source sDepartureSignal { sound_placement::general };
sound_source sHorn1 { sound_placement::external, 5 * EU07_SOUND_RUNNINGNOISECUTOFFRANGE };
sound_source sHorn2 { sound_placement::external, 5 * EU07_SOUND_RUNNINGNOISECUTOFFRANGE };
sound_source rsOuterNoise { sound_placement::external, EU07_SOUND_RUNNINGNOISECUTOFFRANGE };
std::vector<sound_source> m_bogiesounds; // TBD, TODO: wrapper for all bogie-related sounds (noise, brakes, squeal etc)
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, 250.f }; // McZapkie-051202

View File

@@ -5755,8 +5755,8 @@ void TTrain::clear_cab_controls()
btLampkaOgrzewanieSkladu.Clear(11);
btHaslerBrakes.Clear(12); // ciśnienie w cylindrach do odbijania na haslerze
btHaslerCurrent.Clear(13); // prąd na silnikach do odbijania na haslerze
// Jeśli ustawiamy nową wartość dla PoKeys wolna jest 15
// Numer 14 jest używany dla buczka SHP w update_sounds()
// Jeśli ustawiamy nową wartość dla PoKeys wolna jest 15
// other cab controls
// TODO: arrange in more readable manner, and eventually refactor

View File

@@ -239,9 +239,9 @@ void uart_input::poll()
uint16_t pipe_press = (uint16_t)std::min(conf.pipeuart, trainstate.pipe_pressure * 0.1f / conf.pipemax * conf.pipeuart);
uint16_t brake_press = (uint16_t)std::min(conf.brakeuart, trainstate.brake_pressure * 0.1f / conf.brakemax * conf.brakeuart);
uint16_t hv_voltage = (uint16_t)std::min(conf.hvuart, trainstate.hv_voltage / conf.hvmax * conf.hvuart);
uint16_t current1 = (uint16_t)std::min(conf.currentuart, trainstate.hv_current[0]) / conf.currentmax * conf.currentuart;
uint16_t current2 = (uint16_t)std::min(conf.currentuart, trainstate.hv_current[1]) / conf.currentmax * conf.currentuart;
uint16_t current3 = (uint16_t)std::min(conf.currentuart, trainstate.hv_current[2]) / conf.currentmax * conf.currentuart;
uint16_t current1 = (uint16_t)std::min(conf.currentuart, trainstate.hv_current[0] / conf.currentmax * conf.currentuart);
uint16_t current2 = (uint16_t)std::min(conf.currentuart, trainstate.hv_current[1] / conf.currentmax * conf.currentuart);
uint16_t current3 = (uint16_t)std::min(conf.currentuart, trainstate.hv_current[2] / conf.currentmax * conf.currentuart);
std::array<uint8_t, 31> buffer {
//byte 0
@@ -269,15 +269,26 @@ void uart_input::poll()
| trainstate.line_breaker << 5
| trainstate.compressor_overload << 6),
//byte 6
(uint8_t)( trainstate.alerter_sound << 7),
SPLIT_INT16(brake_press), //byte 7-8
SPLIT_INT16(pipe_press), //byte 9-10
SPLIT_INT16(tank_press), //byte 11-12
SPLIT_INT16(hv_voltage), //byte 13-14
SPLIT_INT16(current1), //byte 15-16
SPLIT_INT16(current2), //byte 17-18
SPLIT_INT16(current3), //byte 19-20
0, 0, 0, 0, 0, 0, 0, 0, 0, 0 //byte 21-30
(uint8_t)(
trainstate.recorder_braking << 3
| trainstate.recorder_power << 4
| trainstate.alerter_sound << 7),
//byte 7-8
SPLIT_INT16(brake_press),
//byte 9-10
SPLIT_INT16(pipe_press),
//byte 11-12
SPLIT_INT16(tank_press),
//byte 13-14
SPLIT_INT16(hv_voltage),
//byte 15-16
SPLIT_INT16(current1),
//byte 17-18
SPLIT_INT16(current2),
//byte 19-20
SPLIT_INT16(current3),
//byte 21-30
0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
if (conf.debug)

View File

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