예제 #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);
        }
예제 #2
0
        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();
        }
예제 #3
0
 private void ApplyChanges()
 {
     using (_lock.AcquireExclusiveUsing())
     {
         foreach (var x in _updatesToRemove)
         {
             _scheduledUpdates.Remove(new ScheduledUpdate(x, 0, 0), UpdateEquality.Instance);
         }
         _updatesToRemove.Clear();
         foreach (var x in _updatesToAdd)
         {
             _scheduledUpdates.Insert(x, x.NextUpdate);
         }
         _updatesToAdd.Clear();
     }
 }
예제 #4
0
 /// <summary>
 /// Add a node to m_openNodes.
 /// </summary>
 /// <param name="node">The newly created node.</param>
 /// <param name="estimatedDistance">Distance from start to node + estimated distance to target.</param>
 public void AddOpenNode(ref PathNode node, float estimatedDistance)
 {
     if (m_openNodes.Count == MaxOpenNodes)
     {
         m_openNodes.RemoveMax();
     }
     m_openNodes.Insert(node, estimatedDistance);
 }
예제 #5
0
            private void Insert(int node)
            {
                var      box = _tree.GetAabb(node);
                Vector3D test;

                Vector3D.Clamp(ref _vec, ref box.Min, ref box.Max, out test);
                var dist = Vector3D.DistanceSquared(test, _vec);

                _tmp.Insert(node, dist);
            }
예제 #6
0
        public void QueueEntity(MyEntity entity)
        {
            long time = Time();

            time += EntityPreserveTime;

            m_entities.Insert(new EntityReference
            {
                Entity = entity
            }, time);

            m_index.Add(entity.EntityId);

            if (UpdateOrder == MyUpdateOrder.NoUpdate)
            {
                SetUpdateOrder(MyUpdateOrder.AfterSimulation);
            }
        }