Footstep sounds. (#182)

This commit is contained in:
Pieter-Jan Briers
2019-04-05 02:04:34 +02:00
committed by GitHub
parent 85241a7dce
commit f5bb790edb
28 changed files with 171 additions and 2 deletions

View File

@@ -66,6 +66,7 @@
<Compile Include="Administration\AGhost.cs" />
<Compile Include="AI\AimShootLifeProcessor.cs" />
<Compile Include="EntryPoint.cs" />
<Compile Include="GameObjects\Components\CatwalkComponent.cs" />
<Compile Include="GameObjects\Components\Damage\DamageThreshold.cs" />
<Compile Include="GameObjects\Components\Doors\ServerDoorComponent.cs" />
<Compile Include="GameObjects\Components\Interactable\HandheldLightComponent.cs" />

View File

@@ -150,6 +150,8 @@ namespace Content.Server
factory.Register<AiControllerComponent>();
factory.Register<CatwalkComponent>();
IoCManager.Register<ISharedNotifyManager, ServerNotifyManager>();
IoCManager.Register<IServerNotifyManager, ServerNotifyManager>();
IoCManager.Register<IGameTicker, GameTicker>();

View File

@@ -0,0 +1,12 @@
using SS14.Shared.GameObjects;
namespace Content.Server.GameObjects.Components
{
/// <summary>
/// Literally just a marker component for footsteps for now.
/// </summary>
public sealed class CatwalkComponent : Component
{
public override string Name => "Catwalk";
}
}

View File

@@ -2,6 +2,7 @@
using SS14.Server.GameObjects;
using SS14.Shared.GameObjects;
using SS14.Shared.Log;
using SS14.Shared.Map;
using SS14.Shared.Maths;
using SS14.Shared.Serialization;
using SS14.Shared.ViewVariables;
@@ -45,6 +46,10 @@ namespace Content.Server.GameObjects.Components.Movement
[ViewVariables]
public Vector2 VelocityDir { get; private set; }
public GridCoordinates LastPosition { get; set; }
public float StepSoundDistance { get; set; }
/// <inheritdoc />
public override void OnAdd()
{

View File

@@ -1,17 +1,25 @@
using Content.Server.GameObjects.Components.Movement;
using System;
using Content.Server.GameObjects.Components;
using Content.Server.GameObjects.Components.Movement;
using Content.Server.Interfaces.GameObjects.Components.Movement;
using Content.Shared.Audio;
using Content.Shared.Maps;
using JetBrains.Annotations;
using SS14.Server.GameObjects;
using SS14.Server.GameObjects.EntitySystems;
using SS14.Server.Interfaces.Player;
using SS14.Server.Interfaces.Timing;
using SS14.Shared.Audio;
using SS14.Shared.GameObjects;
using SS14.Shared.GameObjects.Components.Transform;
using SS14.Shared.GameObjects.Systems;
using SS14.Shared.Input;
using SS14.Shared.Interfaces.GameObjects.Components;
using SS14.Shared.IoC;
using SS14.Shared.Map;
using SS14.Shared.Maths;
using SS14.Shared.Players;
using SS14.Shared.Prototypes;
namespace Content.Server.GameObjects.EntitySystems
{
@@ -21,8 +29,16 @@ namespace Content.Server.GameObjects.EntitySystems
#pragma warning disable 649
[Dependency]
private IPauseManager _pauseManager;
[Dependency]
private IPrototypeManager _prototypeManager;
#pragma warning restore 649
private AudioSystem _audioSystem;
private Random _footstepRandom;
private const float StepSoundMoveDistanceRunning = 2;
private const float StepSoundMoveDistanceWalking = 1.5f;
/// <inheritdoc />
public override void Initialize()
{
@@ -56,6 +72,9 @@ namespace Content.Server.GameObjects.EntitySystems
SubscribeEvent<PlayerAttachSystemMessage>(PlayerAttached);
SubscribeEvent<PlayerDetachedSystemMessage>(PlayerDetached);
_footstepRandom = new Random();
_audioSystem = EntitySystemManager.GetEntitySystem<AudioSystem>();
}
private static void PlayerAttached(object sender, PlayerAttachSystemMessage ev)
@@ -103,7 +122,7 @@ namespace Content.Server.GameObjects.EntitySystems
}
}
private static void UpdateKinematics(ITransformComponent transform, PlayerInputMoverComponent mover, PhysicsComponent physics)
private void UpdateKinematics(ITransformComponent transform, PlayerInputMoverComponent mover, PhysicsComponent physics)
{
if (mover.VelocityDir.LengthSquared < 0.001 || !ActionBlockerSystem.CanMove(mover.Owner))
{
@@ -114,6 +133,25 @@ namespace Content.Server.GameObjects.EntitySystems
{
physics.LinearVelocity = mover.VelocityDir * (mover.Sprinting ? mover.SprintMoveSpeed : mover.WalkMoveSpeed);
transform.LocalRotation = mover.VelocityDir.GetDir().ToAngle();
// Handle footsteps.
var distance = transform.GridPosition.Distance(mover.LastPosition);
mover.StepSoundDistance += distance;
mover.LastPosition = transform.GridPosition;
float distanceNeeded;
if (mover.Sprinting)
{
distanceNeeded = StepSoundMoveDistanceRunning;
}
else
{
distanceNeeded = StepSoundMoveDistanceWalking;
}
if (mover.StepSoundDistance > distanceNeeded)
{
mover.StepSoundDistance = 0;
PlayFootstepSound(transform.GridPosition);
}
}
}
@@ -149,5 +187,46 @@ namespace Content.Server.GameObjects.EntitySystems
component = comp;
return true;
}
private void PlayFootstepSound(GridCoordinates coordinates)
{
// Step one: figure out sound collection prototype.
var grid = coordinates.Grid;
var tile = grid.GetTile(coordinates);
// If the coordinates have a catwalk, it's always catwalk.
string soundCollectionName;
var catwalk = false;
foreach (var maybeCatwalk in grid.GetSnapGridCell(tile.GridTile, SnapGridOffset.Center))
{
if (maybeCatwalk.Owner.HasComponent<CatwalkComponent>())
{
catwalk = true;
break;
}
}
if (catwalk)
{
// Catwalk overrides tile sound.s
soundCollectionName = "footstep_catwalk";
}
else
{
// Walking on a tile.
var def = (ContentTileDefinition)tile.TileDef;
if (def.FootstepSounds == null)
{
// Nothing to play, oh well.
return;
}
soundCollectionName = def.FootstepSounds;
}
// Ok well we know the position of the
var soundCollection = _prototypeManager.Index<SoundCollectionPrototype>(soundCollectionName);
var file = _footstepRandom.Pick(soundCollection.PickFiles);
_audioSystem.Play(file, coordinates);
}
}
}

View File

@@ -0,0 +1,28 @@
using System.Collections.Generic;
using SS14.Shared.Prototypes;
using SS14.Shared.Utility;
using YamlDotNet.RepresentationModel;
namespace Content.Shared.Audio
{
[Prototype("sound_collection")]
public sealed class SoundCollectionPrototype : IPrototype, IIndexedPrototype
{
public string ID { get; private set; }
public IReadOnlyList<string> PickFiles { get; private set; }
public void LoadFrom(YamlMappingNode mapping)
{
ID = mapping.GetNode("id").AsString();
var pickFiles = new List<string>();
foreach (var file in mapping.GetNode<YamlSequenceNode>("files"))
{
pickFiles.Add(file.AsString());
}
PickFiles = pickFiles;
}
}
}

View File

@@ -62,6 +62,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Audio\SoundCollectionPrototype.cs" />
<Compile Include="EntryPoint.cs" />
<Compile Include="GameObjects\Components\Damage\DamageableComponent.cs" />
<Compile Include="GameObjects\Components\Doors\SharedDoorComponent.cs" />

View File

@@ -18,6 +18,7 @@ namespace Content.Shared.Maps
public string SpriteName { get; private set; }
public bool IsSubFloor { get; private set; }
public bool CanCrowbar { get; private set; }
public string FootstepSounds { get; private set; }
public void AssignTileId(ushort id)
{
@@ -39,6 +40,11 @@ namespace Content.Shared.Maps
{
CanCrowbar = node.AsBool();
}
if (mapping.TryGetNode("footstep_sounds", out node))
{
FootstepSounds = node.AsString();
}
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1 @@
Sounds in this folder taken from here: https://github.com/discordia-space/CEV-Eris/tree/04f9e57ecf8a1c89ae2cba0f6803b6c5e9887c15/sound/effects/footstep

View File

@@ -18,3 +18,5 @@
- type: IconSmooth
key: catwalk
base: catwalk_
- type: Catwalk

View File

@@ -0,0 +1,27 @@
- type: sound_collection
id: footstep_catwalk
files:
- /Audio/effects/footsteps/catwalk1.ogg
- /Audio/effects/footsteps/catwalk2.ogg
- /Audio/effects/footsteps/catwalk3.ogg
- /Audio/effects/footsteps/catwalk4.ogg
- /Audio/effects/footsteps/catwalk5.ogg
- type: sound_collection
id: footstep_floor
files:
- /Audio/effects/footsteps/floor1.ogg
- /Audio/effects/footsteps/floor2.ogg
- /Audio/effects/footsteps/floor3.ogg
- /Audio/effects/footsteps/floor4.ogg
- /Audio/effects/footsteps/floor5.ogg
- type: sound_collection
id: footstep_plating
files:
- /Audio/effects/footsteps/plating1.ogg
- /Audio/effects/footsteps/plating2.ogg
- /Audio/effects/footsteps/plating3.ogg
- /Audio/effects/footsteps/plating4.ogg
- /Audio/effects/footsteps/plating5.ogg

View File

@@ -4,6 +4,7 @@
texture: "floor_steel"
is_subfloor: false
can_crowbar: true
footstep_sounds: footstep_floor
- type: tile
name: floor_white
@@ -11,6 +12,7 @@
texture: "floor_white"
is_subfloor: false
can_crowbar: true
footstep_sounds: footstep_floor
- type: tile
name: floor_techmaint
@@ -18,3 +20,4 @@
texture: "floor_techmaint"
is_subfloor: false
can_crowbar: true
footstep_sounds: footstep_floor

View File

@@ -3,9 +3,11 @@
display_name: Plating
texture: plating
is_subfloor: true
footstep_sounds: footstep_plating
- type: tile
name: underplating
display_name: Underplating
texture: underplating
is_subfloor: true
footstep_sounds: footstep_plating