Exemplo n.º 1
0
        void LoadThread()
        {
            using (var pool = new MonoTouch.Foundation.NSAutoreleasePool()) {
                while (_continueWorkingInBackground)
                {
                    TileCollectionItem q = null;
                    lock (_loadingTiles) {
                        q = _loadingTiles.GetHighestPriority();
                    }

                    if (q == null)
                    {
                        _wakeupLoader.WaitOne(TimeSpan.FromSeconds(5));
                    }
                    else
                    {
                        var req = q.Name;

                        try {
                            var filename = GetTilePath(req);
                            using (var image = UIImage.FromFileUncached(filename)) {
                                if (image != null)
                                {
                                    var data = TextureData.FromUIImage(image);
                                    lock (_loadedTiles) {
                                        _loadedTiles[req] = data;
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("! Failed to load " + req);
                                    throw new Exception();
                                }
                            }
                        }
                        catch (Exception) {
                            //
                            // If there was an error loading the tile, then it
                            // must be bad. Redownload it.
                            //
                            lock (_onDiskTiles) {
                                _onDiskTiles.Remove(req);
                            }
                        }
                        finally {
                            lock (_loadingTiles) {
                                _loadingTiles.Remove(req);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public TileCollectionItem GetHighestPriority()
        {
            TileCollectionItem tile = null;

            foreach (var t in _tiles.Values)
            {
                if (tile == null || t.Priority < tile.Priority)
                {
                    tile = t;
                }
            }
            return(tile);
        }
Exemplo n.º 3
0
 public T this[TileName name] {
     get {
         TileCollectionItem t = null;
         if (_tiles.TryGetValue(GetId(name), out t))
         {
             t.Priority = _nextPriority++;
             return((T)t.Value);
         }
         else
         {
             return(default(T));
         }
     }
     set {
         var t = new TileCollectionItem()
         {
             Priority = _nextPriority++,
             Name     = name.Clone(),
             Value    = value
         };
         _tiles[GetId(name)] = t;
     }
 }