Commit the last half of the previous commit

This commit is contained in:
Jens Pitkänen 2020-08-08 01:15:33 +03:00
parent 6f0ff60952
commit 1f001c03b7
5 changed files with 28 additions and 13 deletions

View File

@ -237,6 +237,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
Camera: {fileID: 9173392441446035453}
DisableInput: 0
FullSyncFrequency: 2
--- !u!114 &3508289943927587728
MonoBehaviour:
m_ObjectHideFlags: 0

View File

@ -80,8 +80,8 @@ namespace NeonTea.Quakeball.Networking.Instances {
PlayerJumpPckt jump = (PlayerJumpPckt)packet;
Players[jump.PlayerId].Controlled.Jump();
} else if (packet is PlayerSyncPacket) {
PlayerSyncPacket sync = (PlayerSyncPacket)packet;
PlayerSyncPacket syncPckt = (PlayerSyncPacket)packet;
Players[syncPckt.PlayerId].Controlled.ProcessSyncPacket(syncPckt);
}
}
@ -89,7 +89,7 @@ namespace NeonTea.Quakeball.Networking.Instances {
if (pckt.PlayerId == LocalPlayer.Id) {
return; // Ignore, again.
}
Players[pckt.PlayerId].Controlled.ProcessUpdatePacket(ref pckt);
Players[pckt.PlayerId].Controlled.ProcessUpdatePacket(pckt);
}
public override void UpdateLocalPlayer() {
@ -108,8 +108,8 @@ namespace NeonTea.Quakeball.Networking.Instances {
public override void SendPlayerSync() {
if (SelfIdentified && Server != null) {
PlayerSyncPacket packet; // Get the sync packet for LocalPlayer
// SendUnreliable(Server.uid, packet);
PlayerSyncPacket packet = LocalPlayer.Controlled.CreateSyncPacket();
Peer.SendUnreliable(Server.uid, packet);
}
}
}

View File

@ -78,7 +78,7 @@ namespace NeonTea.Quakeball.Networking.Instances {
PlayerUpdatePckt updatePckt = (PlayerUpdatePckt)packet;
if (Players[conn.uid].Controlled != null) {
updatePckt.PlayerId = conn.uid;
Players[conn.uid].Controlled.ProcessUpdatePacket(ref updatePckt);
Players[conn.uid].Controlled.ProcessUpdatePacket(updatePckt);
}
} else if (packet is PlayerJumpPckt) {
PlayerJumpPckt jump = (PlayerJumpPckt)packet;
@ -89,7 +89,11 @@ namespace NeonTea.Quakeball.Networking.Instances {
}
}
} else if (packet is PlayerSyncPacket) {
PlayerSyncPacket sync = (PlayerSyncPacket)packet;
PlayerSyncPacket syncPckt = (PlayerSyncPacket)packet;
if (Players[conn.uid].Controlled != null) {
syncPckt.PlayerId = conn.uid;
Players[conn.uid].Controlled.ProcessSyncPacket(syncPckt);
}
}
}

View File

@ -92,7 +92,9 @@ namespace NeonTea.Quakeball.Players {
if (Time.time - PreviousPlayerFullSync >= 1f / FullSyncFrequency) {
FullSyncFrequency = Time.time;
// TODO: Create and send the packet
if (Networking.Net.Singleton.Instance != null) {
Networking.Net.Singleton.Instance.SendPlayerSync();
}
}
}
}

View File

@ -65,8 +65,8 @@ namespace NeonTea.Quakeball.Players {
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>
public void ProcessUpdatePacket(ref PlayerUpdatePckt packet) {
/// <summary>Updates this Player with the given packet.</summary>
public void ProcessUpdatePacket(PlayerUpdatePckt packet) {
Pitch = packet.Pitch;
Yaw = packet.Yaw;
MoveDirection = packet.MoveDirection;
@ -74,13 +74,21 @@ namespace NeonTea.Quakeball.Players {
packet = null;
}
/// <summary>Creates a PlayerSyncPacket representing this Player's position and velocity, for sending to the server</summary>
/// <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>Applies the sync packet, checking it for cheatiness if shouldApply is false.</summary>
public void ProcessSyncPacket(PlayerSyncPacket syncPckt, bool shouldApplyWithoutInspection = true) {
bool ShouldApply = shouldApplyWithoutInspection;
if (!shouldApplyWithoutInspection) {
// TODO: Gaze into the crystal ball to determine the nefariousness level of the packet and update ShouldApply accordingly.
}
if (ShouldApply) {
transform.position = syncPckt.Location;
GroundVelocity = syncPckt.Location;
}
}
/// <summary>The normal of the ground below the player. If there is no ground, it's <c>Vector3.up</c> by default.</summary>