From b9a40a841b7311673c517f5f1b11bb4bd53d7a8d Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 13 May 2017 21:28:53 +0800 Subject: [PATCH 1/7] Use IsAssignableFrom. --- osu.Game/Graphics/UserInterface/RollingCounter.cs | 2 +- osu.Game/Overlays/NotificationManager.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/RollingCounter.cs b/osu.Game/Graphics/UserInterface/RollingCounter.cs index e98867277a..bdb2054ca4 100644 --- a/osu.Game/Graphics/UserInterface/RollingCounter.cs +++ b/osu.Game/Graphics/UserInterface/RollingCounter.cs @@ -181,7 +181,7 @@ protected virtual string FormatCount(T count) protected virtual void TransformCount(T currentValue, T newValue) { Debug.Assert( - TransformType.IsSubclassOf(typeof(Transform)) || TransformType == typeof(Transform), + typeof(Transform).IsAssignableFrom(TransformType), @"transformType should be a subclass of Transform." ); diff --git a/osu.Game/Overlays/NotificationManager.cs b/osu.Game/Overlays/NotificationManager.cs index b344d533ee..3ddd85cfcf 100644 --- a/osu.Game/Overlays/NotificationManager.cs +++ b/osu.Game/Overlays/NotificationManager.cs @@ -81,7 +81,7 @@ public void Post(Notification notification) hasCompletionTarget.CompletionTarget = Post; var ourType = notification.GetType(); - sections.Children.FirstOrDefault(s => s.AcceptTypes.Any(accept => ourType == accept || ourType.IsSubclassOf(accept)))?.Add(notification); + sections.Children.FirstOrDefault(s => s.AcceptTypes.Any(accept => accept.IsAssignableFrom(ourType)))?.Add(notification); } protected override void PopIn() From d213706d076f384734196e0475ca89f3c390ef42 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Tue, 16 May 2017 21:14:50 +0800 Subject: [PATCH 2/7] Use DateTimeOffset. --- osu.Desktop.VisualTests/Tests/TestCaseResults.cs | 2 +- osu.Game/Online/Chat/ErrorMessage.cs | 2 +- osu.Game/Rulesets/Scoring/Score.cs | 2 +- osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 2 +- osu.Game/Screens/Ranking/ResultsPageScore.cs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseResults.cs b/osu.Desktop.VisualTests/Tests/TestCaseResults.cs index aa3a117667..f8c93e9a73 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseResults.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseResults.cs @@ -47,7 +47,7 @@ public override void Reset() Accuracy = 0.98, MaxCombo = 123, Rank = ScoreRank.A, - Date = DateTime.Now, + Date = DateTimeOffset.Now, Statistics = new Dictionary() { { "300", 50 }, diff --git a/osu.Game/Online/Chat/ErrorMessage.cs b/osu.Game/Online/Chat/ErrorMessage.cs index a410e9044a..48557ca648 100644 --- a/osu.Game/Online/Chat/ErrorMessage.cs +++ b/osu.Game/Online/Chat/ErrorMessage.cs @@ -12,7 +12,7 @@ public class ErrorMessage : Message public ErrorMessage(string message) : base(errorId--) { - Timestamp = DateTime.Now; + Timestamp = DateTimeOffset.Now; Content = message; Sender = new User diff --git a/osu.Game/Rulesets/Scoring/Score.cs b/osu.Game/Rulesets/Scoring/Score.cs index 15d8690322..2cca0f54af 100644 --- a/osu.Game/Rulesets/Scoring/Score.cs +++ b/osu.Game/Rulesets/Scoring/Score.cs @@ -46,7 +46,7 @@ public class Score public long OnlineScoreID; [JsonProperty(@"created_at")] - public DateTime Date; + public DateTimeOffset Date; [JsonProperty(@"statistics")] private Dictionary jsonStats diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index 11c1c273e2..79fb34a523 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -129,7 +129,7 @@ public virtual void PopulateScore(Score score) score.MaxCombo = HighestCombo; score.Accuracy = Accuracy; score.Rank = rankFrom(Accuracy); - score.Date = DateTime.Now; + score.Date = DateTimeOffset.Now; score.Health = Health; } } diff --git a/osu.Game/Screens/Ranking/ResultsPageScore.cs b/osu.Game/Screens/Ranking/ResultsPageScore.cs index fad914e9d4..4dc61b8160 100644 --- a/osu.Game/Screens/Ranking/ResultsPageScore.cs +++ b/osu.Game/Screens/Ranking/ResultsPageScore.cs @@ -116,7 +116,7 @@ private void load(OsuColour colours) Origin = Anchor.TopCentre, Margin = new MarginPadding { Bottom = 10 }, }, - new DateDisplay(Score.Date) + new DateDisplay(Score.Date.LocalDateTime) { Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, From d929de466a2e43e52b5682f2010fa1fe585341f3 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Tue, 16 May 2017 21:16:52 +0800 Subject: [PATCH 3/7] DateDisplay -> DateTimeDisplay for more exactly. --- osu.Game/Screens/Ranking/ResultsPageScore.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/osu.Game/Screens/Ranking/ResultsPageScore.cs b/osu.Game/Screens/Ranking/ResultsPageScore.cs index 4dc61b8160..70542dab8b 100644 --- a/osu.Game/Screens/Ranking/ResultsPageScore.cs +++ b/osu.Game/Screens/Ranking/ResultsPageScore.cs @@ -116,7 +116,7 @@ private void load(OsuColour colours) Origin = Anchor.TopCentre, Margin = new MarginPadding { Bottom = 10 }, }, - new DateDisplay(Score.Date.LocalDateTime) + new DateTimeDisplay(Score.Date.LocalDateTime) { Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, @@ -220,13 +220,13 @@ private void load(OsuColour colours) } } - private class DateDisplay : Container + private class DateTimeDisplay : Container { - private DateTime date; + private DateTime datetime; - public DateDisplay(DateTime date) + public DateTimeDisplay(DateTime datetime) { - this.date = date; + this.datetime = datetime; AutoSizeAxes = Axes.Y; @@ -250,7 +250,7 @@ private void load(OsuColour colours) { Origin = Anchor.CentreLeft, Anchor = Anchor.CentreLeft, - Text = date.ToString("HH:mm"), + Text = datetime.ToString("HH:mm"), Padding = new MarginPadding { Left = 10, Right = 10, Top = 5, Bottom = 5 }, Colour = Color4.White, }, @@ -258,7 +258,7 @@ private void load(OsuColour colours) { Origin = Anchor.CentreRight, Anchor = Anchor.CentreRight, - Text = date.ToString("yyyy/MM/dd"), + Text = datetime.ToString("yyyy/MM/dd"), Padding = new MarginPadding { Left = 10, Right = 10, Top = 5, Bottom = 5 }, Colour = Color4.White, } From e911441394ad80a7871b41a1be8686f672fa76d5 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Tue, 16 May 2017 21:23:14 +0800 Subject: [PATCH 4/7] Why AbandonedMutexException? --- osu.Game/IO/Legacy/SerializationReader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/IO/Legacy/SerializationReader.cs b/osu.Game/IO/Legacy/SerializationReader.cs index 6bb6c3bbbf..c4d56641af 100644 --- a/osu.Game/IO/Legacy/SerializationReader.cs +++ b/osu.Game/IO/Legacy/SerializationReader.cs @@ -66,7 +66,7 @@ public char[] ReadCharArray() public DateTime ReadDateTime() { long ticks = ReadInt64(); - if (ticks < 0) throw new AbandonedMutexException("oops"); + if (ticks < 0) throw new IOException("Bad ticks count read!"); return new DateTime(ticks, DateTimeKind.Utc); } From aaaee5ed102e54a2fe40209e0ebe967015b29b83 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Tue, 16 May 2017 21:46:22 +0800 Subject: [PATCH 5/7] Use generic IComparable for message. --- osu.Game/Online/Chat/Channel.cs | 2 +- osu.Game/Online/Chat/Message.cs | 14 ++------------ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/osu.Game/Online/Chat/Channel.cs b/osu.Game/Online/Chat/Channel.cs index 2925c3ccb4..93fd0a8956 100644 --- a/osu.Game/Online/Chat/Channel.cs +++ b/osu.Game/Online/Chat/Channel.cs @@ -23,7 +23,7 @@ public class Channel [JsonProperty(@"channel_id")] public int Id; - public readonly SortedList Messages = new SortedList((m1, m2) => m1.Id.CompareTo(m2.Id)); + public readonly SortedList Messages = new SortedList(Comparer.Default); //internal bool Joined; diff --git a/osu.Game/Online/Chat/Message.cs b/osu.Game/Online/Chat/Message.cs index bf53a68910..c1887e7824 100644 --- a/osu.Game/Online/Chat/Message.cs +++ b/osu.Game/Online/Chat/Message.cs @@ -8,7 +8,7 @@ namespace osu.Game.Online.Chat { - public class Message + public class Message : IComparable { [JsonProperty(@"message_id")] public readonly long Id; @@ -42,17 +42,7 @@ public Message(long id) Id = id; } - public override bool Equals(object obj) - { - var objMessage = obj as Message; - - return Id == objMessage?.Id; - } - - public override int GetHashCode() - { - return Id.GetHashCode(); - } + public int CompareTo(Message other) => Id.CompareTo(other.Id); } public enum TargetType From f1d5a929505419c71fcd790c37f22a70db49ccb2 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Tue, 16 May 2017 21:49:38 +0800 Subject: [PATCH 6/7] Use generic IEqutable to avoid typeless Equals. --- osu.Game/Graphics/UserInterface/OsuSliderBar.cs | 4 +++- osu.Game/Overlays/Settings/SettingsSlider.cs | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs index 027473921f..6cf7b2dfa5 100644 --- a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs +++ b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; using OpenTK; using osu.Framework.Allocation; using osu.Framework.Audio; @@ -13,7 +14,8 @@ namespace osu.Game.Graphics.UserInterface { - public class OsuSliderBar : SliderBar, IHasTooltip where T : struct + public class OsuSliderBar : SliderBar, IHasTooltip + where T : struct, IEquatable { private SampleChannel sample; private double lastSampleTime; diff --git a/osu.Game/Overlays/Settings/SettingsSlider.cs b/osu.Game/Overlays/Settings/SettingsSlider.cs index beb2bdf645..522d242f2a 100644 --- a/osu.Game/Overlays/Settings/SettingsSlider.cs +++ b/osu.Game/Overlays/Settings/SettingsSlider.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; using osu.Framework.Graphics; using osu.Framework.Graphics.UserInterface; using osu.Game.Graphics.UserInterface; @@ -8,12 +9,12 @@ namespace osu.Game.Overlays.Settings { public class SettingsSlider : SettingsSlider> - where T : struct + where T : struct, IEquatable { } public class SettingsSlider : SettingsItem - where T : struct + where T : struct, IEquatable where U : SliderBar, new() { protected override Drawable CreateControl() => new U() From e2a7f00a5255cc6a68f456a26ee282e0f665181e Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Tue, 16 May 2017 22:20:05 +0800 Subject: [PATCH 7/7] Remove unused namespace. --- osu.Game/IO/Legacy/SerializationReader.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/IO/Legacy/SerializationReader.cs b/osu.Game/IO/Legacy/SerializationReader.cs index c4d56641af..bad143fa6c 100644 --- a/osu.Game/IO/Legacy/SerializationReader.cs +++ b/osu.Game/IO/Legacy/SerializationReader.cs @@ -10,7 +10,6 @@ using System.Runtime.Serialization.Formatters; using System.Runtime.Serialization.Formatters.Binary; using System.Text; -using System.Threading; namespace osu.Game.IO.Legacy {