mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-17 22:39:19 +02:00
refactor(sonar): merge collapsible nested if statements (cpp:S1066)
Comments that preceded the inner if are kept above the merged statement.
This commit is contained in:
@@ -314,15 +314,13 @@ drivermouse_input::button( int const Button, int const Action ) {
|
||||
if( true == FreeFlyModeFlag ) {
|
||||
// freefly mode
|
||||
// left mouse button launches on_click event associated with to the node
|
||||
if( Button == GLFW_MOUSE_BUTTON_LEFT ) {
|
||||
if( Action == GLFW_PRESS ) {
|
||||
GfxRenderer->Pick_Node_Callback(
|
||||
[this](scene::basic_node *node) {
|
||||
if( node == nullptr
|
||||
|| typeid(*node) != typeid(TAnimModel) )
|
||||
return;
|
||||
simulation::Region->on_click( static_cast<TAnimModel const *>( node ) ); } );
|
||||
}
|
||||
if (Button == GLFW_MOUSE_BUTTON_LEFT && Action == GLFW_PRESS) {
|
||||
GfxRenderer->Pick_Node_Callback(
|
||||
[this](scene::basic_node *node) {
|
||||
if( node == nullptr
|
||||
|| typeid(*node) != typeid(TAnimModel) )
|
||||
return;
|
||||
simulation::Region->on_click( static_cast<TAnimModel const *>( node ) ); } );
|
||||
}
|
||||
// right button controls panning
|
||||
if( Button == GLFW_MOUSE_BUTTON_RIGHT ) {
|
||||
@@ -343,11 +341,9 @@ drivermouse_input::button( int const Button, int const Action ) {
|
||||
}
|
||||
else {
|
||||
m_pickwaiting = false;
|
||||
if( Button == GLFW_MOUSE_BUTTON_LEFT ) {
|
||||
if( m_slider.command() != user_command::none ) {
|
||||
m_relay.post( m_slider.command(), 0, 0, Action, 0 );
|
||||
m_slider.release();
|
||||
}
|
||||
if (Button == GLFW_MOUSE_BUTTON_LEFT && m_slider.command() != user_command::none) {
|
||||
m_relay.post( m_slider.command(), 0, 0, Action, 0 );
|
||||
m_slider.release();
|
||||
}
|
||||
// if it's the right mouse button that got released and we had no command active, we were potentially in view panning mode; stop it
|
||||
if( Button == GLFW_MOUSE_BUTTON_RIGHT ) {
|
||||
|
||||
@@ -370,16 +370,14 @@ gamepad_input::process_axes() {
|
||||
auto const deltatime { Timer::GetDeltaTime() * 15.0 };
|
||||
if( axis.state >= 0.0f ) {
|
||||
// first bound command selected
|
||||
if( axis.accumulator < 0.0f ) {
|
||||
// we were issuing the other command, post notification that's no longer the case
|
||||
if( boundcommand2 != user_command::none ) {
|
||||
m_relay.post(
|
||||
boundcommand2,
|
||||
0, 0,
|
||||
GLFW_RELEASE,
|
||||
0 );
|
||||
axis.accumulator = 0.0f;
|
||||
}
|
||||
// we were issuing the other command, post notification that's no longer the case
|
||||
if (axis.accumulator < 0.0f && boundcommand2 != user_command::none) {
|
||||
m_relay.post(
|
||||
boundcommand2,
|
||||
0, 0,
|
||||
GLFW_RELEASE,
|
||||
0 );
|
||||
axis.accumulator = 0.0f;
|
||||
}
|
||||
if( boundcommand1 != user_command::none ) {
|
||||
if( axis.state > m_deadzone ) {
|
||||
@@ -410,16 +408,14 @@ gamepad_input::process_axes() {
|
||||
}
|
||||
else {
|
||||
// second bound command selected
|
||||
if( axis.accumulator > 0.0f ) {
|
||||
// we were issuing the other command, post notification that's no longer the case
|
||||
if( boundcommand1 != user_command::none ) {
|
||||
m_relay.post(
|
||||
boundcommand1,
|
||||
0, 0,
|
||||
GLFW_RELEASE,
|
||||
0 );
|
||||
axis.accumulator = 0.0f;
|
||||
}
|
||||
// we were issuing the other command, post notification that's no longer the case
|
||||
if (axis.accumulator > 0.0f && boundcommand1 != user_command::none) {
|
||||
m_relay.post(
|
||||
boundcommand1,
|
||||
0, 0,
|
||||
GLFW_RELEASE,
|
||||
0 );
|
||||
axis.accumulator = 0.0f;
|
||||
}
|
||||
if( boundcommand1 != user_command::none ) {
|
||||
if( axis.state < -m_deadzone ) {
|
||||
@@ -465,10 +461,8 @@ gamepad_input::process_axes() {
|
||||
else {
|
||||
param = param > 0.0 ? (param - m_deadzone) / (1.0 - m_deadzone) : (param + m_deadzone) / (1.0 - m_deadzone);
|
||||
}
|
||||
if( param != 0.0 ) {
|
||||
if( inputtype == input_type::value_invert ) {
|
||||
param *= -1.0;
|
||||
}
|
||||
if (param != 0.0 && inputtype == input_type::value_invert) {
|
||||
param *= -1.0;
|
||||
}
|
||||
// scale passed value according to command type
|
||||
switch( boundcommand1 ) {
|
||||
|
||||
@@ -63,14 +63,12 @@ OnCommandGet(multiplayer::DaneRozkaz *pRozkaz)
|
||||
|
||||
if( Global.iMultiplayer ) {
|
||||
auto *event = simulation::Events.FindEvent( std::string( pRozkaz->cString + 1, (unsigned)pRozkaz->cString[0] ) );
|
||||
if( event != nullptr ) {
|
||||
if( typeid(*event) == typeid(multi_event)
|
||||
if (event != nullptr && (typeid(*event) == typeid(multi_event)
|
||||
|| typeid(*event) == typeid(lights_event)
|
||||
|| event->m_sibling != nullptr ) {
|
||||
// tylko jawne albo niejawne Multiple
|
||||
|| event->m_sibling != nullptr)) {
|
||||
// tylko jawne albo niejawne Multiple
|
||||
command_relay relay;
|
||||
relay.post(user_command::queueevent, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &event->name());
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -111,17 +109,17 @@ OnCommandGet(multiplayer::DaneRozkaz *pRozkaz)
|
||||
case 5: // ustawienie parametrów
|
||||
{
|
||||
CommLog(Now() + " " + std::to_string(pRozkaz->iComm) + " params " + std::to_string(*pRozkaz->iPar) + " rcvd");
|
||||
if (*pRozkaz->iPar == 0) // sprawdzenie czasu
|
||||
if (*pRozkaz->iPar & 1) // ustawienie czasu
|
||||
{
|
||||
auto t = pRozkaz->fPar[1];
|
||||
simulation::Time.data().wDay = static_cast<uint16_t>(std::floor(t)); // niby nie powinno być dnia, ale...
|
||||
if (Global.fMoveLight >= 0)
|
||||
Global.fMoveLight = t; // trzeba by deklinację Słońca przeliczyć
|
||||
simulation::Time.data().wHour = static_cast<uint16_t>(std::floor(24 * t) - 24.0 * simulation::Time.data().wDay);
|
||||
simulation::Time.data().wMinute = static_cast<uint16_t>(std::floor(60 * 24 * t) - 60.0 * (24.0 * simulation::Time.data().wDay + simulation::Time.data().wHour));
|
||||
simulation::Time.data().wSecond = static_cast<uint16_t>(std::floor( 60 * 60 * 24 * t ) - 60.0 * ( 60.0 * ( 24.0 * simulation::Time.data().wDay + simulation::Time.data().wHour ) + simulation::Time.data().wMinute ));
|
||||
}
|
||||
// sprawdzenie czasu
|
||||
if (*pRozkaz->iPar == 0 && *pRozkaz->iPar & 1) // ustawienie czasu
|
||||
{
|
||||
auto t = pRozkaz->fPar[1];
|
||||
simulation::Time.data().wDay = static_cast<uint16_t>(std::floor(t)); // niby nie powinno być dnia, ale...
|
||||
if (Global.fMoveLight >= 0)
|
||||
Global.fMoveLight = t; // trzeba by deklinację Słońca przeliczyć
|
||||
simulation::Time.data().wHour = static_cast<uint16_t>(std::floor(24 * t) - 24.0 * simulation::Time.data().wDay);
|
||||
simulation::Time.data().wMinute = static_cast<uint16_t>(std::floor(60 * 24 * t) - 60.0 * (24.0 * simulation::Time.data().wDay + simulation::Time.data().wHour));
|
||||
simulation::Time.data().wSecond = static_cast<uint16_t>(std::floor( 60 * 60 * 24 * t ) - 60.0 * ( 60.0 * ( 24.0 * simulation::Time.data().wDay + simulation::Time.data().wHour ) + simulation::Time.data().wMinute ));
|
||||
}
|
||||
if (*pRozkaz->iPar & 2)
|
||||
{ // ustawienie flag zapauzowania
|
||||
Global.iPause = static_cast<int>(pRozkaz->fPar[2]); // zakładamy, że wysyłający wie, co robi
|
||||
|
||||
Reference in New Issue
Block a user