/// <summary>Creates a populated <see cref="Collection{T}"/> of <see cref="Landmark"/> /// instances.</summary> /// <param name="board">The board on which the collection of landmarks is to be instantiated.</param> /// <param name="landmarkCoords">Board coordinates of the desired landmarks</param> public static ILandmarkCollection CreateLandmarks( IHexBoard <IHex> board, IFastList <HexCoords> landmarkCoords ) { if (landmarkCoords == null) { throw new ArgumentNullException("landmarkCoords"); } ILandmarkCollection tempLandmarks = null, landmarks = null; try { tempLandmarks = new LandmarkCollection(( from coords in landmarkCoords.AsParallel().AsOrdered() where board.IsOnboard(coords) select new Landmark(coords, board) ).ToList <ILandmark>()); landmarks = tempLandmarks; tempLandmarks = null; } finally { if (tempLandmarks != null) { tempLandmarks.Dispose(); } } return(landmarks); }
/// <summary>TODO</summary> /// <param name="board"></param> /// <param name="landmarkCoords"></param> /// <param name="token"></param> /// <returns></returns> public static Task <ILandmarkCollection> CreateLandmarksAsync( IHexBoard <IHex> board, IFastList <HexCoords> landmarkCoords, CancellationToken token ) { return(Task.Run(() => CreateLandmarks(board, landmarkCoords))); }
/// <summary>Creates a populated <see cref="Collection{T}"/> of <see cref="Landmark"/> /// instances.</summary> /// <param name="board">The board on which the collection of landmarks is to be instantiated.</param> /// <param name="queueGenerator"></param> /// <param name="landmarkCoords">Board coordinates of the desired landmarks</param> public static ILandmarkCollection CreateLandmarks(this IBoard <IHex> board, IFastList <HexCoords> landmarkCoords, Func <Queue> queueGenerator) => new LandmarkCollection( from coords in (landmarkCoords ?? new List <HexCoords>().ToFastList()) .AsParallel() .WithDegreeOfParallelism(Math.Max(1, Environment.ProcessorCount - 2)) select(from landmark in board[coords] where landmark != null select new Landmark(coords, board?.PopulateLandmark(EntryCost, queueGenerator, landmark), board?.PopulateLandmark(ExitCost, queueGenerator, landmark)) ).ElseDefault() );
/// <summary>TODO</summary> /// <param name="landmarkCoords"><see cref="IFastList{HexCoords}"/> of the hexes to be used as Path-Finding landmarks.</param> /// <returns></returns> protected Exception ResetLandmarks(IFastList <HexCoords> landmarkCoords) { try { #if true Landmarks = (this as IBoard <IHex>).CreateLandmarksHotQueue(landmarkCoords); #else Landmarks = LandmarkCollection.New(this, landmarkCoords); #endif OnLandmarksReady(new EventArgs <ILandmarks>(Landmarks)); return(null); } catch (Exception ex) { return(ex); } }
/// <summary>Utility routine to do the hard-lifting for Dispose().</summary> private void Dispose(bool disposing) { if (!isDisposed) { if (disposing) { var disposable = fastList as IDisposable; if (disposable != null) { disposable.Dispose(); } fastList = null; } } }
/// <summary>Clean up any resources being used.</summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> private void Dispose(bool disposing) { if (!_isDisposed) { if (disposing) { if (_fastList is IDisposable disposable) { disposable.Dispose(); } _fastList = null; } _isDisposed = true; } }
private void SetLandmarks(IFastList <HexCoords> landmarkCoords) { ILandmarks tempLandmarks = null; ILandmarks landmarks = null; try { tempLandmarks = LandmarkCollection.CreateLandmarks(this, landmarkCoords); landmarks = tempLandmarks; tempLandmarks = null; } finally { if (tempLandmarks != null) { tempLandmarks.Dispose(); } } Landmarks = landmarks; }
/// <summary>Creates a new instance of the MapDisplay class.</summary> protected MapDisplay(HexSize sizeHexes, HexSize gridSize, InitializeHex initializeHex, IFastList <HexCoords> landmarkCoords, BoardStorage <Maybe <THex> > storage) : base(sizeHexes, gridSize, storage) { ResetLandmarksAsync(landmarkCoords); GoalHex = HotspotHex = StartHex = HexCoords.EmptyUser; ShadeBrushAlpha = 78; ShowFov = true; ShowHexgrid = true; ShowPath = true; ShowPathArrow = true; HexgridPath = Extensions.InitializeDisposable(() => new GraphicsPath(HexgridPathPoints(gridSize), _hexgridPathPointTypes)); }
/// <summary>Creates a populated <see cref="Collection{T}"/> of <see cref="Landmark"/> /// instances.</summary> /// <param name="board">The board on which the collection of landmarks is to be instantiated.</param> /// <param name="landmarkCoords">Board coordinates of the desired landmarks</param> public static ILandmarkCollection New( INavigableBoard board, IFastList <HexCoords> landmarkCoords ) { int degreeOfParallelism = Math.Max(1, Environment.ProcessorCount - 1); var query = from coords in landmarkCoords.AsParallel() .WithDegreeOfParallelism(degreeOfParallelism) .WithMergeOptions(ParallelMergeOptions.NotBuffered) #if UseSortedDictionary select Landmark.DictionaryPriorityQueueLandmark(coords, board); #else select Landmark.HotPriorityQueueLandmark(coords, board); #endif return(Extensions.InitializeDisposable(() => new LandmarkCollection(query))); }
/// <summary>Creates a new instance of the MapDisplay class.</summary> protected MapDisplay(HexSize sizeHexes, HexSize gridSize, InitializeHex initializeHex, IFastList <HexCoords> landmarkCoords) : base(sizeHexes, gridSize, landmarkCoords, GetGraphicsPath #if FlatBoardStorage , () => new FlatBoardStorage <THex>(sizeHexes, coords => initializeHex(GetGraphicsPath(gridSize), coords)) #else , () => new BlockedBoardStorage32x32 <THex>(sizeHexes, coords => initializeHex(GetGraphicsPath(gridSize), coords)) #endif ) { InitializeProperties(); }
/// <summary>TODO</summary> /// <param name="landmarkCoords"><see cref="IFastList{HexCoords}"/> of the hexes to be used as Path-Finding landmarks.</param> /// <returns></returns> protected async Task <bool> ResetLandmarksAsync(IFastList <HexCoords> landmarkCoords) => await Task.Run(() => ResetLandmarks(landmarkCoords));
/// <summary>TODO</summary> /// <param name="landmarkCoords"><see cref="IFastList{HexCoords}"/> of the hexes to be used as Path-Finding landmarks.</param> /// <returns></returns> protected bool ResetLandmarks(IFastList <HexCoords> landmarkCoords) { Landmarks = LandmarkCollection.New(this, landmarkCoords); OnLandmarksReady(new EventArgs <ILandmarks>(Landmarks)); return(true); }
/// <summary>.</summary> /// <param name="board"></param> /// <param name="landmarkCoords"></param> public static ILandmarkCollection CreateLandmarksHotQueue(this IBoard <IHex> board, IFastList <HexCoords> landmarkCoords) => board.CreateLandmarks(landmarkCoords, PriorityQueueFactory.NewHotPriorityQueue <IHex>);
/// <summary>Creates a new instance of the MapDisplay class.</summary> protected MapDisplay(Size sizeHexes, Size gridSize, InitializeHex initializeHex, IFastList <HexCoords> landmarkCoords) : base(sizeHexes, gridSize, landmarkCoords, GetGraphicsPath #if FlatBoardStorage , () => new FlatBoardStorage <THex>(sizeHexes, coords => initializeHex(board, coords)) #else , () => new BlockedBoardStorage32x32 <THex>(sizeHexes, coords => initializeHex(GetGraphicsPath(gridSize), coords)) #endif ) { InitializeProperties(); var grid = TransposableHexgrid.GetNewGrid(false, gridSize, 1.0F); }
/// <summary>Initializes the internal contents of <see cref="HexBoard{THex,TPath}"/> with landmarks as specified for pathfinding.</summary> /// <param name="sizeHexes">Extent in hexes of the board being initialized, as a <see cref="System.Drawing.Size"/>.</param> /// <param name="gridSize">Extent in pixels of the layout grid for the hexagons, as a <see cref="System.Drawing.Size"/>.</param> /// <param name="landmarkCoords"><see cref="IFastList{HexCoords}"/> of the hexes to be used as Path-Finding landmarks.</param> /// <param name="hexgridPath">Implementation of a graphics path for the hex border.</param> /// <param name="boardStorage">TODO</param> protected HexBoard(HexSize sizeHexes, HexSize gridSize, IFastList <HexCoords> landmarkCoords, Func <HexSize, TPath> hexgridPath, BoardStorageInitializer <THex, TPath> boardStorage ) : this(sizeHexes, gridSize, hexgridPath, boardStorage) { SetLandmarks(landmarkCoords); }
/* For Unit testing */ public void DetachFromList() { m_list = null; m_listPrev = m_listNext = null; }