-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathISceneRuntime.cs
More file actions
246 lines (217 loc) · 13.9 KB
/
Copy pathISceneRuntime.cs
File metadata and controls
246 lines (217 loc) · 13.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
using CrdtEcsBridge.JsModulesImplementation.Communications;
using CrdtEcsBridge.PoolsProviders;
using Cysharp.Threading.Tasks;
using DCL.Multiplayer.Connections.DecentralandUrls;
using DCL.Multiplayer.Connections.RoomHubs;
using DCL.Multiplayer.Profiles.Poses;
using DCL.Profiles;
using DCL.Profiling;
using DCL.Web3;
using DCL.Web3.Identities;
using DCL.WebRequests;
using ECS;
using Microsoft.ClearScript.V8;
using PortableExperiences.Controller;
using SceneRunner.Scene;
using SceneRunner.Scene.ExceptionsHandling;
using SceneRuntime.Apis.Modules;
using SceneRuntime.Apis.Modules.CommsApi;
using SceneRuntime.Apis.Modules.CommunicationsControllerApi;
using SceneRuntime.Apis.Modules.CommunicationsControllerApi.SDKMessageBus;
using SceneRuntime.Apis.Modules.EngineApi;
using SceneRuntime.Apis.Modules.EngineApi.SDKObservableEvents;
using SceneRuntime.Apis.Modules.Ethereums;
using SceneRuntime.Apis.Modules.FetchApi;
using SceneRuntime.Apis.Modules.Players;
using SceneRuntime.Apis.Modules.PortableExperiencesApi;
using SceneRuntime.Apis.Modules.RestrictedActionsApi;
using SceneRuntime.Apis.Modules.Runtime;
using SceneRuntime.Apis.Modules.SceneApi;
using SceneRuntime.Apis.Modules.SignedFetch;
using SceneRuntime.Apis.Modules.UserActions;
using SceneRuntime.Apis.Modules.UserIdentityApi;
using System;
using System.Threading;
namespace SceneRuntime
{
public interface ISceneRuntime : IDisposable
{
internal CancellationTokenSource isDisposingTokenSource { get; }
void Register<T>(string itemName, T target) where T: JsApiWrapper;
UniTask StartScene();
UniTask UpdateScene(float dt);
void ApplyStaticMessages(ReadOnlyMemory<byte> data);
/// <summary>
/// Forcibly interrupts a running JS execution by causing a <see cref="Microsoft.ClearScript.ScriptInterruptedException"/>
/// to be thrown from inside the engine. Safe to call from another thread.
/// After interrupt the engine state may be inconsistent — treat as terminal and dispose the scene.
/// </summary>
void Interrupt();
void SetIsDisposing();
void OnSceneIsCurrentChanged(bool isCurrent);
void RegisterEngineAPIWrapper(EngineApiWrapper newWrapper);
V8RuntimeHeapInfo RuntimeHeapInfo { get; }
/// <summary>
/// Script-bound array operations of the underlying engine,
/// required by the API wrappers that marshal binary data back to the scene
/// </summary>
IJsOperations JsOperations { get; }
}
public static class SceneRuntimeExtensions
{
public static void RegisterAll(this ISceneRuntime sceneRuntime,
IEngineApi engineApi,
ISceneExceptionsHandler exceptionsHandler,
IRoomHub roomHub,
IProfileRepository profileRepository,
ISceneApi sceneApi,
IWebRequestController webRequestController,
IRestrictedActionsAPI restrictedActionsAPI,
DecentralandEnvironment dclEnvironment,
IRuntime runtime,
IEthereumApi ethereumApi,
IWebSocketApi webSocketApi,
IWeb3IdentityCache web3IdentityCache,
ICommunicationsControllerAPI communicationsControllerAPI,
IInstancePoolsProvider instancePoolsProvider,
ISimpleFetchApi simpleFetchApi,
ISceneData sceneData,
IRealmData realmData,
IPortableExperiencesController portableExperiencesController,
IRemoteMetadata remoteMetadata,
ISceneCommunicationPipe sceneCommunicationPipe,
SceneRuntimeMetrics runtimeMetrics
)
{
sceneRuntime.RegisterEngineAPI(sceneData, engineApi, instancePoolsProvider, exceptionsHandler, runtimeMetrics);
sceneRuntime.RegisterPlayers(roomHub, profileRepository, remoteMetadata);
sceneRuntime.RegisterSceneApi(sceneApi);
sceneRuntime.RegisterCommsApi(roomHub, sceneCommunicationPipe, sceneData, exceptionsHandler);
sceneRuntime.RegisterSignedFetch(webRequestController, dclEnvironment, sceneData, realmData, web3IdentityCache);
sceneRuntime.RegisterRestrictedActionsApi(restrictedActionsAPI);
sceneRuntime.RegisterUserActions(restrictedActionsAPI);
sceneRuntime.RegisterRuntime(runtime, exceptionsHandler);
sceneRuntime.RegisterEthereumApi(ethereumApi, web3IdentityCache, exceptionsHandler);
sceneRuntime.RegisterUserIdentityApi(profileRepository, web3IdentityCache, exceptionsHandler);
sceneRuntime.RegisterWebSocketApi(webSocketApi, exceptionsHandler, realmData.IsLocalSceneDevelopment);
sceneRuntime.RegisterSimpleFetchApi(simpleFetchApi, webRequestController, realmData.IsLocalSceneDevelopment);
sceneRuntime.RegisterCommunicationsControllerApi(communicationsControllerAPI, instancePoolsProvider, exceptionsHandler, realmData.IsLocalSceneDevelopment);
sceneRuntime.RegisterPortableExperiencesApi(portableExperiencesController, exceptionsHandler);
}
public static void RegisterAll(this ISceneRuntime sceneRuntime,
ISDKObservableEventsEngineApi engineApi,
ISDKMessageBusCommsControllerAPI commsApiImplementation,
ISceneExceptionsHandler exceptionsHandler,
IRoomHub roomHub,
IProfileRepository profileRepository,
ISceneApi sceneApi,
IWebRequestController webRequestController,
IRestrictedActionsAPI restrictedActionsAPI,
IRuntime runtime,
IEthereumApi ethereumApi,
IWebSocketApi webSocketApi,
IWeb3IdentityCache web3IdentityCache,
DecentralandEnvironment dclEnvironment,
ICommunicationsControllerAPI communicationsControllerAPI,
IInstancePoolsProvider instancePoolsProvider,
ISimpleFetchApi simpleFetchApi,
ISceneData sceneData,
IRealmData realmData,
IPortableExperiencesController portableExperiencesController,
IRemoteMetadata remoteMetadata,
ISceneCommunicationPipe sceneCommunicationPipe,
SceneRuntimeMetrics runtimeMetrics
)
{
sceneRuntime.RegisterEngineAPI( sceneData, engineApi, commsApiImplementation, instancePoolsProvider, exceptionsHandler, runtimeMetrics);
sceneRuntime.RegisterPlayers(roomHub, profileRepository, remoteMetadata);
sceneRuntime.RegisterSceneApi(sceneApi);
sceneRuntime.RegisterCommsApi(roomHub, sceneCommunicationPipe, sceneData, exceptionsHandler);
sceneRuntime.RegisterSignedFetch(webRequestController, dclEnvironment, sceneData, realmData, web3IdentityCache);
sceneRuntime.RegisterRestrictedActionsApi(restrictedActionsAPI);
sceneRuntime.RegisterUserActions(restrictedActionsAPI);
sceneRuntime.RegisterRuntime(runtime, exceptionsHandler);
sceneRuntime.RegisterEthereumApi(ethereumApi, web3IdentityCache, exceptionsHandler);
sceneRuntime.RegisterUserIdentityApi(profileRepository, web3IdentityCache, exceptionsHandler);
sceneRuntime.RegisterWebSocketApi(webSocketApi, exceptionsHandler, realmData.IsLocalSceneDevelopment);
sceneRuntime.RegisterSimpleFetchApi(simpleFetchApi, webRequestController, realmData.IsLocalSceneDevelopment);
sceneRuntime.RegisterCommunicationsControllerApi(communicationsControllerAPI, instancePoolsProvider, exceptionsHandler, realmData.IsLocalSceneDevelopment);
sceneRuntime.RegisterPortableExperiencesApi(portableExperiencesController, exceptionsHandler);
}
internal static void RegisterEngineAPI(this ISceneRuntime sceneRuntime, ISceneData sceneData, IEngineApi engineApi, IInstancePoolsProvider instancePoolsProvider, ISceneExceptionsHandler sceneExceptionsHandler, SceneRuntimeMetrics runtimeMetrics)
{
var newWrapper = new EngineApiWrapper(engineApi, sceneData, instancePoolsProvider, sceneRuntime.JsOperations, sceneExceptionsHandler, runtimeMetrics, sceneRuntime.isDisposingTokenSource);
sceneRuntime.Register("UnityEngineApi", newWrapper);
sceneRuntime.RegisterEngineAPIWrapper(newWrapper);
}
internal static void RegisterEngineAPI(this ISceneRuntime sceneRuntime, ISceneData sceneData, ISDKObservableEventsEngineApi engineApi, ISDKMessageBusCommsControllerAPI commsApiImplementation, IInstancePoolsProvider instancePoolsProvider, ISceneExceptionsHandler sceneExceptionsHandler, SceneRuntimeMetrics runtimeMetrics)
{
var newWrapper = new SDKObservableEventsEngineApiWrapper(engineApi, sceneData, commsApiImplementation, instancePoolsProvider, sceneRuntime.JsOperations, sceneExceptionsHandler, runtimeMetrics, sceneRuntime.isDisposingTokenSource);
sceneRuntime.Register("UnityEngineApi", newWrapper);
sceneRuntime.RegisterEngineAPIWrapper(newWrapper);
}
private static void RegisterPlayers(this ISceneRuntime sceneRuntime, IRoomHub roomHub, IProfileRepository profileRepository, IRemoteMetadata remoteMetadata)
{
sceneRuntime.Register("UnityPlayers", new PlayersWrap(roomHub, profileRepository, remoteMetadata, sceneRuntime.isDisposingTokenSource));
}
private static void RegisterSceneApi(this ISceneRuntime sceneRuntime, ISceneApi api)
{
sceneRuntime.Register("UnitySceneApi", new SceneApiWrapper(api, sceneRuntime.isDisposingTokenSource));
}
private static void RegisterCommsApi(this ISceneRuntime sceneRuntime, IRoomHub roomHub, ISceneCommunicationPipe sceneCommunicationPipe, ISceneData sceneData, ISceneExceptionsHandler sceneExceptionsHandler)
{
sceneRuntime.Register("CommsApi", new CommsApiWrap(roomHub, sceneCommunicationPipe, sceneData, sceneExceptionsHandler, sceneRuntime.isDisposingTokenSource));
}
private static void RegisterSignedFetch(
this ISceneRuntime sceneRuntime,
IWebRequestController webRequestController,
DecentralandEnvironment dclEnvironment,
ISceneData sceneData,
IRealmData realmData,
IWeb3IdentityCache web3IdentityCache
)
{
sceneRuntime.Register("UnitySignedFetch", new SignedFetchWrap(webRequestController, dclEnvironment, sceneData, realmData, web3IdentityCache, sceneRuntime.isDisposingTokenSource));
}
private static void RegisterRestrictedActionsApi(this ISceneRuntime sceneRuntime, IRestrictedActionsAPI api)
{
sceneRuntime.Register("UnityRestrictedActionsApi", new RestrictedActionsAPIWrapper(api, sceneRuntime.isDisposingTokenSource));
}
private static void RegisterUserActions(this ISceneRuntime sceneRuntime, IRestrictedActionsAPI api)
{
sceneRuntime.Register("UnityUserActions", new UserActionsWrapper(api, sceneRuntime.isDisposingTokenSource));
}
private static void RegisterRuntime(this ISceneRuntime sceneRuntime, IRuntime api, ISceneExceptionsHandler sceneExceptionsHandler)
{
sceneRuntime.Register("UnityRuntime", new RuntimeWrapper(api, sceneExceptionsHandler, sceneRuntime.isDisposingTokenSource));
}
private static void RegisterEthereumApi(this ISceneRuntime sceneRuntime, IEthereumApi ethereumApi, IWeb3IdentityCache web3IdentityCache, ISceneExceptionsHandler sceneExceptionsHandler)
{
sceneRuntime.Register("UnityEthereumApi", new EthereumApiWrapper(ethereumApi, sceneExceptionsHandler, web3IdentityCache, sceneRuntime.isDisposingTokenSource));
}
private static void RegisterUserIdentityApi(this ISceneRuntime sceneRuntime, IProfileRepository profileRepository, IWeb3IdentityCache identityCache, ISceneExceptionsHandler sceneExceptionsHandler)
{
sceneRuntime.Register("UnityUserIdentityApi", new UserIdentityApiWrapper(profileRepository, identityCache, sceneExceptionsHandler, sceneRuntime.isDisposingTokenSource));
}
private static void RegisterWebSocketApi(this ISceneRuntime sceneRuntime, IWebSocketApi webSocketApi, ISceneExceptionsHandler sceneExceptionsHandler, bool isLocalSceneDevelopment)
{
sceneRuntime.Register("UnityWebSocketApi", new WebSocketApiWrapper(webSocketApi, sceneExceptionsHandler, sceneRuntime.isDisposingTokenSource, isLocalSceneDevelopment));
}
private static void RegisterCommunicationsControllerApi(this ISceneRuntime sceneRuntime, ICommunicationsControllerAPI api, IInstancePoolsProvider instancePoolsProvider, ISceneExceptionsHandler sceneExceptionsHandler, bool isLocalSceneDevelopment)
{
sceneRuntime.Register("UnityCommunicationsControllerApi", new CommunicationsControllerAPIWrapper(api, instancePoolsProvider, sceneExceptionsHandler, sceneRuntime.isDisposingTokenSource));
}
private static void RegisterSimpleFetchApi(this ISceneRuntime sceneRuntime, ISimpleFetchApi simpleFetchApi, IWebRequestController webRequestController, bool isLocalSceneDevelopment)
{
sceneRuntime.Register("UnitySimpleFetchApi", new SimpleFetchApiWrapper(simpleFetchApi, webRequestController, sceneRuntime.isDisposingTokenSource, isLocalSceneDevelopment));
}
public static void RegisterSDKMessageBusCommsApi(this ISceneRuntime sceneRuntime, ISDKMessageBusCommsControllerAPI api)
{
sceneRuntime.Register("UnitySDKMessageBusCommsControllerApi", new SDKMessageBusCommsControllerAPIWrapper(api, sceneRuntime.isDisposingTokenSource));
}
private static void RegisterPortableExperiencesApi(this ISceneRuntime sceneRuntime, IPortableExperiencesController portableExperiencesController, ISceneExceptionsHandler sceneExceptionsHandler)
{
sceneRuntime.Register("UnityPortableExperiencesApi", new PortableExperiencesApiWrapper(portableExperiencesController, sceneExceptionsHandler, sceneRuntime.isDisposingTokenSource));
}
}
}