当前位置: 首页>>代码示例>>C#>>正文


C# Grid.Reset方法代码示例

本文整理汇总了C#中Grid.Reset方法的典型用法代码示例。如果您正苦于以下问题:C# Grid.Reset方法的具体用法?C# Grid.Reset怎么用?C# Grid.Reset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Grid的用法示例。


在下文中一共展示了Grid.Reset方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Search

    public static List<Cell> Search(Grid grid, Vector2 start, Vector2 end)
    {
        grid.Reset ();

        List<Cell> openList = new List<Cell> ();
        List<Cell> closedList = new List<Cell> ();
        Cell currentCell;
        Cell neighbor;
        float gScore;
        bool gScoreIsBest;
        List<Cell> neighbors;

        int maxJumpHeight = 8;
        int maxDubbleJumpHeight = 2;

        int currentMaxJumpHeight = maxJumpHeight;

        currentCell = grid.GetCell ((int)start.x, (int)start.y);

        if (currentCell.isWall) {
            currentCell.isGround = true;
            currentCell.isWall = false;
            currentCell.tempGroundTile = true;
        }

        openList.Add (currentCell);

        while (openList.Count > 0) {
            openList.Sort(SortOnF);

            currentCell = openList[0];

            if(currentCell.position.Equals(end)){
                List<Cell> path = new List<Cell>();

                while(currentCell.parent != null){
                    path.Add(currentCell);
                    currentCell = currentCell.parent;
                }

                path.Reverse();

                return path;
            }

            openList.Remove(currentCell);
            closedList.Add(currentCell);
            currentCell.isClosed = true;
            currentCell.isOpen = false;

            if(currentCell.neighbors == null){
                currentCell.neighbors = GetNeighbors(grid,currentCell);
            }

            if(currentCell.j >= maxJumpHeight && currentMaxJumpHeight == maxJumpHeight){
                currentMaxJumpHeight += maxDubbleJumpHeight;
            }

            neighbors = currentCell.neighbors;

            int l = neighbors.Count;

            for(int i = 0; i < l; i++){
                neighbor = neighbors[i];

                if(neighbor.isClosed || currentCell.isBlocked){
                    continue; // ignore cell
                }

                if(IsDiagonal(currentCell,neighbor)){
                    gScore = currentCell.g + diagonalScore;
                }else{
                    gScore = currentCell.g + horizontalScore;
                }

                if(currentCell.j > 0 && !neighbor.isGround && !neighbor.isPassableGround && !neighbor.isWall){
                    if(GetNonDiagonalDirection(currentCell,neighbor) != Vector2.left && GetNonDiagonalDirection(currentCell,neighbor) != Vector2.right){
                        neighbor.j = currentCell.j + 1;
                    }else{
                        neighbor.j = currentCell.j + 0.5f;
                    }
                }else if(currentCell.j > 0){
                    if((GetNonDiagonalDirection(currentCell,neighbor) != Vector2.left && GetNonDiagonalDirection(currentCell,neighbor) != Vector2.right && currentCell.parent != null && GetNonDiagonalDirection(currentCell,currentCell.parent) == Vector2.up) || neighbor.isWall){
                        neighbor.j = 0;
                        neighbor.th = 0;
                    }else{
                        continue;
                    }
                }

                if(GetNonDiagonalDirection(currentCell,neighbor) == Vector2.up){
                    //neighbor.infoCell.GetComponent<SpriteRenderer>().color = Color.cyan;
                    if(currentCell.j == 0){
                        neighbor.j = 2;
                    }else if(currentCell.j % 2 != 0){
                        neighbor.j = currentCell.j + 1;
                    }

                    /*else{
                        neighbor.j = currentCell.j + 1;
//.........这里部分代码省略.........
开发者ID:Darkfafi,项目名称:LJ3_Project1_Fighter,代码行数:101,代码来源:AStar.cs

示例2: QuantTilePointsIndexed


//.........这里部分代码省略.........
                        //	var pBest = (SQuantizedPoint3D*)(segmentBuffer.PointDataPtr + offset);

                        //	if ((*p).Z < (*pBest).Z)
                        //		lowResGrid.Data[cellY, cellX] = (int)(pb - segmentBuffer.PointDataPtr);
                        //}

                        pb += source.PointSizeBytes;
                        ++index;
                    }

                    if (!process.Update((float)index / segmentBuffer.PointCount))
                        break;
                }
            }*/

            // determine representative low-res points for each tile and swap them to a new buffer
            using (var process = progressManager.StartProcess("QuantTilePointsIndexedExtractLowRes"))
            {
                var removedBytes = 0;

                var templateQuantizedExtent = quantizedExtent.ComputeQuantizedTileExtent(new SimpleGridCoord(0, 0), tileCounts);
                var cellSizeX = (int)(templateQuantizedExtent.RangeX / lowResGrid.SizeX);
                var cellSizeY = (int)(templateQuantizedExtent.RangeY / lowResGrid.SizeY);

                var index = 0;
                foreach (var tile in tileFilter.GetCellOrdering())
                {
                    var count = tileCounts.Data[tile.Row, tile.Col];
                    var dataPtr = segmentBuffer.PointDataPtr + (index * source.PointSizeBytes);
                    var dataEndPtr = dataPtr + (count * source.PointSizeBytes);

                    var tileQuantizedExtent = quantizedExtent.ComputeQuantizedTileExtent(tile, tileCounts);

                    lowResGrid.Reset();

                    var pb = dataPtr;
                    while (pb < dataEndPtr)
                    {
                        var p = (SQuantizedPoint3D*)pb;

                        var cellX = (((*p).X - tileQuantizedExtent.MinX) / cellSizeX);
                        var cellY = (((*p).Y - tileQuantizedExtent.MinY) / cellSizeY);

                        // todo: make lowResGrid <long> to avoid cast?
                        var offset = lowResGrid.Data[cellY, cellX];
                        if (offset == -1)
                        {
                            lowResGrid.Data[cellY, cellX] = (int)(pb - segmentBuffer.PointDataPtr);
                        }
                        else
                        {
                            var pBest = (SQuantizedPoint3D*)(segmentBuffer.PointDataPtr + offset);

                            //if ((*p).Z > (*pBest).Z)
                            if ((*p).Z < (*pBest).Z)
                                lowResGrid.Data[cellY, cellX] = (int)(pb - segmentBuffer.PointDataPtr);

                            //var cellCenterX = (cellX + 0.5) * cellSizeX;
                            //var cellCenterY = (cellY + 0.5) * cellSizeY;

                            //var bd2 = DistanceRatioFromPointToCellCenter2(pBest, cellCenterX, cellCenterY, cellSizeX, cellSizeY);
                            //var cd2 = DistanceRatioFromPointToCellCenter2(p, cellCenterX, cellCenterY, cellSizeX, cellSizeY);

                            //if (cd2 < bd2)
                            //	lowResGrid.Data[cellY, cellX] = (int)(pb - segmentBuffer.PointDataPtr);
                        }
开发者ID:jdauie,项目名称:cloudae,代码行数:67,代码来源:PointCloudTileManager.cs

示例3: Initialize

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            Services.AddService(typeof(SpriteBatch), spriteBatch);
            grid = new Grid(this, 20) {DrawGridLines = true};
            cursor = new MouseCursor(this, spriteBatch, Content.Load<Texture2D>("cursor"));
            cursor.LeftClick += (o, e) => HandleLeftButton(e.Position);
            cursor.LeftDrag += (o, e) => HandleLeftButton(e.Position);
            cursor.RightClick += (o, e) => HandleRightButton(e.Position);
            cursor.RightDrag += (o, e) => HandleRightButton(e.Position);
            aStar = new AStar(this, grid, new ManhattanDistance());
            aStar.PathFound += (o, e) => {
                console.WriteLine(String.Format("Heuristic: {0}; Path length: {1}; Total Explored length: {2}", aStar.Heuristic.Name, e.TotalPathLength, e.TotalExplored));
                                             foreach (var cell in e.Path)
                                             {
                                                 cell.Type = GridCellType.Path;
                                             }
            };
            Components.Add(cursor);
            gameObjects.Add(grid);
            gameObjects.Add(aStar);

            var singleStroke = new SingleKeyStroke(this);
            singleStroke.KeyDown += (o, e) =>
                                        {
                                            if (console.Opened)
                                            {
                                                return;
                                            }
                                            if (e.Key == Keys.Space)
                                            {
                                                grid.DrawGridLines = !grid.DrawGridLines;
                                            }
                                            if (e.Key == Keys.Enter)
                                            {
                                                grid.Reset();
                                                aStar.Start();
                                            }
                                        };
            Components.Add(singleStroke);
            console = new GameConsole(this, spriteBatch, new IConsoleCommand[]
                                                             {
                                                                new DisplayGridlinesCommand(grid),
                                                                new ResetGridCommand(grid),
                                                                new CellSizeCommand(grid),
                                                                new SetHeuristicCommand(aStar),
                                                                new FullScreenCommand(graphics)
                                                             }, new GameConsoleOptions{Prompt=">", FontColor = Color.GreenYellow});

            base.Initialize();
        }
开发者ID:dreasgrech,项目名称:AStarXNA,代码行数:57,代码来源:Game1.cs

示例4: LoadTileGrid

        public unsafe void LoadTileGrid(PointCloudTile tile, BufferInstance inputBuffer, Grid<float> grid, Grid<int> quantizedGrid)
        {
            Open();

            var quantizedExtent = tile.QuantizedExtent;

            double cellSizeX = (double)quantizedExtent.RangeX / grid.SizeX;
            double cellSizeY = (double)quantizedExtent.RangeY / grid.SizeY;

            #warning Why did I do FillVal it this way?
            //grid.FillVal = -1.0f;
            grid.Reset();
            quantizedGrid.Reset();

            byte* inputBufferPtr = inputBuffer.DataPtr;

            int bytesRead = tile.ReadTile(m_inputStream, inputBuffer.Data);

            byte* pb = inputBufferPtr;
            byte* pbEnd = inputBufferPtr + tile.StorageSize;
            while (pb < pbEnd)
            {
                var p = (SQuantizedPoint3D*)pb;
                pb += PointSizeBytes;

                var pixelX = (int)(((*p).X - quantizedExtent.MinX) / cellSizeX);
                var pixelY = (int)(((*p).Y - quantizedExtent.MinY) / cellSizeY);

                // max val for now, apparently
                if ((*p).Z > quantizedGrid.Data[pixelY, pixelX])
                    quantizedGrid.Data[pixelY, pixelX] = (*p).Z;
            }

            quantizedGrid.CorrectMaxOverflow();
            quantizedGrid.CopyToUnquantized(grid, Quantization, Extent);
        }
开发者ID:jdauie,项目名称:cloudae,代码行数:36,代码来源:PointCloudTileSource.cs


注:本文中的Grid.Reset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。