-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sync footstep audio #2177
Open
OhmV-IR
wants to merge
31
commits into
SubnauticaNitrox:master
Choose a base branch
from
OhmV-IR:sync-footstep-audio
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+207
−8
Open
Sync footstep audio #2177
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
d4e3ff2
Created packet and processors for footstep audio(not functional at al…
OhmV-IR 7e0c624
prototype client-side footstep packet processing
OhmV-IR 380d9ba
Switch to using player's AnimationController to find velocity
OhmV-IR e07a5c3
Footstep packets are forwarded from server to players within hearing …
OhmV-IR 180bb35
Fixed FootstepPacket class to fit format(was crashing)
OhmV-IR 26db96c
Removed duplicate var
OhmV-IR a772c16
cleanup
OhmV-IR eaf1122
Added transpiler to send packets when local client plays footstep sou…
OhmV-IR a879656
Lower volume of other players' footsteps(suggested by NinjaPedroX)
OhmV-IR 8ef9842
Added same structure/submarine check for sending footstep packet to o…
OhmV-IR 092af16
Removed logs
OhmV-IR c6814b3
Formatting changes
OhmV-IR 737028e
Formatting changes
OhmV-IR 103c14e
Newline changes
OhmV-IR 5a5fc18
newline changes
OhmV-IR 91936ec
Split long line into shorter lines
OhmV-IR 6545583
Remove unneeded this keyword
OhmV-IR 33d249c
Applying suggestions from Jannify's review
OhmV-IR 8cc0956
Merge
OhmV-IR c1d0ef3
Added comment in packet processors to keep values updated, trying to …
OhmV-IR c4c851f
Pull sound range from .csv file(UNTESTED)
OhmV-IR 756bece
Add whitespace
OhmV-IR 30055b8
Add whitespace
OhmV-IR d26a186
Merged ifs and removed var type usage
OhmV-IR 5c6f971
Merge branch 'sync-footstep-audio' of https://github.com/OhmV-IR/Nitr…
OhmV-IR 38c6161
Merged else + if into else if
OhmV-IR 9a5927b
Inverted if with early return condition
OhmV-IR 38c1aa7
Compare subroot IDs using .Equals instead of 2 if statements
OhmV-IR 6d4dcbf
Overriding .Equals in Optional<> for consistency and performance
OhmV-IR bef5717
Merged 2 if statements & fixed bad clause
OhmV-IR 7e56f40
Fixed bug(was getting all players instead of only connected ones)
OhmV-IR File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
NitroxClient/Communication/Packets/Processors/FootstepPacketProcessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using FMOD; | ||
using FMOD.Studio; | ||
using FMODUnity; | ||
using NitroxClient.Communication.Packets.Processors.Abstract; | ||
using NitroxClient.GameLogic; | ||
using NitroxClient.GameLogic.FMOD; | ||
using NitroxModel.DataStructures.Util; | ||
using NitroxModel.GameLogic.FMOD; | ||
using NitroxModel.Packets; | ||
|
||
namespace NitroxClient.Communication.Packets.Processors; | ||
|
||
public class FootstepPacketProcessor : ClientPacketProcessor<FootstepPacket> | ||
{ | ||
private readonly PlayerManager remotePlayerManager; | ||
private readonly FootstepSounds localFootstepSounds; | ||
private PARAMETER_ID fmodIndexSpeed = FMODUWE.invalidParameterId; | ||
private readonly float footstepAudioRadius; // To modify this value, modify the last value in the SoundWhitelist_Subnautica.csv file | ||
private const float footstepAudioMaxVolume = 0.5f; | ||
|
||
public FootstepPacketProcessor(PlayerManager remotePlayerManager, FMODWhitelist whitelist) | ||
{ | ||
this.remotePlayerManager = remotePlayerManager; | ||
localFootstepSounds = Player.mainObject.GetComponent<FootstepSounds>(); | ||
whitelist.TryGetSoundData("event:/player/footstep_precursor_base", out SoundData soundData); | ||
footstepAudioRadius = soundData.Radius; | ||
} | ||
|
||
public override void Process(FootstepPacket packet) | ||
{ | ||
Optional<RemotePlayer> player = remotePlayerManager.Find(packet.PlayerID); | ||
if (player.HasValue) | ||
{ | ||
FMODAsset asset = packet.AssetIndex switch | ||
{ | ||
FootstepPacket.StepSounds.PRECURSOR_STEP_SOUND => localFootstepSounds.precursorInteriorSound, | ||
FootstepPacket.StepSounds.METAL_STEP_SOUND => localFootstepSounds.metalSound, | ||
FootstepPacket.StepSounds.LAND_STEP_SOUND => localFootstepSounds.landSound, | ||
_ => null | ||
}; | ||
EventInstance evt = FMODUWE.GetEvent(asset); | ||
if (evt.isValid()) | ||
{ | ||
if (FMODUWE.IsInvalidParameterId(fmodIndexSpeed)) | ||
{ | ||
fmodIndexSpeed = FMODUWE.GetEventInstanceParameterIndex(evt, "speed"); | ||
} | ||
ATTRIBUTES_3D attributes = player.Value.Body.To3DAttributes(); | ||
evt.set3DAttributes(attributes); | ||
evt.setParameterValueByIndex(fmodIndexSpeed, player.Value.AnimationController.Velocity.magnitude); | ||
evt.setVolume(FMODSystem.CalculateVolume(Player.mainObject.transform.position, player.Value.Body.transform.position, footstepAudioRadius, footstepAudioMaxVolume)); | ||
evt.start(); | ||
evt.release(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
|
||
namespace NitroxModel.Packets; | ||
|
||
[Serializable] | ||
public class FootstepPacket : Packet | ||
{ | ||
public ushort PlayerID { get; } | ||
public StepSounds AssetIndex { get; } | ||
|
||
public FootstepPacket(ushort playerID, StepSounds assetIndex) | ||
{ | ||
this.PlayerID = playerID; | ||
this.AssetIndex = assetIndex; | ||
} | ||
|
||
public enum StepSounds : byte | ||
{ | ||
PRECURSOR_STEP_SOUND, | ||
METAL_STEP_SOUND, | ||
LAND_STEP_SOUND | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like we're repeating twice "step sound" while writing StepSounds.X_STEP_SOUND while it could probably be better as StepSounds.X |
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
NitroxServer/Communication/Packets/Processors/FootstepPacketProcessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using NitroxModel.DataStructures.Unity; | ||
using NitroxModel.GameLogic.FMOD; | ||
using NitroxModel.Packets; | ||
using NitroxServer.Communication.Packets.Processors.Abstract; | ||
using NitroxServer.GameLogic; | ||
|
||
namespace NitroxServer.Communication.Packets.Processors; | ||
|
||
public class FootstepPacketProcessor : AuthenticatedPacketProcessor<FootstepPacket> | ||
{ | ||
private readonly float footstepAudioRange; // To modify this value, modify the last value in the SoundWhitelist_Subnautica.csv file | ||
private readonly PlayerManager playerManager; | ||
|
||
public FootstepPacketProcessor(PlayerManager playerManager, FMODWhitelist whitelist) | ||
{ | ||
this.playerManager = playerManager; | ||
whitelist.TryGetSoundData("event:/player/footstep_precursor_base", out SoundData soundData); | ||
footstepAudioRange = soundData.Radius; | ||
} | ||
|
||
public override void Process(FootstepPacket footstepPacket, Player sendingPlayer) | ||
{ | ||
foreach (Player player in playerManager.GetConnectedPlayers()) | ||
{ | ||
if (NitroxVector3.Distance(player.Position, sendingPlayer.Position) >= footstepAudioRange || | ||
player == sendingPlayer) | ||
{ | ||
continue; | ||
} | ||
if(player.SubRootId.Equals(sendingPlayer.SubRootId)) | ||
{ | ||
player.SendPacket(footstepPacket); | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to use
this
ifPlayerID
andplayerID
are not the same word