Implement player sync packet
This commit is contained in:
parent
c37b0b22f0
commit
6f0ff60952
@ -89,12 +89,12 @@ namespace NeonTea.Quakeball.Networking.Instances {
|
|||||||
if (pckt.PlayerId == LocalPlayer.Id) {
|
if (pckt.PlayerId == LocalPlayer.Id) {
|
||||||
return; // Ignore, again.
|
return; // Ignore, again.
|
||||||
}
|
}
|
||||||
Players[pckt.PlayerId].Controlled.ProcessPacket(ref pckt);
|
Players[pckt.PlayerId].Controlled.ProcessUpdatePacket(ref pckt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void UpdateLocalPlayer() {
|
public override void UpdateLocalPlayer() {
|
||||||
if (SelfIdentified && Server != null) {
|
if (SelfIdentified && Server != null) {
|
||||||
PlayerUpdatePckt pckt = LocalPlayer.Controlled.CreatePacket();
|
PlayerUpdatePckt pckt = LocalPlayer.Controlled.CreateUpdatePacket();
|
||||||
Peer.SendUnreliable(Server.uid, pckt);
|
Peer.SendUnreliable(Server.uid, pckt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ namespace NeonTea.Quakeball.Networking.Instances {
|
|||||||
PlayerUpdatePckt updatePckt = (PlayerUpdatePckt)packet;
|
PlayerUpdatePckt updatePckt = (PlayerUpdatePckt)packet;
|
||||||
if (Players[conn.uid].Controlled != null) {
|
if (Players[conn.uid].Controlled != null) {
|
||||||
updatePckt.PlayerId = conn.uid;
|
updatePckt.PlayerId = conn.uid;
|
||||||
Players[conn.uid].Controlled.ProcessPacket(ref updatePckt);
|
Players[conn.uid].Controlled.ProcessUpdatePacket(ref updatePckt);
|
||||||
}
|
}
|
||||||
} else if (packet is PlayerJumpPckt) {
|
} else if (packet is PlayerJumpPckt) {
|
||||||
PlayerJumpPckt jump = (PlayerJumpPckt)packet;
|
PlayerJumpPckt jump = (PlayerJumpPckt)packet;
|
||||||
|
@ -15,7 +15,7 @@ namespace NeonTea.Quakeball.Networking.Packets {
|
|||||||
if (p.Controlled == null) {
|
if (p.Controlled == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Updates.Add(p.Controlled.CreatePacket(p.Id));
|
Updates.Add(p.Controlled.CreateUpdatePacket(p.Id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +59,13 @@ namespace NeonTea.Quakeball.Networking.Packets {
|
|||||||
public Vector3 Location;
|
public Vector3 Location;
|
||||||
public Vector3 GroundVelocity;
|
public Vector3 GroundVelocity;
|
||||||
|
|
||||||
|
public PlayerSyncPacket() { }
|
||||||
|
public PlayerSyncPacket(ulong id, Vector3 location, Vector3 groundVelocity) {
|
||||||
|
PlayerId = id;
|
||||||
|
Location = location;
|
||||||
|
GroundVelocity = groundVelocity;
|
||||||
|
}
|
||||||
|
|
||||||
public override void Read(ByteBuffer buffer) {
|
public override void Read(ByteBuffer buffer) {
|
||||||
PlayerId = buffer.ReadULong();
|
PlayerId = buffer.ReadULong();
|
||||||
Location = buffer.ReadVector3();
|
Location = buffer.ReadVector3();
|
||||||
|
@ -9,6 +9,7 @@ namespace NeonTea.Quakeball.Players {
|
|||||||
public class LocalPlayer : MonoBehaviour {
|
public class LocalPlayer : MonoBehaviour {
|
||||||
public Transform Camera;
|
public Transform Camera;
|
||||||
public bool DisableInput = false;
|
public bool DisableInput = false;
|
||||||
|
public float FullSyncFrequency = 1;
|
||||||
|
|
||||||
private float Lean = 0;
|
private float Lean = 0;
|
||||||
|
|
||||||
@ -19,6 +20,7 @@ namespace NeonTea.Quakeball.Players {
|
|||||||
private InputAction JumpAction;
|
private InputAction JumpAction;
|
||||||
|
|
||||||
private float PreviousPlayerUpdate = -1;
|
private float PreviousPlayerUpdate = -1;
|
||||||
|
private float PreviousPlayerFullSync = -1;
|
||||||
private bool WantsToJump = false;
|
private bool WantsToJump = false;
|
||||||
|
|
||||||
private void Awake() {
|
private void Awake() {
|
||||||
@ -87,6 +89,11 @@ namespace NeonTea.Quakeball.Players {
|
|||||||
}
|
}
|
||||||
WantsToJump = false;
|
WantsToJump = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Time.time - PreviousPlayerFullSync >= 1f / FullSyncFrequency) {
|
||||||
|
FullSyncFrequency = Time.time;
|
||||||
|
// TODO: Create and send the packet
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,12 +61,12 @@ namespace NeonTea.Quakeball.Players {
|
|||||||
private Vector3 FeetPosition;
|
private Vector3 FeetPosition;
|
||||||
|
|
||||||
/// <summary>Creates a PlayerUpdatePckt representing this Player's current status, for sending to other peers.</summary>
|
/// <summary>Creates a PlayerUpdatePckt representing this Player's current status, for sending to other peers.</summary>
|
||||||
public PlayerUpdatePckt CreatePacket(ulong id = 0) {
|
public PlayerUpdatePckt CreateUpdatePacket(ulong id = 0) {
|
||||||
return new PlayerUpdatePckt(MoveDirection, CurrentMoveStyle, Pitch, Yaw, id);
|
return new PlayerUpdatePckt(MoveDirection, CurrentMoveStyle, Pitch, Yaw, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Updates this Player with the given packet, and sets it to null. No reusing packets.</summary>
|
/// <summary>Updates this Player with the given packet, and sets it to null. No reusing packets.</summary>
|
||||||
public void ProcessPacket(ref PlayerUpdatePckt packet) {
|
public void ProcessUpdatePacket(ref PlayerUpdatePckt packet) {
|
||||||
Pitch = packet.Pitch;
|
Pitch = packet.Pitch;
|
||||||
Yaw = packet.Yaw;
|
Yaw = packet.Yaw;
|
||||||
MoveDirection = packet.MoveDirection;
|
MoveDirection = packet.MoveDirection;
|
||||||
@ -74,6 +74,15 @@ namespace NeonTea.Quakeball.Players {
|
|||||||
packet = null;
|
packet = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Creates a PlayerSyncPacket representing this Player's position and velocity, for sending to the server</summary>
|
||||||
|
public PlayerSyncPacket CreateSyncPacket(ulong id = 0) {
|
||||||
|
return new PlayerSyncPacket(id, transform.position, GroundVelocity);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Creates a PlayerSyncPacket representing this Player's position and velocity, for sending to the server</summary>
|
||||||
|
public void ProcessSyncPacket(PlayerSyncPacket syncPckt) {
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>The normal of the ground below the player. If there is no ground, it's <c>Vector3.up</c> by default.</summary>
|
/// <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() {
|
public Vector3 GroundCast() {
|
||||||
RaycastHit Hit;
|
RaycastHit Hit;
|
||||||
|
Loading…
Reference in New Issue
Block a user