Separate Jump from regular update
This commit is contained in:
parent
92165cebc2
commit
c3ff626980
@ -22,6 +22,7 @@ namespace NeonTea.Quakeball.Networking {
|
|||||||
RegisterPacket(typeof(SelfIdentPckt));
|
RegisterPacket(typeof(SelfIdentPckt));
|
||||||
RegisterPacket(typeof(MultiplePlayerUpdatesPckt));
|
RegisterPacket(typeof(MultiplePlayerUpdatesPckt));
|
||||||
RegisterPacket(typeof(PlayerUpdatePckt));
|
RegisterPacket(typeof(PlayerUpdatePckt));
|
||||||
|
RegisterPacket(typeof(PlayerJumpPckt));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ConnectionStatusChanged(ConnectionStatus oldStatus, ConnectionStatus newStatus, Connection conn) {
|
public override void ConnectionStatusChanged(ConnectionStatus oldStatus, ConnectionStatus newStatus, Connection conn) {
|
||||||
|
@ -76,13 +76,9 @@ namespace NeonTea.Quakeball.Networking.Instances {
|
|||||||
foreach (PlayerUpdatePckt pckt in multiple.Updates) {
|
foreach (PlayerUpdatePckt pckt in multiple.Updates) {
|
||||||
HandleUpdatePlayer(pckt);
|
HandleUpdatePlayer(pckt);
|
||||||
}
|
}
|
||||||
}
|
} else if (packet is PlayerJumpPckt) {
|
||||||
}
|
PlayerJumpPckt jump = (PlayerJumpPckt)packet;
|
||||||
|
// Jump!
|
||||||
public override void UpdateLocalPlayer() {
|
|
||||||
if (SelfIdentified && Server != null) {
|
|
||||||
PlayerUpdatePckt pckt = LocalPlayer.Controlled.CreatePacket();
|
|
||||||
Peer.SendUnreliable(Server.uid, pckt);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,5 +88,19 @@ namespace NeonTea.Quakeball.Networking.Instances {
|
|||||||
}
|
}
|
||||||
Players[pckt.PlayerId].Controlled.GetComponent<RemotePlayer>().QueuePacket(pckt);
|
Players[pckt.PlayerId].Controlled.GetComponent<RemotePlayer>().QueuePacket(pckt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void UpdateLocalPlayer() {
|
||||||
|
if (SelfIdentified && Server != null) {
|
||||||
|
PlayerUpdatePckt pckt = LocalPlayer.Controlled.CreatePacket();
|
||||||
|
Peer.SendUnreliable(Server.uid, pckt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void LocalPlayerJump() {
|
||||||
|
if (SelfIdentified && Server != null) {
|
||||||
|
PlayerJumpPckt jump = new PlayerJumpPckt();
|
||||||
|
Peer.SendReliable(Server.uid, jump);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,7 +17,9 @@ namespace NeonTea.Quakeball.Networking.Instances {
|
|||||||
public abstract void Connected(Connection conn);
|
public abstract void Connected(Connection conn);
|
||||||
public abstract void Disconnected(Connection conn);
|
public abstract void Disconnected(Connection conn);
|
||||||
public abstract void Handle(Connection conn, Packet packet);
|
public abstract void Handle(Connection conn, Packet packet);
|
||||||
|
|
||||||
public abstract void UpdateLocalPlayer();
|
public abstract void UpdateLocalPlayer();
|
||||||
|
public abstract void LocalPlayerJump();
|
||||||
|
|
||||||
public void Stop() {
|
public void Stop() {
|
||||||
if (Peer != null) {
|
if (Peer != null) {
|
||||||
|
@ -80,6 +80,13 @@ namespace NeonTea.Quakeball.Networking.Instances {
|
|||||||
updatePckt.PlayerId = conn.uid;
|
updatePckt.PlayerId = conn.uid;
|
||||||
Players[conn.uid].Controlled.GetComponent<RemotePlayer>().QueuePacket(updatePckt);
|
Players[conn.uid].Controlled.GetComponent<RemotePlayer>().QueuePacket(updatePckt);
|
||||||
}
|
}
|
||||||
|
} else if (packet is PlayerJumpPckt) {
|
||||||
|
PlayerJumpPckt jump = (PlayerJumpPckt)packet;
|
||||||
|
if (Players[conn.uid].Controlled != null) {
|
||||||
|
// Check if Players[conn.uid].Controlled can jump, and do the following if true
|
||||||
|
jump.PlayerId = conn.uid;
|
||||||
|
SendReliableToAll(jump);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,6 +113,11 @@ namespace NeonTea.Quakeball.Networking.Instances {
|
|||||||
SendUnreliableToAll(pckt);
|
SendUnreliableToAll(pckt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void LocalPlayerJump() {
|
||||||
|
PlayerJumpPckt jump = new PlayerJumpPckt(LocalPlayer.Id);
|
||||||
|
SendReliableToAll(jump);
|
||||||
|
}
|
||||||
|
|
||||||
private void AddPlayer(NetPlayer player) {
|
private void AddPlayer(NetPlayer player) {
|
||||||
Players.Add(player.Id, player);
|
Players.Add(player.Id, player);
|
||||||
PlayerList.Add(player);
|
PlayerList.Add(player);
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using NeonTea.Quakeball.TeaNet.Packets;
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace NeonTea.Quakeball.Networking.Packets {
|
||||||
|
public class MultiplePlayerUpdatesPckt : Packet {
|
||||||
|
|
||||||
|
public List<PlayerUpdatePckt> Updates = new List<PlayerUpdatePckt>();
|
||||||
|
|
||||||
|
public MultiplePlayerUpdatesPckt() { }
|
||||||
|
|
||||||
|
public MultiplePlayerUpdatesPckt(List<NetPlayer> players) {
|
||||||
|
foreach (NetPlayer p in players) {
|
||||||
|
if (p.Controlled == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Updates.Add(p.Controlled.CreatePacket(p.Id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Read(ByteBuffer buffer) {
|
||||||
|
Updates.Clear();
|
||||||
|
int count = buffer.ReadInt();
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
PlayerUpdatePckt pckt = new PlayerUpdatePckt();
|
||||||
|
pckt.Read(buffer);
|
||||||
|
Updates.Add(pckt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Write(ByteBuffer buffer) {
|
||||||
|
buffer.Write(Updates.Count);
|
||||||
|
foreach (PlayerUpdatePckt p in Updates) {
|
||||||
|
p.Write(buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 505fbc702b619804a8ab46b6211db974
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -1,59 +1,21 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using NeonTea.Quakeball.TeaNet.Packets;
|
using NeonTea.Quakeball.TeaNet.Packets;
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using NeonTea.Quakeball.Networking;
|
|
||||||
|
|
||||||
namespace NeonTea.Quakeball.Networking.Packets {
|
namespace NeonTea.Quakeball.Networking.Packets {
|
||||||
public class MultiplePlayerUpdatesPckt : Packet {
|
|
||||||
|
|
||||||
public List<PlayerUpdatePckt> Updates = new List<PlayerUpdatePckt>();
|
|
||||||
|
|
||||||
public MultiplePlayerUpdatesPckt() { }
|
|
||||||
|
|
||||||
public MultiplePlayerUpdatesPckt(List<NetPlayer> players) {
|
|
||||||
foreach (NetPlayer p in players) {
|
|
||||||
if (p.Controlled == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Updates.Add(p.Controlled.CreatePacket(p.Id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Read(ByteBuffer buffer) {
|
|
||||||
Updates.Clear();
|
|
||||||
int count = buffer.ReadInt();
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
PlayerUpdatePckt pckt = new PlayerUpdatePckt();
|
|
||||||
pckt.Read(buffer);
|
|
||||||
Updates.Add(pckt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Write(ByteBuffer buffer) {
|
|
||||||
buffer.Write(Updates.Count);
|
|
||||||
foreach (PlayerUpdatePckt p in Updates) {
|
|
||||||
p.Write(buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class PlayerUpdatePckt : Packet {
|
public class PlayerUpdatePckt : Packet {
|
||||||
|
|
||||||
public ulong PlayerId;
|
public ulong PlayerId;
|
||||||
|
|
||||||
public Vector3 MoveDirection;
|
public Vector3 MoveDirection;
|
||||||
public byte MoveStyle;
|
public byte MoveStyle;
|
||||||
public bool Jumping;
|
|
||||||
public float Pitch;
|
public float Pitch;
|
||||||
public float Yaw;
|
public float Yaw;
|
||||||
|
|
||||||
public PlayerUpdatePckt() { }
|
public PlayerUpdatePckt() { }
|
||||||
|
|
||||||
public PlayerUpdatePckt(Vector3 moveDirection, byte moveStyle, bool jumping, float pitch, float yaw, ulong id = 0) {
|
public PlayerUpdatePckt(Vector3 moveDirection, byte moveStyle, float pitch, float yaw, ulong id = 0) {
|
||||||
MoveDirection = moveDirection;
|
MoveDirection = moveDirection;
|
||||||
MoveStyle = moveStyle;
|
MoveStyle = moveStyle;
|
||||||
Jumping = jumping;
|
|
||||||
Pitch = pitch;
|
Pitch = pitch;
|
||||||
Yaw = yaw;
|
Yaw = yaw;
|
||||||
PlayerId = id;
|
PlayerId = id;
|
||||||
@ -66,7 +28,6 @@ namespace NeonTea.Quakeball.Networking.Packets {
|
|||||||
float z = buffer.ReadFloat();
|
float z = buffer.ReadFloat();
|
||||||
MoveDirection = new Vector3(x, y, z);
|
MoveDirection = new Vector3(x, y, z);
|
||||||
MoveStyle = buffer.Read();
|
MoveStyle = buffer.Read();
|
||||||
Jumping = buffer.ReadBool();
|
|
||||||
Pitch = buffer.ReadFloat();
|
Pitch = buffer.ReadFloat();
|
||||||
Yaw = buffer.ReadFloat();
|
Yaw = buffer.ReadFloat();
|
||||||
}
|
}
|
||||||
@ -77,9 +38,23 @@ namespace NeonTea.Quakeball.Networking.Packets {
|
|||||||
buffer.Write(MoveDirection.y);
|
buffer.Write(MoveDirection.y);
|
||||||
buffer.Write(MoveDirection.z);
|
buffer.Write(MoveDirection.z);
|
||||||
buffer.Write(MoveStyle);
|
buffer.Write(MoveStyle);
|
||||||
buffer.Write(Jumping);
|
|
||||||
buffer.Write(Pitch);
|
buffer.Write(Pitch);
|
||||||
buffer.Write(Yaw);
|
buffer.Write(Yaw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class PlayerJumpPckt : Packet {
|
||||||
|
public ulong PlayerId;
|
||||||
|
|
||||||
|
public PlayerJumpPckt() { }
|
||||||
|
public PlayerJumpPckt(ulong id) { PlayerId = id; }
|
||||||
|
|
||||||
|
public override void Read(ByteBuffer buffer) {
|
||||||
|
PlayerId = buffer.ReadULong();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Write(ByteBuffer buffer) {
|
||||||
|
buffer.Write(PlayerId);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ namespace NeonTea.Quakeball.Players {
|
|||||||
|
|
||||||
/// <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 CreatePacket(ulong id = 0) {
|
||||||
return new PlayerUpdatePckt(MoveDirection, CurrentMoveStyle, Jumping, 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>
|
||||||
@ -74,7 +74,6 @@ namespace NeonTea.Quakeball.Players {
|
|||||||
Yaw = packet.Yaw;
|
Yaw = packet.Yaw;
|
||||||
MoveDirection = packet.MoveDirection;
|
MoveDirection = packet.MoveDirection;
|
||||||
CurrentMoveStyle = packet.MoveStyle;
|
CurrentMoveStyle = packet.MoveStyle;
|
||||||
Jumping = packet.Jumping;
|
|
||||||
packet = null;
|
packet = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user