< Summary

Class:DCL.Main
Assembly:Main
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Scene/Main/Main.cs
Covered lines:0
Uncovered lines:70
Coverable lines:70
Total lines:172
Line coverage:0% (0 of 70)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%42600%
OnLoadingScreenVisibleStateChange(...)0%6200%
SetupPlugins()0%2100%
SetupEnvironment()0%2100%
MessagingContextBuilder()0%2100%
PlatformContextBuilder()0%2100%
WorldRuntimeContextBuilder()0%2100%
HUDContextBuilder()0%2100%
Start()0%2100%
Update()0%6200%
OnDestroy()0%20400%
InitializeSceneDependencies()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Scene/Main/Main.cs

#LineLine coverage
 1using System;
 2using DCL.Components;
 3using DCL.Controllers;
 4using DCL.Helpers;
 5using DCL.SettingsCommon;
 6using UnityEngine;
 7using UnityEngine.Serialization;
 8
 9namespace DCL
 10{
 11    /// <summary>
 12    /// This is the InitialScene entry point.
 13    /// Most of the application subsystems should be initialized from this class Awake() event.
 14    /// </summary>
 15    public class Main : MonoBehaviour
 16    {
 17        [SerializeField] private bool disableSceneDependencies;
 018        public static Main i { get; private set; }
 19
 20        public PoolableComponentFactory componentFactory;
 21
 22        private PerformanceMetricsController performanceMetricsController;
 23        protected IKernelCommunication kernelCommunication;
 24
 25        private PluginSystem pluginSystem;
 26
 27        protected virtual void Awake()
 28        {
 029            if (i != null)
 30            {
 031                Utils.SafeDestroy(this);
 032                return;
 33            }
 34
 035            i = this;
 36
 037            Settings.CreateSharedInstance(new DefaultSettingsFactory());
 38
 039            if (!disableSceneDependencies)
 040                InitializeSceneDependencies();
 41
 042            if (!Configuration.EnvironmentSettings.RUNNING_TESTS)
 43            {
 044                performanceMetricsController = new PerformanceMetricsController();
 045                RenderProfileManifest.i.Initialize();
 046                SetupEnvironment();
 47
 048                DataStore.i.HUDs.loadingHUD.visible.OnChange += OnLoadingScreenVisibleStateChange;
 49            }
 50
 051            SetupPlugins();
 52
 53#if UNITY_WEBGL && !UNITY_EDITOR
 54            Debug.Log("DCL Unity Build Version: " + DCL.Configuration.ApplicationSettings.version);
 55            Debug.unityLogger.logEnabled = false;
 56
 57            kernelCommunication = new NativeBridgeCommunication(Environment.i.world.sceneController);
 58#else
 59            // TODO(Brian): Remove this branching once we finish migrating all tests out of the
 60            //              IntegrationTestSuite_Legacy base class.
 061            if (!Configuration.EnvironmentSettings.RUNNING_TESTS)
 62            {
 63#if UNITY_STANDALONE && !UNITY_EDITOR
 64                kernelCommunication = new WebSocketCommunication(true);
 65#else
 066                kernelCommunication = new WebSocketCommunication(DebugConfigComponent.i.webSocketSSL);
 67#endif
 68            }
 69#endif
 70
 71            // TODO(Brian): This is a temporary fix to address elevators issue in the xmas event.
 72            // We should re-enable this later as produces a performance regression.
 073            if (!Configuration.EnvironmentSettings.RUNNING_TESTS)
 074                Environment.i.platform.cullingController.SetAnimationCulling(false);
 075        }
 76
 77        void OnLoadingScreenVisibleStateChange(bool newVisibleValue, bool previousVisibleValue)
 78        {
 079            if (newVisibleValue)
 80            {
 81                // Prewarm shader variants
 082                Resources.Load<ShaderVariantCollection>("ShaderVariantCollections/shaderVariants-selected").WarmUp();
 083                DataStore.i.HUDs.loadingHUD.visible.OnChange -= OnLoadingScreenVisibleStateChange;
 84            }
 085        }
 86
 87        protected virtual void SetupPlugins()
 88        {
 089            pluginSystem = PluginSystemFactory.Create();
 090        }
 91
 92        protected virtual void SetupEnvironment()
 93        {
 094            Environment.SetupWithBuilders(
 95                messagingBuilder: MessagingContextBuilder,
 96                platformBuilder: PlatformContextBuilder,
 97                worldRuntimeBuilder: WorldRuntimeContextBuilder,
 98                hudBuilder: HUDContextBuilder);
 099        }
 100
 0101        protected virtual MessagingContext MessagingContextBuilder() { return MessagingContextFactory.CreateDefault(); }
 102
 0103        protected virtual PlatformContext PlatformContextBuilder() { return PlatformContextFactory.CreateDefault(); }
 104
 0105        protected virtual WorldRuntimeContext WorldRuntimeContextBuilder() { return WorldRuntimeContextFactory.CreateDef
 106
 0107        protected virtual HUDContext HUDContextBuilder() { return HUDContextFactory.CreateDefault(); }
 108
 109        protected virtual void Start()
 110        {
 111            // this event should be the last one to be executed after initialization
 112            // it is used by the kernel to signal "EngineReady" or something like that
 113            // to prevent race conditions like "SceneController is not an object",
 114            // aka sending events before unity is ready
 0115            DCL.Interface.WebInterface.SendSystemInfoReport();
 116
 117            // We trigger the Decentraland logic once everything is initialized.
 0118            DCL.Interface.WebInterface.StartDecentraland();
 119
 0120            Environment.i.world.sceneController.Start();
 0121        }
 122
 123        protected virtual void Update()
 124        {
 0125            Environment.i.platform.Update();
 0126            performanceMetricsController?.Update();
 0127        }
 128
 129        protected virtual void OnDestroy()
 130        {
 0131            DataStore.i.HUDs.loadingHUD.visible.OnChange -= OnLoadingScreenVisibleStateChange;
 132
 0133            DataStore.i.common.isWorldBeingDestroyed.Set(true);
 134
 0135            pluginSystem?.Dispose();
 136
 0137            if (!Configuration.EnvironmentSettings.RUNNING_TESTS)
 0138                Environment.Dispose();
 139
 0140            kernelCommunication?.Dispose();
 0141        }
 142
 143        protected virtual void InitializeSceneDependencies()
 144        {
 0145            gameObject.AddComponent<UserProfileController>();
 0146            gameObject.AddComponent<RenderingController>();
 0147            gameObject.AddComponent<CatalogController>();
 0148            gameObject.AddComponent<MinimapMetadataController>();
 0149            gameObject.AddComponent<ChatController>();
 0150            gameObject.AddComponent<FriendsController>();
 0151            gameObject.AddComponent<LoadingFeedbackController>();
 0152            gameObject.AddComponent<HotScenesController>();
 0153            gameObject.AddComponent<GIFProcessingBridge>();
 0154            gameObject.AddComponent<RenderProfileBridge>();
 0155            gameObject.AddComponent<AssetCatalogBridge>();
 0156            gameObject.AddComponent<ScreenSizeWatcher>();
 0157            gameObject.AddComponent<SceneControllerBridge>();
 158
 0159            MainSceneFactory.CreateBuilderInWorldBridge(gameObject);
 0160            MainSceneFactory.CreateBridges();
 0161            MainSceneFactory.CreateMouseCatcher();
 0162            MainSceneFactory.CreatePlayerSystems();
 0163            MainSceneFactory.CreateEnvironment();
 0164            MainSceneFactory.CreateAudioHandler();
 0165            MainSceneFactory.CreateHudController();
 0166            MainSceneFactory.CreateSettingsController();
 0167            MainSceneFactory.CreateNavMap();
 0168            MainSceneFactory.CreateEventSystem();
 0169            MainSceneFactory.CreateInteractionHoverCanvas();
 0170        }
 171    }
 172}