Skip to content

Commit

Permalink
Added non-allocating overloads for Message's array retrieval methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-weiland committed Jul 2, 2021
1 parent 5812dd3 commit b1b81c6
Show file tree
Hide file tree
Showing 7 changed files with 658 additions and 163 deletions.
Binary file not shown.
180 changes: 159 additions & 21 deletions Demos/Unity/Client/Assets/Scripts/Multiplayer/RiptideNetworking.xml

Large diffs are not rendered by default.

Binary file not shown.
180 changes: 159 additions & 21 deletions Demos/Unity/Server/Assets/Scripts/Multiplayer/RiptideNetworking.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public static void PlayerName(ServerClient fromClient, Message message)

public static void PlayerInput(ServerClient fromClient, Message message)
{
Player.List[fromClient.Id].SetInput(message.GetBools(5), message.GetVector3());
Player player = Player.List[fromClient.Id];
message.GetBools(5, player.Inputs);
player.SetForwardDirection(message.GetVector3());
}
}
17 changes: 8 additions & 9 deletions Demos/Unity/Server/Assets/Scripts/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Player : MonoBehaviour
[SerializeField] private float moveSpeed;
[SerializeField] private float jumpSpeed;

private bool[] inputs;
public bool[] Inputs { get; set; }
private float yVelocity;

private void OnValidate()
Expand All @@ -31,22 +31,22 @@ private void Start()
moveSpeed *= Time.fixedDeltaTime;
jumpSpeed *= Time.fixedDeltaTime;

inputs = new bool[5];
Inputs = new bool[5];
}

private void FixedUpdate()
{
Vector2 inputDirection = Vector2.zero;
if (inputs[0])
if (Inputs[0])
inputDirection.y += 1;

if (inputs[1])
if (Inputs[1])
inputDirection.y -= 1;

if (inputs[2])
if (Inputs[2])
inputDirection.x -= 1;

if (inputs[3])
if (Inputs[3])
inputDirection.x += 1;

Move(inputDirection);
Expand All @@ -60,7 +60,7 @@ private void Move(Vector2 inputDirection)
if (controller.isGrounded)
{
yVelocity = 0f;
if (inputs[4])
if (Inputs[4])
yVelocity = jumpSpeed;
}
yVelocity += gravity;
Expand All @@ -71,9 +71,8 @@ private void Move(Vector2 inputDirection)
SendMovement();
}

public void SetInput(bool[] inputs, Vector3 forward)
public void SetForwardDirection(Vector3 forward)
{
this.inputs = inputs;
forward.y = 0; // Keep the player upright
transform.forward = forward;
}
Expand Down
440 changes: 329 additions & 111 deletions RiptideNetworking/RiptideNetworking/Message.cs

Large diffs are not rendered by default.

0 comments on commit b1b81c6

Please sign in to comment.