mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-27 21:45:16 +01:00
refactor: no side effects in the right operand of && and || (Sonar S912) (#364)
The ogl initialisation, the -resolution/-margin values of the standalone previews and the submodel lookups of TGauge::Load assign or increment in the right operand of && or ||. Each becomes plain statements which run exactly when the operand ran before: init_ogl() only when needs_ogl(), i advanced only when a value follows (and accepted), and the lookups by name and then by name + "_off" per model, in the same order, leaving submodel, submodelon and m_sourcemodel with the same values.
This commit is contained in:
@@ -211,15 +211,15 @@ void TGauge::Load( cParser &Parser, TDynamicObject const *Owner, double const mu
|
||||
m_sourcemodel = nullptr;
|
||||
std::array<TModel3d *, 2> sources { Owner->mdKabina, Owner->mdLowPolyInt };
|
||||
for( auto const *source : sources ) {
|
||||
if( source != nullptr
|
||||
&& ( submodel = source->GetFromName( submodelname ) ) != nullptr ) {
|
||||
// got what we wanted, bail out
|
||||
m_sourcemodel = source;
|
||||
break;
|
||||
if( source == nullptr ) {
|
||||
continue;
|
||||
}
|
||||
// there's a possibility the default submodel was named with _off suffix
|
||||
if( source != nullptr
|
||||
&& ( submodel = source->GetFromName( submodelname + "_off" ) ) != nullptr ) {
|
||||
submodel = source->GetFromName( submodelname );
|
||||
if( submodel == nullptr ) {
|
||||
// there's a possibility the default submodel was named with _off suffix
|
||||
submodel = source->GetFromName( submodelname + "_off" );
|
||||
}
|
||||
if( submodel != nullptr ) {
|
||||
// got what we wanted, bail out
|
||||
m_sourcemodel = source;
|
||||
break;
|
||||
@@ -231,8 +231,11 @@ void TGauge::Load( cParser &Parser, TDynamicObject const *Owner, double const mu
|
||||
// see if we can locate optional submodel for active state, with _on suffix
|
||||
TSubModel *submodelon { nullptr };
|
||||
for( auto const *source : sources ) {
|
||||
if( source != nullptr
|
||||
&& ( submodelon = source->GetFromName( submodelname + "_on" ) ) != nullptr ) {
|
||||
if( source == nullptr ) {
|
||||
continue;
|
||||
}
|
||||
submodelon = source->GetFromName( submodelname + "_on" );
|
||||
if( submodelon != nullptr ) {
|
||||
// got what we wanted, bail out
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user