fix part where client loads earlier than host

This commit is contained in:
RandomityGuy 2024-05-29 21:47:55 +05:30
parent f23c0eb203
commit 1fe7736d4d
3 changed files with 17 additions and 8 deletions

View file

@ -523,6 +523,9 @@ class MarbleWorld extends Scheduler {
shape.onLevelStart(); shape.onLevelStart();
if (this.isMultiplayer && Net.isClient) if (this.isMultiplayer && Net.isClient)
NetCommands.clientIsReady(Net.clientId); NetCommands.clientIsReady(Net.clientId);
if (this.isMultiplayer && Net.isHost) {
NetCommands.clientIsReady(-1);
}
var cc = 0; var cc = 0;
for (client in Net.clients) for (client in Net.clients)
cc++; cc++;

View file

@ -72,6 +72,7 @@ class Net {
public static var lobbyHostReady:Bool; public static var lobbyHostReady:Bool;
public static var lobbyClientReady:Bool; public static var lobbyClientReady:Bool;
public static var hostReady:Bool;
public static var clientId:Int; public static var clientId:Int;
public static var networkRNG:Float; public static var networkRNG:Float;
@ -354,6 +355,7 @@ class Net {
Net.remoteServerInfo = null; Net.remoteServerInfo = null;
Net.lobbyHostReady = false; Net.lobbyHostReady = false;
Net.lobbyClientReady = false; Net.lobbyClientReady = false;
Net.hostReady = false;
} }
if (Net.isHost) { if (Net.isHost) {
NetCommands.serverClosed(); NetCommands.serverClosed();
@ -371,6 +373,7 @@ class Net {
Net.remoteServerInfo = null; Net.remoteServerInfo = null;
Net.lobbyHostReady = false; Net.lobbyHostReady = false;
Net.lobbyClientReady = false; Net.lobbyClientReady = false;
Net.hostReady = false;
} }
} }

View file

@ -85,7 +85,10 @@ class NetCommands {
@:rpc(client) public static function clientIsReady(clientId:Int) { @:rpc(client) public static function clientIsReady(clientId:Int) {
if (Net.isHost) { if (Net.isHost) {
if (Net.serverInfo.state == "WAITING" && MarbleGame.instance.world != null) { 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; var allReady = true;
for (id => client in Net.clientIdMap) { for (id => client in Net.clientIdMap) {
if (client.state != GameplayState.GAME) { if (client.state != GameplayState.GAME) {
@ -93,12 +96,10 @@ class NetCommands {
break; break;
} }
} }
if (allReady) { if (allReady && Net.hostReady) {
if (MarbleGame.instance.world != null) { if (MarbleGame.instance.world != null) {
MarbleGame.instance.world.allClientsReady(); MarbleGame.instance.world.allClientsReady();
} }
}
if (Net.isHost) {
Net.serverInfo.state = "PLAYING"; Net.serverInfo.state = "PLAYING";
MasterServerClient.instance.sendServerInfo(Net.serverInfo); // notify the server of the playing state 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) { @:rpc(server) public static function setStartTicks(ticks:Int) {
if (MarbleGame.instance.world != null) { if (MarbleGame.instance.world != null) {
MarbleGame.instance.world.serverStartTicks = ticks + 1; // Extra tick so we don't get 0 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 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) { if (Net.isHost) {
Net.lobbyHostReady = false; Net.lobbyHostReady = false;
Net.hostReady = false;
if (Net.isHost) { Net.serverInfo.state = "LOBBY";
Net.serverInfo.state = "LOBBY"; MasterServerClient.instance.sendServerInfo(Net.serverInfo); // notify the server of the playing state
MasterServerClient.instance.sendServerInfo(Net.serverInfo); // notify the server of the playing state
}
} }
} }