< Summary

Class:DCL.Environment
Assembly:Environment
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Environment/Environment.cs
Covered lines:34
Uncovered lines:4
Coverable lines:38
Total lines:119
Line coverage:89.4% (34 of 38)
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        {
 76530            Environment.messagingBuilder = messagingBuilder;
 76531            Environment.platformBuilder = platformBuilder;
 76532            Environment.worldRuntimeBuilder = worldRuntimeBuilder;
 76533            Environment.hudBuilder = hudBuilder;
 76534            Setup();
 76535        }
 36
 37        /// <summary>
 38        /// Setup the environment with the configured builder funcs.
 39        /// </summary>
 40        public static void Setup()
 41        {
 76542            i = new Model(messagingBuilder, platformBuilder, worldRuntimeBuilder, hudBuilder);
 76543            Initialize();
 76544        }
 45
 46        /// <summary>
 47        /// Wire the system dependencies. We should improve this approach later.
 48        /// </summary>
 49        private static void Initialize()
 50        {
 76551            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
 76557            model.messaging.manager.Initialize(i.world.sceneController);
 58
 59            // Platform systems
 76560            model.platform.cullingController.Start();
 76561            model.platform.parcelScenesCleaner.Initialize();
 62
 63            // World context systems
 76564            model.world.sceneController.Initialize();
 76565            model.world.pointerEventsController.Initialize();
 76566            model.world.state.Initialize();
 76567            model.world.blockersController.InitializeWithDefaultDependencies(
 68                model.world.state, model.platform.cullingController);
 76569            model.world.sceneBoundsChecker.Start();
 76570            model.world.componentFactory.Initialize();
 71
 72            // HUD context system
 76573            model.hud.controller.Initialize(model.hud.factory);
 76574        }
 75
 76        /// <summary>
 77        /// Dispose() and Setup() using the current environment configuration.
 78        /// </summary>
 79        public static void Reset()
 80        {
 081            Dispose();
 082            Setup();
 083        }
 84
 85        /// <summary>
 86        /// Dispose() all the current environment systems.
 87        /// </summary>
 157288        public static void Dispose() { i?.Dispose(); }
 89
 90        public class Model
 91        {
 92            public readonly MessagingContext messaging;
 93            public readonly PlatformContext platform;
 94            public readonly WorldRuntimeContext world;
 95            public readonly HUDContext hud;
 96
 097            public Model () { }
 98
 76599            public Model(System.Func<MessagingContext> messagingBuilder,
 100                System.Func<PlatformContext> platformBuilder,
 101                System.Func<WorldRuntimeContext> worldBuilder,
 102                System.Func<HUDContext> hudBuilder)
 103            {
 765104                this.messaging = messagingBuilder();
 765105                this.platform = platformBuilder();
 765106                this.world = worldBuilder();
 765107                this.hud = hudBuilder();
 765108            }
 109
 110            public void Dispose()
 111            {
 786112                messaging?.Dispose();
 786113                world?.Dispose();
 786114                platform?.Dispose();
 786115                hud?.Dispose();
 786116            }
 117        }
 118    }
 119}