< 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:180
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
 084            RPCServerBuilder.BuildDefaultServer();
 085        }
 86
 87        void OnLoadingScreenVisibleStateChange(bool newVisibleValue, bool previousVisibleValue)
 88        {
 089            if (newVisibleValue)
 90            {
 91                // Prewarm shader variants
 092                Resources.Load<ShaderVariantCollection>("ShaderVariantCollections/shaderVariants-selected").WarmUp();
 093                DataStore.i.HUDs.loadingHUD.visible.OnChange -= OnLoadingScreenVisibleStateChange;
 94            }
 095        }
 96
 97        protected virtual void SetupPlugins()
 98        {
 099            pluginSystem = PluginSystemFactory.Create();
 0100            pluginSystem.Initialize();
 0101        }
 102
 103        protected virtual void SetupServices()
 104        {
 0105            Environment.Setup(ServiceLocatorFactory.CreateDefault());
 0106        }
 107
 108        protected virtual void Start()
 109        {
 110            // this event should be the last one to be executed after initialization
 111            // it is used by the kernel to signal "EngineReady" or something like that
 112            // to prevent race conditions like "SceneController is not an object",
 113            // aka sending events before unity is ready
 0114            DCL.Interface.WebInterface.SendSystemInfoReport();
 115
 116            // We trigger the Decentraland logic once everything is initialized.
 0117            DCL.Interface.WebInterface.StartDecentraland();
 0118        }
 119
 120        protected virtual void Update()
 121        {
 0122            performanceMetricsController?.Update();
 0123        }
 124
 125        [RuntimeInitializeOnLoadMethod]
 126        static void RunOnStart()
 127        {
 0128            Application.wantsToQuit += ApplicationWantsToQuit;
 0129        }
 130        private static bool ApplicationWantsToQuit()
 131        {
 0132            if (i != null)
 0133                i.Dispose();
 134
 0135            return true;
 136        }
 137
 138        protected virtual void Dispose()
 139        {
 0140            DataStore.i.HUDs.loadingHUD.visible.OnChange -= OnLoadingScreenVisibleStateChange;
 141
 0142            DataStore.i.common.isApplicationQuitting.Set(true);
 143
 0144            pluginSystem?.Dispose();
 145
 0146            if (!Configuration.EnvironmentSettings.RUNNING_TESTS)
 0147                Environment.Dispose();
 148
 0149            kernelCommunication?.Dispose();
 0150        }
 151
 152        protected virtual void InitializeSceneDependencies()
 153        {
 0154            gameObject.AddComponent<UserProfileController>();
 0155            gameObject.AddComponent<RenderingController>();
 0156            gameObject.AddComponent<CatalogController>();
 0157            gameObject.AddComponent<MinimapMetadataController>();
 0158            gameObject.AddComponent<ChatController>();
 0159            gameObject.AddComponent<FriendsController>();
 0160            gameObject.AddComponent<HotScenesController>();
 0161            gameObject.AddComponent<GIFProcessingBridge>();
 0162            gameObject.AddComponent<RenderProfileBridge>();
 0163            gameObject.AddComponent<AssetCatalogBridge>();
 0164            gameObject.AddComponent<ScreenSizeWatcher>();
 0165            gameObject.AddComponent<SceneControllerBridge>();
 166
 0167            MainSceneFactory.CreateBuilderInWorldBridge(gameObject);
 0168            MainSceneFactory.CreateBridges();
 0169            MainSceneFactory.CreateMouseCatcher();
 0170            MainSceneFactory.CreatePlayerSystems();
 0171            CreateEnvironment();
 0172            MainSceneFactory.CreateAudioHandler();
 0173            MainSceneFactory.CreateHudController();
 0174            MainSceneFactory.CreateNavMap();
 0175            MainSceneFactory.CreateEventSystem();
 0176        }
 177
 0178        protected virtual void CreateEnvironment() => MainSceneFactory.CreateEnvironment();
 179    }
 180}