Add SyncPckt part 1
This commit is contained in:
parent
c9a57b0709
commit
c37b0b22f0
@ -79,6 +79,9 @@ namespace NeonTea.Quakeball.Networking.Instances {
|
|||||||
} else if (packet is PlayerJumpPckt) {
|
} else if (packet is PlayerJumpPckt) {
|
||||||
PlayerJumpPckt jump = (PlayerJumpPckt)packet;
|
PlayerJumpPckt jump = (PlayerJumpPckt)packet;
|
||||||
Players[jump.PlayerId].Controlled.Jump();
|
Players[jump.PlayerId].Controlled.Jump();
|
||||||
|
} else if (packet is PlayerSyncPacket) {
|
||||||
|
PlayerSyncPacket sync = (PlayerSyncPacket)packet;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,5 +105,12 @@ namespace NeonTea.Quakeball.Networking.Instances {
|
|||||||
Peer.SendReliable(Server.uid, jump);
|
Peer.SendReliable(Server.uid, jump);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void SendPlayerSync() {
|
||||||
|
if (SelfIdentified && Server != null) {
|
||||||
|
PlayerSyncPacket packet; // Get the sync packet for LocalPlayer
|
||||||
|
// SendUnreliable(Server.uid, packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,6 +19,7 @@ namespace NeonTea.Quakeball.Networking.Instances {
|
|||||||
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 SendPlayerSync();
|
||||||
public abstract void LocalPlayerJump();
|
public abstract void LocalPlayerJump();
|
||||||
|
|
||||||
public void Stop() {
|
public void Stop() {
|
||||||
|
@ -88,9 +88,21 @@ namespace NeonTea.Quakeball.Networking.Instances {
|
|||||||
SendReliableToAll(jump);
|
SendReliableToAll(jump);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (packet is PlayerSyncPacket) {
|
||||||
|
PlayerSyncPacket sync = (PlayerSyncPacket)packet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AddPlayer(NetPlayer player) {
|
||||||
|
Players.Add(player.Id, player);
|
||||||
|
PlayerList.Add(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RemovePlayer(NetPlayer player) {
|
||||||
|
Players.Remove(player.Id);
|
||||||
|
PlayerList.Remove(player);
|
||||||
|
}
|
||||||
|
|
||||||
public void SendReliableToAll(Packet packet, ulong except = ulong.MaxValue) {
|
public void SendReliableToAll(Packet packet, ulong except = ulong.MaxValue) {
|
||||||
foreach (NetPlayer p in Players.Values) {
|
foreach (NetPlayer p in Players.Values) {
|
||||||
if (p.Id == ulong.MaxValue || p.Id == except) {
|
if (p.Id == ulong.MaxValue || p.Id == except) {
|
||||||
@ -119,14 +131,9 @@ namespace NeonTea.Quakeball.Networking.Instances {
|
|||||||
SendReliableToAll(jump);
|
SendReliableToAll(jump);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddPlayer(NetPlayer player) {
|
public override void SendPlayerSync() {
|
||||||
Players.Add(player.Id, player);
|
MultipleSyncsPckt pckt = new MultipleSyncsPckt(PlayerList);
|
||||||
PlayerList.Add(player);
|
SendUnreliableToAll(pckt);
|
||||||
}
|
|
||||||
|
|
||||||
private void RemovePlayer(NetPlayer player) {
|
|
||||||
Players.Remove(player.Id);
|
|
||||||
PlayerList.Remove(player);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -36,4 +36,37 @@ namespace NeonTea.Quakeball.Networking.Packets {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class MultipleSyncsPckt : Packet {
|
||||||
|
|
||||||
|
public List<PlayerSyncPacket> Updates = new List<PlayerSyncPacket>();
|
||||||
|
|
||||||
|
public MultipleSyncsPckt() { }
|
||||||
|
|
||||||
|
public MultipleSyncsPckt(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++) {
|
||||||
|
PlayerSyncPacket pckt = new PlayerSyncPacket();
|
||||||
|
pckt.Read(buffer);
|
||||||
|
Updates.Add(pckt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Write(ByteBuffer buffer) {
|
||||||
|
buffer.Write(Updates.Count);
|
||||||
|
foreach (PlayerSyncPacket p in Updates) {
|
||||||
|
p.Write(buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user