/// <summary> /// Translates virtual texture address to physical rectangle in physical texture. /// </summary> /// <param name="address"></param> /// <param name="rectangle"></param> /// <returns>False if address is not presented in cache</returns> public bool TranslateAddress(VTAddress address, VTTile tile, out Rectangle rectangle) { Page page; if (cache.TryGetValue(address, out page)) { var pa = page.Address; var ppc = pageCount; var size = VTConfig.PageSizeBordered; int x = (pa % ppc) * size; int y = (pa / ppc) * size; int w = size; int h = size; rectangle = new Rectangle(x, y, w, h); page.Tile = tile; return(true); } else { rectangle = new Rectangle(); return(false); } }
/// <summary> /// Functionas running in separate thread /// </summary> void LoaderTask() { while (!stopLoader) { VTAddress address; #if USE_PRIORITY_QUEUE address = default(VTAddress); KeyValuePair <int, VTAddress> result; if (!requestQueue.TryDequeue(out result)) { //Thread.Sleep(1); continue; } else { address = result.Value; } #else if (!requestQueue.TryDequeue(out address)) { //Thread.Sleep(1); continue; } #endif var fileName = address.GetFileNameWithoutExtension(".tile"); //Log.Message("...vt tile load : {0}", fileName ); try { var tile = new VTTile(address); tile.Read(storage.OpenFile(fileName, FileMode.Open, FileAccess.Read)); loadedTiles.Enqueue(tile); } catch (IOException ioex) { var tile = new VTTile(address); tile.Clear(Color.Magenta); loadedTiles.Enqueue(tile); Log.Warning("{0}", ioex); } } }
/// <summary> /// Gets loaded tile or zero /// </summary> /// <returns></returns> public bool TryGetTile(out VTTile image) { return(loadedTiles.TryDequeue(out image)); }
/// <summary> /// Add tile to stamp queue /// </summary> /// <param name="tile"></param> /// <param name="rect"></param> public void Add(VTTile tile, Rectangle rect) { stamps[rect] = new Stamp(tile, rect); }
/// <summary> /// /// </summary> /// <param name="tile"></param> /// <param name="rect"></param> public Stamp(VTTile tile, Rectangle rect) { this.Tile = tile; this.Rectangle = rect; }