more mid-game join stuff

This commit is contained in:
RandomityGuy 2024-04-27 13:54:53 +05:30
parent b3fab7bc2a
commit d79ff47598
4 changed files with 31 additions and 2 deletions

View file

@ -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);

View file

@ -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;

View file

@ -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();

View file

@ -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