-
-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: Stride Gamebuilder as an alternative for .NET IOC startup #2806
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
Open
Doprez
wants to merge
38
commits into
stride3d:master
Choose a base branch
from
Doprez:gamebuilder
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
75f1515
initial PoC
Doprez 2372862
reorganizing code to work with GameStudio
Doprez 2f7f213
clean up
Doprez 5e82aa1
fixing input issues
Doprez 7136214
Separated input
Doprez aa3c9fe
clean up and docs
Doprez 257c458
Kryptos feedback
Doprez e83810a
missed some duplicate packages
Doprez 18397c5
add option for DI in GameFontSystem
Doprez 2588b5f
Fix error caused by StreamingManager DI.
Doprez f1f7b49
renaming to favour ServiceCollection
Doprez 938a50c
typo
Doprez c2de7f4
docs
Doprez 3b26a45
docs
Doprez 384dd48
clean up and build logging
Doprez ceaec04
remove some hardcoded Game references
Doprez 2003364
feat: Setup concurrency for CI workflows (#2807)
Kryptos-FR d64fedd
fix: concurrency group names can collide when running from the CI (ma…
Kryptos-FR 27f87bf
chore: Increment PublicVersion Build number following the breaking ch…
Eideren 8723abe
initial PoC
Doprez 7590a43
reorganizing code to work with GameStudio
Doprez 6f02a8b
clean up
Doprez 9f7bd52
fixing input issues
Doprez 848bd10
Separated input
Doprez 731610d
clean up and docs
Doprez 8c7eaea
Kryptos feedback
Doprez 415cd6f
missed some duplicate packages
Doprez 08dc3ce
add option for DI in GameFontSystem
Doprez a51d8cf
Fix error caused by StreamingManager DI.
Doprez 1bcc2e5
renaming to favour ServiceCollection
Doprez c5d1c3d
typo
Doprez 1f8eba6
docs
Doprez a315d2b
docs
Doprez 0ed0012
clean up and build logging
Doprez 4718339
remove some hardcoded Game references
Doprez 5d34b28
GameWindowTest
Doprez c252f6e
rebase
Doprez 850659d
writable ConentManager
Doprez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
sources/engine/Stride.Engine/Engine/Builder/GameBuilder.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Stride.Core; | ||
using Stride.Core.Diagnostics; | ||
using Stride.Core.IO; | ||
using Stride.Games; | ||
using Stride.Input; | ||
|
||
namespace Stride.Engine.Builder; | ||
|
||
/// <summary> | ||
/// Helps build the game and preps it to be able to run after built. | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
public class GameBuilder : IGameBuilder | ||
{ | ||
public Dictionary<Type, object> Services { get; internal set; } = []; | ||
Doprez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
public IServiceCollection DiServices { get; internal set; } = new ServiceCollection(); | ||
|
||
public GameSystemCollection GameSystems { get; internal set; } | ||
|
||
public List<LogListener> LogListeners { get; internal set; } = []; | ||
|
||
public List<IInputSource> InputSources { get; internal set; } = []; | ||
|
||
public DatabaseFileProvider DatabaseFileProvider { get; set; } | ||
|
||
public GameBase Game { get; set; } | ||
|
||
public GameContext Context { get; set; } | ||
|
||
internal GameBuilder() | ||
{ | ||
Game = new MinimalGame(null); | ||
GameSystems = Game.GameSystems; | ||
DiServices.AddSingleton<IServiceRegistry>(Game.Services); | ||
Services.Add(typeof(IServiceRegistry), Game.Services); | ||
} | ||
|
||
public static GameBuilder Create() | ||
{ | ||
return new GameBuilder(); | ||
} | ||
|
||
public virtual GameBase Build() | ||
{ | ||
var provider = DiServices.BuildServiceProvider(); | ||
foreach (var service in Services) | ||
{ | ||
if (service.Key == typeof(IServiceRegistry) || service.Key == typeof(IServiceProvider)) | ||
continue; | ||
|
||
try | ||
{ | ||
if (service.Value == null) | ||
{ | ||
var instance = provider.GetService(service.Key); | ||
|
||
if(instance == null) | ||
{ | ||
//check if the type is inherited from another instance in the services. | ||
foreach (var kvp in Services) | ||
{ | ||
if (kvp.Key.IsAssignableFrom(service.Key) && kvp.Value != null) | ||
{ | ||
instance = provider.GetService(kvp.Key); | ||
if(instance is not null) | ||
break; | ||
} | ||
} | ||
} | ||
|
||
Game.Services.AddService(instance, service.Key); | ||
Services[service.Key] = instance; | ||
} | ||
else | ||
{ | ||
Game.Services.AddService(service.Value, service.Key); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
// TODO: check if service is already registered first. | ||
} | ||
} | ||
|
||
// Add all game systems to the game. | ||
foreach (var service in Services) | ||
{ | ||
var system = provider.GetService(service.Key); | ||
if (system is IGameSystemBase gameSystem && !Game.GameSystems.Contains(gameSystem)) | ||
{ | ||
Game.GameSystems.Add(gameSystem); | ||
} | ||
} | ||
|
||
foreach (var logListener in LogListeners) | ||
{ | ||
GlobalLogger.GlobalMessageLogged += logListener; | ||
} | ||
|
||
if (Context != null) | ||
{ | ||
Game.SetGameContext(Context); | ||
} | ||
|
||
if(InputSources.Count > 0) | ||
{ | ||
var inputManager = Game.Services.GetService<InputManager>() ?? throw new InvalidOperationException("InputManager is not registered in the service registry."); | ||
foreach (var inputSource in InputSources) | ||
{ | ||
inputManager.Sources.Add(inputSource); | ||
} | ||
} | ||
|
||
var dataBase = Game.Services.GetService<IDatabaseFileProviderService>(); | ||
dataBase.FileProvider = DatabaseFileProvider; | ||
|
||
return Game; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.