From e99f1adfae220ec00e49de2ea83036397c007d5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Tue, 26 Dec 2017 11:37:00 +0100 Subject: [PATCH 1/3] Fixed exception on task dispose (fix #357) --- Vocaluxe/Base/CBackgroundMusic.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index b8768aa7..19c47c19 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -263,7 +263,6 @@ namespace Vocaluxe.Base if (_PreviewStartHelperTask != null && (_PreviewPlayer.Length > 0 || _PreviewStartWaitCounter++ >= _PreviewStartWaitMaxTries)) { _PreviewStartHelperTask.RunSynchronously(TaskScheduler.FromCurrentSynchronizationContext()); - _PreviewStartHelperTask.Dispose(); _PreviewStartHelperTask = null; _PreviewStartWaitCounter = 0; } @@ -327,11 +326,6 @@ namespace Vocaluxe.Base { lock (_PreviewStartHelperTaskLock) { - // Check if the old _PreviewStartHelperTask needs to disposed - if (_PreviewStartHelperTask != null) - { - _PreviewStartHelperTask.Dispose(); - } _PreviewStartHelperTask = new Task(() => { float length = _PreviewPlayer.Length; @@ -360,7 +354,6 @@ namespace Vocaluxe.Base // Recheck the condition as it cloud have change before we got the lock if (_PreviewStartHelperTask != null) { - _PreviewStartHelperTask.Dispose(); _PreviewStartHelperTask = null; } } From f9e71693eaacdccc114f84d360dc0e60aed84c85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Tue, 26 Dec 2017 12:51:16 +0100 Subject: [PATCH 2/3] Fix: Winner in challenge mode wasn't calculated properly --- .../PartyModeChallenge/CPartyModeChallenge.cs | 54 ++++++++++---- .../CPartyModeChallengeMedley.cs | 71 ++++++++++--------- 2 files changed, 77 insertions(+), 48 deletions(-) diff --git a/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs b/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs index e336d4de..f34ed0a5 100644 --- a/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs +++ b/PartyModes/PartyModeChallenge/CPartyModeChallenge.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; using System.Runtime.InteropServices; +using VocaluxeLib.Game; using VocaluxeLib.Menu; [assembly: ComVisible(false)] @@ -430,39 +431,62 @@ namespace VocaluxeLib.PartyModes.Challenge private void _UpdateScores() { + //Prepare results table if (GameData.ResultTable.Count == 0) { for (int i = 0; i < GameData.NumPlayer; i++) { - var row = new CResultTableRow {PlayerID = GameData.ProfileIDs[i], NumPlayed = 0, NumWon = 0, NumSingPoints = 0, NumGamePoints = 0}; + var row = new CResultTableRow { PlayerID = GameData.ProfileIDs[i], NumPlayed = 0, NumWon = 0, NumSingPoints = 0, NumGamePoints = 0 }; GameData.ResultTable.Add(row); } - GameData.Results = new int[GameData.NumRounds,GameData.NumPlayerAtOnce]; + GameData.Results = new int[GameData.NumRounds, GameData.NumPlayerAtOnce]; for (int i = 0; i < GameData.NumRounds; i++) { for (int j = 0; j < GameData.NumPlayerAtOnce; j++) GameData.Results[i, j] = 0; } } - SPlayer[] results = CBase.Game.GetPlayers(); - if (results == null) - return; - if (results.Length < GameData.NumPlayerAtOnce) - return; + //Get points from game + CPoints points = CBase.Game.GetPoints(); + SPlayer[] players = CBase.Game.GetPlayers(); - for (int j = 0; j < GameData.NumPlayerAtOnce; j++) - GameData.Results[GameData.CurrentRoundNr - 2, j] = (int)Math.Round(results[j].Points); + //Go over all rounds and sum up points + for (int round = 0; round < points.NumRounds; round++) + { + SPlayer[] res = points.GetPlayer(round, GameData.NumPlayerAtOnce); - List points = _GetPointsForPlayer(results); + if (res == null || res.Length < GameData.NumPlayerAtOnce) + return; + + for (int p = 0; p < GameData.NumPlayerAtOnce; p++) + { + players[p].Points += res[p].Points; + players[p].PointsGoldenNotes += res[p].PointsGoldenNotes; + players[p].PointsLineBonus += res[p].PointsLineBonus; + } + } + //Calculate average points + for (int p = 0; p < GameData.NumPlayerAtOnce; p++) + { + players[p].Points /= points.NumRounds; + players[p].PointsGoldenNotes /= points.NumRounds; + players[p].PointsLineBonus /= points.NumRounds; + + //Save points in GameData + GameData.Results[GameData.CurrentRoundNr - 2, p] = (int)Math.Round(players[p].Points); + } + + List stats = _GetPointsForPlayer(players); for (int i = 0; i < GameData.NumPlayerAtOnce; i++) { + //Find matching row in results table int index = -1; for (int j = 0; j < GameData.ResultTable.Count; j++) { - if (points[i].ProfileID == GameData.ResultTable[j].PlayerID) + if (stats[i].ProfileID == GameData.ResultTable[j].PlayerID) { index = j; break; @@ -473,14 +497,14 @@ namespace VocaluxeLib.PartyModes.Challenge continue; CResultTableRow row = GameData.ResultTable[index]; + //Update results entry row.NumPlayed++; - row.NumWon += points[i].Won; - row.NumSingPoints += points[i].SingPoints; - row.NumGamePoints += points[i].GamePoints; + row.NumWon += stats[i].Won; + row.NumSingPoints += stats[i].SingPoints; + row.NumGamePoints += stats[i].GamePoints; GameData.ResultTable[index] = row; } - GameData.ResultTable.Sort(); diff --git a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs index 78da5f05..e8ec6b18 100644 --- a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs +++ b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs @@ -411,74 +411,79 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley private void _UpdateScores() { + //Prepare results table if (GameData.ResultTable.Count == 0) { for (int i = 0; i < GameData.NumPlayer; i++) { - CResultTableRow row = new CResultTableRow {PlayerID = GameData.ProfileIDs[i], NumPlayed = 0, NumWon = 0, NumSingPoints = 0, NumGamePoints = 0}; + var row = new CResultTableRow { PlayerID = GameData.ProfileIDs[i], NumPlayed = 0, NumWon = 0, NumSingPoints = 0, NumGamePoints = 0 }; GameData.ResultTable.Add(row); } - GameData.Results = new int[GameData.NumRounds,GameData.NumPlayerAtOnce]; + GameData.Results = new int[GameData.NumRounds, GameData.NumPlayerAtOnce]; for (int i = 0; i < GameData.NumRounds; i++) { for (int j = 0; j < GameData.NumPlayerAtOnce; j++) GameData.Results[i, j] = 0; } } - - CPoints gamePoints = CBase.Game.GetPoints(); - if (gamePoints == null || gamePoints.NumPlayer < GameData.NumPlayerAtOnce) - return; - SPlayer[] results = gamePoints.GetPlayer(0, GameData.NumPlayerAtOnce); - if (results == null) - return; + //Get points from game + CPoints points = CBase.Game.GetPoints(); + SPlayer[] players = CBase.Game.GetPlayers(); - if (results.Length < GameData.NumPlayerAtOnce) - return; - - if (gamePoints.NumRounds == 0) - return; - - for (int i = 1; i < gamePoints.NumRounds; i++) + //Go over all rounds and sum up points + for (int round = 0; round < points.NumRounds; round++) { - SPlayer[] temp = gamePoints.GetPlayer(i, GameData.NumPlayerAtOnce); + SPlayer[] res = points.GetPlayer(round, GameData.NumPlayerAtOnce); + + if (res == null || res.Length < GameData.NumPlayerAtOnce) + return; + for (int p = 0; p < GameData.NumPlayerAtOnce; p++) - results[p].Points += temp[p].Points; + { + players[p].Points += res[p].Points; + players[p].PointsGoldenNotes += res[p].PointsGoldenNotes; + players[p].PointsLineBonus += res[p].PointsLineBonus; + } } - - for (int j = 0; j < GameData.NumPlayerAtOnce; j++) + //Calculate average points + for (int p = 0; p < GameData.NumPlayerAtOnce; p++) { - results[j].Points = results[j].Points / gamePoints.NumRounds; - GameData.Results[GameData.CurrentRoundNr - 2, j] = (int)Math.Round(results[j].Points); + players[p].Points /= points.NumRounds; + players[p].PointsGoldenNotes /= points.NumRounds; + players[p].PointsLineBonus /= points.NumRounds; + + //Save points in GameData + GameData.Results[GameData.CurrentRoundNr - 2, p] = (int)Math.Round(players[p].Points); } - List points = _GetPointsForPlayer(results); + List stats = _GetPointsForPlayer(players); for (int i = 0; i < GameData.NumPlayerAtOnce; i++) { + //Find matching row in results table int index = -1; for (int j = 0; j < GameData.ResultTable.Count; j++) { - if (points[i].ProfileID == GameData.ResultTable[j].PlayerID) + if (stats[i].ProfileID == GameData.ResultTable[j].PlayerID) { index = j; break; } } - if (index != -1) - { - CResultTableRow row = GameData.ResultTable[index]; + if (index == -1) + continue; + CResultTableRow row = GameData.ResultTable[index]; - row.NumPlayed++; - row.NumWon += points[i].Won; - row.NumSingPoints += points[i].SingPoints; - row.NumGamePoints += points[i].GamePoints; + //Update results entry + row.NumPlayed++; + row.NumWon += stats[i].Won; + row.NumSingPoints += stats[i].SingPoints; + row.NumGamePoints += stats[i].GamePoints; - GameData.ResultTable[index] = row; - } + GameData.ResultTable[index] = row; } GameData.ResultTable.Sort(); From 675edce193cc2b45fba87f2895c46092c2e4bd56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Tue, 26 Dec 2017 15:46:21 +0100 Subject: [PATCH 3/3] Fix: winner calc in tic-tac-toe mode (closes #349) --- .../PartyModeTicTacToe/CPartyModeTicTacToe.cs | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs b/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs index 636e3cfe..e867335b 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyModeTicTacToe.cs @@ -20,6 +20,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Runtime.InteropServices; +using VocaluxeLib.Game; using VocaluxeLib.Menu; using VocaluxeLib.Songs; @@ -530,13 +531,33 @@ namespace VocaluxeLib.PartyModes.TicTacToe if (!GameData.Rounds[GameData.FieldNr].Finished) GameData.CurrentRoundNr++; + CPoints points = CBase.Game.GetPoints(); SPlayer[] results = CBase.Game.GetPlayers(); - if (results == null) + + if (results == null || results.Length < 2) return; - if (results.Length < 2) - return; + //Sum up all points + for (int r = 0; r < points.NumRounds; r++) + { + SPlayer[] player = points.GetPlayer(r, 2); + for (int i = 0; i < 2; i++) + { + results[i].Points += player[i].Points; + results[i].PointsGoldenNotes += player[i].PointsGoldenNotes; + results[i].PointsLineBonus += player[i].PointsLineBonus; + } + } + //Calc average of points + for (int i = 0; i < 2; i++) + { + results[i].Points /= points.NumRounds; + results[i].PointsGoldenNotes /= points.NumRounds; + results[i].PointsLineBonus /= points.NumRounds; + } + + //Decide who has won GameData.Rounds[GameData.FieldNr].PointsTeam1 = (int)Math.Round(results[0].Points); GameData.Rounds[GameData.FieldNr].PointsTeam2 = (int)Math.Round(results[1].Points); GameData.Rounds[GameData.FieldNr].Finished = true;