< Summary

Class:DCL.MainDesktop
Assembly:MainDesktop
File(s):/tmp/workspace/explorer-desktop/unity-renderer-desktop/Assets/Scripts/MainScripts/DCL/MainDesktop/MainDesktop.cs
Covered lines:0
Uncovered lines:63
Coverable lines:63
Total lines:167
Line coverage:0% (0 of 63)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%2100%
InitializeDataStore()0%2100%
FeatureFlagsReady(...)0%6200%
InitializeCommunication()0%6200%
SetupPlugins()0%2100%
InitializeSettings()0%2100%
Dispose()0%2100%
DesktopDestroy()0%2100%
OnCommunicationEstablished(...)0%6200%
Update()0%30500%
InitializeSceneDependencies()0%2100%
SetupServices()0%2100%

File(s)

/tmp/workspace/explorer-desktop/unity-renderer-desktop/Assets/Scripts/MainScripts/DCL/MainDesktop/MainDesktop.cs

#LineLine coverage
 1using System;
 2using DCL.SettingsCommon;
 3using DCL.Components;
 4using MainScripts.DCL.Controllers.HUD.Preloading;
 5using MainScripts.DCL.Controllers.LoadingFlow;
 6using MainScripts.DCL.Controllers.SettingsDesktop;
 7using MainScripts.DCL.Utils;
 8using UnityEngine;
 9
 10namespace DCL
 11{
 12    /// <summary>
 13    /// This is the MainDesktop entry point.
 14    /// Most of the application subsystems should be initialized from this class Awake() event.
 15    /// </summary>
 16    public class MainDesktop : Main
 17    {
 18        [SerializeField] private bool logWs = false;
 19        private LoadingFlowController loadingFlowController;
 20        private PreloadingController preloadingController;
 21        private bool isConnectionLost;
 22        private readonly DataStoreRef<DataStore_LoadingScreen> loadingScreenRef;
 23
 024        private BaseVariable<FeatureFlag> featureFlags => DataStore.i.featureFlags.flags;
 25
 26        protected override void Awake()
 27        {
 028            CommandLineParserUtils.ParseArguments();
 029            isConnectionLost = false;
 30
 031            DCLVideoTexture.videoPluginWrapperBuilder = VideoProviderFactory.CreateVideoProvider;
 32
 033            featureFlags.OnChange += FeatureFlagsReady;
 34
 035            InitializeSettings();
 36
 037            base.Awake();
 038            DataStore.i.wsCommunication.communicationEstablished.OnChange += OnCommunicationEstablished;
 039            DataStore.i.performance.multithreading.Set(true);
 040            DataStore.i.performance.maxDownloads.Set(50);
 041            Texture.allowThreadedTextureCreation = true;
 042        }
 43
 44        protected override void InitializeDataStore()
 45        {
 046            DataStore.i.textureConfig.gltfMaxSize.Set(TextureCompressionSettingsDesktop.GLTF_TEX_MAX_SIZE_DESKTOP);
 047            DataStore.i.textureConfig.generalMaxSize.Set(TextureCompressionSettingsDesktop.GENERAL_TEX_MAX_SIZE_DESKTOP)
 048            DataStore.i.avatarConfig.useHologramAvatar.Set(true);
 049        }
 50
 51        private void FeatureFlagsReady(FeatureFlag current, FeatureFlag previous)
 52        {
 053            DCLVideoTexture.videoPluginWrapperBuilder = VideoProviderFactory.CreateVideoProvider;
 054            if (current.IsFeatureEnabled(DataStore.i.featureFlags.DECOUPLED_LOADING_SCREEN_FF))
 55            {
 056                loadingFlowController = new LoadingFlowController(
 57                    loadingScreenRef.Ref.decoupledLoadingHUD.visible,
 58                    CommonScriptableObjects.rendererState,
 59                    DataStore.i.wsCommunication.communicationEstablished);
 60            }
 61            else
 62            {
 063                loadingFlowController = new LoadingFlowController(
 64                    loadingScreenRef.Ref.loadingHUD.visible,
 65                    CommonScriptableObjects.rendererState,
 66                    DataStore.i.wsCommunication.communicationEstablished);
 67            }
 068            DataStore.i.featureFlags.flags.OnChange -= FeatureFlagsReady;
 69
 070        }
 71
 72        protected override void InitializeCommunication()
 73        {
 074            DataStore.i.debugConfig.logWs = logWs;
 75            // TODO(Brian): Remove this branching once we finish migrating all tests out of the
 76            //              IntegrationTestSuite_Legacy base class.
 077            if (!Configuration.EnvironmentSettings.RUNNING_TESTS)
 78            {
 079                var withSSL = true;
 080                int startPort = CommandLineParserUtils.startPort;
 81
 82#if UNITY_EDITOR
 083                withSSL = DebugConfigComponent.i.webSocketSSL;
 084                startPort = 5000;
 85#endif
 86
 087                int endPort = startPort + 100;
 088                kernelCommunication = new WebSocketCommunication(withSSL, startPort, endPort);
 89            }
 090        }
 91
 92        protected override void SetupPlugins()
 93        {
 094            pluginSystem = PluginSystemFactoryDesktop.Create();
 095            pluginSystem.Initialize();
 096        }
 97
 98        private void InitializeSettings()
 99        {
 0100            Settings.CreateSharedInstance(new DefaultSettingsFactory()
 101                .WithGraphicsQualitySettingsPresetPath("DesktopGraphicsQualityPresets"));
 0102        }
 103
 104        protected override void Dispose()
 105        {
 106            try
 107            {
 0108                DataStore.i.wsCommunication.communicationEstablished.OnChange -= OnCommunicationEstablished;
 109
 0110                base.Dispose();
 0111                DesktopDestroy();
 0112            }
 113            catch (Exception e)
 114            {
 0115                Debug.LogException(e);
 0116            }
 0117        }
 118
 119        private void DesktopDestroy()
 120        {
 0121            loadingFlowController.Dispose();
 0122            preloadingController.Dispose();
 123#if !AV_PRO_PRESENT
 0124            DCLVideoPlayer.StopAllThreads();
 125#endif
 0126        }
 127
 128        void OnCommunicationEstablished(bool current, bool previous)
 129        {
 0130            if (current == false && previous)
 131            {
 0132                isConnectionLost = true;
 133            }
 0134        }
 135
 136        protected override void Update()
 137        {
 0138            base.Update();
 139
 0140            if (isConnectionLost)
 141            {
 0142                DesktopUtils.Quit();
 143            }
 144
 145            // TODO: Remove this after we refactor InputController to support overrides from desktop or to use the lates
 146            // This shortcut will help some users to fix the small resolution bugs that may happen if the player prefs a
 0147            if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
 148                && Input.GetKeyDown(KeyCode.F11))
 149            {
 0150                DisplaySettings newDisplaySettings = new DisplaySettings { windowMode = WindowMode.Borderless };
 0151                SettingsDesktop.i.displaySettings.Apply(newDisplaySettings);
 0152                SettingsDesktop.i.displaySettings.Save();
 153            }
 0154        }
 155
 156        protected override void InitializeSceneDependencies()
 157        {
 0158            base.InitializeSceneDependencies();
 0159            preloadingController = new PreloadingController();
 0160        }
 161
 162        protected override void SetupServices()
 163        {
 0164            Environment.Setup(ServiceLocatorDesktopFactory.CreateDefault());
 0165        }
 166    }
 167}