17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-18 10:19:20 +02:00

Fix/sonar maintainability rebased (#209)

* refactor(sonar): use override instead of redundant virtual (cpp:S3471)

* refactor(sonar): remove empty statements, one declaration per statement (cpp:S1116, cpp:S1659)

* refactor(sonar): drop redundant lambda return types (cpp:S3574)

* refactor(sonar): prefer using over typedef (cpp:S5416)

* refactor(sonar): use =default for trivial special members (cpp:S3490)

* refactor(sonar): use nullptr literal (cpp:S4962)

* refactor(sonar): remove redundant access specifiers (cpp:S3539)

* refactor(sonar): remove redundant casts (cpp:S1905)

* refactor(sonar): use std::scoped_lock instead of std::lock_guard (cpp:S5997)

* refactor(sonar): construct elements in place with emplace_back (cpp:S6003)

* refactor(sonar): make narrowing conversions explicit (cpp:S5276)

* refactor(sonar): mark unused parameters (cpp:S1172)

Unused names are commented out; parameters used only on some platforms
are marked [[maybe_unused]].

* refactor(sonar): declare non-mutating member functions const (cpp:S5817)

Virtual functions are left untouched so overrides keep matching.

* refactor(sonar): merge collapsible nested if statements (cpp:S1066)

Comments that preceded the inner if are kept above the merged statement.

* refactor(sonar): scope single-use variables in if init-statements (cpp:S6004)

* fix(sonar): give polymorphic base classes virtual destructors (cpp:S1235)

* refactor(sonar): use try_emplace for map insertion (cpp:S6030)

* refactor(sonar): use auto where the type is spelled out on the right (cpp:S5827)

* refactor(sonar): remove redundant parentheses (cpp:S1110)

* refactor(sonar): document intentionally empty functions (cpp:S1186)

* refactor(sonar): remove dead stores (cpp:S1854)

Side effects (e.g. LISTLINE++) are kept.

* refactor(sonar): remove unused variables, captures and private fields (cpp:S1481, cpp:S1068)

* refactor(sonar): use structured bindings for pair access (cpp:S6005)

* refactor(sonar): use range-based loops and ranges algorithms (cpp:S5566)

* refactor(sonar): split chained assignments (cpp:S1121)

* refactor(sonar): add default cases to switch statements (cpp:S3562)

* refactor(sonar): use std::size for array lengths (cpp:S7127)

* refactor(sonar): use std::ranges algorithms and std::erase(_if) (cpp:S6197)

* refactor(sonar): access static members through the class (cpp:S2209)

* refactor(sonar): add braces around nested if-else (cpp:S5261)

* refactor(sonar): avoid side effects inside typeid operands (cpp:S5279)

* refactor(sonar): drop top-level const from by-value return types (cpp:S5951)

* refactor(sonar): declare variables separately from their type definitions (cpp:S3646)

* refactor(sonar): declare loop counters in the for statement (cpp:S5955)

* refactor(sonar): rely on class template argument deduction (cpp:S6012)

* refactor(sonar): inherit base constructors instead of forwarding them (cpp:S5952)

* refactor(sonar): rename locals that shadow outer declarations (cpp:S1117)

Only local variables and definition parameters are renamed; shadowing
struct fields and enumerators in headers are left for a separate change.

* refactor(sonar): reduce enum qualification with using enum (cpp:S6177)

Applied only where no unqualified name in the block could be captured by
the introduced enumerators.

* refactor(sonar): mark converting constructors explicit (cpp:S1709)

sound_source and the gl::object conversion operators stay implicit; they
are relied upon by copy-list-initialisation and GL calls.

* refactor(sonar): initialise members in initialiser lists or declarations (cpp:S3230)

* refactor(sonar): make read-only local references and pointers const (cpp:S5350)

* refactor(sonar): take read-only pointer and reference parameters as const (cpp:S995)

TTrain command handlers keep their signature, it is fixed by the handler table.

* refactor(sonar): pass expensive-to-copy parameters by const reference (cpp:S1238)

Signatures declared in files touched by PR 206 (Driver.h, EU07.cpp) and
virtual overrides are left unchanged.

* refactor(sonar): use transparent comparators for string-keyed maps (cpp:S6045)

std::unordered_map instances and map types exposed in headers used by
other modules are left as they are.

* fix(sonar): do not use UI text as a printf format string (cpp:S5281)

Text lines containing '%' would otherwise be interpreted as format
specifiers by ImGui::TextColored.

* refactor(sonar): use std::bind_front for callbacks (cpp:S5995)

* refactor(sonar): drop const_cast on string literals passed to the Python C API (cpp:S859)

* refactor(sonar): take read-only string parameters as std::string_view (cpp:S6009)

The Windows messaging helpers keep std::string, they need c_str().

* refactor(sonar): make read-only global tables const (cpp:S5421)

Mutable global state (flags, timers, singletons) is left as is.

* refactor(sonar): replace single-case switch statements with if (cpp:S1301)

* refactor(sonar): format UUIDs and log timestamps with std::format (cpp:S6494, cpp:S5945)

* refactor(sonar): use std::array for local fixed-size arrays (cpp:S5945)

Arrays that are class members or part of headers are left unchanged.

* fix(sonar): test the bearing damage bit, not bit 0 (cpp:S872)

'DamageFlag & dtrain_bearing > 0' parsed as 'DamageFlag & (dtrain_bearing > 0)',
i.e. DamageFlag & 1, so bearing friction reacted to the wrong damage flag.

* refactor(sonar): assorted small fixes

- empty() instead of size() comparisons (cpp:S1155)
- member initialisers in declaration order (cpp:S3229)
- no redundant c_str() when a std::string is accepted (cpp:S7121)
- contains() on associative containers (cpp:S6171)
- const reference instead of a copying range-for (cpp:S6032)
- starts_with() for prefix checks (cpp:S6178)
- no std::move on temporaries (cpp:S5274)
- has_value() on std::optional (cpp:S7172)
- bool literals for bool members (cpp:S5820)
- inline only on the definition (cpp:S3548)
- explicit base access specifier (cpp:S5965)
- explicit element access instead of dereferencing an array (cpp:S7116)
- rely on the C++20 rewritten operator!= (cpp:S6186)

* refactor(sonar): more small fixes

- std::format instead of iostream manipulators in to_string/to_hex_str (cpp:S6495);
  output verified identical, negative hex values keep the unsigned form
- remove an empty compound statement (cpp:S108)
- drop an always-false unsigned < 0 branch (cpp:S1768)
- explicit lambda capture (cpp:S3608)
- std::make_unique (cpp:S5950)

* chore: strip stray carriage returns left in TTrain constructor comments

* fix: keep quantize() in its own value type

The S5276 change cast the result of the generic quantize<Type_>() to
unsigned int, which truncated float/double callers (shadow angle slider,
editor rotation snapping, AI speed control steps) and broke negative values.

* fix(sonar): use integer loop counters in segment sampling (cpp:S2193)

* refactor(sonar): clean up issues reported on PR 209

- remove locals left unused after the dead-store cleanup (cpp:S1481, cpp:S1854)
- unnamed unused parameter (cpp:S1172)
- single-use declarations moved into if init-statements (cpp:S6004)
- auto for casted initialisers (cpp:S5827)
- const references and pointers where nothing is modified (cpp:S5350)
- rename structured bindings shadowed by inner declarations (cpp:S1117)
This commit is contained in:
jerrrrycho
2026-10-11 13:22:33 +02:00
committed by GitHub
parent c26041f2e7
commit 6263fe539b
162 changed files with 4220 additions and 4598 deletions

View File

@@ -114,10 +114,9 @@ TTraction::Load( cParser *parser, glm::dvec3 const &pOrigin ) {
// SKB70-C, CuCd70-2C, KB95-2C, C95-C, C95-2C, YC95-2C, YpC95-2C, YC120-2C
// YpC120-2C, YzC120-2C, YwsC120-2C, YC150-C150, YC150-2C150, C150-C150
// C120-2C, 2C120-2C, 2C120-2C-1, 2C120-2C-2, 2C120-2C-3, 2C120-2C-4
auto const material = parser->getToken<std::string>();
// 1=miedziana, rysuje się na zielono albo czerwono
// 2=aluminiowa, rysuje się na czarno
if( material == "none" ) { Material = 0; }
if( auto const material = parser->getToken<std::string>(); material == "none" ) { Material = 0; }
else if( material == "al" ) { Material = 2; }
else { Material = 1; }
parser->getTokens( 2 );
@@ -131,7 +130,7 @@ TTraction::Load( cParser *parser, glm::dvec3 const &pOrigin ) {
auto const minheight { parser->getToken<double>() };
fHeightDifference = ( pPoint3.y - pPoint1.y + pPoint4.y - pPoint2.y ) * 0.5 - minheight;
auto const segmentlength { parser->getToken<double>() };
iNumSections = segmentlength ? glm::length(pPoint1 - pPoint2) / segmentlength : 0;
iNumSections = segmentlength != 0.0 ? static_cast<int>(glm::length(pPoint1 - pPoint2) / segmentlength) : 0;
parser->getTokens( 2 );
*parser
>> Wires
@@ -164,7 +163,7 @@ TTraction::endpoints() const {
}
std::size_t
TTraction::create_geometry( gfx::geometrybank_handle const &Bank ) {
TTraction::create_geometry( gfx::geometrybank_handle const &Geometrybank ) {
if( m_geometry != null_handle ) {
return GfxRenderer->Vertices( m_geometry ).size() / 2;
}
@@ -175,7 +174,8 @@ TTraction::create_geometry( gfx::geometrybank_handle const &Bank ) {
if( Wires == 2 )
WireOffset = 0;
// jezdny
gfx::basic_vertex startvertex, endvertex;
gfx::basic_vertex startvertex;
gfx::basic_vertex endvertex;
startvertex.position =
glm::vec3(
pPoint1.x - ( pPoint2.z / ddp - pPoint1.z / ddp ) * WireOffset - m_origin.x,
@@ -189,7 +189,12 @@ TTraction::create_geometry( gfx::geometrybank_handle const &Bank ) {
vertices.emplace_back( startvertex );
vertices.emplace_back( endvertex );
// Nie wiem co 'Marcin
glm::dvec3 pt1, pt2, pt3, pt4, v1, v2;
glm::dvec3 pt1;
glm::dvec3 pt2;
glm::dvec3 pt3;
glm::dvec3 pt4;
glm::dvec3 v1;
glm::dvec3 v2;
v1 = pPoint4 - pPoint3;
v2 = pPoint2 - pPoint1;
float step = 0;
@@ -207,7 +212,7 @@ TTraction::create_geometry( gfx::geometrybank_handle const &Bank ) {
pPoint3.z - m_origin.z );
for( int i = 0; i < iNumSections - 1; ++i ) {
pt3 = pPoint3 + v1 * f;
t = 1 - std::fabs(f - mid) * 2;
t = static_cast<float>(1 - std::fabs(f - mid) * 2);
if( Wires < 4
|| ( i != 0
&& i != iNumSections - 2 ) ) {
@@ -256,7 +261,7 @@ TTraction::create_geometry( gfx::geometrybank_handle const &Bank ) {
pPoint3.z - m_origin.z );
for( int i = 0; i < iNumSections - 1; ++i ) {
pt3 = pPoint3 + v1 * f;
t = 1 - std::fabs(f - mid) * 2;
t = static_cast<float>(1 - std::fabs(f - mid) * 2);
endvertex.position =
glm::vec3(
pt3.x - m_origin.x,
@@ -288,7 +293,7 @@ TTraction::create_geometry( gfx::geometrybank_handle const &Bank ) {
for( int i = 0; i < iNumSections - 1; ++i ) {
pt3 = pPoint3 + v1 * f;
pt4 = pPoint1 + v2 * f;
t = 1 - std::fabs(f - mid) * 2;
t = static_cast<float>(1 - std::fabs(f - mid) * 2);
if( i % 2 == 0 ) {
startvertex.position =
glm::vec3(
@@ -338,12 +343,12 @@ TTraction::create_geometry( gfx::geometrybank_handle const &Bank ) {
auto const elementcount = vertices.size() / 2;
gfx::userdata_array empty_userdata{};
m_geometry = GfxRenderer->Insert( vertices, empty_userdata, Bank, GL_LINES );
m_geometry = GfxRenderer->Insert( vertices, empty_userdata, Geometrybank, GL_LINES );
return elementcount;
}
int TTraction::TestPoint(glm::dvec3 const &Point)
int TTraction::TestPoint(glm::dvec3 const &Point) const
{ // sprawdzanie, czy przęsła można połączyć
if( hvNext[0] == nullptr
&& glm::all(glm::epsilonEqual(Point, pPoint1, 0.025)) ) {
@@ -410,7 +415,8 @@ void TTraction::ResistanceCalc(int d, double r, TTractionPowerSource *ps)
{ //(this) jest przęsłem zasilanym, o rezystancji (r), policzyć rezystancję zastępczą sąsiednich
if (d >= 0)
{ // podążanie we wskazanym kierunku
TTraction *t = hvNext[d], *p;
TTraction *t = hvNext[d];
TTraction const *p;
if (ps)
psPower[d ^ 1] = ps; // podłączenie podanego
else
@@ -432,7 +438,7 @@ void TTraction::ResistanceCalc(int d, double r, TTractionPowerSource *ps)
}
}
t->psPower[d] = ps; // skopiowanie wskaźnika zasilacza od danej strony
t->fResistance[d] = r; // wpisanie rezystancji w kierunku tego zasilacza
t->fResistance[d] = static_cast<float>(r); // wpisanie rezystancji w kierunku tego zasilacza
r += t->fResistivity * glm::length(t->vParametric); // doliczenie oporu kolejnego odcinka
p = t; // zapamiętanie dotychczasowego
t = p->hvNext[d ^ 1]; // podążanie w tę samą stronę
@@ -457,17 +463,18 @@ void TTraction::PowerSet(TTractionPowerSource *ps)
else
{ // ustalenie punktu zasilania (nie ma jeszcze połączeń między przęsłami)
psPowered = ps; // ustawienie bezpośredniego zasilania dla przęsła
psPower[0] = psPower[1] = ps; // a to chyba nie jest dobry pomysł, bo nawet zasilane przęsło
psPower[0] = ps; // a to chyba nie jest dobry pomysł, bo nawet zasilane przęsło
psPower[1] = ps;
// powinno mieć wskazania na inne
fResistance[0] = fResistance[1] = 0.0; // a liczy się tylko rezystancja zasilacza
fResistance[0] = 0.0; // a liczy się tylko rezystancja zasilacza
fResistance[1] = 0.0;
}
};
double TTraction::VoltageGet(double u, double i)
{ // pobranie napięcia na przęśle po podłączeniu do niego rezystancji (res) - na razie jest to prąd
if (!psSection)
if (!psPowered)
return NominalVoltage; // jak nie ma zasilacza, to napięcie podane w przęśle
if (!psSection && !psPowered)
return NominalVoltage; // jak nie ma zasilacza, to napięcie podane w przęśle
// na początek można założyć, że wszystkie podstacje mają to samo napięcie i nie płynie prąd
// pomiędzy nimi
// dla danego przęsła mamy 3 źródła zasilania
@@ -485,8 +492,12 @@ double TTraction::VoltageGet(double u, double i)
return 0.0;
}
double r0t, r1t, r0g, r1g;
double i0, i1;
double r0t;
double r1t;
double r0g;
double r1g;
double i0;
double i1;
r0t = fResistance[0]; //średni pomysł, ale lepsze niż nic
r1t = fResistance[1]; // bo nie uwzględnia spadków z innych pojazdów
if (psPower[0] && psPower[1])
@@ -729,29 +740,25 @@ traction_table::InitTraction() {
break;
}
}
if( traction->hvNext[ 0 ] ) {
// jeśli został podłączony
if( traction->psSection != nullptr
&& matchingtraction->psSection != nullptr ) {
// tylko przęsło z izolatorem może nie mieć zasilania, bo ma 2, trzeba sprawdzać sąsiednie
if( traction->psSection != matchingtraction->psSection ) {
// połączone odcinki mają różne zasilacze
// to może być albo podłączenie podstacji lub kabiny sekcyjnej do sekcji, albo błąd
if( true == traction->psSection->bSection
&& false == matchingtraction->psSection->bSection ) {
//(tmp->psSection) jest podstacją, a (Traction->psSection) nazwą sekcji
matchingtraction->PowerSet( traction->psSection ); // zastąpienie wskazaniem sekcji
}
else if( false == traction->psSection->bSection
&& true == matchingtraction->psSection->bSection ) {
//(Traction->psSection) jest podstacją, a (tmp->psSection) nazwą sekcji
traction->PowerSet( matchingtraction->psSection ); // zastąpienie wskazaniem sekcji
}
else {
// jeśli obie to sekcje albo obie podstacje, to będzie błąd
ErrorLog( "Bad scenario: faulty traction power connection at location " + to_string( traction->pPoint1 ) );
}
}
// jeśli został podłączony
// tylko przęsło z izolatorem może nie mieć zasilania, bo ma 2, trzeba sprawdzać sąsiednie
if (traction->hvNext[ 0 ] && traction->psSection != nullptr
&& matchingtraction->psSection != nullptr && traction->psSection != matchingtraction->psSection) {
// połączone odcinki mają różne zasilacze
// to może być albo podłączenie podstacji lub kabiny sekcyjnej do sekcji, albo błąd
if( true == traction->psSection->bSection
&& false == matchingtraction->psSection->bSection ) {
//(tmp->psSection) jest podstacją, a (Traction->psSection) nazwą sekcji
matchingtraction->PowerSet( traction->psSection ); // zastąpienie wskazaniem sekcji
}
else if( false == traction->psSection->bSection
&& true == matchingtraction->psSection->bSection ) {
//(Traction->psSection) jest podstacją, a (tmp->psSection) nazwą sekcji
traction->PowerSet( matchingtraction->psSection ); // zastąpienie wskazaniem sekcji
}
else {
// jeśli obie to sekcje albo obie podstacje, to będzie błąd
ErrorLog( "Bad scenario: faulty traction power connection at location " + to_string( traction->pPoint1 ) );
}
}
}
@@ -768,28 +775,24 @@ traction_table::InitTraction() {
break;
}
}
if( traction->hvNext[ 1 ] ) {
// jeśli został podłączony
if( traction->psSection != nullptr
&& matchingtraction->psSection != nullptr ) {
// tylko przęsło z izolatorem może nie mieć zasilania, bo ma 2, trzeba sprawdzać sąsiednie
if( traction->psSection != matchingtraction->psSection ) {
// to może być albo podłączenie podstacji lub kabiny sekcyjnej do sekcji, albo błąd
if( true == traction->psSection->bSection
&& false == matchingtraction->psSection->bSection ) {
//(tmp->psSection) jest podstacją, a (Traction->psSection) nazwą sekcji
matchingtraction->PowerSet( traction->psSection ); // zastąpienie wskazaniem sekcji
}
else if( false == traction->psSection->bSection
&& true == matchingtraction->psSection->bSection ) {
//(Traction->psSection) jest podstacją, a (tmp->psSection) nazwą sekcji
traction->PowerSet( matchingtraction->psSection ); // zastąpienie wskazaniem sekcji
}
else {
// jeśli obie to sekcje albo obie podstacje, to będzie błąd
ErrorLog( "Bad scenario: faulty traction power connection at location " + to_string( traction->pPoint2 ) );
}
}
// jeśli został podłączony
// tylko przęsło z izolatorem może nie mieć zasilania, bo ma 2, trzeba sprawdzać sąsiednie
if (traction->hvNext[ 1 ] && traction->psSection != nullptr
&& matchingtraction->psSection != nullptr && traction->psSection != matchingtraction->psSection) {
// to może być albo podłączenie podstacji lub kabiny sekcyjnej do sekcji, albo błąd
if( true == traction->psSection->bSection
&& false == matchingtraction->psSection->bSection ) {
//(tmp->psSection) jest podstacją, a (Traction->psSection) nazwą sekcji
matchingtraction->PowerSet( traction->psSection ); // zastąpienie wskazaniem sekcji
}
else if( false == traction->psSection->bSection
&& true == matchingtraction->psSection->bSection ) {
//(Traction->psSection) jest podstacją, a (tmp->psSection) nazwą sekcji
traction->PowerSet( matchingtraction->psSection ); // zastąpienie wskazaniem sekcji
}
else {
// jeśli obie to sekcje albo obie podstacje, to będzie błąd
ErrorLog( "Bad scenario: faulty traction power connection at location " + to_string( traction->pPoint2 ) );
}
}
}
@@ -822,8 +825,7 @@ traction_table::InitTraction() {
}
else if( traction->hvParallel == nullptr ) {
// jeśli jeszcze nie został włączony w kółko
auto *nTemp = find( traction->asParallel );
if( nTemp != nullptr ) {
if( auto *nTemp = find( traction->asParallel ); nTemp != nullptr ) {
// o ile zostanie znalezione przęsło o takiej nazwie
if( nTemp->hvParallel == nullptr ) {
// jeśli tamten jeszcze nie ma wskaźnika bieżni wspólnej