diff --git a/Slipspace Engine/Data/Scripts/WarpDrive/WarpDriveSession.cs b/Slipspace Engine/Data/Scripts/WarpDrive/WarpDriveSession.cs index f664a72..a7e018c 100644 --- a/Slipspace Engine/Data/Scripts/WarpDrive/WarpDriveSession.cs +++ b/Slipspace Engine/Data/Scripts/WarpDrive/WarpDriveSession.cs @@ -254,48 +254,19 @@ public void TransmitToggleWarp(IMyTerminalBlock block) // MyAPIGateway.Multiplayer.SendMessageToOthers(toggleWarpPacketIdSpeed, data); } - private Dictionary speedUpdateInfo = new Dictionary(); - - private class SpeedUpdateInfo - { - public int UpdateTick = 0; - public double LastSentSpeed = 0; - } - - private const int SPEED_UPDATE_DELAY = 60; // Update once per second (assuming 60 ticks per second) - private const double SPEED_CHANGE_THRESHOLD = 1.0; // Only update if speed changed by 1 m/s or more - public void TransmitWarpSpeed(IMyFunctionalBlock WarpBlock, double currentSpeedPt) { var DriveBlock = WarpBlock as IMyTerminalBlock; - WarpDrive drive = DriveBlock != null ? DriveBlock.GameLogic.GetAs() : null; + WarpDrive drive = DriveBlock?.GameLogic?.GetAs(); if (drive == null) return; - long entityId = DriveBlock.EntityId; - - SpeedUpdateInfo updateInfo; - if (!speedUpdateInfo.TryGetValue(entityId, out updateInfo)) - { - updateInfo = new SpeedUpdateInfo(); - speedUpdateInfo[entityId] = updateInfo; - } - - updateInfo.UpdateTick++; - if (updateInfo.UpdateTick >= SPEED_UPDATE_DELAY) - { - updateInfo.UpdateTick = 0; - if (Math.Abs(currentSpeedPt - updateInfo.LastSentSpeed) >= SPEED_CHANGE_THRESHOLD) + MyAPIGateway.Multiplayer.SendMessageToServer(toggleWarpPacketIdSpeed, + message: MyAPIGateway.Utilities.SerializeToBinary(new SpeedMessage { - MyAPIGateway.Multiplayer.SendMessageToServer(toggleWarpPacketIdSpeed, - message: MyAPIGateway.Utilities.SerializeToBinary(new SpeedMessage - { - EntityId = entityId, - WarpSpeed = currentSpeedPt - })); - updateInfo.LastSentSpeed = currentSpeedPt; - } - } + EntityId = DriveBlock.EntityId, + WarpSpeed = currentSpeedPt + })); } private void ReceiveWarpConfig(ushort channel, byte[] data, ulong sender, bool fromServer)