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:
@@ -393,10 +393,14 @@ int eu07_application::init(int Argc, char *Argv[])
|
|||||||
ErrorLog("Failed to initialize glfw!");
|
ErrorLog("Failed to initialize glfw!");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if (needs_ogl() && (result = init_ogl()) != 0)
|
if (needs_ogl())
|
||||||
{
|
{
|
||||||
ErrorLog("Failed to initialize ogl!");
|
result = init_ogl();
|
||||||
return result;
|
if (result != 0)
|
||||||
|
{
|
||||||
|
ErrorLog("Failed to initialize ogl!");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (crashreport_is_pending() && false == Global.test.enabled)
|
if (crashreport_is_pending() && false == Global.test.enabled)
|
||||||
|
|||||||
@@ -76,19 +76,21 @@ bool parse_arguments(int const Argc, char *Argv[], preview_settings &Settings)
|
|||||||
}
|
}
|
||||||
else if (token == "-resolution")
|
else if (token == "-resolution")
|
||||||
{
|
{
|
||||||
if ((i + 1 >= Argc) || (false == parse_number(Argv[++i], Settings.resolution)) || (Settings.resolution < 16))
|
if ((i + 1 >= Argc) || (false == parse_number(Argv[i + 1], Settings.resolution)) || (Settings.resolution < 16))
|
||||||
{
|
{
|
||||||
report("-resolution needs a number of pixels, 16 or more", true);
|
report("-resolution needs a number of pixels, 16 or more", true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
++i;
|
||||||
}
|
}
|
||||||
else if (token == "-margin")
|
else if (token == "-margin")
|
||||||
{
|
{
|
||||||
if ((i + 1 >= Argc) || (false == parse_number(Argv[++i], Settings.margin)) || (Settings.margin < 0))
|
if ((i + 1 >= Argc) || (false == parse_number(Argv[i + 1], Settings.margin)) || (Settings.margin < 0))
|
||||||
{
|
{
|
||||||
report("-margin needs a number of pixels, 0 or more", true);
|
report("-margin needs a number of pixels, 0 or more", true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
++i;
|
||||||
}
|
}
|
||||||
else if (token == "-no-shadows")
|
else if (token == "-no-shadows")
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -211,15 +211,15 @@ void TGauge::Load( cParser &Parser, TDynamicObject const *Owner, double const mu
|
|||||||
m_sourcemodel = nullptr;
|
m_sourcemodel = nullptr;
|
||||||
std::array<TModel3d *, 2> sources { Owner->mdKabina, Owner->mdLowPolyInt };
|
std::array<TModel3d *, 2> sources { Owner->mdKabina, Owner->mdLowPolyInt };
|
||||||
for( auto const *source : sources ) {
|
for( auto const *source : sources ) {
|
||||||
if( source != nullptr
|
if( source == nullptr ) {
|
||||||
&& ( submodel = source->GetFromName( submodelname ) ) != nullptr ) {
|
continue;
|
||||||
// got what we wanted, bail out
|
|
||||||
m_sourcemodel = source;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
// there's a possibility the default submodel was named with _off suffix
|
submodel = source->GetFromName( submodelname );
|
||||||
if( source != nullptr
|
if( submodel == nullptr ) {
|
||||||
&& ( submodel = source->GetFromName( submodelname + "_off" ) ) != 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
|
// got what we wanted, bail out
|
||||||
m_sourcemodel = source;
|
m_sourcemodel = source;
|
||||||
break;
|
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
|
// see if we can locate optional submodel for active state, with _on suffix
|
||||||
TSubModel *submodelon { nullptr };
|
TSubModel *submodelon { nullptr };
|
||||||
for( auto const *source : sources ) {
|
for( auto const *source : sources ) {
|
||||||
if( source != nullptr
|
if( source == nullptr ) {
|
||||||
&& ( submodelon = source->GetFromName( submodelname + "_on" ) ) != nullptr ) {
|
continue;
|
||||||
|
}
|
||||||
|
submodelon = source->GetFromName( submodelname + "_on" );
|
||||||
|
if( submodelon != nullptr ) {
|
||||||
// got what we wanted, bail out
|
// got what we wanted, bail out
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user