< 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:74
Coverable lines:74
Total lines:179
Line coverage:0% (0 of 74)
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.Chat;
 2using DCL.Components;
 3using DCL.Configuration;
 4using DCL.Controllers;
 5using DCL.Helpers;
 6using DCL.Interface;
 7using DCL.SettingsCommon;
 8using RPC;
 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 PerformanceMetricsController performanceMetricsController;
 25        protected IKernelCommunication kernelCommunication;
 26
 27        protected PluginSystem pluginSystem;
 28
 29        protected virtual void Awake()
 30        {
 031            if (i != null)
 32            {
 033                Utils.SafeDestroy(this);
 034                return;
 35            }
 36
 037            i = this;
 38
 039            if (!disableSceneDependencies)
 040                InitializeSceneDependencies();
 41
 042            Settings.CreateSharedInstance(new DefaultSettingsFactory());
 43
 044            if (!EnvironmentSettings.RUNNING_TESTS)
 45            {
 046                performanceMetricsController = new PerformanceMetricsController();
 047                SetupServices();
 48
 049                DataStore.i.HUDs.loadingHUD.visible.OnChange += OnLoadingScreenVisibleStateChange;
 50            }
 51
 52#if UNITY_STANDALONE || UNITY_EDITOR
 053            Application.quitting += () => DataStore.i.common.isApplicationQuitting.Set(true);
 54#endif
 55
 056            InitializeDataStore();
 057            SetupPlugins();
 058            InitializeCommunication();
 059        }
 60
 61        protected virtual void InitializeDataStore()
 62        {
 063            DataStore.i.textureConfig.gltfMaxSize.Set(TextureCompressionSettings.GLTF_TEX_MAX_SIZE_WEB);
 064            DataStore.i.textureConfig.generalMaxSize.Set(TextureCompressionSettings.GENERAL_TEX_MAX_SIZE_WEB);
 065            DataStore.i.avatarConfig.useHologramAvatar.Set(true);
 066        }
 67
 68        protected virtual void InitializeCommunication()
 69        {
 70#if UNITY_WEBGL && !UNITY_EDITOR
 71            Debug.Log("DCL Unity Build Version: " + DCL.Configuration.ApplicationSettings.version);
 72            Debug.unityLogger.logEnabled = false;
 73
 74            kernelCommunication = new NativeBridgeCommunication(Environment.i.world.sceneController);
 75#else
 76            // TODO(Brian): Remove this branching once we finish migrating all tests out of the
 77            //              IntegrationTestSuite_Legacy base class.
 078            if (!EnvironmentSettings.RUNNING_TESTS)
 79            {
 080                kernelCommunication = new WebSocketCommunication(DebugConfigComponent.i.webSocketSSL);
 81            }
 82#endif
 083            RPCServerBuilder.BuildDefaultServer();
 084        }
 85
 86        void OnLoadingScreenVisibleStateChange(bool newVisibleValue, bool previousVisibleValue)
 87        {
 088            if (newVisibleValue)
 89            {
 90                // Prewarm shader variants
 091                Resources.Load<ShaderVariantCollection>("ShaderVariantCollections/shaderVariants-selected").WarmUp();
 092                DataStore.i.HUDs.loadingHUD.visible.OnChange -= OnLoadingScreenVisibleStateChange;
 93            }
 094        }
 95
 96        protected virtual void SetupPlugins()
 97        {
 098            pluginSystem = PluginSystemFactory.Create();
 099            pluginSystem.Initialize();
 0100        }
 101
 102        protected virtual void SetupServices()
 103        {
 0104            Environment.Setup(ServiceLocatorFactory.CreateDefault());
 0105        }
 106
 107        protected virtual void Start()
 108        {
 109            // this event should be the last one to be executed after initialization
 110            // it is used by the kernel to signal "EngineReady" or something like that
 111            // to prevent race conditions like "SceneController is not an object",
 112            // aka sending events before unity is ready
 0113            WebInterface.SendSystemInfoReport();
 114
 115            // We trigger the Decentraland logic once everything is initialized.
 0116            WebInterface.StartDecentraland();
 0117        }
 118
 119        protected virtual void Update()
 120        {
 0121            performanceMetricsController?.Update();
 0122        }
 123
 124        [RuntimeInitializeOnLoadMethod]
 125        static void RunOnStart()
 126        {
 0127            Application.wantsToQuit += ApplicationWantsToQuit;
 0128        }
 129        private static bool ApplicationWantsToQuit()
 130        {
 0131            if (i != null)
 0132                i.Dispose();
 133
 0134            return true;
 135        }
 136
 137        protected virtual void Dispose()
 138        {
 0139            DataStore.i.HUDs.loadingHUD.visible.OnChange -= OnLoadingScreenVisibleStateChange;
 140
 0141            DataStore.i.common.isApplicationQuitting.Set(true);
 142
 0143            pluginSystem?.Dispose();
 144
 0145            if (!EnvironmentSettings.RUNNING_TESTS)
 0146                Environment.Dispose();
 147
 0148            kernelCommunication?.Dispose();
 0149        }
 150
 151        protected virtual void InitializeSceneDependencies()
 152        {
 0153            gameObject.AddComponent<UserProfileController>();
 0154            gameObject.AddComponent<RenderingController>();
 0155            gameObject.AddComponent<CatalogController>();
 0156            gameObject.AddComponent<MinimapMetadataController>();
 0157            gameObject.AddComponent<ChatController>();
 0158            gameObject.AddComponent<FriendsController>();
 0159            gameObject.AddComponent<HotScenesController>();
 0160            gameObject.AddComponent<GIFProcessingBridge>();
 0161            gameObject.AddComponent<RenderProfileBridge>();
 0162            gameObject.AddComponent<AssetCatalogBridge>();
 0163            gameObject.AddComponent<ScreenSizeWatcher>();
 0164            gameObject.AddComponent<SceneControllerBridge>();
 165
 0166            MainSceneFactory.CreateBuilderInWorldBridge(gameObject);
 0167            MainSceneFactory.CreateBridges();
 0168            MainSceneFactory.CreateMouseCatcher();
 0169            MainSceneFactory.CreatePlayerSystems();
 0170            CreateEnvironment();
 0171            MainSceneFactory.CreateAudioHandler();
 0172            MainSceneFactory.CreateHudController();
 0173            MainSceneFactory.CreateNavMap();
 0174            MainSceneFactory.CreateEventSystem();
 0175        }
 176
 0177        protected virtual void CreateEnvironment() => MainSceneFactory.CreateEnvironment();
 178    }
 179}