Overlord: mirror sound RPC command (#2094)

And replace the previous mechanism for mirroring the sound.
This commit is contained in:
Ziemas 2023-01-05 00:22:18 +01:00 committed by GitHub
parent 8f4dfa27dd
commit f0ca0cbe6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 63 additions and 12 deletions

View File

@ -601,6 +601,7 @@
(list-sounds)
(unload-music)
(set-fps)
(set-mirror 201) ;; added
)
;; flavors for music
@ -3429,6 +3430,17 @@
:flag-assert #x900000004
)
; added
(defenum sound-mirror-mode
:type uint8
(normal)
(mirrored)
)
; added for mirror mode
(deftype sound-rpc-set-mirror-mode (sound-rpc-cmd)
((mirror sound-mirror-mode)))
(deftype sound-rpc-union (structure)
((data uint32 20 :offset-assert 0)
(load-bank sound-rpc-load-bank :offset 0)
@ -3454,6 +3466,7 @@
(shutdown sound-rpc-shutdown :offset 0)
(list-sounds sound-rpc-list-sounds :offset 0)
(unload-music sound-rpc-unload-music :offset 0)
(mirror-mode sound-rpc-set-mirror-mode :offset 0) ;; added
)
:method-count-assert 9
:size-assert #x50

View File

@ -733,9 +733,13 @@ void* RPC_Loader(unsigned int /*fno*/, void* data, int size) {
}
SignalSema(gSema);
} break;
case Jak1SoundCommand::MIRROR_MODE: {
gMirrorMode = cmd->mirror.value;
} break;
default:
ASSERT_MSG(false, fmt::format("Unhandled RPC Loader command {}",
magic_enum::enum_name(cmd->j1command)));
ASSERT_MSG(false,
fmt::format("Unhandled RPC Loader command {} ({})",
magic_enum::enum_name(cmd->j1command), (int)cmd->j1command));
}
n_messages--;
cmd++;

View File

@ -43,7 +43,8 @@ enum class Jak1SoundCommand : u16 {
SET_EAR_TRANS = 19,
SHUTDOWN = 20,
LIST_SOUNDS = 21,
UNLOAD_MUSIC = 22
UNLOAD_MUSIC = 22,
MIRROR_MODE = 201,
};
enum class Jak2SoundCommand : u16 {
@ -193,6 +194,10 @@ struct SoundRpcSetMidiReg {
s32 value;
};
struct SoundRpcSetMirrror {
u8 value;
};
struct SoundRpcCommand {
u16 rsvd1;
union {
@ -217,6 +222,7 @@ struct SoundRpcCommand {
SoundRpcSetParamCommand param;
SoundRpcStereoMode stereo_mode;
SoundRpcSetMidiReg midi_reg;
SoundRpcSetMirrror mirror;
u8 max_size[0x4C]; // Temporary
};
};

View File

@ -27,6 +27,8 @@ s32 gMusicFadeDir = 0;
u32 gStreamSRAM = 0;
u32 gTrapSRAM = 0;
u8 gMirrorMode = 0;
s32 gSema;
static u32 sLastTick;
@ -351,6 +353,7 @@ s32 CalculateFallofVolume(Vec3w* pos, s32 volume, s32 fo_curve, s32 fo_min, s32
s32 CalculateAngle(Vec3w* trans) {
s32 diffX = gCamTrans.x - trans->x;
s32 diffZ = gCamTrans.z - trans->z;
s32 angle;
s32 lookupX = diffX;
s32 lookupZ = diffZ;
@ -367,7 +370,6 @@ s32 CalculateAngle(Vec3w* trans) {
return 0;
}
s32 angle;
if (lookupZ >= lookupX) {
angle = atan_table[(lookupX << 8) / lookupZ];
@ -396,7 +398,13 @@ s32 CalculateAngle(Vec3w* trans) {
}
}
return (angle - gCamAngle + 720) % 360;
angle = (angle - gCamAngle + 720) % 360;
if (gMirrorMode) {
angle = ((180 - angle) + 180) % 360;
}
return angle;
}
s32 GetVolume(Sound* sound) {

View File

@ -18,6 +18,7 @@ extern s32 gMusicVol;
extern VolumePair gPanTable[361];
extern u32 gStreamSRAM;
extern u32 gTrapSRAM;
extern u8 gMirrorMode;
struct Vec3w {
s32 x;

View File

@ -94,6 +94,7 @@
(list-sounds)
(unload-music)
(set-fps)
(set-mirror 201)
)
;; flavors for music
@ -164,6 +165,12 @@
(fo-curve)
)
(defenum sound-mirror-mode
:type uint8
(normal)
(mirrored)
)
;; like should match the sound type in OVERLORD
;; This is shared between all sound RPCs and acts like the header for the sound messages
(deftype sound-rpc-cmd (structure)
@ -412,6 +419,10 @@
:flag-assert #x900000004
)
; added for mirror mode
(deftype sound-rpc-set-mirror-mode (sound-rpc-cmd)
((mirror sound-mirror-mode)))
;; union of all the possible sound commands.
(deftype sound-rpc-union (structure)
((data uint32 20 :offset-assert 0)
@ -438,6 +449,7 @@
(shutdown sound-rpc-shutdown :offset 0)
(list-sounds sound-rpc-list-sounds :offset 0)
(unload-music sound-rpc-unload-music :offset 0)
(mirror-mode sound-rpc-set-mirror-mode :offset 0)
)
:method-count-assert 9
:size-assert #x50

View File

@ -212,6 +212,15 @@
0
)
(define *sound-current-mirror* (sound-mirror-mode normal))
(defun sound-set-mirror-mode ((mode sound-mirror-mode))
(when (!= mode *sound-current-mirror*)
(let ((cmd (the sound-rpc-set-mirror-mode (add-element *sound-loader-rpc*))))
(set! (-> cmd command) (sound-command set-mirror))
(set! (-> cmd mirror) mode))
(call *sound-loader-rpc* (the-as uint 0) (the-as pointer 0) (the-as uint 0))
(set! *sound-current-mirror* mode))
(none))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; sound playback
@ -335,13 +344,6 @@
(sound-trans-convert (-> cmd ear-trans) ear-trans)
(sound-trans-convert (-> cmd cam-trans) cam-trans)
(set! (-> cmd cam-angle) (sound-angle-convert cam-angle))
(#when PC_PORT
(when (pc-cheats? (-> *pc-settings* cheats) mirror)
;; flip sound pan.
;; this isn't really appropriate if there's front-back panning (surround)...
(+! (-> cmd cam-angle) 180)
)
)
)
0
)

View File

@ -245,6 +245,10 @@
(pc-sound-set-fade-hack fade-hack)
)
(if (pc-cheats? (-> obj cheats) mirror)
(sound-set-mirror-mode (sound-mirror-mode mirrored))
(sound-set-mirror-mode (sound-mirror-mode normal)))
(none))
;; where we store the input progress for the cheat codes. make sure there's enough space for all cheats.

View File

@ -599,6 +599,7 @@
(shutdown sound-rpc-shutdown :offset 0)
(list-sounds sound-rpc-list-sounds :offset 0)
(unload-music sound-rpc-unload-music :offset 0)
(mirror-mode sound-rpc-set-mirror-mode :offset 0)
)
:method-count-assert 9
:size-assert #x50