< Summary

Class:ECSSystemsController
Assembly:ECS7Plugin.Systems
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/Systems/ECSSystemsController.cs
Covered lines:45
Uncovered lines:23
Coverable lines:68
Total lines:261
Line coverage:66.1% (45 of 68)
Covered branches:0
Total branches:0
Covered methods:2
Total methods:4
Method coverage:50% (2 of 4)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ECSSystemsController(...)0%110100%
Dispose()0%110100%
Update()0%6200%
LateUpdate()0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/Systems/ECSSystemsController.cs

#LineLine coverage
 1using DCL;
 2using ECSSystems.AnimationSystem;
 3using ECSSystems.AvatarModifierAreaSystem;
 4using ECSSystems.BillboardSystem;
 5using ECSSystems.CameraSystem;
 6using ECSSystems.ECSEngineInfoSystem;
 7using ECSSystems.ECSRaycastSystem;
 8using ECSSystems.ECSSceneBoundsCheckerSystem;
 9using ECSSystems.ECSUiPointerEventsSystem;
 10using ECSSystems.GltfContainerLoadingStateSystem;
 11using ECSSystems.InputSenderSystem;
 12using ECSSystems.MaterialSystem;
 13using ECSSystems.PlayerSystem;
 14using ECSSystems.PointerInputSystem;
 15using ECSSystems.ScenesUiSystem;
 16using ECSSystems.TweenSystem;
 17using ECSSystems.UiCanvasInformationSystem;
 18using ECSSystems.UIInputSenderSystem;
 19using ECSSystems.VideoPlayerSystem;
 20using ECSSystems.VisibilitySystem;
 21using System;
 22using System.Collections.Generic;
 23using UnityEngine;
 24using UnityEngine.UIElements;
 25using ECS7System = System.Action;
 26using Environment = DCL.Environment;
 27using Object = UnityEngine.Object;
 28
 29public class ECSSystemsController : IDisposable
 30{
 31    private readonly IList<ECS7System> updateSystems;
 32    private readonly IList<ECS7System> lateUpdateSystems;
 33    private readonly IUpdateEventHandler updateEventHandler;
 34    private readonly ECS7System internalComponentMarkDirtySystem;
 35    private readonly ECS7System internalComponentRemoveDirtySystem;
 36    private readonly ECSScenesUiSystem uiSystem;
 37    private readonly ECSCameraEntitySystem cameraEntitySystem;
 38    private readonly ECSPlayerTransformSystem playerTransformSystem;
 39    private readonly ECSSceneBoundsCheckerSystem sceneBoundsCheckerSystem;
 40    private readonly ECSUiCanvasInformationSystem uiCanvasInformationSystem;
 41    private readonly GameObject hoverCanvas;
 42    private readonly GameObject scenesUi;
 43    private readonly IWorldState worldState;
 44
 145    public ECSSystemsController(SystemsContext context)
 46    {
 147        this.worldState = Environment.i.world.state;
 148        this.updateEventHandler = Environment.i.platform.updateEventHandler;
 149        this.internalComponentMarkDirtySystem = context.internalEcsComponents.MarkDirtyComponentsUpdate;
 150        this.internalComponentRemoveDirtySystem = context.internalEcsComponents.ResetDirtyComponentsUpdate;
 51
 152        var canvas = Resources.Load<GameObject>("ECSInteractionHoverCanvas");
 153        hoverCanvas = Object.Instantiate(canvas);
 154        hoverCanvas.name = "_ECSInteractionHoverCanvas";
 155        IECSInteractionHoverCanvas interactionHoverCanvas = hoverCanvas.GetComponent<IECSInteractionHoverCanvas>();
 56
 157        var scenesUiResource = Resources.Load<UIDocument>("ScenesUI");
 158        var scenesUiDocument = Object.Instantiate(scenesUiResource);
 159        scenesUiDocument.name = "_ECSScenesUI";
 160        scenesUi = scenesUiDocument.gameObject;
 61
 162        uiSystem = new ECSScenesUiSystem(
 63            scenesUiDocument,
 64            context.internalEcsComponents.uiContainerComponent,
 65            DataStore.i.ecs7.scenes,
 66            Environment.i.world.state,
 67            CommonScriptableObjects.allUIHidden,
 68            DataStore.i.HUDs.isCurrentSceneUiEnabled,
 69            DataStore.i.HUDs.isSceneUiEnabled);
 70
 171        ECSBillboardSystem billboardSystem = new ECSBillboardSystem(context.billboards, DataStore.i.camera);
 72
 173        ECSVideoPlayerSystem videoPlayerSystem = new ECSVideoPlayerSystem(
 74            context.internalEcsComponents.videoPlayerComponent,
 75            context.internalEcsComponents.videoMaterialComponent,
 76            context.internalEcsComponents.EngineInfo,
 77            context.ComponentWriters,
 78            context.VideoEventPool);
 79
 180        cameraEntitySystem = new ECSCameraEntitySystem(context.ComponentWriters,
 81            context.CameraModePool, context.PointerLockPool, context.TransformPool, context.TransformComponent,
 82            DataStore.i.ecs7.scenes, DataStore.i.camera.transform, CommonScriptableObjects.worldOffset, CommonScriptable
 83
 184        playerTransformSystem = new ECSPlayerTransformSystem(context.ComponentWriters, context.TransformPool,
 85            context.TransformComponent, DataStore.i.ecs7.scenes,
 86            DataStore.i.world.avatarTransform, CommonScriptableObjects.worldOffset);
 87
 188        ECSUIInputSenderSystem uiInputSenderSystem = new ECSUIInputSenderSystem(
 89            context.internalEcsComponents.uiInputResultsComponent,
 90            context.ComponentWriters);
 91
 192        ECSRaycastSystem raycastSystem = new ECSRaycastSystem(
 93            context.internalEcsComponents.raycastComponent,
 94            context.internalEcsComponents.physicColliderComponent,
 95            context.internalEcsComponents.onPointerColliderComponent,
 96            context.internalEcsComponents.customLayerColliderComponent,
 97            context.internalEcsComponents.EngineInfo,
 98            context.ComponentWriters,
 99            context.RaycastResultPool);
 100
 1101        sceneBoundsCheckerSystem = new ECSSceneBoundsCheckerSystem(
 102            DataStore.i.ecs7.scenes,
 103            context.internalEcsComponents.sceneBoundsCheckComponent,
 104            context.internalEcsComponents.visibilityComponent,
 105            context.internalEcsComponents.renderersComponent,
 106            context.internalEcsComponents.onPointerColliderComponent,
 107            context.internalEcsComponents.physicColliderComponent,
 108            DataStore.i.debugConfig.isDebugMode.Get());
 109
 1110        ECSUiPointerEventsSystem uiPointerEventsSystem = new ECSUiPointerEventsSystem(
 111            context.internalEcsComponents.RegisteredUiPointerEventsComponent,
 112            context.internalEcsComponents.inputEventResultsComponent,
 113            context.componentGroups.UnregisteredUiPointerEvents,
 114            context.componentGroups.RegisteredUiPointerEvents,
 115            context.componentGroups.RegisteredUiPointerEventsWithUiRemoved,
 116            context.componentGroups.RegisteredUiPointerEventsWithPointerEventsRemoved);
 117
 1118        ECSPointerInputSystem pointerInputSystem = new ECSPointerInputSystem(
 119            context.internalEcsComponents.onPointerColliderComponent,
 120            context.internalEcsComponents.inputEventResultsComponent,
 121            context.internalEcsComponents.PointerEventsComponent,
 122            interactionHoverCanvas,
 123            Environment.i.world.state,
 124            DataStore.i.ecs7);
 125
 1126        GltfContainerLoadingStateSystem gltfContainerLoadingStateSystem = new GltfContainerLoadingStateSystem(
 127            context.ComponentWriters,
 128            context.GltfContainerLoadingStatePool,
 129            context.internalEcsComponents.GltfContainerLoadingStateComponent);
 130
 1131        ECSEngineInfoSystem engineInfoSystem = new ECSEngineInfoSystem(
 132            context.ComponentWriters,
 133            context.EngineInfoPool,
 134            context.internalEcsComponents.EngineInfo);
 135
 1136        uiCanvasInformationSystem = new ECSUiCanvasInformationSystem(
 137            context.ComponentWriters,
 138            context.UiCanvasInformationPool,
 139            DataStore.i.ecs7.scenes);
 140
 1141        ECSInputSenderSystem inputSenderSystem = new ECSInputSenderSystem(
 142            context.internalEcsComponents.inputEventResultsComponent,
 143            context.internalEcsComponents.EngineInfo,
 144            context.ComponentWriters,
 145            context.PointerEventsResultPool,
 0146            () => worldState.GetCurrentSceneNumber());
 147
 1148        AnimationSystem animationSystem = new AnimationSystem(
 149            context.componentGroups.AnimationGroup,
 150            context.internalEcsComponents.Animation);
 151
 1152        ECSTweenSystem tweenSystem = new ECSTweenSystem(
 153            context.internalEcsComponents.TweenComponent,
 154            context.ComponentWriters,
 155            context.TweenStatePool,
 156            context.TransformPool,
 157            CommonScriptableObjects.worldOffset,
 158            context.internalEcsComponents.sceneBoundsCheckComponent);
 159
 1160        ECSAvatarModifierAreaSystem avatarModifierAreaSystem = new ECSAvatarModifierAreaSystem(
 161            context.internalEcsComponents.AvatarModifierAreaComponent, DataStore.i.player);
 162
 1163        updateEventHandler.AddListener(IUpdateEventHandler.EventType.Update, Update);
 1164        updateEventHandler.AddListener(IUpdateEventHandler.EventType.LateUpdate, LateUpdate);
 165
 1166        updateSystems = new ECS7System[]
 167        {
 168            engineInfoSystem.Update,
 169            ECSTransformParentingSystem.CreateSystem(context.internalEcsComponents.sceneBoundsCheckComponent),
 170            tweenSystem.Update,
 171            ECSMaterialSystem.CreateSystem(context.componentGroups.texturizableGroup,
 172                context.internalEcsComponents.texturizableComponent, context.internalEcsComponents.materialComponent),
 173            ECSVisibilitySystem.CreateSystem(context.componentGroups.visibilityGroup,
 174                context.internalEcsComponents.renderersComponent, context.internalEcsComponents.visibilityComponent),
 175            avatarModifierAreaSystem.Update,
 176            uiSystem.Update,
 177            pointerInputSystem.Update,
 178            billboardSystem.Update,
 179            videoPlayerSystem.Update,
 180            uiCanvasInformationSystem.Update,
 181            animationSystem.Update
 182        };
 183
 1184        lateUpdateSystems = new ECS7System[]
 185        {
 186            uiPointerEventsSystem.Update,
 187            uiInputSenderSystem.Update, // Input detection happens during Update() so this system has to run in LateUpda
 188            inputSenderSystem.Update,
 189            cameraEntitySystem.Update,
 190            playerTransformSystem.Update,
 191            gltfContainerLoadingStateSystem.Update,
 192            raycastSystem.Update, // Should always be after player/entity transformations update
 193            sceneBoundsCheckerSystem.Update // Should always be the last system
 194        };
 1195    }
 196
 197    public void Dispose()
 198    {
 1199        updateEventHandler.RemoveListener(IUpdateEventHandler.EventType.Update, Update);
 1200        updateEventHandler.RemoveListener(IUpdateEventHandler.EventType.LateUpdate, LateUpdate);
 1201        uiSystem.Dispose();
 1202        cameraEntitySystem.Dispose();
 1203        playerTransformSystem.Dispose();
 1204        sceneBoundsCheckerSystem.Dispose();
 1205        uiCanvasInformationSystem.Dispose();
 1206        Object.Destroy(hoverCanvas);
 1207        Object.Destroy(scenesUi);
 1208    }
 209
 210    private void Update()
 211    {
 212        try
 213        {
 0214            internalComponentMarkDirtySystem.Invoke();
 0215        }
 216        catch (Exception e)
 217        {
 0218            Debug.LogException(e);
 0219        }
 220
 0221        int count = updateSystems.Count;
 222
 0223        for (int i = 0; i < count; i++)
 224        {
 225            try
 226            {
 0227                updateSystems[i].Invoke();
 0228            }
 229            catch (Exception e)
 230            {
 0231                Debug.LogException(e);
 0232            }
 233        }
 0234    }
 235
 236    private void LateUpdate()
 237    {
 0238        int count = lateUpdateSystems.Count;
 239
 0240        for (int i = 0; i < count; i++)
 241        {
 242            try
 243            {
 0244                lateUpdateSystems[i].Invoke();
 0245            }
 246            catch (Exception e)
 247            {
 0248                Debug.LogException(e);
 0249            }
 250        }
 251
 252        try
 253        {
 0254            internalComponentRemoveDirtySystem.Invoke();
 0255        }
 256        catch (Exception e)
 257        {
 0258            Debug.LogException(e);
 0259        }
 0260    }
 261}