mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-12-03 02:05:18 +01:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9583117eea |
@@ -14,7 +14,7 @@ public class SoftwareRenderTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Without_the_switch_it_is_not_asked_for()
|
public void Without_the_switch_the_graphics_card_draws()
|
||||||
{
|
{
|
||||||
Assert.False(SoftwareRender.AskedIn(Array.Empty<string>()));
|
Assert.False(SoftwareRender.AskedIn(Array.Empty<string>()));
|
||||||
Assert.False(SoftwareRender.AskedIn(new[] { "--software" }));
|
Assert.False(SoftwareRender.AskedIn(new[] { "--software" }));
|
||||||
@@ -25,25 +25,21 @@ public class SoftwareRenderTests
|
|||||||
{
|
{
|
||||||
var options = SoftwareRender.Win32Options;
|
var options = SoftwareRender.Win32Options;
|
||||||
|
|
||||||
// No WinUI composition, DirectComposition or swap chain of the graphics card's.
|
|
||||||
Assert.Equal(new[] { Win32RenderingMode.Software }, options.RenderingMode);
|
Assert.Equal(new[] { Win32RenderingMode.Software }, options.RenderingMode);
|
||||||
Assert.Equal(new[] { Win32CompositionMode.RedirectionSurface }, options.CompositionMode);
|
Assert.Equal(new[] { Win32CompositionMode.RedirectionSurface }, options.CompositionMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void X11_draws_on_the_processor_when_asked()
|
public void X11_draws_on_the_processor()
|
||||||
{
|
{
|
||||||
Assert.Equal(new[] { X11RenderingMode.Software }, SoftwareRender.X11Options.RenderingMode);
|
Assert.Equal(new[] { X11RenderingMode.Software }, SoftwareRender.X11Options.RenderingMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Fact]
|
||||||
[InlineData(false)]
|
public void Both_platforms_options_go_to_the_same_builder()
|
||||||
[InlineData(true)]
|
|
||||||
public void The_options_go_to_the_same_builder_with_or_without_the_switch(bool asked)
|
|
||||||
{
|
{
|
||||||
var builder = AppBuilder.Configure<Avalonia.Application>();
|
var builder = AppBuilder.Configure<Avalonia.Application>();
|
||||||
string[] args = asked ? new[] { SoftwareRender.Switch } : Array.Empty<string>();
|
|
||||||
|
|
||||||
Assert.Same(builder, SoftwareRender.ApplyTo(builder, args));
|
Assert.Same(builder, SoftwareRender.ApplyTo(builder));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,6 +79,20 @@ public class TrainsetDisplayTests
|
|||||||
Assert.True(TrainsetDisplay.StartableIn(decor, Mode(advanced: true)));
|
Assert.True(TrainsetDisplay.StartableIn(decor, Mode(advanced: true)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void The_standard_mode_changes_the_crew_but_not_in_the_simulators_own_consists()
|
||||||
|
{
|
||||||
|
var standard = Mode(advanced: false);
|
||||||
|
var decor = new Trainset("trainset a tor 0 0 //$decor\nnode -1 0 v1 dynamic d s m 0 headdriver 3 0 enddynamic\nendtrainset");
|
||||||
|
|
||||||
|
Assert.True(TrainsetDisplay.CrewEditableIn(Consist(), standard));
|
||||||
|
Assert.True(TrainsetDisplay.CrewEditableIn(Consist(driver: "nobody"), standard));
|
||||||
|
Assert.True(TrainsetDisplay.CrewEditableIn(null, standard));
|
||||||
|
Assert.False(TrainsetDisplay.CrewEditableIn(Consist(description: "-ai"), standard));
|
||||||
|
Assert.False(TrainsetDisplay.CrewEditableIn(decor, standard));
|
||||||
|
Assert.True(TrainsetDisplay.CrewEditableIn(Consist(description: "-ai"), Mode(advanced: true)));
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void The_filters_work_in_the_advanced_mode()
|
public void The_filters_work_in_the_advanced_mode()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
using Avalonia;
|
||||||
|
using StarterNG.Infrastructure;
|
||||||
|
|
||||||
|
namespace StarterNG.Tests;
|
||||||
|
|
||||||
|
public class WindowSurfacesTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Windows_draws_into_a_directcomposition_surface_and_never_through_winui_composition()
|
||||||
|
{
|
||||||
|
var options = WindowSurfaces.Win32Options;
|
||||||
|
|
||||||
|
Assert.Equal(Win32CompositionMode.DirectComposition, options.CompositionMode.First());
|
||||||
|
Assert.DoesNotContain(Win32CompositionMode.WinUIComposition, options.CompositionMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void The_window_surface_is_only_the_fallback()
|
||||||
|
{
|
||||||
|
// There ANGLE presents through a swap chain, and the Steam overlay draws over it.
|
||||||
|
Assert.Equal(Win32CompositionMode.RedirectionSurface, WindowSurfaces.Win32Options.CompositionMode.Last());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void No_swap_chain_of_its_own_is_asked_for()
|
||||||
|
{
|
||||||
|
Assert.DoesNotContain(Win32CompositionMode.LowLatencyDxgiSwapChain, WindowSurfaces.Win32Options.CompositionMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void The_graphics_card_still_draws()
|
||||||
|
{
|
||||||
|
Assert.Equal(new Win32PlatformOptions().RenderingMode, WindowSurfaces.Win32Options.RenderingMode);
|
||||||
|
Assert.Contains(Win32RenderingMode.AngleEgl, WindowSurfaces.Win32Options.RenderingMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(false)]
|
||||||
|
[InlineData(true)]
|
||||||
|
public void The_options_go_to_the_same_builder_with_or_without_the_processor(bool softwareRender)
|
||||||
|
{
|
||||||
|
var builder = AppBuilder.Configure<Avalonia.Application>();
|
||||||
|
|
||||||
|
Assert.Same(builder, WindowSurfaces.ApplyTo(builder, softwareRender));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -52,6 +52,14 @@ public static class TrainsetDisplay
|
|||||||
public static bool StartableIn(Trainset trainset, SimulatorSettings settings) =>
|
public static bool StartableIn(Trainset trainset, SimulatorSettings settings) =>
|
||||||
settings.AdvancedSettings || (!IsAi(trainset) && !trainset.Decor);
|
settings.AdvancedSettings || (!IsAi(trainset) && !trainset.Decor);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether the crew of the consist being edited may be changed: in the standard mode
|
||||||
|
/// only in one the player may start in - the simulator's own consists and the
|
||||||
|
/// decorations keep the crew the scenario gave them.
|
||||||
|
/// </summary>
|
||||||
|
public static bool CrewEditableIn(Trainset? trainset, SimulatorSettings settings) =>
|
||||||
|
trainset is null || StartableIn(trainset, settings);
|
||||||
|
|
||||||
/// <summary>The consist's row in those lists: what it is made of, or the track of one with nothing on it.</summary>
|
/// <summary>The consist's row in those lists: what it is made of, or the track of one with nothing on it.</summary>
|
||||||
public static string ListLabel(Trainset trainset) =>
|
public static string ListLabel(Trainset trainset) =>
|
||||||
CompositionText(trainset) ?? string.Format(App.Loc["EmptyTrainset"], trainset.Track ?? "");
|
CompositionText(trainset) ?? string.Format(App.Loc["EmptyTrainset"], trainset.Track ?? "");
|
||||||
|
|||||||
@@ -6,15 +6,8 @@ using Avalonia;
|
|||||||
namespace StarterNG.Infrastructure;
|
namespace StarterNG.Infrastructure;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// On Windows the processor draws the starter's windows, and each frame is copied into its window
|
/// Drawn by the processor instead of the graphics card, for a machine on which the
|
||||||
/// by GDI. Every way of the graphics card's failed on some machine: Avalonia's WinUI composition
|
/// window comes up empty. Each platform reads only its own options, so both are given.
|
||||||
/// visual left windows black on Windows 11 25H2, the Steam overlay drew its frame counter over a
|
|
||||||
/// window's own swap chain, and with DirectComposition the starter vanished a few seconds after its
|
|
||||||
/// window came up on a Windows 10 machine with a GTX 1650, without a word in its log. A frame copied
|
|
||||||
/// by GDI has no swap chain for an overlay to hook, and lists, text and pictures are no work for the
|
|
||||||
/// processor.
|
|
||||||
/// On X11 the graphics card draws, unless <see cref="Switch"/> asks the processor, for a machine on
|
|
||||||
/// which the window comes up empty. Each platform reads only its own options.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class SoftwareRender
|
public static class SoftwareRender
|
||||||
{
|
{
|
||||||
@@ -34,9 +27,6 @@ public static class SoftwareRender
|
|||||||
RenderingMode = new[] { X11RenderingMode.Software }
|
RenderingMode = new[] { X11RenderingMode.Software }
|
||||||
};
|
};
|
||||||
|
|
||||||
public static AppBuilder ApplyTo(AppBuilder builder, IEnumerable<string> args)
|
public static AppBuilder ApplyTo(AppBuilder builder) =>
|
||||||
{
|
builder.With(Win32Options).With(X11Options);
|
||||||
builder.With(Win32Options);
|
|
||||||
return AskedIn(args) ? builder.With(X11Options) : builder;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using Avalonia;
|
||||||
|
|
||||||
|
namespace StarterNG.Infrastructure;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// On Windows the graphics card draws each window of the starter into a DirectComposition
|
||||||
|
/// surface, not into Avalonia's default WinUI composition visual. On Windows 11 25H2 that
|
||||||
|
/// visual was left empty on many starts: the main window, or a dialog opened later,
|
||||||
|
/// stayed black while the others drew, and came back only now and then.
|
||||||
|
/// The window's own redirection surface is only the fallback: there ANGLE draws through a
|
||||||
|
/// swap chain of the window, and the Steam overlay, which Steam puts into the starter as
|
||||||
|
/// the game it launches, hooks that swap chain's Present and draws its frame counter and
|
||||||
|
/// notifications over the starter. A composition surface is drawn without a Present.
|
||||||
|
/// </summary>
|
||||||
|
public static class WindowSurfaces
|
||||||
|
{
|
||||||
|
public static Win32PlatformOptions Win32Options => new()
|
||||||
|
{
|
||||||
|
CompositionMode = new[]
|
||||||
|
{
|
||||||
|
Win32CompositionMode.DirectComposition,
|
||||||
|
Win32CompositionMode.RedirectionSurface
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The options a platform reads are the last given, so the processor, when asked
|
||||||
|
/// for, draws with <see cref="SoftwareRender"/>'s own and these are left out.
|
||||||
|
/// </summary>
|
||||||
|
public static AppBuilder ApplyTo(AppBuilder builder, bool softwareRender) =>
|
||||||
|
softwareRender ? SoftwareRender.ApplyTo(builder) : builder.With(Win32Options);
|
||||||
|
}
|
||||||
@@ -10,8 +10,7 @@ namespace StarterNG;
|
|||||||
static class Program
|
static class Program
|
||||||
{
|
{
|
||||||
|
|
||||||
// What --software-render is looked for in; none for the designer, which calls BuildAvaloniaApp itself.
|
private static bool _softwareRender;
|
||||||
private static string[] _args = Array.Empty<string>();
|
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
@@ -20,7 +19,7 @@ static class Program
|
|||||||
var graphics = SystemGraphicsLibraries.TakeOnWindows();
|
var graphics = SystemGraphicsLibraries.TakeOnWindows();
|
||||||
graphics?.ServeTo(typeof(Win32PlatformOptions).Assembly);
|
graphics?.ServeTo(typeof(Win32PlatformOptions).Assembly);
|
||||||
|
|
||||||
_args = args;
|
_softwareRender = SoftwareRender.AskedIn(args);
|
||||||
|
|
||||||
// Composition root first: everything below, including the crash handlers,
|
// Composition root first: everything below, including the crash handlers,
|
||||||
// resolves its collaborators from this graph.
|
// resolves its collaborators from this graph.
|
||||||
@@ -74,14 +73,14 @@ static class Program
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// On Windows the processor draws; on X11 the graphics card, unless --software-render.
|
// Without the switch the graphics card draws, into the window surfaces.
|
||||||
private static AppBuilder WithSoftwareRender(this AppBuilder builder) =>
|
private static AppBuilder WithSoftwareRenderIfAsked(this AppBuilder builder) =>
|
||||||
SoftwareRender.ApplyTo(builder, _args);
|
WindowSurfaces.ApplyTo(builder, _softwareRender);
|
||||||
|
|
||||||
public static AppBuilder BuildAvaloniaApp()
|
public static AppBuilder BuildAvaloniaApp()
|
||||||
=> AppBuilder.Configure<App>()
|
=> AppBuilder.Configure<App>()
|
||||||
.UsePlatformDetect()
|
.UsePlatformDetect()
|
||||||
.WithSoftwareRender()
|
.WithSoftwareRenderIfAsked()
|
||||||
.WithInterFont()
|
.WithInterFont()
|
||||||
.WithDiagnosticsLogging()
|
.WithDiagnosticsLogging()
|
||||||
.AfterSetup(_ => LogUiExceptions());
|
.AfterSetup(_ => LogUiExceptions());
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public partial class Depot : UserControl
|
|||||||
if (Design.IsDesignMode)
|
if (Design.IsDesignMode)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// The standard mode lists other consists and leaves the crew alone.
|
// The standard mode lists other consists and leaves the crew of the simulator's own alone.
|
||||||
Settings.AdvancedModeChanged += () =>
|
Settings.AdvancedModeChanged += () =>
|
||||||
{
|
{
|
||||||
PopulateSceneryConsists();
|
PopulateSceneryConsists();
|
||||||
|
|||||||
@@ -49,6 +49,9 @@ public sealed class VehicleCards
|
|||||||
|
|
||||||
public Dynamic? PressedCar { get; set; }
|
public Dynamic? PressedCar { get; set; }
|
||||||
|
|
||||||
|
private bool CrewEditable =>
|
||||||
|
TrainsetDisplay.CrewEditableIn(_consist.EditingTrainset, AppServices.Current.Settings);
|
||||||
|
|
||||||
public VehicleCards(Panel consistStack, VehicleCatalog db, Consist consist,
|
public VehicleCards(Panel consistStack, VehicleCatalog db, Consist consist,
|
||||||
Cargo cargo, MiniTextures minis, Cursor hand,
|
Cargo cargo, MiniTextures minis, Cursor hand,
|
||||||
Action redraw, Action refreshDetails, Action<Dynamic> selectInBrowser,
|
Action redraw, Action refreshDetails, Action<Dynamic> selectInBrowser,
|
||||||
@@ -117,8 +120,8 @@ public sealed class VehicleCards
|
|||||||
HorizontalAlignment = HorizontalAlignment.Center,
|
HorizontalAlignment = HorizontalAlignment.Center,
|
||||||
Margin = new Thickness(0, 1, 0, 2)
|
Margin = new Thickness(0, 1, 0, 2)
|
||||||
};
|
};
|
||||||
// Who sits in the cab - the player, the simulator, a passenger or nobody - is for the advanced mode.
|
// Who sits in the cab; in the standard mode not in the simulator's own consists.
|
||||||
if (AppServices.Current.Settings.AdvancedSettings)
|
if (CrewEditable)
|
||||||
controls.Children.Add(DriverButton(item));
|
controls.Children.Add(DriverButton(item));
|
||||||
controls.Children.Add(FlipButton(item));
|
controls.Children.Add(FlipButton(item));
|
||||||
|
|
||||||
@@ -695,7 +698,7 @@ public sealed class VehicleCards
|
|||||||
else if (_consist.CanJoin(item, index))
|
else if (_consist.CanJoin(item, index))
|
||||||
menu.AddItem(App.Loc["TipJoin"], () => _consist.Join(item));
|
menu.AddItem(App.Loc["TipJoin"], () => _consist.Join(item));
|
||||||
|
|
||||||
if (AppServices.Current.Settings.AdvancedSettings)
|
if (CrewEditable)
|
||||||
{
|
{
|
||||||
var crew = new MenuItem { Header = App.Loc["CrewLabel"] };
|
var crew = new MenuItem { Header = App.Loc["CrewLabel"] };
|
||||||
foreach (var (type, key) in CrewChoices.All)
|
foreach (var (type, key) in CrewChoices.All)
|
||||||
|
|||||||
@@ -280,8 +280,8 @@ public sealed class VehicleDetails
|
|||||||
};
|
};
|
||||||
driver.MinWidth = 0;
|
driver.MinWidth = 0;
|
||||||
driver.HorizontalAlignment = HorizontalAlignment.Stretch;
|
driver.HorizontalAlignment = HorizontalAlignment.Stretch;
|
||||||
// Shown but not changed in the standard mode: who drives is for the advanced one.
|
// Shown but not changed in the standard mode in the simulator's own consists.
|
||||||
driver.IsEnabled = AppServices.Current.Settings.AdvancedSettings;
|
driver.IsEnabled = TrainsetDisplay.CrewEditableIn(_consist.EditingTrainset, AppServices.Current.Settings);
|
||||||
|
|
||||||
var rows = new StackPanel();
|
var rows = new StackPanel();
|
||||||
rows.Children.Add(Row(App.Loc["CrewLabel"], driver));
|
rows.Children.Add(Row(App.Loc["CrewLabel"], driver));
|
||||||
|
|||||||
Reference in New Issue
Block a user