Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sources/engine/Stride.Engine/Engine/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<IDatabaseFileProviderService>()).FileProvider = databaseFileProvider;

Expand Down
76 changes: 30 additions & 46 deletions sources/engine/Stride/Data/PlatformConfigurations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ namespace Stride.Data
[DataContract]
public class PlatformConfigurations
{
public static string RendererName = string.Empty;

public static string DeviceModel = string.Empty;
/// <summary>String identifying the rendering device, used for configuration overrides.</summary>
public static string RendererName { get; set; } = string.Empty;

[DataMember]
public List<ConfigurationOverride> Configurations = [];
Expand All @@ -24,62 +23,47 @@ public class PlatformConfigurations

public T Get<T>() 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;
Expand Down