< 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:36
Uncovered lines:17
Coverable lines:53
Total lines:160
Line coverage:67.9% (36 of 53)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%9.016056.25%
SetupPlugins()0%110100%
SetupEnvironment()0%2100%
MessagingContextBuilder()0%2100%
PlatformContextBuilder()0%2100%
WorldRuntimeContextBuilder()0%2100%
HUDContextBuilder()0%2100%
Start()0%110100%
Update()0%2.062075%
LateUpdate()0%110100%
OnDestroy()0%5.024060%
InitializeSceneDependencies()0%110100%
Init(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Scene/Main/Main.cs

#LineLine coverage
 1using System;
 2using DCL.Components;
 3using DCL.Controllers;
 4using DCL.Helpers;
 5using UnityEngine;
 6using UnityEngine.Serialization;
 7
 8namespace DCL
 9{
 10    /// <summary>
 11    /// This is the InitialScene entry point.
 12    /// Most of the application subsystems should be initialized from this class Awake() event.
 13    /// </summary>
 14    public class Main : MonoBehaviour
 15    {
 16        [SerializeField] private bool disableSceneDependencies;
 017        public static Main i { get; private set; }
 18
 19        public PoolableComponentFactory componentFactory;
 20
 21        private PerformanceMetricsController performanceMetricsController;
 22        private IKernelCommunication kernelCommunication;
 23
 24        private PluginSystem pluginSystem;
 25
 26        protected virtual void Awake()
 27        {
 12528            if (i != null)
 29            {
 030                Utils.SafeDestroy(this);
 031                return;
 32            }
 33
 12534            i = this;
 35
 12536            if (!disableSceneDependencies)
 10437                InitializeSceneDependencies();
 38
 12539            if (!Configuration.EnvironmentSettings.RUNNING_TESTS)
 40            {
 041                performanceMetricsController = new PerformanceMetricsController();
 042                RenderProfileManifest.i.Initialize();
 043                SetupEnvironment();
 44            }
 45
 12546            SetupPlugins();
 47
 48#if UNITY_WEBGL && !UNITY_EDITOR
 49            Debug.Log("DCL Unity Build Version: " + DCL.Configuration.ApplicationSettings.version);
 50            Debug.unityLogger.logEnabled = false;
 51
 52            kernelCommunication = new NativeBridgeCommunication(Environment.i.world.sceneController);
 53#else
 54            // TODO(Brian): Remove this branching once we finish migrating all tests out of the
 55            //              IntegrationTestSuite_Legacy base class.
 12556            if (!Configuration.EnvironmentSettings.RUNNING_TESTS)
 57            {
 058                kernelCommunication = new WebSocketCommunication();
 59            }
 60#endif
 61
 62            // TODO(Brian): This is a temporary fix to address elevators issue in the xmas event.
 63            // We should re-enable this later as produces a performance regression.
 12564            if (!Configuration.EnvironmentSettings.RUNNING_TESTS)
 065                Environment.i.platform.cullingController.SetAnimationCulling(false);
 12566        }
 67
 68        protected virtual void SetupPlugins()
 69        {
 12570            pluginSystem = PluginSystemFactory.Create();
 12571        }
 72
 73        protected virtual void SetupEnvironment()
 74        {
 075            Environment.SetupWithBuilders(
 76                messagingBuilder: MessagingContextBuilder,
 77                platformBuilder: PlatformContextBuilder,
 78                worldRuntimeBuilder: WorldRuntimeContextBuilder,
 79                hudBuilder: HUDContextBuilder);
 080        }
 81
 082        protected virtual MessagingContext MessagingContextBuilder() { return MessagingContextFactory.CreateDefault(); }
 83
 084        protected virtual PlatformContext PlatformContextBuilder() { return PlatformContextFactory.CreateDefault(); }
 85
 086        protected virtual WorldRuntimeContext WorldRuntimeContextBuilder() { return WorldRuntimeContextFactory.CreateDef
 87
 088        protected virtual HUDContext HUDContextBuilder() { return HUDContextFactory.CreateDefault(); }
 89
 90        private void Start()
 91        {
 92            // this event should be the last one to be executed after initialization
 93            // it is used by the kernel to signal "EngineReady" or something like that
 94            // to prevent race conditions like "SceneController is not an object",
 95            // aka sending events before unity is ready
 12596            DCL.Interface.WebInterface.SendSystemInfoReport();
 97
 98            // We trigger the Decentraland logic once everything is initialized.
 12599            DCL.Interface.WebInterface.StartDecentraland();
 100
 125101            Environment.i.world.sceneController.Start();
 125102        }
 103
 104        protected virtual void Update()
 105        {
 21447106            Environment.i.platform.Update();
 21447107            Environment.i.world.sceneController.Update();
 21447108            performanceMetricsController?.Update();
 0109        }
 110
 111        protected virtual void LateUpdate()
 112        {
 21446113            Environment.i.world.sceneController.LateUpdate();
 21446114        }
 115
 116        protected virtual void OnDestroy()
 117        {
 124118            if (!Configuration.EnvironmentSettings.RUNNING_TESTS)
 0119                Environment.Dispose();
 124120            pluginSystem?.Dispose();
 124121            kernelCommunication?.Dispose();
 0122        }
 123
 124        protected virtual void InitializeSceneDependencies()
 125        {
 104126            var bridges = Init("Bridges");
 104127            var mouseCatcher = Init("MouseCatcher").GetComponent<MouseCatcher>();
 104128            var environment = Init("Environment").GetComponent<EnvironmentReferences>();
 104129            var playerReferences = Init("Player").GetComponent<PlayerReferences>();
 130
 104131            Init("HUDController");
 104132            Init("HUDAudioHandler");
 104133            Init("NavMap");
 104134            Init("SettingsController");
 135
 104136            SceneReferences.i.Initialize(
 137                mouseCatcher,
 138                environment.ground,
 139                playerReferences.biwCameraRoot,
 140                playerReferences.inputController,
 141                playerReferences.cursorCanvas,
 142                gameObject,
 143                playerReferences.avatarController,
 144                playerReferences.cameraController,
 145                playerReferences.mainCamera,
 146                bridges,
 147                environment.environmentLight,
 148                environment.postProcessVolume,
 149                playerReferences.thirdPersonCamera,
 150                playerReferences.firstPersonCamera);
 104151        }
 152
 153        private static GameObject Init(string name)
 154        {
 832155            GameObject instance = Instantiate(Resources.Load(name)) as GameObject;
 832156            instance.name = name;
 832157            return instance;
 158        }
 159    }
 160}