< Summary

Class:RenderingController
Assembly:Rendering
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/Rendering/RenderingController.cs
Covered lines:0
Uncovered lines:60
Coverable lines:60
Total lines:134
Line coverage:0% (0 of 60)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:18
Method coverage:0% (0 of 18)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
RenderingController()0%2100%
Awake()0%2100%
DecoupleLoadingScreenVisibilityChange(...)0%6200%
OnDestroy()0%2100%
DeactivateRendering()0%6200%
DeactivateRendering_Internal()0%12300%
ActivateRendering()0%6200%
ForceActivateRendering()0%6200%
ActivateRendering_Internal(...)0%30500%
ActivateRendering_Internal()0%12300%
AddLock(...)0%30500%
RemoveLock(...)0%20400%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/Rendering/RenderingController.cs

#LineLine coverage
 1using DCL;
 2using DCL.Configuration;
 3using DCL.Helpers;
 4using DCL.Interface;
 5using System;
 6using UnityEngine;
 7
 8public class RenderingController : MonoBehaviour
 9{
 010    public static float firstActivationTime { get; private set; }
 11    private bool firstActivationTimeHasBeenSet;
 12    private readonly bool VERBOSE = false;
 13
 014    public CompositeLock renderingActivatedAckLock = new ();
 15
 016    private bool activatedRenderingBefore { get; set; }
 017    private bool isDecoupledLoadingScreenEnabled => true;
 018    private bool isSignUpFlow => DataStore.i.common.isSignUpFlow.Get();
 19
 20    private DataStoreRef<DataStore_LoadingScreen> dataStore_LoadingScreenRef;
 21
 22    private void Awake()
 23    {
 024        CommonScriptableObjects.rendererState.OnLockAdded += AddLock;
 025        CommonScriptableObjects.rendererState.OnLockRemoved += RemoveLock;
 026        CommonScriptableObjects.rendererState.Set(false);
 27
 028        dataStore_LoadingScreenRef.Ref.decoupledLoadingHUD.visible.OnChange += DecoupleLoadingScreenVisibilityChange;
 029        DecoupleLoadingScreenVisibilityChange(true, true);
 030    }
 31
 32    private void DecoupleLoadingScreenVisibilityChange(bool visible, bool _)
 33    {
 034        if (visible)
 035            DeactivateRendering_Internal();
 36        else
 37            //Coming-from-kernel condition. If we are on signup flow, then we must force the ActivateRendering
 038            ActivateRendering_Internal(isSignUpFlow);
 039    }
 40
 41    private void OnDestroy()
 42    {
 043        CommonScriptableObjects.rendererState.OnLockAdded -= AddLock;
 044        CommonScriptableObjects.rendererState.OnLockRemoved -= RemoveLock;
 045    }
 46
 47    [ContextMenu("Disable Rendering")]
 48    public void DeactivateRendering()
 49    {
 050        if (isDecoupledLoadingScreenEnabled) return;
 51
 052        DeactivateRendering_Internal();
 053    }
 54
 55    private void DeactivateRendering_Internal()
 56    {
 057        if (!CommonScriptableObjects.rendererState.Get()) return;
 58
 059        CommonScriptableObjects.rendererState.Set(false);
 60
 061        if (!isDecoupledLoadingScreenEnabled)
 062            WebInterface.ReportControlEvent(new WebInterface.DeactivateRenderingACK());
 063    }
 64
 65    [ContextMenu("Enable Rendering")]
 66    public void ActivateRendering()
 67    {
 068        if (isDecoupledLoadingScreenEnabled) return;
 69
 070        ActivateRendering_Internal(forceActivate: false);
 071    }
 72
 73    public void ForceActivateRendering()
 74    {
 075        if (isDecoupledLoadingScreenEnabled) return;
 76
 077        ActivateRendering_Internal(forceActivate: true);
 078    }
 79
 80    public void ActivateRendering_Internal(bool forceActivate)
 81    {
 082        if (CommonScriptableObjects.rendererState.Get()) return;
 83
 084        if (!firstActivationTimeHasBeenSet)
 85        {
 086            firstActivationTime = Time.realtimeSinceStartup;
 087            firstActivationTimeHasBeenSet = true;
 88        }
 89
 090        if (!forceActivate && !renderingActivatedAckLock.isUnlocked)
 91        {
 092            renderingActivatedAckLock.OnAllLocksRemoved -= ActivateRendering_Internal;
 093            renderingActivatedAckLock.OnAllLocksRemoved += ActivateRendering_Internal;
 094            return;
 95        }
 96
 097        ActivateRendering_Internal();
 098    }
 99
 100    private void ActivateRendering_Internal()
 101    {
 0102        renderingActivatedAckLock.OnAllLocksRemoved -= ActivateRendering_Internal;
 103
 0104        if (!activatedRenderingBefore)
 105        {
 0106            Utils.UnlockCursor();
 0107            activatedRenderingBefore = true;
 108        }
 109
 0110        CommonScriptableObjects.rendererState.Set(true);
 111
 0112        if (!isDecoupledLoadingScreenEnabled)
 0113            WebInterface.ReportControlEvent(new WebInterface.ActivateRenderingACK());
 0114    }
 115
 116    private void AddLock(object id)
 117    {
 0118        if (CommonScriptableObjects.rendererState.Get())
 0119            return;
 120
 0121        if (VERBOSE)
 0122            Debug.Log("Add lock: " + id);
 123
 0124        renderingActivatedAckLock.AddLock(id);
 0125    }
 126
 127    private void RemoveLock(object id)
 128    {
 0129        if (VERBOSE)
 0130            Debug.Log("remove lock: " + id);
 131
 0132        renderingActivatedAckLock.RemoveLock(id);
 0133    }
 134}