Exemple #1
0
        // link every hole into the outer loop, producing a single-ring polygon without holes
        private static Node EliminateHoles(LightList <float> data, LightList <int> holeIndices, Node outerNode)
        {
            var len = holeIndices.Count;

            for (var i = 0; i < len; i++)
            {
                var start = holeIndices[i] * 2;
                var end   = i < len - 1 ? holeIndices[i + 1] * 2 : data.Count;
                var list  = LinkedList(data.Array, start, end, false);
                if (list == list.next)
                {
                    list.steiner = true;
                }

                holeQueue.Add(GetLeftmost(list));
            }

            holeQueue.Sort(nodeComparer);

            // process holes from left to right
            for (var i = 0; i < holeQueue.Count; i++)
            {
                EliminateHole(holeQueue[i], outerNode);
                outerNode = FilterPoints(outerNode, outerNode.next);
            }

            holeQueue.QuickClear();

            return(outerNode);
        }
Exemple #2
0
 public void Clear()
 {
     parent           = null;
     isDrawn          = false;
     clipPath         = null;
     isCulled         = false;
     visibleBoxCount  = 0;
     isTransformed    = false;
     renderBox        = null;
     intersected.size = 0;
     worldBounds      = default;
     dependents.QuickClear();
 }
Exemple #3
0
        public static void Tessellate(LightList <float> input, LightList <int> holeIndices, LightList <int> output)
        {
            float[] data     = input.Array;
            bool    hasHoles = holeIndices.Count > 0;
            int     outerLen = hasHoles ? holeIndices[0] * 2 : input.Count;

            Node outerNode = LinkedList(data, 0, outerLen, true);

            LightList <int> triangles = output ?? new LightList <int>();

            if (outerNode == null)
            {
                return;
            }

            float minX    = float.PositiveInfinity;
            float minY    = float.PositiveInfinity;
            float maxX    = float.NegativeInfinity;
            float maxY    = float.NegativeInfinity;
            float invSize = default(float);


            if (hasHoles)
            {
                outerNode = EliminateHoles(input, holeIndices, outerNode);
            }

            // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
            if (input.Count > 80 * 2)
            {
                for (int i = 0; i < outerLen; i += 2)
                {
                    float x = data[i];
                    float y = data[i + 1];

                    if (x < minX)
                    {
                        minX = x;
                    }

                    if (y < minY)
                    {
                        minY = y;
                    }

                    if (x > maxX)
                    {
                        maxX = x;
                    }

                    if (y > maxY)
                    {
                        maxY = y;
                    }
                }

                // minX, minY and invSize are later used to transform coords into integers for z-order calculation
                invSize = Math.Max(maxX - minX, maxY - minY);
                invSize = invSize != 0 ? 1 / invSize : 0;
            }

            EarcutLinked(outerNode, triangles, minX, minY, invSize);

            // pooling clears on Get, not release so we don't need to re-iterate the list
            inactive.AddRange(active);
            active.QuickClear();
        }
Exemple #4
0
        internal void OnUpdate()
        {
            UITask[] tasks = thisFrame.Array;
            float    delta = Time.unscaledDeltaTime;

            int count = thisFrame.Count;

            for (int i = 0; i < count; i++)
            {
                UITask      task  = tasks[i];
                UITaskState state = task.state;

                float time = delta;

                if (state == UITaskState.Pending)
                {
                    task.OnInitialized();
                    task.StartTime = Time.unscaledTime;
                    state          = UITaskState.Running;
                    time           = 0;
                }
                else if (state == UITaskState.Restarting)
                {
                    task.RestartTime = Time.unscaledTime;
                    time             = 0;
                }

                if ((state & (UITaskState.Running | UITaskState.Restarting)) != 0)
                {
                    task.FrameCount++;
                    task.ElapsedTime += time;
                    UITaskResult result = task.Run(time);
                    switch (result)
                    {
                    case UITaskResult.Running:
                        task.state = UITaskState.Running;
                        nextFrame.Add(task);
                        break;

                    case UITaskResult.Completed:
                        task.state = UITaskState.Completed;
                        task.OnCompleted();
                        break;

                    case UITaskResult.Restarted:
                        task.ResetCount++;
                        task.state = UITaskState.Restarting;
                        nextFrame.Add(task);
                        break;

                    case UITaskResult.Failed:
                        task.state = UITaskState.Failed;
                        task.OnFailed();
                        task.owner = null;
                        break;

                    case UITaskResult.Cancelled:
                        task.state = UITaskState.Cancelled;
                        task.OnCancelled();
                        task.owner = null;
                        break;

                    default:
                        task.state = UITaskState.Cancelled;
                        task.OnCancelled();
                        task.owner = null;
                        break;
                    }
                }
            }

            LightList <UITask> swap = nextFrame;

            nextFrame = thisFrame;
            thisFrame = swap;
            nextFrame.QuickClear();
        }
Exemple #5
0
 internal void OnDestroy()
 {
     thisFrame.QuickClear();
     nextFrame.QuickClear();
 }