< 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:78
Coverable lines:78
Total lines:192
Line coverage:0% (0 of 78)
Covered branches:0
Total branches:0

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%
OnLoadingScreenVisibleStateChange(...)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 DCL.Components;
 2using DCL.Configuration;
 3using DCL.Helpers;
 4using DCL.Interface;
 5using DCL.SettingsCommon;
 6using DCL.Social.Chat;
 7using DCl.Social.Friends;
 8using DCL.Social.Friends;
 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;
 20
 21        public PoolableComponentFactory componentFactory;
 22        private readonly DataStoreRef<DataStore_LoadingScreen> dataStoreLoadingScreen;
 23        protected IKernelCommunication kernelCommunication;
 24
 25        private PerformanceMetricsController performanceMetricsController;
 26
 27        protected PluginSystem pluginSystem;
 028        public static Main i { get; private set; }
 29
 30        protected virtual void Awake()
 31        {
 032            if (i != null)
 33            {
 034                Utils.SafeDestroy(this);
 035                return;
 36            }
 37
 038            i = this;
 39
 040            if (!disableSceneDependencies)
 041                InitializeSceneDependencies();
 42
 043            Settings.CreateSharedInstance(new DefaultSettingsFactory());
 44
 45            // TODO: migrate chat controller singleton into a service in the service locator
 046            ChatController.CreateSharedInstance(GetComponent<WebInterfaceChatBridge>(), DataStore.i);
 47
 048            if (!EnvironmentSettings.RUNNING_TESTS)
 49            {
 050                performanceMetricsController = new PerformanceMetricsController();
 051                SetupServices();
 52
 053                dataStoreLoadingScreen.Ref.loadingHUD.visible.OnChange += OnLoadingScreenVisibleStateChange;
 054                dataStoreLoadingScreen.Ref.decoupledLoadingHUD.visible.OnChange += OnLoadingScreenVisibleStateChange;
 55            }
 56
 57            // TODO (NEW FRIEND REQUESTS): remove when the kernel bridge is production ready
 058            WebInterfaceFriendsApiBridge webInterfaceFriendsApiBridge = GetComponent<WebInterfaceFriendsApiBridge>();
 59
 060            FriendsController.CreateSharedInstance(new WebInterfaceFriendsApiBridgeProxy(
 61                webInterfaceFriendsApiBridge,
 62                RPCFriendsApiBridge.CreateSharedInstance(Environment.i.serviceLocator.Get<IRPC>(), webInterfaceFriendsAp
 63                DataStore.i));
 64
 65#if UNITY_STANDALONE || UNITY_EDITOR
 066            Application.quitting += () => DataStore.i.common.isApplicationQuitting.Set(true);
 67#endif
 68
 069            InitializeDataStore();
 070            SetupPlugins();
 071            InitializeCommunication();
 072        }
 73
 74        protected virtual void Start()
 75        {
 76            // this event should be the last one to be executed after initialization
 77            // it is used by the kernel to signal "EngineReady" or something like that
 78            // to prevent race conditions like "SceneController is not an object",
 79            // aka sending events before unity is ready
 080            WebInterface.SendSystemInfoReport();
 81
 82            // We trigger the Decentraland logic once everything is initialized.
 083            WebInterface.StartDecentraland();
 084        }
 85
 86        protected virtual void Update()
 87        {
 088            performanceMetricsController?.Update();
 089        }
 90
 91        protected virtual void InitializeDataStore()
 92        {
 093            DataStore.i.textureConfig.gltfMaxSize.Set(TextureCompressionSettings.GLTF_TEX_MAX_SIZE_WEB);
 094            DataStore.i.textureConfig.generalMaxSize.Set(TextureCompressionSettings.GENERAL_TEX_MAX_SIZE_WEB);
 095            DataStore.i.avatarConfig.useHologramAvatar.Set(true);
 096        }
 97
 98        protected virtual void InitializeCommunication()
 99        {
 100#if UNITY_WEBGL && !UNITY_EDITOR
 101            Debug.Log("DCL Unity Build Version: " + DCL.Configuration.ApplicationSettings.version);
 102
 103            kernelCommunication = new NativeBridgeCommunication(Environment.i.world.sceneController);
 104#else
 105
 106            // TODO(Brian): Remove this branching once we finish migrating all tests out of the
 107            //              IntegrationTestSuite_Legacy base class.
 0108            if (!EnvironmentSettings.RUNNING_TESTS) { kernelCommunication = new WebSocketCommunication(DebugConfigCompon
 109#endif
 0110        }
 111
 112        private void OnLoadingScreenVisibleStateChange(bool newVisibleValue, bool previousVisibleValue)
 113        {
 0114            if (newVisibleValue)
 115            {
 116                // Prewarm shader variants
 0117                Resources.Load<ShaderVariantCollection>("ShaderVariantCollections/shaderVariants-selected").WarmUp();
 0118                dataStoreLoadingScreen.Ref.loadingHUD.visible.OnChange -= OnLoadingScreenVisibleStateChange;
 0119                dataStoreLoadingScreen.Ref.decoupledLoadingHUD.visible.OnChange -= OnLoadingScreenVisibleStateChange;
 120            }
 0121        }
 122
 123        protected virtual void SetupPlugins()
 124        {
 0125            pluginSystem = PluginSystemFactory.Create();
 0126            pluginSystem.Initialize();
 0127        }
 128
 129        protected virtual void SetupServices()
 130        {
 0131            Environment.Setup(ServiceLocatorFactory.CreateDefault());
 0132        }
 133
 134        [RuntimeInitializeOnLoadMethod]
 135        private static void RunOnStart()
 136        {
 0137            Application.wantsToQuit += ApplicationWantsToQuit;
 0138        }
 139
 140        private static bool ApplicationWantsToQuit()
 141        {
 0142            if (i != null)
 0143                i.Dispose();
 144
 0145            return true;
 146        }
 147
 148        protected virtual void Dispose()
 149        {
 0150            dataStoreLoadingScreen.Ref.loadingHUD.visible.OnChange -= OnLoadingScreenVisibleStateChange;
 0151            dataStoreLoadingScreen.Ref.decoupledLoadingHUD.visible.OnChange -= OnLoadingScreenVisibleStateChange;
 152
 0153            DataStore.i.common.isApplicationQuitting.Set(true);
 0154            Settings.i.SaveSettings();
 155
 0156            pluginSystem?.Dispose();
 157
 0158            if (!EnvironmentSettings.RUNNING_TESTS)
 0159                Environment.Dispose();
 160
 0161            kernelCommunication?.Dispose();
 0162        }
 163
 164        protected virtual void InitializeSceneDependencies()
 165        {
 0166            gameObject.AddComponent<UserProfileController>();
 0167            gameObject.AddComponent<RenderingController>();
 0168            gameObject.AddComponent<CatalogController>();
 0169            gameObject.AddComponent<MinimapMetadataController>();
 0170            gameObject.AddComponent<WebInterfaceChatBridge>();
 0171            gameObject.AddComponent<WebInterfaceFriendsApiBridge>();
 0172            gameObject.AddComponent<HotScenesController>();
 0173            gameObject.AddComponent<GIFProcessingBridge>();
 0174            gameObject.AddComponent<RenderProfileBridge>();
 0175            gameObject.AddComponent<AssetCatalogBridge>();
 0176            gameObject.AddComponent<ScreenSizeWatcher>();
 0177            gameObject.AddComponent<SceneControllerBridge>();
 178
 0179            MainSceneFactory.CreateBridges();
 0180            MainSceneFactory.CreateMouseCatcher();
 0181            MainSceneFactory.CreatePlayerSystems();
 0182            CreateEnvironment();
 0183            MainSceneFactory.CreateAudioHandler();
 0184            MainSceneFactory.CreateHudController();
 0185            MainSceneFactory.CreateNavMap();
 0186            MainSceneFactory.CreateEventSystem();
 0187        }
 188
 189        protected virtual void CreateEnvironment() =>
 0190            MainSceneFactory.CreateEnvironment();
 191    }
 192}