Nerf emitsoundoncollide (#16602)

This commit is contained in:
metalgearsloth
2023-05-20 02:04:26 +10:00
committed by GitHub
parent 373435c006
commit d6adf9880d
4 changed files with 17 additions and 6 deletions

View File

@@ -24,6 +24,7 @@ public sealed class GravityWellSystem : SharedGravityWellSystem
[Dependency] private readonly IViewVariablesManager _vvManager = default!; [Dependency] private readonly IViewVariablesManager _vvManager = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!; [Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!; [Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
#endregion Dependencies #endregion Dependencies
/// <summary> /// <summary>
@@ -181,9 +182,12 @@ public sealed class GravityWellSystem : SharedGravityWellSystem
var epicenter = mapPos.Position; var epicenter = mapPos.Position;
var minRange2 = MathF.Max(minRange * minRange, MinGravPulseRange); // Cache square value for speed. Also apply a sane minimum value to the minimum value so that div/0s don't happen. var minRange2 = MathF.Max(minRange * minRange, MinGravPulseRange); // Cache square value for speed. Also apply a sane minimum value to the minimum value so that div/0s don't happen.
var bodyQuery = GetEntityQuery<PhysicsComponent>();
var xformQuery = GetEntityQuery<TransformComponent>();
foreach(var entity in _lookup.GetEntitiesInRange(mapPos.MapId, epicenter, maxRange, flags: LookupFlags.Dynamic | LookupFlags.Sundries)) foreach(var entity in _lookup.GetEntitiesInRange(mapPos.MapId, epicenter, maxRange, flags: LookupFlags.Dynamic | LookupFlags.Sundries))
{ {
if (!TryComp<PhysicsComponent>(entity, out var physics) if (!bodyQuery.TryGetComponent(entity, out var physics)
|| physics.BodyType == BodyType.Static) || physics.BodyType == BodyType.Static)
{ {
continue; continue;
@@ -192,7 +196,7 @@ public sealed class GravityWellSystem : SharedGravityWellSystem
if(!CanGravPulseAffect(entity)) if(!CanGravPulseAffect(entity))
continue; continue;
var displacement = epicenter - Transform(entity).WorldPosition; var displacement = epicenter - _transform.GetWorldPosition(entity, xformQuery);
var distance2 = displacement.LengthSquared; var distance2 = displacement.LengthSquared;
if (distance2 < minRange2) if (distance2 < minRange2)
continue; continue;

View File

@@ -12,7 +12,7 @@ public sealed class EmitSoundOnCollideComponent : BaseEmitSoundComponent
/// Minimum velocity required for the sound to play. /// Minimum velocity required for the sound to play.
/// </summary> /// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("minVelocity")] [ViewVariables(VVAccess.ReadWrite), DataField("minVelocity")]
public float MinimumVelocity = 1f; public float MinimumVelocity = 3f;
/// <summary> /// <summary>
/// To avoid sound spam add a cooldown to it. /// To avoid sound spam add a cooldown to it.

View File

@@ -6,6 +6,7 @@ using Content.Shared.Popups;
using Content.Shared.Sound.Components; using Content.Shared.Sound.Components;
using Content.Shared.Throwing; using Content.Shared.Throwing;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.Audio;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Network; using Robust.Shared.Network;
using Robust.Shared.Physics.Components; using Robust.Shared.Physics.Components;
@@ -133,7 +134,15 @@ public abstract class SharedEmitSoundSystem : EntitySystem
return; return;
} }
const float MaxVolumeVelocity = 10f;
const float MinVolume = -10f;
const float MaxVolume = 2f;
var fraction = MathF.Min(1f, (physics.LinearVelocity.Length - component.MinimumVelocity) / MaxVolumeVelocity);
var volume = MinVolume + (MaxVolume - MinVolume) * fraction;
component.NextSound = _timing.CurTime + EmitSoundOnCollideComponent.CollideCooldown; component.NextSound = _timing.CurTime + EmitSoundOnCollideComponent.CollideCooldown;
TryEmitSound(uid, component, predict: false);
if (_netMan.IsServer)
_audioSystem.PlayPvs(component.Sound, uid, AudioParams.Default.WithVolume(volume));
} }
} }

View File

@@ -11,8 +11,6 @@
- type: EmitSoundOnCollide - type: EmitSoundOnCollide
sound: sound:
path: /Audio/Effects/wall_bonk.ogg path: /Audio/Effects/wall_bonk.ogg
params:
volume: 2
- type: EmitSoundOnLand - type: EmitSoundOnLand
sound: sound:
path: /Audio/Effects/drop.ogg path: /Audio/Effects/drop.ogg