-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathSceneInstanceDeps.cs
More file actions
339 lines (318 loc) · 15.9 KB
/
Copy pathSceneInstanceDeps.cs
File metadata and controls
339 lines (318 loc) · 15.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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
using Arch.Core;
using CommunicationData.URLHelpers;
using CRDT;
using CRDT.Deserializer;
using CRDT.Memory;
using CRDT.Protocol;
using CRDT.Serializer;
using CrdtEcsBridge.Components;
using CrdtEcsBridge.ComponentWriter;
using CrdtEcsBridge.ECSToCRDTWriter;
using CrdtEcsBridge.JsModulesImplementation;
using CrdtEcsBridge.JsModulesImplementation.Communications;
using CrdtEcsBridge.OutgoingMessages;
using CrdtEcsBridge.PoolsProviders;
using CrdtEcsBridge.RestrictedActions;
using CrdtEcsBridge.UpdateGate;
using CrdtEcsBridge.WorldSynchronizer;
using DCL.Clipboard;
using DCL.Infrastructure.CrdtEcsBridge.JsModulesImplementation.RestrictedActions;
using DCL.Interaction.Utility;
using DCL.Multiplayer.Connections.RoomHubs;
using DCL.PluginSystem.World.Dependencies;
using DCL.Profiles;
using DCL.Profiling;
using DCL.SceneRunner;
using DCL.SceneRuntime.Apis.RestrictedActionsApi;
using DCL.SDKComponents.MediaStream;
using DCL.SkyBox;
using DCL.Utilities;
using DCL.Utilities.Extensions;
using DCL.WebRequests;
using ECS;
using ECS.Abstract;
using ECS.Prioritization.Components;
using MVC;
using SceneRunner.ECSWorld;
using SceneRunner.Scene;
using SceneRunner.Scene.ExceptionsHandling;
using SceneRuntime;
using SceneRuntime.Apis.Modules;
using SceneRuntime.Apis.Modules.CommunicationsControllerApi;
using SceneRuntime.Apis.Modules.EngineApi;
using SceneRuntime.Apis.Modules.FetchApi;
using SceneRuntime.Apis.Modules.Runtime;
using SceneRuntime.Apis.Modules.SceneApi;
using SceneRuntime.ScenePermissions;
using System;
using System.Collections.Generic;
using Utility.Multithreading;
using RichTypes;
namespace SceneRunner
{
/// <summary>
/// Dependencies that are unique for each instance of the scene,
/// this class itself contains the first stage of dependencies
/// </summary>
public class SceneInstanceDependencies : IDisposable
{
public readonly ICRDTProtocol CRDTProtocol;
public readonly IInstancePoolsProvider PoolsProvider;
public readonly ICRDTMemoryAllocator CRDTMemoryAllocator;
public readonly IOutgoingCRDTMessagesProvider OutgoingCRDTMessagesProvider;
public readonly IEntityCollidersSceneCache EntityCollidersCache;
public readonly ISceneStateProvider SceneStateProvider;
public readonly ISceneExceptionsHandler ExceptionsHandler;
public readonly ECSWorldFacade ECSWorldFacade;
public readonly SceneRuntimeMetrics RuntimeMetrics = new ();
public readonly ICRDTWorldSynchronizer CRDTWorldSynchronizer;
public readonly URLAddress SceneCodeUrl;
public readonly SceneEcsExecutor EcsExecutor;
internal readonly ISystemGroupsUpdateGate systemGroupThrottler;
private readonly ISystemsUpdateGate systemsUpdateGate;
private readonly ISceneData sceneData;
private readonly IJsApiPermissionsProvider permissionsProvider;
private readonly MultiThreadSync ecsMultiThreadSync;
private readonly ICRDTDeserializer crdtDeserializer;
private readonly IECSToCRDTWriter ecsToCRDTWriter;
private readonly ECSWorldInstanceSharedDependencies ecsWorldSharedDependencies;
private readonly Dictionary<CRDTEntity, Entity> entitiesMap = new (1000, CRDTEntityComparer.INSTANCE);
#if UNITY_INCLUDE_TESTS
internal SceneInstanceDependencies(
ICRDTProtocol crdtProtocol,
IInstancePoolsProvider poolsProvider,
ICRDTMemoryAllocator crdtMemoryAllocator,
IOutgoingCRDTMessagesProvider outgoingCRDTMessagesProvider,
IEntityCollidersSceneCache entityCollidersCache,
ISceneStateProvider sceneStateProvider,
ISceneExceptionsHandler exceptionsHandler,
ECSWorldFacade ecsWorldFacade,
ICRDTWorldSynchronizer crdtWorldSynchronizer,
URLAddress sceneCodeUrl,
SceneEcsExecutor ecsExecutor,
ISceneData sceneData,
MultiThreadSync ecsMultiThreadSync,
ICRDTDeserializer crdtDeserializer,
IECSToCRDTWriter ecsToCRDTWriter,
ISystemGroupsUpdateGate systemGroupThrottler,
ISystemsUpdateGate systemsUpdateGate,
ECSWorldInstanceSharedDependencies ecsWorldSharedDependencies)
{
CRDTProtocol = crdtProtocol;
PoolsProvider = poolsProvider;
CRDTMemoryAllocator = crdtMemoryAllocator;
OutgoingCRDTMessagesProvider = outgoingCRDTMessagesProvider;
EntityCollidersCache = entityCollidersCache;
SceneStateProvider = sceneStateProvider;
ExceptionsHandler = exceptionsHandler;
ECSWorldFacade = ecsWorldFacade;
CRDTWorldSynchronizer = crdtWorldSynchronizer;
SceneCodeUrl = sceneCodeUrl;
EcsExecutor = ecsExecutor;
this.sceneData = sceneData;
this.ecsMultiThreadSync = ecsMultiThreadSync;
this.crdtDeserializer = crdtDeserializer;
this.ecsToCRDTWriter = ecsToCRDTWriter;
this.systemGroupThrottler = systemGroupThrottler;
this.systemsUpdateGate = systemsUpdateGate;
this.ecsWorldSharedDependencies = ecsWorldSharedDependencies;
}
#endif
public SceneInstanceDependencies(
ISDKComponentsRegistry sdkComponentsRegistry,
IEntityCollidersGlobalCache entityCollidersGlobalCache,
ISceneData sceneData,
IJsApiPermissionsProvider permissionsProvider,
IPartitionComponent partitionProvider,
IECSWorldFactory ecsWorldFactory,
ISceneEntityFactory entityFactory)
{
this.sceneData = sceneData;
this.permissionsProvider = permissionsProvider;
ecsMultiThreadSync = new MultiThreadSync(sceneData.SceneShortInfo);
CRDTProtocol = new CRDTProtocol();
SceneStateProvider = new SceneStateProvider();
systemGroupThrottler = new SystemGroupsUpdateGate();
systemsUpdateGate = new SystemsPriorityComponentsGate();
PoolsProvider = InstancePoolsProvider.Create().EnsureNotNull();
CRDTMemoryAllocator = CRDTPooledMemoryAllocator.Create().EnsureNotNull();
crdtDeserializer = new CRDTDeserializer(CRDTMemoryAllocator);
OutgoingCRDTMessagesProvider = new OutgoingCRDTMessagesProvider(sdkComponentsRegistry, CRDTProtocol, CRDTMemoryAllocator);
ecsToCRDTWriter = new ECSToCRDTWriter(OutgoingCRDTMessagesProvider);
EntityCollidersCache = EntityCollidersSceneCache.Create(entityCollidersGlobalCache);
ExceptionsHandler = SceneExceptionsHandler.Create(SceneStateProvider, sceneData.SceneShortInfo).EnsureNotNull();
var entityEventsBuilder = new EntityEventsBuilder();
/* Pass dependencies here if they are needed by the systems */
ecsWorldSharedDependencies = new ECSWorldInstanceSharedDependencies(sceneData, partitionProvider, ecsToCRDTWriter, entitiesMap,
ExceptionsHandler, EntityCollidersCache, SceneStateProvider, entityEventsBuilder, ecsMultiThreadSync,
systemGroupThrottler, systemsUpdateGate, RuntimeMetrics);
ECSWorldFacade = ecsWorldFactory.CreateWorld(new ECSWorldFactoryArgs(ecsWorldSharedDependencies, systemGroupThrottler, sceneData));
CRDTWorldSynchronizer = new CRDTWorldSynchronizer(ECSWorldFacade.EcsWorld, sdkComponentsRegistry, entityFactory, entitiesMap);
EcsExecutor = new SceneEcsExecutor(ECSWorldFacade.EcsWorld);
entityCollidersGlobalCache.AddSceneInfo(EntityCollidersCache, EcsExecutor);
if (sceneData.IsSdk7()) // Create an instance of Scene Runtime on the thread pool
sceneData.TryGetMainScriptUrl(out SceneCodeUrl);
else
SceneCodeUrl = URLAddress.FromString("https://renderer-artifacts.decentraland.org/sdk7-adaption-layer/main/index.js");
}
public void Dispose()
{
// The order can make a difference here
ECSWorldFacade.Dispose();
CRDTProtocol.Dispose();
OutgoingCRDTMessagesProvider.Dispose();
CRDTWorldSynchronizer.Dispose();
PoolsProvider.Dispose();
CRDTMemoryAllocator.Dispose();
systemGroupThrottler.Dispose();
systemsUpdateGate.Dispose();
EntityCollidersCache.Dispose();
ecsMultiThreadSync.Dispose();
ExceptionsHandler.Dispose();
}
/// <summary>
/// The base class is for Observables
/// </summary>
public abstract class WithRuntimeAndJsAPIBase : IDisposable
{
public readonly IRestrictedActionsAPI RestrictedActionsAPI;
public readonly IRuntime RuntimeImplementation;
public readonly ISceneApi SceneApiImplementation;
public readonly IWebSocketApi WebSocketAipImplementation;
public readonly ICommunicationsControllerAPI CommunicationsControllerAPI;
public readonly ISimpleFetchApi SimpleFetchApi;
public readonly SceneInstanceDependencies SyncDeps;
public readonly ISceneRuntime Runtime;
public readonly IEngineApi EngineAPI;
/// <summary>
/// For Unit Tests only
/// </summary>
protected internal WithRuntimeAndJsAPIBase(
IEngineApi engineAPI,
IRestrictedActionsAPI restrictedActionsAPI,
IRuntime runtimeImplementation,
ISceneApi sceneApiImplementation,
IWebSocketApi webSocketApi,
ISimpleFetchApi simpleFetchApi,
ICommunicationsControllerAPI communicationsControllerAPI,
SceneInstanceDependencies syncDeps,
ISceneRuntime runtime
)
{
EngineAPI = engineAPI;
RestrictedActionsAPI = restrictedActionsAPI;
RuntimeImplementation = runtimeImplementation;
SceneApiImplementation = sceneApiImplementation;
CommunicationsControllerAPI = communicationsControllerAPI;
WebSocketAipImplementation = webSocketApi;
SimpleFetchApi = simpleFetchApi;
SyncDeps = syncDeps;
Runtime = runtime;
}
protected WithRuntimeAndJsAPIBase(
IEngineApi engineApi,
SceneInstanceDependencies syncDeps,
ISceneRuntime sceneRuntime,
IJsOperations jsOperations,
IMVCManager mvcManager,
IGlobalWorldActions globalWorldActions,
IRealmData realmData,
IProfileRepository profileRepository,
ISceneCommunicationPipe messagePipesHub,
IWebRequestController webRequestController,
SkyboxSettingsAsset skyboxSettings,
ISystemClipboard systemClipboard,
IRoomHub roomHub,
string installSource)
: this(
engineApi,
new RestrictedActionsAPIImplementation(mvcManager, syncDeps.ecsWorldSharedDependencies.SceneStateProvider, globalWorldActions, syncDeps.sceneData, syncDeps.permissionsProvider, systemClipboard, syncDeps.ECSWorldFacade.EcsWorld, syncDeps.ECSWorldFacade.PersistentEntities.Player, new ExplorerUiActions(mvcManager)),
new RuntimeImplementation(jsOperations, syncDeps.sceneData, realmData, webRequestController, skyboxSettings, roomHub, installSource),
new SceneApiImplementation(syncDeps.sceneData),
new ClientWebSocketApiImplementation(syncDeps.PoolsProvider, jsOperations, syncDeps.permissionsProvider),
new LogSimpleFetchApi(new SimpleFetchApiImplementation(syncDeps.sceneData.SceneShortInfo, syncDeps.permissionsProvider, profileRepository)),
new CommunicationsControllerAPIImplementation(
syncDeps.sceneData,
messagePipesHub,
jsOperations,
syncDeps.PoolsProvider
),
syncDeps,
sceneRuntime
) { }
public void Dispose()
{
// Runtime is responsible to dispose APIs
Runtime.Dispose();
SyncDeps.Dispose();
}
}
internal class WithRuntimeAndJsAPI : WithRuntimeAndJsAPIBase
{
public WithRuntimeAndJsAPI
(SceneInstanceDependencies syncDeps, SceneRuntimeImpl sceneRuntime, ISharedPoolsProvider sharedPoolsProvider, ICRDTSerializer crdtSerializer, IMVCManager mvcManager,
IGlobalWorldActions globalWorldActions, IRealmData realmData, ISceneCommunicationPipe messagePipesHub,
IWebRequestController webRequestController,
SkyboxSettingsAsset skyboxSettings,
MultiThreadSync.Owner syncOwner,
IProfileRepository profileRepository,
ISystemClipboard systemClipboard,
IRoomHub roomHub,
string installSource)
: base(new EngineAPIImplementation(
sharedPoolsProvider,
syncDeps.PoolsProvider,
syncDeps.CRDTProtocol,
syncDeps.crdtDeserializer,
crdtSerializer,
syncDeps.CRDTWorldSynchronizer,
syncDeps.OutgoingCRDTMessagesProvider,
syncDeps.systemGroupThrottler,
syncDeps.ExceptionsHandler,
syncDeps.ecsMultiThreadSync,
syncOwner,
syncDeps.RuntimeMetrics),
syncDeps, sceneRuntime, sceneRuntime, mvcManager, globalWorldActions, realmData, profileRepository, messagePipesHub, webRequestController, skyboxSettings, systemClipboard, roomHub, installSource) { }
}
internal class WithRuntimeJsAndSDKObservablesEngineAPI : WithRuntimeAndJsAPIBase
{
public WithRuntimeJsAndSDKObservablesEngineAPI
(SceneInstanceDependencies syncDeps, SceneRuntimeImpl sceneRuntime, ISharedPoolsProvider sharedPoolsProvider, ICRDTSerializer crdtSerializer, IMVCManager mvcManager,
IGlobalWorldActions globalWorldActions, IRealmData realmData, ISceneCommunicationPipe messagePipesHub,
IWebRequestController webRequestController, SkyboxSettingsAsset skyboxSettings, MultiThreadSync.Owner syncOwner,
IProfileRepository profileRepository,
ISystemClipboard systemClipboard,
IRoomHub roomHub,
string installSource)
: base(
new SDKObservableEventsEngineAPIImplementation(
sharedPoolsProvider,
syncDeps.PoolsProvider,
syncDeps.CRDTProtocol,
syncDeps.crdtDeserializer,
crdtSerializer,
syncDeps.CRDTWorldSynchronizer,
syncDeps.OutgoingCRDTMessagesProvider,
syncDeps.systemGroupThrottler,
syncDeps.ExceptionsHandler,
syncDeps.ecsMultiThreadSync,
syncOwner,
syncDeps.RuntimeMetrics
),
syncDeps,
sceneRuntime,
sceneRuntime,
mvcManager,
globalWorldActions,
realmData,
profileRepository,
messagePipesHub,
webRequestController,
skyboxSettings,
systemClipboard,
roomHub,
installSource
) { }
}
}
}