< Summary

Class:DCLServices.MapRendererV2.ComponentsFactory.MapRendererChunkComponentsFactory
Assembly:MapRendererV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLServices/MapRendererV2/ComponentsFactory/MapRendererChunkComponentsFactory.cs
Covered lines:52
Uncovered lines:7
Coverable lines:59
Total lines:162
Line coverage:88.1% (52 of 59)
Covered branches:0
Total branches:0
Covered methods:16
Total methods:16
Method coverage:100% (16 of 16)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
DCLServices-MapRendererV2-ComponentsFactory-IMapRendererComponentsFactory-Create()0%15150100%
CreateSatelliteAtlas()0%110100%
>c__DisplayClass33_0/<<CreateSatelliteAtlas()0%550100%
CreateAtlas()0%110100%
<CreateAtlas()0%550100%
CreateHighlightMarker(...)0%110100%
GetAtlasChunkPrefab()0%330100%
GetParcelHighlightMarkerPrefab()0%330100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLServices/MapRendererV2/ComponentsFactory/MapRendererChunkComponentsFactory.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCL;
 3using DCL.Providers;
 4using DCL.Social.Friends;
 5using DCLServices.MapRendererV2.CoordsUtils;
 6using DCLServices.MapRendererV2.Culling;
 7using DCLServices.MapRendererV2.MapCameraController;
 8using DCLServices.MapRendererV2.MapLayers;
 9using DCLServices.MapRendererV2.MapLayers.Atlas;
 10using DCLServices.MapRendererV2.MapLayers.Atlas.SatelliteAtlas;
 11using DCLServices.MapRendererV2.MapLayers.ParcelHighlight;
 12using DCLServices.PlacesAPIService;
 13using DCLServices.MapRendererV2.MapLayers.SatelliteAtlas;
 14using MainScripts.DCL.Controllers.HotScenes;
 15using MainScripts.DCL.Helpers.Utils;
 16using System.Collections.Generic;
 17using System.Threading;
 18using System.Threading.Tasks;
 19using UnityEngine;
 20using UnityEngine.Pool;
 21
 22namespace DCLServices.MapRendererV2.ComponentsFactory
 23{
 24    public class MapRendererChunkComponentsFactory : IMapRendererComponentsFactory
 25    {
 26        private const int ATLAS_CHUNK_SIZE = 1020;
 27        private const int PARCEL_SIZE = 20;
 28        // it is quite expensive to disable TextMeshPro so larger bounds should help keeping the right balance
 29        private const float CULLING_BOUNDS_IN_PARCELS = 10;
 30
 31        private const string ATLAS_CHUNK_ADDRESS = "AtlasChunk";
 32        private const string MAP_CONFIGURATION_ADDRESS = "MapRendererConfiguration";
 33        private const string MAP_CAMERA_OBJECT_ADDRESS = "MapCameraObject";
 34        private const string PARCEL_HIGHLIGHT_OBJECT_ADDRESS = "MapParcelHighlightMarker";
 35
 36        private Service<IAddressableResourceProvider> addressablesProvider;
 37        private Service<IHotScenesFetcher> hotScenesFetcher;
 38
 9639        internal ColdUsersMarkersInstaller coldUsersMarkersInstaller { get; }
 9640        internal SceneOfInterestsMarkersInstaller sceneOfInterestsMarkersInstaller { get; }
 9641        internal FavoritesMarkersInstaller favoritesMarkersInstaller { get; }
 9642        internal HomePointMarkerInstaller homePointMarkerInstaller { get; }
 9643        internal HotUsersMarkersInstaller hotUsersMarkersInstaller { get; }
 44
 9645        internal FriendUsersMarkersInstaller friendUsersMarkersInstaller { get; }
 9646        internal PlayerMarkerInstaller playerMarkerInstaller { get; }
 47
 139148        private IAddressableResourceProvider AddressableProvider => addressablesProvider.Ref;
 49
 50        async UniTask<MapRendererComponents> IMapRendererComponentsFactory.Create(CancellationToken cancellationToken)
 51        {
 9952            MapRendererConfiguration configuration = Object.Instantiate(await AddressableProvider.GetAddressable<MapRend
 9753            var coordsUtils = new ChunkCoordsUtils(PARCEL_SIZE);
 9754            IMapCullingController cullingController = new MapCullingController(new MapCullingRectVisibilityChecker(CULLI
 9755            var layers = new Dictionary<MapLayer, IMapLayerController>();
 9756            var zoomScalingLayers = new List<IZoomScalingLayer>();
 57
 9958            ParcelHighlightMarkerObject highlightMarkerPrefab = await GetParcelHighlightMarkerPrefab(cancellationToken);
 9759            var highlightMarkersPool = new ObjectPool<IParcelHighlightMarker>(
 9760                () => CreateHighlightMarker(highlightMarkerPrefab, configuration, coordsUtils),
 9761                _ => { },
 9762                marker => marker.Deactivate(),
 063                marker => marker.Dispose()
 64            );
 9765            highlightMarkersPool.Prewarm(1);
 66
 10167            MapCameraObject mapCameraObjectPrefab = await AddressableProvider.GetAddressable<MapCameraObject>(MAP_CAMERA
 9668            IObjectPool<IMapCameraControllerInternal> cameraControllersPool = new ObjectPool<IMapCameraControllerInterna
 69                CameraControllerBuilder,
 070                x => x.SetActive(true),
 071                x => x.SetActive(false),
 072                x => x.Dispose()
 73            );
 74
 28875            await UniTask.WhenAll(
 76                CreateAtlas(layers, configuration, coordsUtils, cullingController, cancellationToken),
 77                CreateSatelliteAtlas(layers, configuration, coordsUtils, cullingController, cancellationToken),
 78                coldUsersMarkersInstaller.Install(layers, configuration, coordsUtils, cullingController, cancellationTok
 79                sceneOfInterestsMarkersInstaller.Install(layers, zoomScalingLayers, configuration, coordsUtils, cullingC
 80                playerMarkerInstaller.Install(layers, zoomScalingLayers, configuration, coordsUtils, cullingController, 
 81                homePointMarkerInstaller.Install(layers, zoomScalingLayers, configuration, coordsUtils, cullingControlle
 82                favoritesMarkersInstaller.Install(layers, zoomScalingLayers, configuration, coordsUtils, cullingControll
 83                hotUsersMarkersInstaller.Install(layers, configuration, coordsUtils, cullingController, cancellationToke
 84                friendUsersMarkersInstaller.Install(layers, zoomScalingLayers, configuration, coordsUtils, cullingContro
 85                /* List of other creators that can be executed in parallel */);
 86
 8887            return new MapRendererComponents(configuration, layers, zoomScalingLayers, cullingController, cameraControll
 88
 89            IMapCameraControllerInternal CameraControllerBuilder()
 90            {
 091                MapCameraObject instance = Object.Instantiate(mapCameraObjectPrefab, configuration.MapCamerasRoot);
 092                var interactivityController = new MapCameraInteractivityController(configuration.MapCamerasRoot, instanc
 93
 094                return new MapCameraController.MapCameraController(interactivityController, instance, coordsUtils, culli
 95            }
 8896        }
 97
 98        private async UniTask CreateSatelliteAtlas(Dictionary<MapLayer, IMapLayerController> layers, MapRendererConfigur
 99        {
 100            const int GRID_SIZE = 8; // satellite images are provided by 8x8 grid.
 101            const int PARCELS_INSIDE_CHUNK = 40; // One satellite image contains 40 parcels.
 102
 96103            var chunkAtlas = new SatelliteChunkAtlasController(configuration.SatelliteAtlasRoot, GRID_SIZE, PARCELS_INSI
 104
 105            // initialize Atlas but don't block the flow (to accelerate loading time)
 96106            chunkAtlas.Initialize(cancellationToken).SuppressCancellationThrow().Forget();
 107
 96108            layers.Add(MapLayer.SatelliteAtlas, chunkAtlas);
 96109            return;
 110
 111            async UniTask<IChunkController> CreateSatelliteChunk(Vector3 chunkLocalPosition, Vector2Int chunkId, Transfo
 112            {
 560113                SpriteRenderer atlasChunkPrefab = await GetAtlasChunkPrefab(ct);
 114
 550115                var chunk = new SatelliteChunkController(atlasChunkPrefab, chunkLocalPosition, chunkId, parent, MapRende
 1650116                await chunk.LoadImage(chunkId, PARCELS_INSIDE_CHUNK * coordsUtils.ParcelSize, ct);
 117
 81118                return chunk;
 81119            }
 96120        }
 121
 122        private async UniTask CreateAtlas(Dictionary<MapLayer, IMapLayerController> layers, MapRendererConfiguration con
 123        {
 96124            var chunkAtlas = new ParcelChunkAtlasController(configuration.AtlasRoot, ATLAS_CHUNK_SIZE, coordsUtils, cull
 125
 126            // initialize Atlas but don't block the flow (to accelerate loading time)
 96127            chunkAtlas.Initialize(cancellationToken).SuppressCancellationThrow().Forget();
 128
 96129            layers.Add(MapLayer.ParcelsAtlas, chunkAtlas);
 96130            return;
 131
 132            async UniTask<IChunkController> CreateChunk(Vector3 chunkLocalPosition, Vector2Int coordsCenter, Transform p
 133            {
 560134                SpriteRenderer atlasChunkPrefab = await GetAtlasChunkPrefab(ct);
 135
 550136                var chunk = new ParcelChunkController(atlasChunkPrefab, chunkLocalPosition, coordsCenter, parent);
 550137                chunk.SetDrawOrder(MapRendererDrawOrder.ATLAS);
 1650138                await chunk.LoadImage(ATLAS_CHUNK_SIZE, PARCEL_SIZE, coordsCenter, ct);
 139
 70140                return chunk;
 70141            }
 96142        }
 143
 144        private static IParcelHighlightMarker CreateHighlightMarker(ParcelHighlightMarkerObject highlightMarkerPrefab,
 145            MapRendererConfiguration configuration, ICoordsUtils coordsUtils)
 146        {
 97147            ParcelHighlightMarkerObject obj = Object.Instantiate(highlightMarkerPrefab, configuration.ParcelHighlightRoo
 148
 97149            obj.spriteRenderer.sortingOrder = MapRendererDrawOrder.PARCEL_HIGHLIGHT;
 97150            obj.text.sortingOrder = MapRendererDrawOrder.PARCEL_HIGHLIGHT;
 97151            coordsUtils.SetObjectScale(obj);
 152
 97153            return new ParcelHighlightMarker(obj);
 154        }
 155
 156        internal async Task<SpriteRenderer> GetAtlasChunkPrefab(CancellationToken cancellationToken) =>
 1120157            await AddressableProvider.GetAddressable<SpriteRenderer>(ATLAS_CHUNK_ADDRESS, cancellationToken);
 158
 159        private async UniTask<ParcelHighlightMarkerObject> GetParcelHighlightMarkerPrefab(CancellationToken cancellation
 99160            await AddressableProvider.GetAddressable<ParcelHighlightMarkerObject>(PARCEL_HIGHLIGHT_OBJECT_ADDRESS, cance
 161    }
 162}