< 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        {
 54830            Environment.messagingBuilder = messagingBuilder;
 54831            Environment.platformBuilder = platformBuilder;
 54832            Environment.worldRuntimeBuilder = worldRuntimeBuilder;
 54833            Environment.hudBuilder = hudBuilder;
 54834            Setup();
 54835        }
 36
 37        /// <summary>
 38        /// Setup the environment with the configured builder funcs.
 39        /// </summary>
 40        public static void Setup()
 41        {
 54842            i = new Model(messagingBuilder, platformBuilder, worldRuntimeBuilder, hudBuilder);
 54843            Initialize();
 54844        }
 45
 46        /// <summary>
 47        /// Wire the system dependencies. We should improve this approach later.
 48        /// </summary>
 49        private static void Initialize()
 50        {
 54851            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
 54857            model.messaging.manager.Initialize(i.world.sceneController);
 58
 59            // Platform systems
 54860            model.platform.parcelScenesCleaner.Start();
 54861            model.platform.memoryManager.Initialize(model.platform.parcelScenesCleaner);
 54862            model.platform.cullingController.Start();
 63
 64            // World context systems
 54865            model.world.sceneController.Initialize();
 54866            model.world.pointerEventsController.Initialize();
 54867            model.world.state.Initialize();
 54868            model.world.blockersController.InitializeWithDefaultDependencies(
 69                model.world.state, model.platform.cullingController);
 54870            model.world.sceneBoundsChecker.Start();
 54871            model.world.componentFactory.Initialize();
 72
 73            // HUD context system
 54874            model.hud.controller.Initialize(model.hud.factory);
 54875        }
 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>
 110889        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
 548100            public Model(System.Func<MessagingContext> messagingBuilder,
 101                System.Func<PlatformContext> platformBuilder,
 102                System.Func<WorldRuntimeContext> worldBuilder,
 103                System.Func<HUDContext> hudBuilder)
 104            {
 548105                this.messaging = messagingBuilder();
 548106                this.platform = platformBuilder();
 548107                this.world = worldBuilder();
 548108                this.hud = hudBuilder();
 548109            }
 110
 111            public void Dispose()
 112            {
 554113                messaging?.Dispose();
 554114                world?.Dispose();
 554115                platform?.Dispose();
 554116                hud?.Dispose();
 554117            }
 118        }
 119    }
 120}