< 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:67
Coverable lines:67
Total lines:164
Line coverage:0% (0 of 67)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%42600%
InitializeCommunication()0%6200%
OnLoadingScreenVisibleStateChange(...)0%6200%
SetupPlugins()0%2100%
SetupServices()0%2100%
Start()0%2100%
Update()0%6200%
OnDestroy()0%30500%
InitializeSceneDependencies()0%2100%
CreateEnvironment()0%2100%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using DCL.Components;
 4using DCL.Controllers;
 5using DCL.Helpers;
 6using DCL.SettingsCommon;
 7using UnityEngine;
 8using UnityEngine.Serialization;
 9
 10namespace DCL
 11{
 12    /// <summary>
 13    /// This is the InitialScene entry point.
 14    /// Most of the application subsystems should be initialized from this class Awake() event.
 15    /// </summary>
 16    public class Main : MonoBehaviour
 17    {
 18        [SerializeField] private bool disableSceneDependencies;
 019        public static Main i { get; private set; }
 20
 21        public PoolableComponentFactory componentFactory;
 22
 23        private PerformanceMetricsController performanceMetricsController;
 24        protected IKernelCommunication kernelCommunication;
 25
 26        protected PluginSystem pluginSystem;
 27
 28        protected virtual void Awake()
 29        {
 030            if (i != null)
 31            {
 032                Utils.SafeDestroy(this);
 033                return;
 34            }
 35
 036            i = this;
 37
 038            Settings.CreateSharedInstance(new DefaultSettingsFactory());
 39
 040            if (!disableSceneDependencies)
 041                InitializeSceneDependencies();
 42
 043            if (!Configuration.EnvironmentSettings.RUNNING_TESTS)
 44            {
 045                performanceMetricsController = new PerformanceMetricsController();
 046                SetupServices();
 47
 048                DataStore.i.HUDs.loadingHUD.visible.OnChange += OnLoadingScreenVisibleStateChange;
 49            }
 50
 51#if UNITY_STANDALONE || UNITY_EDITOR
 052            Application.quitting += () => DataStore.i.common.isApplicationQuitting.Set(true);
 53#endif
 54
 055            SetupPlugins();
 56
 057            InitializeCommunication();
 58
 59            // TODO(Brian): This is a temporary fix to address elevators issue in the xmas event.
 60            // We should re-enable this later as produces a performance regression.
 061            if (!Configuration.EnvironmentSettings.RUNNING_TESTS)
 062                Environment.i.platform.cullingController.SetAnimationCulling(false);
 063        }
 64
 65        protected virtual void InitializeCommunication()
 66        {
 67
 68#if UNITY_WEBGL && !UNITY_EDITOR
 69            Debug.Log("DCL Unity Build Version: " + DCL.Configuration.ApplicationSettings.version);
 70            Debug.unityLogger.logEnabled = false;
 71
 72            kernelCommunication = new NativeBridgeCommunication(Environment.i.world.sceneController);
 73#else
 74            // TODO(Brian): Remove this branching once we finish migrating all tests out of the
 75            //              IntegrationTestSuite_Legacy base class.
 076            if (!Configuration.EnvironmentSettings.RUNNING_TESTS)
 77            {
 078                kernelCommunication = new WebSocketCommunication(DebugConfigComponent.i.webSocketSSL);
 79            }
 80#endif
 081        }
 82
 83        void OnLoadingScreenVisibleStateChange(bool newVisibleValue, bool previousVisibleValue)
 84        {
 085            if (newVisibleValue)
 86            {
 87                // Prewarm shader variants
 088                Resources.Load<ShaderVariantCollection>("ShaderVariantCollections/shaderVariants-selected").WarmUp();
 089                DataStore.i.HUDs.loadingHUD.visible.OnChange -= OnLoadingScreenVisibleStateChange;
 90            }
 091        }
 92
 93        protected virtual void SetupPlugins()
 94        {
 095            pluginSystem = PluginSystemFactory.Create();
 096        }
 97
 98        protected virtual void SetupServices()
 99        {
 0100            Environment.Setup(ServiceLocatorFactory.CreateDefault());
 0101        }
 102
 103        protected virtual void Start()
 104        {
 105            // this event should be the last one to be executed after initialization
 106            // it is used by the kernel to signal "EngineReady" or something like that
 107            // to prevent race conditions like "SceneController is not an object",
 108            // aka sending events before unity is ready
 0109            DCL.Interface.WebInterface.SendSystemInfoReport();
 110
 111            // We trigger the Decentraland logic once everything is initialized.
 0112            DCL.Interface.WebInterface.StartDecentraland();
 0113        }
 114
 115        protected virtual void Update()
 116        {
 0117            performanceMetricsController?.Update();
 0118        }
 119
 120        protected virtual void OnDestroy()
 121        {
 0122            DataStore.i.HUDs.loadingHUD.visible.OnChange -= OnLoadingScreenVisibleStateChange;
 123
 0124            DataStore.i.common.isApplicationQuitting.Set(true);
 125
 0126            pluginSystem?.Dispose();
 127
 0128            if (!Configuration.EnvironmentSettings.RUNNING_TESTS)
 0129                Environment.Dispose();
 0130            pluginSystem?.Dispose();
 0131            kernelCommunication?.Dispose();
 0132        }
 133
 134        protected virtual void InitializeSceneDependencies()
 135        {
 0136            gameObject.AddComponent<UserProfileController>();
 0137            gameObject.AddComponent<RenderingController>();
 0138            gameObject.AddComponent<CatalogController>();
 0139            gameObject.AddComponent<MinimapMetadataController>();
 0140            gameObject.AddComponent<ChatController>();
 0141            gameObject.AddComponent<FriendsController>();
 0142            gameObject.AddComponent<HotScenesController>();
 0143            gameObject.AddComponent<GIFProcessingBridge>();
 0144            gameObject.AddComponent<RenderProfileBridge>();
 0145            gameObject.AddComponent<AssetCatalogBridge>();
 0146            gameObject.AddComponent<ScreenSizeWatcher>();
 0147            gameObject.AddComponent<SceneControllerBridge>();
 148
 0149            MainSceneFactory.CreateBuilderInWorldBridge(gameObject);
 0150            MainSceneFactory.CreateBridges();
 0151            MainSceneFactory.CreateMouseCatcher();
 0152            MainSceneFactory.CreatePlayerSystems();
 0153            CreateEnvironment();
 0154            MainSceneFactory.CreateAudioHandler();
 0155            MainSceneFactory.CreateHudController();
 0156            MainSceneFactory.CreateSettingsController();
 0157            MainSceneFactory.CreateNavMap();
 0158            MainSceneFactory.CreateEventSystem();
 0159            MainSceneFactory.CreateInteractionHoverCanvas();
 0160        }
 161
 0162        protected virtual void CreateEnvironment() => MainSceneFactory.CreateEnvironment();
 163    }
 164}