예제 #1
0
        // #########################################
        #endregion

        #region Process
        // #########################################

        private void StartProcess(MapSceneDataControl mapSceneDataControl)
        {
            if (updatingStorage.ContainsKey(mapSceneDataControl) && updatingStorage[mapSceneDataControl])
            {
                Debug.Log("The data was already being updated!");
                return;
            }

            updatingStorage[mapSceneDataControl] = true;
        }
 public GameplayAreaDataControl(MapSceneDataControl mapSceneDataControl)
 {
     this.mapSceneDataControl = mapSceneDataControl;
     this.mapScene            = mapSceneDataControl.getContent() as MapScene;
     this.gameplayArea        = new GameplayArea
     {
         UsesGameplayArea   = mapScene.UsesGameplayArea,
         BoundingBox        = mapScene.GameplayArea,
         TileMetaIdentifier = mapScene.TileMetaIdentifier
     };
 }
예제 #3
0
        private void RemoveAndDownloadTiles(MapSceneDataControl mapSceneDataControl, System.Action <int, bool> update)
        {
            var current = storageProcesses[mapSceneDataControl];

            var toRemove = current.toRemoveTiles.Keys.ToArray();

            AssetDatabase.StartAssetEditing();
            foreach (var tile in toRemove)
            {
                // Remove the tile
                update(0, RemoveTile(current.toRemoveTiles[tile], tile, current.toRemoveMeta));
            }
            AssetDatabase.StopAssetEditing();

            var toDownload = current.toDownloadTiles.Keys.ToArray();

            current.toStorePromises = new List <ITilePromise>();
            if (toDownload.Length > 0)
            {
                var downloadChunk = toDownload.Length / (float)MaxDownloadSlots;
                for (int i = 0; i < MaxDownloadSlots; i++)
                {
                    // Download the tile
                    DownloadWaterfall(current.toDownloadTiles, mapSceneDataControl, toDownload, current.toDownloadMeta,
                                      Mathf.CeilToInt(i * downloadChunk), Mathf.CeilToInt((i + 1) * downloadChunk), 0,
                                      (currentMapScene, tileIndex, tilePromise, result) =>
                    {
                        var process  = storageProcesses[currentMapScene];
                        var promises = process.toStorePromises;
                        if (!result)
                        {
                            Debug.Log("Failed to download tile " + toDownload[tileIndex]);
                        }
                        update(1, result);
                        promises.Add(tilePromise);
                        if (promises.Count == toDownload.Length)
                        {
                            AssetDatabase.StartAssetEditing();
                            foreach (var promise in promises)
                            {
                                result = StoreTile(process.toDownloadTiles[promise.Tile], promise.Tile,
                                                   promise.Meta, promise);
                                update(2, result);
                            }
                            AssetDatabase.StopAssetEditing();
                        }
                    });
                }
            }
            else
            {
                update(2, true);
            }
        }
        protected override void DrawInspector()
        {
            if (GeoController.Instance.SelectedMapScene != -1 &&
                GeoController.Instance.SelectedMapScene != lastSelectedMapScene)
            {
                lastSelectedMapScene = GeoController.Instance.SelectedMapScene;
                workingMapScene      = GeoController.Instance.MapScenes[lastSelectedMapScene];
                mapElements.SetData(workingMapScene.Elements, e => (e as ListDataControl <MapSceneDataControl, MapElementDataControl>).DataControls.Cast <DataControl>().ToList());
            }

            mapElements.DoList(160);
        }
예제 #5
0
        // #########################################
        private List <AreaMeta> GetAllAreasExcept(MapSceneDataControl mapSceneDataControl)
        {
            var mapScenes = GeoController.Instance.MapScenes;

            auxList[0] = mapSceneDataControl;

            var allAreas = mapScenes.DataControls
                           .Except(auxList) // Except mapSceneDataControl
                           .Where(m => m.GameplayArea.UsesGameplayArea)
                           .Select(m => new AreaMeta(m)).ToList();

            return(allAreas);
        }
 public AreaMeta(MapSceneDataControl mapScene)
     : this(mapScene.GameplayArea.BoundingBox, mapScene.GameplayArea.TileMetaIdentifier)
 {
 }
예제 #7
0
        public void StoreTiles(MapSceneDataControl mapSceneDataControl, bool displayProgressBar, System.Action <bool> callback)
        {
            StartProcess(mapSceneDataControl);

            if (displayProgressBar)
            {
                EditorUtility.DisplayProgressBar("Geo.TileManager.Progress.Title".Traslate(),
                                                 "Geo.TileManager.Calculating".Traslate(), 0);
            }

            var allAreas     = GetAllAreasExcept(mapSceneDataControl);
            var mapScene     = mapSceneDataControl.getContent() as MapScene;
            var previousArea = new AreaMeta(mapScene);
            var newArea      = new AreaMeta(mapSceneDataControl);
            var current      = new StorageProcess();

            storageProcesses[mapSceneDataControl] = current;

            // Get the tile metas to remove or to download if they exist
            current.toRemoveMeta   = TileProvider.Instance.GetTileMeta(mapScene.TileMetaIdentifier);
            current.toDownloadMeta = TileProvider.Instance.GetTileMeta(mapSceneDataControl.GameplayArea.TileMetaIdentifier);

            // We have to remove if there is gameplayArea based on the previous area and we must substract the new area if it's used
            current.toRemoveTiles = GetNonCollidingStorableTiles(mapScene.UsesGameplayArea, allAreas, previousArea,
                                                                 mapSceneDataControl.GameplayArea.UsesGameplayArea, newArea, current.toRemoveMeta);

            // We have to download if there is gameplayArea based on the new area and we must substract the old area if it's used
            current.toDownloadTiles = GetNonCollidingStorableTiles(mapSceneDataControl.GameplayArea.UsesGameplayArea, allAreas,
                                                                   newArea, mapScene.UsesGameplayArea, previousArea, current.toDownloadMeta);

            // In case any of them is null it means that we have no storer to use for any of the tiles
            if (current.toRemoveTiles == null || current.toDownloadTiles == null)
            {
                FinishProcess(mapSceneDataControl);
                callback(false);
                return;
            }

            RemoveAndDownloadTiles(mapSceneDataControl, new ProgressCallback(current.toRemoveTiles.Count + current.toDownloadTiles.Count * 2,
                                                                             (fase, progress, result) =>
            {
                bool cancel = false;
                if (displayProgressBar)
                {
                    if (fase == 0)
                    {
                        EditorUtility.DisplayProgressBar("Geo.TileManager.Progress.Title".Traslate(),
                                                         "Geo.TileManager.Removing".Traslate(), progress.Progress);
                    }
                    else if (fase == 1)
                    {
                        cancel = EditorUtility.DisplayCancelableProgressBar("Geo.TileManager.Progress.Title".Traslate(),
                                                                            "Geo.TileManager.Downloading".Traslate(), progress.Progress);
                    }
                    else if (fase == 2)
                    {
                        cancel = EditorUtility.DisplayCancelableProgressBar("Geo.TileManager.Progress.Title".Traslate(),
                                                                            "Geo.TileManager.Storing".Traslate(), progress.Progress);
                    }
                }

                if ((fase != 0 && !result) || cancel)
                {
                    FinishProcess(mapSceneDataControl);
                    callback(false);
                }

                if (progress.Progress >= 1f)
                {
                    FinishProcess(mapSceneDataControl);
                    callback(true);
                }
            }).Update);
        }
예제 #8
0
 private bool IsFinished(MapSceneDataControl mapSceneDataControl)
 {
     return(!updatingStorage[mapSceneDataControl]);
 }
예제 #9
0
 private void FinishProcess(MapSceneDataControl mapSceneDataControl)
 {
     updatingStorage[mapSceneDataControl] = false;
     EditorUtility.ClearProgressBar();
 }
예제 #10
0
        private void DownloadWaterfall(Dictionary <Vector3d, ITileStorer> tileStorer, MapSceneDataControl mapScene, Vector3d[] tiles,
                                       ITileMeta meta, int index, int endIndex, int tries, System.Action <MapSceneDataControl, int, ITilePromise, bool> finished)
        {
            if (index == endIndex || IsFinished(mapScene))
            {
                return;
            }

            if (tries < 5)
            {
                DownloadTile(tiles[index], meta, tp =>
                {
                    if (tp.Data == null)
                    {
                        Debug.Log("Failed to download the tile" + tiles[index] + ", retrying... (" + tries + ")");
                        DownloadWaterfall(tileStorer, mapScene, tiles, meta, index, endIndex, tries + 1, finished);
                    }
                    else
                    {
                        finished(mapScene, index, tp, true);
                        DownloadWaterfall(tileStorer, mapScene, tiles, meta, index + 1, endIndex, 0, finished);
                    }
                });
            }
            else
            {
                finished(mapScene, index, null, false);
            }
        }