CScriptSound: Brace conditionals where applicable

This commit is contained in:
Lioncash 2020-05-07 12:26:05 -04:00
parent ecbcb86bc5
commit 7186e57a9d
1 changed files with 59 additions and 44 deletions

View File

@ -35,9 +35,10 @@ CScriptSound::CScriptSound(TUniqueId uid, std::string_view name, const CEntityIn
, x11c_29_acoustics(acoustics)
, x11c_30_worldSfx(worldSfx)
, x11d_24_allowDuplicates(allowDuplicates) {
if (x11c_30_worldSfx && (!x11c_26_nonEmitter || !x11c_25_looped))
if (x11c_30_worldSfx && (!x11c_26_nonEmitter || !x11c_25_looped)) {
x11c_30_worldSfx = false;
}
}
void CScriptSound::Accept(IVisitor& visitor) { visitor.Visit(this); }
@ -51,12 +52,12 @@ constexpr CMaterialFilter kSolidFilter =
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {EMaterialTypes::ProjectilePassthrough});
float CScriptSound::GetOccludedVolumeAmount(const zeus::CVector3f& pos, const CStateManager& mgr) {
zeus::CTransform camXf = mgr.GetCameraManager()->GetCurrentCameraTransform(mgr);
zeus::CVector3f soundToCam = camXf.origin - pos;
float soundToCamMag = soundToCam.magnitude();
zeus::CVector3f soundToCamNorm = soundToCam * (1.f / soundToCamMag);
zeus::CVector3f thirdEdge = zeus::skUp - soundToCamNorm * soundToCamNorm.dot(zeus::skUp);
zeus::CVector3f cross = soundToCamNorm.cross(thirdEdge);
const zeus::CTransform camXf = mgr.GetCameraManager()->GetCurrentCameraTransform(mgr);
const zeus::CVector3f soundToCam = camXf.origin - pos;
const float soundToCamMag = soundToCam.magnitude();
const zeus::CVector3f soundToCamNorm = soundToCam * (1.f / soundToCamMag);
const zeus::CVector3f thirdEdge = zeus::skUp - soundToCamNorm * soundToCamNorm.dot(zeus::skUp);
const zeus::CVector3f cross = soundToCamNorm.cross(thirdEdge);
static float kInfluenceAmount = 3.f / soundToCamMag;
static float kInfluenceIncrement = kInfluenceAmount;
@ -64,12 +65,13 @@ float CScriptSound::GetOccludedVolumeAmount(const zeus::CVector3f& pos, const CS
int invalCount = 0;
float f17 = -kInfluenceAmount;
while (f17 <= kInfluenceAmount) {
zeus::CVector3f angledDir = thirdEdge * f17 + soundToCamNorm;
const zeus::CVector3f angledDir = thirdEdge * f17 + soundToCamNorm;
float f16 = -kInfluenceAmount;
while (f16 <= kInfluenceAmount) {
if (mgr.RayStaticIntersection(pos, (cross * f16 + angledDir).normalized(), soundToCamMag, kSolidFilter)
.IsInvalid())
.IsInvalid()) {
++invalCount;
}
++totalCount;
f16 += kInfluenceIncrement;
}
@ -84,8 +86,9 @@ void CScriptSound::Think(float dt, CStateManager& mgr) {
mgr.FreeScriptObject(GetUniqueId());
} else if (GetActive()) {
if (!x11c_25_looped && x11c_27_autoStart && !x11c_24_playRequested && xec_sfxHandle &&
!CSfxManager::IsPlaying(xec_sfxHandle))
!CSfxManager::IsPlaying(xec_sfxHandle)) {
mgr.FreeScriptObject(GetUniqueId());
}
if (!x11c_26_nonEmitter && xec_sfxHandle) {
if (xf8_updateTimer <= 0.f) {
@ -99,19 +102,20 @@ void CScriptSound::Think(float dt, CStateManager& mgr) {
if (xec_sfxHandle && !x11c_26_nonEmitter && x11c_28_occlusionTest) {
if (xe8_occUpdateTimer <= 0.f && sFirstInFrame) {
sFirstInFrame = false;
float occVol = GetOccludedVolumeAmount(GetTranslation(), mgr);
float newMaxVol = std::max(occVol * x10e_vol, x10c_minVol);
const float occVol = GetOccludedVolumeAmount(GetTranslation(), mgr);
const float newMaxVol = std::max(occVol * x10e_vol, x10c_minVol);
if (newMaxVol != xf0_maxVol) {
xf0_maxVol = newMaxVol;
float delta = xf0_maxVol - xf2_maxVolUpd;
const float delta = xf0_maxVol - xf2_maxVolUpd;
xf4_maxVolUpdDelta = delta / 10.5f;
if (xf4_maxVolUpdDelta == 0.f) {
if (xf2_maxVolUpd < xf0_maxVol)
if (xf2_maxVolUpd < xf0_maxVol) {
xf4_maxVolUpdDelta = 1.f / 127.f;
else
} else {
xf4_maxVolUpdDelta = -1.f / 127.f;
}
}
}
xe8_occUpdateTimer = 0.5f;
} else {
xe8_occUpdateTimer -= dt;
@ -119,10 +123,12 @@ void CScriptSound::Think(float dt, CStateManager& mgr) {
if (xf2_maxVolUpd != xf0_maxVol) {
xf2_maxVolUpd += xf4_maxVolUpdDelta;
if (xf4_maxVolUpdDelta > 0.f && xf2_maxVolUpd > xf0_maxVol)
if (xf4_maxVolUpdDelta > 0.f && xf2_maxVolUpd > xf0_maxVol) {
xf2_maxVolUpd = xf0_maxVol;
if (xf4_maxVolUpdDelta < 0.f && xf2_maxVolUpd < xf0_maxVol)
}
if (xf4_maxVolUpdDelta < 0.f && xf2_maxVolUpd < xf0_maxVol) {
xf2_maxVolUpd = xf0_maxVol;
}
CSfxManager::UpdateEmitter(xec_sfxHandle, GetTranslation(), zeus::skZero3f, xf2_maxVolUpd);
}
}
@ -135,38 +141,44 @@ void CScriptSound::Think(float dt, CStateManager& mgr) {
}
}
if (x118_pitch != 0.f && xec_sfxHandle)
if (x118_pitch != 0.f && xec_sfxHandle) {
CSfxManager::PitchBend(xec_sfxHandle, x118_pitch);
}
}
}
void CScriptSound::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
CActor::AcceptScriptMsg(msg, uid, mgr);
switch (msg) {
case EScriptObjectMessage::Registered: {
if (GetActive() && x11c_27_autoStart)
if (GetActive() && x11c_27_autoStart) {
x11c_24_playRequested = true;
}
x11c_31_selfFree = mgr.GetIsGeneratingObject();
} break;
case EScriptObjectMessage::Play: {
if (GetActive())
if (GetActive()) {
PlaySound(mgr);
}
} break;
case EScriptObjectMessage::Stop: {
if (GetActive())
if (GetActive()) {
StopSound(mgr);
}
} break;
case EScriptObjectMessage::Deactivate: {
StopSound(mgr);
} break;
case EScriptObjectMessage::Activate: {
if (GetActive())
if (GetActive()) {
x11c_24_playRequested = true;
}
} break;
case EScriptObjectMessage::Deleted: {
if (!x11c_30_worldSfx)
if (!x11c_30_worldSfx) {
StopSound(mgr);
}
} break;
default:
break;
@ -174,17 +186,21 @@ void CScriptSound::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CSta
}
void CScriptSound::PlaySound(CStateManager& mgr) {
if ((x11d_24_allowDuplicates || !xec_sfxHandle || xec_sfxHandle->IsClosed()) && !x11d_25_processedThisFrame) {
if (!x11d_24_allowDuplicates && xec_sfxHandle && !xec_sfxHandle->IsClosed() || x11d_25_processedThisFrame) {
return;
}
x11d_25_processedThisFrame = true;
if (x11c_26_nonEmitter) {
if (!x11c_30_worldSfx || !mgr.GetWorld()->HasGlobalSound(x100_soundId)) {
xec_sfxHandle = CSfxManager::SfxStart(x100_soundId, x10e_vol, x114_pan, x11c_29_acoustics, x112_prio,
x11c_25_looped, x11c_30_worldSfx ? kInvalidAreaId : GetAreaIdAlways());
if (x11c_30_worldSfx)
if (x11c_30_worldSfx) {
mgr.GetWorld()->AddGlobalSound(xec_sfxHandle);
}
}
} else {
float occVol = x11c_28_occlusionTest ? GetOccludedVolumeAmount(GetTranslation(), mgr) : 1.f;
const float occVol = x11c_28_occlusionTest ? GetOccludedVolumeAmount(GetTranslation(), mgr) : 1.f;
xf0_maxVol = xf2_maxVolUpd = x10e_vol * occVol;
CAudioSys::C3DEmitterParmData data = {};
data.x0_pos = GetTranslation();
@ -198,7 +214,6 @@ void CScriptSound::PlaySound(CStateManager& mgr) {
xec_sfxHandle = CSfxManager::AddEmitter(data, x11c_29_acoustics, x112_prio, x11c_25_looped, GetAreaIdAlways());
}
}
}
void CScriptSound::StopSound(CStateManager& mgr) {
x11c_24_playRequested = false;