diff --git a/data/ui/xbox/platform_android.png b/data/ui/xbox/platform_android.png index 0081e4df..4f78b698 100644 Binary files a/data/ui/xbox/platform_android.png and b/data/ui/xbox/platform_android.png differ diff --git a/data/ui/xbox/platform_desktop.png b/data/ui/xbox/platform_desktop.png index 5a37d83d..46ce0111 100644 Binary files a/data/ui/xbox/platform_desktop.png and b/data/ui/xbox/platform_desktop.png differ diff --git a/data/ui/xbox/platform_mac.png b/data/ui/xbox/platform_mac.png new file mode 100644 index 00000000..009915ee Binary files /dev/null and b/data/ui/xbox/platform_mac.png differ diff --git a/data/ui/xbox/platform_unknown.png b/data/ui/xbox/platform_unknown.png new file mode 100644 index 00000000..8504eeef Binary files /dev/null and b/data/ui/xbox/platform_unknown.png differ diff --git a/data/ui/xbox/platform_web.png b/data/ui/xbox/platform_web.png index 9925a989..d1e087d1 100644 Binary files a/data/ui/xbox/platform_web.png and b/data/ui/xbox/platform_web.png differ diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index 97cd12d8..1961eac1 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -521,6 +521,7 @@ class MarbleWorld extends Scheduler { public function restartMultiplayerState() { if (this.isMultiplayer) { serverStartTicks = 0; + startTime = 1e8; lastMoves = new MarbleUpdateQueue(); predictions = new MarblePredictionStore(); powerupPredictions = new PowerupPredictionStore(); @@ -1189,21 +1190,21 @@ class MarbleWorld extends Scheduler { advanceTimeState.dt = 0.032; advanceTimeState.ticks = ourLastMoveTime; - if (marbleNeedsPrediction & (1 << Net.clientId) > 0) { // Only for our clients pls - // if (qm != null) { - // var mvs = qm.powerupStates.copy(); - for (pw in marble.level.powerUps) { - // var val = mvs.shift(); - // if (pw.lastPickUpTime != val) - // Console.log('Revert powerup pickup: ${pw.lastPickUpTime} -> ${val}'); - pw.lastPickUpTime = powerupPredictions.getState(pw.netIndex); - } - var huntMode:HuntMode = cast this.gameMode; - for (activeGem in @:privateAccess huntMode.activeGemSpawnGroup) { - huntMode.setGemHiddenStatus(activeGem, gemPredictions.getState(activeGem)); - } - // } + // if (marbleNeedsPrediction & (1 << Net.clientId) > 0) { // Only for our clients pls + // if (qm != null) { + // var mvs = qm.powerupStates.copy(); + for (pw in marble.level.powerUps) { + // var val = mvs.shift(); + // if (pw.lastPickUpTime != val) + // Console.log('Revert powerup pickup: ${pw.lastPickUpTime} -> ${val}'); + pw.lastPickUpTime = powerupPredictions.getState(pw.netIndex); } + var huntMode:HuntMode = cast this.gameMode; + for (activeGem in @:privateAccess huntMode.activeGemSpawnGroup) { + huntMode.setGemHiddenStatus(activeGem, gemPredictions.getState(activeGem)); + } + // } + // } ackLag = ourQueuedMoves.length; diff --git a/src/gui/MultiplayerLevelSelectGui.hx b/src/gui/MultiplayerLevelSelectGui.hx index 97ae8f9b..e9e52eb3 100644 --- a/src/gui/MultiplayerLevelSelectGui.hx +++ b/src/gui/MultiplayerLevelSelectGui.hx @@ -1,5 +1,6 @@ package gui; +import net.ClientConnection.NetPlatform; import net.Net; import net.NetCommands; import modes.GameMode.ScoreType; @@ -152,18 +153,21 @@ class MultiplayerLevelSelectGui extends GuiImage { if (Net.isHost) { playerListArr.push({ name: Settings.highscoreName, - state: Net.lobbyHostReady + state: Net.lobbyHostReady, + platform: Net.getPlatform() }); } if (Net.isClient) { playerListArr.push({ name: Settings.highscoreName, - state: Net.clientConnection.lobbyReady + state: Net.clientConnection.lobbyReady, + platform: Net.getPlatform() }); for (c => v in Net.clientIdMap) { playerListArr.push({ name: v.name, - state: v.lobbyReady + state: v.lobbyReady, + platform: v.platform }); } } @@ -174,12 +178,22 @@ class MultiplayerLevelSelectGui extends GuiImage { return ResourceLoader.getResource("data/ui/xbox/Ready.png", ResourceLoader.getImage, this.imageResources).toTile(); case "notready": return ResourceLoader.getResource("data/ui/xbox/NotReady.png", ResourceLoader.getImage, this.imageResources).toTile(); + case "pc": + return ResourceLoader.getResource("data/ui/xbox/platform_desktop.png", ResourceLoader.getImage, this.imageResources).toTile(); + case "mac": + return ResourceLoader.getResource("data/ui/xbox/platform_mac.png", ResourceLoader.getImage, this.imageResources).toTile(); + case "web": + return ResourceLoader.getResource("data/ui/xbox/platform_web.png", ResourceLoader.getImage, this.imageResources).toTile(); + case "android": + return ResourceLoader.getResource("data/ui/xbox/platform_android.png", ResourceLoader.getImage, this.imageResources).toTile(); + case "unknown": + return ResourceLoader.getResource("data/ui/xbox/platform_unknown.png", ResourceLoader.getImage, this.imageResources).toTile(); } return null; } playerList = new GuiMLTextListCtrl(arial14, playerListArr.map(player -> { - return '${player.name}'; + return '${player.name}'; }), imgLoader); playerList.selectedColor = 0xF29515; playerList.selectedFillColor = 0xEBEBEB; @@ -327,29 +341,42 @@ class MultiplayerLevelSelectGui extends GuiImage { super.onResize(width, height); } + inline function platformToString(platform:NetPlatform) { + return switch (platform) { + case Unknown: return "unknown"; + case Android: return "android"; + case MacOS: return "mac"; + case PC: return "pc"; + case Web: return "web"; + } + } + public function updateLobbyNames() { var playerListArr = []; if (Net.isHost) { playerListArr.push({ name: Settings.highscoreName, - state: Net.lobbyHostReady + state: Net.lobbyHostReady, + platform: Net.getPlatform() }); } if (Net.isClient) { playerListArr.push({ name: Settings.highscoreName, - state: Net.lobbyClientReady + state: Net.lobbyClientReady, + platform: Net.getPlatform() }); } for (c => v in Net.clientIdMap) { playerListArr.push({ name: v.name, - state: v.lobbyReady + state: v.lobbyReady, + platform: v.platform }); } playerList.setTexts(playerListArr.map(player -> { - return '${player.name}'; + return '${player.name}'; })); } diff --git a/src/modes/HuntMode.hx b/src/modes/HuntMode.hx index 4c1f12b2..975356e2 100644 --- a/src/modes/HuntMode.hx +++ b/src/modes/HuntMode.hx @@ -463,6 +463,18 @@ class HuntMode extends NullMode { } public function setActiveSpawnSphere(spawnGroup:Array) { + Console.log("Got new gem spawn from server!"); + if (activeGemSpawnGroup != null) { + for (agem in activeGemSpawnGroup) { + var gemSpawn = gemSpawnPoints[agem]; + if (gemSpawn.gem != null) { + gemSpawn.gem.pickedUp = true; + gemSpawn.gem.setHide(true); + gemSpawn.gemBeam.setHide(true); + activeGems.remove(gemSpawn.gem); + } + } + } for (sphereId in spawnGroup) { var gemSpawn = gemSpawnPoints[sphereId]; if (gemSpawn.gem != null) { diff --git a/src/net/ClientConnection.hx b/src/net/ClientConnection.hx index c607f110..3bb7e1ef 100644 --- a/src/net/ClientConnection.hx +++ b/src/net/ClientConnection.hx @@ -12,6 +12,14 @@ enum abstract GameplayState(Int) from Int to Int { var GAME; } +enum abstract NetPlatform(Int) from Int to Int { + var Unknown; + var PC; + var MacOS; + var Web; + var Android; +} + @:publicFields class ClientConnection extends GameConnection { var socket:RTCPeerConnection; @@ -50,8 +58,9 @@ abstract class GameConnection { var moveManager:MoveManager; var name:String; var lobbyReady:Bool; + var platform:NetPlatform; - public function new(id:Int) { + function new(id:Int) { this.id = id; this.moveManager = new MoveManager(this); this.lobbyReady = false; diff --git a/src/net/Net.hx b/src/net/Net.hx index 83915f79..d219cdf5 100644 --- a/src/net/Net.hx +++ b/src/net/Net.hx @@ -45,9 +45,9 @@ class ServerInfo { var privateServer:Bool; var inviteCode:Int; var state:String; - var platform:String; + var platform:NetPlatform; - public function new(name:String, players:Int, maxPlayers:Int, privateSlots:Int, privateServer:Bool, inviteCode:Int, state:String, platform:String) { + public function new(name:String, players:Int, maxPlayers:Int, privateSlots:Int, privateServer:Bool, inviteCode:Int, state:String, platform:NetPlatform) { this.name = name; this.players = players; this.maxPlayers = maxPlayers; @@ -298,6 +298,7 @@ class Net { for (c => v in clientIdMap) { b.writeByte(c); b.writeByte(v.lobbyReady ? 1 : 0); + b.writeByte(v.platform); var name = v.getName(); b.writeByte(name.length); for (i in 0...name.length) { @@ -307,6 +308,7 @@ class Net { // Write host data b.writeByte(0); b.writeByte(Net.lobbyHostReady ? 1 : 0); + b.writeByte(getPlatform()); var name = Settings.highscoreName; b.writeByte(name.length); for (i in 0...name.length) { @@ -327,6 +329,7 @@ class Net { clientId = input.readByte(); // 8 bit client id, hopefully we don't exceed this Console.log('Client ID set to ${clientId}'); NetCommands.setPlayerName(clientId, Settings.highscoreName); // Send our player name to the server + NetCommands.transmitPlatform(clientId, getPlatform()); // send our platform too case Ping: var pingLeft = input.readByte(); @@ -407,6 +410,7 @@ class Net { for (i in 0...count) { var id = input.readByte(); var cready = input.readByte() == 1; + var platform = input.readByte(); if (id != 0 && id != Net.clientId && !clientIdMap.exists(id)) { Console.log('Adding ghost connection ${id}'); addGhost(id); @@ -420,6 +424,7 @@ class Net { if (clientIdMap.exists(id)) { clientIdMap[id].setName(name); clientIdMap[id].lobbyReady = cready; + clientIdMap[id].platform = platform; } if (Net.clientId == id) { Net.lobbyClientReady = cready; @@ -457,15 +462,19 @@ class Net { } } - public static function getPlatform() { + public static inline function getPlatform() { #if js - return "Browser"; + return NetPlatform.Web; #end #if hl #if MACOS_BUNDLE - return "MacOS"; + return NetPlatform.MacOS; #else - return "Windows"; + #if android + return NetPlatform.Android; + #else + return NetPlatform.PC; + #end #end #end } diff --git a/src/net/NetCommands.hx b/src/net/NetCommands.hx index 455393cd..254ff0fe 100644 --- a/src/net/NetCommands.hx +++ b/src/net/NetCommands.hx @@ -1,5 +1,6 @@ package net; +import net.ClientConnection.NetPlatform; import gui.EndGameGui; import modes.HuntMode; import net.ClientConnection.GameplayState; @@ -128,6 +129,15 @@ class NetCommands { } } + @:rpc(client) public static function transmitPlatform(clientId:Int, platform:Int) { + if (Net.isHost) { + Net.clientIdMap[clientId].platform = platform; + if (MarbleGame.canvas.content is MultiplayerLevelSelectGui) { + cast(MarbleGame.canvas.content, MultiplayerLevelSelectGui).updateLobbyNames(); + } + } + } + @:rpc(server) public static function endGame() { if (Net.isClient) { if (MarbleGame.instance.world != null) { @@ -146,10 +156,8 @@ class NetCommands { @:rpc(server) public static function restartGame() { var world = MarbleGame.instance.world; if (Net.isHost) { - world.schedule(1, () -> { - world.allClientsReady(); - return null; - }); + world.startTime = 1e8; + haxe.Timer.delay(() -> world.allClientsReady(), 1500); } if (Net.isClient) { var gui = MarbleGame.canvas.children[MarbleGame.canvas.children.length - 1];