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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
#include "d/snd/d_snd_source_group.h"
#include "common.h"
#include "d/snd/d_snd_source.h"
#include "d/snd/d_snd_source_enums.h"
#include "d/snd/d_snd_source_mgr.h"
#include "d/snd/d_snd_state_mgr.h"
#include "nw4r/ut/ut_list.h"
#include <cmath>
void dSndSourceGroup_c::setParam(s32 sourceType, const char *name) {
resetSoundSourceParam();
bool assignedParam = false;
switch (mSourceCategory) {
case SND_SOURCE_CATEGORY_PLAYER: {
assignedParam = true;
mParam.field_0x10 = INFINITY;
break;
}
case SND_SOURCE_CATEGORY_EQUIPMENT:
if (sourceType == SND_SOURCE_ARROW) {
assignedParam = true;
mParam.field_0x00 = 1500.0f;
mParam.field_0x10 = INFINITY;
}
break;
}
if (!assignedParam && (sourceType == SND_SOURCE_KENSEI || sourceType == SND_SOURCE_58)) {
assignedParam = true;
mParam.field_0x10 = INFINITY;
}
if (!assignedParam) {
assignedParam = setParamFromName(name);
}
if (!assignedParam) {
switch (sourceType) {
case SND_SOURCE_NPC_51: {
mParam.field_0x00 = 300.0f;
mParam.field_0x04 = 800.0;
mParam.field_0x10 = 2200.0;
break;
}
case SND_SOURCE_NPC_HEAD: {
if (dSndStateMgr_c::isInStage("F401")) {
mParam.field_0x00 = 500.0f;
mParam.field_0x04 = 4000.0;
} else if (dSndStateMgr_c::isInStage("F402")) {
mParam.field_0x00 = 400.0f;
mParam.field_0x04 = 3500.0;
} else {
mParam.field_0x00 = 300.0f;
mParam.field_0x04 = 800.0;
mParam.field_0x10 = 2200.0;
}
mParam.field_0x10 = INFINITY;
}
}
}
}
void dSndSourceGroup_c::resetSoundSourceParam() {
mParam.reset();
}
dSndSourceGroup_c::dSndSourceGroup_c()
: mSubtype(0),
mIsActive(false),
field_0x1D(false),
mName(""),
mpOrigName(nullptr),
mpCachedClosestSourceToListener(nullptr),
mpCachedClosestSourceToPlayer(nullptr),
mCalculatedClosestToListener(false),
mCalculatedClosestToPlayer(false) {
// TODO offsetof
nw4r::ut::List_Init(&mSubSourceList, 0x138);
resetSoundSourceParam();
}
dSndSourceGroup_c::dSndSourceGroup_c(s32 sourceType, const char *name, const char *origName, s32 subtype)
: mSourceCategory(-1),
mSubtype(subtype),
mIsActive(false),
field_0x1D(false),
mName(name),
mpOrigName(origName),
mpCachedClosestSourceToListener(nullptr),
mpCachedClosestSourceToPlayer(nullptr),
mCalculatedClosestToListener(false),
mCalculatedClosestToPlayer(false) {
nw4r::ut::List_Init(&mSubSourceList, 0x138);
setParam(sourceType, name);
}
void dSndSourceGroup_c::set(s32 sourceType, const char *name, const char *origName, s32 subtype) {
mSourceCategory = dSndSourceMgr_c::getSourceCategoryForSourceType(sourceType, name);
setParam(sourceType, name);
mSourceType = sourceType;
mName = name;
mSubtype = subtype;
mpCachedClosestSourceToPlayer = nullptr;
mpCachedClosestSourceToListener = nullptr;
mCalculatedClosestToPlayer = false;
mCalculatedClosestToListener = false;
mpOrigName = origName;
}
void dSndSourceGroup_c::setTemp(s32 sourceType, const char *name, s32 subtype) {
mSourceType = sourceType;
mName = name;
mSubtype = subtype;
}
dSndSourceGroup_c::~dSndSourceGroup_c() {
clearList();
}
void dSndSourceGroup_c::clear() {
clearList();
mIsActive = false;
field_0x1D = false;
mName = "";
}
void dSndSourceGroup_c::clearTemp() {
mIsActive = false;
field_0x1D = false;
mName = "";
}
void dSndSourceGroup_c::calc() {
// Reset freshness flags, computed on-demand
mCalculatedClosestToPlayer = false;
mCalculatedClosestToListener = false;
}
s32 dSndSourceGroup_c::getNumSources() const {
return nw4r::ut::List_GetSize(&mSubSourceList);
}
void dSndSourceGroup_c::registerSource(dSoundSource_c *source) {
if (source != nullptr) {
appendSubSource(source);
}
}
void dSndSourceGroup_c::unregisterSource(dSoundSource_c *source) {
if (source != nullptr) {
removeSubSource(source);
}
}
void dSndSourceGroup_c::clearList() {
dSoundSource_c *source = getSubSourceFirst();
while (source != nullptr) {
removeSubSource(source);
source = getSubSourceFirst();
}
}
dSoundSource_c *dSndSourceGroup_c::getSourceClosestToListener() {
if (mCalculatedClosestToListener) {
return mpCachedClosestSourceToListener;
}
mpCachedClosestSourceToListener = nullptr;
f32 closest = INFINITY;
for (dSoundSource_c *source = getSubSourceFirst();
source != nullptr; source = getSubSourceNext(source)) {
if (source->getSourceType() != SND_SOURCE_PLAYER_HEAD && source->getSourceType() != SND_SOURCE_NPC_HEAD) {
f32 dist = source->getDistanceToListener();
if (dist < closest) {
closest = dist;
mpCachedClosestSourceToListener = source;
}
}
}
mCalculatedClosestToListener = true;
return mpCachedClosestSourceToListener;
}
dSoundSource_c *dSndSourceGroup_c::getSourceClosestToPlayer() {
if (mCalculatedClosestToPlayer) {
return mpCachedClosestSourceToPlayer;
}
if ((s32)nw4r::ut::List_GetSize(&mSubSourceList) <= 1) {
return getSubSourceFirst();
}
mpCachedClosestSourceToPlayer = nullptr;
f32 closest = INFINITY;
for (dSoundSource_c *source = getSubSourceFirst();
source != nullptr; source = getSubSourceNext(source)) {
if (source->getSourceType() != 1 && source->getSourceType() != 48) {
f32 dist = source->getDistanceToPlayer();
if (dist < closest) {
closest = dist;
mpCachedClosestSourceToPlayer = source;
}
}
}
mCalculatedClosestToPlayer = true;
return mpCachedClosestSourceToPlayer;
}
bool dSndSourceGroup_c::setParamFromName(const char *) {
// TODO
return false;
}
|