16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 12:49:18 +02:00

reformat: remove redundant parentheses

This commit is contained in:
jerrrrycho
2026-06-30 21:19:46 +02:00
parent 7c88907f6b
commit d85096f64d
108 changed files with 4098 additions and 4662 deletions

View File

@@ -74,7 +74,7 @@ public:
};
inline bool Active() const
{
return ( ( ModelOn != nullptr ) || ( ModelxOn != nullptr ) );
return ModelOn != nullptr || ModelxOn != nullptr;
};
};

View File

@@ -34,7 +34,7 @@ bool TButton::Init( std::string const &asName, TModel3d const *pModel, bool bNew
m_state = bNewOn;
Update();
return( ( pModelOn != nullptr ) || ( pModelOff != nullptr ) );
return pModelOn != nullptr || pModelOff != nullptr;
};
void TButton::Load( cParser &Parser, TDynamicObject const *Owner ) {
@@ -66,8 +66,8 @@ void TButton::Load( cParser &Parser, TDynamicObject const *Owner ) {
break;
}
}
if( ( pModelOn == nullptr )
&& ( pModelOff == nullptr ) ) {
if( pModelOn == nullptr
&& pModelOff == nullptr ) {
// if we failed to locate even one state submodel, cry
ErrorLog( "Bad model: failed to locate sub-model \"" + submodelname + "\" in 3d model(s) of \"" + Owner->name() + "\"", logtype::model );
}
@@ -88,7 +88,7 @@ TButton::Load_mapping( cParser &Input ) {
// token can be a key or block end
std::string const key { Input.getToken<std::string>( true, "\n\r\t ,;" ) };
if( ( true == key.empty() ) || ( key == "}" ) ) { return false; }
if( true == key.empty() || key == "}" ) { return false; }
// if not block end then the key is followed by assigned value or sub-block
if( key == "soundinc:" ) { m_soundfxincrease.deserialize( Input, sound_type::single ); }
else if( key == "sounddec:" ) { m_soundfxdecrease.deserialize( Input, sound_type::single ); }
@@ -106,10 +106,7 @@ TButton::model_offset() const {
pModelOff ? pModelOff :
nullptr ) };
return (
submodel != nullptr ?
submodel->offset( std::numeric_limits<float>::max() ) :
glm::vec3() );
return submodel != nullptr ? submodel->offset(std::numeric_limits<float>::max()) : glm::vec3();
}
void
@@ -135,7 +132,7 @@ void TButton::Update( bool const Power ) {
}
if( pModelOn != nullptr ) { pModelOn->iVisible = m_state; }
if( pModelOff != nullptr ) { pModelOff->iVisible = (!m_state); }
if( pModelOff != nullptr ) { pModelOff->iVisible = !m_state; }
#ifdef _WIN32
if (iFeedbackBit) {

View File

@@ -28,8 +28,7 @@ public:
return m_state; }
inline
bool Active() {
return ( ( pModelOn != nullptr )
|| ( pModelOff != nullptr ) ); }
return pModelOn != nullptr || pModelOff != nullptr; }
void Update( bool const Power = true );
bool Init( std::string const &asName, TModel3d const *pModel, bool bNewOn = false );
void Load( cParser &Parser, TDynamicObject const *Owner );

View File

@@ -48,7 +48,7 @@ static double ComputeAxisSpeed(double param, double walkspeed, double maxspeed,
double absval = std::abs(param);
// 2/3rd of the stick range lerps walk speed, past that we lerp between max walk and run speed
double walk = walkspeed * std::min(absval / threshold, 1.0);
double run = (std::max(0.0, absval - threshold) / (1.0 - threshold)) * std::max(0.0, maxspeed - walkspeed);
double run = std::max(0.0, absval - threshold) / (1.0 - threshold) * std::max(0.0, maxspeed - walkspeed);
return (param >= 0.0 ? 1.0 : -1.0) * (walk + run);
}
@@ -76,17 +76,13 @@ TCamera::OnCommand( command_data const &Command ) {
case user_command::movehorizontal:
case user_command::movehorizontalfast: {
auto const movespeed = (
m_owner == nullptr ? runspeed : // free roam
auto const movespeed = m_owner == nullptr ? runspeed : // free roam
false == FreeFlyModeFlag ? walkspeed : // vehicle cab
0.0 ); // vehicle external
0.0; // vehicle external
// if( movespeed == 0.0 ) { break; } // enable to fix external cameras in place
auto const speedmultiplier = (
( ( true == FreeFlyModeFlag ) && ( Command.command == user_command::movehorizontalfast ) ) ?
( m_owner == nullptr ) ? 30.0 : 5.0 :
1.0 );
auto const speedmultiplier = true == FreeFlyModeFlag && Command.command == user_command::movehorizontalfast ? m_owner == nullptr ? 30.0 : 5.0 : 1.0;
// left-right
m_moverate.x = ComputeAxisSpeed(Command.param1, walkspeed, movespeed, stickthreshold) * speedmultiplier;
@@ -99,17 +95,13 @@ TCamera::OnCommand( command_data const &Command ) {
case user_command::movevertical:
case user_command::moveverticalfast: {
auto const movespeed = (
m_owner == nullptr ? runspeed * 0.5 : // free roam
auto const movespeed = m_owner == nullptr ? runspeed * 0.5 : // free roam
false == FreeFlyModeFlag ? walkspeed : // vehicle cab
0.0 ); // vehicle external
0.0; // vehicle external
// if( movespeed == 0.0 ) { break; } // enable to fix external cameras in place
auto const speedmultiplier = (
( ( true == FreeFlyModeFlag ) && ( Command.command == user_command::moveverticalfast ) ) ?
( m_owner == nullptr ) ? 10.0 : 3.0 :
1.0 );
auto const speedmultiplier = true == FreeFlyModeFlag && Command.command == user_command::moveverticalfast ? m_owner == nullptr ? 10.0 : 3.0 : 1.0;
// up-down
m_moverate.y = ComputeAxisSpeed(Command.param1, walkspeed, movespeed, stickthreshold) * speedmultiplier;
@@ -151,26 +143,26 @@ void TCamera::Update()
auto const rotationfactor { std::min( 1.0, 20 * deltatime ) };
Angle.y -= m_rotationoffsets.y * rotationfactor;
m_rotationoffsets.y *= ( 1.0 - rotationfactor );
m_rotationoffsets.y *= 1.0 - rotationfactor;
Angle.y = std::remainder(Angle.y, 2.0 * M_PI);
// Limit the camera pitch to +/- 90°.
Angle.x = std::clamp(Angle.x - (m_rotationoffsets.x * rotationfactor), -M_PI_2, M_PI_2);
m_rotationoffsets.x *= ( 1.0 - rotationfactor );
Angle.x = std::clamp(Angle.x - m_rotationoffsets.x * rotationfactor, -M_PI_2, M_PI_2);
m_rotationoffsets.x *= 1.0 - rotationfactor;
// update position
if( ( m_owner == nullptr )
|| ( true == FreeFlyModeFlag )
|| ( false == Global.ctrlState )
|| ( true == DebugCameraFlag ) ) {
if( m_owner == nullptr
|| true == FreeFlyModeFlag
|| false == Global.ctrlState
|| true == DebugCameraFlag ) {
// ctrl is used for mirror view, so we ignore the controls when in vehicle if ctrl is pressed
// McZapkie-170402: poruszanie i rozgladanie we free takie samo jak w follow
UpdateVelocityAxis(Velocity.x, m_moverate.x, deltatime);
UpdateVelocityAxis(Velocity.y, m_moverate.y, deltatime);
UpdateVelocityAxis(Velocity.z, m_moverate.z, deltatime);
}
if( ( m_owner == nullptr )
|| ( true == DebugCameraFlag ) ) {
if( m_owner == nullptr
|| true == DebugCameraFlag ) {
// free movement position update
auto movement { Velocity };
movement = RotateY(movement, (double)Angle.y);
@@ -184,8 +176,8 @@ void TCamera::Update()
m_owner->Mechanik ?
m_owner->Mechanik :
m_owner->ctOwner ) };
if( ( owner && owner->Occupied() )
&& ( owner->Occupied()->CabOccupied < 0 ) ) {
if( owner && owner->Occupied()
&& owner->Occupied()->CabOccupied < 0 ) {
movement *= -1.f;
movement.y = -movement.y;
}
@@ -208,7 +200,7 @@ bool TCamera::SetMatrix( glm::dmat4 &Matrix ) {
Matrix = glm::rotate(Matrix, -(double)Angle.y, glm::dvec3(0, 1, 0)); // w zewnętrznym widoku: kierunek patrzenia
Matrix = glm::rotate(Matrix, -(double)Angle.z, glm::dvec3(0, 0, 1)); // po wyłączeniu tego kręci się pojazd, a sceneria nie
if( ( m_owner != nullptr ) && ( false == DebugCameraFlag ) ) {
if( m_owner != nullptr && false == DebugCameraFlag ) {
Matrix *= glm::lookAt(Pos, LookAt, glm::dvec3{ vUp } );
}
@@ -222,7 +214,7 @@ bool TCamera::SetMatrix( glm::dmat4 &Matrix ) {
void TCamera::RaLook()
{ // zmiana kierunku patrzenia - przelicza Yaw
auto where = LookAt - Pos /*+ Math3D::vector3(0, 3, 0)*/; // trochę w górę od szyn
if( ( where.x != 0.0 ) || ( where.z != 0.0 ) ) {
if( where.x != 0.0 || where.z != 0.0 ) {
Angle.y = atan2( -where.x, -where.z ); // kąt horyzontalny
m_rotationoffsets.y = 0.0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -224,11 +224,11 @@ public:
void TakeControl( bool const Aidriver, bool const Forcevehiclecheck = false );
inline
bool primary( bool const Primary ) {
SetFlag( iDrivigFlags, ( Primary ? movePrimary : -movePrimary ) );
SetFlag( iDrivigFlags, Primary ? movePrimary : -movePrimary );
return primary(); }
inline
bool primary() const {
return ( ( iDrivigFlags & movePrimary ) != 0 ); };
return (iDrivigFlags & movePrimary) != 0; };
inline
TMoverParameters const *Controlling() const {
return mvControlling; }
@@ -257,14 +257,13 @@ public:
return TestFlag( mvOccupied->CategoryFlag, 2 ); }
inline
bool is_emu() const {
return ( mvControlling->TrainType == dt_EZT ); }
return mvControlling->TrainType == dt_EZT; }
inline
bool is_dmu() const {
return ( mvControlling->TrainType == dt_DMU ); }
return mvControlling->TrainType == dt_DMU; }
inline
bool has_diesel_engine() const {
return ( ( mvControlling->EngineType == TEngineType::DieselElectric )
|| ( mvControlling->EngineType == TEngineType::DieselEngine ) );
return mvControlling->EngineType == TEngineType::DieselElectric || mvControlling->EngineType == TEngineType::DieselEngine;
}
TBrakeSystem consist_brake_system() const;
private:

File diff suppressed because it is too large Load Diff

View File

@@ -712,7 +712,7 @@ private:
Axle1.pPosition :
Axle0.pPosition; };
inline double Roll() {
return ( ( Axle1.GetRoll() + Axle0.GetRoll() ) ); }
return Axle1.GetRoll() + Axle0.GetRoll(); }
/*
// TODO: check if scanning takes into account direction when selecting axle
// if it does, replace the version above
@@ -743,16 +743,14 @@ private:
// calculates distance between event-starting axle and front of the vehicle
double tracing_offset() const;
inline TTrack * GetTrack() {
return (iAxleFirst ?
Axle1.GetTrack() :
Axle0.GetTrack()); };
return iAxleFirst ? Axle1.GetTrack() : Axle0.GetTrack(); };
// McZapkie-260202
void LoadMMediaFile(std::string const &TypeName, std::string const &ReplacableSkin);
TModel3d *LoadMMediaFile_mdload( std::string const &Name ) const;
inline double ABuGetDirection() const { // ABu.
return (Axle1.GetTrack() == MyTrack ? Axle1.GetDirection() : Axle0.GetDirection()); };
return Axle1.GetTrack() == MyTrack ? Axle1.GetDirection() : Axle0.GetDirection(); };
// zwraca kierunek pojazdu na torze z aktywną osą
inline double RaDirectionGet() const {
return iAxleFirst ?

View File

@@ -49,18 +49,18 @@ void TGauge::Init(TSubModel *Submodel, TSubModel *Submodelon, TGaugeAnimation Ty
auto *sm { ( SubModel ? SubModel->ChildGet() : nullptr ) };
while( sm != nullptr ) {
// pętla po submodelach potomnych i obracanie ich o kąt zależy od cyfry w (fValue)
if( ( sm->pName.size() )// musi mieć niepustą nazwę
&& ( std::isdigit( sm->pName[ 0 ] ) ) ) {
if( sm->pName.size() // musi mieć niepustą nazwę
&& std::isdigit(sm->pName[0]) ) {
sm->WillBeAnimated(); // wyłączenie optymalizacji
}
sm = sm->NextGet();
}
// do the same for the active version
sm = ( SubModelOn ? SubModelOn->ChildGet() : nullptr );
sm = SubModelOn ? SubModelOn->ChildGet() : nullptr;
while( sm != nullptr ) {
// pętla po submodelach potomnych i obracanie ich o kąt zależy od cyfry w (fValue)
if( ( sm->pName.size() )// musi mieć niepustą nazwę
&& ( std::isdigit( sm->pName[ 0 ] ) ) ) {
if( sm->pName.size() // musi mieć niepustą nazwę
&& std::isdigit(sm->pName[0]) ) {
sm->WillBeAnimated(); // wyłączenie optymalizacji
}
sm = sm->NextGet();
@@ -113,8 +113,8 @@ void TGauge::Load( cParser &Parser, TDynamicObject const *Owner, double const mu
>> scale
>> offset
>> friction;
if( ( gaugetypename == "rotvar" )
|| ( gaugetypename == "movvar" ) ) {
if( gaugetypename == "rotvar"
|| gaugetypename == "movvar" ) {
interpolatescale = true;
Parser.getTokens( 2, false );
Parser
@@ -132,8 +132,8 @@ void TGauge::Load( cParser &Parser, TDynamicObject const *Owner, double const mu
>> scale
>> offset
>> friction;
if( ( gaugetypename == "rotvar" )
|| ( gaugetypename == "movvar" ) ) {
if( gaugetypename == "rotvar"
|| gaugetypename == "movvar" ) {
interpolatescale = true;
Parser.getTokens( 2, false );
Parser
@@ -186,13 +186,13 @@ void TGauge::Load( cParser &Parser, TDynamicObject const *Owner, double const mu
TSubModel *submodel { nullptr };
std::array<TModel3d *, 2> sources { Owner->mdKabina, Owner->mdLowPolyInt };
for( auto const *source : sources ) {
if( ( source != nullptr )
if( source != nullptr
&& ( submodel = source->GetFromName( submodelname ) ) != nullptr ) {
// got what we wanted, bail out
break;
}
// there's a possibility the default submodel was named with _off suffix
if( ( source != nullptr )
if( source != nullptr
&& ( submodel = source->GetFromName( submodelname + "_off" ) ) != nullptr ) {
// got what we wanted, bail out
break;
@@ -204,7 +204,7 @@ 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 )
if( source != nullptr
&& ( submodelon = source->GetFromName( submodelname + "_on" ) ) != nullptr ) {
// got what we wanted, bail out
break;
@@ -220,10 +220,7 @@ void TGauge::Load( cParser &Parser, TDynamicObject const *Owner, double const mu
{ "dgt", TGaugeAnimation::gt_Digital }
};
auto lookup = gaugetypes.find( gaugetypename );
auto const type = (
lookup != gaugetypes.end() ?
lookup->second :
TGaugeAnimation::gt_Unknown );
auto const type = lookup != gaugetypes.end() ? lookup->second : TGaugeAnimation::gt_Unknown;
Init( submodel, submodelon, type, scale, offset, friction, 0, endvalue, endscale, interpolatescale );
@@ -235,18 +232,17 @@ TGauge::Load_mapping( cParser &Input, TGauge::scratch_data &Scratchpad ) {
// token can be a key or block end
auto const key { Input.getToken<std::string>( true, "\n\r\t ,;" ) };
if( ( true == key.empty() ) || ( key == "}" ) ) { return false; }
if( true == key.empty() || key == "}" ) { return false; }
// if not block end then the key is followed by assigned value or sub-block
if( key == "type:" ) {
auto const gaugetype { Input.getToken<std::string>( true, "\n\r\t ,;" ) };
m_type = (
gaugetype == "push" ? TGaugeType::push :
gaugetype == "impulse" ? TGaugeType::push :
gaugetype == "return" ? TGaugeType::push :
gaugetype == "delayed" ? TGaugeType::push_delayed :
gaugetype == "pushtoggle" ? TGaugeType::pushtoggle :
gaugetype == "toggle" ? TGaugeType::toggle :
TGaugeType::toggle ); // default
m_type = gaugetype == "push" ? TGaugeType::push :
gaugetype == "impulse" ? TGaugeType::push :
gaugetype == "return" ? TGaugeType::push :
gaugetype == "delayed" ? TGaugeType::push_delayed :
gaugetype == "pushtoggle" ? TGaugeType::pushtoggle :
gaugetype == "toggle" ? TGaugeType::toggle :
TGaugeType::toggle; // default
}
else if( key == "soundinc:" ) {
m_soundfxincrease.deserialize( Input, sound_type::single );
@@ -363,7 +359,7 @@ void TGauge::Update( bool const Power ) {
// TODO: remove passing manually power state when LD is in place
if( m_value != m_targetvalue ) {
float dt = Timer::GetDeltaTime();
if( ( m_friction > 0 ) && ( dt < 0.5 * m_friction ) ) {
if( m_friction > 0 && dt < 0.5 * m_friction ) {
// McZapkie-281102: zabezpieczenie przed oscylacjami dla dlugich czasow
m_value += dt * ( m_targetvalue - m_value ) / m_friction;
if( std::abs( m_targetvalue - m_value ) <= 0.0001 ) {
@@ -388,7 +384,7 @@ void TGauge::Update( bool const Power ) {
if( SubModelOn != nullptr ) {
SubModelOn->iVisible = m_state;
if( SubModel != nullptr ) {
SubModel->iVisible = ( !m_state );
SubModel->iVisible = !m_state;
}
}
// update submodel animations
@@ -437,7 +433,7 @@ void TGauge::UpdateValue()
break;
}
case 'b': {
UpdateValue( ( *bData ? 1.f : 0.f ) );
UpdateValue( *bData ? 1.f : 0.f );
break;
}
default: {
@@ -453,16 +449,7 @@ void TGauge::AssignState( bool const *State ) {
float TGauge::GetScaledValue() const {
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 );
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;
}
void
@@ -498,8 +485,8 @@ TGauge::UpdateAnimation( TSubModel *Submodel ) {
*/ std::string n( "000000000" + std::to_string( static_cast<int>( std::floor( GetScaledValue() ) ) ) );
if( n.length() > 10 ) { n.erase( 0, n.length() - 10 ); } // also dumb but should work for now
do { // pętla po submodelach potomnych i obracanie ich o kąt zależy od cyfry w (fValue)
if( ( sm->pName.size() )
&& ( std::isdigit( sm->pName[ 0 ] ) ) ) {
if( sm->pName.size()
&& std::isdigit(sm->pName[0]) ) {
sm->SetRotate(
float3( 0, 1, 0 ),
-36.0 * ( n[ '0' + 9 - sm->pName[ 0 ] ] - '0' ) );
@@ -518,10 +505,7 @@ TGauge::UpdateAnimation( TSubModel *Submodel ) {
glm::vec3
TGauge::model_offset() const {
return (
SubModel != nullptr ?
SubModel->offset( 1.f ) :
glm::vec3() );
return SubModel != nullptr ? SubModel->offset(1.f) : glm::vec3();
}
TGaugeType

View File

@@ -25,9 +25,9 @@ enum class TGaugeType : int {
toggle = 1 << 0,
push = 1 << 1,
delayed = 1 << 2,
pushtoggle = ( toggle | push ),
push_delayed = ( push | delayed ),
pushtoggle_delayed = ( toggle | push | delayed )
pushtoggle = toggle | push,
push_delayed = push | delayed,
pushtoggle_delayed = toggle | push | delayed
};
// animowany wskaźnik, mogący przyjmować wiele stanów pośrednich

File diff suppressed because it is too large Load Diff

View File

@@ -218,10 +218,7 @@ class TTrain {
void update_sounds_radio();
inline
end cab_to_end( int const End ) const {
return (
End == 2 ?
end::rear :
end::front ); }
return End == 2 ? end::rear : end::front; }
inline
end cab_to_end() const {
return cab_to_end( iCabn ); }
@@ -926,7 +923,7 @@ private:
// plays provided sound from position of the radio
bool radio_message_played;
void radio_message( sound_source *Message, int const Channel );
inline auto const RadioChannel() const { return ( Dynamic()->Mechanik ? Dynamic()->Mechanik->iRadioChannel : 1 ); }
inline auto const RadioChannel() const { return Dynamic()->Mechanik ? Dynamic()->Mechanik->iRadioChannel : 1; }
inline auto &RadioChannel() { return Dynamic()->Mechanik->iRadioChannel; }
inline TDynamicObject *Dynamic() { return DynamicObject; };
inline TDynamicObject const *Dynamic() const { return DynamicObject; };