Skip to content
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
wants to merge 31 commits into
base: master
Choose a base branch
from

Conversation

OhmV-IR
Copy link
Contributor

@OhmV-IR OhmV-IR commented Sep 7, 2024

Fixes issue #2164
Does what the title says

  • Footstep audio radius is currently set to 20m feel free to change it depending on your preference
  • Footstep max audio multiplier is 0.5f, once again feel free to change it depending on your preference
  • Server checks for same structure and will not send footstep packets to players who are outside of the sending player's structure
  • Footstep sound volume scales with distance
  • Uses reflection to create and send footstep packet when local game plays footstep sound

@Measurity Measurity linked an issue Sep 10, 2024 that may be closed by this pull request
@Measurity Measurity added this to the 1.8 milestone Sep 10, 2024
@OhmV-IR
Copy link
Contributor Author

OhmV-IR commented Sep 21, 2024

Did another test with the help of kookoo, CSV sound range works, tested everything else and it was still fine so review away

NitroxModel/Packets/FootstepPacket.cs Outdated Show resolved Hide resolved
if (player.SubRootId.HasValue)
{
// If both players have id's, check if they are the same
if (NitroxVector3.Distance(player.Position, sendingPlayer.Position) <= footstepAudioRange && player != sendingPlayer && player.SubRootId.Value == sendingPlayer.SubRootId.Value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long imo

Still not fixed or commented why keeping that way.

These two ifs could be merged

think I did that

With merging I mean that two nested ifs with no else can be merged into one statement, meaning you chain both conditions together with an &&

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think I got this done actually this time but will keep conversation open until you mark it as resolved

// if both player's don't have SubRootIds
if (!player.SubRootId.HasValue)
{
if (NitroxVector3.Distance(player.Position, sendingPlayer.Position) <= footstepAudioRange && player != sendingPlayer)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first if in this brnaching tree should be the most common. In this case the NitroxVector3.Distance [...] && player != sendingPlayer bc it's in both branches

Done

Not done.

Also if you apply this I would recommend inverting the if so you have an early return for better clarity. Visit this for more information

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I got this now, but I'll leave this open until you resolve it

player.SendPacket(footstepPacket);
}
}
// If one player doesn't have an id and other does, automatically false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are many comments. Just keep in mind that comments should explain the important external things needed to understand the code (line), not explain the code itself. For example: No need to write that "both ids should be the same" if the if-statement below does exactly that check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the comments, don't think there is enough of a reason to have them. Leaving this open in case you think otherwise

@OhmV-IR
Copy link
Contributor Author

OhmV-IR commented Sep 24, 2024

Will do another test after approving reviews, so don't merge until that happens(will post here again when it does)

@OhmV-IR
Copy link
Contributor Author

OhmV-IR commented Sep 28, 2024

I have tested the PR as of commit 7e56f40, so if code reviews are approving, then this is ready to merge imo

Copy link
Collaborator

@tornac1234 tornac1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to update FootstepSounds_OnStep_PatchTest (change the number of instructions added by the transpiler). Also please use "Remove and Sort usings" before committing changes to a file.
It works fine IG but for some reason, the local player also sends packet for exosuits even if they're not walking those.
Can we have some sort of check that the FootstepSounds is for sure emitted by the local player or by an exosuit controlled by the local player ?

PRECURSOR_STEP_SOUND,
METAL_STEP_SOUND,
LAND_STEP_SOUND
}
Copy link
Collaborator

Choose a reason for hiding this comment

The 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


public FootstepPacket(ushort playerID, StepSounds assetIndex)
{
this.PlayerID = playerID;
Copy link
Collaborator

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 if PlayerID and playerID are not the same word

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Footsteps sounds not synced
4 participants