< Summary

Class:DCLServices.MapRendererV2.MapLayers.SatelliteAtlas.SatelliteChunkAtlasController
Assembly:MapRendererV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLServices/MapRendererV2/MapLayers/Atlas/SatelliteAtlas/SatelliteChunkAtlasController.cs
Covered lines:29
Uncovered lines:7
Coverable lines:36
Total lines:103
Line coverage:80.5% (29 of 36)
Covered branches:0
Total branches:0
Covered methods:5
Total methods:6
Method coverage:83.3% (5 of 6)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SatelliteChunkAtlasController(...)0%110100%
Initialize()0%109076.92%
SatelliteMapOffset()0%110100%
Enable(...)0%2100%
Disable(...)0%110100%
DisposeImpl()0%2.152066.67%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLServices/MapRendererV2/MapLayers/Atlas/SatelliteAtlas/SatelliteChunkAtlasController.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCLServices.MapRendererV2.CoordsUtils;
 3using DCLServices.MapRendererV2.Culling;
 4using DCLServices.MapRendererV2.MapCameraController;
 5using DCLServices.MapRendererV2.MapLayers.Atlas;
 6using System;
 7using System.Collections.Generic;
 8using System.Threading;
 9using UnityEngine;
 10
 11namespace DCLServices.MapRendererV2.MapLayers.SatelliteAtlas
 12{
 13    internal class SatelliteChunkAtlasController : MapLayerControllerBase, IAtlasController
 14    {
 15        public delegate UniTask<IChunkController> ChunkBuilder(Vector3 chunkLocalPosition, Vector2Int coordsCenter, Tran
 16
 17        private const int CHUNKS_CREATED_PER_BATCH = 5;
 18
 19        private readonly int gridSize;
 20        private readonly int parcelsInsideChunk;
 21
 22        private readonly ChunkBuilder chunkBuilder;
 23        private readonly List<IChunkController> chunks;
 24
 25        public SatelliteChunkAtlasController(Transform parent, int gridSize, int parcelsInsideChunk, ICoordsUtils coords
 9626            : base(parent, coordsUtils, cullingController)
 27        {
 9628            this.gridSize = gridSize;
 9629            this.parcelsInsideChunk = parcelsInsideChunk;
 9630            this.chunkBuilder = chunkBuilder;
 31
 9632            var chunkAmounts = new Vector2Int(gridSize, gridSize);
 9633            chunks = new List<IChunkController>(chunkAmounts.x * chunkAmounts.y);
 9634        }
 35
 36        public async UniTask Initialize(CancellationToken ct)
 37        {
 9638            int chunkSpriteSize = parcelsInsideChunk * coordsUtils.ParcelSize;
 9639            Vector3 offset = SatelliteMapOffset();
 40
 9641            CancellationToken linkedCt = CancellationTokenSource.CreateLinkedTokenSource(ctsDisposing.Token, ct).Token;
 42
 9643            var chunksCreating = new List<UniTask<IChunkController>>(CHUNKS_CREATED_PER_BATCH);
 44
 21645            for (var i = 0; i < gridSize; i++)
 46            {
 10847                float x = offset.x + (chunkSpriteSize * i);
 48
 131649                for (var j = 0; j < gridSize; j++)
 50                {
 64651                    float y = offset.y - (chunkSpriteSize * j);
 52
 64653                    if (chunksCreating.Count >= CHUNKS_CREATED_PER_BATCH)
 54                    {
 33055                        chunks.AddRange(await UniTask.WhenAll(chunksCreating));
 1456                        chunksCreating.Clear();
 57                    }
 58
 55059                    var localPosition = new Vector3(x, y, 0);
 60
 55061                    UniTask<IChunkController> instance = chunkBuilder.Invoke(chunkLocalPosition: localPosition, new Vect
 55062                    chunksCreating.Add(instance);
 63                }
 64            }
 65
 066            if (chunksCreating.Count >= 0)
 67            {
 068                chunks.AddRange(await UniTask.WhenAll(chunksCreating));
 069                chunksCreating.Clear();
 70            }
 071        }
 72
 73        private Vector3 SatelliteMapOffset()
 74        {
 75            // World minimum plus half size of the chunk to get position (in parcels units) for the center of first chun
 9676            Vector2Int topLeftCornerChunkCenter = coordsUtils.WorldMinCoords + new Vector2Int(parcelsInsideChunk / 2, pa
 77            // offset by (3,2) parcels because Satellite image has border parcels outside of the world
 9678            topLeftCornerChunkCenter = new Vector2Int(topLeftCornerChunkCenter.x - 3, Math.Abs(topLeftCornerChunkCenter.
 79
 9680            return coordsUtils.CoordsToPosition(topLeftCornerChunkCenter);
 81        }
 82
 83        UniTask IMapLayerController.Enable(CancellationToken cancellationToken)
 84        {
 085            instantiationParent.gameObject.SetActive(true);
 086            return UniTask.CompletedTask;
 87        }
 88
 89        UniTask IMapLayerController.Disable(CancellationToken cancellationToken)
 90        {
 8891            instantiationParent.gameObject.SetActive(false);
 8892            return UniTask.CompletedTask;
 93        }
 94
 95        protected override void DisposeImpl()
 96        {
 1297            foreach (IChunkController chunk in chunks)
 098                chunk.Dispose();
 99
 6100            chunks.Clear();
 6101        }
 102    }
 103}