< 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:178
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.Components;
 2using DCL.Configuration;
 3using DCL.Controllers;
 4using DCL.Helpers;
 5using DCL.Interface;
 6using DCL.SettingsCommon;
 7using RPC;
 8using UnityEngine;
 9
 10namespace DCL
 11{
 12    /// <summary>
 13    /// This is the InitialScene entry point.
 14    /// Most of the application subsystems should be initialized from this class Awake() event.
 15    /// </summary>
 16    public class Main : MonoBehaviour
 17    {
 18        [SerializeField] private bool disableSceneDependencies;
 019        public static Main i { get; private set; }
 20
 21        public PoolableComponentFactory componentFactory;
 22
 23        private PerformanceMetricsController performanceMetricsController;
 24        protected IKernelCommunication kernelCommunication;
 25
 26        protected PluginSystem pluginSystem;
 27
 28        protected virtual void Awake()
 29        {
 030            if (i != null)
 31            {
 032                Utils.SafeDestroy(this);
 033                return;
 34            }
 35
 036            i = this;
 37
 038            if (!disableSceneDependencies)
 039                InitializeSceneDependencies();
 40
 041            Settings.CreateSharedInstance(new DefaultSettingsFactory());
 42
 043            if (!EnvironmentSettings.RUNNING_TESTS)
 44            {
 045                performanceMetricsController = new PerformanceMetricsController();
 046                SetupServices();
 47
 048                DataStore.i.HUDs.loadingHUD.visible.OnChange += OnLoadingScreenVisibleStateChange;
 49            }
 50
 51#if UNITY_STANDALONE || UNITY_EDITOR
 052            Application.quitting += () => DataStore.i.common.isApplicationQuitting.Set(true);
 53#endif
 54
 055            InitializeDataStore();
 056            SetupPlugins();
 057            InitializeCommunication();
 058        }
 59
 60        protected virtual void InitializeDataStore()
 61        {
 062            DataStore.i.textureConfig.gltfMaxSize.Set(TextureCompressionSettings.GLTF_TEX_MAX_SIZE_WEB);
 063            DataStore.i.textureConfig.generalMaxSize.Set(TextureCompressionSettings.GENERAL_TEX_MAX_SIZE_WEB);
 064            DataStore.i.avatarConfig.useHologramAvatar.Set(true);
 065        }
 66
 67        protected virtual void InitializeCommunication()
 68        {
 69#if UNITY_WEBGL && !UNITY_EDITOR
 70            Debug.Log("DCL Unity Build Version: " + DCL.Configuration.ApplicationSettings.version);
 71            Debug.unityLogger.logEnabled = false;
 72
 73            kernelCommunication = new NativeBridgeCommunication(Environment.i.world.sceneController);
 74#else
 75            // TODO(Brian): Remove this branching once we finish migrating all tests out of the
 76            //              IntegrationTestSuite_Legacy base class.
 077            if (!EnvironmentSettings.RUNNING_TESTS)
 78            {
 079                kernelCommunication = new WebSocketCommunication(DebugConfigComponent.i.webSocketSSL);
 80            }
 81#endif
 082            RPCServerBuilder.BuildDefaultServer();
 083        }
 84
 85        void OnLoadingScreenVisibleStateChange(bool newVisibleValue, bool previousVisibleValue)
 86        {
 087            if (newVisibleValue)
 88            {
 89                // Prewarm shader variants
 090                Resources.Load<ShaderVariantCollection>("ShaderVariantCollections/shaderVariants-selected").WarmUp();
 091                DataStore.i.HUDs.loadingHUD.visible.OnChange -= OnLoadingScreenVisibleStateChange;
 92            }
 093        }
 94
 95        protected virtual void SetupPlugins()
 96        {
 097            pluginSystem = PluginSystemFactory.Create();
 098            pluginSystem.Initialize();
 099        }
 100
 101        protected virtual void SetupServices()
 102        {
 0103            Environment.Setup(ServiceLocatorFactory.CreateDefault());
 0104        }
 105
 106        protected virtual void Start()
 107        {
 108            // this event should be the last one to be executed after initialization
 109            // it is used by the kernel to signal "EngineReady" or something like that
 110            // to prevent race conditions like "SceneController is not an object",
 111            // aka sending events before unity is ready
 0112            WebInterface.SendSystemInfoReport();
 113
 114            // We trigger the Decentraland logic once everything is initialized.
 0115            WebInterface.StartDecentraland();
 0116        }
 117
 118        protected virtual void Update()
 119        {
 0120            performanceMetricsController?.Update();
 0121        }
 122
 123        [RuntimeInitializeOnLoadMethod]
 124        static void RunOnStart()
 125        {
 0126            Application.wantsToQuit += ApplicationWantsToQuit;
 0127        }
 128        private static bool ApplicationWantsToQuit()
 129        {
 0130            if (i != null)
 0131                i.Dispose();
 132
 0133            return true;
 134        }
 135
 136        protected virtual void Dispose()
 137        {
 0138            DataStore.i.HUDs.loadingHUD.visible.OnChange -= OnLoadingScreenVisibleStateChange;
 139
 0140            DataStore.i.common.isApplicationQuitting.Set(true);
 141
 0142            pluginSystem?.Dispose();
 143
 0144            if (!EnvironmentSettings.RUNNING_TESTS)
 0145                Environment.Dispose();
 146
 0147            kernelCommunication?.Dispose();
 0148        }
 149
 150        protected virtual void InitializeSceneDependencies()
 151        {
 0152            gameObject.AddComponent<UserProfileController>();
 0153            gameObject.AddComponent<RenderingController>();
 0154            gameObject.AddComponent<CatalogController>();
 0155            gameObject.AddComponent<MinimapMetadataController>();
 0156            gameObject.AddComponent<ChatController>();
 0157            gameObject.AddComponent<FriendsController>();
 0158            gameObject.AddComponent<HotScenesController>();
 0159            gameObject.AddComponent<GIFProcessingBridge>();
 0160            gameObject.AddComponent<RenderProfileBridge>();
 0161            gameObject.AddComponent<AssetCatalogBridge>();
 0162            gameObject.AddComponent<ScreenSizeWatcher>();
 0163            gameObject.AddComponent<SceneControllerBridge>();
 164
 0165            MainSceneFactory.CreateBuilderInWorldBridge(gameObject);
 0166            MainSceneFactory.CreateBridges();
 0167            MainSceneFactory.CreateMouseCatcher();
 0168            MainSceneFactory.CreatePlayerSystems();
 0169            CreateEnvironment();
 0170            MainSceneFactory.CreateAudioHandler();
 0171            MainSceneFactory.CreateHudController();
 0172            MainSceneFactory.CreateNavMap();
 0173            MainSceneFactory.CreateEventSystem();
 0174        }
 175
 0176        protected virtual void CreateEnvironment() => MainSceneFactory.CreateEnvironment();
 177    }
 178}