Example #1
0
        private void DoUpdate()
        {
            if (Time.time <= lastStep + RevelationSpeed)
            {
                return;
            }

            lastStep += RevelationSpeed;

            foreach (var cell in prevCells)
            {
                if (!cell.IsNude || cell.IsBomb)
                {
                    continue;
                }

                foreach (var neighbor in cell.Neighbors)
                {
                    if (neighbor.State == CellState.Default)
                    {
                        neighbor.State = CellState.Revealed;

                        if (neighbor.IsNude && !neighbor.IsBomb)
                        {
                            buffer.Add(neighbor);
                        }
                    }
                }
            }

            if (buffer.Count == 0)
            {
                IsFinished = true;

                foreach (var action in followupActions)
                {
                    action.Invoke();
                }

                OnFinished();

                GlobalListPool <BoardCell> .Put(prevCells);

                GlobalListPool <BoardCell> .Put(buffer);

                GlobalListPool <Action> .Put(followupActions);

                CallProvider.RemoveUpdateListener(DoUpdate);
                return;
            }

            var tmp = prevCells;

            prevCells = buffer;
            buffer    = tmp;
            buffer.Clear();
        }
Example #2
0
        public void Dispose()
        {
            if (this.data == null)
            {
                return;
            }

            GlobalListPool <Vector3> .Put(this.data);

            this.data = null;
        }
        /// <summary>
        /// Triangulates a list of vertices, interpreted as the vertices of a planar polygon in clockwise order.
        /// </summary>
        /// <param name="vertices">The vertices.</param>
        /// <param name="normal">The normal of the polygon, if not know, use the overload without normal.</param>
        public static int[] Triangulate(this IList <Vector3> vertices, Vector3 normal)
        {
            var output = GlobalListPool <int> .Get(vertices.Count * 3 - 2);

            vertices.Triangulate(normal, output);
            var result = output.ToArray();

            GlobalListPool <int> .Put(output);

            return(result);
        }
        /// <summary>
        /// Triangulates a list of vertices, interpreted as the vertices of a planar polygon in clockwise order.
        /// </summary>
        /// <param name="vertices">The vertices.</param>
        public static int[] TriangulateWithCuttingEars(this IList <Vector3> vertices)
        {
            var output = GlobalListPool <int> .Get(vertices.Count * 3 - 2);

            vertices.TriangulateWithCuttingEars(output);
            var result = output.ToArray();

            GlobalListPool <int> .Put(output);

            return(result);
        }
Example #5
0
        public void Dispose()
        {
            if (this.coeff == null)
            {
                return;
            }

            GlobalListPool <float> .Put(this.coeff);

            this.coeff = null;
        }
Example #6
0
        /// <summary>
        /// Converts any enumerator to an array.
        /// </summary>
        /// <typeparam name="T">The item type.</typeparam>
        /// <param name="enumerator">The enumerator to convert.</param>
        /// <returns>Returns the resulting array.</returns>
        public static T[] ToArray <T>(this IEnumerator <T> enumerator)
        {
            var result = GlobalListPool <T> .Get();

            enumerator.CopyTo(result);
            var output = result.ToArray();

            GlobalListPool <T> .Put(result);

            return(output);
        }
        public void Dispose()
        {
            if (points == null)
            {
                return;
            }

            // Allow the internal list to be reused
            GlobalListPool <Vector2> .Put(points);

            points = null;
        }
Example #8
0
        /// <summary>
        /// Applies a filter on a list and returns the matches.
        /// </summary>
        /// <typeparam name="T">The item type.</typeparam>
        /// <param name="items">The list to search.</param>
        /// <param name="filter">The filter function.</param>
        /// <returns></returns>
        public static T[] Filter <T>(this IReadOnlyList <T> items, Func <T, bool> filter)
        {
            var filtered = GlobalListPool <T> .Get(items.Count);

            foreach (var item in items)
            {
                if (filter(item))
                {
                    filtered.Add(item);
                }
            }

            var result = filtered.ToArray();

            GlobalListPool <T> .Put(filtered);

            return(result);
        }
        public Mesh ToMesh()
        {
            var vertexCache = GlobalListPool <Vector3> .Get(this.vertices.Count);

            var indexCache = GlobalListPool <int> .Get(this.vertices.Count);

            var meshVertices = GlobalListPool <Vector3> .Get(this.vertices.Count * 3);

            foreach (var face in faces)
            {
                vertexCache.Clear();
                indexCache.Clear();

                foreach (var vertex in face.Vertices)
                {
                    vertexCache.Add(vertex.Vertex);
                }

                vertexCache.Triangulate(indexCache);

                foreach (var index in indexCache)
                {
                    meshVertices.Add(vertexCache[index]);
                }
            }

            var mesh = new Mesh();

            mesh.vertices  = meshVertices.ToArray();
            mesh.triangles = CollectionUtil.CreateArray(meshVertices.Count, 0, i => i + 1);

            GlobalListPool <Vector3> .Put(vertexCache);

            GlobalListPool <int> .Put(indexCache);

            GlobalListPool <Vector3> .Put(meshVertices);

            return(mesh);
        }
Example #10
0
        private void CollapseNode(int index)
        {
            Debug.Assert(index >= 0);
            Debug.Assert(index < nodeCount * NodeSize);
            Debug.Assert(index % NodeSize == 0);
            Debug.Assert(nodes[index + 1] < NodeCollapseCount);

            for (var i = ChildIndexOffset; i < NodeSize; i++)
            {
                Debug.Assert(nodes[index + i] <= 0, "If a node has few enough items to be collapsed, it can't be that the node contains child nodes.");
            }

            if (index == 0)
            {
                // Don't collapse root
                return;
            }

            // Node is bellow collapse threshold -> collapse into leaf
            var itemCache = GlobalListPool <ItemEntry> .Get(nodes[index + 1]);

            for (var i = ChildIndexOffset; i < NodeSize; i++)
            {
                var reference = nodes[index + i];
                nodes[index + i] = 0;

                if (reference < 0)
                {
                    var leafIndex = -(reference + 1);
                    var leaf      = leafs[leafIndex];

                    for (var j = 0; j < leaf.Count; j++)
                    {
                        itemCache.Add(leaf.Content[j]);
                    }

                    CacheContentArray(leaf.Content);
                    RemoveLeaf(leafIndex);
                }
            }

            var parent       = nodes[index];
            var newLeafIndex = AddLeaf(parent, itemCache);

            for (var i = ChildIndexOffset; i < NodeSize; i++)
            {
                if (nodes[parent + i] == index)
                {
                    nodes[parent + i] = newLeafIndex;
                }
            }

            RemoveNode(index);
            GlobalListPool <ItemEntry> .Put(itemCache);

            if (parent == nodeCount * NodeSize)
            {
                // In case parent was the last node and was used to replace the current node
            }

            if (nodes[parent + 1] < NodeCollapseCount)
            {
                CollapseNode(parent);
            }
        }