Skip to content

Commit 13f1aa1

Browse files
authored
[jak2] fully implement PLAYER set-param for VAG streams + fix regression (#3314)
At last...
1 parent ba7b039 commit 13f1aa1

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

game/overlord/common/ssound.cpp

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,14 @@ s32 CalculateFalloffVolume(Vec3w* pos, s32 volume, s32 fo_curve, s32 fo_min, s32
172172
} else {
173173
if (fo_curve == 1) {
174174
return volume;
175-
} else if (fo_curve == 9) {
175+
} else if (fo_curve == 9 || fo_curve == 11) {
176176
xdiff = gEarTrans[1].x - pos->x;
177177
ydiff = gEarTrans[1].y - pos->y;
178178
zdiff = gEarTrans[1].z - pos->z;
179179
} else if (fo_curve == 10) {
180180
xdiff = 0;
181181
ydiff = gEarTrans[0].y - pos->y;
182182
zdiff = 0;
183-
} else if (fo_curve == 11) {
184-
xdiff = gEarTrans[1].x - pos->x;
185-
ydiff = gEarTrans[1].y - pos->y;
186-
zdiff = gEarTrans[1].z - pos->z;
187183
} else {
188184
xdiff = gEarTrans[0].x - pos->x;
189185
ydiff = gEarTrans[0].y - pos->y;
@@ -213,37 +209,35 @@ s32 CalculateFalloffVolume(Vec3w* pos, s32 volume, s32 fo_curve, s32 fo_min, s32
213209
ydiff >>= 1;
214210
zdiff >>= 1;
215211
}
216-
s32 dist_squared = xdiff * xdiff + ydiff * ydiff + zdiff * zdiff;
212+
u32 dist_squared = xdiff * xdiff + ydiff * ydiff + zdiff * zdiff;
217213
s32 dist_steps = 0;
218214
if (dist_squared != 0) {
219215
while ((dist_squared & 0xc0000000) == 0) {
220-
dist_steps = dist_steps + 1;
216+
++dist_steps;
221217
dist_squared <<= 2;
222218
}
223219
dist_steps = sqrt_table[dist_squared >> 24] >> (dist_steps & 0x1f);
224220
}
225221
new_vol = volume;
226222
if (min < dist_steps) {
227-
s32 voldiff = dist_steps - min;
223+
u32 voldiff = dist_steps - min;
228224
if (dist_steps < max) {
229225
dist_steps = max - min;
230-
while (0xffff < voldiff) {
226+
while (voldiff > 0xffff) {
231227
dist_steps >>= 1;
232228
voldiff >>= 1;
233229
}
234230
voldiff = (voldiff << 0x10) / dist_steps;
235231
if (voldiff != 0x10000) {
236-
new_vol = voldiff * voldiff >> 0x10;
237-
new_vol = gCurves[fo_curve].unk4 * 0x10000 + gCurves[fo_curve].unk3 * voldiff +
238-
gCurves[fo_curve].unk2 * new_vol +
239-
gCurves[fo_curve].unk1 * ((new_vol * voldiff) >> 0x10) >>
232+
new_vol = (voldiff * voldiff) >> 0x10;
233+
new_vol = (gCurves[fo_curve].unk4 * 0x10000 + gCurves[fo_curve].unk3 * voldiff +
234+
gCurves[fo_curve].unk2 * new_vol +
235+
gCurves[fo_curve].unk1 * ((new_vol * voldiff) >> 0x10)) >>
240236
0xc;
241237
if (new_vol < 0) {
242238
new_vol = 0;
243-
} else {
244-
if (0x10000 < new_vol) {
245-
new_vol = 0x10000;
246-
}
239+
} else if (0x10000 < new_vol) {
240+
new_vol = 0x10000;
247241
}
248242
new_vol = (new_vol * volume) >> 0x10;
249243
}

game/overlord/jak2/srpc.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ void* RPC_Player(unsigned int /*fno*/, void* data, int size) {
176176
PauseVAG(vs, 1);
177177
}
178178
}
179-
// TODO vag
180179
} break;
181180
case Jak2SoundCommand::stop_sound: {
182181
Sound* sound = LookupSound(cmd->sound_id.sound_id);
@@ -188,7 +187,6 @@ void* RPC_Player(unsigned int /*fno*/, void* data, int size) {
188187
StopVagStream(vs, 1);
189188
}
190189
}
191-
// TODO vag
192190
} break;
193191
case Jak2SoundCommand::continue_sound: {
194192
Sound* sound = LookupSound(cmd->sound_id.sound_id);
@@ -200,7 +198,6 @@ void* RPC_Player(unsigned int /*fno*/, void* data, int size) {
200198
UnPauseVAG(vs, 1);
201199
}
202200
}
203-
// TODO vag
204201
} break;
205202
case Jak2SoundCommand::set_param: {
206203
Sound* sound = LookupSound(cmd->sound_id.sound_id);
@@ -271,9 +268,24 @@ void* RPC_Player(unsigned int /*fno*/, void* data, int size) {
271268
if (mask & 0x2) {
272269
SetVAGStreamPitch(cmd->param.sound_id, cmd->param.parms.pitch_mod);
273270
}
271+
if (mask & 0x20) {
272+
vs->vec3 = cmd->param.parms.trans;
273+
vs->unk_296 = 1;
274+
}
275+
if (mask & 0x40) {
276+
vs->fo_min = cmd->param.parms.fo_min;
277+
}
278+
if (mask & 0x80) {
279+
vs->fo_max = cmd->param.parms.fo_max;
280+
}
281+
if (mask & 0x100) {
282+
vs->fo_curve = cmd->param.parms.fo_curve;
283+
}
284+
if (mask & 0x1) {
285+
vs->vol_multiplier = cmd->param.parms.volume;
286+
}
274287
}
275288
}
276-
// TODO vag
277289
} break;
278290
case Jak2SoundCommand::set_master_volume: {
279291
u32 group = cmd->master_volume.group.group;

0 commit comments

Comments
 (0)