< 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:70
Coverable lines:70
Total lines:183
Line coverage:0% (0 of 70)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:14
Method coverage:0% (0 of 14)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%30500%
Start()0%2100%
Update()0%6200%
InitializeDataStore()0%2100%
InitializeCommunication()0%6200%
SetupPlugins()0%2100%
SetupServices()0%2100%
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 Cysharp.Threading.Tasks;
 2using DCL.Components;
 3using DCL.Configuration;
 4using DCL.Helpers;
 5using DCL.Interface;
 6using DCL.Map;
 7using DCL.Providers;
 8using DCL.SettingsCommon;
 9using DCl.Social.Friends;
 10using DCL.Social.Friends;
 11using MainScripts.DCL.Controllers.HotScenes;
 12using DCLServices.WearablesCatalogService;
 13using MainScripts.DCL.Controllers.FriendsController;
 14using UnityEngine;
 15#if UNITY_EDITOR
 16using DG.Tweening;
 17#endif
 18
 19namespace DCL
 20{
 21    /// <summary>
 22    ///     This is the InitialScene entry point.
 23    ///     Most of the application subsystems should be initialized from this class Awake() event.
 24    /// </summary>
 25    public class Main : MonoBehaviour
 26    {
 27        [SerializeField] private bool disableSceneDependencies;
 28
 29        private HotScenesController hotScenesController;
 30
 31        private readonly DataStoreRef<DataStore_LoadingScreen> dataStoreLoadingScreen;
 32        protected IKernelCommunication kernelCommunication;
 33
 34        private PerformanceMetricsController performanceMetricsController;
 35
 36        protected PluginSystem pluginSystem;
 037        public static Main i { get; private set; }
 38
 39        protected virtual void Awake()
 40        {
 041            if (i != null)
 42            {
 043                Utils.SafeDestroy(this);
 044                return;
 45            }
 46
 047            i = this;
 48
 049            if (!disableSceneDependencies)
 050                InitializeSceneDependencies();
 51
 52#if UNITY_EDITOR
 53
 54            // Prevent warning when starting on unity editor mode
 55            // TODO: Are we instantiating 500 different kinds of animations?
 056            DOTween.SetTweensCapacity(500, 50);
 57#endif
 58
 059            Settings.CreateSharedInstance(new DefaultSettingsFactory());
 60
 061            if (!EnvironmentSettings.RUNNING_TESTS)
 62            {
 063                SetupServices();
 064                performanceMetricsController = new PerformanceMetricsController();
 65            }
 66
 67#if UNITY_STANDALONE || UNITY_EDITOR
 068            Application.quitting += () => DataStore.i.common.isApplicationQuitting.Set(true);
 69#endif
 70
 071            InitializeDataStore();
 072            SetupPlugins();
 073            InitializeCommunication();
 074        }
 75
 76        protected virtual void Start()
 77        {
 78            // this event should be the last one to be executed after initialization
 79            // it is used by the kernel to signal "EngineReady" or something like that
 80            // to prevent race conditions like "SceneController is not an object",
 81            // aka sending events before unity is ready
 082            WebInterface.SendSystemInfoReport();
 83
 84            // We trigger the Decentraland logic once everything is initialized.
 085            WebInterface.StartDecentraland();
 086        }
 87
 88        protected virtual void Update()
 89        {
 090            performanceMetricsController?.Update();
 091        }
 92
 93        protected virtual void InitializeDataStore()
 94        {
 095            DataStore.i.textureConfig.gltfMaxSize.Set(TextureCompressionSettings.GLTF_TEX_MAX_SIZE_WEB);
 096            DataStore.i.textureConfig.generalMaxSize.Set(TextureCompressionSettings.GENERAL_TEX_MAX_SIZE_WEB);
 097            DataStore.i.avatarConfig.useHologramAvatar.Set(true);
 098        }
 99
 100        protected virtual void InitializeCommunication()
 101        {
 102#if UNITY_WEBGL && !UNITY_EDITOR
 103            Debug.Log("DCL Unity Build Version: " + DCL.Configuration.ApplicationSettings.version);
 104
 105            kernelCommunication = new NativeBridgeCommunication(Environment.i.world.sceneController);
 106#else
 107
 108            // TODO(Brian): Remove this branching once we finish migrating all tests out of the
 109            //              IntegrationTestSuite_Legacy base class.
 0110            if (!EnvironmentSettings.RUNNING_TESTS) { kernelCommunication = new WebSocketCommunication(DebugConfigCompon
 111#endif
 0112        }
 113
 114        protected virtual void SetupPlugins()
 115        {
 0116            pluginSystem = PluginSystemFactory.Create();
 0117            pluginSystem.Initialize();
 0118        }
 119
 120        protected virtual void SetupServices()
 121        {
 0122            var serviceLocator = ServiceLocatorFactory.CreateDefault();
 0123            serviceLocator.Register<IHotScenesController>(() => hotScenesController);
 0124            Environment.Setup(serviceLocator);
 0125        }
 126
 127        [RuntimeInitializeOnLoadMethod]
 128        private static void RunOnStart()
 129        {
 0130            Application.wantsToQuit += ApplicationWantsToQuit;
 0131        }
 132
 133        private static bool ApplicationWantsToQuit()
 134        {
 0135            if (i != null)
 0136                i.Dispose();
 137
 0138            return true;
 139        }
 140
 141        protected virtual void Dispose()
 142        {
 0143            DataStore.i.common.isApplicationQuitting.Set(true);
 0144            Settings.i.SaveSettings();
 145
 0146            pluginSystem?.Dispose();
 147
 0148            if (!EnvironmentSettings.RUNNING_TESTS)
 0149                Environment.Dispose();
 150
 0151            kernelCommunication?.Dispose();
 0152        }
 153
 154        protected virtual void InitializeSceneDependencies()
 155        {
 0156            gameObject.AddComponent<UserProfileController>();
 0157            gameObject.AddComponent<RenderingController>();
 0158            gameObject.AddComponent<WebInterfaceWearablesCatalogService>();
 0159            gameObject.AddComponent<WebInterfaceMinimapApiBridge>();
 0160            gameObject.AddComponent<MinimapMetadataController>();
 0161            gameObject.AddComponent<WebInterfaceFriendsApiBridge>();
 0162            hotScenesController = gameObject.AddComponent<HotScenesController>();
 0163            gameObject.AddComponent<MatrixInitializationBridge>();
 0164            gameObject.AddComponent<GIFProcessingBridge>();
 0165            gameObject.AddComponent<RenderProfileBridge>();
 0166            gameObject.AddComponent<AssetCatalogBridge>();
 0167            gameObject.AddComponent<ScreenSizeWatcher>();
 0168            gameObject.AddComponent<SceneControllerBridge>();
 169
 0170            MainSceneFactory.CreateBridges();
 0171            MainSceneFactory.CreateMouseCatcher();
 0172            MainSceneFactory.CreatePlayerSystems();
 0173            CreateEnvironment();
 0174            MainSceneFactory.CreateAudioHandler();
 0175            MainSceneFactory.CreateHudController();
 0176            MainSceneFactory.CreateNavMap();
 0177            MainSceneFactory.CreateEventSystem();
 0178        }
 179
 180        protected virtual void CreateEnvironment() =>
 0181            MainSceneFactory.CreateEnvironment();
 182    }
 183}