Exemple #1
0
        // Finds common parent for set of given nodes
        protected static MyVisualSyntaxNode CommonParent(IEnumerable <MyVisualSyntaxNode> nodes)
        {
            m_commonParentSet.Clear();
            m_activeHeap.Clear();

            // Use the set to remove duplicities
            foreach (var node in nodes)
            {
                if (m_commonParentSet.Add(node))
                {
                    // inverse the Depth because we have only Min heap
                    m_activeHeap.Insert(new HeapNodeWrapper {
                        Node = node
                    }, -node.Depth);
                }
            }

            HeapNodeWrapper current;

            do
            {
                current = m_activeHeap.RemoveMin();
                // We have a solution
                if (m_activeHeap.Count == 0)
                {
                    break;
                }
                // Node with no sequence inputs means that we have a solution or
                // there is no solution of we still have some nodes in the heap.
                if (current.Node.SequenceInputs.Count == 0)
                {
                    if (m_activeHeap.Count > 0)
                    {
                        return(null);
                    }

                    continue;
                }

                current.Node.SequenceInputs.ForEach(node =>
                {
                    // Insert all not visited inputs into the heap
                    if (m_activeHeap.Count > 0 && m_commonParentSet.Add(node))
                    {
                        current.Node = node;
                        m_activeHeap.Insert(current, -current.Node.Depth);
                    }
                });
            } while (true);

            // Special case...
            if (current.Node is MyVisualSyntaxForLoopNode)
            {
                var parent = current.Node.SequenceInputs.FirstOrDefault();
                return(parent);
            }

            return(current.Node);
        }
Exemple #2
0
        public override void UpdateAfterSimulation()
        {
            long time = Time();

            while (m_entities.Count > 0 && m_entities.MinKey() < time)
            {
                m_index.Remove(m_entities.RemoveMin().Entity.EntityId);
            }

            if (m_entities.Count == 0)
            {
                SetUpdateOrder(MyUpdateOrder.NoUpdate);
            }
        }
        public void MarkBoxForAddition(BoundingBoxD box)
        {
            ProfilerShort.Begin("VoxelNavMesh.MarkBoxForAddition");
            Vector3I pos, end;

            MyVoxelCoordSystems.WorldPositionToVoxelCoord(m_voxelMap.PositionLeftBottomCorner, ref box.Min, out pos);
            MyVoxelCoordSystems.WorldPositionToVoxelCoord(m_voxelMap.PositionLeftBottomCorner, ref box.Max, out end);

            m_voxelMap.Storage.ClampVoxelCoord(ref pos);
            m_voxelMap.Storage.ClampVoxelCoord(ref end);

            MyVoxelCoordSystems.VoxelCoordToGeometryCellCoord(ref pos, out pos);
            MyVoxelCoordSystems.VoxelCoordToGeometryCellCoord(ref end, out end);

            Vector3 center = pos + end;

            center = center * 0.5f;

            pos /= 1 << NAVMESH_LOD;
            end /= 1 << NAVMESH_LOD;

            for (var it = new Vector3I.RangeIterator(ref pos, ref end); it.IsValid(); it.GetNext(out pos))
            {
                if (!m_processedCells.Contains(ref pos) && !m_markedForAddition.Contains(ref pos))
                {
                    float weight = 1.0f / (0.01f + Vector3.RectangularDistance(pos, center));

                    if (!m_toAdd.Full)
                    {
                        m_toAdd.Insert(pos, weight);
                        m_markedForAddition.Add(ref pos);
                    }
                    else
                    {
                        float min = m_toAdd.MinKey();
                        if (weight > min)
                        {
                            Vector3I posRemoved = m_toAdd.RemoveMin();
                            m_markedForAddition.Remove(ref posRemoved);

                            m_toAdd.Insert(pos, weight);
                            m_markedForAddition.Add(ref pos);
                        }
                    }
                }
            }
            ProfilerShort.End();
        }
            public bool MoveNext()
            {
                while (_tmp.Count > 0)
                {
                    var minKey = _tmp.MinKey();
                    var min = _tmp.RemoveMin();
                    int child1, child2;
                    _tree.GetChildren(min, out child1, out child2);
                    if (child1 == -1)
                    {
                        Current = new KeyValuePair <int, double>(min, minKey);
                        return(true);
                    }

                    Insert(child1);
                    Insert(child2);
                }

                Current = default(KeyValuePair <int, double>);
                return(false);
            }
 protected void RunUpdate(long ticks)
 {
     ApplyChanges();
     _ticks += ticks;
     do
     {
         if (_scheduledUpdates.Count == 0)
         {
             return;
         }
         if (_scheduledUpdates.MinKey() > _ticks)
         {
             return;
         }
         var test = _scheduledUpdates.RemoveMin();
         test.Callback((ulong)(_ticks - test.LastUpdate));
         if (test.Interval > 0)
         {
             var next = new ScheduledUpdate(test.Callback, _ticks, test.NextUpdate + test.Interval,
                                            test.Interval);
             _scheduledUpdates.Insert(next, next.NextUpdate);
         }
     } while (true);
 }