From 1fe7736d4d8c069ac8987be213d8de819e6d0d21 Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Wed, 29 May 2024 21:47:55 +0530 Subject: [PATCH] fix part where client loads earlier than host --- src/MarbleWorld.hx | 3 +++ src/net/Net.hx | 3 +++ src/net/NetCommands.hx | 19 +++++++++++-------- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index 0d9683ea..5b0919a7 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -523,6 +523,9 @@ class MarbleWorld extends Scheduler { shape.onLevelStart(); if (this.isMultiplayer && Net.isClient) NetCommands.clientIsReady(Net.clientId); + if (this.isMultiplayer && Net.isHost) { + NetCommands.clientIsReady(-1); + } var cc = 0; for (client in Net.clients) cc++; diff --git a/src/net/Net.hx b/src/net/Net.hx index c6a6eaf1..fc9a11d0 100644 --- a/src/net/Net.hx +++ b/src/net/Net.hx @@ -72,6 +72,7 @@ class Net { public static var lobbyHostReady:Bool; public static var lobbyClientReady:Bool; + public static var hostReady:Bool; public static var clientId:Int; public static var networkRNG:Float; @@ -354,6 +355,7 @@ class Net { Net.remoteServerInfo = null; Net.lobbyHostReady = false; Net.lobbyClientReady = false; + Net.hostReady = false; } if (Net.isHost) { NetCommands.serverClosed(); @@ -371,6 +373,7 @@ class Net { Net.remoteServerInfo = null; Net.lobbyHostReady = false; Net.lobbyClientReady = false; + Net.hostReady = false; } } diff --git a/src/net/NetCommands.hx b/src/net/NetCommands.hx index b93a314d..0d6a1047 100644 --- a/src/net/NetCommands.hx +++ b/src/net/NetCommands.hx @@ -85,7 +85,10 @@ class NetCommands { @:rpc(client) public static function clientIsReady(clientId:Int) { if (Net.isHost) { if (Net.serverInfo.state == "WAITING" && MarbleGame.instance.world != null) { - Net.clientIdMap[clientId].ready(); + if (clientId != -1) + Net.clientIdMap[clientId].ready(); + else + Net.hostReady = true; var allReady = true; for (id => client in Net.clientIdMap) { if (client.state != GameplayState.GAME) { @@ -93,12 +96,10 @@ class NetCommands { break; } } - if (allReady) { + if (allReady && Net.hostReady) { if (MarbleGame.instance.world != null) { MarbleGame.instance.world.allClientsReady(); } - } - if (Net.isHost) { Net.serverInfo.state = "PLAYING"; MasterServerClient.instance.sendServerInfo(Net.serverInfo); // notify the server of the playing state } @@ -147,6 +148,9 @@ class NetCommands { @:rpc(server) public static function setStartTicks(ticks:Int) { if (MarbleGame.instance.world != null) { MarbleGame.instance.world.serverStartTicks = ticks + 1; // Extra tick so we don't get 0 + if (Net.isClient) { + @:privateAccess MarbleGame.instance.world.marble.serverTicks = ticks; + } MarbleGame.instance.world.startTime = MarbleGame.instance.world.timeState.timeSinceLoad + 3.5 + 0.032; // 1 extra tick } } @@ -245,11 +249,10 @@ class NetCommands { } if (Net.isHost) { Net.lobbyHostReady = false; + Net.hostReady = false; - if (Net.isHost) { - Net.serverInfo.state = "LOBBY"; - MasterServerClient.instance.sendServerInfo(Net.serverInfo); // notify the server of the playing state - } + Net.serverInfo.state = "LOBBY"; + MasterServerClient.instance.sendServerInfo(Net.serverInfo); // notify the server of the playing state } }