[jak2] fully implement PLAYER set-param for VAG streams + fix regression (#3314)

At last...
This commit is contained in:
ManDude 2024-01-18 01:59:04 +00:00 committed by GitHub
parent ba7b0397b1
commit 13f1aa1785
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 21 deletions

View file

@ -172,7 +172,7 @@ s32 CalculateFalloffVolume(Vec3w* pos, s32 volume, s32 fo_curve, s32 fo_min, s32
} else {
if (fo_curve == 1) {
return volume;
} else if (fo_curve == 9) {
} else if (fo_curve == 9 || fo_curve == 11) {
xdiff = gEarTrans[1].x - pos->x;
ydiff = gEarTrans[1].y - pos->y;
zdiff = gEarTrans[1].z - pos->z;
@ -180,10 +180,6 @@ s32 CalculateFalloffVolume(Vec3w* pos, s32 volume, s32 fo_curve, s32 fo_min, s32
xdiff = 0;
ydiff = gEarTrans[0].y - pos->y;
zdiff = 0;
} else if (fo_curve == 11) {
xdiff = gEarTrans[1].x - pos->x;
ydiff = gEarTrans[1].y - pos->y;
zdiff = gEarTrans[1].z - pos->z;
} else {
xdiff = gEarTrans[0].x - pos->x;
ydiff = gEarTrans[0].y - pos->y;
@ -213,38 +209,36 @@ s32 CalculateFalloffVolume(Vec3w* pos, s32 volume, s32 fo_curve, s32 fo_min, s32
ydiff >>= 1;
zdiff >>= 1;
}
s32 dist_squared = xdiff * xdiff + ydiff * ydiff + zdiff * zdiff;
u32 dist_squared = xdiff * xdiff + ydiff * ydiff + zdiff * zdiff;
s32 dist_steps = 0;
if (dist_squared != 0) {
while ((dist_squared & 0xc0000000) == 0) {
dist_steps = dist_steps + 1;
++dist_steps;
dist_squared <<= 2;
}
dist_steps = sqrt_table[dist_squared >> 24] >> (dist_steps & 0x1f);
}
new_vol = volume;
if (min < dist_steps) {
s32 voldiff = dist_steps - min;
u32 voldiff = dist_steps - min;
if (dist_steps < max) {
dist_steps = max - min;
while (0xffff < voldiff) {
while (voldiff > 0xffff) {
dist_steps >>= 1;
voldiff >>= 1;
}
voldiff = (voldiff << 0x10) / dist_steps;
if (voldiff != 0x10000) {
new_vol = voldiff * voldiff >> 0x10;
new_vol = gCurves[fo_curve].unk4 * 0x10000 + gCurves[fo_curve].unk3 * voldiff +
new_vol = (voldiff * voldiff) >> 0x10;
new_vol = (gCurves[fo_curve].unk4 * 0x10000 + gCurves[fo_curve].unk3 * voldiff +
gCurves[fo_curve].unk2 * new_vol +
gCurves[fo_curve].unk1 * ((new_vol * voldiff) >> 0x10) >>
gCurves[fo_curve].unk1 * ((new_vol * voldiff) >> 0x10)) >>
0xc;
if (new_vol < 0) {
new_vol = 0;
} else {
if (0x10000 < new_vol) {
} else if (0x10000 < new_vol) {
new_vol = 0x10000;
}
}
new_vol = (new_vol * volume) >> 0x10;
}
} else {

View file

@ -176,7 +176,6 @@ void* RPC_Player(unsigned int /*fno*/, void* data, int size) {
PauseVAG(vs, 1);
}
}
// TODO vag
} break;
case Jak2SoundCommand::stop_sound: {
Sound* sound = LookupSound(cmd->sound_id.sound_id);
@ -188,7 +187,6 @@ void* RPC_Player(unsigned int /*fno*/, void* data, int size) {
StopVagStream(vs, 1);
}
}
// TODO vag
} break;
case Jak2SoundCommand::continue_sound: {
Sound* sound = LookupSound(cmd->sound_id.sound_id);
@ -200,7 +198,6 @@ void* RPC_Player(unsigned int /*fno*/, void* data, int size) {
UnPauseVAG(vs, 1);
}
}
// TODO vag
} break;
case Jak2SoundCommand::set_param: {
Sound* sound = LookupSound(cmd->sound_id.sound_id);
@ -271,9 +268,24 @@ void* RPC_Player(unsigned int /*fno*/, void* data, int size) {
if (mask & 0x2) {
SetVAGStreamPitch(cmd->param.sound_id, cmd->param.parms.pitch_mod);
}
if (mask & 0x20) {
vs->vec3 = cmd->param.parms.trans;
vs->unk_296 = 1;
}
if (mask & 0x40) {
vs->fo_min = cmd->param.parms.fo_min;
}
if (mask & 0x80) {
vs->fo_max = cmd->param.parms.fo_max;
}
if (mask & 0x100) {
vs->fo_curve = cmd->param.parms.fo_curve;
}
if (mask & 0x1) {
vs->vol_multiplier = cmd->param.parms.volume;
}
}
}
// TODO vag
} break;
case Jak2SoundCommand::set_master_volume: {
u32 group = cmd->master_volume.group.group;