CEyeball: Eliminate unnecessary runtime initialzer in Think()

We can just fold the result into the constant directly, which allows us
to avoid the need for a static runtime initializer. This is bit-exact
with what the result would be, so this is fine.
This commit is contained in:
Lioncash 2020-03-06 07:25:58 -05:00
parent 2f9dd38bbe
commit c3809162bf
1 changed files with 11 additions and 6 deletions

View File

@ -83,17 +83,22 @@ void CEyeball::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateMa
CPatterned::AcceptScriptMsg(msg, uid, mgr);
}
static float kMinAngle = std::cos(zeus::degToRad(45.f));
void CEyeball::Think(float dt, CStateManager& mgr) {
CPatterned::Think(dt, mgr);
if (!GetActive())
return;
CPlayer& player = mgr.GetPlayer();
zeus::CVector3f direction = (player.GetTranslation() - GetTranslation()).normalized();
if (!GetActive()) {
return;
}
const CPlayer& player = mgr.GetPlayer();
const zeus::CVector3f direction = (player.GetTranslation() - GetTranslation()).normalized();
// Used to be directly calculated as std::cos(zeus::degToRad(45.f));
// but was converted into the exact constant to avoid unnecessary runtime initialization.
constexpr float minAngle = 0.707106769f;
x60c_25_playerInRange = (player.GetMorphballTransitionState() == CPlayer::EPlayerMorphBallState::Morphed &&
direction.dot(GetTransform().frontVector()) > kMinAngle);
direction.dot(GetTransform().frontVector()) > minAngle);
if (x60c_25_playerInRange) {
x570_boneTracking.SetActive(true);