Add PlayerSyncPckt

This commit is contained in:
Sofia 2020-08-08 00:47:03 +03:00
parent a0b286cbd6
commit c9a57b0709
3 changed files with 41 additions and 7 deletions

View File

@ -23,6 +23,7 @@ namespace NeonTea.Quakeball.Networking {
RegisterPacket(typeof(MultiplePlayerUpdatesPckt));
RegisterPacket(typeof(PlayerUpdatePckt));
RegisterPacket(typeof(PlayerJumpPckt));
RegisterPacket(typeof(PlayerSyncPacket));
}
public override void ConnectionStatusChanged(ConnectionStatus oldStatus, ConnectionStatus newStatus, Connection conn) {

View File

@ -1,6 +1,7 @@
using UnityEngine;
using NeonTea.Quakeball.Networking.Instances;
using NeonTea.Quakeball.TeaNet.Peers;
using NeonTea.Quakeball.TeaNet.Packets;
using System.Collections.Generic;
namespace NeonTea.Quakeball.Networking {
@ -31,4 +32,22 @@ namespace NeonTea.Quakeball.Networking {
Application.quitting += Quit;
}
}
public static class ByteBufferExtensions {
/// <summary>Extension: Reads Vector3</summary>
public static Vector3 ReadVector3(this ByteBuffer buffer) {
float x = buffer.ReadFloat();
float y = buffer.ReadFloat();
float z = buffer.ReadFloat();
return new Vector3(x, y, z);
}
/// <summary>Extension: Writes Vector3</summary>
public static void Write(this ByteBuffer buffer, Vector3 vector) {
buffer.Write(vector.x);
buffer.Write(vector.y);
buffer.Write(vector.z);
}
}
}

View File

@ -23,10 +23,7 @@ namespace NeonTea.Quakeball.Networking.Packets {
public override void Read(ByteBuffer buffer) {
PlayerId = buffer.ReadULong();
float x = buffer.ReadFloat();
float y = buffer.ReadFloat();
float z = buffer.ReadFloat();
MoveDirection = new Vector3(x, y, z);
MoveDirection = buffer.ReadVector3();
MoveStyle = buffer.Read();
Pitch = buffer.ReadFloat();
Yaw = buffer.ReadFloat();
@ -34,9 +31,7 @@ namespace NeonTea.Quakeball.Networking.Packets {
public override void Write(ByteBuffer buffer) {
buffer.Write(PlayerId);
buffer.Write(MoveDirection.x);
buffer.Write(MoveDirection.y);
buffer.Write(MoveDirection.z);
buffer.Write(MoveDirection);
buffer.Write(MoveStyle);
buffer.Write(Pitch);
buffer.Write(Yaw);
@ -57,4 +52,23 @@ namespace NeonTea.Quakeball.Networking.Packets {
buffer.Write(PlayerId);
}
}
public class PlayerSyncPacket : Packet {
public ulong PlayerId;
public Vector3 Location;
public Vector3 GroundVelocity;
public override void Read(ByteBuffer buffer) {
PlayerId = buffer.ReadULong();
Location = buffer.ReadVector3();
GroundVelocity = buffer.ReadVector3();
}
public override void Write(ByteBuffer buffer) {
buffer.ReadULong();
buffer.Write(Location);
buffer.Write(GroundVelocity);
}
}
}