CPlayerGun and CLight fixes

This commit is contained in:
Phillip Stephens 2022-10-06 07:25:26 -07:00
parent 1f3e001f68
commit 1758ea076d
3 changed files with 36 additions and 22 deletions

View File

@ -8,20 +8,21 @@ constexpr zeus::CVector3f kDefaultPosition(0.f, 0.f, 0.f);
constexpr zeus::CVector3f kDefaultDirection(0.f, -1.f, 0.f); constexpr zeus::CVector3f kDefaultDirection(0.f, -1.f, 0.f);
float CLight::CalculateLightRadius() const { float CLight::CalculateLightRadius() const {
if (FLT_EPSILON > x28_distL && FLT_EPSILON > x2c_distQ) { if (x28_distL < FLT_EPSILON && x2c_distQ < FLT_EPSILON) {
return FLT_MAX; return FLT_MAX;
} }
float intensity = GetIntensity(); float intensity = GetIntensity();
if (x2c_distQ <= FLT_EPSILON) { float ret = 0.f;
if (x2c_distQ > FLT_EPSILON) {
constexpr float mulVal = std::min(0.05882353f, 0.2f); // Yes, retro really did do this constexpr float mulVal = std::min(0.05882353f, 0.2f); // Yes, retro really did do this
if (x28_distL > FLT_EPSILON) { if (intensity > FLT_EPSILON) {
return intensity / (mulVal * x28_distL); return std::sqrt(intensity / (mulVal * x2c_distQ));
} }
} else { } else {
constexpr float mulVal = std::min(0.05882353f, 0.2f); // See above comment constexpr float mulVal = std::min(0.05882353f, 0.2f); // See above comment
if (intensity > FLT_EPSILON) { if (x28_distL > FLT_EPSILON) {
return std::sqrt(intensity / (mulVal * x2c_distQ)); return intensity / (mulVal * x28_distL);
} }
} }
@ -69,7 +70,7 @@ zeus::CColor CLight::GetNormalIndependentLightingAtPoint(const zeus::CVector3f&
return x18_color; return x18_color;
float dist = std::max((x0_pos - point).magnitude(), FLT_EPSILON); float dist = std::max((x0_pos - point).magnitude(), FLT_EPSILON);
return x18_color * (1.f / (x2c_distQ * dist * dist + x28_distL * dist + x24_distC)); return x18_color * (1.f / (dist * (x2c_distQ * dist) + (x28_distL * dist + x24_distC)));
} }
CLight CLight::BuildDirectional(const zeus::CVector3f& dir, const zeus::CColor& color) { CLight CLight::BuildDirectional(const zeus::CVector3f& dir, const zeus::CColor& color) {

View File

@ -49,9 +49,9 @@ void CDroneLaser::AddToRenderer(const zeus::CFrustum& frustum, CStateManager& mg
} }
void CDroneLaser::Render(CStateManager& mgr) { void CDroneLaser::Render(CStateManager& mgr) {
// g_Renderer->SetDepthReadWrite(true, true); g_Renderer->SetDepthReadWrite(true, true);
RenderBeam(4, 0.01f, zeus::CColor(1.f, .9f, .9f, 1.f), true); RenderBeam(4, 0.01f, zeus::CColor(1.f, .9f, .9f, 1.f), true);
// g_Renderer->SetDepthReadWrite(true, false); g_Renderer->SetDepthReadWrite(true, false);
RenderBeam(5, 0.06f, zeus::CColor(.4f, .0f, .0f, .5f), true); RenderBeam(5, 0.06f, zeus::CColor(.4f, .0f, .0f, .5f), true);
RenderBeam(7, 0.06f, zeus::CColor(.4f, .2f, .2f, .1f), true); RenderBeam(7, 0.06f, zeus::CColor(.4f, .2f, .2f, .1f), true);
} }

View File

@ -733,9 +733,11 @@ void CPlayerGun::ReturnToRestPose() {
} }
void CPlayerGun::ResetIdle(CStateManager& mgr) { void CPlayerGun::ResetIdle(CStateManager& mgr) {
CFidget::EState fidgetState = x3a4_fidget.GetState();
x370_gunMotionSpeedMult = 1.f;
x550_camBob.SetState(CPlayerCameraBob::ECameraBobState::GunFireNoBob, mgr); x550_camBob.SetState(CPlayerCameraBob::ECameraBobState::GunFireNoBob, mgr);
if (x3a4_fidget.GetState() != CFidget::EState::NoFidget) { if (fidgetState != CFidget::EState::NoFidget) {
if (x3a4_fidget.GetState() == CFidget::EState::Loading) if (fidgetState == CFidget::EState::Loading)
UnLoadFidget(); UnLoadFidget();
ReturnArmAndGunToDefault(mgr, true); ReturnArmAndGunToDefault(mgr, true);
} }
@ -1423,22 +1425,27 @@ void CPlayerGun::ActivateCombo(CStateManager& mgr) {
} }
void CPlayerGun::ProcessChargeState(u32 releasedStates, u32 pressedStates, CStateManager& mgr, float dt) { void CPlayerGun::ProcessChargeState(u32 releasedStates, u32 pressedStates, CStateManager& mgr, float dt) {
if ((releasedStates & 0x1) != 0) if ((releasedStates & 0x1) != 0) {
ResetCharged(dt, mgr); ResetCharged(dt, mgr);
return;
}
if ((pressedStates & 0x1) != 0) { if ((pressedStates & 0x1) != 0) {
if (x32c_chargePhase == EChargePhase::NotCharging && (pressedStates & 0x1) != 0 && if (x32c_chargePhase == EChargePhase::NotCharging && (pressedStates & 0x1) != 0 &&
x348_chargeCooldownTimer == 0.f && x832_28_readyForShot) { x348_chargeCooldownTimer == 0.f && x832_28_readyForShot == 1) {
UpdateNormalShotCycle(dt, mgr); UpdateNormalShotCycle(dt, mgr);
x32c_chargePhase = EChargePhase::ChargeRequested; x32c_chargePhase = EChargePhase::ChargeRequested;
} }
} else if (mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::Missiles) && (pressedStates & 0x2) != 0) { } else {
const auto& state = mgr.GetPlayerState();
if (state->HasPowerUp(CPlayerState::EItemType::Missiles) && (pressedStates & 0x2) != 0) {
if (x32c_chargePhase >= EChargePhase::FxGrown) { if (x32c_chargePhase >= EChargePhase::FxGrown) {
if (mgr.GetPlayerState()->HasPowerUp(skBeamComboArr[size_t(x310_currentBeam)])) if (state->HasPowerUp(skBeamComboArr[size_t(x310_currentBeam)]))
ActivateCombo(mgr); ActivateCombo(mgr);
} else if (x32c_chargePhase == EChargePhase::NotCharging) { } else if (x32c_chargePhase == EChargePhase::NotCharging) {
FireSecondary(dt, mgr); FireSecondary(dt, mgr);
} }
} }
}
} }
void CPlayerGun::ResetNormal(CStateManager& mgr) { void CPlayerGun::ResetNormal(CStateManager& mgr) {
@ -1473,12 +1480,18 @@ void CPlayerGun::UpdateNormalShotCycle(float dt, CStateManager& mgr) {
} }
void CPlayerGun::ProcessNormalState(u32 releasedStates, u32 pressedStates, CStateManager& mgr, float dt) { void CPlayerGun::ProcessNormalState(u32 releasedStates, u32 pressedStates, CStateManager& mgr, float dt) {
if ((releasedStates & 0x1) != 0) if ((releasedStates & 0x1) != 0) {
ResetNormal(mgr); ResetNormal(mgr);
if ((pressedStates & 0x1) != 0 && x348_chargeCooldownTimer == 0.f && x832_28_readyForShot) return;
}
if ((pressedStates & 0x1) != 0 && x348_chargeCooldownTimer == 0.f && x832_28_readyForShot == 1) {
UpdateNormalShotCycle(dt, mgr); UpdateNormalShotCycle(dt, mgr);
else if ((pressedStates & 0x2) != 0) return;
}
if ((pressedStates & 0x2) != 0) {
FireSecondary(dt, mgr); FireSecondary(dt, mgr);
}
} }
void CPlayerGun::UpdateWeaponFire(float dt, const CPlayerState& playerState, CStateManager& mgr) { void CPlayerGun::UpdateWeaponFire(float dt, const CPlayerState& playerState, CStateManager& mgr) {