Exemplo n.º 1
0
        public void DownloadChunks()
        {
            logger.LogTechState("Downloading chunk data...");
            const int maxFails = 5;

            Parallel.ForEach(chunks, chunkXY =>
            {
                int fails;
                bool success = false;
                do
                {
                    fails = 0;
                    try
                    {
                        logger.LogDebug($"DownloadChunks(): chunk {chunkXY}");
                        byte[] data = GetChunkData(chunkXY, (byte)canvas);
                        BinaryConversion.DropPixelProtectionInfo(data);
                        SaveChunk(chunkXY, data);
                        success = true;
                    }
                    catch (Exception ex)
                    {
                        logger.LogDebug($"DownloadChunks(): error - {ex}");
                        if (++fails == maxFails)
                        {
                            fails = 0;
                            Thread.Sleep(TimeSpan.FromSeconds(30));
                            break;
                        }
                    }
                } while (!success);
            });
            logger.LogTechInfo("Chunk data is downloaded");
            OnMapUpdated?.Invoke(this, null);
        }
Exemplo n.º 2
0
 private void Wrapper_OnConnectionRestored(object sender, ConnectionRestoredEventArgs e)
 {
     logger.LogDebug($"Wrapper_OnConnectionRestored(): {e.OfflinePeriod.TotalSeconds:F2} seconds offline");
     if (e.OfflinePeriod > maxOffline)
     {
         DownloadChunks();
     }
     else
     {
         OnMapUpdated?.Invoke(this, null);
     }
 }
        public void RenderDungeonMap(MapGrid map, float roomSize, float roadLength)
        {
            Assert.IsNotNull(tilemap);
            Assert.IsNotNull(roadTile);
            Assert.IsNotNull(roomTile);

            this.roomSize   = Convert.ToInt32(roomSize);
            this.roadLength = Convert.ToInt32(roadLength);
            tilemap.ClearAllTiles();
            foreach (var level in map.Levels)
            {
                RenderLevel(level);
            }
            OnMapUpdated?.Invoke(tilemap);

            Debug.Log($"Tilemap size is {tilemap.size.x} x {tilemap.size.y}, with cell size {tilemap.cellSize.x}x{tilemap.cellSize.y}");
        }
Exemplo n.º 4
0
        public void DownloadChunks()
        {
            logger.LogTechState("Downloading chunk data...");
            const int maxFails = 5;

            Parallel.ForEach(chunks, chunkXY =>
            {
                int fails;
                bool success = false;
                do
                {
                    fails = 0;
                    try
                    {
                        logger.LogDebug($"DownloadChunks(): downloading chunk {chunkXY}");
                        byte[] data = HttpWrapper.GetChunkData(chunkXY);
                        BinaryConversion.DropPixelProtectionInfo(data);
                        CachedChunks[chunkXY] = BinaryConversion.ToColorRectangle(data, PixelMap.ChunkSideSize, PixelMap.ChunkSideSize);
                        logger.LogDebug($"DownloadChunks(): downloaded chunk  {chunkXY}");
                        success = true;
                    }
                    catch (Exception ex)
                    {
                        logger.LogDebug($"DownloadChunks(): error - {ex.Message}");
                        if (++fails == maxFails)
                        {
                            fails = 0;
                            logger.LogDebug($"DownloadChunks(): {maxFails} fails in row, pause 30s");
                            Thread.Sleep(TimeSpan.FromSeconds(30));
                            break;
                        }
                    }
                } while (!success);
            });
            logger.LogTechInfo("Chunk data is downloaded");
            OnMapUpdated?.Invoke(this, null);
        }