using UnityEngine; using NeonTea.Quakeball.Net.Packets; using NeonTea.Quakeball.Interface; namespace NeonTea.Quakeball.Player { /// A controller class for a remote player. Gets updates from the network and touches the relevant components. [RequireComponent(typeof(Player))] public class RemotePlayer : MonoBehaviour { private Player Player; private PlayerUpdatePckt QueuedPckt = null; private float LastUpdateTime = -1; public void QueuePacket(PlayerUpdatePckt packet) { if (QueuedPckt != null) { 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($"{Warning}"); // Re-sync? Player.ProcessPacket(ref QueuedPckt); LastUpdateTime = Time.time; } QueuedPckt = packet; } private void Awake() { Player = GetComponent(); } private void Update() { if (Time.time - LastUpdateTime >= 1f / Player.UpdateFrequency && QueuedPckt != null) { Player.ProcessPacket(ref QueuedPckt); LastUpdateTime = Time.time; } } } }