Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requirements for fully custom Game runtime management #2404

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions sources/engine/Stride.Engine/Engine/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,9 @@ protected virtual Task LoadContent()
return Task.FromResult(true);
}

internal override void LoadContentInternal()
public override void LoadContentDefault()
{
base.LoadContentInternal();
base.LoadContentDefault();
Script.AddTask(LoadContent);
}
protected virtual LogListener GetLogListener()
Expand Down
4 changes: 2 additions & 2 deletions sources/engine/Stride.Games/Desktop/GamePlatformDesktop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

namespace Stride.Games
{
internal class GamePlatformDesktop : GamePlatform
public class GamePlatformDesktop : GamePlatform
{
public GamePlatformDesktop(GameBase game) : base(game)
{
Expand All @@ -51,7 +51,7 @@ public override string DefaultAppDirectory
}
}

internal override GameWindow GetSupportedGameWindow(AppContextType type)
public override GameWindow GetSupportedGameWindow(AppContextType type)
{
switch (type)
{
Expand Down
6 changes: 3 additions & 3 deletions sources/engine/Stride.Games/Desktop/GameWindowWinforms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public override void EndScreenDeviceChange(int clientWidth, int clientHeight)
deviceChangeWillBeFullScreen = null;
}

protected internal override void SetSupportedOrientations(DisplayOrientation orientations)
public override void SetSupportedOrientations(DisplayOrientation orientations)
{
// Desktop doesn't have orientation (unless on Windows 8?)
}
Expand Down Expand Up @@ -166,7 +166,7 @@ protected override void Initialize(GameContext<Control> gameContext)
}
}

internal override void Run()
public override void Run()
{
Debug.Assert(InitCallback != null, $"{nameof(InitCallback)} is null");
Debug.Assert(RunCallback != null, $"{nameof(RunCallback)} is null");
Expand Down Expand Up @@ -298,7 +298,7 @@ protected override void SetTitle(string title)
}
}

internal override void Resize(int width, int height)
public override void Resize(int width, int height)
{
Control.ClientSize = new Size(width, height);
}
Expand Down
16 changes: 8 additions & 8 deletions sources/engine/Stride.Games/GameBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public abstract class GameBase : ComponentBase, IGame

private bool isMouseVisible;

internal object TickLock = new object();
public object TickLock = new object();

#endregion

Expand All @@ -68,7 +68,7 @@ public abstract class GameBase : ComponentBase, IGame
/// <summary>
/// Initializes a new instance of the <see cref="GameBase" /> class.
/// </summary>
protected GameBase()
protected GameBase(GamePlatform platform = null)
{
// Internals
Log = GlobalLogger.GetLogger(GetType().GetTypeInfo().Name);
Expand Down Expand Up @@ -96,7 +96,7 @@ protected GameBase()
Services.AddService<IGameSystemCollection>(GameSystems);

// Create Platform
gamePlatform = GamePlatform.Create(this);
gamePlatform = platform ?? GamePlatform.Create(this);
gamePlatform.Activated += GamePlatform_Activated;
gamePlatform.Deactivated += GamePlatform_Deactivated;
gamePlatform.Exiting += GamePlatform_Exiting;
Expand Down Expand Up @@ -216,7 +216,7 @@ protected GameBase()
/// Gets or sets a value indicating whether this instance should force exactly one update step per one draw step
/// </summary>
/// <value><c>true</c> if this instance forces one update step per one draw step; otherwise, <c>false</c>.</value>
protected internal bool ForceOneUpdatePerDraw { get; set; }
protected bool ForceOneUpdatePerDraw { get; set; }

/// <summary>
/// When <see cref="IsFixedTimeStep"/> is set, is it allowed to render frames between two steps when we have time to do so.
Expand Down Expand Up @@ -340,7 +340,7 @@ public void ResetElapsedTime()
forceElapsedTimeToZero = true;
}

internal void InitializeBeforeRun()
public void InitializeBeforeRun()
{
try
{
Expand Down Expand Up @@ -371,7 +371,7 @@ internal void InitializeBeforeRun()
// Bind Graphics Context enabling initialize to use GL API eg. SetData to texture ...etc
BeginDraw();

LoadContentInternal();
LoadContentDefault();

IsRunning = true;

Expand Down Expand Up @@ -848,7 +848,7 @@ protected virtual void Initialize()
GameSystems.Initialize();
}

internal virtual void LoadContentInternal()
public virtual void LoadContentDefault()
{
GameSystems.LoadContent();
}
Expand Down Expand Up @@ -978,7 +978,7 @@ private void GraphicsDeviceService_DeviceCreated(object sender, EventArgs e)

if (GameSystems.State != GameSystemState.ContentLoaded)
{
LoadContentInternal();
LoadContentDefault();
}
}

Expand Down
12 changes: 6 additions & 6 deletions sources/engine/Stride.Games/GameContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,27 @@ public abstract class GameContext
/// <summary>
/// The requested width.
/// </summary>
internal int RequestedWidth;
public int RequestedWidth;

/// <summary>
/// The requested height.
/// </summary>
internal int RequestedHeight;
public int RequestedHeight;

/// <summary>
/// The requested back buffer format.
/// </summary>
internal PixelFormat RequestedBackBufferFormat;
public PixelFormat RequestedBackBufferFormat;

/// <summary>
/// The requested depth stencil format.
/// </summary>
internal PixelFormat RequestedDepthStencilFormat;
public PixelFormat RequestedDepthStencilFormat;

/// <summary>
/// The requested graphics profiles.
/// </summary>
internal GraphicsProfile[] RequestedGraphicsProfile;
public GraphicsProfile[] RequestedGraphicsProfile;

/// <summary>
/// The device creation flags that will be used to create the <see cref="GraphicsDevice"/>.
Expand All @@ -98,7 +98,7 @@ public abstract class GameContext
/// Product name of game.
/// TODO: Provide proper access title through code and game studio
/// </summary>
internal static string ProductName
public static string ProductName
{
get
{
Expand Down
2 changes: 2 additions & 0 deletions sources/engine/Stride.Games/GameContextFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public static GameContext NewGameContext(AppContextType type, int requestedWidth
case AppContextType.iOS:
res = NewGameContextiOS();
break;
case AppContextType.Custom:
throw new InvalidOperationException("Custom Contexts can not be created by the factory. Consider using a built in context if you are unsure.");
}

if (res == null)
Expand Down
4 changes: 2 additions & 2 deletions sources/engine/Stride.Games/GamePlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

namespace Stride.Games
{
internal abstract class GamePlatform : ReferenceBase, IGraphicsDeviceFactory, IGamePlatform
public abstract class GamePlatform : ReferenceBase, IGraphicsDeviceFactory, IGamePlatform
{
private bool hasExitRan = false;

Expand Down Expand Up @@ -88,7 +88,7 @@ public GameWindow MainWindow
}
}

internal abstract GameWindow GetSupportedGameWindow(AppContextType type);
public abstract GameWindow GetSupportedGameWindow(AppContextType type);

public virtual GameWindow CreateWindow(GameContext gameContext)
{
Expand Down
15 changes: 12 additions & 3 deletions sources/engine/Stride.Games/GameTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,13 @@ public double Factor
set => factor = value > 0 ? value : 0;
}


internal void Update(TimeSpan totalGameTime, TimeSpan elapsedGameTime, bool incrementFrameCount)
/// <summary>
/// Updated total GameTime, Elapsed GameTime and increments the frame count if set to true.
Doprez marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
/// <param name="totalGameTime"></param>
/// <param name="elapsedGameTime"></param>
/// <param name="incrementFrameCount"></param>
public void Update(TimeSpan totalGameTime, TimeSpan elapsedGameTime, bool incrementFrameCount)
{
Total = totalGameTime;
Elapsed = elapsedGameTime;
Expand All @@ -145,7 +150,11 @@ internal void Update(TimeSpan totalGameTime, TimeSpan elapsedGameTime, bool incr
}
}

internal void Reset(TimeSpan totalGameTime)
/// <summary>
/// Resets GameTime, does not increment frame count.
Doprez marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
/// <param name="totalGameTime"></param>
public void Reset(TimeSpan totalGameTime)
{
Update(totalGameTime, TimeSpan.Zero, false);
accumulatedElapsedTime = TimeSpan.Zero;
Expand Down
28 changes: 14 additions & 14 deletions sources/engine/Stride.Games/GameWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public bool IsFullscreen
/// Allow the GraphicsDeviceManager to set the actual window state after applying the device changes.
/// </summary>
/// <param name="isReallyFullscreen"></param>
internal void SetIsReallyFullscreen(bool isReallyFullscreen)
public void SetIsReallyFullscreen(bool isReallyFullscreen)
{
isFullscreen = isReallyFullscreen;
}
Expand All @@ -225,19 +225,19 @@ public void EndScreenDeviceChange()

#region Methods

protected internal abstract void Initialize(GameContext gameContext);
public abstract void Initialize(GameContext gameContext);

internal bool Exiting;
public bool Exiting;

internal Action InitCallback;
public Action InitCallback;

internal Action RunCallback;
public Action RunCallback;

internal Action ExitCallback;
public Action ExitCallback;

private bool isFullscreen;

internal abstract void Run();
public abstract void Run();

/// <summary>
/// Sets the size of the client area and triggers the <see cref="ClientSizeChanged"/> event.
Expand All @@ -253,17 +253,17 @@ public void SetSize(Int2 size)
/// Only used internally by the device managers when they adapt the window size to the backbuffer size.
/// Resizes the window, without sending the resized event.
/// </summary>
internal abstract void Resize(int width, int height);
public abstract void Resize(int width, int height);

public virtual IMessageLoop CreateUserManagedMessageLoop()
{
// Default: not implemented
throw new PlatformNotSupportedException();
}

internal IServiceRegistry Services { get; set; }
public IServiceRegistry Services { get; set; }

protected internal abstract void SetSupportedOrientations(DisplayOrientation orientations);
public abstract void SetSupportedOrientations(DisplayOrientation orientations);

protected void OnActivated(object source, EventArgs e)
{
Expand Down Expand Up @@ -319,20 +319,20 @@ protected void OnClosing(object source, EventArgs e)

#endregion

internal void OnPause()
public void OnPause()
{
OnDeactivated(this, EventArgs.Empty);
}

internal void OnResume()
public void OnResume()
{
OnActivated(this, EventArgs.Empty);
}
}

public abstract class GameWindow<TK> : GameWindow
{
protected internal sealed override void Initialize(GameContext gameContext)
public sealed override void Initialize(GameContext gameContext)
{
var context = gameContext as GameContext<TK>;
if (context != null)
Expand All @@ -346,7 +346,7 @@ protected internal sealed override void Initialize(GameContext gameContext)
}
}

internal GameContext<TK> GameContext;
public GameContext<TK> GameContext;

protected abstract void Initialize(GameContext<TK> context);
}
Expand Down
2 changes: 1 addition & 1 deletion sources/engine/Stride.Games/GraphicsDeviceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class GraphicsDeviceManager : ComponentBase, IGraphicsDeviceManager, IGra
/// </summary>
/// <param name="game">The game.</param>
/// <exception cref="System.ArgumentNullException">The game instance cannot be null.</exception>
internal GraphicsDeviceManager(GameBase game)
public GraphicsDeviceManager(GameBase game)
{
this.game = game;
if (this.game == null)
Expand Down
6 changes: 3 additions & 3 deletions sources/engine/Stride.Games/SDL/GameWindowSDL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public override void EndScreenDeviceChange(int clientWidth, int clientHeight)
deviceChangeWillBeFullScreen = null;
}

protected internal override void SetSupportedOrientations(DisplayOrientation orientations)
public override void SetSupportedOrientations(DisplayOrientation orientations)
{
// Desktop doesn't have orientation (unless on Windows 8?)
}
Expand Down Expand Up @@ -133,7 +133,7 @@ private void GameForm_CloseActions()
OnClosing(this, new EventArgs());
}

internal override void Run()
public override void Run()
{
Debug.Assert(InitCallback != null, $"{nameof(InitCallback)} is null");
Debug.Assert(RunCallback != null, $"{nameof(RunCallback)} is null");
Expand Down Expand Up @@ -269,7 +269,7 @@ protected override void SetTitle(string title)
}
}

internal override void Resize(int width, int height)
public override void Resize(int width, int height)
{
window.ClientSize = new Size2(width, height);
}
Expand Down
7 changes: 5 additions & 2 deletions sources/engine/Stride.Graphics/AppContextType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,14 @@ public enum AppContextType
/// </summary>
UWPCoreWindow,

#pragma warning disable SA1300 // Element must begin with upper-case letter
/// <summary>
/// Game running on iOS in a iPhoneOSGameView.
/// </summary>
iOS,
#pragma warning restore SA1300 // Element must begin with upper-case letter

/// <summary>
/// Game running on a custom context.
/// </summary>
Custom,
}
}
2 changes: 1 addition & 1 deletion sources/engine/Stride/Graphics/ImageSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Stride.Graphics
{
internal class ImageSerializer : ContentSerializerBase<Image>
public class ImageSerializer : ContentSerializerBase<Image>
{
public override void Serialize(ContentSerializerContext context, SerializationStream stream, Image textureData)
{
Expand Down