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

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jerrrrycho
2026-10-10 15:16:28 +02:00
parent 80464d0bc1
commit 8c23c1fe2b
53 changed files with 468 additions and 468 deletions

View File

@@ -34,14 +34,14 @@ int vk_to_glfw_key( int const Keycode ) {
char key = 0;
if (Keycode < 'A') {
key = Keycode;
key = static_cast<char>(Keycode);
} else if (Keycode <= 'Z') {
key = Keycode;
key = static_cast<char>(Keycode);
modifier = GLFW_MOD_SHIFT;
} else if (Keycode < 'a') {
key = Keycode;
key = static_cast<char>(Keycode);
} else if (Keycode <= 'z') {
key = Keycode - 32;
key = static_cast<char>(Keycode - 32);
} else {
ErrorLog("unknown key: " + std::to_string(Keycode));
}
@@ -164,7 +164,7 @@ bool TEventLauncher::check_activation_key() {
bool result = Console::Pressed(key);
char modifier = iKey >> 8;
char modifier = static_cast<char>(iKey >> 8);
if (modifier & GLFW_MOD_SHIFT)
result &= Global.shiftState;
if (modifier & GLFW_MOD_CONTROL)
@@ -239,7 +239,7 @@ bool TEventLauncher::IsRadioActivated() const {
float
TEventLauncher::radius_() {
return std::sqrt( dRadius );
return static_cast<float>(std::sqrt( dRadius ));
}
// serialize() subclass details, sends content of the subclass to provided stream

View File

@@ -67,8 +67,8 @@ bool TSegment::Init(glm::dvec3 &NewPoint1, glm::dvec3 NewCPointOut, glm::dvec3 N
CPointIn = NewCPointIn;
Point2 = NewPoint2;
// poprawienie przechyłki
fRoll1 = glm::radians(fNewRoll1); // Ra: przeliczone jest bardziej przydatne do obliczeń
fRoll2 = glm::radians(fNewRoll2);
fRoll1 = static_cast<float>(glm::radians(fNewRoll1)); // Ra: przeliczone jest bardziej przydatne do obliczeń
fRoll2 = static_cast<float>(glm::radians(fNewRoll2));
bCurve = bIsCurve;
if (Global.bRollFix)
{ // Ra: poprawianie przechyłki
@@ -85,7 +85,7 @@ bool TSegment::Init(glm::dvec3 &NewPoint1, glm::dvec3 NewCPointOut, glm::dvec3 N
Point1.y += w1; // modyfikacja musi być przed policzeniem dalszych parametrów
if (bCurve)
CPointOut.y += w1; // prosty ma wektory jednostkowe
pOwner->MovedUp1(w1); // zwrócić trzeba informację o podwyższeniu podsypki
pOwner->MovedUp1(static_cast<float>(w1)); // zwrócić trzeba informację o podwyższeniu podsypki
}
if (fRoll2 != 0.f)
{
@@ -125,7 +125,7 @@ bool TSegment::Init(glm::dvec3 &NewPoint1, glm::dvec3 NewCPointOut, glm::dvec3 N
fStep = fLength / ( 3.0 * Global.SplineFidelity );
}
// iSegCount = static_cast<int>( std::ceil( fLength / fStep ) ); // potrzebne do VBO
iSegCount = pOwner->eType == tt_Switch ? 6 * Global.SplineFidelity : static_cast<int>(std::ceil(fLength / fStep)); // potrzebne do VBO
iSegCount = pOwner->eType == tt_Switch ? static_cast<int>(6 * Global.SplineFidelity) : static_cast<int>(std::ceil(fLength / fStep)); // potrzebne do VBO
fStep = fLength / iSegCount; // update step to equalize size of individual pieces
@@ -267,7 +267,7 @@ double TSegment::ComputeLength() const // McZapkie-150503: dlugosc miedzy punkta
double l = 0;
glm::dvec3 last{0, 0, 0}; // długość liczona po przesunięciu odcinka do początku układu
glm::dvec3 tmp = Point2 - Point1;
int m = 20.0 * glm::length(tmp); // było zawsze do 10000, teraz jest liczone odcinkami po około 5cm
int m = static_cast<int>(20.0 * glm::length(tmp)); // było zawsze do 10000, teraz jest liczone odcinkami po około 5cm
for (int i = 1; i <= m; i++)
{
t = double(i) / double(m); // wyznaczenie parametru na krzywej z przedziału (0,1>
@@ -372,22 +372,22 @@ void TSegment::RaPositionGet(double const fDistance, glm::dvec3 &position, glm::
auto const t = FastGetTFromS(fDistance); // aproksymacja dystansu na krzywej Beziera na parametr (t)
position = FastGetPoint( t );
// przechyłka w danym miejscu (zmienia się liniowo)
rotation.x = std::lerp( fRoll1, fRoll2, t );
rotation.x = static_cast<float>(std::lerp( fRoll1, fRoll2, t ));
// pochodna
auto const tangent = GetFirstDerivative( t );
// pochylenie krzywej (w pionie)
rotation.y = std::atan( tangent.y );
rotation.y = static_cast<float>(std::atan( tangent.y ));
// kierunek krzywej w planie
rotation.z = -std::atan2( tangent.x, tangent.z );
rotation.z = static_cast<float>(-std::atan2( tangent.x, tangent.z ));
}
else {
// wyliczenie dla odcinka prostego jest prostsze
auto const t = fDistance / fLength; // zerowych torów nie ma
position = FastGetPoint( t );
// przechyłka w danym miejscu (zmienia się liniowo)
rotation.x = std::lerp( fRoll1, fRoll2, t );
rotation.y = fStoop; // pochylenie toru prostego
rotation.z = fDirection; // kierunek toru w planie
rotation.x = static_cast<float>(std::lerp( fRoll1, fRoll2, t ));
rotation.y = static_cast<float>(fStoop); // pochylenie toru prostego
rotation.z = static_cast<float>(fDirection); // kierunek toru w planie
}
};
@@ -420,20 +420,20 @@ bool TSegment::RenderLoft( gfx::vertex_array &Output, glm::dvec3 const &Origin,
float t;
float fEnd;
auto const iNumShapePoints = Transition ? ShapePoints.size() / 2 : ShapePoints.size();
float const texturelength = fTextureLength * Texturescale;
float const texturescale = Texturescale;
float const texturelength = static_cast<float>(fTextureLength * Texturescale);
float const texturescale = static_cast<float>(Texturescale);
float m1;
float jmm1;
float m2;
float jmm2; // pozycje względne na odcinku 0...1 (ale nie parametr Beziera)
step = fStep;
step = static_cast<float>(fStep);
tv1 = 1.0; // Ra: to by można było wyliczać dla odcinka, wyglądało by lepiej
s = fStep * iSkip; // iSkip - ile odcinków z początku pominąć
s = static_cast<float>(fStep * iSkip); // iSkip - ile odcinków z początku pominąć
int i = iSkip; // domyślnie 0
t = fTsBuffer[ i ]; // tabela wattości t dla segmentów
t = static_cast<float>(fTsBuffer[ i ]); // tabela wattości t dla segmentów
// BUG: length of spline can be 0, we should skip geometry generation for such cases
fOffset = 0.1 / fLength; // pierwsze 10cm
fOffset = static_cast<float>(0.1 / fLength); // pierwsze 10cm
pos1 = glm::dvec3{ FastGetPoint( t ) - Origin }; // wektor początku segmentu
dir = glm::dvec3{ FastGetDirection( t, fOffset ) }; // wektor kierunku
parallel1 = glm::vec3{ -dir.z, 0.f, dir.x }; // wektor poprzeczny
@@ -444,11 +444,11 @@ bool TSegment::RenderLoft( gfx::vertex_array &Output, glm::dvec3 const &Origin,
parallel1 = glm::normalize( parallel1 );
if( iEnd == 0 )
iEnd = iSegCount;
fEnd = fLength * double( iEnd ) / double( iSegCount );
fEnd = static_cast<float>(fLength * double( iEnd ) / double( iSegCount ));
/*
m2 = s / fEnd;
*/
m2 = static_cast<float>( i - iSkip ) / ( iEnd - iSkip );
m2 = static_cast<float>( i - iSkip ) / ( static_cast<float>(iEnd - iSkip) );
jmm2 = 1.f - m2;
@@ -461,7 +461,7 @@ bool TSegment::RenderLoft( gfx::vertex_array &Output, glm::dvec3 const &Origin,
/*
m2 = s / fEnd;
*/
m2 = static_cast<float>( i - iSkip ) / ( iEnd - iSkip );
m2 = static_cast<float>( i - iSkip ) / ( static_cast<float>(iEnd - iSkip) );
jmm2 = 1.f - m2; // nowa pozycja
if( i == iEnd ) { // gdy przekroczyliśmy koniec - stąd dziury w torach...
@@ -478,7 +478,7 @@ bool TSegment::RenderLoft( gfx::vertex_array &Output, glm::dvec3 const &Origin,
tv1 = clamp_circular( tv1, 1.0f );
tv2 = tv1 - step / texturelength; // mapowanie na końcu segmentu
t = fTsBuffer[ i ]; // szybsze od GetTFromS(s);
t = static_cast<float>(fTsBuffer[ i ]); // szybsze od GetTFromS(s);
pos2 = glm::dvec3{ FastGetPoint( t ) - Origin };
dir = glm::dvec3{ FastGetDirection( t, fOffset ) }; // nowy wektor kierunku
parallel2 = glm::vec3{ -dir.z, 0.f, dir.x }; // wektor poprzeczny
@@ -565,7 +565,7 @@ bool TSegment::RenderLoft( gfx::vertex_array &Output, glm::dvec3 const &Origin,
void TSegment::render_lines(std::vector<gfx::basic_vertex> &out, float quality) const
{
float step = 1.0f / iSegCount / quality;
float step = 1.0f / static_cast<float>(iSegCount) / quality;
float x;
@@ -586,7 +586,7 @@ void TSegment::render_lines(std::vector<gfx::basic_vertex> &out, float quality)
glm::vec3 TSegment::get_nearest_point(const glm::dvec3 &point, float quality) const
{
float step = 1.0f / iSegCount / quality;
float step = 1.0f / static_cast<float>(iSegCount) / quality;
float x;

View File

@@ -13,8 +13,8 @@ http://mozilla.org/MPL/2.0/.
void TSpring::Init(double nKs, double nKd) {
Ks = nKs;
Kd = nKd;
ks = Ks;
kd = Kd;
ks = static_cast<float>(Ks);
kd = static_cast<float>(Kd);
}
glm::dvec3 TSpring::ComputateForces(glm::dvec3 const &pPosition1, glm::dvec3 const &pPosition2) {

View File

@@ -131,7 +131,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
@@ -213,7 +213,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 ) ) {
@@ -262,7 +262,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,
@@ -294,7 +294,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(
@@ -439,7 +439,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ę

View File

@@ -125,7 +125,7 @@ double TTractionPowerSource::CurrentGet(double res)
}
if (res > 0 || (res < 0 && (Recuperation || true)))
TotalAdmitance += 1.0 / res; // połączenie równoległe rezystancji jest równoważne sumie admitancji
float NomVolt = TotalPreviousAdmitance < 0 ? NominalVoltage * 1.083 : NominalVoltage;
float NomVolt = TotalPreviousAdmitance < 0 ? static_cast<float>(NominalVoltage * 1.083) : static_cast<float>(NominalVoltage);
TotalCurrent = TotalPreviousAdmitance != 0.0 ?
NomVolt / (InternalRes + 1.0 / TotalPreviousAdmitance) :
0.0; // napięcie dzielone przez sumę rezystancji wewnętrznej i obciążenia

View File

@@ -235,7 +235,7 @@ void TTrainParameters::UpdateVelocity(int StationCount, double vActual)
// TTVmax:=vActual; {PROWIZORKA!!!}
while (i >= 0 && TimeTable[i].vmax == -1)
{
TimeTable[i].vmax = vActual; // prędkość dojazdu do przystanku i
TimeTable[i].vmax = static_cast<float>(vActual); // prędkość dojazdu do przystanku i
--i; // ewentualnie do poprzedniego też
}
}
@@ -412,7 +412,7 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
ConversionError = -4;
if (false == contains( s,"|") )
{
record->km = atof(s.c_str());
record->km = static_cast<float>(atof(s.c_str()));
fin >> s;
}
if (contains( s,"|_____|")) /*zmiana predkosci szlakowej*/
@@ -439,12 +439,12 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
if (contains( s, hrsd) )
{
record->Ah = atoi( s.substr(0, s.find(hrsd)).c_str()); // godzina przyjazdu
record->Am = atof(s.substr(s.find(hrsd) + 1, s.length()).c_str()); // minuta przyjazdu
record->Am = static_cast<float>(atof(s.substr(s.find(hrsd) + 1, s.length()).c_str())); // minuta przyjazdu
}
else
{
record->Ah = TimeTable[StationCount - 1].Ah; // godzina z poprzedniej pozycji
record->Am = atof(s.c_str()); // bo tylko minuty podane
record->Am = static_cast<float>(atof(s.c_str())); // bo tylko minuty podane
}
}
do
@@ -452,7 +452,7 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
fin >> s;
} while (!(s != "|" || fin.bad()));
if (s != "]")
record->tm = atof(s.c_str());
record->tm = static_cast<float>(atof(s.c_str()));
do
{
fin >> s;
@@ -514,12 +514,12 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
if (contains( s, hrsd) )
{
record->Dh = atoi(s.substr(0, s.find(hrsd)).c_str()); // godzina odjazdu
record->Dm = atof(s.substr(s.find(hrsd) + 1, s.length()).c_str()); // minuta odjazdu
record->Dm = static_cast<float>(atof(s.substr(s.find(hrsd) + 1, s.length()).c_str())); // minuta odjazdu
}
else
{
record->Dh = TimeTable[StationCount - 1].Dh; // godzina z poprzedniej pozycji
record->Dm = atof(s.c_str()); // bo tylko minuty podane
record->Dm = static_cast<float>(atof(s.c_str())); // bo tylko minuty podane
}
}
else
@@ -532,7 +532,7 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
fin >> s;
} while (!(s != "|" || fin.bad()));
if (s != "]")
record->tm = atof(s.c_str());
record->tm = static_cast<float>(atof(s.c_str()));
do
{
fin >> s;
@@ -586,13 +586,13 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
{
if (TimeTable[i].Ah >= 0)
{
adjustedtime = clamp_circular<float>( TimeTable[i].Ah * 60 + TimeTable[i].Am + timeoffset, 24 * 60 ); // nowe minuty
adjustedtime = clamp_circular<float>( static_cast<float>(TimeTable[i].Ah * 60) + TimeTable[i].Am + static_cast<float>(timeoffset), 24 * 60 ); // nowe minuty
TimeTable[i].Am = int(60 * adjustedtime) % 3600 / 60.f;
TimeTable[i].Ah = int(adjustedtime / 60) % 24;
}
if (TimeTable[i].Dh >= 0)
{
adjustedtime = clamp_circular<float>( TimeTable[i].Dh * 60 + TimeTable[i].Dm + timeoffset, 24 * 60 ); // nowe minuty
adjustedtime = clamp_circular<float>( static_cast<float>(TimeTable[i].Dh * 60) + TimeTable[i].Dm + static_cast<float>(timeoffset), 24 * 60 ); // nowe minuty
TimeTable[i].Dm = int(60 * adjustedtime) % 3600 / 60.f;
TimeTable[i].Dh = int(adjustedtime / 60) % 24;
}

View File

@@ -63,7 +63,7 @@ basic_station::update_load( TDynamicObject *First, Mtable::TTrainParameters &Sch
maintenancestop ? 0 :
std::min<float>(
parameters.LoadAmount,
Random( parameters.MaxLoad * 0.15f * stationsizemodifier ) ) );
static_cast<float>(Random( parameters.MaxLoad * 0.15f * stationsizemodifier )) ) );
auto loadcount = static_cast<int>(
TestFlag( parameters.DamageFlag, dtrain_out ) ? 0 :
laststop ? 0 :