mirror of https://github.com/ppy/osu
Add thread safety somewhere it will never be required.
This commit is contained in:
parent
9a8003f6fa
commit
e01057df3d
|
@ -16,6 +16,8 @@ public class CatchRuleset : Ruleset
|
|||
|
||||
public override HitRenderer CreateHitRendererWith(List<HitObject> objects) => new CatchHitRenderer { Objects = objects };
|
||||
|
||||
protected override PlayMode PlayMode => PlayMode.Mania;
|
||||
|
||||
public override HitObjectParser CreateHitObjectParser() => new OsuHitObjectParser();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ public class ManiaRuleset : Ruleset
|
|||
|
||||
public override HitRenderer CreateHitRendererWith(List<HitObject> objects) => new ManiaHitRenderer { Objects = objects };
|
||||
|
||||
protected override PlayMode PlayMode => PlayMode.Mania;
|
||||
|
||||
public override HitObjectParser CreateHitObjectParser() => new OsuHitObjectParser();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ public class TaikoRuleset : Ruleset
|
|||
|
||||
public override HitRenderer CreateHitRendererWith(List<HitObject> objects) => new TaikoHitRenderer { Objects = objects };
|
||||
|
||||
protected override PlayMode PlayMode => PlayMode.Taiko;
|
||||
|
||||
public override HitObjectParser CreateHitObjectParser() => new OsuHitObjectParser();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,13 +7,14 @@
|
|||
using System.Reflection;
|
||||
using osu.Framework.Extensions;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Linq;
|
||||
|
||||
namespace osu.Game.Modes
|
||||
{
|
||||
public abstract class Ruleset
|
||||
{
|
||||
private static List<Type> availableRulesets = new List<Type>();
|
||||
private static ConcurrentDictionary<PlayMode, Type> availableRulesets = new ConcurrentDictionary<PlayMode, Type>();
|
||||
|
||||
public abstract ScoreOverlay CreateScoreOverlay();
|
||||
|
||||
|
@ -21,13 +22,15 @@ public abstract class Ruleset
|
|||
|
||||
public abstract HitObjectParser CreateHitObjectParser();
|
||||
|
||||
public static void Register(Ruleset ruleset) => availableRulesets.Add(ruleset.GetType());
|
||||
public static void Register(Ruleset ruleset) => availableRulesets.TryAdd(ruleset.PlayMode, ruleset.GetType());
|
||||
|
||||
protected virtual PlayMode PlayMode => PlayMode.Osu;
|
||||
|
||||
public static Ruleset GetRuleset(PlayMode mode)
|
||||
{
|
||||
Type type = availableRulesets.FirstOrDefault(t => t.Name == $@"{mode}Ruleset");
|
||||
Type type;
|
||||
|
||||
if (type == null)
|
||||
if (!availableRulesets.TryGetValue(mode, out type))
|
||||
return null;
|
||||
|
||||
return Activator.CreateInstance(type) as Ruleset;
|
||||
|
|
Loading…
Reference in New Issue