Move PlayerUpdatePckt creation and consumption to Player.cs
This commit is contained in:
parent
f313f8aaf4
commit
b34edcab2d
@ -83,8 +83,7 @@ namespace NeonTea.Quakeball.Player {
|
||||
WantsToJump = false;
|
||||
|
||||
if (Net.Net.Singleton.Instance != null) {
|
||||
PlayerUpdatePckt pckt = new PlayerUpdatePckt(Player.MoveDirection, Player.CurrentMoveStyle, Player.Jumping, Player.Pitch, Player.Yaw);
|
||||
Net.Net.Singleton.Instance.UpdateLocalPlayer(pckt);
|
||||
Net.Net.Singleton.Instance.UpdateLocalPlayer(Player.CreatePacket());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using NeonTea.Quakeball.Net.Packets;
|
||||
|
||||
namespace NeonTea.Quakeball.Player {
|
||||
/// <summary>The central glue class for players (both local and remote).</summary>
|
||||
@ -62,6 +63,21 @@ namespace NeonTea.Quakeball.Player {
|
||||
private CharacterController CharacterController;
|
||||
private Vector3 FeetPosition;
|
||||
|
||||
/// <summary>Creates a PlayerUpdatePckt representing this Player's current status, for sending to other peers.</summary>
|
||||
public PlayerUpdatePckt CreatePacket() {
|
||||
return new PlayerUpdatePckt(MoveDirection, CurrentMoveStyle, Jumping, Pitch, Yaw);
|
||||
}
|
||||
|
||||
/// <summary>Updates this Player with the given packet, and sets it to null. No reusing packets.</summary>
|
||||
public void ProcessPacket(ref PlayerUpdatePckt packet) {
|
||||
Pitch = packet.Pitch;
|
||||
Yaw = packet.Yaw;
|
||||
MoveDirection = packet.MoveDirection;
|
||||
CurrentMoveStyle = packet.MoveStyle;
|
||||
Jumping = packet.Jumping;
|
||||
packet = null;
|
||||
}
|
||||
|
||||
/// <summary>The normal of the ground below the player. If there is no ground, it's <c>Vector3.up</c> by default.</summary>
|
||||
public Vector3 GroundCast() {
|
||||
RaycastHit Hit;
|
||||
|
@ -12,11 +12,13 @@ namespace NeonTea.Quakeball.Player {
|
||||
|
||||
public void QueuePacket(PlayerUpdatePckt packet) {
|
||||
if (QueuedPckt != null) {
|
||||
// Re-sync?
|
||||
ProcessPacket(ref QueuedPckt);
|
||||
string Warning = "Can't keep up! Got another packet while one was still in queue, fast-forwarding (and probably desyncing)!";
|
||||
Debug.LogWarning(Warning);
|
||||
Terminal.Singleton.Println($"<color={Terminal.ERROR_COLOR}>{Warning}</color>");
|
||||
|
||||
// Re-sync?
|
||||
Player.ProcessPacket(ref QueuedPckt);
|
||||
LastUpdateTime = Time.time;
|
||||
}
|
||||
QueuedPckt = packet;
|
||||
}
|
||||
@ -27,18 +29,9 @@ namespace NeonTea.Quakeball.Player {
|
||||
|
||||
private void Update() {
|
||||
if (Time.time - LastUpdateTime >= 1f / Player.UpdateFrequency && QueuedPckt != null) {
|
||||
ProcessPacket(ref QueuedPckt);
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessPacket(ref PlayerUpdatePckt packet) {
|
||||
Player.Pitch = packet.Pitch;
|
||||
Player.Yaw = packet.Yaw;
|
||||
Player.MoveDirection = packet.MoveDirection;
|
||||
Player.CurrentMoveStyle = packet.MoveStyle;
|
||||
Player.Jumping = packet.Jumping;
|
||||
Player.ProcessPacket(ref QueuedPckt);
|
||||
LastUpdateTime = Time.time;
|
||||
packet = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user