Skip to content

Commit

Permalink
Fix loud white nosie after mouse steering (#5812)
Browse files Browse the repository at this point in the history
* Prevent NaN poisoning in right-mouse rotation (fixes loud thruster sounds and inability to turn)

* Document savebump changes
  • Loading branch information
neumond committed Apr 27, 2024
1 parent ff98b64 commit ef183ff
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions SAVEBUMP.txt
Expand Up @@ -13,4 +13,5 @@ Regular tasks
- data/libs/NameGen.lua: Add new authors to name generator

One-time tasks
- DynamicBody.cpp: the std::isnan() check in constructor should be removed
- add your one-time tasks here
6 changes: 6 additions & 0 deletions src/DynamicBody.cpp
Expand Up @@ -67,6 +67,12 @@ DynamicBody::DynamicBody(const Json &jsonObj, Space *space) :
throw SavedGameCorruptException();
}

// fix saves with nans
// SAVEBUMP: This can be removed starting with save version 91
if (std::isnan(m_angVel.x) || std::isnan(m_angVel.y) || std::isnan(m_angVel.z)) {
m_angVel = vector3d(0.0);
}

m_aiMessage = AIError::AIERROR_NONE;
m_decelerating = false;
}
Expand Down
4 changes: 3 additions & 1 deletion src/ship/PlayerShipController.cpp
Expand Up @@ -106,7 +106,9 @@ struct PlayerShipController::Util {
auto good_speed = sqrt(2 * max_accel * want_rot) * 0.95;
auto frame_speed = want_rot / timeStep;
auto tot_speed = std::min(good_speed, frame_speed / 2);
rot_vel = (ship_dir.Cross(dir) * c.m_ship->GetOrient()).Normalized() * tot_speed;
// this cross product often becomes all-zeros (ship_dir coincides with requested dir)
// NormalizedSafe is crucial there to avoid NaN poisoning
rot_vel = (ship_dir.Cross(dir) * c.m_ship->GetOrient()).NormalizedSafe() * tot_speed;
}
return rot_vel;
};
Expand Down

0 comments on commit ef183ff

Please sign in to comment.