snd_Sound3DActor OK

This commit is contained in:
robojumper
2025-05-29 00:59:18 +02:00
parent 2374b07ba4
commit 05fe105f5d
11 changed files with 164 additions and 35 deletions
+86
View File
@@ -1 +1,87 @@
#include "nw4r/snd/snd_Sound3DActor.h"
#include "nw4r/snd/snd_BasicSound.h"
#include "nw4r/snd/snd_ExternalSoundPlayer.h"
#include "nw4r/snd/snd_Sound3DManager.h"
#include "nw4r/snd/snd_SoundArchive.h"
#include "nw4r/snd/snd_SoundArchivePlayer.h"
#include "nw4r/snd/snd_SoundHandle.h"
#include "nw4r/snd/snd_SoundStartable.h"
#include "nw4r/snd/snd_global.h"
namespace nw4r {
namespace snd {
Sound3DActor::Sound3DActor(SoundArchivePlayer &rPlayer, Sound3DManager &rManager)
: SoundActor(rPlayer),
m3DManager(rManager),
mSoundArchivePlayer(&rPlayer),
mUserParam(0),
mPosition(0.0f, 0.0f, 0.0f),
mVelocity(0.0f, 0.0f, 0.0f),
mSkipVelocityUpdate(true) {}
Sound3DActor::~Sound3DActor() {
ForEachSound(ClearUpdateCallback, false);
}
SoundStartable::StartResult
Sound3DActor::SetupSound(SoundHandle *pHandle, u32 soundId, const StartInfo *pStartInfo, void *pArg) {
Sound3DParam param;
param.position = mPosition;
param.velocity = mVelocity;
param.userParam = mUserParam;
if (mSoundArchivePlayer != NULL) {
const SoundArchive &archive = mSoundArchivePlayer->GetSoundArchive();
nw4r::snd::SoundArchive::Sound3DParam arParam;
if (archive.detail_ReadSound3DParam(soundId, &arParam)) {
param.field_0x18 = arParam.flags;
param.decayRatio = arParam.decayRatio;
param.field_0x1E = arParam.field_0x06;
switch (arParam.decayCurve) {
case 1: param.decayCurve = 1; break;
case 2: param.decayCurve = 2; break;
default: param.decayCurve = 1; break;
}
}
param.field_0x24 = archive.GetSoundUserParam(soundId);
}
detail::BasicSound::AmbientInfo info = {
&m3DManager, this, &m3DManager, &param, sizeof(Sound3DParam),
};
SoundStartable::StartResult result =
SoundActor::detail_SetupSoundWithAmbientInfo(pHandle, soundId, pStartInfo, &info, pArg);
if (pHandle->detail_GetAttachedSound() != NULL) {
pHandle->detail_GetAttachedSound()->SetPanCurve(PAN_CURVE_SINCOS);
}
return result;
}
void Sound3DActor::SetPosition(const math::VEC3 &position) {
if (!mSkipVelocityUpdate) {
VEC3Sub(&mVelocity, &position, &mPosition);
}
mPosition = position;
mSkipVelocityUpdate = 0;
}
void Sound3DActor::at_0x0c(void *arg, detail::BasicSound *sound) {
Sound3DParam *p = static_cast<Sound3DParam *>(arg);
p->position = mPosition;
p->velocity = mVelocity;
p->userParam = mUserParam;
}
void Sound3DActor::ClearUpdateCallback(SoundHandle& rHandle) {
if (rHandle.IsAttachedSound()) {
rHandle.detail_GetAttachedSound()->ClearAmbientArgUpdateCallback();
}
}
} // namespace snd
} // namespace nw4r
+2 -2
View File
@@ -131,10 +131,10 @@ void Sound3DCalculator::CalcPitch(
f32 f3 = param.field_0x1E / 32.0f;
f32 f1, f2;
if (distance > 0.0f) {
f1 = -math::VEC3Dot(&relativePos, &param.field_0x0C);
f1 = -math::VEC3Dot(&relativePos, &param.velocity);
f2 = -math::VEC3Dot(&relativePos, &listener.GetVelocity());
} else {
f1 = -math::VEC3Len(&param.field_0x0C);
f1 = -math::VEC3Len(&param.velocity);
f2 = math::VEC3Len(&listener.GetVelocity());
}
f32 pitch;
+1 -1
View File
@@ -94,7 +94,7 @@ Sound3DParam::Sound3DParam() {
decayCurve = Sound3DManager::DECAY_CURVE_LOGARITHMIC;
decayRatio = 128;
field_0x1E = 0;
field_0x20 = 0;
userParam = 0;
field_0x24 = 0;
}