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


C# RawList.Reserve方法代码示例

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


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

示例1: QueryVisibleRenderers

		public void QueryVisibleRenderers(IDrawDevice device, RawList<ICmpRenderer> targetList)
		{
			// Empty the cached list of visible renderers
			targetList.Count = 0;
			targetList.Reserve(this.totalRendererCount);

			// Copy references to all renderers that are visible to the target device
			int visibleCount = 0;
			ICmpRenderer[] targetData = targetList.Data;
			foreach (var pair in this.renderersByType)
			{
				ICmpRenderer[] data = pair.Value.Data;
				for (int i = 0; i < data.Length; i++)
				{
					if (i >= pair.Value.Count) break;

					if ((data[i] as Component).Active && data[i].IsVisible(device))
					{
						targetData[visibleCount] = data[i];
						visibleCount++;
					}
				}
			}
			targetList.Count = visibleCount;
		}
开发者ID:ChrisLakeZA,项目名称:duality,代码行数:25,代码来源:DefaultRendererVisibilityStrategy.cs

示例2: GenerateCollisionShapes

        private static void GenerateCollisionShapes(TileEdgeMap edgeMap, Vector2 origin, Vector2 tileSize, bool roundedCorners, IList<ShapeInfo> shapeList)
        {
            // Traverse the edge map and gradually create chain / loop
            // shapes until all edges have been used.
            RawList<Point2> currentChain = new RawList<Point2>();
            RawList<Vector2> vertexBuffer = new RawList<Vector2>();
            while (true)
            {
                // Begin a new continuous chain of nodes
                currentChain.Clear();

                // Find a starting node for our current chain.
                // If there is none, we found and handled all edges.
                Point2 start = edgeMap.FindNonEmpty();
                if (start == new Point2(-1, -1))
                    break;

                // Traverse the current chain node-by-node from the start we found
                Point2 current = start;
                while (true)
                {
                    // Add the current node to our continuous chain
                    currentChain.Add(current);

                    // Find the next node that connects to the current one.
                    // If there is none, our current chain is done.
                    Point2 next = edgeMap.GetClockwiseNextFrom(current);
                    if (next == new Point2(-1, -1))
                        break;

                    // Remove the edge we used to get to the next node
                    edgeMap.RemoveEdge(current, next);

                    // Use the next node as origin for traversing further
                    current = next;
                }

                // Generate a shape from the current chain
                bool isLoop = (start == currentChain[currentChain.Count - 1]);
                if (isLoop) currentChain.RemoveAt(currentChain.Count - 1);
                vertexBuffer.Clear();

                // Rounded corners
                if (roundedCorners && currentChain.Count >= 3)
                {
                    vertexBuffer.Reserve(currentChain.Count * 2);
                    vertexBuffer.Count = 0;
                    for (int i = 0; i < currentChain.Count; i++)
                    {
                        int prevIndex = (i - 1 + currentChain.Count) % currentChain.Count;
                        int nextIndex = (i + 1) % currentChain.Count;

                        Vector2 currentVert = origin + tileSize * (Vector2)currentChain[i];
                        Vector2 prevVert = origin + tileSize * (Vector2)currentChain[prevIndex];
                        Vector2 nextVert = origin + tileSize * (Vector2)currentChain[nextIndex];

                        if (nextVert - currentVert != currentVert - prevVert)
                        {
                            if (!isLoop && (i == 0 || i == currentChain.Count - 1))
                            {
                                vertexBuffer.Add(currentVert);
                            }
                            else
                            {
                                vertexBuffer.Add(currentVert + (prevVert - currentVert).Normalized * tileSize * 0.2f);
                                vertexBuffer.Add(currentVert + (nextVert - currentVert).Normalized * tileSize * 0.2f);
                            }
                        }
                    }
                }
                // Sharp corners
                else
                {
                    vertexBuffer.Reserve(currentChain.Count);
                    vertexBuffer.Count = 0;
                    for (int i = 0; i < currentChain.Count; i++)
                    {
                        int prevIndex = (i - 1 + currentChain.Count) % currentChain.Count;
                        int nextIndex = (i + 1) % currentChain.Count;

                        Vector2 currentVert = origin + tileSize * (Vector2)currentChain[i];
                        Vector2 prevVert = origin + tileSize * (Vector2)currentChain[prevIndex];
                        Vector2 nextVert = origin + tileSize * (Vector2)currentChain[nextIndex];

                        if (nextVert - currentVert != currentVert - prevVert)
                            vertexBuffer.Add(currentVert);
                    }
                }
                shapeList.Add(isLoop ?
                    (ShapeInfo)new LoopShapeInfo(vertexBuffer) :
                    (ShapeInfo)new ChainShapeInfo(vertexBuffer));
            }
        }
开发者ID:SirePi,项目名称:duality,代码行数:93,代码来源:TilemapCollider.cs


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