Exemplo n.º 1
0
        public static void Add(MyEntity entity)
        {
            Debug.Assert(entity.Parent == null, "Only topmost entities");

            if (entity.TopMostPruningProxyId != MyVRageConstants.PRUNING_PROXY_ID_UNITIALIZED)
            {
                return;                                                                                 // already inserted
            }
            BoundingBoxD bbox = GetEntityAABB(entity);

            if (bbox.Size == Vector3D.Zero)
            {
                return;                              // don't add entities with zero bounding boxes
            }
            if (IsEntityStatic(entity))
            {
                entity.TopMostPruningProxyId     = m_staticObjectsTree.AddProxy(ref bbox, entity, 0);
                entity.StaticForPruningStructure = true;
            }
            else
            {
                entity.TopMostPruningProxyId     = m_dynamicObjectsTree.AddProxy(ref bbox, entity, 0);
                entity.StaticForPruningStructure = false;
            }

            var voxelMap = entity as MyVoxelBase;

            if (voxelMap != null)
            {
                voxelMap.VoxelMapPruningProxyId = m_voxelMapsTree.AddProxy(ref bbox, entity, 0);
            }
        }
        protected void GenerateObjectSeeds(ref BoundingSphereD sphere)
        {
            ProfilerShort.Begin("GenerateObjectSeedsInBox");

            BoundingBoxD box = BoundingBoxD.CreateFromSphere(sphere);

            Vector3I cellId = Vector3I.Floor(box.Min / CELL_SIZE);

            for (var iter = GetCellsIterator(sphere); iter.IsValid(); iter.GetNext(out cellId))
            {
                if (m_cells.ContainsKey(cellId))
                {
                    continue;
                }

                var cellBox = new BoundingBoxD(cellId * CELL_SIZE, (cellId + 1) * CELL_SIZE);
                if (sphere.Contains(cellBox) == ContainmentType.Disjoint)
                {
                    continue;
                }

                var cell = GenerateProceduralCell(ref cellId);
                if (cell != null)
                {
                    m_cells.Add(cellId, cell);
                    var cellBBox = cell.BoundingVolume;
                    cell.proxyId = m_cellsTree.AddProxy(ref cellBBox, cell, 0);
                }
            }
            ProfilerShort.End();
        }
Exemplo n.º 3
0
        private int ConcealGroup(ConcealGroup group)
        {
            if (ConcealedGroups.Any(g => g.Id == group.Id))
            {
                return(0);
            }

            Log.Debug($"Concealing grids: {group.GridNames}");
            group.Conceal();
            foreach (var entity in group.Grids)
            {
                entity.GetStorage().SetValue(Id, "True");
            }

            group.UpdateAABB();
            var aabb = group.WorldAABB;

            group.ProxyId  = _concealedAabbTree.AddProxy(ref aabb, group, 0);
            group.Closing += Group_Closing;
            Task.Run(() =>
            {
                group.UpdatePostConceal();
                Log.Debug($"Group {group.Id} cached");
                group.IsConcealed = true;
                Torch.Invoke(() => ConcealedGroups.Add(group));
            });
            return(group.Grids.Count);
        }
Exemplo n.º 4
0
 public void Add(ref BoundingBoxD box, T obj, uint flags = 0)
 {
     boxes[indexes[obj] = tree.AddProxy(ref box, obj, flags)] = new AABBKeeper()
     {
         Box = box
     };
 }
        /// <summary>
        /// Generates all Cells data that are within sphere, if they have not been generated.
        /// </summary>
        /// <param name="sphere">Bounding Sphere of the cells to generate</param>
        protected void GenerateObjectsData(ref BoundingSphereD sphere)
        {
            BoundingBoxD box = BoundingBoxD.CreateFromSphere(sphere);

            Vector3I cellId = Vector3I.Floor(box.Min / CELL_SIZE);

            for (var it = GetCellsIterator(sphere); it.IsValid(); it.GetNext(out cellId))
            {
                if (m_cells.ContainsKey(cellId))
                {
                    continue;
                }

                BoundingBoxD cellBounds = new BoundingBoxD(cellId * CELL_SIZE, (cellId + 1) * CELL_SIZE);
                if (!(sphere.Contains(cellBounds) != ContainmentType.Disjoint))
                {
                    continue;
                }

                MyProceduralCell cell = GenerateCell(ref cellId);
                if (cell != null)
                {
                    m_cells.Add(cellId, cell);

                    BoundingBoxD aabb = cell.BoundingVolume;
                    cell.proxyId = m_cellsTree.AddProxy(ref aabb, cell, 0u);
                }
            }
        }
Exemplo n.º 6
0
 public static void AddPlaceArea(MyPlaceArea area)
 {
     if (area.PlaceAreaProxyId == MyConstants.PRUNING_PROXY_ID_UNITIALIZED)
     {
         BoundingBoxD box = area.PositionComp.WorldAABB;
         area.PlaceAreaProxyId = m_aabbTree.AddProxy(ref box, area, 0);
     }
 }
Exemplo n.º 7
0
 public static void AddBroadcaster(MyRadioBroadcaster broadcaster)
 {
     if (broadcaster.RadioProxyID == MyConstants.PRUNING_PROXY_ID_UNITIALIZED)
     {
         BoundingBoxD box = BoundingBoxD.CreateFromSphere(new BoundingSphereD(broadcaster.BroadcastPosition, broadcaster.BroadcastRadius));
         broadcaster.RadioProxyID = m_aabbTree.AddProxy(ref box, broadcaster, 0);
     }
 }
Exemplo n.º 8
0
            internal bool OnAddedToScene(MyClipmapCellProxy cellProxy)
            {
                if (!IsUsed())
                {
                    return(false);
                }

                bool         lodAabbChanged = false;
                int          rootProxy      = m_boundingBoxes.GetRoot();
                BoundingBoxD lodAabbBefore  = BoundingBoxD.CreateInvalid();

                if (rootProxy != -1)
                {
                    lodAabbBefore = m_boundingBoxes.GetAabb(rootProxy);
                }

                BoundingBoxD cellAabb = (BoundingBoxD)cellProxy.LocalAabb;

                m_cellProxyToAabbProxy.Add(cellProxy, m_boundingBoxes.AddProxy(ref cellAabb, null, 0));

                if (rootProxy != -1)
                {
                    BoundingBoxD lodAabbAfter = m_boundingBoxes.GetAabb(rootProxy);
                    lodAabbChanged = lodAabbBefore.Equals(lodAabbAfter);
                }

                if (lodAabbChanged)
                {
                    InvalidateAllMergedMeshesInLod();
                }

                Vector3D translation = cellProxy.Translation;
                int      divideIndex = GetDivideIndex(ref translation);

                m_trackedActors[divideIndex].Add(cellProxy.Actor);

                MyMergedLodMeshId mergedLodMeshId = MyMeshes.GetMergedLodMesh(m_mergedLodMeshProxies[divideIndex].MeshId, 0);
                LodMeshId         lodMeshToMerge  = MyMeshes.GetLodMesh(cellProxy.MeshId, 0);
                bool mergedMesh = mergedLodMeshId.MergeLodMesh(lodMeshToMerge);

                if (mergedMesh)
                {
                    InvalidateAllMergedMeshesInLod();
                }

                TryCancelMergeJob(divideIndex, MeshId.NULL);
                bool startedMerge = TryStartMergeJob(divideIndex, 1000);

                bool shouldMarkDirty = !mergedMesh && !startedMerge;

                if (shouldMarkDirty)
                {
                    m_dirtyProxyIndices.Add(divideIndex);
                }

                return(shouldMarkDirty);
            }
Exemplo n.º 9
0
        public void AddShield(DefenseShields shield)
        {
            if (shield.DtreeProxyId != -1)
            {
                return;
            }
            BoundingBoxD worldAabb = shield.WebBox;

            shield.DtreeProxyId = _aabbTree.AddProxy(ref worldAabb, shield, 0U, true);
        }
Exemplo n.º 10
0
 private bool AddToTree(ProceduralObject t)
 {
     if (t.m_proxyID != -1)
     {
         return(false);
     }
     t.m_proxyID  = m_tree.AddProxy(ref t.m_boundingBox, t, 0);
     t.OnMoved   += ObjectMoved;
     t.OnRemoved += RemoveFromTree;
     return(true);
 }
Exemplo n.º 11
0
        override protected void AddRoot(IMyReplicable replicable)
        {
            System.Diagnostics.Debug.Assert(!replicable.HasToBeChild, "Cannot add children replicables to root!");

            m_roots.Add(replicable);

            BoundingBoxD aabb = replicable.GetAABB();

            m_proxies.Add(replicable, m_rootsAABB.AddProxy(ref aabb, replicable, 0));

            replicable.OnAABBChanged += OnRootMoved;
        }
Exemplo n.º 12
0
 public static void AddBroadcaster(MyRadioBroadcaster broadcaster)
 {
     if (broadcaster.Parent is MyCubeBlock)
     {
         MyCubeGrid grid = (broadcaster.Parent as MyCubeBlock).CubeGrid;
         Debug.Assert(grid.InScene, "adding broadcaster when grid is not in scene");
     }
     if (broadcaster.RadioProxyID == MyConstants.PRUNING_PROXY_ID_UNITIALIZED)
     {
         BoundingBoxD box = BoundingBoxD.CreateFromSphere(new BoundingSphereD(broadcaster.BroadcastPosition, broadcaster.BroadcastRadius));
         broadcaster.RadioProxyID = m_aabbTree.AddProxy(ref box, broadcaster, 0);
     }
 }
        public static void Add(MyEntity entity)
        {
            if (entity.GamePruningProxyId != MyConstants.PRUNING_PROXY_ID_UNITIALIZED)
            {
                return;                                                                         // already inserted
            }
            BoundingBoxD bbox = GetEntityAABB(entity);

            if (bbox.Size == Vector3D.Zero)
            {
                return;                              // don't add entities with zero bounding boxes
            }
            entity.GamePruningProxyId = m_aabbTree.AddProxy(ref bbox, entity, 0);

            bool isTarget = false;

            if (MyFakes.SHOW_FACTIONS_GUI)
            {
                var        moduleOwner = entity as IMyComponentOwner <MyIDModule>;
                MyIDModule module;
                if (moduleOwner != null && moduleOwner.GetComponent(out module))
                {
                    isTarget = true;
                }
            }
            foreach (var targetType in TargetTypes)
            {
                if (targetType == entity.GetType())
                {
                    isTarget = true;
                    break;
                }
            }

            if (isTarget)
            {
                entity.TargetPruningProxyId = m_targetsTree.AddProxy(ref bbox, entity, 0);
            }

            if (SensableTypes.Contains(entity.GetType()))
            {
                entity.SensablePruningProxyId = m_sensableTree.AddProxy(ref bbox, entity, 0);
            }

            var voxelMap = entity as MyVoxelMap;

            if (voxelMap != null)
            {
                voxelMap.VoxelMapPruningProxyId = m_voxelMapsTree.AddProxy(ref bbox, entity, 0);
            }
        }
Exemplo n.º 14
0
        private void EnsureDetector(string researchKey, Ob_Trigger_Location trigger)
        {
            var key = new ResearchStatefulKey(researchKey, trigger.StateStorageKey);

            if (_detectors.ContainsKey(key))
            {
                return;
            }
            var data = new DetectorData(key, trigger);

            _detectors.Add(key, data);
            var aabb = BoundingBoxD.CreateFromSphere(data.Detector);

            data.Handle = _detectorTree.AddProxy(ref aabb, data, 0);
        }
Exemplo n.º 15
0
        internal static int UpdateBvh(MyDynamicAABBTreeD bvh, LightId lid, bool enabled, int proxy, ref BoundingBoxD aabb)
        {
            if (enabled && proxy == -1)
            {
                return(bvh.AddProxy(ref aabb, lid, 0));
            }
            else if (enabled && proxy != -1)
            {
                bvh.MoveProxy(proxy, ref aabb, Vector3.Zero);
                return(proxy);
            }
            else
            {
                bvh.RemoveProxy(proxy);
            }

            return(-1);
        }
Exemplo n.º 16
0
        public void Add(AABBEntity entity)
        {
            int proxyId = GetProxyIdForEntity(entity);

            Log.Trace("Add entity " + proxyId, "Add");

            BoundingBoxD bbox = GetEntityAABB(entity);

            if (bbox.Size == Vector3D.Zero)
            {
                return;                              // don't add entities with zero bounding boxes
            }
            int newProxyId = MathTree.AddProxy(ref bbox, entity, 0);

            SetProxyIdForEntity(entity, newProxyId);

            Log.Trace("Finished Add entity " + newProxyId, "Add");
        }
Exemplo n.º 17
0
        private MyCluster CreateCluster(ref BoundingBoxD clusterBB)
        {
            MyCluster cluster = new MyCluster()
            {
                AABB    = clusterBB,
                Objects = new HashSet <ulong>()
            };

            cluster.ClusterId = m_clusterTree.AddProxy(ref cluster.AABB, cluster, 0);

            if (OnClusterCreated != null)
            {
                cluster.UserData = OnClusterCreated(cluster.ClusterId, cluster.AABB);
            }

            m_clusters.Add(cluster);
            m_userObjects.Add(cluster.UserData);

            return(cluster);
        }
Exemplo n.º 18
0
        private MyCluster CreateCluster(ref BoundingBoxD clusterBB)
        {
            MyCluster cluster = new MyCluster() //Center = {X:-10968.2552425968 Y:-3958.99401506744 Z:-188.682065703847} Max = {X:11118.0759795131 Y:11202.10024965 Z:11287.440539642}Min = {X:-33054.5864647067 Y:-19120.0882797849 Z:-11664.8046710497}
            {
                AABB    = clusterBB,
                Objects = new HashSet <ulong>()
            };

            cluster.ClusterId = m_clusterTree.AddProxy(ref cluster.AABB, cluster, 0);

            if (OnClusterCreated != null)
            {
                cluster.UserData = OnClusterCreated(cluster.ClusterId, cluster.AABB);
            }

            m_clusters.Add(cluster);
            m_userObjects.Add(cluster.UserData);

            return(cluster);
        }
Exemplo n.º 19
0
        public void AddChildEntity(MyEntity child)
        {
            if (MyFakes.ENABLE_PLANET_HIERARCHY)
            {
                var bbox = child.PositionComp.WorldAABB;

                ProfilerShort.Begin("Add sector to tree.");
                int proxyId = m_sectors.AddProxy(ref bbox, child, 0);
                ProfilerShort.BeginNextBlock("Add to child hierarchy.");
                Hierarchy.AddChild(child, true);
                ProfilerShort.End();

                MyHierarchyComponentBase childHierarchy = child.Components.Get <MyHierarchyComponentBase>();
                childHierarchy.ChildId = proxyId;
            }
            else
            {
                MyEntities.Add(child);
            }
        }
        /// <summary>
        /// Generates all marked to be loaded cells seeds
        /// </summary>
        public void LoadCells()
        {
            m_toLoadCells.ApplyAdditions();

            foreach (var cellId in m_toLoadCells)
            {
                if (m_loadedCells.ContainsKey(cellId))
                {
                    continue;
                }

                MyProceduralCell cell = GenerateCellSeeds(cellId);
                if (cell != null)
                {
                    m_loadedCells.Add(cellId, cell);

                    BoundingBoxD aabb = cell.BoundingVolume;
                    cell.proxyId = m_cellsTree.AddProxy(ref aabb, cell, 0u);
                }
            }

            m_toLoadCells.Clear();
        }
Exemplo n.º 21
0
        public static void Add(MyEntity entity)
        {
            Debug.Assert(entity.Parent == null, "Only topmost entities");

            if (entity.TopMostPruningProxyId != MyConstants.PRUNING_PROXY_ID_UNITIALIZED)
            {
                return;                                                                            // already inserted
            }
            BoundingBoxD bbox = GetEntityAABB(entity);

            if (bbox.Size == Vector3D.Zero)
            {
                return;                              // don't add entities with zero bounding boxes
            }
            entity.TopMostPruningProxyId = m_topMostEntitiesTree.AddProxy(ref bbox, entity, 0);

            var voxelMap = entity as MyVoxelBase;

            if (voxelMap != null)
            {
                voxelMap.VoxelMapPruningProxyId = m_voxelMapsTree.AddProxy(ref bbox, entity, 0);
            }
        }
Exemplo n.º 22
0
        internal static int UpdateBvh(MyDynamicAABBTreeD bvh, LightId lid, bool enabled, int proxy, ref BoundingBoxD aabb)
        {
            if(enabled && proxy == -1)
            {
                return bvh.AddProxy(ref aabb, lid, 0);
            }
            else if(enabled && proxy != -1)
            {
                bvh.MoveProxy(proxy, ref aabb, Vector3.Zero);
                return proxy;
            }
            else
            {
                bvh.RemoveProxy(proxy);
            }

            return -1;
        }
Exemplo n.º 23
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 AddObject(MyObjectSeed objectSeed)
        {
            var bbox = objectSeed.BoundingVolume;

            objectSeed.m_proxyId = m_tree.AddProxy(ref bbox, objectSeed, 0);
        }