< 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        {
 75830            Environment.messagingBuilder = messagingBuilder;
 75831            Environment.platformBuilder = platformBuilder;
 75832            Environment.worldRuntimeBuilder = worldRuntimeBuilder;
 75833            Environment.hudBuilder = hudBuilder;
 75834            Setup();
 75835        }
 36
 37        /// <summary>
 38        /// Setup the environment with the configured builder funcs.
 39        /// </summary>
 40        public static void Setup()
 41        {
 75842            i = new Model(messagingBuilder, platformBuilder, worldRuntimeBuilder, hudBuilder);
 75843            Initialize();
 75844        }
 45
 46        /// <summary>
 47        /// Wire the system dependencies. We should improve this approach later.
 48        /// </summary>
 49        private static void Initialize()
 50        {
 75851            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
 75857            model.messaging.manager.Initialize(i.world.sceneController);
 58
 59            // Platform systems
 75860            model.platform.parcelScenesCleaner.Start();
 75861            model.platform.memoryManager.Initialize(model.platform.parcelScenesCleaner);
 75862            model.platform.cullingController.Start();
 63
 64            // World context systems
 75865            model.world.sceneController.Initialize();
 75866            model.world.pointerEventsController.Initialize();
 75867            model.world.state.Initialize();
 75868            model.world.blockersController.InitializeWithDefaultDependencies(
 69                model.world.state, model.platform.cullingController);
 75870            model.world.sceneBoundsChecker.Start();
 75871            model.world.componentFactory.Initialize();
 72
 73            // HUD context system
 75874            model.hud.controller.Initialize(model.hud.factory);
 75875        }
 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>
 155689        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
 758100            public Model(System.Func<MessagingContext> messagingBuilder,
 101                System.Func<PlatformContext> platformBuilder,
 102                System.Func<WorldRuntimeContext> worldBuilder,
 103                System.Func<HUDContext> hudBuilder)
 104            {
 758105                this.messaging = messagingBuilder();
 758106                this.platform = platformBuilder();
 758107                this.world = worldBuilder();
 758108                this.hud = hudBuilder();
 758109            }
 110
 111            public void Dispose()
 112            {
 778113                messaging?.Dispose();
 778114                world?.Dispose();
 778115                platform?.Dispose();
 778116                hud?.Dispose();
 778117            }
 118        }
 119    }
 120}