< 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:77
Coverable lines:77
Total lines:190
Line coverage:0% (0 of 77)
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.Components;
 2using DCL.Configuration;
 3using DCL.Helpers;
 4using DCL.Interface;
 5using DCL.SettingsCommon;
 6using DCL.Social.Chat;
 7using DCl.Social.Friends;
 8using DCL.Social.Friends;
 9using UnityEngine;
 10
 11namespace DCL
 12{
 13    /// <summary>
 14    /// This is the InitialScene entry point.
 15    /// Most of the application subsystems should be initialized from this class Awake() event.
 16    /// </summary>
 17    public class Main : MonoBehaviour
 18    {
 19        [SerializeField] private bool disableSceneDependencies;
 020        public static Main i { get; private set; }
 21
 22        public PoolableComponentFactory componentFactory;
 23
 24        private NewFriendRequestsApiBridgeMock newFriendRequestsApiBridgeMock;
 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            // TODO: migrate chat controller singleton into a service in the service locator
 045            ChatController.CreateSharedInstance(GetComponent<WebInterfaceChatBridge>(), DataStore.i);
 46            // FriendsController.CreateSharedInstance(GetComponent<WebInterfaceFriendsApiBridge>());
 47            // TODO (NEW FRIEND REQUESTS): remove when the kernel bridge is production ready
 048            WebInterfaceFriendsApiBridge newFriendRequestsApiBridge = GetComponent<WebInterfaceFriendsApiBridge>();
 049            newFriendRequestsApiBridgeMock = new NewFriendRequestsApiBridgeMock(newFriendRequestsApiBridge, new UserProf
 050            FriendsController.CreateSharedInstance(new WebInterfaceFriendsApiBridgeProxy(
 51                RPCFriendsApiBridge.CreateSharedInstance(Environment.i.serviceLocator.Get<IRPC>(), newFriendRequestsApiB
 52                newFriendRequestsApiBridgeMock, DataStore.i));
 53
 054            if (!EnvironmentSettings.RUNNING_TESTS)
 55            {
 056                performanceMetricsController = new PerformanceMetricsController();
 057                SetupServices();
 58
 059                DataStore.i.HUDs.loadingHUD.visible.OnChange += OnLoadingScreenVisibleStateChange;
 60            }
 61
 62#if UNITY_STANDALONE || UNITY_EDITOR
 063            Application.quitting += () => DataStore.i.common.isApplicationQuitting.Set(true);
 64#endif
 65
 066            InitializeDataStore();
 067            SetupPlugins();
 068            InitializeCommunication();
 069        }
 70
 71        protected virtual void InitializeDataStore()
 72        {
 073            DataStore.i.textureConfig.gltfMaxSize.Set(TextureCompressionSettings.GLTF_TEX_MAX_SIZE_WEB);
 074            DataStore.i.textureConfig.generalMaxSize.Set(TextureCompressionSettings.GENERAL_TEX_MAX_SIZE_WEB);
 075            DataStore.i.avatarConfig.useHologramAvatar.Set(true);
 076        }
 77
 78        protected virtual void InitializeCommunication()
 79        {
 80#if UNITY_WEBGL && !UNITY_EDITOR
 81            Debug.Log("DCL Unity Build Version: " + DCL.Configuration.ApplicationSettings.version);
 82            Debug.unityLogger.logEnabled = false;
 83
 84            kernelCommunication = new NativeBridgeCommunication(Environment.i.world.sceneController);
 85#else
 86            // TODO(Brian): Remove this branching once we finish migrating all tests out of the
 87            //              IntegrationTestSuite_Legacy base class.
 088            if (!EnvironmentSettings.RUNNING_TESTS)
 89            {
 090                kernelCommunication = new WebSocketCommunication(DebugConfigComponent.i.webSocketSSL);
 91            }
 92#endif
 093        }
 94
 95        void OnLoadingScreenVisibleStateChange(bool newVisibleValue, bool previousVisibleValue)
 96        {
 097            if (newVisibleValue)
 98            {
 99                // Prewarm shader variants
 0100                Resources.Load<ShaderVariantCollection>("ShaderVariantCollections/shaderVariants-selected").WarmUp();
 0101                DataStore.i.HUDs.loadingHUD.visible.OnChange -= OnLoadingScreenVisibleStateChange;
 102            }
 0103        }
 104
 105        protected virtual void SetupPlugins()
 106        {
 0107            pluginSystem = PluginSystemFactory.Create();
 0108            pluginSystem.Initialize();
 0109        }
 110
 111        protected virtual void SetupServices()
 112        {
 0113            Environment.Setup(ServiceLocatorFactory.CreateDefault());
 0114        }
 115
 116        protected virtual void Start()
 117        {
 118            // this event should be the last one to be executed after initialization
 119            // it is used by the kernel to signal "EngineReady" or something like that
 120            // to prevent race conditions like "SceneController is not an object",
 121            // aka sending events before unity is ready
 0122            WebInterface.SendSystemInfoReport();
 123
 124            // We trigger the Decentraland logic once everything is initialized.
 0125            WebInterface.StartDecentraland();
 0126        }
 127
 128        protected virtual void Update()
 129        {
 0130            performanceMetricsController?.Update();
 0131        }
 132
 133        [RuntimeInitializeOnLoadMethod]
 134        static void RunOnStart()
 135        {
 0136            Application.wantsToQuit += ApplicationWantsToQuit;
 0137        }
 138        private static bool ApplicationWantsToQuit()
 139        {
 0140            if (i != null)
 0141                i.Dispose();
 142
 0143            return true;
 144        }
 145
 146        protected virtual void Dispose()
 147        {
 0148            DataStore.i.HUDs.loadingHUD.visible.OnChange -= OnLoadingScreenVisibleStateChange;
 149
 0150            DataStore.i.common.isApplicationQuitting.Set(true);
 151
 0152            pluginSystem?.Dispose();
 153
 0154            if (!EnvironmentSettings.RUNNING_TESTS)
 0155                Environment.Dispose();
 156
 0157            kernelCommunication?.Dispose();
 158
 159            // TODO (NEW FRIEND REQUESTS): remove when the kernel bridge is production ready
 0160            newFriendRequestsApiBridgeMock.Dispose();
 0161        }
 162
 163        protected virtual void InitializeSceneDependencies()
 164        {
 0165            gameObject.AddComponent<UserProfileController>();
 0166            gameObject.AddComponent<RenderingController>();
 0167            gameObject.AddComponent<CatalogController>();
 0168            gameObject.AddComponent<MinimapMetadataController>();
 0169            gameObject.AddComponent<WebInterfaceChatBridge>();
 0170            gameObject.AddComponent<WebInterfaceFriendsApiBridge>();
 0171            gameObject.AddComponent<HotScenesController>();
 0172            gameObject.AddComponent<GIFProcessingBridge>();
 0173            gameObject.AddComponent<RenderProfileBridge>();
 0174            gameObject.AddComponent<AssetCatalogBridge>();
 0175            gameObject.AddComponent<ScreenSizeWatcher>();
 0176            gameObject.AddComponent<SceneControllerBridge>();
 177
 0178            MainSceneFactory.CreateBridges();
 0179            MainSceneFactory.CreateMouseCatcher();
 0180            MainSceneFactory.CreatePlayerSystems();
 0181            CreateEnvironment();
 0182            MainSceneFactory.CreateAudioHandler();
 0183            MainSceneFactory.CreateHudController();
 0184            MainSceneFactory.CreateNavMap();
 0185            MainSceneFactory.CreateEventSystem();
 0186        }
 187
 0188        protected virtual void CreateEnvironment() => MainSceneFactory.CreateEnvironment();
 189    }
 190}