diff --git a/game/graphics/sceGraphicsInterface.cpp b/game/graphics/sceGraphicsInterface.cpp index d291f90b1e..6aac5303d2 100644 --- a/game/graphics/sceGraphicsInterface.cpp +++ b/game/graphics/sceGraphicsInterface.cpp @@ -2,6 +2,7 @@ #include "game/graphics/gfx.h" #include #include "common/util/Assert.h" +#include "game/overlord/srpc.h" /*! * Wait for rendering to complete. @@ -28,5 +29,6 @@ u32 sceGsSyncPath(u32 mode, u32 timeout) { */ u32 sceGsSyncV(u32 mode) { ASSERT(mode == 0); + VBlank_Handler(); return Gfx::vsync(); } diff --git a/game/overlord/srpc.cpp b/game/overlord/srpc.cpp index b028b162ef..355c2502a3 100644 --- a/game/overlord/srpc.cpp +++ b/game/overlord/srpc.cpp @@ -104,19 +104,21 @@ void* RPC_Player(unsigned int /*fno*/, void* data, int size) { while (n_messages > 0) { switch (cmd->command) { case SoundCommand::PLAY: { - // spool- soundsn are vag sounds? + if (cmd->play.sound_id == 0) { + break; + } if (!memcmp(cmd->play.name, "spool-", 6)) { - char namebuf[8]; - char langbuf[8]; - auto name = cmd->play.name; + char namebuf[16]; + const char* name = &cmd->play.name[6]; size_t len = strlen(name); if (len < 9) { - memset(namebuf, 32, sizeof(namebuf)); + memset(namebuf, ' ', 8); memcpy(namebuf, name, len); } else { - memcpy(namebuf, name, sizeof(namebuf)); + memcpy(namebuf, name, 8); } + // ASCII toupper for (int i = 0; i < 8; i++) { if (namebuf[i] >= 0x61 && namebuf[i] < 0x7b) { namebuf[i] -= 0x20; @@ -126,8 +128,8 @@ void* RPC_Player(unsigned int /*fno*/, void* data, int size) { // TODO vagfile = FindVAGFile(namebuf); void* vagfile = nullptr; - memcpy(namebuf, "VAGWAD ", sizeof(namebuf)); - strcpy(langbuf, gLanguage); + memcpy(namebuf, "VAGWAD ", 8); + strcpy(&namebuf[8], gLanguage); FileRecord* rec = isofs->find_in(namebuf); if (vagfile != nullptr) { @@ -191,7 +193,7 @@ void* RPC_Player(unsigned int /*fno*/, void* data, int size) { sound->params.pitch_mod, sound->params.bend); sound->sound_handle = handle; if (sound->sound_handle) { - sound->id = index; + sound->id = cmd->play.sound_id; } } break; case SoundCommand::PAUSE_SOUND: { @@ -223,7 +225,7 @@ void* RPC_Player(unsigned int /*fno*/, void* data, int size) { u32 mask = cmd->param.parms.mask; if (sound != nullptr) { if (mask & 1) { - if (mask & 0x20) { + if (mask & 0x10) { sound->auto_time = cmd->param.auto_time; sound->new_volume = cmd->param.parms.volume; } else { @@ -240,7 +242,7 @@ void* RPC_Player(unsigned int /*fno*/, void* data, int size) { sound->params.pitch_mod = cmd->param.parms.pitch_mod; if (mask & 0x10) { snd_AutoPitch(sound->sound_handle, sound->params.pitch_mod, cmd->param.auto_time, - cmd->param.auto_time); + cmd->param.auto_from); } else { snd_SetSoundPitchModifier(sound->sound_handle, cmd->param.parms.pitch_mod); } @@ -249,7 +251,7 @@ void* RPC_Player(unsigned int /*fno*/, void* data, int size) { sound->params.bend = cmd->param.parms.bend; if (mask & 0x10) { snd_AutoPitchBend(sound->sound_handle, sound->params.bend, cmd->param.auto_time, - cmd->param.auto_time); + cmd->param.auto_from); } else { snd_SetSoundPitchBend(sound->sound_handle, cmd->param.parms.bend); } @@ -420,5 +422,22 @@ void* RPC_Loader(unsigned int /*fno*/, void* data, int size) { } s32 VBlank_Handler() { + if (!gSoundEnable) + return 1; + + if (gMusicFadeDir > 0) { + gMusicFade += 1024; + if (gMusicFade > 0x10000) { + gMusicFade = 0x10000; + gMusicFadeDir = 0; + } + } else if (gMusicFadeDir < 0) { + gMusicFade -= 512; + if (gMusicFade < 0) { + gMusicFade = 0; + gMusicFadeDir = 0; + } + } + return 1; } diff --git a/game/overlord/ssound.cpp b/game/overlord/ssound.cpp index 51e368beab..9c2f7e3da4 100644 --- a/game/overlord/ssound.cpp +++ b/game/overlord/ssound.cpp @@ -249,7 +249,7 @@ s32 CalculateFallofVolume(Vec3w* pos, s32 volume, s32 fo_curve, s32 fo_min, s32 zdiff >>= 1; } - s32 distance = xdiff * xdiff + ydiff * ydiff + zdiff * zdiff; + u32 distance = xdiff * xdiff + ydiff * ydiff + zdiff * zdiff; if (distance != 0) { s32 steps = 0; while ((distance & 0xc0000000) == 0) { @@ -284,7 +284,7 @@ s32 CalculateFallofVolume(Vec3w* pos, s32 volume, s32 fo_curve, s32 fo_min, s32 } s32 factor = ((gCurve[fo_curve].unk4 << 16) + gCurve[fo_curve].unk3 * v13 + - gCurve[fo_curve].unk2 * ((v13 * 13) >> 16) + + gCurve[fo_curve].unk2 * ((v13 * v13) >> 16) + gCurve[fo_curve].unk1 * (((((v13 * v13) >> 16) * v13) >> 16) >> 16)) >> 12; @@ -310,7 +310,7 @@ s32 CalculateAngle(Vec3w* trans) { lookupZ = trans->z - gCamTrans.z; } - if (diffX == 0 && diffZ == 0) { + if (lookupX == 0 && lookupZ == 0) { return 0; } @@ -339,7 +339,7 @@ s32 CalculateAngle(Vec3w* trans) { } else if (diffZ >= 0) { angle = angle + 270; } else { - angle = 270 - 90; + angle = 270 - angle; } } @@ -413,10 +413,10 @@ static void UpdateAutoVol(Sound* sound, s32 ticks) { if (sound->new_volume == -4) { snd_StopSound(sound->sound_handle); sound->id = 0; - return; + } else { + sound->params.volume = sound->new_volume; } - sound->params.volume = sound->new_volume; sound->auto_time = 0; }