2020-08-07 02:45:29 +02:00
|
|
|
|
using UnityEngine;
|
2020-08-07 20:20:13 +02:00
|
|
|
|
using NeonTea.Quakeball.Networking.Packets;
|
2020-08-07 02:45:29 +02:00
|
|
|
|
using NeonTea.Quakeball.Interface;
|
|
|
|
|
|
2020-08-07 20:23:21 +02:00
|
|
|
|
namespace NeonTea.Quakeball.Players {
|
2020-08-07 02:45:29 +02:00
|
|
|
|
/// <summary>A controller class for a remote player. Gets updates from the network and touches the relevant components.</summary>
|
|
|
|
|
[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($"<color={Terminal.ERROR_COLOR}>{Warning}</color>");
|
2020-08-07 20:12:53 +02:00
|
|
|
|
|
|
|
|
|
// Re-sync?
|
|
|
|
|
Player.ProcessPacket(ref QueuedPckt);
|
|
|
|
|
LastUpdateTime = Time.time;
|
2020-08-07 02:45:29 +02:00
|
|
|
|
}
|
|
|
|
|
QueuedPckt = packet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Awake() {
|
|
|
|
|
Player = GetComponent<Player>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Update() {
|
2020-08-07 04:42:12 +02:00
|
|
|
|
if (Time.time - LastUpdateTime >= 1f / Player.UpdateFrequency && QueuedPckt != null) {
|
2020-08-07 20:12:53 +02:00
|
|
|
|
Player.ProcessPacket(ref QueuedPckt);
|
|
|
|
|
LastUpdateTime = Time.time;
|
2020-08-07 02:45:29 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|