< 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:99
Coverable lines:99
Total lines:283
Line coverage:0% (0 of 99)
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        private readonly DataStoreRef<DataStore_LoadingScreen> dataStoreLoadingScreen;
 12
 13        public static DebugConfigComponent i
 14        {
 15            get
 16            {
 017                if (sharedInstance == null)
 018                    sharedInstance = FindObjectOfType<DebugConfigComponent>();
 19
 020                return sharedInstance;
 21            }
 022            private set => sharedInstance = value;
 23        }
 24
 25        public DebugConfig debugConfig;
 26
 27        public enum DebugPanel
 28        {
 29            Off,
 30            Scene,
 31            Engine
 32        }
 33
 34        public enum BaseUrl
 35        {
 36            ZONE,
 37            ORG,
 38            LOCAL_HOST,
 39            CUSTOM,
 40        }
 41
 42        public enum Network
 43        {
 44            MAINNET,
 45            GOERLI,
 46        }
 47
 48        [Header("General Settings")] public bool OpenBrowserOnStart;
 49        public bool webSocketSSL = false;
 50
 51        [Header("Kernel General Settings")] public string kernelVersion;
 52        public bool useCustomContentServer = false;
 53
 054        public string customContentServerUrl = "http://localhost:1338/";
 55
 56        [Space(10)] public BaseUrl baseUrlMode = BaseUrl.ZONE;
 57        [DrawIf("baseUrlMode", BaseUrl.CUSTOM)]
 058        public string customURL = "https://play.decentraland.zone/?";
 59
 60        [Space(10)] public Network network;
 61
 62        [Tooltip(
 63            "Set this field to force the realm (server). On the latin-american zone, recommended realms are fenrir-amber
 64        public string realm;
 65
 066        public Vector2 startInCoords = new Vector2(-99, 109);
 67
 068        [Header("Kernel Misc Settings")] public bool forceLocalComms = true;
 69
 70        public bool enableTutorial = false;
 71        public bool builderInWorld = false;
 072        public bool soloScene = true;
 73        public bool disableAssetBundles = false;
 74        public bool enableGLTFast = false;
 75        public bool enableDebugMode = false;
 76        public DebugPanel debugPanelMode = DebugPanel.Off;
 77
 78
 79        [Header("Performance")]
 80        public bool disableGLTFDownloadThrottle = false;
 81        public bool multithreaded = false;
 82        public bool runPerformanceMeterToolDuringLoading = false;
 83        private PerformanceMeterController performanceMeterController;
 84
 85
 86        private void Awake()
 87        {
 088            if (sharedInstance == null)
 089                sharedInstance = this;
 90
 091            DataStore.i.debugConfig.soloScene = debugConfig.soloScene;
 092            DataStore.i.debugConfig.soloSceneCoords = debugConfig.soloSceneCoords;
 093            DataStore.i.debugConfig.ignoreGlobalScenes = debugConfig.ignoreGlobalScenes;
 094            DataStore.i.debugConfig.msgStepByStep = debugConfig.msgStepByStep;
 095            DataStore.i.performance.multithreading.Set(multithreaded);
 096            if (disableGLTFDownloadThrottle) DataStore.i.performance.maxDownloads.Set(999);
 097            Texture.allowThreadedTextureCreation = multithreaded;
 098        }
 99
 100        private void Start()
 101        {
 0102            lock (DataStore.i.wsCommunication.communicationReady)
 103            {
 0104                if (DataStore.i.wsCommunication.communicationReady.Get())
 105                {
 0106                    InitConfig();
 107                }
 108                else
 109                {
 0110                    DataStore.i.wsCommunication.communicationReady.OnChange += OnCommunicationReadyChangedValue;
 111                }
 0112            }
 0113        }
 114
 115        private void OnCommunicationReadyChangedValue(bool newState, bool prevState)
 116        {
 0117            if (newState && !prevState)
 0118                InitConfig();
 119
 0120            DataStore.i.wsCommunication.communicationReady.OnChange -= OnCommunicationReadyChangedValue;
 0121        }
 122
 123        private void InitConfig()
 124        {
 0125            if (useCustomContentServer)
 126            {
 0127                RendereableAssetLoadHelper.useCustomContentServerUrl = true;
 0128                RendereableAssetLoadHelper.customContentServerUrl = customContentServerUrl;
 129            }
 130
 0131            if (OpenBrowserOnStart)
 0132                OpenWebBrowser();
 133
 0134            if (runPerformanceMeterToolDuringLoading)
 135            {
 0136                CommonScriptableObjects.forcePerformanceMeter.Set(true);
 0137                performanceMeterController = new PerformanceMeterController();
 138
 0139                dataStoreLoadingScreen.Ref.decoupledLoadingHUD.visible.OnChange += StartSampling;
 0140                dataStoreLoadingScreen.Ref.loadingHUD.visible.OnChange += StartSampling;
 0141                CommonScriptableObjects.rendererState.OnChange += EndSampling;
 142            }
 0143        }
 144
 145        private void StartSampling(bool current, bool previous)
 146        {
 0147            dataStoreLoadingScreen.Ref.decoupledLoadingHUD.visible.OnChange -= StartSampling;
 0148            dataStoreLoadingScreen.Ref.loadingHUD.visible.OnChange -= StartSampling;
 0149            performanceMeterController.StartSampling(999);
 0150        }
 151        private void EndSampling(bool current, bool previous)
 152        {
 0153            CommonScriptableObjects.rendererState.OnChange -= EndSampling;
 0154            performanceMeterController.StopSampling();
 0155        }
 156
 157        private void OpenWebBrowser()
 158        {
 159#if (UNITY_EDITOR || UNITY_STANDALONE)
 0160            string baseUrl = "";
 0161            string debugString = "";
 162
 0163            if (baseUrlMode.Equals(BaseUrl.CUSTOM))
 164            {
 0165                baseUrl = this.customURL;
 0166                if (string.IsNullOrEmpty(this.customURL))
 167                {
 0168                    Debug.LogError("Custom url cannot be empty");
 0169                    QuitGame();
 0170                    return;
 171                }
 172            }
 0173            else if (baseUrlMode.Equals(BaseUrl.LOCAL_HOST))
 174            {
 0175                baseUrl = "http://localhost:8080/?";
 176            }
 0177            else if (baseUrlMode.Equals(BaseUrl.ORG))
 178            {
 0179                baseUrl = "http://play.decentraland.org/?";
 0180                if (!webSocketSSL)
 181                {
 0182                    Debug.LogError(
 183                        "play.decentraland.org only works with WebSocket SSL, please change the base URL to play.decentr
 0184                    QuitGame();
 0185                    return;
 186                }
 187            }
 188            else
 189            {
 0190                baseUrl = "http://play.decentraland.zone/?";
 191            }
 192
 0193            switch (network)
 194            {
 195                case Network.GOERLI:
 0196                    debugString = "NETWORK=goerli&";
 0197                    break;
 198                case Network.MAINNET:
 0199                    debugString = "NETWORK=mainnet&";
 200                    break;
 201            }
 202
 0203            if (!string.IsNullOrEmpty(kernelVersion))
 204            {
 0205                debugString += $"kernel-version={kernelVersion}&";
 206            }
 207
 0208            if (forceLocalComms)
 209            {
 0210                debugString += "LOCAL_COMMS&";
 211            }
 212
 0213            if (enableTutorial)
 214            {
 0215                debugString += "RESET_TUTORIAL&";
 216            }
 217
 0218            if (soloScene)
 219            {
 0220                debugString += "LOS=0&";
 221            }
 222
 0223            if (builderInWorld)
 224            {
 0225                debugString += "ENABLE_BUILDER_IN_WORLD&";
 226            }
 227
 0228            if (disableAssetBundles)
 229            {
 0230                debugString += "DISABLE_ASSET_BUNDLES&DISABLE_WEARABLE_ASSET_BUNDLES&";
 231            }
 232
 0233            if (enableGLTFast)
 234            {
 0235                debugString += "ENABLE_GLTFAST&";
 236            }
 237
 0238            if (enableDebugMode)
 239            {
 0240                debugString += "DEBUG_MODE&";
 241            }
 242
 0243            if (!string.IsNullOrEmpty(realm))
 244            {
 0245                debugString += $"realm={realm}&";
 246            }
 247
 0248            string debugPanelString = "";
 249
 0250            if (debugPanelMode == DebugPanel.Engine)
 251            {
 0252                debugPanelString = "ENGINE_DEBUG_PANEL&";
 253            }
 0254            else if (debugPanelMode == DebugPanel.Scene)
 255            {
 0256                debugPanelString = "SCENE_DEBUG_PANEL&";
 257            }
 258
 0259            if (webSocketSSL)
 260            {
 0261                Debug.Log(
 262                    "[REMINDER] To be able to connect with SSL you should start Chrome with the --ignore-certificate-err
 263            }
 264
 0265            Application.OpenURL(
 266                $"{baseUrl}{debugString}{debugPanelString}position={startInCoords.x}%2C{startInCoords.y}&ws={DataStore.i
 267#endif
 0268        }
 269
 0270        private void OnDestroy() { DataStore.i.wsCommunication.communicationReady.OnChange -= OnCommunicationReadyChange
 271
 272        private void QuitGame()
 273        {
 274#if UNITY_EDITOR
 275            // Application.Quit() does not work in the editor so
 276            // UnityEditor.EditorApplication.isPlaying need to be set to false to end the game
 0277            UnityEditor.EditorApplication.isPlaying = false;
 278#else
 279            Application.Quit();
 280#endif
 0281        }
 282    }
 283}