Per-map parallax support (#9786)

* Per-map parallax support

* Comments for future sloth

* c

* bet

* Fix exception

* VV support

* Fix parallax

* mem

* weightless sounds

* Gravity stuff

* placeholder coz im too lazy to stash don't @ me son

* decent clouds

* sky

* Fast parallax

* Imagine spelling

* Loicense

* perish

* Fix weightless status

Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2022-07-25 15:10:23 +10:00
committed by GitHub
parent aad6a22a6a
commit bfac53e7bc
36 changed files with 607 additions and 412 deletions

View File

@@ -10,6 +10,7 @@ using Content.Shared.MobState.EntitySystems;
using Content.Shared.Movement.Components;
using Content.Shared.Movement.Events;
using Content.Shared.Pulling.Components;
using Content.Shared.Sound;
using Content.Shared.Tag;
using Robust.Shared.Audio;
using Robust.Shared.Configuration;
@@ -61,6 +62,7 @@ namespace Content.Shared.Movement.Systems
public override void Initialize()
{
base.Initialize();
InitializeFootsteps();
InitializeInput();
InitializeMob();
InitializePushing();
@@ -215,12 +217,13 @@ namespace Content.Shared.Movement.Systems
: worldTotal.ToWorldAngle();
rotateXform.DeferUpdates = false;
if (!weightless && TryComp<MobMoverComponent>(mover.Owner, out var mobMover) && TryGetSound(mover, mobMover, xform, out var variation, out var sound))
if (!weightless && TryComp<MobMoverComponent>(mover.Owner, out var mobMover) &&
TryGetSound(weightless, mover, mobMover, xform, out var sound))
{
var soundModifier = mover.Sprinting ? 1.0f : FootstepWalkingAddedVolumeMultiplier;
SoundSystem.Play(sound,
SoundSystem.Play(sound.GetSound(),
GetSoundPlayers(mover.Owner),
mover.Owner, AudioHelpers.WithVariation(variation).WithVolume(FootstepVolume * soundModifier));
mover.Owner, sound.Params.WithVolume(FootstepVolume * soundModifier));
}
}
@@ -313,19 +316,17 @@ namespace Content.Shared.Movement.Systems
protected abstract bool CanSound();
private bool TryGetSound(InputMoverComponent mover, MobMoverComponent mobMover, TransformComponent xform, out float variation, [NotNullWhen(true)] out string? sound)
private bool TryGetSound(bool weightless, InputMoverComponent mover, MobMoverComponent mobMover, TransformComponent xform, [NotNullWhen(true)] out SoundSpecifier? sound)
{
sound = null;
variation = 0f;
if (!CanSound() || !_tags.HasTag(mover.Owner, "FootstepSound")) return false;
var coordinates = xform.Coordinates;
var gridId = coordinates.GetGridUid(EntityManager);
var distanceNeeded = mover.Sprinting ? StepSoundMoveDistanceRunning : StepSoundMoveDistanceWalking;
// Handle footsteps.
if (_mapManager.GridExists(gridId))
if (!weightless)
{
// Can happen when teleporting between grids.
if (!coordinates.TryDistance(EntityManager, mobMover.LastPosition, out var distance) ||
@@ -344,7 +345,6 @@ namespace Content.Shared.Movement.Systems
return false;
}
DebugTools.Assert(gridId != null);
mobMover.LastPosition = coordinates;
if (mobMover.StepSoundDistance < distanceNeeded) return false;
@@ -354,19 +354,31 @@ namespace Content.Shared.Movement.Systems
if (_inventory.TryGetSlotEntity(mover.Owner, "shoes", out var shoes) &&
EntityManager.TryGetComponent<FootstepModifierComponent>(shoes, out var modifier))
{
sound = modifier.SoundCollection.GetSound();
variation = modifier.Variation;
sound = modifier.Sound;
return true;
}
return TryGetFootstepSound(gridId!.Value, coordinates, out variation, out sound);
return TryGetFootstepSound(coordinates, out sound);
}
private bool TryGetFootstepSound(EntityUid gridId, EntityCoordinates coordinates, out float variation, [NotNullWhen(true)] out string? sound)
private bool TryGetFootstepSound(EntityCoordinates coordinates, [NotNullWhen(true)] out SoundSpecifier? sound)
{
variation = 0f;
sound = null;
var grid = _mapManager.GetGrid(gridId);
var gridUid = coordinates.GetGridUid(EntityManager);
// Fallback to the map
if (gridUid == null)
{
if (TryComp<FootstepModifierComponent>(coordinates.GetMapUid(EntityManager), out var modifier))
{
sound = modifier.Sound;
return true;
}
return false;
}
var grid = _mapManager.GetGrid(gridUid.Value);
var tile = grid.GetTileRef(coordinates);
if (tile.IsSpace(_tileDefinitionManager)) return false;
@@ -377,18 +389,15 @@ namespace Content.Shared.Movement.Systems
{
if (EntityManager.TryGetComponent(maybeFootstep, out FootstepModifierComponent? footstep))
{
sound = footstep.SoundCollection.GetSound();
variation = footstep.Variation;
sound = footstep.Sound;
return true;
}
}
// Walking on a tile.
var def = (ContentTileDefinition) _tileDefinitionManager[tile.Tile.TypeId];
sound = def.FootstepSounds?.GetSound();
variation = FootstepVariation;
return !string.IsNullOrEmpty(sound);
sound = def.FootstepSounds;
return sound != null;
}
}
}