mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-12-03 18:24:38 +01:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 381c815528 | |||
| 6d81ec700d | |||
| 705f2049fd | |||
| 9583117eea | |||
| dc1f43d385 |
@@ -14,7 +14,7 @@ public class SoftwareRenderTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Without_the_switch_the_graphics_card_draws()
|
||||
public void Without_the_switch_it_is_not_asked_for()
|
||||
{
|
||||
Assert.False(SoftwareRender.AskedIn(Array.Empty<string>()));
|
||||
Assert.False(SoftwareRender.AskedIn(new[] { "--software" }));
|
||||
@@ -25,21 +25,25 @@ public class SoftwareRenderTests
|
||||
{
|
||||
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[] { Win32CompositionMode.RedirectionSurface }, options.CompositionMode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void X11_draws_on_the_processor()
|
||||
public void X11_draws_on_the_processor_when_asked()
|
||||
{
|
||||
Assert.Equal(new[] { X11RenderingMode.Software }, SoftwareRender.X11Options.RenderingMode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Both_platforms_options_go_to_the_same_builder()
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public void The_options_go_to_the_same_builder_with_or_without_the_switch(bool asked)
|
||||
{
|
||||
var builder = AppBuilder.Configure<Avalonia.Application>();
|
||||
string[] args = asked ? new[] { SoftwareRender.Switch } : Array.Empty<string>();
|
||||
|
||||
Assert.Same(builder, SoftwareRender.ApplyTo(builder));
|
||||
Assert.Same(builder, SoftwareRender.ApplyTo(builder, args));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +79,20 @@ public class TrainsetDisplayTests
|
||||
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]
|
||||
public void The_filters_work_in_the_advanced_mode()
|
||||
{
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
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) =>
|
||||
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>
|
||||
public static string ListLabel(Trainset trainset) =>
|
||||
CompositionText(trainset) ?? string.Format(App.Loc["EmptyTrainset"], trainset.Track ?? "");
|
||||
|
||||
@@ -6,8 +6,15 @@ using Avalonia;
|
||||
namespace StarterNG.Infrastructure;
|
||||
|
||||
/// <summary>
|
||||
/// Drawn by the processor instead of the graphics card, for a machine on which the
|
||||
/// window comes up empty. Each platform reads only its own options, so both are given.
|
||||
/// On Windows the processor draws the starter's windows, and each frame is copied into its window
|
||||
/// by GDI. Every way of the graphics card's failed on some machine: Avalonia's WinUI composition
|
||||
/// 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>
|
||||
public static class SoftwareRender
|
||||
{
|
||||
@@ -27,6 +34,9 @@ public static class SoftwareRender
|
||||
RenderingMode = new[] { X11RenderingMode.Software }
|
||||
};
|
||||
|
||||
public static AppBuilder ApplyTo(AppBuilder builder) =>
|
||||
builder.With(Win32Options).With(X11Options);
|
||||
public static AppBuilder ApplyTo(AppBuilder builder, IEnumerable<string> args)
|
||||
{
|
||||
builder.With(Win32Options);
|
||||
return AskedIn(args) ? builder.With(X11Options) : builder;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
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,7 +10,8 @@ namespace StarterNG;
|
||||
static class Program
|
||||
{
|
||||
|
||||
private static bool _softwareRender;
|
||||
// What --software-render is looked for in; none for the designer, which calls BuildAvaloniaApp itself.
|
||||
private static string[] _args = Array.Empty<string>();
|
||||
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
@@ -19,7 +20,7 @@ static class Program
|
||||
var graphics = SystemGraphicsLibraries.TakeOnWindows();
|
||||
graphics?.ServeTo(typeof(Win32PlatformOptions).Assembly);
|
||||
|
||||
_softwareRender = SoftwareRender.AskedIn(args);
|
||||
_args = args;
|
||||
|
||||
// Composition root first: everything below, including the crash handlers,
|
||||
// resolves its collaborators from this graph.
|
||||
@@ -73,14 +74,14 @@ static class Program
|
||||
};
|
||||
}
|
||||
|
||||
// Without the switch the graphics card draws, into the window surfaces.
|
||||
private static AppBuilder WithSoftwareRenderIfAsked(this AppBuilder builder) =>
|
||||
WindowSurfaces.ApplyTo(builder, _softwareRender);
|
||||
// On Windows the processor draws; on X11 the graphics card, unless --software-render.
|
||||
private static AppBuilder WithSoftwareRender(this AppBuilder builder) =>
|
||||
SoftwareRender.ApplyTo(builder, _args);
|
||||
|
||||
public static AppBuilder BuildAvaloniaApp()
|
||||
=> AppBuilder.Configure<App>()
|
||||
.UsePlatformDetect()
|
||||
.WithSoftwareRenderIfAsked()
|
||||
.WithSoftwareRender()
|
||||
.WithInterFont()
|
||||
.WithDiagnosticsLogging()
|
||||
.AfterSetup(_ => LogUiExceptions());
|
||||
|
||||
@@ -69,7 +69,7 @@ public partial class Depot : UserControl
|
||||
if (Design.IsDesignMode)
|
||||
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 += () =>
|
||||
{
|
||||
PopulateSceneryConsists();
|
||||
|
||||
@@ -49,6 +49,9 @@ public sealed class VehicleCards
|
||||
|
||||
public Dynamic? PressedCar { get; set; }
|
||||
|
||||
private bool CrewEditable =>
|
||||
TrainsetDisplay.CrewEditableIn(_consist.EditingTrainset, AppServices.Current.Settings);
|
||||
|
||||
public VehicleCards(Panel consistStack, VehicleCatalog db, Consist consist,
|
||||
Cargo cargo, MiniTextures minis, Cursor hand,
|
||||
Action redraw, Action refreshDetails, Action<Dynamic> selectInBrowser,
|
||||
@@ -117,8 +120,8 @@ public sealed class VehicleCards
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
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.
|
||||
if (AppServices.Current.Settings.AdvancedSettings)
|
||||
// Who sits in the cab; in the standard mode not in the simulator's own consists.
|
||||
if (CrewEditable)
|
||||
controls.Children.Add(DriverButton(item));
|
||||
controls.Children.Add(FlipButton(item));
|
||||
|
||||
@@ -695,7 +698,7 @@ public sealed class VehicleCards
|
||||
else if (_consist.CanJoin(item, index))
|
||||
menu.AddItem(App.Loc["TipJoin"], () => _consist.Join(item));
|
||||
|
||||
if (AppServices.Current.Settings.AdvancedSettings)
|
||||
if (CrewEditable)
|
||||
{
|
||||
var crew = new MenuItem { Header = App.Loc["CrewLabel"] };
|
||||
foreach (var (type, key) in CrewChoices.All)
|
||||
|
||||
@@ -280,8 +280,8 @@ public sealed class VehicleDetails
|
||||
};
|
||||
driver.MinWidth = 0;
|
||||
driver.HorizontalAlignment = HorizontalAlignment.Stretch;
|
||||
// Shown but not changed in the standard mode: who drives is for the advanced one.
|
||||
driver.IsEnabled = AppServices.Current.Settings.AdvancedSettings;
|
||||
// Shown but not changed in the standard mode in the simulator's own consists.
|
||||
driver.IsEnabled = TrainsetDisplay.CrewEditableIn(_consist.EditingTrainset, AppServices.Current.Settings);
|
||||
|
||||
var rows = new StackPanel();
|
||||
rows.Children.Add(Row(App.Loc["CrewLabel"], driver));
|
||||
|
||||
Reference in New Issue
Block a user