Rejig Device networks (#7380)
This commit is contained in:
@@ -21,7 +21,7 @@ namespace Content.Server.Medical.CrewMonitoring
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<CrewMonitoringConsoleComponent, ComponentRemove>(OnRemove);
|
||||
SubscribeLocalEvent<CrewMonitoringConsoleComponent, PacketSentEvent>(OnPacketReceived);
|
||||
SubscribeLocalEvent<CrewMonitoringConsoleComponent, DeviceNetworkPacketEvent>(OnPacketReceived);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
@@ -47,7 +47,7 @@ namespace Content.Server.Medical.CrewMonitoring
|
||||
component.ConnectedSensors.Clear();
|
||||
}
|
||||
|
||||
private void OnPacketReceived(EntityUid uid, CrewMonitoringConsoleComponent component, PacketSentEvent args)
|
||||
private void OnPacketReceived(EntityUid uid, CrewMonitoringConsoleComponent component, DeviceNetworkPacketEvent args)
|
||||
{
|
||||
var suitSensor = _sensors.PacketToSuitSensor(args.Data);
|
||||
if (suitSensor == null)
|
||||
|
||||
@@ -40,10 +40,10 @@ namespace Content.Server.Medical.SuitSensors
|
||||
public string ActivationSlot = "jumpsuit";
|
||||
|
||||
/// <summary>
|
||||
/// How often does sensor update its owners status (in seconds).
|
||||
/// How often does sensor update its owners status (in seconds). Limited by the system update rate.
|
||||
/// </summary>
|
||||
[DataField("updateRate")]
|
||||
public float UpdateRate = 2f;
|
||||
public TimeSpan UpdateRate = TimeSpan.FromSeconds(2f);
|
||||
|
||||
/// <summary>
|
||||
/// Current user that wears suit sensor. Null if nobody wearing it.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using Content.Server.Access.Systems;
|
||||
using Content.Server.DeviceNetwork;
|
||||
using Content.Server.DeviceNetwork.Components;
|
||||
@@ -30,7 +30,7 @@ namespace Content.Server.Medical.SuitSensors
|
||||
[Dependency] private readonly DeviceNetworkSystem _deviceNetworkSystem = default!;
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
private const float UpdateRate = 0.5f;
|
||||
private const float UpdateRate = 1f;
|
||||
private float _updateDif;
|
||||
|
||||
public override void Initialize()
|
||||
@@ -58,8 +58,11 @@ namespace Content.Server.Medical.SuitSensors
|
||||
var sensors = EntityManager.EntityQuery<SuitSensorComponent, DeviceNetworkComponent>();
|
||||
foreach (var (sensor, device) in sensors)
|
||||
{
|
||||
if (device.TransmitFrequency is not uint frequency)
|
||||
continue;
|
||||
|
||||
// check if sensor is ready to update
|
||||
if (curTime - sensor.LastUpdate < TimeSpan.FromSeconds(sensor.UpdateRate))
|
||||
if (curTime - sensor.LastUpdate < sensor.UpdateRate)
|
||||
continue;
|
||||
sensor.LastUpdate = curTime;
|
||||
|
||||
@@ -70,7 +73,7 @@ namespace Content.Server.Medical.SuitSensors
|
||||
|
||||
// broadcast it to device network
|
||||
var payload = SuitSensorToPacket(status);
|
||||
_deviceNetworkSystem.QueuePacket(sensor.Owner, DeviceNetworkConstants.NullAddress, device.Frequency, payload, true);
|
||||
_deviceNetworkSystem.QueuePacket(sensor.Owner, null, payload, device: device);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user