diff --git a/osu.Android.props b/osu.Android.props
index 8a9bf1b9cd..05367c00f6 100644
--- a/osu.Android.props
+++ b/osu.Android.props
@@ -51,7 +51,7 @@
-
+
diff --git a/osu.Game.Tests/Database/TestRealmKeyBindingStore.cs b/osu.Game.Tests/Database/TestRealmKeyBindingStore.cs
index 642ecf00b8..8be74f1a7c 100644
--- a/osu.Game.Tests/Database/TestRealmKeyBindingStore.cs
+++ b/osu.Game.Tests/Database/TestRealmKeyBindingStore.cs
@@ -11,6 +11,7 @@ using osu.Framework.Platform;
using osu.Game.Database;
using osu.Game.Input;
using osu.Game.Input.Bindings;
+using osu.Game.Rulesets;
using Realms;
namespace osu.Game.Tests.Database
@@ -42,7 +43,7 @@ namespace osu.Game.Tests.Database
KeyBindingContainer testContainer = new TestKeyBindingContainer();
- keyBindingStore.Register(testContainer);
+ keyBindingStore.Register(testContainer, Enumerable.Empty());
Assert.That(queryCount(), Is.EqualTo(3));
@@ -66,7 +67,7 @@ namespace osu.Game.Tests.Database
{
KeyBindingContainer testContainer = new TestKeyBindingContainer();
- keyBindingStore.Register(testContainer);
+ keyBindingStore.Register(testContainer, Enumerable.Empty());
using (var primaryUsage = realmContextFactory.GetForRead())
{
diff --git a/osu.Game/Input/RealmKeyBindingStore.cs b/osu.Game/Input/RealmKeyBindingStore.cs
index 9089169877..03cb4031ca 100644
--- a/osu.Game/Input/RealmKeyBindingStore.cs
+++ b/osu.Game/Input/RealmKeyBindingStore.cs
@@ -46,52 +46,53 @@ namespace osu.Game.Input
}
///
- /// Register a new type of , adding default bindings from .
+ /// Register all defaults for this store.
///
/// The container to populate defaults from.
- public void Register(KeyBindingContainer container) => insertDefaults(container.DefaultKeyBindings);
-
- ///
- /// Register a ruleset, adding default bindings for each of its variants.
- ///
- /// The ruleset to populate defaults from.
- public void Register(RulesetInfo ruleset)
- {
- var instance = ruleset.CreateInstance();
-
- foreach (var variant in instance.AvailableVariants)
- insertDefaults(instance.GetDefaultKeyBindings(variant), ruleset.ID, variant);
- }
-
- private void insertDefaults(IEnumerable defaults, int? rulesetId = null, int? variant = null)
+ /// The rulesets to populate defaults from.
+ public void Register(KeyBindingContainer container, IEnumerable rulesets)
{
using (var usage = realmFactory.GetForWrite())
{
- // compare counts in database vs defaults
- foreach (var defaultsForAction in defaults.GroupBy(k => k.Action))
+ // intentionally flattened to a list rather than querying against the IQueryable, as nullable fields being queried against aren't indexed.
+ // this is much faster as a result.
+ var existingBindings = usage.Realm.All().ToList();
+
+ insertDefaults(usage, existingBindings, container.DefaultKeyBindings);
+
+ foreach (var ruleset in rulesets)
{
- int existingCount = usage.Realm.All().Count(k => k.RulesetID == rulesetId && k.Variant == variant && k.ActionInt == (int)defaultsForAction.Key);
-
- if (defaultsForAction.Count() <= existingCount)
- continue;
-
- foreach (var k in defaultsForAction.Skip(existingCount))
- {
- // insert any defaults which are missing.
- usage.Realm.Add(new RealmKeyBinding
- {
- KeyCombinationString = k.KeyCombination.ToString(),
- ActionInt = (int)k.Action,
- RulesetID = rulesetId,
- Variant = variant
- });
- }
+ var instance = ruleset.CreateInstance();
+ foreach (var variant in instance.AvailableVariants)
+ insertDefaults(usage, existingBindings, instance.GetDefaultKeyBindings(variant), ruleset.ID, variant);
}
usage.Commit();
}
}
+ private void insertDefaults(RealmContextFactory.RealmUsage usage, List existingBindings, IEnumerable defaults, int? rulesetId = null, int? variant = null)
+ {
+ // compare counts in database vs defaults for each action type.
+ foreach (var defaultsForAction in defaults.GroupBy(k => k.Action))
+ {
+ // avoid performing redundant queries when the database is empty and needs to be re-filled.
+ int existingCount = existingBindings.Count(k => k.RulesetID == rulesetId && k.Variant == variant && k.ActionInt == (int)defaultsForAction.Key);
+
+ if (defaultsForAction.Count() <= existingCount)
+ continue;
+
+ // insert any defaults which are missing.
+ usage.Realm.Add(defaultsForAction.Skip(existingCount).Select(k => new RealmKeyBinding
+ {
+ KeyCombinationString = k.KeyCombination.ToString(),
+ ActionInt = (int)k.Action,
+ RulesetID = rulesetId,
+ Variant = variant
+ }));
+ }
+ }
+
///
/// Keys which should not be allowed for gameplay input purposes.
///
diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs
index 762216e93c..c0d220007f 100644
--- a/osu.Game/OsuGameBase.cs
+++ b/osu.Game/OsuGameBase.cs
@@ -205,31 +205,7 @@ namespace osu.Game
dependencies.CacheAs(this);
dependencies.CacheAs(LocalConfig);
- AddFont(Resources, @"Fonts/osuFont");
-
- AddFont(Resources, @"Fonts/Torus/Torus-Regular");
- AddFont(Resources, @"Fonts/Torus/Torus-Light");
- AddFont(Resources, @"Fonts/Torus/Torus-SemiBold");
- AddFont(Resources, @"Fonts/Torus/Torus-Bold");
-
- AddFont(Resources, @"Fonts/Inter/Inter-Regular");
- AddFont(Resources, @"Fonts/Inter/Inter-RegularItalic");
- AddFont(Resources, @"Fonts/Inter/Inter-Light");
- AddFont(Resources, @"Fonts/Inter/Inter-LightItalic");
- AddFont(Resources, @"Fonts/Inter/Inter-SemiBold");
- AddFont(Resources, @"Fonts/Inter/Inter-SemiBoldItalic");
- AddFont(Resources, @"Fonts/Inter/Inter-Bold");
- AddFont(Resources, @"Fonts/Inter/Inter-BoldItalic");
-
- AddFont(Resources, @"Fonts/Noto/Noto-Basic");
- AddFont(Resources, @"Fonts/Noto/Noto-Hangul");
- AddFont(Resources, @"Fonts/Noto/Noto-CJK-Basic");
- AddFont(Resources, @"Fonts/Noto/Noto-CJK-Compatibility");
- AddFont(Resources, @"Fonts/Noto/Noto-Thai");
-
- AddFont(Resources, @"Fonts/Venera/Venera-Light");
- AddFont(Resources, @"Fonts/Venera/Venera-Bold");
- AddFont(Resources, @"Fonts/Venera/Venera-Black");
+ InitialiseFonts();
Audio.Samples.PlaybackConcurrency = SAMPLE_CONCURRENCY;
@@ -351,10 +327,7 @@ namespace osu.Game
base.Content.Add(CreateScalingContainer().WithChildren(mainContent));
KeyBindingStore = new RealmKeyBindingStore(realmFactory);
- KeyBindingStore.Register(globalBindings);
-
- foreach (var r in RulesetStore.AvailableRulesets)
- KeyBindingStore.Register(r);
+ KeyBindingStore.Register(globalBindings, RulesetStore.AvailableRulesets);
dependencies.Cache(globalBindings);
@@ -368,6 +341,35 @@ namespace osu.Game
Ruleset.BindValueChanged(onRulesetChanged);
}
+ protected virtual void InitialiseFonts()
+ {
+ AddFont(Resources, @"Fonts/osuFont");
+
+ AddFont(Resources, @"Fonts/Torus/Torus-Regular");
+ AddFont(Resources, @"Fonts/Torus/Torus-Light");
+ AddFont(Resources, @"Fonts/Torus/Torus-SemiBold");
+ AddFont(Resources, @"Fonts/Torus/Torus-Bold");
+
+ AddFont(Resources, @"Fonts/Inter/Inter-Regular");
+ AddFont(Resources, @"Fonts/Inter/Inter-RegularItalic");
+ AddFont(Resources, @"Fonts/Inter/Inter-Light");
+ AddFont(Resources, @"Fonts/Inter/Inter-LightItalic");
+ AddFont(Resources, @"Fonts/Inter/Inter-SemiBold");
+ AddFont(Resources, @"Fonts/Inter/Inter-SemiBoldItalic");
+ AddFont(Resources, @"Fonts/Inter/Inter-Bold");
+ AddFont(Resources, @"Fonts/Inter/Inter-BoldItalic");
+
+ AddFont(Resources, @"Fonts/Noto/Noto-Basic");
+ AddFont(Resources, @"Fonts/Noto/Noto-Hangul");
+ AddFont(Resources, @"Fonts/Noto/Noto-CJK-Basic");
+ AddFont(Resources, @"Fonts/Noto/Noto-CJK-Compatibility");
+ AddFont(Resources, @"Fonts/Noto/Noto-Thai");
+
+ AddFont(Resources, @"Fonts/Venera/Venera-Light");
+ AddFont(Resources, @"Fonts/Venera/Venera-Bold");
+ AddFont(Resources, @"Fonts/Venera/Venera-Black");
+ }
+
private IDisposable blocking;
private void updateThreadStateChanged(ValueChangedEvent state)
diff --git a/osu.Game/Tests/Visual/OsuTestScene.cs b/osu.Game/Tests/Visual/OsuTestScene.cs
index ef9181c8a6..03434961ea 100644
--- a/osu.Game/Tests/Visual/OsuTestScene.cs
+++ b/osu.Game/Tests/Visual/OsuTestScene.cs
@@ -367,6 +367,11 @@ namespace osu.Game.Tests.Visual
Add(runner = new TestSceneTestRunner.TestRunner());
}
+ protected override void InitialiseFonts()
+ {
+ // skip fonts load as it's not required for testing purposes.
+ }
+
public void RunTestBlocking(TestScene test) => runner.RunTestBlocking(test);
}
}
diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj
index ebe3de6ea4..ae423bac8c 100644
--- a/osu.Game/osu.Game.csproj
+++ b/osu.Game/osu.Game.csproj
@@ -37,7 +37,7 @@
-
+
diff --git a/osu.iOS.props b/osu.iOS.props
index 1714bae53c..be737392e1 100644
--- a/osu.iOS.props
+++ b/osu.iOS.props
@@ -71,7 +71,7 @@
-
+