< 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:100
Coverable lines:100
Total lines:276
Line coverage:0% (0 of 100)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:12
Method coverage:0% (0 of 12)

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%6200%
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 DCL.Components;
 2using UnityEngine;
 3using System.Diagnostics;
 4using Debug = UnityEngine.Debug;
 5using Utils = DCL.Helpers.Utils;
 6
 7namespace DCL
 8{
 9    public class DebugConfigComponent : MonoBehaviour
 10    {
 11        private Stopwatch loadingStopwatch;
 12        private static DebugConfigComponent sharedInstance;
 13        private readonly DataStoreRef<DataStore_LoadingScreen> dataStoreLoadingScreen;
 14
 15        public static DebugConfigComponent i
 16        {
 17            get
 18            {
 019                if (sharedInstance == null)
 020                    sharedInstance = FindObjectOfType<DebugConfigComponent>();
 21
 022                return sharedInstance;
 23            }
 24
 025            private set => sharedInstance = value;
 26        }
 27
 28        public DebugConfig debugConfig;
 29
 30        public enum DebugPanel
 31        {
 32            Off,
 33            Scene,
 34            Engine
 35        }
 36
 37        public enum BaseUrl
 38        {
 39            ZONE,
 40            ORG,
 41            LOCAL_HOST,
 42            SDK_TEST_SCENES,
 43            CUSTOM,
 44        }
 45
 46        public enum Network
 47        {
 48            MAINNET,
 49            SEPOLIA,
 50        }
 51
 52        [Header("General Settings")] public bool OpenBrowserOnStart;
 53        public bool webSocketSSL = false;
 54
 55        [Header("Kernel General Settings")] public string kernelVersion;
 56        public bool useCustomContentServer = false;
 57
 058        public string customContentServerUrl = "http://localhost:1338/";
 59
 60        [Space(10)] public BaseUrl baseUrlMode = BaseUrl.ZONE;
 61        [DrawIf("baseUrlMode", BaseUrl.CUSTOM)]
 062        public string customURL = "https://play.decentraland.zone/?";
 63
 64        [Space(10)] public Network network;
 65
 66        [Tooltip(
 67            "Set this field to force the realm (server). On the latin-american zone, recommended realms are fenrir-amber
 68        public string realm;
 69
 070        public Vector2 startInCoords = new Vector2(-99, 109);
 71
 072        [Header("Kernel Misc Settings")] public bool forceLocalComms = true;
 73
 74        public bool enableTutorial = false;
 75        public bool builderInWorld = false;
 076        public bool soloScene = true;
 77        public bool disableAssetBundles = false;
 78        public bool enableDebugMode = false;
 79        public DebugPanel debugPanelMode = DebugPanel.Off;
 80
 81        [Header("Performance")]
 82        public bool disableGLTFDownloadThrottle = false;
 83        public bool multithreaded = false;
 84        public bool runPerformanceMeterToolDuringLoading = false;
 85        private PerformanceMeterController performanceMeterController;
 86
 87        private void Awake()
 88        {
 089            if (sharedInstance == null)
 090                sharedInstance = this;
 91
 092            DataStore.i.debugConfig.soloScene = debugConfig.soloScene;
 093            DataStore.i.debugConfig.soloSceneCoords = debugConfig.soloSceneCoords;
 094            DataStore.i.debugConfig.ignoreGlobalScenes = debugConfig.ignoreGlobalScenes;
 095            DataStore.i.debugConfig.msgStepByStep = debugConfig.msgStepByStep;
 096            DataStore.i.performance.multithreading.Set(multithreaded);
 097            if (disableGLTFDownloadThrottle) DataStore.i.performance.maxDownloads.Set(999);
 098            Texture.allowThreadedTextureCreation = multithreaded;
 099        }
 100
 101        private void Start()
 102        {
 0103            lock (DataStore.i.wsCommunication.communicationReady)
 104            {
 0105                if (DataStore.i.wsCommunication.communicationReady.Get()) { InitConfig(); }
 0106                else { DataStore.i.wsCommunication.communicationReady.OnChange += OnCommunicationReadyChangedValue; }
 0107            }
 0108        }
 109
 110        private void OnCommunicationReadyChangedValue(bool newState, bool prevState)
 111        {
 0112            if (newState && !prevState)
 0113                InitConfig();
 114
 0115            DataStore.i.wsCommunication.communicationReady.OnChange -= OnCommunicationReadyChangedValue;
 0116        }
 117
 118        private void InitConfig()
 119        {
 0120            if (useCustomContentServer)
 121            {
 0122                RendereableAssetLoadHelper.useCustomContentServerUrl = true;
 0123                RendereableAssetLoadHelper.customContentServerUrl = customContentServerUrl;
 124            }
 125
 0126            if (OpenBrowserOnStart)
 0127                OpenWebBrowser();
 128
 0129            if (runPerformanceMeterToolDuringLoading)
 130            {
 0131                CommonScriptableObjects.forcePerformanceMeter.Set(true);
 0132                performanceMeterController = new PerformanceMeterController();
 133
 0134                StartSampling();
 0135                CommonScriptableObjects.rendererState.OnChange += EndSampling;
 136            }
 0137        }
 138
 139        private void StartSampling()
 140        {
 0141            loadingStopwatch = new Stopwatch();
 0142            loadingStopwatch.Start();
 0143            performanceMeterController.StartSampling(999);
 0144        }
 145
 146        private void EndSampling(bool current, bool previous)
 147        {
 0148            if (current)
 149            {
 0150                loadingStopwatch.Stop();
 0151                CommonScriptableObjects.rendererState.OnChange -= EndSampling;
 0152                performanceMeterController.StopSampling();
 0153                Debug.Log($"Loading time: {loadingStopwatch.Elapsed.Seconds} seconds");
 154            }
 0155        }
 156
 157        private void OpenWebBrowser()
 158        {
 159#if (UNITY_EDITOR)
 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            }
 0188            else if (baseUrlMode.Equals(BaseUrl.SDK_TEST_SCENES)) { baseUrl = "http://sdk-test-scenes.decentraland.zone/
 189            else
 190            {
 0191                baseUrl = "http://play.decentraland.zone/?";
 192            }
 193
 0194            switch (network)
 195            {
 196                case Network.SEPOLIA:
 0197                    debugString = "NETWORK=sepolia&";
 0198                    break;
 199                case Network.MAINNET:
 0200                    debugString = "NETWORK=mainnet&";
 201                    break;
 202            }
 203
 0204            if (!string.IsNullOrEmpty(kernelVersion))
 205            {
 0206                debugString += $"kernel-version={kernelVersion}&";
 207            }
 208
 0209            if (forceLocalComms)
 210            {
 0211                debugString += "LOCAL_COMMS&";
 212            }
 213
 0214            if (enableTutorial)
 215            {
 0216                debugString += "RESET_TUTORIAL&";
 217            }
 218
 0219            if (soloScene)
 220            {
 0221                debugString += "LOS=0&";
 222            }
 223
 0224            if (builderInWorld)
 225            {
 0226                debugString += "ENABLE_BUILDER_IN_WORLD&";
 227            }
 228
 0229            if (disableAssetBundles)
 230            {
 0231                debugString += "DISABLE_ASSET_BUNDLES&DISABLE_WEARABLE_ASSET_BUNDLES&";
 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
 266        private void OnDestroy()
 267        {
 0268            DataStore.i.wsCommunication.communicationReady.OnChange -= OnCommunicationReadyChangedValue;
 0269        }
 270
 271        private void QuitGame()
 272        {
 0273            Utils.QuitApplication();
 0274        }
 275    }
 276}