Skip to content

Commit 4e79708

Browse files
committed
feat: ✨ Implement the possible separation of building the app context and booting
1 parent 2635684 commit 4e79708

File tree

1 file changed

+44
-21
lines changed

1 file changed

+44
-21
lines changed

Source/Runtime/AppHost.cs

+44-21
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
using GoDough.Visuals;
1111
using System;
1212

13-
namespace GoDough.Runtime {
14-
public class AppHost {
13+
namespace GoDough.Runtime
14+
{
15+
public class AppHost
16+
{
1517
#region Private Fields
1618
public Node AutoLoadNode { get; private set; }
1719
#endregion
@@ -29,21 +31,24 @@ public class AppHost {
2931
public event InputEventHandler OnUnhandledInput;
3032

3133
private static AppHost? _instance = null;
32-
public static AppHost? Instance {
34+
public static AppHost? Instance
35+
{
3336
get { return AppHost._instance; }
3437
}
3538
#endregion
3639

3740
#region Ctor
38-
public AppHost(Node autoLoadNode) {
41+
public AppHost(Node autoLoadNode)
42+
{
3943
this.AutoLoadNode = autoLoadNode;
4044

4145
AppHost._instance = AppHost.Instance ?? this;
4246
}
4347
#endregion
4448

4549
#region Public Methods
46-
public void Start() {
50+
public void Start(Boolean deferBoot = false)
51+
{
4752
GD.Print("[GoDough] Building AppHost");
4853
var builder = Host.CreateDefaultBuilder(null);
4954

@@ -55,39 +60,49 @@ public void Start() {
5560
GD.Print("[GoDough] Sealing AppHost");
5661
this.Application = builder.Build();
5762

58-
this.Boot();
63+
if (!deferBoot)
64+
{
65+
this.Boot();
66+
}
5967
}
6068

61-
public virtual void ConfigureLogging(ILoggingBuilder loggingBuilder) {
69+
public virtual void ConfigureLogging(ILoggingBuilder loggingBuilder)
70+
{
6271
loggingBuilder.AddGodotLogger();
6372

64-
if (!OS.IsDebugBuild()) {
73+
if (!OS.IsDebugBuild())
74+
{
6575
return;
6676
}
6777

6878
loggingBuilder.SetMinimumLevel(LogLevel.Trace);
6979
}
7080

71-
public virtual void ConfigureServices(IServiceCollection services) {
81+
public virtual void ConfigureServices(IServiceCollection services)
82+
{
7283
services
7384
.AddSingleton<IAppHostNodeProvider, AppHostNodeProvider>(x =>
7485
new AppHostNodeProvider(() => this.AutoLoadNode))
7586
.AddSingleton(typeof(SceneManagementService<>));
7687
}
7788

78-
private void Boot() {
89+
public void Boot()
90+
{
7991
var logger = this.Application.Services.GetService<ILogger<AppHost>>();
8092

8193
var bootstrappers = this.Application.Services.GetServices<IBootstrapper>();
8294
logger.LogInformation("Booting App with {0} Bootstrappers", bootstrappers.Count());
8395

84-
foreach(var service in bootstrappers) {
96+
foreach (var service in bootstrappers)
97+
{
8598
service.Run();
8699
}
87100
}
88101

89-
public void PhysicsProcess(double delta) {
90-
if (this.OnPhysicsProcess != null) {
102+
public void PhysicsProcess(double delta)
103+
{
104+
if (this.OnPhysicsProcess != null)
105+
{
91106
this.OnPhysicsProcess.Invoke(this, delta);
92107
}
93108

@@ -97,17 +112,21 @@ public void PhysicsProcess(double delta) {
97112

98113

99114

100-
public void UnhandledInput(InputEvent ev) {
101-
if (this.OnUnhandledInput != null) {
115+
public void UnhandledInput(InputEvent ev)
116+
{
117+
if (this.OnUnhandledInput != null)
118+
{
102119
this.OnUnhandledInput.Invoke(this, ev);
103120
}
104121

105122
this.InvokeLifeCycleHooks<IOnUnhandledInput>(x =>
106123
x.OnUnhandledInput(ev));
107124
}
108125

109-
public void Input(InputEvent ev) {
110-
if (this.OnInput != null) {
126+
public void Input(InputEvent ev)
127+
{
128+
if (this.OnInput != null)
129+
{
111130
this.OnInput.Invoke(this, ev);
112131
}
113132

@@ -116,8 +135,10 @@ public void Input(InputEvent ev) {
116135
}
117136

118137

119-
public void Process(double delta) {
120-
if (this.OnProcess != null) {
138+
public void Process(double delta)
139+
{
140+
if (this.OnProcess != null)
141+
{
121142
this.OnProcess.Invoke(this, delta);
122143
}
123144

@@ -127,9 +148,11 @@ public void Process(double delta) {
127148
#endregion
128149

129150
#region Private Methods
130-
private void InvokeLifeCycleHooks<T>(Action<T> action) {
151+
private void InvokeLifeCycleHooks<T>(Action<T> action)
152+
{
131153
var framebasedServices = this.Application.Services.GetServices<T>();
132-
foreach(var service in framebasedServices) {
154+
foreach (var service in framebasedServices)
155+
{
133156
action(service);
134157
}
135158
}

0 commit comments

Comments
 (0)