Skip to content

Commit 1c756c8

Browse files
committed
fix (Network): Reduced payload by changing movement from float to sbyte
1 parent 9d6d443 commit 1c756c8

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

Assets/Scenes/TestMap.unity

0 Bytes
Binary file not shown.

Assets/Scripts/Character/CharacterInput.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public void Parse(int inputState)
2929
{
3030
currentInput.inputState = inputState;
3131

32-
currentInput.inputHorizontal = Input.GetAxis("Horizontal");
33-
currentInput.inputVertical = Input.GetAxis("Vertical");
32+
currentInput.setInputHorizontal(Input.GetAxis("Horizontal"));
33+
currentInput.setInputVertical(Input.GetAxis("Vertical"));
3434
currentInput.inputJump = Input.GetButton("Jump");
3535
currentInput.inputAim = cameraAim.aimPoint; //Get the aim from the camera
3636
}
@@ -49,10 +49,30 @@ public struct InputState
4949
{
5050
public int inputState;
5151

52-
public float inputHorizontal;
53-
public float inputVertical;
52+
public sbyte inputHorizontal;
53+
public sbyte inputVertical;
5454
public bool inputJump;
5555
public Vector3 inputAim;
56+
57+
public void setInputHorizontal(float value)
58+
{
59+
inputHorizontal = (sbyte)(value * 127);
60+
}
61+
62+
public void setInputVertical(float value)
63+
{
64+
inputVertical = (sbyte)(value * 127);
65+
}
66+
67+
public float getInputHorizontal()
68+
{
69+
return (float)inputHorizontal / 127;
70+
}
71+
72+
public float getInputVertical()
73+
{
74+
return (float)inputVertical / 127;
75+
}
5676
}
5777

5878
}

Assets/Scripts/Character/CharacterMovement.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void RunUpdate(float delta)
3131
{
3232
if (IsGrounded())
3333
{
34-
moveDirection = new Vector3(input.currentInput.inputHorizontal, 0, input.currentInput.inputVertical);
34+
moveDirection = new Vector3(input.currentInput.getInputHorizontal(), 0, input.currentInput.getInputVertical());
3535
moveDirection = transform.TransformDirection(moveDirection);
3636
moveDirection *= speed;
3737

Assets/Scripts/Character/CharacterNetworkInput.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void FixedUpdate () {
8181
if (inputStates.Count > MAX_CLIENT_WAITING_STATES) {
8282
Debug.LogError("Too many waiting states, starting to drop frames");
8383
}
84-
while (inputStates.Count > MAX_CLIENT_WAITING_STATES) { inputStates.Dequeue(); }
84+
//while (inputStates.Count > MAX_CLIENT_WAITING_STATES) { inputStates.Dequeue(); }
8585
if (nextSendTime < Time.time)
8686
{
8787
CmdSetServerInput(inputStates.ToArray(), transform.position);

0 commit comments

Comments
 (0)