< 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:76
Coverable lines:76
Total lines:185
Line coverage:0% (0 of 76)
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 DCL.Chat;
 2using DCL.Components;
 3using DCL.Configuration;
 4using DCL.Controllers;
 5using DCL.Helpers;
 6using DCL.Interface;
 7using DCL.SettingsCommon;
 8using DCL.Social.Chat;
 9using DCL.Social.Friends;
 10using RPC;
 11using UnityEngine;
 12
 13namespace DCL
 14{
 15    /// <summary>
 16    /// This is the InitialScene entry point.
 17    /// Most of the application subsystems should be initialized from this class Awake() event.
 18    /// </summary>
 19    public class Main : MonoBehaviour
 20    {
 21        [SerializeField] private bool disableSceneDependencies;
 022        public static Main i { get; private set; }
 23
 24        public PoolableComponentFactory componentFactory;
 25
 26        private PerformanceMetricsController performanceMetricsController;
 27        protected IKernelCommunication kernelCommunication;
 28
 29        protected PluginSystem pluginSystem;
 30
 31        protected virtual void Awake()
 32        {
 033            if (i != null)
 34            {
 035                Utils.SafeDestroy(this);
 036                return;
 37            }
 38
 039            i = this;
 40
 041            if (!disableSceneDependencies)
 042                InitializeSceneDependencies();
 43
 044            Settings.CreateSharedInstance(new DefaultSettingsFactory());
 45            // TODO: migrate chat controller singleton into a service in the service locator
 046            ChatController.CreateSharedInstance(GetComponent<WebInterfaceChatBridge>(), DataStore.i);
 047            FriendsController.CreateSharedInstance(GetComponent<WebInterfaceFriendsApiBridge>());
 48
 049            if (!EnvironmentSettings.RUNNING_TESTS)
 50            {
 051                performanceMetricsController = new PerformanceMetricsController();
 052                SetupServices();
 53
 054                DataStore.i.HUDs.loadingHUD.visible.OnChange += OnLoadingScreenVisibleStateChange;
 55            }
 56
 57#if UNITY_STANDALONE || UNITY_EDITOR
 058            Application.quitting += () => DataStore.i.common.isApplicationQuitting.Set(true);
 59#endif
 60
 061            InitializeDataStore();
 062            SetupPlugins();
 063            InitializeCommunication();
 064        }
 65
 66        protected virtual void InitializeDataStore()
 67        {
 068            DataStore.i.textureConfig.gltfMaxSize.Set(TextureCompressionSettings.GLTF_TEX_MAX_SIZE_WEB);
 069            DataStore.i.textureConfig.generalMaxSize.Set(TextureCompressionSettings.GENERAL_TEX_MAX_SIZE_WEB);
 070            DataStore.i.avatarConfig.useHologramAvatar.Set(true);
 071        }
 72
 73        protected virtual void InitializeCommunication()
 74        {
 75#if UNITY_WEBGL && !UNITY_EDITOR
 76            Debug.Log("DCL Unity Build Version: " + DCL.Configuration.ApplicationSettings.version);
 77            Debug.unityLogger.logEnabled = false;
 78
 79            kernelCommunication = new NativeBridgeCommunication(Environment.i.world.sceneController);
 80#else
 81            // TODO(Brian): Remove this branching once we finish migrating all tests out of the
 82            //              IntegrationTestSuite_Legacy base class.
 083            if (!EnvironmentSettings.RUNNING_TESTS)
 84            {
 085                kernelCommunication = new WebSocketCommunication(DebugConfigComponent.i.webSocketSSL);
 86            }
 87#endif
 88
 089            RPCServerBuilder.BuildDefaultServer();
 090        }
 91
 92        void OnLoadingScreenVisibleStateChange(bool newVisibleValue, bool previousVisibleValue)
 93        {
 094            if (newVisibleValue)
 95            {
 96                // Prewarm shader variants
 097                Resources.Load<ShaderVariantCollection>("ShaderVariantCollections/shaderVariants-selected").WarmUp();
 098                DataStore.i.HUDs.loadingHUD.visible.OnChange -= OnLoadingScreenVisibleStateChange;
 99            }
 0100        }
 101
 102        protected virtual void SetupPlugins()
 103        {
 0104            pluginSystem = PluginSystemFactory.Create();
 0105            pluginSystem.Initialize();
 0106        }
 107
 108        protected virtual void SetupServices()
 109        {
 0110            Environment.Setup(ServiceLocatorFactory.CreateDefault());
 0111        }
 112
 113        protected virtual void Start()
 114        {
 115            // this event should be the last one to be executed after initialization
 116            // it is used by the kernel to signal "EngineReady" or something like that
 117            // to prevent race conditions like "SceneController is not an object",
 118            // aka sending events before unity is ready
 0119            WebInterface.SendSystemInfoReport();
 120
 121            // We trigger the Decentraland logic once everything is initialized.
 0122            WebInterface.StartDecentraland();
 0123        }
 124
 125        protected virtual void Update()
 126        {
 0127            performanceMetricsController?.Update();
 0128        }
 129
 130        [RuntimeInitializeOnLoadMethod]
 131        static void RunOnStart()
 132        {
 0133            Application.wantsToQuit += ApplicationWantsToQuit;
 0134        }
 135        private static bool ApplicationWantsToQuit()
 136        {
 0137            if (i != null)
 0138                i.Dispose();
 139
 0140            return true;
 141        }
 142
 143        protected virtual void Dispose()
 144        {
 0145            DataStore.i.HUDs.loadingHUD.visible.OnChange -= OnLoadingScreenVisibleStateChange;
 146
 0147            DataStore.i.common.isApplicationQuitting.Set(true);
 148
 0149            pluginSystem?.Dispose();
 150
 0151            if (!EnvironmentSettings.RUNNING_TESTS)
 0152                Environment.Dispose();
 153
 0154            kernelCommunication?.Dispose();
 0155        }
 156
 157        protected virtual void InitializeSceneDependencies()
 158        {
 0159            gameObject.AddComponent<UserProfileController>();
 0160            gameObject.AddComponent<RenderingController>();
 0161            gameObject.AddComponent<CatalogController>();
 0162            gameObject.AddComponent<MinimapMetadataController>();
 0163            gameObject.AddComponent<WebInterfaceChatBridge>();
 0164            gameObject.AddComponent<WebInterfaceFriendsApiBridge>();
 0165            gameObject.AddComponent<HotScenesController>();
 0166            gameObject.AddComponent<GIFProcessingBridge>();
 0167            gameObject.AddComponent<RenderProfileBridge>();
 0168            gameObject.AddComponent<AssetCatalogBridge>();
 0169            gameObject.AddComponent<ScreenSizeWatcher>();
 0170            gameObject.AddComponent<SceneControllerBridge>();
 171
 0172            MainSceneFactory.CreateBuilderInWorldBridge(gameObject);
 0173            MainSceneFactory.CreateBridges();
 0174            MainSceneFactory.CreateMouseCatcher();
 0175            MainSceneFactory.CreatePlayerSystems();
 0176            CreateEnvironment();
 0177            MainSceneFactory.CreateAudioHandler();
 0178            MainSceneFactory.CreateHudController();
 0179            MainSceneFactory.CreateNavMap();
 0180            MainSceneFactory.CreateEventSystem();
 0181        }
 182
 0183        protected virtual void CreateEnvironment() => MainSceneFactory.CreateEnvironment();
 184    }
 185}