< Summary

Class:DCL.DebugConfigComponent
Assembly:DebugParameters
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/Debugging/DebugParameters/DebugConfigComponent.cs
Covered lines:0
Uncovered lines:97
Coverable lines:97
Total lines:279
Line coverage:0% (0 of 97)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
DebugConfigComponent()0%2100%
Awake()0%12300%
Start()0%12300%
OnCommunicationReadyChangedValue(...)0%12300%
InitConfig()0%20400%
StartSampling(...)0%2100%
EndSampling(...)0%2100%
OpenWebBrowser()0%4202000%
OnDestroy()0%2100%
QuitGame()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/Debugging/DebugParameters/DebugConfigComponent.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using DCL.Components;
 4using UnityEngine;
 5
 6namespace DCL
 7{
 8    public class DebugConfigComponent : MonoBehaviour
 9    {
 10        private static DebugConfigComponent sharedInstance;
 11
 12        public static DebugConfigComponent i
 13        {
 14            get
 15            {
 016                if (sharedInstance == null)
 017                    sharedInstance = FindObjectOfType<DebugConfigComponent>();
 18
 019                return sharedInstance;
 20            }
 021            private set => sharedInstance = value;
 22        }
 23
 24        public DebugConfig debugConfig;
 25
 26        public enum DebugPanel
 27        {
 28            Off,
 29            Scene,
 30            Engine
 31        }
 32
 33        public enum BaseUrl
 34        {
 35            ZONE,
 36            ORG,
 37            LOCAL_HOST,
 38            CUSTOM,
 39        }
 40
 41        public enum Network
 42        {
 43            MAINNET,
 44            GOERLI,
 45        }
 46
 47        [Header("General Settings")] public bool OpenBrowserOnStart;
 48        public bool webSocketSSL = false;
 49
 50        [Header("Kernel General Settings")] public string kernelVersion;
 51        public bool useCustomContentServer = false;
 52
 053        public string customContentServerUrl = "http://localhost:1338/";
 54
 55        [Space(10)] public BaseUrl baseUrlMode = BaseUrl.ZONE;
 56        [DrawIf("baseUrlMode", BaseUrl.CUSTOM)]
 057        public string customURL = "https://play.decentraland.zone/?";
 58
 59        [Space(10)] public Network network;
 60
 61        [Tooltip(
 62            "Set this field to force the realm (server). On the latin-american zone, recommended realms are fenrir-amber
 63        public string realm;
 64
 065        public Vector2 startInCoords = new Vector2(-99, 109);
 66
 067        [Header("Kernel Misc Settings")] public bool forceLocalComms = true;
 68
 69        public bool enableTutorial = false;
 70        public bool builderInWorld = false;
 071        public bool soloScene = true;
 72        public bool disableAssetBundles = false;
 73        public bool enableGLTFast = false;
 74        public bool enableDebugMode = false;
 75        public DebugPanel debugPanelMode = DebugPanel.Off;
 76
 77
 78        [Header("Performance")]
 79        public bool disableGLTFDownloadThrottle = false;
 80        public bool multithreaded = false;
 81        public bool runPerformanceMeterToolDuringLoading = false;
 82        private PerformanceMeterController performanceMeterController;
 83
 84        private void Awake()
 85        {
 086            if (sharedInstance == null)
 087                sharedInstance = this;
 88
 089            DataStore.i.debugConfig.soloScene = debugConfig.soloScene;
 090            DataStore.i.debugConfig.soloSceneCoords = debugConfig.soloSceneCoords;
 091            DataStore.i.debugConfig.ignoreGlobalScenes = debugConfig.ignoreGlobalScenes;
 092            DataStore.i.debugConfig.msgStepByStep = debugConfig.msgStepByStep;
 093            DataStore.i.performance.multithreading.Set(multithreaded);
 094            if (disableGLTFDownloadThrottle) DataStore.i.performance.maxDownloads.Set(999);
 095            Texture.allowThreadedTextureCreation = multithreaded;
 096        }
 97
 98        private void Start()
 99        {
 0100            lock (DataStore.i.wsCommunication.communicationReady)
 101            {
 0102                if (DataStore.i.wsCommunication.communicationReady.Get())
 103                {
 0104                    InitConfig();
 105                }
 106                else
 107                {
 0108                    DataStore.i.wsCommunication.communicationReady.OnChange += OnCommunicationReadyChangedValue;
 109                }
 0110            }
 0111        }
 112
 113        private void OnCommunicationReadyChangedValue(bool newState, bool prevState)
 114        {
 0115            if (newState && !prevState)
 0116                InitConfig();
 117
 0118            DataStore.i.wsCommunication.communicationReady.OnChange -= OnCommunicationReadyChangedValue;
 0119        }
 120
 121        private void InitConfig()
 122        {
 0123            if (useCustomContentServer)
 124            {
 0125                RendereableAssetLoadHelper.useCustomContentServerUrl = true;
 0126                RendereableAssetLoadHelper.customContentServerUrl = customContentServerUrl;
 127            }
 128
 0129            if (OpenBrowserOnStart)
 0130                OpenWebBrowser();
 131
 0132            if (runPerformanceMeterToolDuringLoading)
 133            {
 0134                CommonScriptableObjects.forcePerformanceMeter.Set(true);
 0135                performanceMeterController = new PerformanceMeterController();
 136
 0137                DataStore.i.HUDs.loadingHUD.visible.OnChange += StartSampling;
 0138                CommonScriptableObjects.rendererState.OnChange += EndSampling;
 139            }
 0140        }
 141
 142        private void StartSampling(bool current, bool previous)
 143        {
 0144            DataStore.i.HUDs.loadingHUD.visible.OnChange -= StartSampling;
 0145            performanceMeterController.StartSampling(999);
 0146        }
 147        private void EndSampling(bool current, bool previous)
 148        {
 0149            CommonScriptableObjects.rendererState.OnChange -= EndSampling;
 0150            performanceMeterController.StopSampling();
 0151        }
 152
 153        private void OpenWebBrowser()
 154        {
 155#if (UNITY_EDITOR || UNITY_STANDALONE)
 0156            string baseUrl = "";
 0157            string debugString = "";
 158
 0159            if (baseUrlMode.Equals(BaseUrl.CUSTOM))
 160            {
 0161                baseUrl = this.customURL;
 0162                if (string.IsNullOrEmpty(this.customURL))
 163                {
 0164                    Debug.LogError("Custom url cannot be empty");
 0165                    QuitGame();
 0166                    return;
 167                }
 168            }
 0169            else if (baseUrlMode.Equals(BaseUrl.LOCAL_HOST))
 170            {
 0171                baseUrl = "http://localhost:8080/?";
 172            }
 0173            else if (baseUrlMode.Equals(BaseUrl.ORG))
 174            {
 0175                baseUrl = "http://play.decentraland.org/?";
 0176                if (!webSocketSSL)
 177                {
 0178                    Debug.LogError(
 179                        "play.decentraland.org only works with WebSocket SSL, please change the base URL to play.decentr
 0180                    QuitGame();
 0181                    return;
 182                }
 183            }
 184            else
 185            {
 0186                baseUrl = "http://play.decentraland.zone/?";
 187            }
 188
 0189            switch (network)
 190            {
 191                case Network.GOERLI:
 0192                    debugString = "NETWORK=goerli&";
 0193                    break;
 194                case Network.MAINNET:
 0195                    debugString = "NETWORK=mainnet&";
 196                    break;
 197            }
 198
 0199            if (!string.IsNullOrEmpty(kernelVersion))
 200            {
 0201                debugString += $"kernel-version={kernelVersion}&";
 202            }
 203
 0204            if (forceLocalComms)
 205            {
 0206                debugString += "LOCAL_COMMS&";
 207            }
 208
 0209            if (enableTutorial)
 210            {
 0211                debugString += "RESET_TUTORIAL&";
 212            }
 213
 0214            if (soloScene)
 215            {
 0216                debugString += "LOS=0&";
 217            }
 218
 0219            if (builderInWorld)
 220            {
 0221                debugString += "ENABLE_BUILDER_IN_WORLD&";
 222            }
 223
 0224            if (disableAssetBundles)
 225            {
 0226                debugString += "DISABLE_ASSET_BUNDLES&DISABLE_WEARABLE_ASSET_BUNDLES&";
 227            }
 228
 0229            if (enableGLTFast)
 230            {
 0231                debugString += "ENABLE_GLTFAST&";
 232            }
 233
 0234            if (enableDebugMode)
 235            {
 0236                debugString += "DEBUG_MODE&";
 237            }
 238
 0239            if (!string.IsNullOrEmpty(realm))
 240            {
 0241                debugString += $"realm={realm}&";
 242            }
 243
 0244            string debugPanelString = "";
 245
 0246            if (debugPanelMode == DebugPanel.Engine)
 247            {
 0248                debugPanelString = "ENGINE_DEBUG_PANEL&";
 249            }
 0250            else if (debugPanelMode == DebugPanel.Scene)
 251            {
 0252                debugPanelString = "SCENE_DEBUG_PANEL&";
 253            }
 254
 0255            if (webSocketSSL)
 256            {
 0257                Debug.Log(
 258                    "[REMINDER] To be able to connect with SSL you should start Chrome with the --ignore-certificate-err
 259            }
 260
 0261            Application.OpenURL(
 262                $"{baseUrl}{debugString}{debugPanelString}position={startInCoords.x}%2C{startInCoords.y}&ws={DataStore.i
 263#endif
 0264        }
 265
 0266        private void OnDestroy() { DataStore.i.wsCommunication.communicationReady.OnChange -= OnCommunicationReadyChange
 267
 268        private void QuitGame()
 269        {
 270#if UNITY_EDITOR
 271            // Application.Quit() does not work in the editor so
 272            // UnityEditor.EditorApplication.isPlaying need to be set to false to end the game
 0273            UnityEditor.EditorApplication.isPlaying = false;
 274#else
 275            Application.Quit();
 276#endif
 0277        }
 278    }
 279}