Skip to content

Commit

Permalink
Improve smoothness
Browse files Browse the repository at this point in the history
  • Loading branch information
riperiperi committed Apr 1, 2023
1 parent ea88989 commit df81acc
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
4 changes: 3 additions & 1 deletion TSOClient/FSO.Server.Clients/AriesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 3 additions & 1 deletion TSOClient/tso.client/Network/Sandbox/FSOSandboxClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
49 changes: 47 additions & 2 deletions TSOClient/tso.simantics/Engine/VMDirectControlFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public class VMDirectControlFrame : VMStackFrame
private VMDirectControlState State;
private VMDirectControlInput UserInput;

private int HasDelayedInputs;
private VMDirectControlInput DelayedInput;

private List<VMDirectControlInput> ClientInputs = new List<VMDirectControlInput>();

// Animations for mixing:
Expand Down Expand Up @@ -113,14 +116,48 @@ 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)
{
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");
Expand Down Expand Up @@ -402,6 +439,7 @@ private void ProcessClientInputs(Tuple<float, bool> directionInputs)
{
VMDirectControlState dupeState = State;
int lookaheads = 0;
int removed = 0;

for (int i = 0; i < ClientInputs.Count; i++)
{
Expand All @@ -410,6 +448,7 @@ private void ProcessClientInputs(Tuple<float, bool> directionInputs)
if (State.Input.ID - input.ID >= 0)
{
ClientInputs.RemoveAt(i--);
removed++;
continue;
}

Expand All @@ -430,9 +469,10 @@ private void ProcessClientInputs(Tuple<float, bool> directionInputs)
TryMove(obstacles, ref dupeState, lookaheads + i + 1);
}

if (lookaheads > LastLookaheads || lookaheads == 0)
if (lookaheads >= LastLookaheads || lookaheads == 0)
{
LastLookaheads = lookaheads;
TickN = 0;
}
else
{
Expand Down Expand Up @@ -543,6 +583,11 @@ private void UpdateAnimation(ref VMDirectControlState state, Tuple<float, bool>

public VMPrimitiveExitCode Tick()
{
if (VM.IsServer)
{
TakeDelayedInput();
}

VM.Context.NextRandom(1); //rng cycle - for desync detect
var avatar = (VMAvatar)Caller;

Expand Down

0 comments on commit df81acc

Please sign in to comment.