Merge remote-tracking branch 'refs/remotes/origin/devTestBranch'

This commit is contained in:
Niko Jochim 2020-07-02 12:54:22 +02:00
commit 66aa21ccb4

View File

@ -13,6 +13,7 @@ class RoundTimer: Timer {
var timer: Timer? var timer: Timer?
var timeLeft: Int = 0 var timeLeft: Int = 0
var isHeartbeatLocked = false var isHeartbeatLocked = false
var isTimerStopped = false
var calculate = false var calculate = false
var roundEnded = "Syncing" var roundEnded = "Syncing"
@ -31,48 +32,42 @@ class RoundTimer: Timer {
} }
func stopTimer() { func stopTimer() {
guard timer != nil else { return } isTimerStopped = true
timer?.invalidate()
timer = nil
} }
func resumeTimer() { func resumeTimer() {
timer = Timer.scheduledTimer( isTimerStopped = false
timeInterval: 1.0,
target: self,
selector: #selector(onTimerFires),
userInfo: nil,
repeats: true
)
} }
@objc func onTimerFires() @objc func onTimerFires()
{ {
timeLeft -= 1 if !isTimerStopped {
EntityManager.gameEMInstance.updateTime(time: (timeLeft > 0 ? String(timeLeft) : roundEnded)) timeLeft -= 1
EntityManager.gameEMInstance.updateTime(time: (timeLeft > 0 ? String(timeLeft) : roundEnded))
if timeLeft == 0 {
EntityManager.gameEMInstance.removeModal() if timeLeft == 0 {
RoundCalculatorService.sharedInstance.resetNumberOfAttacksAndFormats() EntityManager.gameEMInstance.removeModal()
if !MultiplayerNetwork.sharedInstance.isSending { RoundCalculatorService.sharedInstance.resetNumberOfAttacksAndFormats()
MultiplayerNetwork.sharedInstance.sendPlayerMoves(localRoundData: DataService.sharedInstance.localRoundData) if !MultiplayerNetwork.sharedInstance.isSending {
MultiplayerNetwork.sharedInstance.sendPlayerMoves(localRoundData: DataService.sharedInstance.localRoundData)
}
calculate = true
} }
calculate = true
} if timeLeft <= 0 {
if calculate
if timeLeft <= 0 { && !RoundCalculatorService.sharedInstance.isCalculating
if calculate && DataService.sharedInstance.didReceiveAllData()
&& !RoundCalculatorService.sharedInstance.isCalculating && GameCenterManager.sharedInstance.isServer {
&& DataService.sharedInstance.didReceiveAllData() RoundCalculatorService.sharedInstance.calculateRound()
&& GameCenterManager.sharedInstance.isServer { calculate = false
RoundCalculatorService.sharedInstance.calculateRound() }
calculate = false }
if (!isHeartbeatLocked && (timeLeft % 7 == 0)){
MultiplayerNetwork.sharedInstance.sendHeartbeatToPlayer()
isHeartbeatLocked = true;
} }
}
if (!isHeartbeatLocked && (timeLeft % 7 == 0)){
MultiplayerNetwork.sharedInstance.sendHeartbeatToPlayer()
isHeartbeatLocked = true;
} }
} }
} }