using OpenMetaverse; using System; using System.Collections.Concurrent; using System.Collections.Generic; namespace Raindrop.Map.Model { /// /// API to retrieve, delete, modify, create MapTiles in the scene /// public class MapTilesRAM { //number of tiles that are in the scene. public int visibleCount => sceneTiles.Count; int poolSize => pool.Count; //tiles that are in the scene. private Dictionary sceneTiles = new Dictionary(); private MapTilesPool pool; private ConcurrentQueue readyForDecode_DataQueue; public MapTilesRAM(int poolSize, ConcurrentQueue receivedDataQueue) { pool = new MapTilesPool(poolSize); } /// /// push a tile into visible scene, at a specific handle location. /// /// location in grid coordinates * 256 /// the map data public void setTile(ulong handle, MapTile tile) { sceneTiles.Add(handle, tile); } /// /// gets a maptile, if it is present /// /// the region handle of the tile to get ; gridCoords * 256 and pack X&Y together. /// Tile public bool tryGetTile_RAM(ulong handle, out MapTile tile) { // MapTile tile = null; bool success = sceneTiles.TryGetValue(handle, out tile); return success; } /// /// creates a blank maptile at a grid handle. /// /// the region handle of the tile to get ; gridCoords * 256 and pack X&Y together. /// Tile public MapTile setEmptyTile(ulong handle) { MapTile tile = pool.acquireTile(); sceneTiles.Add(handle, tile); return tile; } /// /// Returns a Region to the pool. -- EG not visible anymore /// /// the region handle public void deprecateTile(ulong handle) { MapTile maptile; sceneTiles.TryGetValue(handle, out maptile); if (maptile == null) { throw new Exception("Tile not found when trying to deprecate tile."); } else { sceneTiles.Remove(handle); pool.releaseTile(maptile); } } } }