diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index 8dff2d28..8594236e 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -1810,18 +1810,18 @@ class MarbleWorld extends Scheduler { var gameplayHigh = ourStartTime - ticksSinceTimerStart * 0.032; var gameplayLow = ourStartTime - (ticksSinceTimerStart + 1) * 0.032; // Clamp timer to be between these two - if (gameplayLow > this.timeState.gameplayClock) { - this.timeState.gameplayClock = gameplayLow - this.timeState.gameplayClock + gameplayHigh; - } - if (gameplayHigh < this.timeState.gameplayClock) { - this.timeState.gameplayClock = gameplayLow + this.timeState.gameplayClock - gameplayHigh; + if (gameplayHigh < this.timeState.gameplayClock || gameplayLow > this.timeState.gameplayClock) { + var clockTicks = Math.floor((ourStartTime - this.timeState.gameplayClock) / 0.032); + var clockTickTime = ourStartTime - clockTicks * 0.032; + var delta = clockTickTime - this.timeState.gameplayClock; + this.timeState.gameplayClock = gameplayHigh - delta; } } this.timeState.gameplayClock += dt * timeMultiplier; } - if (this.timeState.gameplayClock < 0) + if (this.timeState.gameplayClock < 0 && !Net.isClient) this.gameMode.onTimeExpire(); } if (!this.isMultiplayer || this.multiplayerStarted) diff --git a/src/modes/HuntMode.hx b/src/modes/HuntMode.hx index f095f8b5..791f592a 100644 --- a/src/modes/HuntMode.hx +++ b/src/modes/HuntMode.hx @@ -634,14 +634,13 @@ class HuntMode extends NullMode { level.cancel(@:privateAccess level.marble.oobSchedule); if (!level.isWatching) { if (level.isMultiplayer) { - if (Net.isHost) { - for (marble in level.marbles) { - marble.setMode(Start); - level.cancel(@:privateAccess marble.oobSchedule); - } - - NetCommands.timerRanOut(); + for (marble in level.marbles) { + marble.setMode(Start); + level.cancel(@:privateAccess marble.oobSchedule); } + if (Net.isHost) + NetCommands.timerRanOut(); + if (!level.isWatching) { @:privateAccess level.schedule(level.timeState.currentAttemptTime + 5, () -> cast level.mpFinish()); } diff --git a/src/net/Net.hx b/src/net/Net.hx index 66719de2..e65a46b5 100644 --- a/src/net/Net.hx +++ b/src/net/Net.hx @@ -140,6 +140,8 @@ class Net { var finishSdp = () -> { if (sdpFinished) return; + if (peer == null) + return; sdpFinished = true; var sdpObj = StringTools.trim(peer.localDescription); sdpObj = sdpObj + '\r\n' + candidates.join('\r\n') + '\r\n'; @@ -218,6 +220,8 @@ class Net { if (sdpFinished) return; sdpFinished = true; + if (client == null) + return; Console.log("Local Description Set!"); var sdpObj = StringTools.trim(client.localDescription); sdpObj = sdpObj + '\r\n' + candidates.join('\r\n') + '\r\n';