Files
Delta-v/Content.Shared/Gravity/SharedGravitySystem.Shake.cs
T
9146c59ecf feat: Fancy Screenshake from Ephemeral Space (#5503)
* cherry-pick: Screenshake (EphemeralSpace/ephemeral-space#627)

* commit your shit at some point maybe

* y

* who knows

* rename?

* debugging  + shit api

* i hope no one fucks my ass

* erm

* p

* replace with shit that makes way more sense

* stuff

* pretty sure this is just fine

* actual fix noise shit

* uhhh hmaybe if i feel like it wrong then later

* explosion shake

* grav shake

* gun shake

* idk

* projectile melee

Co-authored-by: DisposableCrewmember42 <disposablecrewmember42@proton.me>

* tweak: tune recoil on weapons

* docs: add _ES license info to LEGAL.md

* fix: screenshake on spawn fix from ss14Starlight/space-station-14#3664

Co-authored-by: neomoth <69372252+neomoth@users.noreply.github.com>

* feat: add client cvar to disable screenshake

* feat: add screenshake toggle to accessibility settings

* fix: upmerge compatibility

* docs: properly document cvar

* docs: add missing import comments

---------

Co-authored-by: mirrorcult <mirrorcult@pm.me>
Co-authored-by: neomoth <69372252+neomoth@users.noreply.github.com>
2026-05-15 23:32:40 +02:00

76 lines
2.4 KiB
C#

using Content.Shared._ES.Camera; // ES
using Content.Shared.GameTicking; // ES
using Robust.Shared.Player; // ES
using Robust.Shared.Timing; // ES
namespace Content.Shared.Gravity;
public abstract partial class SharedGravitySystem
{
// ES START
[Dependency] private readonly SharedGameTicker _ticker = default!;
[Dependency] private readonly SharedESScreenshakeSystem _shake = default!;
// ES END
protected const float GravityKick = 100.0f;
protected const float ShakeCooldown = 0.2f;
private void UpdateShake()
{
var curTime = Timing.CurTime;
var gravityQuery = GetEntityQuery<GravityComponent>();
var query = EntityQueryEnumerator<GravityShakeComponent>();
while (query.MoveNext(out var uid, out var comp))
{
if (comp.NextShake <= curTime)
{
if (comp.ShakeTimes == 0 || !gravityQuery.TryGetComponent(uid, out var gravity))
{
RemCompDeferred<GravityShakeComponent>(uid);
continue;
}
ShakeGrid(uid, gravity);
comp.ShakeTimes--;
comp.NextShake += TimeSpan.FromSeconds(ShakeCooldown);
Dirty(uid, comp);
}
}
}
public void StartGridShake(EntityUid uid, GravityComponent? gravity = null)
{
if (Terminating(uid))
return;
if (!Resolve(uid, ref gravity, false))
return;
// ES START
// do not shake grid if the round just started
// i did not want to have to think this logic through more. this is the simplest solution i could think of
if (Timing.CurTime - _ticker.RoundStartTimeSpan < TimeSpan.FromSeconds(30))
return;
// ES SCREENSHAKE LOGIC
// instead of poopass camera kick
var translation = new ESScreenshakeParameters() { Trauma = 0.8f, DecayRate = 0.04f, Frequency = 0.015f };
var filter = Filter.BroadcastGrid(uid);
_shake.Screenshake(filter, translation, null);
return;
// ES END
if (!TryComp<GravityShakeComponent>(uid, out var shake))
{
shake = AddComp<GravityShakeComponent>(uid);
shake.NextShake = Timing.CurTime;
}
shake.ShakeTimes = 10;
Dirty(uid, shake);
}
protected virtual void ShakeGrid(EntityUid uid, GravityComponent? comp = null) {}
}