| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using DCL; |
| | 3 | | using DCL.Providers; |
| | 4 | | using DCL.Social.Friends; |
| | 5 | | using DCLServices.MapRendererV2.CoordsUtils; |
| | 6 | | using DCLServices.MapRendererV2.Culling; |
| | 7 | | using DCLServices.MapRendererV2.MapCameraController; |
| | 8 | | using DCLServices.MapRendererV2.MapLayers; |
| | 9 | | using DCLServices.MapRendererV2.MapLayers.Atlas; |
| | 10 | | using DCLServices.MapRendererV2.MapLayers.Atlas.SatelliteAtlas; |
| | 11 | | using DCLServices.MapRendererV2.MapLayers.ParcelHighlight; |
| | 12 | | using DCLServices.PlacesAPIService; |
| | 13 | | using DCLServices.MapRendererV2.MapLayers.SatelliteAtlas; |
| | 14 | | using MainScripts.DCL.Controllers.HotScenes; |
| | 15 | | using MainScripts.DCL.Helpers.Utils; |
| | 16 | | using System.Collections.Generic; |
| | 17 | | using System.Threading; |
| | 18 | | using System.Threading.Tasks; |
| | 19 | | using UnityEngine; |
| | 20 | | using UnityEngine.Pool; |
| | 21 | |
|
| | 22 | | namespace 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 | |
|
| 96 | 39 | | internal ColdUsersMarkersInstaller coldUsersMarkersInstaller { get; } |
| 96 | 40 | | internal SceneOfInterestsMarkersInstaller sceneOfInterestsMarkersInstaller { get; } |
| 96 | 41 | | internal FavoritesMarkersInstaller favoritesMarkersInstaller { get; } |
| 96 | 42 | | internal HomePointMarkerInstaller homePointMarkerInstaller { get; } |
| 96 | 43 | | internal HotUsersMarkersInstaller hotUsersMarkersInstaller { get; } |
| | 44 | |
|
| 96 | 45 | | internal FriendUsersMarkersInstaller friendUsersMarkersInstaller { get; } |
| 96 | 46 | | internal PlayerMarkerInstaller playerMarkerInstaller { get; } |
| | 47 | |
|
| 1391 | 48 | | private IAddressableResourceProvider AddressableProvider => addressablesProvider.Ref; |
| | 49 | |
|
| | 50 | | async UniTask<MapRendererComponents> IMapRendererComponentsFactory.Create(CancellationToken cancellationToken) |
| | 51 | | { |
| 99 | 52 | | MapRendererConfiguration configuration = Object.Instantiate(await AddressableProvider.GetAddressable<MapRend |
| 97 | 53 | | var coordsUtils = new ChunkCoordsUtils(PARCEL_SIZE); |
| 97 | 54 | | IMapCullingController cullingController = new MapCullingController(new MapCullingRectVisibilityChecker(CULLI |
| 97 | 55 | | var layers = new Dictionary<MapLayer, IMapLayerController>(); |
| 97 | 56 | | var zoomScalingLayers = new List<IZoomScalingLayer>(); |
| | 57 | |
|
| 99 | 58 | | ParcelHighlightMarkerObject highlightMarkerPrefab = await GetParcelHighlightMarkerPrefab(cancellationToken); |
| 97 | 59 | | var highlightMarkersPool = new ObjectPool<IParcelHighlightMarker>( |
| 97 | 60 | | () => CreateHighlightMarker(highlightMarkerPrefab, configuration, coordsUtils), |
| 97 | 61 | | _ => { }, |
| 97 | 62 | | marker => marker.Deactivate(), |
| 0 | 63 | | marker => marker.Dispose() |
| | 64 | | ); |
| 97 | 65 | | highlightMarkersPool.Prewarm(1); |
| | 66 | |
|
| 101 | 67 | | MapCameraObject mapCameraObjectPrefab = await AddressableProvider.GetAddressable<MapCameraObject>(MAP_CAMERA |
| 96 | 68 | | IObjectPool<IMapCameraControllerInternal> cameraControllersPool = new ObjectPool<IMapCameraControllerInterna |
| | 69 | | CameraControllerBuilder, |
| 0 | 70 | | x => x.SetActive(true), |
| 0 | 71 | | x => x.SetActive(false), |
| 0 | 72 | | x => x.Dispose() |
| | 73 | | ); |
| | 74 | |
|
| 288 | 75 | | 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 | |
|
| 88 | 87 | | return new MapRendererComponents(configuration, layers, zoomScalingLayers, cullingController, cameraControll |
| | 88 | |
|
| | 89 | | IMapCameraControllerInternal CameraControllerBuilder() |
| | 90 | | { |
| 0 | 91 | | MapCameraObject instance = Object.Instantiate(mapCameraObjectPrefab, configuration.MapCamerasRoot); |
| 0 | 92 | | var interactivityController = new MapCameraInteractivityController(configuration.MapCamerasRoot, instanc |
| | 93 | |
|
| 0 | 94 | | return new MapCameraController.MapCameraController(interactivityController, instance, coordsUtils, culli |
| | 95 | | } |
| 88 | 96 | | } |
| | 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 | |
|
| 96 | 103 | | var chunkAtlas = new SatelliteChunkAtlasController(configuration.SatelliteAtlasRoot, GRID_SIZE, PARCELS_INSI |
| | 104 | |
|
| | 105 | | // initialize Atlas but don't block the flow (to accelerate loading time) |
| 96 | 106 | | chunkAtlas.Initialize(cancellationToken).SuppressCancellationThrow().Forget(); |
| | 107 | |
|
| 96 | 108 | | layers.Add(MapLayer.SatelliteAtlas, chunkAtlas); |
| 96 | 109 | | return; |
| | 110 | |
|
| | 111 | | async UniTask<IChunkController> CreateSatelliteChunk(Vector3 chunkLocalPosition, Vector2Int chunkId, Transfo |
| | 112 | | { |
| 560 | 113 | | SpriteRenderer atlasChunkPrefab = await GetAtlasChunkPrefab(ct); |
| | 114 | |
|
| 550 | 115 | | var chunk = new SatelliteChunkController(atlasChunkPrefab, chunkLocalPosition, chunkId, parent, MapRende |
| 1650 | 116 | | await chunk.LoadImage(chunkId, PARCELS_INSIDE_CHUNK * coordsUtils.ParcelSize, ct); |
| | 117 | |
|
| 81 | 118 | | return chunk; |
| 81 | 119 | | } |
| 96 | 120 | | } |
| | 121 | |
|
| | 122 | | private async UniTask CreateAtlas(Dictionary<MapLayer, IMapLayerController> layers, MapRendererConfiguration con |
| | 123 | | { |
| 96 | 124 | | 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) |
| 96 | 127 | | chunkAtlas.Initialize(cancellationToken).SuppressCancellationThrow().Forget(); |
| | 128 | |
|
| 96 | 129 | | layers.Add(MapLayer.ParcelsAtlas, chunkAtlas); |
| 96 | 130 | | return; |
| | 131 | |
|
| | 132 | | async UniTask<IChunkController> CreateChunk(Vector3 chunkLocalPosition, Vector2Int coordsCenter, Transform p |
| | 133 | | { |
| 560 | 134 | | SpriteRenderer atlasChunkPrefab = await GetAtlasChunkPrefab(ct); |
| | 135 | |
|
| 550 | 136 | | var chunk = new ParcelChunkController(atlasChunkPrefab, chunkLocalPosition, coordsCenter, parent); |
| 550 | 137 | | chunk.SetDrawOrder(MapRendererDrawOrder.ATLAS); |
| 1650 | 138 | | await chunk.LoadImage(ATLAS_CHUNK_SIZE, PARCEL_SIZE, coordsCenter, ct); |
| | 139 | |
|
| 70 | 140 | | return chunk; |
| 70 | 141 | | } |
| 96 | 142 | | } |
| | 143 | |
|
| | 144 | | private static IParcelHighlightMarker CreateHighlightMarker(ParcelHighlightMarkerObject highlightMarkerPrefab, |
| | 145 | | MapRendererConfiguration configuration, ICoordsUtils coordsUtils) |
| | 146 | | { |
| 97 | 147 | | ParcelHighlightMarkerObject obj = Object.Instantiate(highlightMarkerPrefab, configuration.ParcelHighlightRoo |
| | 148 | |
|
| 97 | 149 | | obj.spriteRenderer.sortingOrder = MapRendererDrawOrder.PARCEL_HIGHLIGHT; |
| 97 | 150 | | obj.text.sortingOrder = MapRendererDrawOrder.PARCEL_HIGHLIGHT; |
| 97 | 151 | | coordsUtils.SetObjectScale(obj); |
| | 152 | |
|
| 97 | 153 | | return new ParcelHighlightMarker(obj); |
| | 154 | | } |
| | 155 | |
|
| | 156 | | internal async Task<SpriteRenderer> GetAtlasChunkPrefab(CancellationToken cancellationToken) => |
| 1120 | 157 | | await AddressableProvider.GetAddressable<SpriteRenderer>(ATLAS_CHUNK_ADDRESS, cancellationToken); |
| | 158 | |
|
| | 159 | | private async UniTask<ParcelHighlightMarkerObject> GetParcelHighlightMarkerPrefab(CancellationToken cancellation |
| 99 | 160 | | await AddressableProvider.GetAddressable<ParcelHighlightMarkerObject>(PARCEL_HIGHLIGHT_OBJECT_ADDRESS, cance |
| | 161 | | } |
| | 162 | | } |