Skip to content

Commit

Permalink
Predict two-way levers (#25043)
Browse files Browse the repository at this point in the history
* Predict two-way levers

Annoys me the rare occasions I touch cargo. Doesn't predict the signal but at least the lever responds immediately.

* space

* a
  • Loading branch information
metalgearsloth authored Feb 11, 2024
1 parent 8e59b4f commit 05a2ddf
Show file tree
Hide file tree
Showing 35 changed files with 114 additions and 68 deletions.
2 changes: 1 addition & 1 deletion Content.Benchmarks/DeviceNetworkingBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using Content.IntegrationTests;
using Content.IntegrationTests.Pair;
using Content.IntegrationTests.Tests.DeviceNetwork;
using Content.Server.DeviceNetwork;
using Content.Server.DeviceNetwork.Systems;
using Content.Shared.DeviceNetwork;
using Robust.Shared;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
Expand Down
8 changes: 8 additions & 0 deletions Content.Client/DeviceLinking/DeviceLinkSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Content.Shared.DeviceLinking;

namespace Content.Client.DeviceLinking;

public sealed class DeviceLinkSystem : SharedDeviceLinkSystem
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Content.Server.DeviceNetwork;
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Systems;
using Content.Shared.DeviceNetwork;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

using Content.Server.DeviceNetwork;
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Systems;
using Content.Shared.DeviceNetwork;
using Robust.Shared.GameObjects;
using Robust.Shared.Reflection;

Expand Down
1 change: 1 addition & 0 deletions Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Content.Shared.Atmos.Monitor.Components;
using Content.Shared.Atmos.Piping.Unary.Components;
using Content.Shared.DeviceLinking;
using Content.Shared.DeviceNetwork;
using Content.Shared.DeviceNetwork.Systems;
using Content.Shared.Interaction;
using Content.Shared.Wires;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Content.Server.DeviceNetwork.Systems;
using Content.Server.Power.Components;
using Content.Shared.Atmos.Monitor;
using Content.Shared.DeviceNetwork;
using Content.Shared.Tag;
using Robust.Server.Audio;
using Robust.Server.GameObjects;
Expand Down
1 change: 1 addition & 0 deletions Content.Server/Atmos/Monitor/Systems/AtmosDeviceNetwork.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Content.Server.DeviceNetwork;
using Content.Server.DeviceNetwork.Systems;
using Content.Shared.Atmos.Monitor.Components;
using Content.Shared.DeviceNetwork;

namespace Content.Server.Atmos.Monitor.Systems;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Content.Server.Power.EntitySystems;
using Content.Shared.Atmos;
using Content.Shared.Atmos.Monitor;
using Content.Shared.DeviceNetwork;
using Content.Shared.Tag;
using Robust.Shared.Prototypes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Content.Shared.Atmos.Visuals;
using Content.Shared.Audio;
using Content.Shared.Database;
using Content.Shared.DeviceNetwork;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Popups;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Content.Shared.UserInterface;
using Content.Shared.Administration.Logs;
using Content.Shared.Database;
using Content.Shared.DeviceNetwork;
using Content.Shared.Examine;

namespace Content.Server.Atmos.Piping.Unary.EntitySystems
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Content.Shared.Atmos.Piping.Unary.Components;
using Content.Shared.Atmos.Visuals;
using Content.Shared.Audio;
using Content.Shared.DeviceNetwork;
using Content.Shared.Examine;
using Content.Shared.Tools.Systems;
using JetBrains.Annotations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Content.Shared.Atmos.Monitor;
using Content.Shared.Atmos.Piping.Unary.Components;
using Content.Shared.Audio;
using Content.Shared.DeviceNetwork;
using Content.Shared.Tools.Systems;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using Content.Shared.Chat;
using Content.Shared.Communications;
using Content.Shared.Database;
using Content.Shared.DeviceNetwork;
using Content.Shared.Emag.Components;
using Content.Shared.Popups;
using Robust.Server.GameObjects;
Expand Down
24 changes: 0 additions & 24 deletions Content.Server/DeviceLinking/Components/TwoWayLeverComponent.cs

This file was deleted.

1 change: 1 addition & 0 deletions Content.Server/DeviceLinking/Events/SignalReceivedEvent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Server.DeviceNetwork;
using Content.Shared.DeviceNetwork;

namespace Content.Server.DeviceLinking.Events;

Expand Down
11 changes: 2 additions & 9 deletions Content.Server/DeviceLinking/Systems/DeviceLinkSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Systems;
using Content.Shared.DeviceLinking;
using Content.Shared.DeviceNetwork;

namespace Content.Server.DeviceLinking.Systems;

Expand Down Expand Up @@ -35,15 +36,7 @@ public override void Update(float frameTime)
}

#region Sending & Receiving
/// <summary>
/// Sends a network payload directed at the sink entity.
/// Just raises a <see cref="SignalReceivedEvent"/> without data if the source or the sink doesn't have a <see cref="DeviceNetworkComponent"/>
/// </summary>
/// <param name="uid">The source uid that invokes the port</param>
/// <param name="port">The port to invoke</param>
/// <param name="data">Optional data to send along</param>
/// <param name="sourceComponent"></param>
public void InvokePort(EntityUid uid, string port, NetworkPayload? data = null, DeviceLinkSourceComponent? sourceComponent = null)
public override void InvokePort(EntityUid uid, string port, NetworkPayload? data = null, DeviceLinkSourceComponent? sourceComponent = null)
{
if (!Resolve(uid, ref sourceComponent) || !sourceComponent.Outputs.TryGetValue(port, out var sinks))
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Content.Server.DeviceLinking.Components;
using Content.Server.DeviceNetwork;
using Content.Server.Doors.Systems;
using Content.Shared.DeviceNetwork;
using Content.Shared.Doors.Components;
using Content.Shared.Doors;
using JetBrains.Annotations;
Expand Down
26 changes: 0 additions & 26 deletions Content.Server/DeviceNetwork/NetworkPayload.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Components.Devices;
using Content.Shared.DeviceNetwork;
using Content.Shared.Interaction;

namespace Content.Server.DeviceNetwork.Systems.Devices
Expand Down
1 change: 1 addition & 0 deletions Content.Server/Disposal/Mailing/MailingUnitSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Content.Server.DeviceNetwork.Systems;
using Content.Server.Disposal.Unit.EntitySystems;
using Content.Server.Power.Components;
using Content.Shared.DeviceNetwork;
using Content.Shared.Disposal;
using Content.Shared.Interaction;
using Robust.Server.GameObjects;
Expand Down
1 change: 1 addition & 0 deletions Content.Server/Fax/FaxSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Content.Shared.Administration.Logs;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Database;
using Content.Shared.DeviceNetwork;
using Content.Shared.Emag.Components;
using Content.Shared.Emag.Systems;
using Content.Shared.Fax;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Content.Server.Medical.SuitSensors;
using Content.Server.Power.Components;
using Content.Server.Station.Systems;
using Content.Shared.DeviceNetwork;
using Content.Shared.Medical.SuitSensor;
using Robust.Shared.Timing;

Expand Down
1 change: 1 addition & 0 deletions Content.Server/Medical/SuitSensors/SuitSensorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Content.Server.Popups;
using Content.Server.Station.Systems;
using Content.Shared.Damage;
using Content.Shared.DeviceNetwork;
using Content.Shared.Emp;
using Content.Shared.Examine;
using Content.Shared.Inventory.Events;
Expand Down
1 change: 1 addition & 0 deletions Content.Server/Power/Generation/Teg/TegSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Content.Server.NodeContainer;
using Content.Server.NodeContainer.Nodes;
using Content.Server.Power.Components;
using Content.Shared.DeviceNetwork;
using Content.Shared.Examine;
using Content.Shared.Power.Generation.Teg;
using Content.Shared.Rounding;
Expand Down
1 change: 1 addition & 0 deletions Content.Server/RoundEnd/RoundEndSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Content.Server.Station.Components;
using Content.Server.Station.Systems;
using Content.Shared.Database;
using Content.Shared.DeviceNetwork;
using Content.Shared.GameTicking;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Configuration;
Expand Down
1 change: 1 addition & 0 deletions Content.Server/SensorMonitoring/BatterySensorSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Content.Server.DeviceNetwork;
using Content.Server.DeviceNetwork.Systems;
using Content.Server.Power.Components;
using Content.Shared.DeviceNetwork;

namespace Content.Server.SensorMonitoring;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
using Content.Shared.Atmos.Monitor;
using Content.Shared.Atmos.Piping.Binary.Components;
using Content.Shared.Atmos.Piping.Unary.Components;
using Content.Shared.DeviceNetwork;
using Content.Shared.DeviceNetwork.Components;
using Content.Shared.DeviceNetwork.Systems;
using Content.Shared.SensorMonitoring;
using Robust.Server.GameObjects;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using ConsoleUIState = Content.Shared.SensorMonitoring.SensorMonitoringConsoleBoundInterfaceState;

namespace Content.Server.SensorMonitoring;

Expand Down
1 change: 1 addition & 0 deletions Content.Server/Shuttles/Systems/ArrivalsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Content.Server.Station.Systems;
using Content.Shared.Administration;
using Content.Shared.CCVar;
using Content.Shared.DeviceNetwork;
using Content.Shared.Mobs.Components;
using Content.Shared.Movement.Components;
using Content.Shared.Parallax.Biomes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Content.Shared.Access;
using Content.Shared.CCVar;
using Content.Shared.Database;
using Content.Shared.DeviceNetwork;
using Content.Shared.Popups;
using Content.Shared.Shuttles.BUIStates;
using Content.Shared.Shuttles.Events;
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Shuttles/Systems/EmergencyShuttleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Content.Server.Administration.Managers;
using Content.Server.Chat.Systems;
using Content.Server.Communications;
using Content.Server.DeviceNetwork;
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Systems;
using Content.Server.GameTicking.Events;
Expand All @@ -19,6 +18,7 @@
using Content.Shared.Access.Systems;
using Content.Shared.CCVar;
using Content.Shared.Database;
using Content.Shared.DeviceNetwork;
using Content.Shared.Shuttles.Components;
using Content.Shared.Shuttles.Events;
using Content.Shared.Tag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Content.Server.DeviceNetwork;
using Content.Server.DeviceNetwork.Systems;
using Content.Server.Power.Components;
using Content.Shared.DeviceNetwork;
using Content.Shared.UserInterface;
using Content.Shared.SurveillanceCamera;
using Robust.Server.GameObjects;
Expand Down
26 changes: 26 additions & 0 deletions Content.Shared/DeviceLinking/Components/TwoWayLeverComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;

namespace Content.Shared.DeviceLinking.Components;

/// <summary>
/// Simple ternary state for device linking.
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class TwoWayLeverComponent : Component
{
[DataField, AutoNetworkedField]
public TwoWayLeverState State;

[DataField, AutoNetworkedField]
public bool NextSignalLeft;

[DataField]
public ProtoId<SourcePortPrototype> LeftPort = "Left";

[DataField]
public ProtoId<SourcePortPrototype> RightPort = "Right";

[DataField]
public ProtoId<SourcePortPrototype> MiddlePort = "Middle";
}
23 changes: 23 additions & 0 deletions Content.Shared/DeviceLinking/SharedDeviceLinkSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Content.Shared.Administration.Logs;
using Content.Shared.Database;
using Content.Shared.DeviceLinking.Events;
using Content.Shared.DeviceNetwork;
using Content.Shared.Popups;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
Expand Down Expand Up @@ -148,6 +149,9 @@ private void OnSinkRemoved(EntityUid sinkUid, DeviceLinkSinkComponent sinkCompon
/// </summary>
public void EnsureSourcePorts(EntityUid uid, params string[] ports)
{
if (ports.Length == 0)
return;

var comp = EnsureComp<DeviceLinkSourceComponent>(uid);
comp.Ports ??= new HashSet<string>();

Expand All @@ -163,6 +167,9 @@ public void EnsureSourcePorts(EntityUid uid, params string[] ports)
/// </summary>
public void EnsureSinkPorts(EntityUid uid, params string[] ports)
{
if (ports.Length == 0)
return;

var comp = EnsureComp<DeviceLinkSinkComponent>(uid);
comp.Ports ??= new HashSet<string>();

Expand Down Expand Up @@ -550,4 +557,20 @@ private void CreateLinkPopup(EntityUid? userId, EntityUid sourceUid, string sour
("machine2", sinkUid), ("port2", PortName<SinkPortPrototype>(sink))), userId.Value, PopupType.Medium);
}
#endregion

#region Sending & Receiving
/// <summary>
/// Sends a network payload directed at the sink entity.
/// Just raises a <see cref="SignalReceivedEvent"/> without data if the source or the sink doesn't have a <see cref="DeviceNetworkComponent"/>
/// </summary>
/// <param name="uid">The source uid that invokes the port</param>
/// <param name="port">The port to invoke</param>
/// <param name="data">Optional data to send along</param>
/// <param name="sourceComponent"></param>
public virtual void InvokePort(EntityUid uid, string port, NetworkPayload? data = null,
DeviceLinkSourceComponent? sourceComponent = null)
{
// NOOP on client for the moment.
}
#endregion
}
Loading

0 comments on commit 05a2ddf

Please sign in to comment.