< Summary

Class:DCL.Environment
Assembly:Environment
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Environment/Environment.cs
Covered lines:35
Uncovered lines:4
Coverable lines:39
Total lines:120
Line coverage:89.7% (35 of 39)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Environment()0%110100%
SetupWithBuilders(...)0%110100%
Setup()0%110100%
Initialize()0%110100%
Reset()0%2100%
Dispose()0%220100%
Model()0%2100%
Model(...)0%110100%
Dispose()0%550100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Environment/Environment.cs

#LineLine coverage
 1using System.ComponentModel;
 2using DCL.Controllers;
 3using UnityEngine;
 4using UnityEngine.SceneManagement;
 5
 6namespace DCL
 7{
 8    public class Environment
 9    {
 110        public static Model i = new Model();
 11        private static System.Func<MessagingContext> messagingBuilder;
 12        private static System.Func<PlatformContext> platformBuilder;
 13        private static System.Func<WorldRuntimeContext> worldRuntimeBuilder;
 14        private static System.Func<HUDContext> hudBuilder;
 15
 16        /// <summary>
 17        /// Configure and setup the environment with custom implementations given by each func passed as parameter.
 18        ///
 19        /// The funcs are stored. So the same environment can be replicated by just calling Setup() later.
 20        /// </summary>
 21        /// <param name="messagingBuilder">A func returning a MessagingContext to be used by the environment.</param>
 22        /// <param name="platformBuilder">A func returning a PlatformContext to be used by the environment.</param>
 23        /// <param name="worldRuntimeBuilder">A func returning a WorldRuntimeContext to be used by the environment.</par
 24        public static void SetupWithBuilders(
 25            System.Func<MessagingContext> messagingBuilder,
 26            System.Func<PlatformContext> platformBuilder,
 27            System.Func<WorldRuntimeContext> worldRuntimeBuilder,
 28            System.Func<HUDContext> hudBuilder)
 29        {
 75530            Environment.messagingBuilder = messagingBuilder;
 75531            Environment.platformBuilder = platformBuilder;
 75532            Environment.worldRuntimeBuilder = worldRuntimeBuilder;
 75533            Environment.hudBuilder = hudBuilder;
 75534            Setup();
 75535        }
 36
 37        /// <summary>
 38        /// Setup the environment with the configured builder funcs.
 39        /// </summary>
 40        public static void Setup()
 41        {
 75542            i = new Model(messagingBuilder, platformBuilder, worldRuntimeBuilder, hudBuilder);
 75543            Initialize();
 75544        }
 45
 46        /// <summary>
 47        /// Wire the system dependencies. We should improve this approach later.
 48        /// </summary>
 49        private static void Initialize()
 50        {
 75551            Model model = i;
 52
 53            //TODO(Brian): We can move to a RAII scheme + promises later to make this
 54            //             more scalable.
 55
 56            // Messaging systems
 75557            model.messaging.manager.Initialize(i.world.sceneController);
 58
 59            // Platform systems
 75560            model.platform.parcelScenesCleaner.Start();
 75561            model.platform.memoryManager.Initialize(model.platform.parcelScenesCleaner);
 75562            model.platform.cullingController.Start();
 63
 64            // World context systems
 75565            model.world.sceneController.Initialize();
 75566            model.world.pointerEventsController.Initialize();
 75567            model.world.state.Initialize();
 75568            model.world.blockersController.InitializeWithDefaultDependencies(
 69                model.world.state, model.platform.cullingController);
 75570            model.world.sceneBoundsChecker.Start();
 75571            model.world.componentFactory.Initialize();
 72
 73            // HUD context system
 75574            model.hud.controller.Initialize(model.hud.factory);
 75575        }
 76
 77        /// <summary>
 78        /// Dispose() and Setup() using the current environment configuration.
 79        /// </summary>
 80        public static void Reset()
 81        {
 082            Dispose();
 083            Setup();
 084        }
 85
 86        /// <summary>
 87        /// Dispose() all the current environment systems.
 88        /// </summary>
 155089        public static void Dispose() { i?.Dispose(); }
 90
 91        public class Model
 92        {
 93            public readonly MessagingContext messaging;
 94            public readonly PlatformContext platform;
 95            public readonly WorldRuntimeContext world;
 96            public readonly HUDContext hud;
 97
 098            public Model () { }
 99
 755100            public Model(System.Func<MessagingContext> messagingBuilder,
 101                System.Func<PlatformContext> platformBuilder,
 102                System.Func<WorldRuntimeContext> worldBuilder,
 103                System.Func<HUDContext> hudBuilder)
 104            {
 755105                this.messaging = messagingBuilder();
 755106                this.platform = platformBuilder();
 755107                this.world = worldBuilder();
 755108                this.hud = hudBuilder();
 755109            }
 110
 111            public void Dispose()
 112            {
 775113                messaging?.Dispose();
 775114                world?.Dispose();
 775115                platform?.Dispose();
 775116                hud?.Dispose();
 775117            }
 118        }
 119    }
 120}