Skip to content

Commit 8bda67d

Browse files
committed
fix: Store DirectX feature level as the enum internally for performance
This has impact on performance because the Enum.Parse function allocates a lot of memory each time it is called, so instead of calling that repeatedly it is now only called when the feature level is set. This results in a drop of 21% in TOTAL allocations in a simple profiling run (load activity and exit after 1000 frames are rendered), and a drop of 57% (!) in allocations post-loading.
1 parent 0dc5a2c commit 8bda67d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Source/ORTS.Settings/UserSettings.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public enum AntiAliasingMethod
123123

124124
public enum DirectXFeature
125125
{
126+
Level /* Default value which gets replaced with what is supported */,
126127
Level9_1,
127128
Level9_3,
128129
Level10_0,
@@ -364,8 +365,13 @@ public enum DirectXFeature
364365
[Default("")]
365366
public string ScreenshotPath { get; set; }
366367
[Default("")]
367-
public string DirectXFeatureLevel { get; set; }
368-
public bool IsDirectXFeatureLevelIncluded(DirectXFeature level) => (int)level <= (int)Enum.Parse(typeof(DirectXFeature), "Level" + this.DirectXFeatureLevel);
368+
public string DirectXFeatureLevel
369+
{
370+
get => DirectXFeatureEnum.ToString().Replace("Level", "");
371+
set => DirectXFeatureEnum = (DirectXFeature)Enum.Parse(typeof(DirectXFeature), "Level" + value);
372+
}
373+
DirectXFeature DirectXFeatureEnum;
374+
public bool IsDirectXFeatureLevelIncluded(DirectXFeature level) => level <= DirectXFeatureEnum;
369375
[Default(true)]
370376
public bool ShadowMapBlur { get; set; }
371377
[Default(4)]

0 commit comments

Comments
 (0)