diff --git a/Assets/Scripts/Game/GameMaster.cs b/Assets/Scripts/Game/GameMaster.cs index 4bae873..74dcf11 100644 --- a/Assets/Scripts/Game/GameMaster.cs +++ b/Assets/Scripts/Game/GameMaster.cs @@ -26,13 +26,13 @@ namespace NeonTea.Quakeball.Game { Team team = Team.FreeForAll; if (GameMode == GameMode.TeamPlay) { if (Players[Team.Sun].Count > Players[Team.Moon].Count) { - team = Team.Sun; - } else { team = Team.Moon; + } else { + team = Team.Sun; } } - Players[Team.Sun].Add(player.Id); player.Team = team; + Players[player.Team].Add(player.Id); Terminal.Singleton.Println($"Put {player.Nick} to Team {player.Team}"); } diff --git a/Assets/Scripts/Networking/Instances/Client.cs b/Assets/Scripts/Networking/Instances/Client.cs index 7d3d2da..a309ae5 100644 --- a/Assets/Scripts/Networking/Instances/Client.cs +++ b/Assets/Scripts/Networking/Instances/Client.cs @@ -23,7 +23,7 @@ namespace NeonTea.Quakeball.Networking.Instances { public Client() { Net = GameObject.FindGameObjectWithTag("Net").GetComponent(); - LocalPlayer = new NetPlayer(ulong.MaxValue - 1); + LocalPlayer = new NetPlayer(ulong.MaxValue - 1, false); LocalPlayer.Controlled = GameObject.FindGameObjectWithTag("Player").GetComponent(); } @@ -87,6 +87,7 @@ namespace NeonTea.Quakeball.Networking.Instances { LocalPlayer.Controlled.NetId = LocalPlayer.Id; AddPlayer(LocalPlayer); SelfIdentified = true; + LocalPlayer.Ready = true; NicknamePckt nickpckt = new NicknamePckt(LocalPlayer.Nick); Peer.SendReliableLater(Server.uid, nickpckt); @@ -114,15 +115,16 @@ namespace NeonTea.Quakeball.Networking.Instances { } } else if (packet is PlayerInitPckt) { PlayerInitPckt init = (PlayerInitPckt)packet; - if (Players.ContainsKey(conn.uid)) { + if (Players.ContainsKey(init.PlayerId)) { return; // Got the same init twice } - NetPlayer player = new NetPlayer(init.PlayerId); + NetPlayer player = new NetPlayer(init.PlayerId, true); player.Nick = init.NicknamePckt.Nick; player.Team = init.Team; Player obj = Net.SpawnPlayer(init.SpawnPckt.Location).GetComponent(); player.Controlled = obj; AddPlayer(player); + Debug.Log("Added player" + player.Nick); } else if (packet is DeadPckt) { DeadPckt dead = (DeadPckt)packet; if (Players.ContainsKey(dead.DeadPlayerId)) { @@ -173,14 +175,14 @@ namespace NeonTea.Quakeball.Networking.Instances { } private void HandleUpdatePlayer(PlayerUpdatePckt pckt) { - if (pckt.PlayerId == LocalPlayer.Id && Players[pckt.PlayerId] != null) { + if (pckt.PlayerId == LocalPlayer.Id || !Players.ContainsKey(pckt.PlayerId)) { return; // Ignore, again. } Players[pckt.PlayerId].Controlled.ProcessUpdatePacket(pckt); } private void HandleSyncPckt(PlayerSyncPacket syncPckt) { - if (Players[syncPckt.PlayerId] != null && (syncPckt.Unsynced || syncPckt.PlayerId != LocalPlayer.Id)) { + if (Players.ContainsKey(syncPckt.PlayerId) && (syncPckt.Unsynced || syncPckt.PlayerId != LocalPlayer.Id)) { Players[syncPckt.PlayerId].Controlled.ProcessSyncPacket(syncPckt); } } diff --git a/Assets/Scripts/Networking/Instances/Server.cs b/Assets/Scripts/Networking/Instances/Server.cs index b763419..9ed5df2 100644 --- a/Assets/Scripts/Networking/Instances/Server.cs +++ b/Assets/Scripts/Networking/Instances/Server.cs @@ -22,7 +22,7 @@ namespace NeonTea.Quakeball.Networking.Instances { public GameMaster GameMaster; public Server() { - LocalPlayer = new NetPlayer(ulong.MaxValue); + LocalPlayer = new NetPlayer(ulong.MaxValue, true); } public override void Start(string address, int port, string nick, PeerMessageListener listener) { @@ -63,7 +63,7 @@ namespace NeonTea.Quakeball.Networking.Instances { Terminal.Singleton.Println($"{conn.uid} Connected"); foreach (NetPlayer p in Players.Values) { - if (p.Controlled == null) { // Not yet initialized, sending later. + if (!IsReady(p.Id)) { // Not yet ready, sending later. continue; } @@ -72,7 +72,7 @@ namespace NeonTea.Quakeball.Networking.Instances { PlayerInitPckt init = new PlayerInitPckt(p.Id, p.Team, nick, spawn); Peer.SendReliableLater(conn.uid, init); } - NetPlayer RemotePlayer = new NetPlayer(PlayerIdCounter++); + NetPlayer RemotePlayer = new NetPlayer(PlayerIdCounter++, false); GameMaster.PlayerJoined(RemotePlayer); AddPlayer(RemotePlayer); @@ -91,15 +91,17 @@ namespace NeonTea.Quakeball.Networking.Instances { } public void PlayerJoined(NetPlayer player) { + player.Ready = true; NicknamePckt nick = new NicknamePckt(player.Nick, player.Id); SpawnPckt spawn = new SpawnPckt(player.Controlled.transform.position, player.Id); PlayerInitPckt init = new PlayerInitPckt(player.Id, player.Team, nick, spawn); - SendReliableToAll(init, except: spawn.PlayerId); + Debug.Log("Sending init: " + player.Id); + SendReliableToAll(init, except: player.Id); } public override void Handle(Connection conn, Packet packet) { if (packet is ReadyPckt) { - if (Players[conn.uid].Controlled == null) { + if (!IsReady(conn.uid)) { NetPlayer player = Players[conn.uid]; Player obj = Net.SpawnPlayer(GameMaster.GetSpawn(player)).GetComponent(); player.Controlled = obj; @@ -113,7 +115,9 @@ namespace NeonTea.Quakeball.Networking.Instances { NicknamePckt nick = (NicknamePckt)packet; Players[conn.uid].Nick = nick.Nick; nick.PlayerId = conn.uid; - SendReliableToAll(nick); + if (IsReady(conn.uid)) { + SendReliableToAll(nick); + } } else if (packet is PlayerUpdatePckt) { PlayerUpdatePckt updatePckt = (PlayerUpdatePckt)packet; HandleUpdatePckt(conn.uid, updatePckt); @@ -211,6 +215,10 @@ namespace NeonTea.Quakeball.Networking.Instances { } } + public bool IsReady(ulong uid) { + return Players.ContainsKey(uid) && Players[uid].ReadyAndSpawned; + } + public override void UpdateLocalPlayer() { MultiplePlayerUpdatesPckt pckt = new MultiplePlayerUpdatesPckt(PlayerList); SendUnreliableToAll(pckt); diff --git a/Assets/Scripts/Networking/NetPlayer.cs b/Assets/Scripts/Networking/NetPlayer.cs index 5eb12cf..489730f 100644 --- a/Assets/Scripts/Networking/NetPlayer.cs +++ b/Assets/Scripts/Networking/NetPlayer.cs @@ -27,12 +27,17 @@ namespace NeonTea.Quakeball.Networking { } public string Nick; public Team Team = Team.FreeForAll; + + public bool Ready; + public bool ReadyAndSpawned => Ready && _Controlled != null; + public bool Unsynced = false; public float Ping = 0; - public NetPlayer(ulong id, Player obj = null) { + public NetPlayer(ulong id, bool ready, Player obj = null) { Id = id; Controlled = obj; + Ready = ready; Nick = id.ToString(); } } diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index fe06517..20bd559 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -96,7 +96,8 @@ "depth": 0, "source": "builtin", "dependencies": { - "com.unity.modules.ui": "1.0.0" + "com.unity.modules.ui": "1.0.0", + "com.unity.modules.imgui": "1.0.0" } }, "com.unity.modules.ai": { diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index a77d016..d90503f 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -115,6 +115,8 @@ PlayerSettings: switchNVNShaderPoolsGranularity: 33554432 switchNVNDefaultPoolsGranularity: 16777216 switchNVNOtherPoolsGranularity: 16777216 + switchNVNMaxPublicTextureIDCount: 0 + switchNVNMaxPublicSamplerIDCount: 0 stadiaPresentMode: 0 stadiaTargetFramerate: 0 vulkanNumSwapchainBuffers: 3 @@ -517,6 +519,7 @@ PlayerSettings: ps4ShareFilePath: ps4ShareOverlayImagePath: ps4PrivacyGuardImagePath: + ps4ExtraSceSysFile: ps4NPtitleDatPath: ps4RemotePlayKeyAssignment: -1 ps4RemotePlayKeyMappingDir: @@ -559,6 +562,8 @@ PlayerSettings: ps4disableAutoHideSplash: 0 ps4videoRecordingFeaturesUsed: 0 ps4contentSearchFeaturesUsed: 0 + ps4CompatibilityPS5: 0 + ps4GPU800MHz: 1 ps4attribEyeToEyeDistanceSettingVR: 0 ps4IncludedModules: [] ps4attribVROutputEnabled: 0 diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index e18cabd..15f2dbb 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 2020.1.0f1 -m_EditorVersionWithRevision: 2020.1.0f1 (2ab9c4179772) +m_EditorVersion: 2020.1.2f1 +m_EditorVersionWithRevision: 2020.1.2f1 (7b32bc54ba47)