Skip to content

Commit

Permalink
Fix audio position on first tick (space-wizards#4533)
Browse files Browse the repository at this point in the history
  • Loading branch information
metalgearsloth authored Oct 29, 2023
1 parent 9b04270 commit 8dc2345
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Robust.Client/Audio/AudioSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,6 @@ private void OnAudioStartup(EntityUid uid, AudioComponent component, ComponentSt
// Don't play until first frame so occlusion etc. are correct.
component.Gain = 0f;

if (!MetaData(uid).EntityPaused)
{
component.StartPlaying();
}

// If audio came into range then start playback at the correct position.
var offset = (Timing.CurTime - component.AudioStart).TotalSeconds % GetAudioLength(component.FileName).TotalSeconds;

Expand Down Expand Up @@ -227,6 +222,11 @@ private void ProcessStream(EntityUid entity, AudioComponent component, Transform
// TODO:
// I Originally tried to be fancier here but it caused audio issues so just trying
// to replicate the old behaviour for now.
if (!component.Started)
{
component.Started = true;
component.StartPlaying();
}

// If it's global but on another map (that isn't nullspace) then stop playing it.
if (component.Global)
Expand Down
4 changes: 4 additions & 0 deletions Robust.Shared/Audio/Components/AudioComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public sealed partial class AudioComponent : Component, IAudioSource

#endregion

// We can't just start playing on audio creation as we don't have the correct position yet.
// As such we'll wait for FrameUpdate before we start playing to avoid the position being cooked.
public bool Started = false;

[AutoNetworkedField]
[DataField(required: true)]
public string FileName = string.Empty;
Expand Down

0 comments on commit 8dc2345

Please sign in to comment.