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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%30500%
InitializeDataStore()0%2100%
InitializeCommunication()0%6200%
OnLoadingScreenVisibleStateChange(...)0%6200%
SetupPlugins()0%2100%
SetupServices()0%2100%
Start()0%2100%
Update()0%6200%
RunOnStart()0%2100%
ApplicationWantsToQuit()0%6200%
Dispose()0%20400%
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.Configuration;
 5using DCL.Controllers;
 6using DCL.Helpers;
 7using DCL.SettingsCommon;
 8using RPC;
 9using UnityEngine;
 10using UnityEngine.Serialization;
 11
 12namespace DCL
 13{
 14    /// <summary>
 15    /// This is the InitialScene entry point.
 16    /// Most of the application subsystems should be initialized from this class Awake() event.
 17    /// </summary>
 18    public class Main : MonoBehaviour
 19    {
 20        [SerializeField] private bool disableSceneDependencies;
 021        public static Main i { get; private set; }
 22
 23        public PoolableComponentFactory componentFactory;
 24
 25        private PerformanceMetricsController performanceMetricsController;
 26        protected IKernelCommunication kernelCommunication;
 27
 28        protected PluginSystem pluginSystem;
 29
 30        protected virtual void Awake()
 31        {
 032            if (i != null)
 33            {
 034                Utils.SafeDestroy(this);
 035                return;
 36            }
 37
 038            i = this;
 39
 040            if (!disableSceneDependencies)
 041                InitializeSceneDependencies();
 42
 043            Settings.CreateSharedInstance(new DefaultSettingsFactory());
 44
 045            if (!Configuration.EnvironmentSettings.RUNNING_TESTS)
 46            {
 047                performanceMetricsController = new PerformanceMetricsController();
 048                SetupServices();
 49
 050                DataStore.i.HUDs.loadingHUD.visible.OnChange += OnLoadingScreenVisibleStateChange;
 51            }
 52
 53#if UNITY_STANDALONE || UNITY_EDITOR
 054            Application.quitting += () => DataStore.i.common.isApplicationQuitting.Set(true);
 55#endif
 56
 057            InitializeDataStore();
 058            SetupPlugins();
 059            InitializeCommunication();
 060        }
 61
 62        protected virtual void InitializeDataStore()
 63        {
 064            DataStore.i.textureConfig.gltfMaxSize.Set(TextureCompressionSettings.GLTF_TEX_MAX_SIZE_WEB);
 065            DataStore.i.textureConfig.generalMaxSize.Set(TextureCompressionSettings.GENERAL_TEX_MAX_SIZE_WEB);
 066            DataStore.i.avatarConfig.useHologramAvatar.Set(true);
 067        }
 68
 69        protected virtual void InitializeCommunication()
 70        {
 71#if UNITY_WEBGL && !UNITY_EDITOR
 72            Debug.Log("DCL Unity Build Version: " + DCL.Configuration.ApplicationSettings.version);
 73            Debug.unityLogger.logEnabled = false;
 74
 75            kernelCommunication = new NativeBridgeCommunication(Environment.i.world.sceneController);
 76#else
 77            // TODO(Brian): Remove this branching once we finish migrating all tests out of the
 78            //              IntegrationTestSuite_Legacy base class.
 079            if (!Configuration.EnvironmentSettings.RUNNING_TESTS)
 80            {
 081                kernelCommunication = new WebSocketCommunication(DebugConfigComponent.i.webSocketSSL);
 82            }
 83#endif
 84
 085            RPCServerBuilder.BuildDefaultServer();
 086        }
 87
 88        void OnLoadingScreenVisibleStateChange(bool newVisibleValue, bool previousVisibleValue)
 89        {
 090            if (newVisibleValue)
 91            {
 92                // Prewarm shader variants
 093                Resources.Load<ShaderVariantCollection>("ShaderVariantCollections/shaderVariants-selected").WarmUp();
 094                DataStore.i.HUDs.loadingHUD.visible.OnChange -= OnLoadingScreenVisibleStateChange;
 95            }
 096        }
 97
 98        protected virtual void SetupPlugins()
 99        {
 0100            pluginSystem = PluginSystemFactory.Create();
 0101            pluginSystem.Initialize();
 0102        }
 103
 104        protected virtual void SetupServices()
 105        {
 0106            Environment.Setup(ServiceLocatorFactory.CreateDefault());
 0107        }
 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();
 0119        }
 120
 121        protected virtual void Update()
 122        {
 0123            performanceMetricsController?.Update();
 0124        }
 125
 126        [RuntimeInitializeOnLoadMethod]
 127        static void RunOnStart()
 128        {
 0129            Application.wantsToQuit += ApplicationWantsToQuit;
 0130        }
 131        private static bool ApplicationWantsToQuit()
 132        {
 0133            if (i != null)
 0134                i.Dispose();
 135
 0136            return true;
 137        }
 138
 139        protected virtual void Dispose()
 140        {
 0141            DataStore.i.HUDs.loadingHUD.visible.OnChange -= OnLoadingScreenVisibleStateChange;
 142
 0143            DataStore.i.common.isApplicationQuitting.Set(true);
 144
 0145            pluginSystem?.Dispose();
 146
 0147            if (!Configuration.EnvironmentSettings.RUNNING_TESTS)
 0148                Environment.Dispose();
 149
 0150            kernelCommunication?.Dispose();
 0151        }
 152
 153        protected virtual void InitializeSceneDependencies()
 154        {
 0155            gameObject.AddComponent<UserProfileController>();
 0156            gameObject.AddComponent<RenderingController>();
 0157            gameObject.AddComponent<CatalogController>();
 0158            gameObject.AddComponent<MinimapMetadataController>();
 0159            gameObject.AddComponent<ChatController>();
 0160            gameObject.AddComponent<FriendsController>();
 0161            gameObject.AddComponent<HotScenesController>();
 0162            gameObject.AddComponent<GIFProcessingBridge>();
 0163            gameObject.AddComponent<RenderProfileBridge>();
 0164            gameObject.AddComponent<AssetCatalogBridge>();
 0165            gameObject.AddComponent<ScreenSizeWatcher>();
 0166            gameObject.AddComponent<SceneControllerBridge>();
 167
 0168            MainSceneFactory.CreateBuilderInWorldBridge(gameObject);
 0169            MainSceneFactory.CreateBridges();
 0170            MainSceneFactory.CreateMouseCatcher();
 0171            MainSceneFactory.CreatePlayerSystems();
 0172            CreateEnvironment();
 0173            MainSceneFactory.CreateAudioHandler();
 0174            MainSceneFactory.CreateHudController();
 0175            MainSceneFactory.CreateNavMap();
 0176            MainSceneFactory.CreateEventSystem();
 0177        }
 178
 0179        protected virtual void CreateEnvironment() => MainSceneFactory.CreateEnvironment();
 180    }
 181}