mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-19 16:55:10 +01:00
feat: controller position marker of the diesel locomotives (#74)
The mainctrlact: gauge showed MainCtrlActualPos, which nothing sets for DieselEngine/DieselElectric without an EIM controller, so the ST43's marker never moved. For those it now follows MainCtrlPos (vehicle/mainctrlact.h); every other vehicle reads what it did before. New optional gauge key scaletable: [ value scaled, ... ] in the block form gives a non-uniform scale, interpolated linearly between its points, in the units of value * scale + offset; without it gauges behave as before. Assets: none needed. To get the true ST43 scale, the line "mainctrlact: stery_1 rot -0.016 0 0.0" of dynamic/pkp/st43_v1/*.mmd is to become a block with a scaletable: of the 25 positions read off the cab's scale; until then the marker moves linearly with -0.016 turn per position.
This commit is contained in:
@@ -152,6 +152,12 @@ void TGauge::Load( cParser &Parser, TDynamicObject const *Owner, double const mu
|
||||
while( true == Load_mapping( Parser, scratchpad ) ) {
|
||||
// all work done by while()
|
||||
}
|
||||
// the values of the table are in the units the config uses for the scale, which the multiplier converts the gauge's value to
|
||||
for( auto &point : scratchpad.scaletable ) {
|
||||
point.value = static_cast<float>( point.value / mul );
|
||||
}
|
||||
gauge_scale::sort( scratchpad.scaletable );
|
||||
m_scaletable = std::move( scratchpad.scaletable );
|
||||
// post-deserialization cleanup
|
||||
// set provided custom soundproofing to assigned sounds (for sounds without their own custom soundproofing)
|
||||
if( scratchpad.soundproofing ) {
|
||||
@@ -275,6 +281,10 @@ TGauge::Load_mapping( cParser &Input, TGauge::scratch_data &Scratchpad ) {
|
||||
>> soundproofing[ 5 ];
|
||||
Scratchpad.soundproofing = soundproofing;
|
||||
}
|
||||
else if( key == "scaletable:" ) {
|
||||
// non-uniform scale in format [ value1 scaled1, value2 scaled2, ... ]
|
||||
return Load_scaletable( Input, Scratchpad );
|
||||
}
|
||||
else if( key.starts_with("sound") ) {
|
||||
// sounds assigned to specific gauge values, defined by key soundX: where X = value
|
||||
auto const indexstart { key.find_first_of( "-1234567890" ) };
|
||||
@@ -288,6 +298,20 @@ TGauge::Load_mapping( cParser &Input, TGauge::scratch_data &Scratchpad ) {
|
||||
return true; // return value marks a key: value pair was extracted, nothing about whether it's recognized
|
||||
}
|
||||
|
||||
// imports the optional non-uniform scale (MaSzyna-EU07/maszyna#74); returns false if it ran into the end of the block
|
||||
bool
|
||||
TGauge::Load_scaletable( cParser &Input, TGauge::scratch_data &Scratchpad ) {
|
||||
|
||||
auto table { gauge_scale::read( Input ) };
|
||||
if( table.malformed || false == table.closed || table.points.size() < 2 ) {
|
||||
ErrorLog( "Bad model: malformed scaletable of a gauge, it needs [ value scaled, value scaled, ... ] with at least two pairs", logtype::model );
|
||||
}
|
||||
if( table.points.size() >= 2 ) {
|
||||
Scratchpad.scaletable = std::move( table.points );
|
||||
}
|
||||
return false == table.block_end;
|
||||
}
|
||||
|
||||
// ustawienie wartości docelowej. plays provided fallback sound, if no sound was defined in the control itself
|
||||
bool
|
||||
TGauge::UpdateValue( float fNewDesired, std::optional<sound_source> &Fallbacksound ) {
|
||||
@@ -446,6 +470,9 @@ void TGauge::AssignState( bool const *State ) {
|
||||
|
||||
float TGauge::GetScaledValue() const {
|
||||
|
||||
if( false == m_scaletable.empty() ) {
|
||||
return gauge_scale::interpolate( m_scaletable, m_value );
|
||||
}
|
||||
return false == m_interpolatescale ? m_value * m_scale + m_offset : m_value * std::lerp(m_scale, m_endscale, std::clamp(m_value / m_endvalue, 0.f, 1.f)) + m_offset;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user