< Summary

Class:DCL.Rendering.CullingObjectsTracker
Assembly:CullingController
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Rendering/Culling/CullingObjectsTracker.cs
Covered lines:32
Uncovered lines:1
Coverable lines:33
Total lines:113
Line coverage:96.9% (32 of 33)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CullingObjectsTracker()0%110100%
PopulateRenderersList()0%550100%
ForcePopulateRenderersList(...)0%110100%
SetIgnoredLayersMask(...)0%110100%
MarkDirty()0%110100%
IsDirty()0%110100%
GetRenderers()0%110100%
GetSkinnedRenderers()0%110100%
GetAnimations()0%110100%
Dispose()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Rendering/Culling/CullingObjectsTracker.cs

#LineLine coverage
 1using System.Collections;
 2using System.Linq;
 3using UnityEngine;
 4using Object = UnityEngine.Object;
 5
 6namespace DCL.Rendering
 7{
 8    /// <summary>
 9    /// This class is used for tracking all the renderers, skinnedMeshRenderers and Animations of the world.
 10    ///
 11    /// It currently uses a very lazy FindObjectsOfType approach, but is enough for its purposes as its used
 12    /// to optimize a bigger bottleneck.
 13    /// </summary>
 14    public class CullingObjectsTracker : ICullingObjectsTracker
 15    {
 16        Renderer[] renderers;
 17        SkinnedMeshRenderer[] skinnedRenderers;
 18        Animation[] animations;
 19
 6720        bool dirty = true;
 21        private int ignoredLayersMask;
 22
 6723        public CullingObjectsTracker ()
 24        {
 6725            PoolManager.i.OnGet -= MarkDirty;
 6726            PoolManager.i.OnGet += MarkDirty;
 6727        }
 28
 29        /// <summary>
 30        /// If the dirty flag is true, this coroutine will re-populate all the tracked objects.
 31        /// </summary>
 32        public IEnumerator PopulateRenderersList()
 33        {
 1634            if (!dirty)
 135                yield break;
 36
 1537            renderers = Object.FindObjectsOfType<Renderer>()
 2538                .Where(x => !(x is SkinnedMeshRenderer)
 39                            && !(x is ParticleSystemRenderer)
 40                            && ((1 << x.gameObject.layer) & ignoredLayersMask) == 0)
 41                .ToArray();
 42
 1543            yield return null;
 44
 1145            skinnedRenderers = Object.FindObjectsOfType<SkinnedMeshRenderer>()
 746                .Where(x => ((1 << x.gameObject.layer) & ignoredLayersMask) == 0)
 47                .ToArray();
 48
 1149            yield return null;
 50
 1051            animations = Object.FindObjectsOfType<Animation>();
 52
 1053            dirty = false;
 1054        }
 55
 56        /// <summary>
 57        ///  This will re-populate all the tracked objects in a sync way.
 58        /// </summary>
 59        /// <param name="includeInactives">True for add inactive objects to the tracked list.</param>
 60        public void ForcePopulateRenderersList(bool includeInactives)
 61        {
 6162            renderers = Object.FindObjectsOfType<Renderer>(includeInactives)
 25863                .Where(x => !(x is SkinnedMeshRenderer)
 64                            && !(x is ParticleSystemRenderer)
 65                            && ((1 << x.gameObject.layer) & ignoredLayersMask) == 0)
 66                .ToArray();
 67
 6168            skinnedRenderers = Object.FindObjectsOfType<SkinnedMeshRenderer>(includeInactives)
 069                .Where(x => ((1 << x.gameObject.layer) & ignoredLayersMask) == 0)
 70                .ToArray();
 6171        }
 72
 16273        public void SetIgnoredLayersMask(int ignoredLayersMask) { this.ignoredLayersMask = ignoredLayersMask; }
 74
 75        /// <summary>
 76        /// Sets the dirty flag to true to make PopulateRenderersList retrieve all the scene objects on its next call.
 77        /// </summary>
 275878        public void MarkDirty() { dirty = true; }
 79
 80        /// <summary>
 81        /// Returns true if dirty.
 82        /// </summary>
 83        /// <returns>True if dirty.</returns>
 384        public bool IsDirty() { return dirty; }
 85
 86        /// <summary>
 87        /// Returns the renderers list.
 88        /// </summary>
 89        /// <returns>An array with all the tracked renderers.</returns>
 7290        public Renderer[] GetRenderers() { return renderers; }
 91
 92        /// <summary>
 93        /// Returns the skinned renderers list.
 94        /// </summary>
 95        /// <returns>An array with all the tracked skinned renderers.</returns>
 7296        public SkinnedMeshRenderer[] GetSkinnedRenderers() { return skinnedRenderers; }
 97
 98        /// <summary>
 99        /// Returns the animations list.
 100        /// </summary>
 101        /// <returns>An array with all the tracked animations.</returns>
 66102        public Animation[] GetAnimations() { return animations; }
 103
 104        public void Dispose()
 105        {
 63106            dirty = true;
 63107            renderers = null;
 63108            animations = null;
 63109            skinnedRenderers = null;
 63110            PoolManager.i.OnGet -= MarkDirty;
 63111        }
 112    }
 113}