public static void GetAllEntitiesInBox(ref BoundingBoxD box, List <MyEntity> result)
        {
            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MyGamePruningStructure::GetAllEntitiesInBox");

            m_topMostEntitiesTree.OverlapAllBoundingBox <MyEntity>(ref box, result, 0, false);
            int topmostCount = result.Count;

            for (int i = 0; i < topmostCount; i++)
            {
                if (result[i].Hierarchy != null)
                {
                    result[i].Hierarchy.QueryAABB(ref box, result);
                }
            }
            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
        }
 protected void OverlapAllBoundingBox(ref BoundingBoxD box, List <MyObjectSeed> list)
 {
     m_cellsTree.OverlapAllBoundingBox(ref box, m_tempProceduralCellsList);
     foreach (var cell in m_tempProceduralCellsList)
     {
         cell.OverlapAllBoundingBox(ref box, list);
     }
     m_tempProceduralCellsList.Clear();
 }
Exemplo n.º 3
0
        public static void GetAllEntitiesInBox(ref BoundingBoxD box, List <MyEntity> result, MyEntityQueryType qtype = MyEntityQueryType.Both)
        {
            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MyGamePruningStructure::GetAllEntitiesInBox");

            if (qtype.HasDynamic())
            {
                m_dynamicObjectsTree.OverlapAllBoundingBox <MyEntity>(ref box, result, 0, false);
            }
            if (qtype.HasStatic())
            {
                m_staticObjectsTree.OverlapAllBoundingBox <MyEntity>(ref box, result, 0, false);
            }

            int topmostCount = result.Count;

            for (int i = 0; i < topmostCount; i++)
            {
                if (result[i].Hierarchy != null)
                {
                    result[i].Hierarchy.QueryAABB(ref box, result);
                }
            }
            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
        }
Exemplo n.º 4
0
        private void OnPositionChanged(MyPositionComponentBase obj)
        {
            var ent = obj.Container?.Entity;

            if (ent == null)
            {
                return;
            }
            var player = MyAPIGateway.Players.GetPlayerControllingEntity(ent);

            if (player == null)
            {
                return;
            }
            HashSet <ResearchStatefulKey> activated;

            if (!_activatedEntries.TryGetValue(player.IdentityId, out activated) || activated.Count == 0)
            {
                return;
            }
            var worldBox = obj.WorldAABB;

            _detectorTree.OverlapAllBoundingBox(ref worldBox, _matchingDetectors);
            if (_matchingDetectors.Count == 0)
            {
                return;
            }
            var playerState = Manager.GetOrCreatePlayer(player);

            foreach (var k in _matchingDetectors)
            {
                if (worldBox.Intersects(k.Detector) && activated.Contains(k.Key))
                {
                    var prs = playerState.PlayerResearchState(k.Key.ResearchKey);
                    prs?.UpdateStatefulStorage(k.Key.StatefulKey, true);
                }
            }
        }
 public static void GetAllVoxelMapsInBox(ref BoundingBoxD box, List <MyVoxelBase> result)
 {
     VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MyGamePruningStructure::GetAllVoxelMapsInBox");
     m_voxelMapsTree.OverlapAllBoundingBox <MyVoxelBase>(ref box, result, 0, false);
     VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
 }
Exemplo n.º 6
0
        public ulong AddObject(BoundingBoxD bbox, Vector3 velocity, IMyActivationHandler activationHandler, ulong?customId)
        {
            if (SingleCluster.HasValue && m_clusters.Count == 0)
            {
                BoundingBoxD bb = SingleCluster.Value;
                bb.Inflate(200); //inflate 200m so objects near world border have AABB inside => physics created
                CreateCluster(ref bb);
            }

            BoundingBoxD inflatedBBox;

            if (SingleCluster.HasValue)
            {
                inflatedBBox = bbox;
            }
            else
            {
                inflatedBBox = bbox.GetInflated(MinimumDistanceFromBorder);
            }

            m_clusterTree.OverlapAllBoundingBox(ref inflatedBBox, m_returnedClusters);

            MyCluster cluster     = null;
            bool      needReorder = false;

            if (m_returnedClusters.Count == 1)
            {
                if (m_returnedClusters[0].AABB.Contains(inflatedBBox) == ContainmentType.Contains)
                {
                    cluster = m_returnedClusters[0];
                }
                else
                if (m_returnedClusters[0].AABB.Contains(inflatedBBox) == ContainmentType.Intersects && activationHandler.IsStaticForCluster)
                {
                    if (m_returnedClusters[0].AABB.Contains(bbox) == ContainmentType.Disjoint)
                    {       //completely out
                    }
                    else
                    {
                        cluster = m_returnedClusters[0];
                    }
                }
                else
                {
                    needReorder = true;
                }
            }
            else
            if (m_returnedClusters.Count > 1)
            {
                needReorder = true;
            }
            else
            if (m_returnedClusters.Count == 0)
            {
                if (!activationHandler.IsStaticForCluster)
                {
                    var clusterBB = new BoundingBoxD(bbox.Center - IdealClusterSize / 2, bbox.Center + IdealClusterSize / 2);
                    m_clusterTree.OverlapAllBoundingBox(ref clusterBB, m_returnedClusters);

                    if (m_returnedClusters.Count == 0)
                    {     //Space is empty, create new cluster
                        m_staticTree.OverlapAllBoundingBox(ref clusterBB, m_objectDataResultList);
                        cluster = CreateCluster(ref clusterBB);

                        foreach (var ob in m_objectDataResultList)
                        {
                            System.Diagnostics.Debug.Assert(m_objectsData[ob].Cluster == null, "Found object must not be in cluster!");
                            AddObjectToCluster(cluster, ob, false);
                        }
                    }
                    else      //There is still some blocking cluster
                    {
                        needReorder = true;
                    }
                }
            }

            ulong objectId       = customId.HasValue ? customId.Value : m_clusterObjectCounter++;
            int   staticObjectId = MyDynamicAABBTreeD.NullNode;

            m_objectsData[objectId] = new MyObjectData()
            {
                Id                = objectId,
                Cluster           = cluster,
                ActivationHandler = activationHandler,
                AABB              = bbox,
                StaticId          = staticObjectId
            };

            System.Diagnostics.Debug.Assert(!needReorder || (!SingleCluster.HasValue && needReorder), "Object cannot be added outside borders of a single cluster");

            if (needReorder && !SingleCluster.HasValue)
            {
                System.Diagnostics.Debug.Assert(cluster == null, "Error in cluster logic");

                ReorderClusters(bbox, objectId);
                if (!m_objectsData[objectId].ActivationHandler.IsStaticForCluster)
                {
                    System.Diagnostics.Debug.Assert(m_objectsData[objectId].Cluster != null, "Object not added");
                }
#if DEBUG
                m_clusterTree.OverlapAllBoundingBox(ref bbox, m_returnedClusters);

                System.Diagnostics.Debug.Assert(m_returnedClusters.Count <= 1, "Clusters overlap!");
                if (m_returnedClusters.Count != 0)
                {
                    System.Diagnostics.Debug.Assert(activationHandler.IsStaticForCluster ? m_returnedClusters[0].AABB.Contains(inflatedBBox) != ContainmentType.Disjoint : m_returnedClusters[0].AABB.Contains(inflatedBBox) == ContainmentType.Contains, "Clusters reorder failure!");
                }
#endif
            }

            if (activationHandler.IsStaticForCluster)
            {
                staticObjectId = m_staticTree.AddProxy(ref bbox, objectId, 0);

                m_objectsData[objectId].StaticId = staticObjectId;
            }

            if (cluster != null)
            {
                return(AddObjectToCluster(cluster, objectId, false));
            }
            else
            {
                return(objectId);
            }
        }
 public void OverlapAllBoundingBox(ref BoundingBoxD box, List <MyObjectSeed> list, bool clear = false)
 {
     m_tree.OverlapAllBoundingBox(ref box, list, 0, clear);
 }
Exemplo n.º 8
0
 public override void GetReplicablesInBox(BoundingBoxD aabb, List <IMyReplicable> list)
 {
     m_rootsAABB.OverlapAllBoundingBox(ref aabb, list);
 }
Exemplo n.º 9
0
 public void GetAllShieldsInBox(BoundingBoxD box, List <DefenseShields> result)
 {
     _aabbTree.OverlapAllBoundingBox(ref box, result, 0U, false);
 }
Exemplo n.º 10
0
 private void Hierarchy_QueryAABB(BoundingBoxD query, List <MyEntity> results)
 {
     m_sectors.OverlapAllBoundingBox <MyEntity>(ref query, results, clear: false);
 }
 static void GetEntitiesFromPrunningStructure(MyDynamicAABBTreeD tree, ref BoundingBoxD boundingBox, List<MyElement> list)
 {
     tree.OverlapAllBoundingBox(ref boundingBox, list, 0, false);
 }
 public static void GetAllSensableEntitiesInBox <T>(ref BoundingBoxD box, List <T> result)
 {
     VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MyGamePruningStructure::GetAllSensableEntitiesInBox");
     m_sensableTree.OverlapAllBoundingBox <T>(ref box, result, 0, false);
     VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
 }
Exemplo n.º 13
0
 public void GetAllInBox(List <T> result, ref BoundingBoxD box, uint flags = 0)
 {
     tree.OverlapAllBoundingBox(ref box, result, flags, false);
 }
Exemplo n.º 14
0
 public void GetAllEntitiesInBox <T>(ref BoundingBoxD box, List <T> result)
 {
     MathTree.OverlapAllBoundingBox <T>(ref box, result, 0, false);
 }