diff --git a/TSOClient/FSO.Server.Clients/AriesClient.cs b/TSOClient/FSO.Server.Clients/AriesClient.cs index 9dd471604..8f7621e5e 100644 --- a/TSOClient/FSO.Server.Clients/AriesClient.cs +++ b/TSOClient/FSO.Server.Clients/AriesClient.cs @@ -138,7 +138,9 @@ public void Connect(IPEndPoint target) //if we tried to dispose it, we'd get random disposed object exceptions because mina doesn't expect you to cancel that early. Disconnect(); //if we have already established a connection, make sure it is closed. } - Connector = new AsyncSocketConnector(); + var socketConnector = new AsyncSocketConnector(); + socketConnector.SessionConfig.NoDelay = true; + Connector = socketConnector; var connector = Connector; Connector.ConnectTimeoutInMillis = 10000; //Connector.FilterChain.AddLast("logging", new LoggingFilter()); diff --git a/TSOClient/tso.client/Network/Sandbox/FSOSandboxClient.cs b/TSOClient/tso.client/Network/Sandbox/FSOSandboxClient.cs index 08d3e4df6..f66a73803 100644 --- a/TSOClient/tso.client/Network/Sandbox/FSOSandboxClient.cs +++ b/TSOClient/tso.client/Network/Sandbox/FSOSandboxClient.cs @@ -38,7 +38,9 @@ public void Disconnect() public void Connect(IPEndPoint target) { - Connector = new AsyncSocketConnector(); + var socketConnector = new AsyncSocketConnector(); + socketConnector.SessionConfig.NoDelay = true; + Connector = socketConnector; Connector.ConnectTimeoutInMillis = 10000; Connector.Handler = this; diff --git a/TSOClient/tso.simantics/Engine/VMDirectControlFrame.cs b/TSOClient/tso.simantics/Engine/VMDirectControlFrame.cs index 8ef6584c0..ba9b34e3e 100644 --- a/TSOClient/tso.simantics/Engine/VMDirectControlFrame.cs +++ b/TSOClient/tso.simantics/Engine/VMDirectControlFrame.cs @@ -58,6 +58,9 @@ public class VMDirectControlFrame : VMStackFrame private VMDirectControlState State; private VMDirectControlInput UserInput; + private int HasDelayedInputs; + private VMDirectControlInput DelayedInput; + private List ClientInputs = new List(); // Animations for mixing: @@ -113,7 +116,28 @@ public void InitAnimations() public void SendControls(VMDirectControlInput input) { - State.Input = input; + if (VM.IsServer) + { + if (HasDelayedInputs == 0) + { + State.Input = input; + HasDelayedInputs++; + } + else if (HasDelayedInputs == 1) + { + DelayedInput = input; + HasDelayedInputs++; + } + else + { + // Skip + } + } + else + { + + State.Input = input; + } } public void SendUserControls(VMDirectControlInput input) @@ -121,6 +145,19 @@ public void SendUserControls(VMDirectControlInput input) UserInput = input; } + public void TakeDelayedInput() + { + if (HasDelayedInputs == 2) + { + State.Input = DelayedInput; + } + + if (HasDelayedInputs > 0) + { + HasDelayedInputs--; + } + } + private VMAnimationState PlayAnim(string name, VMAvatar avatar) { var animation = FSO.Content.Content.Get().AvatarAnimations.Get(name + ".anim"); @@ -402,6 +439,7 @@ private void ProcessClientInputs(Tuple directionInputs) { VMDirectControlState dupeState = State; int lookaheads = 0; + int removed = 0; for (int i = 0; i < ClientInputs.Count; i++) { @@ -410,6 +448,7 @@ private void ProcessClientInputs(Tuple directionInputs) if (State.Input.ID - input.ID >= 0) { ClientInputs.RemoveAt(i--); + removed++; continue; } @@ -430,9 +469,10 @@ private void ProcessClientInputs(Tuple directionInputs) TryMove(obstacles, ref dupeState, lookaheads + i + 1); } - if (lookaheads > LastLookaheads || lookaheads == 0) + if (lookaheads >= LastLookaheads || lookaheads == 0) { LastLookaheads = lookaheads; + TickN = 0; } else { @@ -543,6 +583,11 @@ private void UpdateAnimation(ref VMDirectControlState state, Tuple public VMPrimitiveExitCode Tick() { + if (VM.IsServer) + { + TakeDelayedInput(); + } + VM.Context.NextRandom(1); //rng cycle - for desync detect var avatar = (VMAvatar)Caller;