Example #1
0
 public void ClearAllLevels()
 {
     Lock.AcquireWriterLock();
     try
     {
         foreach (var matrix in Levels)
         {
             foreach (var t in matrix)
             {
                 t.Value.Dispose();
             }
             matrix.Clear();
         }
     }
     finally
     {
         Lock.ReleaseWriterLock();
     }
 }
Example #2
0
File: Core.cs Project: ralex1975/zq
        /// <summary>
        /// updates map bounds
        /// </summary>
        void UpdateBounds()
        {
            if (!IsStarted || Provider.Equals(EmptyProvider.Instance))
            {
                return;
            }

            updatingBounds = true;

            tileDrawingListLock.AcquireWriterLock();
            try
            {
                #region -- find tiles around --
                tileDrawingList.Clear();

                for (long i = -sizeOfMapArea.Width; i <= sizeOfMapArea.Width; i++)
                {
                    for (long j = -sizeOfMapArea.Height; j <= sizeOfMapArea.Height; j++)
                    {
                        GPoint p = centerTileXYLocation;
                        p.X += i;
                        p.Y += j;

#if ContinuesMap
                        // ----------------------------
                        if (p.X < minOfTiles.Width)
                        {
                            p.X += (maxOfTiles.Width + 1);
                        }

                        if (p.X > maxOfTiles.Width)
                        {
                            p.X -= (maxOfTiles.Width + 1);
                        }
                        // ----------------------------
#endif

                        if (p.X >= minOfTiles.Width && p.Y >= minOfTiles.Height && p.X <= maxOfTiles.Width && p.Y <= maxOfTiles.Height)
                        {
                            DrawTile dt = new DrawTile(p, new GPoint(p.X * tileRect.Width, p.Y * tileRect.Height));

                            if (!tileDrawingList.Contains(dt))
                            {
                                tileDrawingList.Add(dt);

                                //Debug.WriteLine("draw: " + dt);
                            }
                        }
                    }
                }

                if (CFMaps.Instance.ShuffleTilesOnLoad)
                {
                    Stuff.Shuffle <DrawTile>(tileDrawingList);
                }
                #endregion
            }
            finally
            {
                tileDrawingListLock.ReleaseWriterLock();
            }

            Monitor.Enter(tileLoadQueue);
            try
            {
                tileDrawingListLock.AcquireReaderLock();
                try
                {
                    foreach (DrawTile p in tileDrawingList)
                    {
                        LoadTask task = new LoadTask(p.PosXY, Zoom);
                        {
                            if (!tileLoadQueue.Contains(task))
                            {
                                tileLoadQueue.Push(task);
                            }
                        }
                    }
                }
                finally
                {
                    tileDrawingListLock.ReleaseReaderLock();
                }

                #region -- starts loader threads if needed --

                lock (GThreadPool)
                {
                    while (GThreadPool.Count < GThreadPoolSize)
                    {
                        Thread t = new Thread(new ThreadStart(ProcessLoadTask));
                        {
                            t.Name         = "TileLoader: " + GThreadPool.Count;
                            t.IsBackground = true;
                            t.Priority     = ThreadPriority.BelowNormal;
                        }
                        GThreadPool.Add(t);

                        Debug.WriteLine("add " + t.Name + " to GThreadPool");

                        t.Start();
                    }
                }
                #endregion

                {
                    LastTileLoadStart = DateTime.Now;
                    Debug.WriteLine("OnTileLoadStart - at zoom " + Zoom + ", time: " + LastTileLoadStart.TimeOfDay);
                }

                loadWaitCount = 0;
                Monitor.PulseAll(tileLoadQueue);
            }
            finally
            {
                Monitor.Exit(tileLoadQueue);
            }

            updatingBounds = false;

            if (OnTileLoadStart != null)
            {
                OnTileLoadStart();
            }
        }