Skip to content

Commit

Permalink
Revert "fix: Add possibility to add ScriptComponent before running ga…
Browse files Browse the repository at this point in the history
…me (#2230)" (#2245)

This reverts commit 3a9ed13.
  • Loading branch information
Eideren authored May 14, 2024
1 parent cd8e17f commit ad8496f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 49 deletions.
19 changes: 10 additions & 9 deletions sources/engine/Stride.Engine/Engine/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,6 @@ public Game()

VRDeviceSystem = new VRDeviceSystem(Services);
Services.AddService(VRDeviceSystem);
// Add the input manager
// Add it first so that it can obtained by the UI system
var inputSystem = new InputSystem(Services);
Input = inputSystem.Manager;
Services.AddService(Input);
GameSystems.Add(inputSystem);

EffectSystem = new EffectSystem(Services);
Services.AddService(EffectSystem);

// Creates the graphics device manager
GraphicsDeviceManager = new GraphicsDeviceManager(this);
Expand Down Expand Up @@ -345,6 +336,13 @@ protected override void Initialize()
// (Unless overriden by gameSystem.UpdateOrder)
// ---------------------------------------------------------

// Add the input manager
// Add it first so that it can obtained by the UI system
var inputSystem = new InputSystem(Services);
Input = inputSystem.Manager;
Services.AddService(Input);
GameSystems.Add(inputSystem);

// Initialize the systems
base.Initialize();

Expand All @@ -365,6 +363,9 @@ protected override void Initialize()
GameSystems.Add(DebugTextSystem);
GameSystems.Add(ProfilingSystem);

EffectSystem = new EffectSystem(Services);
Services.AddService(EffectSystem);

// If requested in game settings, compile effects remotely and/or notify new shader requests
EffectSystem.Compiler = EffectCompilerFactory.CreateEffectCompiler(Content.FileProvider, EffectSystem, Settings?.PackageName, Settings?.EffectCompilation ?? EffectCompilationMode.Local, Settings?.RecordUsedEffects ?? false);

Expand Down
93 changes: 53 additions & 40 deletions sources/engine/Stride.Games/GameBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ protected GameBase()

// Database file provider
Services.AddService<IDatabaseFileProviderService>(new DatabaseFileProviderService(null));
// Content manager
Content = new ContentManager(Services);
Services.AddService<IContentManager>(Content);
Services.AddService(Content);

LaunchParameters = new LaunchParameters();
GameSystems = new GameSystemCollection(Services);
Expand Down Expand Up @@ -348,49 +344,51 @@ internal void InitializeBeforeRun()
{
try
{
using var profile = Profiler.Begin(GameProfilingKeys.GameInitialize);
// Initialize this instance and all game systems before trying to create the device.
Initialize();
using (var profile = Profiler.Begin(GameProfilingKeys.GameInitialize))
{
// Initialize this instance and all game systems before trying to create the device.
Initialize();

// Make sure that the device is already created
graphicsDeviceManager.CreateDevice();
// Make sure that the device is already created
graphicsDeviceManager.CreateDevice();

// Gets the graphics device service
graphicsDeviceService = Services.GetService<IGraphicsDeviceService>();
if (graphicsDeviceService == null)
{
throw new InvalidOperationException("No GraphicsDeviceService found");
}
// Gets the graphics device service
graphicsDeviceService = Services.GetService<IGraphicsDeviceService>();
if (graphicsDeviceService == null)
{
throw new InvalidOperationException("No GraphicsDeviceService found");
}

// Checks the graphics device
if (graphicsDeviceService.GraphicsDevice == null)
{
throw new InvalidOperationException("No GraphicsDevice found");
}
// Checks the graphics device
if (graphicsDeviceService.GraphicsDevice == null)
{
throw new InvalidOperationException("No GraphicsDevice found");
}

// Setup the graphics device if it was not already setup.
SetupGraphicsDeviceEvents();
// Setup the graphics device if it was not already setup.
SetupGraphicsDeviceEvents();

// Bind Graphics Context enabling initialize to use GL API eg. SetData to texture ...etc
BeginDraw();
// Bind Graphics Context enabling initialize to use GL API eg. SetData to texture ...etc
BeginDraw();

LoadContentInternal();
LoadContentInternal();

IsRunning = true;
IsRunning = true;

BeginRun();
BeginRun();

autoTickTimer.Reset();
UpdateTime.Reset(UpdateTime.Total);
autoTickTimer.Reset();
UpdateTime.Reset(UpdateTime.Total);

// Run the first time an update
using (Profiler.Begin(GameProfilingKeys.GameUpdate))
{
Update(UpdateTime);
}
// Run the first time an update
using (Profiler.Begin(GameProfilingKeys.GameUpdate))
{
Update(UpdateTime);
}

// Unbind Graphics Context without presenting
EndDraw(false);
// Unbind Graphics Context without presenting
EndDraw(false);
}
}
catch (Exception ex)
{
Expand Down Expand Up @@ -473,7 +471,13 @@ public void Run(GameContext gameContext = null)
/// <summary>
/// Creates or updates <see cref="Context"/> before window and device are created.
/// </summary>
protected virtual void PrepareContext() { }
protected virtual void PrepareContext()
{
// Content manager
Content = new ContentManager(Services);
Services.AddService<IContentManager>(Content);
Services.AddService(Content);
}

/// <summary>
/// Prevents calls to Draw until the next Update.
Expand Down Expand Up @@ -713,18 +717,27 @@ protected override void Destroy()
for (int i = 0; i < array.Length; i++)
{
var disposable = array[i] as IDisposable;
disposable?.Dispose();
if (disposable != null)
{
disposable.Dispose();
}
}

// Reset graphics context
GraphicsContext = null;

var disposableGraphicsManager = graphicsDeviceManager as IDisposable;
disposableGraphicsManager?.Dispose();
if (disposableGraphicsManager != null)
{
disposableGraphicsManager.Dispose();
}

DisposeGraphicsDeviceEvents();

gamePlatform?.Release();
if (gamePlatform != null)
{
gamePlatform.Release();
}
}
}

Expand Down

0 comments on commit ad8496f

Please sign in to comment.