< Summary

Class:RenderingController
Assembly:Rendering
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Rendering/RenderingController.cs
Covered lines:26
Uncovered lines:23
Coverable lines:49
Total lines:104
Line coverage:53% (26 of 49)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
RenderingController()0%110100%
Awake()0%110100%
OnDestroy()0%110100%
DeactivateRendering()0%2.52050%
DeactivateRendering_Internal()0%2100%
ActivateRendering()0%110100%
ForceActivateRendering()0%2100%
ActivateRendering(...)0%6.25063.64%
ActivateRendering_Internal()0%220100%
AddLock(...)0%30500%
RemoveLock(...)0%20400%

File(s)

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

#LineLine coverage
 1using DCL.Helpers;
 2using DCL.Interface;
 3using UnityEngine;
 4
 5public class RenderingController : MonoBehaviour
 6{
 07    public static float firstActivationTime { get; private set; }
 8    private bool firstActivationTimeHasBeenSet = false;
 9    private bool VERBOSE = false;
 10
 111    public CompositeLock renderingActivatedAckLock = new CompositeLock();
 12
 013    private bool activatedRenderingBefore { get; set; } = false;
 14
 15    void Awake()
 16    {
 117        CommonScriptableObjects.rendererState.OnLockAdded += AddLock;
 118        CommonScriptableObjects.rendererState.OnLockRemoved += RemoveLock;
 119        CommonScriptableObjects.rendererState.Set(false);
 120    }
 21
 22    void OnDestroy()
 23    {
 124        CommonScriptableObjects.rendererState.OnLockAdded -= AddLock;
 125        CommonScriptableObjects.rendererState.OnLockRemoved -= RemoveLock;
 126    }
 27
 28    [ContextMenu("Disable Rendering")]
 29    public void DeactivateRendering()
 30    {
 131        if (!CommonScriptableObjects.rendererState.Get())
 132            return;
 33
 034        DeactivateRendering_Internal();
 035    }
 36
 37    void DeactivateRendering_Internal()
 38    {
 039        DCL.Configuration.ParcelSettings.VISUAL_LOADING_ENABLED = false;
 040        CommonScriptableObjects.rendererState.Set(false);
 041        WebInterface.ReportControlEvent(new WebInterface.DeactivateRenderingACK());
 042    }
 43
 44    [ContextMenu("Enable Rendering")]
 245    public void ActivateRendering() { ActivateRendering(forceActivate: false); }
 46
 047    public void ForceActivateRendering() { ActivateRendering(forceActivate: true); }
 48
 49    public void ActivateRendering(bool forceActivate)
 50    {
 151        if (CommonScriptableObjects.rendererState.Get())
 052            return;
 53
 154        if (!firstActivationTimeHasBeenSet)
 55        {
 156            firstActivationTime = Time.realtimeSinceStartup;
 157            firstActivationTimeHasBeenSet = true;
 58        }
 59
 160        if (!forceActivate && !renderingActivatedAckLock.isUnlocked)
 61        {
 062            renderingActivatedAckLock.OnAllLocksRemoved -= ActivateRendering_Internal;
 063            renderingActivatedAckLock.OnAllLocksRemoved += ActivateRendering_Internal;
 064            return;
 65        }
 66
 167        ActivateRendering_Internal();
 168    }
 69
 70    private void ActivateRendering_Internal()
 71    {
 172        renderingActivatedAckLock.OnAllLocksRemoved -= ActivateRendering_Internal;
 73
 174        if (!activatedRenderingBefore)
 75        {
 176            Utils.UnlockCursor();
 177            activatedRenderingBefore = true;
 78        }
 79
 180        DCL.Configuration.ParcelSettings.VISUAL_LOADING_ENABLED = true;
 181        CommonScriptableObjects.rendererState.Set(true);
 82
 183        WebInterface.ReportControlEvent(new WebInterface.ActivateRenderingACK());
 184    }
 85
 86    private void AddLock(object id)
 87    {
 088        if (CommonScriptableObjects.rendererState.Get())
 089            return;
 90
 091        if (VERBOSE)
 092            Debug.Log("Add lock: " + id);
 93
 094        renderingActivatedAckLock.AddLock(id);
 095    }
 96
 97    private void RemoveLock(object id)
 98    {
 099        if (VERBOSE)
 0100            Debug.Log("remove lock: " + id);
 101
 0102        renderingActivatedAckLock.RemoveLock(id);
 0103    }
 104}