10
10
using GoDough . Visuals ;
11
11
using System ;
12
12
13
- namespace GoDough . Runtime {
14
- public class AppHost {
13
+ namespace GoDough . Runtime
14
+ {
15
+ public class AppHost
16
+ {
15
17
#region Private Fields
16
18
public Node AutoLoadNode { get ; private set ; }
17
19
#endregion
@@ -29,21 +31,24 @@ public class AppHost {
29
31
public event InputEventHandler OnUnhandledInput ;
30
32
31
33
private static AppHost ? _instance = null ;
32
- public static AppHost ? Instance {
34
+ public static AppHost ? Instance
35
+ {
33
36
get { return AppHost . _instance ; }
34
37
}
35
38
#endregion
36
39
37
40
#region Ctor
38
- public AppHost ( Node autoLoadNode ) {
41
+ public AppHost ( Node autoLoadNode )
42
+ {
39
43
this . AutoLoadNode = autoLoadNode ;
40
44
41
45
AppHost . _instance = AppHost . Instance ?? this ;
42
46
}
43
47
#endregion
44
48
45
49
#region Public Methods
46
- public void Start ( ) {
50
+ public void Start ( Boolean deferBoot = false )
51
+ {
47
52
GD . Print ( "[GoDough] Building AppHost" ) ;
48
53
var builder = Host . CreateDefaultBuilder ( null ) ;
49
54
@@ -55,39 +60,49 @@ public void Start() {
55
60
GD . Print ( "[GoDough] Sealing AppHost" ) ;
56
61
this . Application = builder . Build ( ) ;
57
62
58
- this . Boot ( ) ;
63
+ if ( ! deferBoot )
64
+ {
65
+ this . Boot ( ) ;
66
+ }
59
67
}
60
68
61
- public virtual void ConfigureLogging ( ILoggingBuilder loggingBuilder ) {
69
+ public virtual void ConfigureLogging ( ILoggingBuilder loggingBuilder )
70
+ {
62
71
loggingBuilder . AddGodotLogger ( ) ;
63
72
64
- if ( ! OS . IsDebugBuild ( ) ) {
73
+ if ( ! OS . IsDebugBuild ( ) )
74
+ {
65
75
return ;
66
76
}
67
77
68
78
loggingBuilder . SetMinimumLevel ( LogLevel . Trace ) ;
69
79
}
70
80
71
- public virtual void ConfigureServices ( IServiceCollection services ) {
81
+ public virtual void ConfigureServices ( IServiceCollection services )
82
+ {
72
83
services
73
84
. AddSingleton < IAppHostNodeProvider , AppHostNodeProvider > ( x =>
74
85
new AppHostNodeProvider ( ( ) => this . AutoLoadNode ) )
75
86
. AddSingleton ( typeof ( SceneManagementService < > ) ) ;
76
87
}
77
88
78
- private void Boot ( ) {
89
+ public void Boot ( )
90
+ {
79
91
var logger = this . Application . Services . GetService < ILogger < AppHost > > ( ) ;
80
92
81
93
var bootstrappers = this . Application . Services . GetServices < IBootstrapper > ( ) ;
82
94
logger . LogInformation ( "Booting App with {0} Bootstrappers" , bootstrappers . Count ( ) ) ;
83
95
84
- foreach ( var service in bootstrappers ) {
96
+ foreach ( var service in bootstrappers )
97
+ {
85
98
service . Run ( ) ;
86
99
}
87
100
}
88
101
89
- public void PhysicsProcess ( double delta ) {
90
- if ( this . OnPhysicsProcess != null ) {
102
+ public void PhysicsProcess ( double delta )
103
+ {
104
+ if ( this . OnPhysicsProcess != null )
105
+ {
91
106
this . OnPhysicsProcess . Invoke ( this , delta ) ;
92
107
}
93
108
@@ -97,17 +112,21 @@ public void PhysicsProcess(double delta) {
97
112
98
113
99
114
100
- public void UnhandledInput ( InputEvent ev ) {
101
- if ( this . OnUnhandledInput != null ) {
115
+ public void UnhandledInput ( InputEvent ev )
116
+ {
117
+ if ( this . OnUnhandledInput != null )
118
+ {
102
119
this . OnUnhandledInput . Invoke ( this , ev ) ;
103
120
}
104
121
105
122
this . InvokeLifeCycleHooks < IOnUnhandledInput > ( x =>
106
123
x . OnUnhandledInput ( ev ) ) ;
107
124
}
108
125
109
- public void Input ( InputEvent ev ) {
110
- if ( this . OnInput != null ) {
126
+ public void Input ( InputEvent ev )
127
+ {
128
+ if ( this . OnInput != null )
129
+ {
111
130
this . OnInput . Invoke ( this , ev ) ;
112
131
}
113
132
@@ -116,8 +135,10 @@ public void Input(InputEvent ev) {
116
135
}
117
136
118
137
119
- public void Process ( double delta ) {
120
- if ( this . OnProcess != null ) {
138
+ public void Process ( double delta )
139
+ {
140
+ if ( this . OnProcess != null )
141
+ {
121
142
this . OnProcess . Invoke ( this , delta ) ;
122
143
}
123
144
@@ -127,9 +148,11 @@ public void Process(double delta) {
127
148
#endregion
128
149
129
150
#region Private Methods
130
- private void InvokeLifeCycleHooks < T > ( Action < T > action ) {
151
+ private void InvokeLifeCycleHooks < T > ( Action < T > action )
152
+ {
131
153
var framebasedServices = this . Application . Services . GetServices < T > ( ) ;
132
- foreach ( var service in framebasedServices ) {
154
+ foreach ( var service in framebasedServices )
155
+ {
133
156
action ( service ) ;
134
157
}
135
158
}
0 commit comments