Splits the singularity into its component parts + ECS singularity + Support for singularities in containers. (#12132)

* InitialCommit (Broken)

* Fixes compile errors

* PR comments. More doc comments. Fixes

* Makes a singularity/event horizon without radiation/physics a valid state to be in

* VV 'fake' setters, fixes the visualizer, fixes the singularity trying to eat itself instead of nearby things.

* Removes unused dependency from Content.Client.GravityWellSystem

* Testing containment and fake VV setters for SingularityGeneratorComponent

* Fixes gravity wells (broken due to LookupFlags.None). Adds recursive Event Horizon consumption

* Fix merge skew

* Fixes for the master merge

* Fix engine commit

* Dirty is obsolete

* Switch over dirty

* Fix requested changes

* ambiant -> ambient

* Moves EventHorionComponent to Shared

* Proper container handling

* Fixes master merge. Fixes post insertion assertions for singularities. Extends proper container handling to gravity wells and the distortion shader.

* Better support for admemes throwing singularities.

* Moves update timing from accumulators to target times

* Update doc comments
This commit is contained in:
TemporalOroboros
2022-12-19 18:47:15 -08:00
committed by GitHub
parent 490aefecef
commit 9a72b05a50
35 changed files with 2561 additions and 683 deletions

View File

@@ -0,0 +1,71 @@
using Content.Shared.Singularity.Components;
using Content.Server.Singularity.EntitySystems;
namespace Content.Server.Singularity.Components;
/// <summary>
/// The server-side version of <see cref="SharedGravityWellComponent"/>.
/// Primarily managed by <see cref="GravityWellSystem"/>.
/// </summary>
[RegisterComponent]
public sealed class GravityWellComponent : Component
{
/// <summary>
/// The maximum range at which the gravity well can push/pull entities.
/// </summary>
[DataField("maxRange")]
[ViewVariables(VVAccess.ReadWrite)]
public float MaxRange;
/// <summary>
/// The minimum range at which the gravity well can push/pull entities.
/// This is effectively hardfloored at <see cref="GravityWellSystem.MinGravPulseRange"/>.
/// </summary>
[DataField("minRange")]
[ViewVariables(VVAccess.ReadWrite)]
public float MinRange = 0f;
/// <summary>
/// The acceleration entities will experience towards the gravity well at a distance of 1m.
/// Negative values accelerate entities away from the gravity well.
/// Actual acceleration scales with the inverse of the distance to the singularity.
/// </summary>
[DataField("baseRadialAcceleration")]
[ViewVariables(VVAccess.ReadWrite)]
public float BaseRadialAcceleration = 0.0f;
/// <summary>
/// The acceleration entities will experience tangent to the gravity well at a distance of 1m.
/// Positive tangential acceleration is counter-clockwise.
/// Actual acceleration scales with the inverse of the distance to the singularity.
/// </summary>
[DataField("baseTangentialAcceleration")]
[ViewVariables(VVAccess.ReadWrite)]
public float BaseTangentialAcceleration = 0.0f;
#region Update Timing
/// <summary>
/// The amount of time that should elapse between automated updates to this gravity well.
/// </summary>
[DataField("gravPulsePeriod")]
[ViewVariables(VVAccess.ReadOnly)]
[Access(typeof(GravityWellSystem))]
public TimeSpan TargetPulsePeriod { get; internal set; } = TimeSpan.FromSeconds(0.5);
/// <summary>
/// The next time at which this gravity well should pulse.
/// </summary>
[ViewVariables(VVAccess.ReadOnly)]
[Access(typeof(GravityWellSystem))]
public TimeSpan NextPulseTime { get; internal set; } = default!;
/// <summary>
/// The last time this gravity well pulsed.
/// </summary>
[ViewVariables(VVAccess.ReadOnly)]
[Access(typeof(GravityWellSystem))]
public TimeSpan LastPulseTime { get; internal set; } = default!;
#endregion Update Timing
}

View File

@@ -1,96 +0,0 @@
using Content.Shared.Singularity;
using Content.Shared.Singularity.Components;
using Robust.Shared.Audio;
using Robust.Shared.Player;
namespace Content.Server.Singularity.Components
{
[RegisterComponent]
[ComponentReference(typeof(SharedSingularityComponent))]
public sealed class ServerSingularityComponent : SharedSingularityComponent
{
[Dependency] private readonly IEntityManager _entMan = default!;
private SharedSingularitySystem _singularitySystem = default!;
[ViewVariables(VVAccess.ReadWrite)]
public int Energy
{
get => _energy;
set
{
if (value == _energy) return;
_energy = value;
if (_energy <= 0)
{
_entMan.DeleteEntity(Owner);
return;
}
var level = _energy switch
{
>= 1500 => 6,
>= 1000 => 5,
>= 600 => 4,
>= 300 => 3,
>= 200 => 2,
< 200 => 1
};
_singularitySystem.ChangeSingularityLevel(this, level);
}
}
private int _energy = 180;
[ViewVariables]
public int EnergyDrain =>
Level switch
{
6 => 20,
5 => 15,
4 => 10,
3 => 5,
2 => 2,
1 => 1,
_ => 0
};
[DataField("moveAccumulator")]
public float MoveAccumulator;
// This is an interesting little workaround.
// See, two singularities queuing deletion of each other at the same time will annihilate.
// This is undesirable behaviour, so this flag allows the imperatively first one processed to take priority.
[ViewVariables(VVAccess.ReadWrite)]
public bool BeingDeletedByAnotherSingularity { get; set; }
[DataField("singularityFormingSound")] private SoundSpecifier _singularityFormingSound = new SoundPathSpecifier("/Audio/Effects/singularity_form.ogg");
[DataField("singularityCollapsingSound")] private SoundSpecifier _singularityCollapsingSound = new SoundPathSpecifier("/Audio/Effects/singularity_collapse.ogg");
public override ComponentState GetComponentState()
{
return new SingularityComponentState(Level);
}
protected override void Initialize()
{
base.Initialize();
_singularitySystem = EntitySystem.Get<SharedSingularitySystem>();
var audioParams = AudioParams.Default;
audioParams.Loop = true;
audioParams.MaxDistance = 20f;
audioParams.Volume = 5;
SoundSystem.Play(_singularityFormingSound.GetSound(), Filter.Pvs(Owner), Owner);
_singularitySystem.ChangeSingularityLevel(this, 1);
}
protected override void Shutdown()
{
base.Shutdown();
SoundSystem.Play(_singularityCollapsingSound.GetSound(), Filter.Pvs(Owner), _entMan.GetComponent<TransformComponent>(Owner).Coordinates);
}
}
}

View File

@@ -0,0 +1,92 @@
using Content.Shared.Singularity.Components;
using Content.Server.Singularity.EntitySystems;
using Robust.Shared.Audio;
namespace Content.Server.Singularity.Components;
/// <summary>
/// The server-side version of <see cref="SharedSingularityComponent">.
/// Primarily managed by <see cref="SingularitySystem">.
/// </summary>
[RegisterComponent]
[ComponentReference(typeof(SharedSingularityComponent))]
public sealed class SingularityComponent : SharedSingularityComponent
{
/// <summary>
/// The amount of energy this singularity contains.
/// If you want to set this go through <see cref="SingularitySystem.SetEnergy"/>
/// </summary>
[DataField("energy")]
[Access(friends:typeof(SingularitySystem))]
public float Energy = 180f;
/// <summary>
/// The rate at which this singularity loses energy over time.
/// </summary>
[DataField("energyLoss")]
[ViewVariables(VVAccess.ReadWrite)]
public float EnergyDrain;
#region Audio
/// <summary>
/// The sound that this singularity produces by existing.
/// </summary>
[DataField("ambientSound")]
[ViewVariables(VVAccess.ReadOnly)]
public SoundSpecifier? AmbientSound = new SoundPathSpecifier(
"/Audio/Effects/singularity_form.ogg",
AudioParams.Default.WithVolume(5).WithLoop(true).WithMaxDistance(20f)
);
/// <summary>
/// The audio stream that plays the sound specified by <see cref="AmbientSound"> on loop.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public IPlayingAudioStream? AmbientSoundStream = null;
/// <summary>
/// The sound that the singularity produces when it forms.
/// </summary>
[DataField("formationSound")]
[ViewVariables(VVAccess.ReadOnly)]
public SoundSpecifier? FormationSound = null;
/// <summary>
/// The sound that the singularity produces when it dissipates.
/// </summary>
[DataField("dissipationSound")]
[ViewVariables(VVAccess.ReadWrite)]
public SoundSpecifier? DissipationSound = new SoundPathSpecifier(
"/Audio/Effects/singularity_collapse.ogg",
AudioParams.Default
);
#endregion Audio
#region Update Timing
/// <summary>
/// The amount of time that should elapse between automated updates to this singularity.
/// </summary>
[DataField("updatePeriod")]
[ViewVariables(VVAccess.ReadOnly)]
[Access(typeof(SingularitySystem))]
public TimeSpan TargetUpdatePeriod { get; internal set; } = TimeSpan.FromSeconds(1.0);
/// <summary>
/// The next time this singularity should be updated by <see cref="SingularitySystem"/>
/// </summary>
[ViewVariables(VVAccess.ReadOnly)]
[Access(typeof(SingularitySystem))]
public TimeSpan NextUpdateTime { get; internal set; } = default!;
/// <summary>
/// The last time this singularity was be updated by <see cref="SingularitySystem"/>
/// </summary>
[ViewVariables(VVAccess.ReadOnly)]
[Access(typeof(SingularitySystem))]
public TimeSpan LastUpdateTime { get; internal set; } = default!;
#endregion Update Timing
}

View File

@@ -1,26 +1,33 @@
namespace Content.Server.Singularity.Components
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Content.Server.Singularity.EntitySystems;
namespace Content.Server.Singularity.Components;
[RegisterComponent]
public sealed class SingularityGeneratorComponent : Component
{
[RegisterComponent]
public sealed class SingularityGeneratorComponent : Component
{
[Dependency] private readonly IEntityManager _entMan = default!;
/// <summary>
/// The amount of power this generator has accumulated.
/// If you want to set this use <see cref="SingularityGeneratorSystem.SetPower"/>
/// </summary>
[DataField("power")]
[Access(friends:typeof(SingularityGeneratorSystem))]
public float Power = 0;
[ViewVariables] private int _power;
/// <summary>
/// The power threshold at which this generator will spawn a singularity.
/// If you want to set this use <see cref="SingularityGeneratorSystem.SetThreshold"/>
/// </summary>
[DataField("threshold")]
[Access(friends:typeof(SingularityGeneratorSystem))]
public float Threshold = 16;
public int Power
{
get => _power;
set
{
if(_power == value) return;
_power = value;
if (_power > 15)
{
_entMan.SpawnEntity("Singularity", _entMan.GetComponent<TransformComponent>(Owner).Coordinates);
//dont delete ourselves, just wait to get eaten
}
}
}
}
/// <summary>
/// The prototype ID used to spawn a singularity.
/// </summary>
[DataField("spawnId", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
[ViewVariables(VVAccess.ReadWrite)]
public string? SpawnPrototype = "Singularity";
}

View File

@@ -8,6 +8,6 @@ namespace Content.Server.Singularity.Components
{
[ViewVariables(VVAccess.ReadWrite)]
[DataField("energy")]
public int Energy { get; set; } = 1;
public float Energy { get; set; } = 1f;
}
}