Skip to content

Commit

Permalink
Audio hater's PR (SerbiaStrong-220#2473)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alwayswannahunt authored Jan 11, 2025
1 parent 502f977 commit d00f9a0
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 4 deletions.
16 changes: 15 additions & 1 deletion Content.Server/Telephone/TelephoneSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
using Content.Shared.Silicons.StationAi;
using Content.Shared.Silicons.Borgs.Components;
using Content.Shared.SS220.TTS;
using Content.Shared.SS220.CCVars;
using Robust.Shared.Configuration;

namespace Content.Server.Telephone;

Expand All @@ -38,6 +40,11 @@ public sealed class TelephoneSystem : SharedTelephoneSystem
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly IReplayRecordingManager _replay = default!;

// SS220 performance-test-begin
[Dependency] private readonly IConfigurationManager _configManager = default!;
private bool _lessSound;
// SS220 performance-test-end

// Has set used to prevent telephone feedback loops
private HashSet<(EntityUid, string, Entity<TelephoneComponent>)> _recentChatMessages = new();

Expand All @@ -50,6 +57,8 @@ public override void Initialize()
SubscribeLocalEvent<TelephoneComponent, ListenAttemptEvent>(OnAttemptListen);
SubscribeLocalEvent<TelephoneComponent, ListenEvent>(OnListen);
SubscribeLocalEvent<TelephoneComponent, TelephoneMessageReceivedEvent>(OnTelephoneMessageReceived);

Subs.CVar(_configManager, CCVars220.LessSoundSources, value => _lessSound = value, true); // SS220 performance-test
}

#region: Events
Expand Down Expand Up @@ -151,6 +160,11 @@ public override void Update(float frameTime)
if (_timing.CurTime > telephone.StateStartTime + TimeSpan.FromSeconds(telephone.RingingTimeout))
EndTelephoneCalls(entity);

// SS220 performance-test
if (_lessSound)
break;
// SS220 performace-test

else if (telephone.RingTone != null &&
_timing.CurTime > telephone.NextRingToneTime)
{
Expand All @@ -160,7 +174,7 @@ public override void Update(float frameTime)

break;

// Try to hang up if their has been no recent in-call activity
// Try to hang up if their has been no recent in-call activity
case TelephoneState.InCall:
if (_timing.CurTime > telephone.StateStartTime + TimeSpan.FromSeconds(telephone.IdlingTimeout))
EndTelephoneCalls(entity);
Expand Down
14 changes: 14 additions & 0 deletions Content.Shared/Movement/Systems/MovementSoundSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Content.Shared.Movement.Components;
using Content.Shared.Movement.Events;
using Content.Shared.SS220.CCVars;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Configuration;
using Robust.Shared.Timing;
using Robust.Shared.Utility;

Expand All @@ -14,10 +16,17 @@ public sealed class MovementSoundSystem : EntitySystem
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;

// SS220 performance-test-begin
[Dependency] private readonly IConfigurationManager _configManager = default!;
private bool _lessSound;
// SS220 performance-test-end

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<MovementSoundComponent, MoveInputEvent>(OnMoveInput);

Subs.CVar(_configManager, CCVars220.LessSoundSources, value => _lessSound = value, true); // SS220 performance-test
}

private void OnMoveInput(Entity<MovementSoundComponent> ent, ref MoveInputEvent args)
Expand All @@ -31,6 +40,11 @@ private void OnMoveInput(Entity<MovementSoundComponent> ent, ref MoveInputEvent
if (oldMoving == moving)
return;

// SS220 performance-test
if (_lessSound)
return;
// SS220 performace-test

if (moving)
{
DebugTools.Assert(ent.Comp.SoundEntity == null);
Expand Down
6 changes: 5 additions & 1 deletion Content.Shared/Movement/Systems/SharedMoverController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Content.Shared.Mobs.Systems;
using Content.Shared.Movement.Components;
using Content.Shared.Movement.Events;
using Content.Shared.SS220.CCVars;
using Content.Shared.Tag;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
Expand Down Expand Up @@ -66,6 +67,7 @@ public abstract partial class SharedMoverController : VirtualController
private float _stopSpeed;

private bool _relativeMovement;
private bool _lessSound; // SS220 Performance-test

/// <summary>
/// Cache the mob movement calculation to re-use elsewhere.
Expand Down Expand Up @@ -93,6 +95,7 @@ public override void Initialize()
InitializeRelay();
Subs.CVar(_configManager, CCVars.RelativeMovement, value => _relativeMovement = value, true);
Subs.CVar(_configManager, CCVars.StopSpeed, value => _stopSpeed = value, true);
Subs.CVar(_configManager, CCVars220.LessSoundSources, value => _lessSound = value, true); // SS220 performance-test
UpdatesBefore.Add(typeof(TileFrictionController));
}

Expand Down Expand Up @@ -401,7 +404,8 @@ private bool TryGetSound(
{
sound = null;

if (!CanSound() || !_tags.HasTag(uid, "FootstepSound"))
// if (!CanSound() || !_tags.HasTag(uid, "FootstepSound") // SS220 performance test
if (!CanSound() || !_tags.HasTag(uid, "FootstepSound") || _lessSound) // SS220 performance test
return false;

var coordinates = xform.Coordinates;
Expand Down
12 changes: 12 additions & 0 deletions Content.Shared/SS220/CCVars/CCVars220.Performance.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Robust.Shared.Configuration;

namespace Content.Shared.SS220.CCVars;

public sealed partial class CCVars220
{
/// <summary>
/// Cvar which turns off most of player generatish sounds like steps, telephones and etc. Do not affect TTS.
/// </summary>
public static readonly CVarDef<bool> LessSoundSources =
CVarDef.Create("audio.less_sound_sources", false, CVar.SERVER | CVar.REPLICATED, "serve to turn off most of player generatish sounds like steps, telephones and etc. Do not affect TTS.");
}
2 changes: 1 addition & 1 deletion Content.Shared/SS220/CCVars/CCVars220.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Content.Shared.SS220.CCVars;

[CVarDefs]
public sealed class CCVars220
public sealed partial class CCVars220
{
/// <summary>
/// Whether is bloom lighting eanbled or not
Expand Down
12 changes: 11 additions & 1 deletion Content.Shared/Sound/SharedEmitSoundSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
using Content.Shared.Mobs;
using Content.Shared.Popups;
using Content.Shared.Sound.Components;
using Content.Shared.SS220.CCVars;
using Content.Shared.Throwing;
using Content.Shared.UserInterface;
using Content.Shared.Whitelist;
using JetBrains.Annotations;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Configuration;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Network;
Expand All @@ -39,6 +41,11 @@ public abstract class SharedEmitSoundSystem : EntitySystem
[Dependency] private readonly SharedMapSystem _map = default!;
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;

// SS220 performance-test-begin
[Dependency] private readonly IConfigurationManager _configManager = default!;
private bool _lessSound;
// SS220 performance-test-end

public override void Initialize()
{
base.Initialize();
Expand All @@ -55,6 +62,8 @@ public override void Initialize()
SubscribeLocalEvent<EmitSoundOnCollideComponent, StartCollideEvent>(OnEmitSoundOnCollide);

SubscribeLocalEvent<SoundWhileAliveComponent, MobStateChangedEvent>(OnMobState);

Subs.CVar(_configManager, CCVars220.LessSoundSources, value => _lessSound = value, true); // SS220 performance-test
}

private void HandleEmitSoundOnUIOpen(EntityUid uid, EmitSoundOnUIOpenComponent component, AfterActivatableUIOpenEvent args)
Expand Down Expand Up @@ -143,7 +152,8 @@ private void OnEmitSoundOnInteractUsing(Entity<EmitSoundOnInteractUsingComponent
}
protected void TryEmitSound(EntityUid uid, BaseEmitSoundComponent component, EntityUid? user=null, bool predict=true)
{
if (component.Sound == null)
// if (component.Sound == null) // SS220 performance-test
if (component.Sound == null || _lessSound) // SS220 performance-test
return;

if (component.Positional)
Expand Down

0 comments on commit d00f9a0

Please sign in to comment.