diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index 5dfd3e18..52471ebd 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -536,6 +536,18 @@ class MarbleWorld extends Scheduler { this.initMarble(cc, () -> { var addedMarble = clientMarbles.get(cc); this.restart(addedMarble); // spawn it + this.playGui.addPlayer(cc.id, cc.getName(), false); + this.playGui.redrawPlayerList(); + onAdded(); + }); + } + + public function addJoiningClientGhost(cc:GameConnection, onAdded:() -> Void) { + this.initMarble(cc, () -> { + var addedMarble = clientMarbles.get(cc); + this.restart(addedMarble); // spawn it + this.playGui.addPlayer(cc.id, cc.getName(), false); + this.playGui.redrawPlayerList(); onAdded(); }); } @@ -1311,6 +1323,8 @@ class MarbleWorld extends Scheduler { var m = arr.packets[0]; // if (m.serverTicks == ourLastMoveTime) { var marbleToUpdate = clientMarbles[Net.clientIdMap[client]]; + if (@:privateAccess marbleToUpdate.newPos == null) + continue; // Debug.drawSphere(@:privateAccess marbleToUpdate.newPos, marbleToUpdate._radius); // var distFromUs = @:privateAccess marbleToUpdate.newPos.distance(this.marble.newPos); diff --git a/src/gui/CreateMatchGui.hx b/src/gui/CreateMatchGui.hx index a7d3aeee..28571430 100644 --- a/src/gui/CreateMatchGui.hx +++ b/src/gui/CreateMatchGui.hx @@ -71,7 +71,7 @@ class CreateMatchGui extends GuiImage { optionCollection.extent = new Vector(815, 500); innerCtrl.addChild(optionCollection); - var maxPlayers = 2; + var maxPlayers = 8; var privateSlots = 0; var privateGame = false; diff --git a/src/net/Net.hx b/src/net/Net.hx index fd60cecd..2299b509 100644 --- a/src/net/Net.hx +++ b/src/net/Net.hx @@ -299,6 +299,13 @@ class Net { if (serverInfo.state == "PLAYING") { // We initiated the game, directly add in the marble NetCommands.playLevelMidJoinClient(conn, MultiplayerLevelSelectGui.currentSelectionStatic); MarbleGame.instance.world.addJoiningClient(conn, () -> {}); + var playerInfoBytes = sendPlayerInfosBytes(); + for (dc => cc in clients) { + if (cc != conn) { + cc.sendBytes(playerInfoBytes); + NetCommands.addMidGameJoinMarbleClient(cc, conn.id); + } + } } if (serverInfo.state == "LOBBY") { // Connect client to lobby @@ -454,7 +461,7 @@ class Net { } } if (newP) { - AudioManager.playSound(ResourceLoader.getAudio("sounds/spawn_alternate.wav").resource); + // AudioManager.playSound(ResourceLoader.getAudio("sounds/spawn_alternate.wav").resource); } if (MarbleGame.canvas.content is MultiplayerLevelSelectGui) { cast(MarbleGame.canvas.content, MultiplayerLevelSelectGui).updateLobbyNames(); diff --git a/src/net/NetCommands.hx b/src/net/NetCommands.hx index a154b7e9..fd3d1b91 100644 --- a/src/net/NetCommands.hx +++ b/src/net/NetCommands.hx @@ -118,6 +118,14 @@ class NetCommands { } } + @:rpc(server) public static function addMidGameJoinMarble(cc:Int) { + if (Net.isClient) { + if (MarbleGame.instance.world != null) { + MarbleGame.instance.world.addJoiningClientGhost(Net.clientIdMap[cc], () -> {}); + } + } + } + @: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