From 18641f1facc8ce6df359709361342993e353a37f Mon Sep 17 00:00:00 2001 From: InvalidArgument3 Date: Sun, 8 Dec 2024 21:13:33 -0600 Subject: [PATCH 1/2] Revert "reduce teleport rate of sipsapce from 1 tick to every 10 ticsk" This reverts commit d84bf428e797e7a990056938b3a06d8805b47bab. --- .../Scripts/WarpDrive/WarpDriveSession.cs | 2 +- .../Data/Scripts/WarpDrive/WarpSystem.cs | 42 +++++-------- .../Scripts/concatrecursivelyandminify.bat | 60 ------------------- 3 files changed, 16 insertions(+), 88 deletions(-) delete mode 100644 Slipspace Engine/Data/Scripts/concatrecursivelyandminify.bat diff --git a/Slipspace Engine/Data/Scripts/WarpDrive/WarpDriveSession.cs b/Slipspace Engine/Data/Scripts/WarpDrive/WarpDriveSession.cs index a7e018ce..71a440fa 100644 --- a/Slipspace Engine/Data/Scripts/WarpDrive/WarpDriveSession.cs +++ b/Slipspace Engine/Data/Scripts/WarpDrive/WarpDriveSession.cs @@ -228,7 +228,7 @@ public void TransmitToggleWarp(IMyTerminalBlock block) })); } - private void ReceiveWarpSpeed(ushort channel, byte[] data, ulong sender, bool fromServer) //TODO: suspect this for constant warp load sent to clients + private void ReceiveWarpSpeed(ushort channel, byte[] data, ulong sender, bool fromServer) { var message = MyAPIGateway.Utilities.SerializeFromBinary(data); if (message == null) diff --git a/Slipspace Engine/Data/Scripts/WarpDrive/WarpSystem.cs b/Slipspace Engine/Data/Scripts/WarpDrive/WarpSystem.cs index b78fc718..9119ca3f 100644 --- a/Slipspace Engine/Data/Scripts/WarpDrive/WarpSystem.cs +++ b/Slipspace Engine/Data/Scripts/WarpDrive/WarpSystem.cs @@ -76,9 +76,6 @@ public class WarpSystem { public string ProximytyAlert = "Can't Start SSD, Proximity Alert!"; public const float EARTH_GRAVITY = 9.806652f; - private int teleportTick = 0; - private const int TELEPORT_DELAY = 10; // Adjust this value to change the update frequency - public WarpSystem(WarpDrive block, WarpSystem oldSystem) { if (block == null) @@ -214,30 +211,21 @@ public void UpdateBeforeSimulation() { } } - if (TeleportNow && !SafeTriggerON) - { - teleportTick++; - if (teleportTick >= TELEPORT_DELAY) - { - teleportTick = 0; - TeleportNow = false; - - if (currentSpeedPt > 1f && gridMatrix != null) - { - // Multiply the movement by TELEPORT_DELAY to maintain the same effective speed - gridMatrix.Translation += gridMatrix.Forward * currentSpeedPt * TELEPORT_DELAY; - - if (MyAPIGateway.Utilities.IsDedicated || MyAPIGateway.Multiplayer.IsServer) - MainGrid.Teleport(gridMatrix); - - if (!MyAPIGateway.Utilities.IsDedicated) - { - DrawAllLinesCenter1(); - - if (currentSpeedPt > 316.6666) - { - DrawAllLinesCenter4(); - } + if (TeleportNow && !SafeTriggerON) { + TeleportNow = false; + + if (currentSpeedPt > 1f && gridMatrix != null) { + gridMatrix.Translation += gridMatrix.Forward * currentSpeedPt; + + if (MyAPIGateway.Utilities.IsDedicated || MyAPIGateway.Multiplayer.IsServer) + MainGrid.Teleport(gridMatrix); + + if (!MyAPIGateway.Utilities.IsDedicated) { + DrawAllLinesCenter1(); + + if (currentSpeedPt > 316.6666) { + //StartBlinkParticleEffect(); + DrawAllLinesCenter4(); } } } diff --git a/Slipspace Engine/Data/Scripts/concatrecursivelyandminify.bat b/Slipspace Engine/Data/Scripts/concatrecursivelyandminify.bat deleted file mode 100644 index 9bbffa34..00000000 --- a/Slipspace Engine/Data/Scripts/concatrecursivelyandminify.bat +++ /dev/null @@ -1,60 +0,0 @@ -@echo off -setlocal enabledelayedexpansion -chcp 65001 -REM ^^ this is to change the encoding to UTF-8, apparently - -echo Starting operation... - -set TEMP_OUTPUT=temp_concatenated.txt -set FINAL_OUTPUT=minified_output.txt -set /a COUNT=0 -set /a ERRORS=0 - -if exist "%TEMP_OUTPUT%" ( - echo Existing temporary file found. Deleting... - del "%TEMP_OUTPUT%" -) - -if exist "%FINAL_OUTPUT%" ( - echo Existing output file found. Deleting... - del "%FINAL_OUTPUT%" -) - -for /r %%i in (*.cs) do ( - echo Processing: "%%i" - type "%%i" >> "%TEMP_OUTPUT%" - if errorlevel 1 ( - echo Error processing "%%i". - set /a ERRORS+=1 - ) else ( - set /a COUNT+=1 - ) -) - -echo Concatenation completed. -echo Total files processed: %COUNT% -if %ERRORS% gtr 0 ( - echo There were %ERRORS% errors during the concatenation. -) else ( - echo No errors encountered during concatenation. -) - -echo Minifying concatenated file... -csmin < "%TEMP_OUTPUT%" > "%FINAL_OUTPUT%" -if errorlevel 1 ( - echo Error occurred during minification. - set /a ERRORS+=1 -) else ( - echo Minification completed successfully. -) - -echo Cleaning up temporary file... -del "%TEMP_OUTPUT%" - -echo Operation completed. -if %ERRORS% gtr 0 ( - echo There were %ERRORS% errors during the entire operation. -) else ( - echo No errors encountered during the entire operation. -) -pause \ No newline at end of file From 76b71a36a443ecb82584f5c559532d87b3d6eac9 Mon Sep 17 00:00:00 2001 From: InvalidArgument3 Date: Sun, 8 Dec 2024 21:21:40 -0600 Subject: [PATCH 2/2] rate limiter on TransmitWarpSpeed packet --- .../Scripts/WarpDrive/WarpDriveSession.cs | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/Slipspace Engine/Data/Scripts/WarpDrive/WarpDriveSession.cs b/Slipspace Engine/Data/Scripts/WarpDrive/WarpDriveSession.cs index 71a440fa..75b4e1ab 100644 --- a/Slipspace Engine/Data/Scripts/WarpDrive/WarpDriveSession.cs +++ b/Slipspace Engine/Data/Scripts/WarpDrive/WarpDriveSession.cs @@ -254,19 +254,48 @@ private void ReceiveWarpSpeed(ushort channel, byte[] data, ulong sender, bool fr // 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?.GameLogic?.GetAs(); + WarpDrive drive = DriveBlock != null ? DriveBlock.GameLogic.GetAs() : null; if (drive == null) return; - MyAPIGateway.Multiplayer.SendMessageToServer(toggleWarpPacketIdSpeed, - message: MyAPIGateway.Utilities.SerializeToBinary(new SpeedMessage + 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) { - EntityId = DriveBlock.EntityId, - WarpSpeed = currentSpeedPt - })); + MyAPIGateway.Multiplayer.SendMessageToServer(toggleWarpPacketIdSpeed, + message: MyAPIGateway.Utilities.SerializeToBinary(new SpeedMessage + { + EntityId = entityId, + WarpSpeed = currentSpeedPt + })); + updateInfo.LastSentSpeed = currentSpeedPt; + } + } } private void ReceiveWarpConfig(ushort channel, byte[] data, ulong sender, bool fromServer)