Skip to content

Commit eb66f76

Browse files
committed
Game: add option to control whether to show window or not. This prevents graphics unit tests to disrupt user computer.
1 parent a12f7ea commit eb66f76

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

sources/engine/Stride.Games/Desktop/WindowsMessageLoop.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ public static void Run(Control form, RenderCallback renderCallback, bool useAppl
212212
if (form == null) throw new ArgumentNullException("form");
213213
if (renderCallback == null) throw new ArgumentNullException("renderCallback");
214214

215-
form.Show();
216215
using (var renderLoop = new WindowsMessageLoop(form) { UseApplicationDoEvents = useApplicationDoEvents })
217216
{
218217
while (renderLoop.NextFrame())

sources/engine/Stride.Games/GameBase.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ protected GameBase()
218218
/// <value><c>true</c> if this instance forces one update step per one draw step; otherwise, <c>false</c>.</value>
219219
protected internal bool ForceOneUpdatePerDraw { get; set; }
220220

221+
/// <summary>
222+
/// Specifies if <see cref="GameWindow.Visible"/> is set to true during <see cref="Run(GameContext)"/>.
223+
/// Only valid when <see cref="GameContext.IsUserManagingRun"/> is false.
224+
/// </summary>
225+
protected bool MakeWindowVisibleOnRun { get; set; } = true;
226+
221227
/// <summary>
222228
/// When <see cref="IsFixedTimeStep"/> is set, is it allowed to render frames between two steps when we have time to do so.
223229
/// </summary>
@@ -891,6 +897,8 @@ protected virtual void OnWindowCreated()
891897
private void GamePlatformOnWindowCreated(object sender, EventArgs eventArgs)
892898
{
893899
Window.IsMouseVisible = isMouseVisible;
900+
if (MakeWindowVisibleOnRun && !Context.IsUserManagingRun)
901+
Window.Visible = true;
894902
OnWindowCreated();
895903
}
896904

sources/engine/Stride.Games/SDL/SDLMessageLoop.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ public static void Run(Window form, RenderCallback renderCallback)
137137
if (form == null) throw new ArgumentNullException(nameof(form));
138138
if (renderCallback == null) throw new ArgumentNullException(nameof(renderCallback));
139139

140-
form.Show();
141140
using (var renderLoop = new SDLMessageLoop(form))
142141
{
143142
while (renderLoop.NextFrame())

sources/engine/Stride.Graphics.Regression/GameTestBase.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ protected GameTestBase()
163163

164164
// by default we want the same size for the back buffer on mobiles and windows.
165165
BackBufferSizeMode = BackBufferSizeMode.FitToDesiredValues;
166+
167+
// Only make window visible in interactive mode,
168+
// otherwise it's quite disrupting for user: new window might display on top and steal focus
169+
MakeWindowVisibleOnRun = ForceInteractiveMode;
166170
}
167171

168172
/// <inheritdoc />
@@ -189,7 +193,6 @@ protected override void Initialize()
189193
SceneSystem.SplashScreenEnabled = false;
190194
}
191195

192-
193196
/// <summary>
194197
/// Saves a Texture locally or on the test server.
195198
/// </summary>
@@ -366,6 +369,16 @@ private void FitPresentationParametersToWindowRatio(int windowWidth, int windowH
366369
}
367370
#endif
368371

372+
protected override void OnWindowCreated()
373+
{
374+
base.OnWindowCreated();
375+
376+
// Disabled for SDL as a position of (0,0) actually means that the client area of the
377+
// window will be at (0,0) not the top left corner of the non-client area of the window.
378+
if (Context.ContextType != AppContextType.DesktopSDL)
379+
Window.Position = Int2.Zero; // avoid possible side effects due to position of the window in the screen.
380+
}
381+
369382
/// <inheritdoc/>
370383
protected override async Task LoadContent()
371384
{
@@ -388,12 +401,6 @@ protected override async Task LoadContent()
388401
if (!ForceInteractiveMode)
389402
InitializeSimulatedInputSource();
390403

391-
#if !STRIDE_UI_SDL
392-
// Disabled for SDL as a position of (0,0) actually means that the client area of the
393-
// window will be at (0,0) not the top left corner of the non-client area of the window.
394-
Window.Position = Int2.Zero; // avoid possible side effects due to position of the window in the screen.
395-
#endif
396-
397404
Script.AddTask(RegisterTestsInternal);
398405

399406
//

0 commit comments

Comments
 (0)