Skip to content

Commit 9d6d443

Browse files
committed
fix (Network): Fixed buffer filling up too fast
1 parent a06dcfc commit 9d6d443

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

Assets/Scenes/TestMap.unity

0 Bytes
Binary file not shown.

Assets/Scripts/Character/CharacterNetworkInput.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
[NetworkSettings(channel = 1, sendInterval = 0.33f)]
2121
public class CharacterNetworkInput : NetworkBehaviour {
2222

23-
private const float MAX_CLIENT_WAITING_STATES = 25; //How many states to keep on client
23+
private const float MAX_CLIENT_WAITING_STATES = 30; //How many states to keep on client
2424
private const float MAX_CLIENT_DISTANCE_WARNING = 0.25f; //Max distance between server and localy calculated position
2525
private const float MAX_SERVER_DISTANCE_SNAP = 0.15f; //Max distance between client and server calculated position before SNAPPING
2626

@@ -38,6 +38,7 @@ public class CharacterNetworkInput : NetworkBehaviour {
3838
private CharacterMovement characterMovement;
3939
private CharacterRotation characterRotation;
4040

41+
private float nextSendTime; //CLIENT SIDE time when the client must send data to server
4142
private Queue<CharacterInput.InputState> inputStates; //CLIENT SIDE input states not ack by server
4243

4344
private Vector3 serverLastRecvPosition; //CLIENT SIDE last received pos from server
@@ -76,19 +77,24 @@ void FixedUpdate () {
7677
characterMovement.RunUpdate(Time.fixedDeltaTime);
7778
characterRotation.RunUpdate(Time.fixedDeltaTime);
7879
//Client: Trim commands to 25 and send commands to server
80+
Debug.Log(inputStates.Count);
7981
if (inputStates.Count > MAX_CLIENT_WAITING_STATES) {
8082
Debug.LogError("Too many waiting states, starting to drop frames");
8183
}
8284
while (inputStates.Count > MAX_CLIENT_WAITING_STATES) { inputStates.Dequeue(); }
83-
CmdSetServerInput(inputStates.ToArray(), transform.position);
85+
if (nextSendTime < Time.time)
86+
{
87+
CmdSetServerInput(inputStates.ToArray(), transform.position);
88+
nextSendTime = Time.time + 0.33f;
89+
}
8490
}
8591
}
8692

8793
/// <summary>
8894
/// Server: Receive a list of inputs from the client
8995
/// </summary>
9096
/// <param name="newInputs"></param>
91-
[Command]
97+
[Command(channel = 1)]
9298
void CmdSetServerInput(CharacterInput.InputState[] newInputs, Vector3 newClientPos)
9399
{
94100
int index = 0;

ProjectSettings/TimeManager.asset

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)