Event horizon serialization (#18173)
This commit is contained in:
@@ -40,6 +40,8 @@ public sealed class EventHorizonSystem : SharedEventHorizonSystem
|
|||||||
SubscribeLocalEvent<MapGridComponent, EventHorizonAttemptConsumeEntityEvent>(PreventConsume);
|
SubscribeLocalEvent<MapGridComponent, EventHorizonAttemptConsumeEntityEvent>(PreventConsume);
|
||||||
SubscribeLocalEvent<GhostComponent, EventHorizonAttemptConsumeEntityEvent>(PreventConsume);
|
SubscribeLocalEvent<GhostComponent, EventHorizonAttemptConsumeEntityEvent>(PreventConsume);
|
||||||
SubscribeLocalEvent<StationDataComponent, EventHorizonAttemptConsumeEntityEvent>(PreventConsume);
|
SubscribeLocalEvent<StationDataComponent, EventHorizonAttemptConsumeEntityEvent>(PreventConsume);
|
||||||
|
SubscribeLocalEvent<EventHorizonComponent, MapInitEvent>(OnHorizonMapInit);
|
||||||
|
SubscribeLocalEvent<EventHorizonComponent, EntityUnpausedEvent>(OnHorizonUnpaused);
|
||||||
SubscribeLocalEvent<EventHorizonComponent, StartCollideEvent>(OnStartCollide);
|
SubscribeLocalEvent<EventHorizonComponent, StartCollideEvent>(OnStartCollide);
|
||||||
SubscribeLocalEvent<EventHorizonComponent, EntGotInsertedIntoContainerMessage>(OnEventHorizonContained);
|
SubscribeLocalEvent<EventHorizonComponent, EntGotInsertedIntoContainerMessage>(OnEventHorizonContained);
|
||||||
SubscribeLocalEvent<EventHorizonContainedEvent>(OnEventHorizonContained);
|
SubscribeLocalEvent<EventHorizonContainedEvent>(OnEventHorizonContained);
|
||||||
@@ -51,6 +53,16 @@ public sealed class EventHorizonSystem : SharedEventHorizonSystem
|
|||||||
vvHandle.AddPath(nameof(EventHorizonComponent.TargetConsumePeriod), (_, comp) => comp.TargetConsumePeriod, SetConsumePeriod);
|
vvHandle.AddPath(nameof(EventHorizonComponent.TargetConsumePeriod), (_, comp) => comp.TargetConsumePeriod, SetConsumePeriod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnHorizonMapInit(EntityUid uid, EventHorizonComponent component, MapInitEvent args)
|
||||||
|
{
|
||||||
|
component.NextConsumeWaveTime = _timing.CurTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnHorizonUnpaused(EntityUid uid, EventHorizonComponent component, ref EntityUnpausedEvent args)
|
||||||
|
{
|
||||||
|
component.NextConsumeWaveTime += args.PausedTime;
|
||||||
|
}
|
||||||
|
|
||||||
public override void Shutdown()
|
public override void Shutdown()
|
||||||
{
|
{
|
||||||
var vvHandle = Vvm.GetTypeHandler<EventHorizonComponent>();
|
var vvHandle = Vvm.GetTypeHandler<EventHorizonComponent>();
|
||||||
@@ -82,10 +94,10 @@ public sealed class EventHorizonSystem : SharedEventHorizonSystem
|
|||||||
if (!Resolve(uid, ref eventHorizon))
|
if (!Resolve(uid, ref eventHorizon))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
eventHorizon.LastConsumeWaveTime = _timing.CurTime;
|
eventHorizon.NextConsumeWaveTime += eventHorizon.TargetConsumePeriod;
|
||||||
eventHorizon.NextConsumeWaveTime = eventHorizon.LastConsumeWaveTime + eventHorizon.TargetConsumePeriod;
|
|
||||||
if (eventHorizon.BeingConsumedByAnotherEventHorizon)
|
if (eventHorizon.BeingConsumedByAnotherEventHorizon)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!Resolve(uid, ref xform))
|
if (!Resolve(uid, ref xform))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -331,8 +343,9 @@ public sealed class EventHorizonSystem : SharedEventHorizonSystem
|
|||||||
if (MathHelper.CloseTo(eventHorizon.TargetConsumePeriod.TotalSeconds, value.TotalSeconds))
|
if (MathHelper.CloseTo(eventHorizon.TargetConsumePeriod.TotalSeconds, value.TotalSeconds))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
var diff = (value - eventHorizon.TargetConsumePeriod);
|
||||||
eventHorizon.TargetConsumePeriod = value;
|
eventHorizon.TargetConsumePeriod = value;
|
||||||
eventHorizon.NextConsumeWaveTime = eventHorizon.LastConsumeWaveTime + eventHorizon.TargetConsumePeriod;
|
eventHorizon.NextConsumeWaveTime += diff;
|
||||||
|
|
||||||
var curTime = _timing.CurTime;
|
var curTime = _timing.CurTime;
|
||||||
if (eventHorizon.NextConsumeWaveTime < curTime)
|
if (eventHorizon.NextConsumeWaveTime < curTime)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
using Content.Shared.Singularity.EntitySystems;
|
using Content.Shared.Singularity.EntitySystems;
|
||||||
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||||
|
|
||||||
namespace Content.Shared.Singularity.Components;
|
namespace Content.Shared.Singularity.Components;
|
||||||
|
|
||||||
@@ -59,19 +60,13 @@ public sealed class EventHorizonComponent : Component
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("consumePeriod")]
|
[DataField("consumePeriod")]
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
public TimeSpan TargetConsumePeriod { get; set; } = TimeSpan.FromSeconds(0.5);
|
public TimeSpan TargetConsumePeriod = TimeSpan.FromSeconds(0.5);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The last time at which this consumed everything it overlapped with.
|
|
||||||
/// </summary>
|
|
||||||
[ViewVariables(VVAccess.ReadOnly)]
|
|
||||||
public TimeSpan LastConsumeWaveTime { get; set; } = default!;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The next time at which this consumed everything it overlapped with.
|
/// The next time at which this consumed everything it overlapped with.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables(VVAccess.ReadOnly)]
|
[ViewVariables(VVAccess.ReadOnly), DataField("nextConsumeWaveTime", customTypeSerializer:typeof(TimeOffsetSerializer))]
|
||||||
public TimeSpan NextConsumeWaveTime { get; set; } = default!;
|
public TimeSpan NextConsumeWaveTime;
|
||||||
|
|
||||||
#endregion Update Timing
|
#endregion Update Timing
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user