fix: Add possibility to add ScriptComponent before running game (#2230)

This commit is contained in:
Jakub Ławreszuk 2024-04-21 18:43:37 +00:00 коммит произвёл GitHub
Родитель 82888c2e5b
Коммит 3a9ed13501
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 58 добавлений и 72 удалений

Просмотреть файл

@ -225,6 +225,15 @@ namespace Stride.Engine
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);
@ -336,13 +345,6 @@ namespace Stride.Engine
// (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();
@ -363,9 +365,6 @@ namespace Stride.Engine
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);

Просмотреть файл

@ -90,6 +90,10 @@ namespace Stride.Games
// 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);
@ -344,51 +348,49 @@ namespace Stride.Games
{
try
{
using (var profile = Profiler.Begin(GameProfilingKeys.GameInitialize))
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();
// Gets the graphics device service
graphicsDeviceService = Services.GetService<IGraphicsDeviceService>();
if (graphicsDeviceService == null)
{
// Initialize this instance and all game systems before trying to create the device.
Initialize();
// 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");
}
// 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();
// Bind Graphics Context enabling initialize to use GL API eg. SetData to texture ...etc
BeginDraw();
LoadContentInternal();
IsRunning = true;
BeginRun();
autoTickTimer.Reset();
UpdateTime.Reset(UpdateTime.Total);
// Run the first time an update
using (Profiler.Begin(GameProfilingKeys.GameUpdate))
{
Update(UpdateTime);
}
// Unbind Graphics Context without presenting
EndDraw(false);
throw new InvalidOperationException("No GraphicsDeviceService 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();
// Bind Graphics Context enabling initialize to use GL API eg. SetData to texture ...etc
BeginDraw();
LoadContentInternal();
IsRunning = true;
BeginRun();
autoTickTimer.Reset();
UpdateTime.Reset(UpdateTime.Total);
// Run the first time an update
using (Profiler.Begin(GameProfilingKeys.GameUpdate))
{
Update(UpdateTime);
}
// Unbind Graphics Context without presenting
EndDraw(false);
}
catch (Exception ex)
{
@ -471,13 +473,7 @@ namespace Stride.Games
/// <summary>
/// Creates or updates <see cref="Context"/> before window and device are created.
/// </summary>
protected virtual void PrepareContext()
{
// Content manager
Content = new ContentManager(Services);
Services.AddService<IContentManager>(Content);
Services.AddService(Content);
}
protected virtual void PrepareContext() { }
/// <summary>
/// Prevents calls to Draw until the next Update.
@ -717,27 +713,18 @@ namespace Stride.Games
for (int i = 0; i < array.Length; i++)
{
var disposable = array[i] as IDisposable;
if (disposable != null)
{
disposable.Dispose();
}
disposable?.Dispose();
}
// Reset graphics context
GraphicsContext = null;
var disposableGraphicsManager = graphicsDeviceManager as IDisposable;
if (disposableGraphicsManager != null)
{
disposableGraphicsManager.Dispose();
}
disposableGraphicsManager?.Dispose();
DisposeGraphicsDeviceEvents();
if (gamePlatform != null)
{
gamePlatform.Release();
}
gamePlatform?.Release();
}
}