diff --git a/sources/engine/Stride.Engine/Engine/Game.cs b/sources/engine/Stride.Engine/Engine/Game.cs index 456221c538..551650df74 100644 --- a/sources/engine/Stride.Engine/Engine/Game.cs +++ b/sources/engine/Stride.Engine/Engine/Game.cs @@ -11,6 +11,7 @@ using Stride.Core.IO; using Stride.Core.Mathematics; using Stride.Core.Storage; +using Stride.Data; using Stride.Engine.Design; using Stride.Engine.Processors; using Stride.Games; @@ -260,6 +261,8 @@ protected override void PrepareContext() // Init assets if (Context.InitializeDatabase) { + PlatformConfigurations.RendererName = GraphicsAdapterFactory.DefaultAdapter?.Description ?? string.Empty; + databaseFileProvider = InitializeAssetDatabase(); ((DatabaseFileProviderService)Services.GetService()).FileProvider = databaseFileProvider; diff --git a/sources/engine/Stride/Data/PlatformConfigurations.cs b/sources/engine/Stride/Data/PlatformConfigurations.cs index 0bfa551ce8..440b9c31c3 100644 --- a/sources/engine/Stride/Data/PlatformConfigurations.cs +++ b/sources/engine/Stride/Data/PlatformConfigurations.cs @@ -12,9 +12,8 @@ namespace Stride.Data [DataContract] public class PlatformConfigurations { - public static string RendererName = string.Empty; - - public static string DeviceModel = string.Empty; + /// String identifying the rendering device, used for configuration overrides. + public static string RendererName { get; set; } = string.Empty; [DataMember] public List Configurations = []; @@ -24,62 +23,47 @@ public class PlatformConfigurations public T Get() where T : Configuration, new() { - //find default - var config = Configurations.Where(x => x.Platforms == ConfigPlatforms.None).FirstOrDefault(x => x.Configuration is T); - - //perform logic by platform and if required even gpu/cpu/specs + // Find the default for all platforms and devices + var config = Configurations.Where(x => x.Platforms == ConfigPlatforms.None && x.SpecificFilter == -1).LastOrDefault(x => x.Configuration is T); - var platform = ConfigPlatforms.None; - switch (Platform.Type) - { - case PlatformType.Shared: - break; - case PlatformType.Windows: - platform = ConfigPlatforms.Windows; - break; - case PlatformType.Android: - platform = ConfigPlatforms.Android; - break; - case PlatformType.iOS: - platform = ConfigPlatforms.iOS; - break; - case PlatformType.UWP: - platform = ConfigPlatforms.UWP; - break; - case PlatformType.Linux: - platform = ConfigPlatforms.Linux; - break; - case PlatformType.macOS: - platform = ConfigPlatforms.macOS; - break; - default: - throw new ArgumentOutOfRangeException(); - } + // Try finding one for the specific platform or hardware configuration - //find per platform if available - var platformConfig = Configurations.Where(x => x.Platforms.HasFlag(platform) && x.SpecificFilter == -1).FirstOrDefault(x => x.Configuration is T); - if (platformConfig != null) + var platform = Platform.Type switch { - config = platformConfig; - } + PlatformType.Shared => ConfigPlatforms.None, + PlatformType.Windows => ConfigPlatforms.Windows, + PlatformType.Android => ConfigPlatforms.Android, + PlatformType.iOS => ConfigPlatforms.iOS, + PlatformType.UWP => ConfigPlatforms.UWP, + PlatformType.Linux => ConfigPlatforms.Linux, + PlatformType.macOS => ConfigPlatforms.macOS, + _ => throw new ArgumentOutOfRangeException(), + }; - //find per specific renderer settings - platformConfig = Configurations.Where(x => x.Platforms.HasFlag(platform) && x.SpecificFilter != -1 && new Regex(PlatformFilters[x.SpecificFilter], RegexOptions.IgnoreCase).IsMatch(RendererName)).FirstOrDefault(x => x.Configuration is T); - if (platformConfig != null) + // Find per platform if available + if (Configurations.Where(x => x.Platforms.HasFlag(platform) && x.SpecificFilter == -1) + .LastOrDefault(x => x.Configuration is T) is { } platformConfig) { config = platformConfig; } - //find per specific device settings - platformConfig = Configurations.Where(x => x.Platforms.HasFlag(platform) && x.SpecificFilter != -1 && new Regex(PlatformFilters[x.SpecificFilter], RegexOptions.IgnoreCase).IsMatch(DeviceModel)).FirstOrDefault(x => x.Configuration is T); - if (platformConfig != null) + // Find per specific renderer + if (Configurations.Where(x => x.Platforms.HasFlag(platform) && x.SpecificFilter != -1 && new Regex(PlatformFilters[x.SpecificFilter], RegexOptions.IgnoreCase).IsMatch(RendererName)) + .LastOrDefault(x => x.Configuration is T) is { } rendererConfig) { - config = platformConfig; + config = rendererConfig; } if (config == null) { - return new T(); + // If the requested configuration doesn't exist, create and add a new one + var newInstance = new T(); + Configurations.Add(new() + { + Configuration = newInstance, + }); + + return newInstance; } return (T)config.Configuration;