1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#include "d/snd/d_snd_anim_sound.h"
#include "common.h"
#include "d/snd/d_snd_source.h"
#include <cmath>
dSndAnimSound_c::dSndAnimSound_c(dSoundSource_c *source)
: mSound(*source), mpData(nullptr), mRate(1.0f), field_0x98(INFINITY), mNeedFrameReset(false) {}
void dSndAnimSound_c::setData(const void *data, const char *name) {
mDirection = nw4r::snd::AnimSound::FORWARD;
mRate = 1.0f;
if (data == mpData) {
return;
}
mpData = data;
if (mpData != nullptr) {
mNeedFrameReset = true;
mSound.Setup(data);
} else {
mSound.Shutdown();
}
}
void dSndAnimSound_c::setFrame(f32 frame) {
if (mpData == nullptr) {
mSound.Shutdown();
return;
}
if (frame >= mSound.GetAnimDuration()) {
return;
}
if (mNeedFrameReset) {
if (frame <= field_0x98) {
mSound.ResetFrame(0.0f, 0);
} else {
mSound.ResetFrame(frame, 0);
}
mNeedFrameReset = false;
}
mSound.UpdateFrame(frame, mDirection);
}
void dSndAnimSound_c::setRate(f32 rate) {
if (rate < 0.0f) {
mDirection = nw4r::snd::AnimSound::BACKWARD;
} else {
mDirection = nw4r::snd::AnimSound::FORWARD;
}
mRate = rate;
}
void dSndAnimSound_c::resetFrame(f32 frame) {
if (mpData == nullptr || mSound.GetAnimDuration() <= frame) {
return;
}
mNeedFrameReset = false;
mSound.ResetFrame(frame, 0);
}
void dSndAnimSound_c::animCallback(int, s32, const char *, UNKWORD arg, void *userData) {
reinterpret_cast<dSoundSource_c *>(userData)->onAnimSoundEvent(arg);
}
void dSndAnimSound_c::setCallback(dSoundSource_c *source) {
mSound.SetCallback(&animCallback, source);
}
void dSndAnimSound_c::setCallback(nw4r::snd::AnimSound::Callback cb, void *userData) {
mSound.SetCallback(cb, userData);
}
|