Merge pull request #192 from lioncash/init

CEyeball: Eliminate unnecessary runtime initializer in Think()
This commit is contained in:
Phillip Stephens 2020-03-06 16:15:15 -08:00 committed by GitHub
commit 76e0a1f8f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 8 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);
@ -102,9 +107,10 @@ void CEyeball::Think(float dt, CStateManager& mgr) {
x570_boneTracking.Update(dt);
GetModelData()->GetAnimationData()->PreRender();
x570_boneTracking.PreRender(mgr, *GetModelData()->GetAnimationData(), GetTransform(), GetModelData()->GetScale(),
*x450_bodyController.get());
} else
*x450_bodyController);
} else {
x570_boneTracking.SetActive(false);
}
if (GetActive()) {
CPlasmaProjectile* projectile = static_cast<CPlasmaProjectile*>(mgr.ObjectById(x5ec_projectileId));