-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathStaticContainer.cs
More file actions
369 lines (330 loc) · 21.2 KB
/
Copy pathStaticContainer.cs
File metadata and controls
369 lines (330 loc) · 21.2 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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
using Arch.Core;
using CommunicationData.URLHelpers;
using CrdtEcsBridge.Components;
using Cysharp.Threading.Tasks;
using DCL.AssetsProvision;
using DCL.Audio;
using DCL.AvatarRendering.AvatarShape.UnityInterface;
using DCL.AvatarRendering.Emotes;
using DCL.AvatarRendering.Emotes.Play;
using DCL.Multiplayer.Emotes;
using DCL.Character.Plugin;
using DCL.DebugUtilities;
using DCL.Diagnostics;
using DCL.ECSComponents;
using DCL.FeatureFlags;
using DCL.Gizmos.Plugin;
using DCL.Input;
using DCL.Interaction.Utility;
using DCL.Ipfs;
using DCL.Landscape.Utils;
using DCL.MapPins.Bus;
using DCL.Multiplayer.Connections.DecentralandUrls;
using DCL.Multiplayer.Connections.RoomHubs;
using DCL.Multiplayer.Profiles.Tables;
using DCL.Optimization.PerformanceBudgeting;
using DCL.Optimization.Pools;
using DCL.PerformanceAndDiagnostics;
using DCL.PluginSystem;
using DCL.PluginSystem.Global;
using DCL.PluginSystem.World;
using DCL.PluginSystem.World.Dependencies;
using DCL.Profiling;
using DCL.Quality;
using DCL.ResourcesUnloading;
using DCL.SceneRestrictionBusController.SceneRestrictionBus;
using DCL.Utilities;
using DCL.Web3;
using DCL.Web3.Identities;
using DCL.WebRequests.Analytics;
using ECS;
using ECS.Prioritization;
using ECS.SceneLifeCycle;
using ECS.SceneLifeCycle.Components;
using ECS.SceneLifeCycle.Reporting;
using SceneRunner.Mapping;
using System.Collections.Generic;
using System.Threading;
using DCL.PerformanceAndDiagnostics.Analytics;
using DCL.Profiles;
using DCL.RealmNavigation;
using DCL.Rendering.GPUInstancing;
using DCL.SDKComponents.MediaStream;
using DCL.SDKComponents.AvatarLocomotion;
using DCL.SDKComponents.ParticleSystem.Systems;
using DCL.SDKComponents.PhysicsImpulse.Systems;
using DCL.SDKComponents.SkyboxTime;
using DCL.Utility;
using ECS.SceneLifeCycle.IncreasingRadius;
using ECS.StreamableLoading.Cache.Disk;
using ECS.StreamableLoading.Common.Components;
using ECS.StreamableLoading.Textures;
using Global.AppArgs;
using ECS.Unity.GLTFContainer.Asset.Cache;
using PortableExperiences.Controller;
using Runtime.Wearables;
using System.Buffers;
using DCL.UI;
using ECS.Unity.AssetLoad.Cache;
using Global.Dynamic;
using Utility;
using DCL.Multiplayer.SDK.Systems.GlobalWorld;
using MultiplayerPlugin = DCL.PluginSystem.World.MultiplayerPlugin;
namespace Global
{
/// <summary>
/// Produces dependencies that never change during the lifetime of the application
/// and are not connected to the global world or scenes but are used by them.
/// This is the first container to instantiate, should not depend on any other container
/// </summary>
public class StaticContainer : IDCLPlugin<StaticSettings>
{
public readonly ObjectProxy<AvatarBase> MainPlayerAvatarBaseProxy = new ();
public readonly ObjectProxy<IRoomHub> RoomHubProxy = new ();
public readonly ObjectProxy<IReadOnlyEntityParticipantTable> EntityParticipantTableProxy = new ();
public readonly ObjectProxy<IEmotesMessageBus> EmotesMessageBusProxy = new ();
public readonly PartitionDataContainer PartitionDataContainer = new ();
public readonly IMapPinsEventBus MapPinsEventBus = new MapPinsEventBus();
private IAssetsProvisioner assetsProvisioner;
public Entity PlayerEntity { get; set; }
public RealmData RealmData { get; private set; }
public PublishIpfsEntityCommand PublishIpfsEntityCommand { get; private set; }
public ComponentsContainer ComponentsContainer { get; private set; }
public CharacterContainer CharacterContainer { get; private set; }
public MediaPlayerContainer MediaContainer { get; private set; }
public EmotesContainer EmotesContainer { get; private set; }
public ProfilesContainer ProfilesContainer { get; private set; }
public QualityContainer QualityContainer { get; private set; }
public ExposedGlobalDataContainer ExposedGlobalDataContainer { get; private set; }
public WebRequestsContainer WebRequestsContainer { get; private set; }
public IReadOnlyList<IDCLWorldPlugin> ECSWorldPlugins { get; private set; }
public IEmoteStorage EmoteStorage { get; private set; }
public ISystemMemoryCap MemoryCap { get; private set; }
public SceneLoadingLimit SceneLoadingLimit { get; private set; }
/// <summary>
/// Some plugins may implement both interfaces
/// </summary>
public IReadOnlyList<IDCLGlobalPlugin> SharedPlugins { get; private set; }
public ECSWorldSingletonSharedDependencies SingletonSharedDependencies { get; private set; }
public Profiler Profiler { get; private set; }
public IEntityCollidersGlobalCache EntityCollidersGlobalCache { get; private set; }
public IPartitionSettings PartitionSettings => StaticSettings.PartitionSettings;
public IRealmPartitionSettings RealmPartitionSettings => StaticSettings.RealmPartitionSettings;
public StaticSettings StaticSettings { get; private set; }
public CacheCleaner CacheCleaner { get; private set; }
public IEthereumApi EthereumApi { get; private set; }
public IInputBlock InputBlock { get; private set; }
public IScenesCache ScenesCache { get; private set; }
public ISceneReadinessReportQueue SceneReadinessReportQueue { get; private set; }
public HttpFeatureFlagsProvider FeatureFlagsProvider { get; private set; }
public IPortableExperiencesController PortableExperiencesController { get; private set; }
public SmartWearableCache SmartWearableCache { get; private set; }
public ImageControllerProvider ImageControllerProvider { get; private set; }
public IDebugContainerBuilder DebugContainerBuilder { get; private set; }
public ISceneRestrictionBusController SceneRestrictionBusController { get; private set; }
public GPUInstancingService GPUInstancingService { get; private set; }
public ILoadingStatus LoadingStatus { get; private set; }
public ILaunchMode LaunchMode { get; private set; }
public WorldManifestProvider WorldManifestProvider { get; private set; }
public IGltfContainerAssetsCache GltfContainerAssetsCache { get; private set; }
public AssetPreLoadCache AssetPreLoadCache { get; private set; }
public CharacterDataPropagationUtility CharacterDataPropagationUtility { get; private set; }
public void Dispose()
{
QualityContainer.Dispose();
Profiler.Dispose();
SceneRestrictionBusController.Dispose();
}
public UniTask InitializeAsync(StaticSettings settings, CancellationToken ct)
{
StaticSettings = settings;
return UniTask.CompletedTask;
}
public static async UniTask<(StaticContainer? container, bool success)> CreateAsync(
AnalyticsContainer analyticsContainer,
IDecentralandUrlsSource decentralandUrlsSource,
RealmData realmData,
IAssetsProvisioner assetsProvisioner,
IReportsHandlingSettings reportHandlingSettings,
IDebugContainerBuilder debugContainerBuilder,
WebRequestsContainer webRequestsContainer,
IPluginSettingsContainer settingsContainer,
DiagnosticsContainer diagnosticsContainer,
IWeb3IdentityCache web3IdentityProvider,
IEthereumApi ethereumApi,
ILaunchMode launchMode,
bool useRemoteAssetBundles,
World globalWorld,
Entity playerEntity,
ISystemMemoryCap memoryCap,
VolumeBus volumeBus,
bool enableAnalytics,
IDiskCache diskCache,
IDiskCache<PartialLoadingState> partialsDiskCache,
CancellationToken ct,
IAppArgs appArgs,
bool enableGPUInstancing = true)
{
ProfilingCounters.CleanAllCounters();
var componentsContainer = ComponentsContainer.Create();
var exposedGlobalDataContainer = ExposedGlobalDataContainer.Create();
var profilingProvider = new Profiler();
var container = new StaticContainer();
container.RealmData = realmData;
container.PublishIpfsEntityCommand = new PublishIpfsEntityCommand(web3IdentityProvider, webRequestsContainer.WebRequestController, decentralandUrlsSource, realmData);
container.PlayerEntity = playerEntity;
container.DebugContainerBuilder = debugContainerBuilder;
container.EthereumApi = ethereumApi;
container.ScenesCache = new ScenesCache();
container.SceneReadinessReportQueue = new SceneReadinessReportQueue(container.ScenesCache);
container.InputBlock = new ECSInputBlock(globalWorld);
container.assetsProvisioner = assetsProvisioner;
container.MemoryCap = memoryCap;
container.SceneRestrictionBusController = new SceneRestrictionBusController();
container.LaunchMode = launchMode;
var exposedPlayerTransform = new ExposedTransform();
StaticSettings staticSettings = settingsContainer.GetSettings<StaticSettings>();
container.LoadingStatus = enableAnalytics ? new LoadingStatusAnalyticsDecorator(new LoadingStatus(), analyticsContainer.Controller, web3IdentityProvider) : new LoadingStatus();
var sharedDependencies = new ECSWorldSingletonSharedDependencies(
componentsContainer.ComponentPoolsRegistry,
reportHandlingSettings,
new SceneEntityFactory(),
new PartitionedWorldsAggregate.Factory(),
new ConcurrentLoadingPerformanceBudget(staticSettings.AssetsLoadingBudget),
new FrameTimeCapBudget(staticSettings.FrameTimeCap, profilingProvider, container.LoadingStatus.IsLoadingScreenOn),
new MemoryBudget(memoryCap, profilingProvider, staticSettings.MemoryThresholds),
new SceneMapping()
);
DebugWidgetBuilder? cacheWidget = container.DebugContainerBuilder.TryAddWidget("Cache Textures");
container.CacheCleaner = new CacheCleaner(sharedDependencies.FrameTimeBudget, cacheWidget);
container.EmoteStorage = new MemoryEmotesStorage();
container.CacheCleaner.Register(container.EmoteStorage);
container.GltfContainerAssetsCache = new GltfContainerAssetsCache(componentsContainer.ComponentPoolsRegistry);
container.AssetPreLoadCache = new AssetPreLoadCache(container.GltfContainerAssetsCache);
container.GltfContainerAssetsCache.SetAssetLoadCache(container.AssetPreLoadCache);
container.CharacterContainer = new CharacterContainer(container.assetsProvisioner, exposedGlobalDataContainer.ExposedCameraData, exposedPlayerTransform);
container.MediaContainer = new MediaPlayerContainer(assetsProvisioner, webRequestsContainer.WebRequestController, volumeBus, sharedDependencies.FrameTimeBudget, container.RoomHubProxy, container.CacheCleaner, container.AssetPreLoadCache, analyticsContainer.Controller);
container.EmotesContainer = new EmotesContainer(assetsProvisioner);
container.ProfilesContainer = new ProfilesContainer(webRequestsContainer.WebRequestController, decentralandUrlsSource, container.PublishIpfsEntityCommand, analyticsContainer);
bool result = await InitializeContainersAsync(container, settingsContainer, ct);
if (!result)
return (null, false);
container.QualityContainer = await QualityContainer.CreateAsync(settingsContainer, container.assetsProvisioner);
container.ComponentsContainer = componentsContainer;
container.SingletonSharedDependencies = sharedDependencies;
container.Profiler = profilingProvider;
container.EntityCollidersGlobalCache = new EntityCollidersGlobalCache();
container.ExposedGlobalDataContainer = exposedGlobalDataContainer;
container.WebRequestsContainer = webRequestsContainer;
container.PortableExperiencesController = new ECSPortableExperiencesController(web3IdentityProvider, container.WebRequestsContainer.WebRequestController, container.ScenesCache, launchMode, decentralandUrlsSource);
container.SmartWearableCache = new SmartWearableCache(webRequestsContainer.WebRequestController);
container.ImageControllerProvider = new ImageControllerProvider(globalWorld);
container.FeatureFlagsProvider = new HttpFeatureFlagsProvider(container.WebRequestsContainer.WebRequestController);
container.GltfContainerAssetsCache = new GltfContainerAssetsCache(componentsContainer.ComponentPoolsRegistry);
ArrayPool<byte> buffersPool = ArrayPool<byte>.Create(1024 * 1024 * 50, 50);
var assetBundlePlugin = new AssetBundlesPlugin(reportHandlingSettings, container.CacheCleaner, container.WebRequestsContainer.WebRequestController, buffersPool, partialsDiskCache, URLDomain.FromString(decentralandUrlsSource.Url(DecentralandUrl.AssetBundlesCDN)), container.GltfContainerAssetsCache);
var textureDiskCache = new DiskCache<TextureData, SerializeMemoryIterator<TextureDiskSerializer.State>>(diskCache, new TextureDiskSerializer());
var textureResolvePlugin = new TexturesLoadingPlugin(container.WebRequestsContainer.WebRequestController, container.CacheCleaner, textureDiskCache, launchMode, container.ProfilesContainer.Repository);
diagnosticsContainer.AddSentryScopeConfigurator(scope =>
{
if (container.ScenesCache.CurrentScene.Value != null)
diagnosticsContainer.Sentry!.AddCurrentSceneToScope(scope, container.ScenesCache.CurrentScene.Value.Info);
});
container.ScenesCache.CurrentScene.OnUpdate += scene =>
{
if (scene != null)
UnityDiagnosticsCenter.Instance.SetCurrentScene(scene.Info);
};
diagnosticsContainer.AddSentryScopeConfigurator(scope =>
{
diagnosticsContainer.Sentry?.AddRealmInfoToScope(scope,
container.RealmData.Ipfs.CatalystBaseUrl.Value,
container.RealmData.Ipfs.ContentBaseUrl.Value,
container.RealmData.Ipfs.LambdasBaseUrl.Value);
});
var renderFeature = container.QualityContainer.RendererFeaturesCache.GetRendererFeature<GPUInstancingRenderFeature>();
if (enableGPUInstancing && renderFeature != null && renderFeature.Settings != null && renderFeature.Settings.FrustumCullingAndLODGenComputeShader != null)
{
container.GPUInstancingService = new GPUInstancingService(renderFeature.Settings);
renderFeature.Initialize(container.GPUInstancingService, container.RealmData);
}
else
ReportHub.LogError("No renderer feature presented.", ReportCategory.GPU_INSTANCING);
var promisesAnalyticsPlugin = new PromisesAnalyticsPlugin(debugContainerBuilder);
container.CharacterDataPropagationUtility = new CharacterDataPropagationUtility(
componentsContainer.ComponentPoolsRegistry.AddComponentPool<SDKProfile>());
container.ECSWorldPlugins = new IDCLWorldPlugin[]
{
new GltfContainerPlugin(sharedDependencies, container.CacheCleaner, container.SceneReadinessReportQueue, launchMode, useRemoteAssetBundles, container.WebRequestsContainer.WebRequestController, container.LoadingStatus, container.GltfContainerAssetsCache, appArgs, componentsContainer.ComponentPoolsRegistry.RootContainerTransform()),
new TransformsPlugin(sharedDependencies, exposedPlayerTransform, exposedGlobalDataContainer.ExposedCameraData),
new BillboardPlugin(exposedGlobalDataContainer.ExposedCameraData),
new NFTShapePlugin(decentralandUrlsSource, container.assetsProvisioner, sharedDependencies.FrameTimeBudget, componentsContainer.ComponentPoolsRegistry, container.WebRequestsContainer.WebRequestController, container.CacheCleaner, container.MediaContainer.mediaFactoryBuilder),
new TextShapePlugin(sharedDependencies.FrameTimeBudget, container.CacheCleaner, componentsContainer.ComponentPoolsRegistry, assetsProvisioner),
new MaterialsPlugin(sharedDependencies, container.MediaContainer.mediaFactoryBuilder),
textureResolvePlugin,
new AssetsCollidersPlugin(sharedDependencies),
new AvatarShapePlugin(globalWorld, componentsContainer.ComponentPoolsRegistry, launchMode, useRemoteAssetBundles),
new AvatarAttachPlugin(globalWorld, container.MainPlayerAvatarBaseProxy, componentsContainer.ComponentPoolsRegistry, container.EntityParticipantTableProxy, exposedPlayerTransform),
new SceneMaskedEmotePlugin(globalWorld, container.PlayerEntity, container.MainPlayerAvatarBaseProxy, container.EmotesContainer.EmotePlayer, container.EmoteStorage, container.EmotesMessageBusProxy),
new PrimitivesRenderingPlugin(sharedDependencies),
new VisibilityPlugin(),
new AudioSourcesPlugin(sharedDependencies, container.WebRequestsContainer.WebRequestController, container.CacheCleaner, container.assetsProvisioner),
new AudioAnalysisPlugin(sharedDependencies),
assetBundlePlugin,
new InteractionPlugin(sharedDependencies, profilingProvider, exposedGlobalDataContainer.GlobalInputEvents, componentsContainer.ComponentPoolsRegistry, container.assetsProvisioner),
new SceneUIPlugin(sharedDependencies, container.assetsProvisioner, container.InputBlock),
container.CharacterContainer.CreateWorldPlugin(componentsContainer.ComponentPoolsRegistry),
new AnimatorPlugin(),
new TweenPlugin(),
container.MediaContainer.CreatePlugin(exposedGlobalDataContainer.ExposedCameraData),
new SDKEntityTriggerAreaPlugin(
globalWorld,
container.MainPlayerAvatarBaseProxy,
exposedGlobalDataContainer.ExposedCameraData.CameraEntityProxy,
container.CharacterContainer.CharacterObject,
componentsContainer.ComponentPoolsRegistry,
container.assetsProvisioner,
container.CacheCleaner,
exposedGlobalDataContainer.ExposedCameraData,
container.SceneRestrictionBusController, web3IdentityProvider),
new PointerInputAudioPlugin(container.assetsProvisioner),
new MapPinPlugin(globalWorld, container.MapPinsEventBus),
new MultiplayerPlugin(globalWorld, playerEntity, container.CharacterDataPropagationUtility),
new RealmInfoPlugin(container.RealmData, container.RoomHubProxy),
new InputModifierPlugin(globalWorld, container.PlayerEntity, container.SceneRestrictionBusController),
new MainCameraPlugin(componentsContainer.ComponentPoolsRegistry, container.assetsProvisioner, container.CacheCleaner, exposedGlobalDataContainer.ExposedCameraData, container.SceneRestrictionBusController, globalWorld),
new LightSourcePlugin(componentsContainer.ComponentPoolsRegistry, container.assetsProvisioner, container.CacheCleaner, container.CharacterContainer.CharacterObject, globalWorld, appArgs.HasDebugFlag()),
new ParticleSystemPlugin(componentsContainer.ComponentPoolsRegistry, container.assetsProvisioner, container.CacheCleaner, container.DebugContainerBuilder),
new PrimaryPointerInfoPlugin(globalWorld),
promisesAnalyticsPlugin,
new SkyboxTimePlugin(),
new AvatarLocomotionOverridesWorldPlugin(globalWorld, playerEntity),
#if UNITY_EDITOR
new GizmosWorldPlugin(),
#endif
new PointerLockPlugin(globalWorld, exposedGlobalDataContainer.ExposedCameraData),
new AssetPreLoadPlugin(sharedDependencies, container.AssetPreLoadCache),
new SDKExternalPhysicsPlugin(globalWorld, playerEntity),
};
container.SceneLoadingLimit = new SceneLoadingLimit(container.MemoryCap);
container.SharedPlugins = new IDCLGlobalPlugin[]
{
assetBundlePlugin,
textureResolvePlugin,
promisesAnalyticsPlugin
};
container.WorldManifestProvider = new WorldManifestProvider(container.WebRequestsContainer.WebRequestController);
return (container, true);
}
private static async UniTask<bool> InitializeContainersAsync(StaticContainer target, IPluginSettingsContainer settings, CancellationToken ct)
{
((StaticContainer plugin, bool success), (CharacterContainer plugin, bool success), (MediaPlayerContainer plugin, bool success), (EmotesContainer plugin, bool success)) results = await UniTask.WhenAll(
settings.InitializePluginAsync(target, ct),
settings.InitializePluginAsync(target.CharacterContainer, ct),
settings.InitializePluginAsync(target.MediaContainer, ct),
settings.InitializePluginAsync(target.EmotesContainer, ct)
);
return results.Item1.success && results.Item2.success && results.Item3.success && results.Item4.success;
}
}
}