Exemplo n.º 1
0
        protected override void CloseObjectSeed(MyObjectSeed objectSeed)
        {
            switch (objectSeed.Params.Type)
            {
            case MyObjectSeedType.Asteroid:
            case MyObjectSeedType.AsteroidCluster:
                var bbox = objectSeed.BoundingVolume;
                MyGamePruningStructure.GetAllVoxelMapsInBox(ref bbox, m_tmpVoxelMapsList);

                String storageName = string.Format("Asteroid_{0}_{1}_{2}_{3}_{4}", objectSeed.CellId.X, objectSeed.CellId.Y, objectSeed.CellId.Z, objectSeed.Params.Index, objectSeed.Params.Seed);

                foreach (var voxelBase in m_tmpVoxelMapsList)
                {
                    if (voxelBase.StorageName == storageName)
                    {
                        if (!voxelBase.Save)
                        {
                            voxelBase.Close();
                        }
                        break;
                    }
                }
                m_tmpVoxelMapsList.Clear();
                break;

            case MyObjectSeedType.EncounterAlone:
            case MyObjectSeedType.EncounterSingle:
                MyEncounterGenerator.RemoveEncounter(objectSeed.BoundingVolume, objectSeed.Params.Seed);
                break;

            default:
                throw new InvalidBranchException();
                break;
            }
        }
        public MyPlanet GetClosestContainingPlanet(Vector3D point)
        {
            m_voxels.Clear();
            BoundingBoxD b = new BoundingBoxD(point, point);

            MyGamePruningStructure.GetAllVoxelMapsInBox(ref b, m_voxels);

            double dist = double.PositiveInfinity;

            MyPlanet p = null;

            foreach (var v in m_voxels)
            {
                if (v is MyPlanet)
                {
                    var d = Vector3.Distance(v.WorldMatrix.Translation, point);
                    if (d < dist)
                    {
                        dist = d;
                        p    = (MyPlanet)v;
                    }
                }
            }

            return(p);
        }
Exemplo n.º 3
0
        protected override void CloseObjectSeed(MyObjectSeed objectSeed)
        {
            IMyAsteroidFieldDensityFunction func = objectSeed.UserData as IMyAsteroidFieldDensityFunction;

            if (func != null)
            {
                ChildrenRemoveDensityFunctionRemoved(func);
            }

            var bbox = objectSeed.BoundingVolume;

            MyGamePruningStructure.GetAllVoxelMapsInBox(ref bbox, m_tmpVoxelMapsList);

            String storageName = string.Format("{0}_{1}_{2}_{3}_{4}_{5}", objectSeed.Params.Type, objectSeed.CellId.X, objectSeed.CellId.Y, objectSeed.CellId.Z, objectSeed.Params.Index, objectSeed.Params.Seed);

            foreach (var voxelBase in m_tmpVoxelMapsList)
            {
                if (voxelBase.StorageName == storageName)
                {
                    if (!voxelBase.Save)
                    {
                        voxelBase.Close();
                    }
                    break;
                }
            }
            m_tmpVoxelMapsList.Clear();
        }
Exemplo n.º 4
0
        private void PerformCellMarking(List <Vector3D> updatePositions)
        {
            ProfilerShort.Begin("Cell marking");
            Vector3D offset = new Vector3D(1.0f);

            foreach (var pos in updatePositions)
            {
                BoundingBoxD box = new BoundingBoxD(pos - offset, pos + offset);

                ProfilerShort.Begin("GetVoxelMaps");
                m_tmpVoxelMaps.Clear();
                MyGamePruningStructure.GetAllVoxelMapsInBox(ref box, m_tmpVoxelMaps);
                ProfilerShort.End();

                foreach (var map in m_tmpVoxelMaps)
                {
                    MyVoxelNavigationMesh mesh = null;
                    m_navigationMeshes.TryGetValue(map, out mesh);
                    if (mesh == null)
                    {
                        continue;
                    }

                    mesh.MarkBoxForAddition(box);
                }
            }
            m_tmpVoxelMaps.Clear();
            ProfilerShort.End();
        }
        public override void CloseObject(MyObjectSeed obj)
        {
            List <MyVoxelBase> voxelMaps = new List <MyVoxelBase>();
            var bounds = obj.BoundingVolume;

            MyGamePruningStructure.GetAllVoxelMapsInBox(ref bounds, voxelMaps);

            string storageName = string.Format("Asteroid_{0}_{1}_{2}_{3}_{4}", obj.CellId.X, obj.CellId.Y, obj.CellId.Z, obj.Params.Index, obj.Params.Seed);

            foreach (MyVoxelBase map in voxelMaps)
            {
                if (map.StorageName == storageName)
                {
                    if (m_NotSavedMaps.Contains(map))
                    {
                        Action <MyEntity> onClose = null;
                        onClose = delegate
                        {
                            obj.Params.Generated = false;
                            map.OnClose         -= onClose;
                        };
                        map.Save = false;
                        map.Close();
                        map.OnClose += onClose;
                        m_NotSavedMaps.Remove(map);
                    }
                    break;
                }
            }

            voxelMaps.Clear();
        }
        private void GatherEnvItemsInBoxes()
        {
            var work = Interlocked.Exchange(ref m_cubeBlocksPending, m_cubeBlocksToWork);

            m_cubeBlocksToWork = work;

            int itemsVisited  = 0;
            int blocksVisited = 0;

            ProfilerShort.Begin("PlanetEnvironment::GatherItemsInSlimBlocks()");
            foreach (var grid in work.Values)
            {
                for (int blockIndex = 0; blockIndex < grid.Count; ++blockIndex)
                {
                    BoundingBoxD blockAabb = grid[blockIndex];

                    MyGamePruningStructure.GetAllVoxelMapsInBox(ref blockAabb, m_tmpVoxelList);
                    blocksVisited++;

                    for (int i = 0; i < m_tmpVoxelList.Count; ++i)
                    {
                        var p = m_tmpVoxelList[i] as MyPlanet;

                        if (p == null)
                        {
                            continue;
                        }

                        p.Hierarchy.QueryAABB(ref blockAabb, m_tmpEntityList);

                        for (int j = 0; j < m_tmpEntityList.Count; ++j)
                        {
                            var sector = m_tmpEntityList[j] as MyEnvironmentSector;

                            if (sector == null)
                            {
                                return;
                            }

                            var bb = blockAabb;
                            sector.GetItemsInAabb(ref bb, m_itemsToDisable.GetOrAddList(sector));
                            if (sector.DataView != null && sector.DataView.Items != null)
                            {
                                itemsVisited += sector.DataView.Items.Count;
                            }
                        }

                        m_tmpEntityList.Clear();
                    }

                    m_tmpVoxelList.Clear();
                }
            }
            ProfilerShort.End();

            //Debug.Print("Processed {0} blocks with {1} items", blocksVisited, itemsVisited);

            work.Clear();
        }
Exemplo n.º 7
0
        public override void GenerateObjects(List <MyObjectSeed> objectsList, HashSet <MyObjectSeedParams> existingObjectsSeeds)
        {
            ProfilerShort.Begin("GenerateObjects");
            foreach (var objectSeed in objectsList)
            {
                if (objectSeed.Params.Generated)
                {
                    continue;
                }

                objectSeed.Params.Generated = true;

                using (MyRandom.Instance.PushSeed(GetObjectIdSeed(objectSeed)))
                {
                    ProfilerShort.Begin(objectSeed.Params.Type.ToString());

                    var bbox = objectSeed.BoundingVolume;
                    MyGamePruningStructure.GetAllVoxelMapsInBox(ref bbox, m_tmpVoxelMapsList);

                    String storageName = string.Format("{0}_{1}_{2}_{3}_{4}_{5}", objectSeed.Params.Type, objectSeed.CellId.X, objectSeed.CellId.Y, objectSeed.CellId.Z, objectSeed.Params.Index, objectSeed.Params.Seed);

                    bool exists = false;
                    foreach (var voxelMap in m_tmpVoxelMapsList)
                    {
                        if (voxelMap.StorageName == storageName)
                        {
                            existingObjectsSeeds.Add(objectSeed.Params);
                            exists = true;
                            break;
                        }
                    }
                    m_tmpVoxelMapsList.Clear();

                    if (!exists)
                    {
                        /*  var planet = MyWorldGenerator.AddPlanet(storageName, objectSeed.BoundingVolume.Center - VRageMath.MathHelper.GetNearestBiggerPowerOfTwo(objectSeed.Size) / 2, objectSeed.Seed, objectSeed.Size, GetPlanetEntityId(objectSeed), objectSeed.Type == MyObjectSeedType.Moon);
                         *
                         * if (planet == null)
                         * {
                         *    continue;
                         * }
                         * planet.Save = false;
                         * RangeChangedDelegate OnStorageRangeChanged = null;
                         * OnStorageRangeChanged = delegate(Vector3I minVoxelChanged, Vector3I maxVoxelChanged, MyStorageDataTypeFlags changedData)
                         * {
                         *    planet.Save = true;
                         *    planet.Storage.RangeChanged -= OnStorageRangeChanged;
                         * };
                         * planet.Storage.RangeChanged += OnStorageRangeChanged;*/
                    }
                    ProfilerShort.End();
                }
            }
            ProfilerShort.End();
        }
Exemplo n.º 8
0
        private bool IsInVoxel(IMyTerminalBlock block)
        {
            BoundingBoxD       blockWorldAABB = block.PositionComp.WorldAABB; // Axis-Aligned Bounding Box of the block
            List <MyVoxelBase> voxelList      = new List <MyVoxelBase>();

            MyGamePruningStructure.GetAllVoxelMapsInBox(ref blockWorldAABB, voxelList); // Get all voxels in the block's AABB
            var          cubeSize        = block.CubeGrid.GridSize;
            BoundingBoxD localAAABB      = new BoundingBoxD(cubeSize * ((Vector3D)block.Min - 1), cubeSize * ((Vector3D)block.Max + 1));
            var          gridWorldMatrix = block.CubeGrid.WorldMatrix;

            foreach (var map in voxelList)
            {
                if (map.IsAnyAabbCornerInside(ref gridWorldMatrix, localAAABB))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 9
0
        private void PerformCellMarking(List <Vector3D> updatePositions)
        {
            Vector3D vectord = new Vector3D(1.0);

            foreach (Vector3D vectord2 in updatePositions)
            {
                BoundingBoxD box = new BoundingBoxD(vectord2 - vectord, vectord2 + vectord);
                this.m_tmpVoxelMaps.Clear();
                MyGamePruningStructure.GetAllVoxelMapsInBox(ref box, this.m_tmpVoxelMaps);
                foreach (MyVoxelBase base2 in this.m_tmpVoxelMaps)
                {
                    MyVoxelNavigationMesh mesh = null;
                    this.m_navigationMeshes.TryGetValue(base2, out mesh);
                    if (mesh != null)
                    {
                        mesh.MarkBoxForAddition(box);
                    }
                }
            }
            this.m_tmpVoxelMaps.Clear();
        }
Exemplo n.º 10
0
        private bool IsInVoxel(IMyTerminalBlock block)
        {
            BoundingBoxD       blockWorldAABB = block.PositionComp.WorldAABB;
            List <MyVoxelBase> voxelList      = new List <MyVoxelBase>();

            MyGamePruningStructure.GetAllVoxelMapsInBox(ref blockWorldAABB, voxelList);

            var cubeSize = block.CubeGrid.GridSize;

            BoundingBoxD localAABB       = new BoundingBoxD(cubeSize * ((Vector3D)block.Min - 1), cubeSize * ((Vector3D)block.Max + 1));
            var          gridWorldMatrix = block.CubeGrid.WorldMatrix;

            //Logging.Instance.WriteLine($"Total Voxels: {voxelList.Count}.  CubeSize: {cubeSize}.  localAABB: {localAABB}");

            foreach (var map in voxelList)
            {
                if (map.IsAnyAabbCornerInside(ref gridWorldMatrix, localAABB))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 11
0
        public override void UpdateAfterSimulation10()
        {
            base.UpdateAfterSimulation10();

            if (!Sync.IsServer || !IsWorking || !ResourceSink.IsPowered)
            {
                return;
            }

            var rotation1 = Quaternion.CreateFromForwardUp(WorldMatrix.Forward, WorldMatrix.Up);
            var position1 = PositionComp.GetPosition() + Vector3D.Transform(PositionComp.LocalVolume.Center + (m_fieldMax + m_fieldMin) * 0.5f, rotation1);

            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Recreate Field");
            if (m_recreateField)
            {
                m_recreateField = false;
                m_fieldShape.RemoveReference();
                m_fieldShape = GetHkShape();
                ResourceSink.Update();
            }
            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();

            var boundingBox = new BoundingBoxD(m_fieldMin, m_fieldMax).Translate(PositionComp.LocalVolume.Center).Transform(WorldMatrix.GetOrientation()).Translate(PositionComp.GetPosition());

            m_potentialPenetrations.Clear();
            MyGamePruningStructure.GetAllTopMostEntitiesInBox(ref boundingBox, m_potentialPenetrations);

            m_potentialVoxelPenetrations.Clear();
            MyGamePruningStructure.GetAllVoxelMapsInBox(ref boundingBox, m_potentialVoxelPenetrations);

            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Sensor Physics");
            LastDetectedEntity = null;
            if (IsActive)
            {
                bool empty = true;
                foreach (var entity in m_potentialPenetrations)
                {
                    if (entity is MyVoxelBase)
                    {
                        continue;
                    }
                    if (ShouldDetect(entity))
                    {
                        Quaternion rotation2;
                        Vector3    posDiff;
                        HkShape?   shape2;
                        if (GetPropertiesFromEntity(entity, ref position1, out rotation2, out posDiff, out shape2))
                        {
                            if (entity.Physics.HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2))
                            {
                                LastDetectedEntity = entity;
                                empty = false;
                                break;
                            }
                        }
                    }
                }

                foreach (var entity in m_potentialVoxelPenetrations)
                {
                    if (ShouldDetect(entity))
                    {
                        Quaternion rotation2;
                        Vector3    posDiff;
                        HkShape?   shape2;
                        if (GetPropertiesFromEntity(entity, ref position1, out rotation2, out posDiff, out shape2))
                        {
                            if (entity.Physics.HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2))
                            {
                                LastDetectedEntity = entity;
                                empty = false;
                                break;
                            }
                        }
                    }
                }

                if (empty)
                {
                    IsActive = false;
                }
            }
            else
            {
                foreach (var entity in m_potentialPenetrations)
                {
                    if (entity is MyVoxelBase)
                    {
                        continue;
                    }
                    if (ShouldDetect(entity))
                    {
                        Quaternion rotation2;
                        Vector3    posDiff;
                        HkShape?   shape2;
                        if (GetPropertiesFromEntity(entity, ref position1, out rotation2, out posDiff, out shape2))
                        {
                            if (entity.Physics.HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2))
                            {
                                LastDetectedEntity = entity;
                                IsActive           = true;
                                break;
                            }
                        }
                    }
                }

                foreach (var entity in m_potentialVoxelPenetrations)
                {
                    if (ShouldDetect(entity))
                    {
                        Quaternion rotation2;
                        Vector3    posDiff;
                        HkShape?   shape2;
                        if (GetPropertiesFromEntity(entity, ref position1, out rotation2, out posDiff, out shape2))
                        {
                            if (entity.Physics.HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2))
                            {
                                LastDetectedEntity = entity;
                                IsActive           = true;
                                break;
                            }
                        }
                    }
                }
            }
            m_potentialPenetrations.Clear();
            m_potentialVoxelPenetrations.Clear();
            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
        }
        public override void GenerateObjects(List <MyObjectSeed> objects, HashSet <MyObjectSeedParams> existingObjectSeeds)
        {
            List <MyVoxelBase> tmp_voxelMaps = new List <MyVoxelBase>();

            foreach (var obj in objects)
            {
                if (obj.Params.Generated)
                {
                    continue;
                }

                obj.Params.Generated = true;

                using (MyRandom.Instance.PushSeed(GetObjectIdSeed(obj)))
                {
                    if (obj.Params.Type != MyObjectSeedType.Asteroid)
                    {
                        continue;
                    }

                    var bounds = obj.BoundingVolume;
                    MyGamePruningStructure.GetAllVoxelMapsInBox(ref bounds, tmp_voxelMaps);

                    string storageName = string.Format("Asteroid_{0}_{1}_{2}_{3}_{4}", obj.CellId.X, obj.CellId.Y, obj.CellId.Z, obj.Params.Index, obj.Params.Seed);

                    bool exists = false;
                    foreach (var voxelMap in tmp_voxelMaps)
                    {
                        if (voxelMap.StorageName == storageName)
                        {
                            if (!existingObjectSeeds.Contains(obj.Params))
                            {
                                existingObjectSeeds.Add(obj.Params);
                            }
                            exists = true;
                            break;
                        }
                    }

                    if (!exists)
                    {
                        var      storage = CreateAsteroidStorage(GetAsteroidVoxelSize(obj.Size), obj.Params.Seed, obj.Size, m_data.UseGeneratorSeed ? obj.Params.GeneratorSeed : 0, 3);
                        Vector3D pos     = obj.BoundingVolume.Center - MathHelper.GetNearestBiggerPowerOfTwo(obj.Size) / 2;

                        MyVoxelMap voxelMap;

                        voxelMap = MyWorldGenerator.AddVoxelMap(storageName, storage, pos, GetAsteroidEntityId(storageName));
                        if (voxelMap == null)
                        {
                            continue;
                        }
                        voxelMap.Save = true;

                        m_NotSavedMaps.Add(voxelMap);

                        MyVoxelBase.StorageChanged OnStorageRangeChanged = null;
                        OnStorageRangeChanged = delegate(MyVoxelBase voxel, Vector3I minVoxelChanged, Vector3I maxVoxelChanged, MyStorageDataTypeFlags changedData)
                        {
                            voxelMap.Save = true;
                            m_NotSavedMaps.Remove(voxelMap);
                            voxelMap.RangeChanged -= OnStorageRangeChanged;
                        };

                        voxelMap.RangeChanged += OnStorageRangeChanged;
                    }
                    tmp_voxelMaps.Clear();
                }
            }
        }
        public override void CloseObject(MyObjectSeed seed)
        {
            m_existingObjectSeeds.Remove(seed);
            MyVoxelBase voxelMap;

            if (seed.UserData != null)
            {
                if (seed.UserData is MyVoxelBase)
                {
                    voxelMap = seed.UserData as MyVoxelBase;

                    //If the reference cant be found, search the array by comparing storage names.
                    //Only a failsafe, if somehow the voxelmap references differs, should not happen normally.
                    if (!m_tmpAsteroids.Remove(voxelMap))
                    {
                        for (int i = 0; i < m_tmpAsteroids.Count; i++)
                        {
                            if (m_tmpAsteroids[i].StorageName.Equals(voxelMap.StorageName))
                            {
                                m_tmpAsteroids.RemoveAt(i);
                                voxelMap.Save = false;
                                break;
                            }
                        }
                    }
                    else
                    {
                        voxelMap.Save = false;
                    }

                    voxelMap.IsSeedOpen = false;
                    seed.UserData       = null;

                    voxelMap.Close();
                }
            }
            else
            {
                List <MyVoxelBase> voxelMaps = new List <MyVoxelBase>();
                var bounds = seed.BoundingVolume;

                MyGamePruningStructure.GetAllVoxelMapsInBox(ref bounds, voxelMaps);

                string storageName = string.Format("Asteroid_{0}_{1}_{2}_{3}_{4}", seed.CellId.X, seed.CellId.Y, seed.CellId.Z, seed.Params.Index, seed.Params.Seed);

                foreach (MyVoxelBase map in voxelMaps)
                {
                    if (map.StorageName == storageName)
                    {
                        if (m_tmpAsteroids.Contains(map))
                        {
                            map.Save = false;
                        }

                        m_tmpAsteroids.Remove(map);
                        map.IsSeedOpen = false;
                        map.Close();
                        break;
                    }
                }

                voxelMaps.Clear();
            }
        }
Exemplo n.º 14
0
        public static bool CheckEnabled(IMyTerminalBlock Block)
        {
            if (SafeZoneCore.delayControls)
            {
                return(isEnabled);
            }

            var safezoneBlock = Block as IMySafeZoneBlock;

            if (safezoneBlock == null)
            {
                return(isEnabled);
            }

            bool toggleEnabled = safezoneBlock.IsSafeZoneEnabled();

            if (toggleEnabled)
            {
                return(true);
            }

            if (SafeZoneCore.IntermodConfig != null)
            {
                if (SafeZoneCore.IntermodConfig.spawnStalinRoid)
                {
                    if (Vector3D.Distance(Block.GetPosition(), SafeZoneCore.IntermodConfig.stalinRoidGPS) <= SafeZoneCore.IntermodConfig.MaxSpawnCoverage + 2000)
                    {
                        return(false);
                    }
                }

                if (SafeZoneCore.IntermodConfig.enableWarpLocation)
                {
                    if (Vector3D.Distance(Block.GetPosition(), SafeZoneCore.IntermodConfig.warpGateGPS) <= 5000)
                    {
                        return(false);
                    }
                }
            }

            var  grid     = Block.CubeGrid;
            var  cubeGrid = grid as MyCubeGrid;
            bool inVoxel  = false;

            List <IMySlimBlock> blockList      = new List <IMySlimBlock>();
            List <MyVoxelBase>  m_tmpVoxelList = new List <MyVoxelBase>();

            grid.GetBlocks(blockList);
            // MyVisualScriptLogicProvider.ShowNotification("BlockList = " + blockList.Count, 20000, "Red");

            foreach (var block in blockList)
            {
                if (block.CubeGrid.Physics == null)
                {
                    return(false);
                }

                BoundingBoxD boundingBoxD;
                block.GetWorldBoundingBox(out boundingBoxD, false);
                m_tmpVoxelList.Clear();
                MyGamePruningStructure.GetAllVoxelMapsInBox(ref boundingBoxD, m_tmpVoxelList);
                float        gridSize    = block.CubeGrid.GridSize;
                BoundingBoxD aabb        = new BoundingBoxD((double)gridSize * (block.Min - (int)0.5), (double)gridSize * (block.Max + (int)0.5));
                MatrixD      worldMatrix = block.CubeGrid.WorldMatrix;
                using (List <MyVoxelBase> .Enumerator enumerator = m_tmpVoxelList.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        if (enumerator.Current.IsAnyAabbCornerInside(ref worldMatrix, aabb))
                        {
                            inVoxel = true;
                            break;
                        }
                    }
                }
            }

            SafeZoneCore.delayControls = true;
            RefreshControls(Block);

            if (inVoxel)
            {
                if (!CheckEnemies(Block))
                {
                    isEnabled = true;
                    return(true);
                }
            }

            //MyVisualScriptLogicProvider.ShowNotification("Control Disabled - Not in voxel", 10000, "Red");
            isEnabled = false;
            return(false);
        }
Exemplo n.º 15
0
        public override void GenerateObjects(List <MyObjectSeed> objectsList, HashSet <MyObjectSeedParams> existingObjectsSeeds)
        {
            ProfilerShort.Begin("GenerateObjects");
            foreach (var objectSeed in objectsList)
            {
                if (objectSeed.Params.Generated || existingObjectsSeeds.Contains(objectSeed.Params))
                {
                    continue;
                }

                objectSeed.Params.Generated = true;

                using (MyRandom.Instance.PushSeed(GetObjectIdSeed(objectSeed)))
                {
                    switch (objectSeed.Params.Type)
                    {
                    case MyObjectSeedType.Asteroid:
                        ProfilerShort.Begin("Asteroid");

                        var bbox = objectSeed.BoundingVolume;
                        MyGamePruningStructure.GetAllVoxelMapsInBox(ref bbox, m_tmpVoxelMapsList);

                        String storageName = string.Format("Asteroid_{0}_{1}_{2}_{3}_{4}", objectSeed.CellId.X, objectSeed.CellId.Y, objectSeed.CellId.Z, objectSeed.Params.Index, objectSeed.Params.Seed);

                        bool exists = false;
                        foreach (var voxelMap in m_tmpVoxelMapsList)
                        {
                            if (voxelMap.StorageName == storageName)
                            {
                                existingObjectsSeeds.Add(objectSeed.Params);
                                exists = true;
                                break;
                            }
                        }

                        if (!exists)
                        {
                            var           provider = MyCompositeShapeProvider.CreateAsteroidShape(objectSeed.Params.Seed, objectSeed.Size, MySession.Static.Settings.VoxelGeneratorVersion);
                            MyStorageBase storage  = new MyOctreeStorage(provider, GetAsteroidVoxelSize(objectSeed.Size));
                            var           voxelMap = MyWorldGenerator.AddVoxelMap(storageName, storage, objectSeed.BoundingVolume.Center - VRageMath.MathHelper.GetNearestBiggerPowerOfTwo(objectSeed.Size) / 2, GetAsteroidEntityId(storageName));

                            if (voxelMap != null)
                            {
                                voxelMap.Save = false;
                                MyVoxelBase.StorageChanged OnStorageRangeChanged = null;
                                OnStorageRangeChanged = delegate(MyVoxelBase voxel, Vector3I minVoxelChanged, Vector3I maxVoxelChanged, MyStorageDataTypeFlags changedData)
                                {
                                    voxelMap.Save          = true;
                                    voxelMap.RangeChanged -= OnStorageRangeChanged;
                                };
                                voxelMap.RangeChanged += OnStorageRangeChanged;
                            }
                        }
                        m_tmpVoxelMapsList.Clear();
                        ProfilerShort.End();
                        break;

                    case MyObjectSeedType.EncounterAlone:
                    case MyObjectSeedType.EncounterSingle:
                    case MyObjectSeedType.EncounterMulti:
                        ProfilerShort.Begin("Encounter");
                        bool doSpawn = true;
                        foreach (var start in MySession.Static.Scenario.PossiblePlayerStarts)
                        {
                            Vector3D?startPos = start.GetStartingLocation();
                            if (!startPos.HasValue)
                            {
                                startPos = Vector3D.Zero;
                            }
                            if ((startPos.Value - objectSeed.BoundingVolume.Center).LengthSquared() < (15000 * 15000))
                            {
                                doSpawn = false;
                            }
                        }
                        if (doSpawn)
                        {
                            MyEncounterGenerator.PlaceEncounterToWorld(objectSeed.BoundingVolume, objectSeed.Params.Seed, objectSeed.Params.Type);
                        }
                        ProfilerShort.End();
                        break;

                    default:
                        throw new InvalidBranchException();
                        break;
                    }
                }
            }
            ProfilerShort.End();
        }
            public override void Draw()
            {
                base.Draw();

                if (MySession.Static == null)
                {
                    return;
                }

                if (m_showVoxelProbe)
                {
                    float halfSize = m_probeSize * .5f;
                    float lodSize  = 1 << m_probeLod;

                    if (m_moveProbe)
                    {
                        m_probePosition = MySector.MainCamera.Position + MySector.MainCamera.ForwardVector * m_probeSize * 3;
                    }

                    BoundingBox  bb;
                    BoundingBoxD bbp; // Box used for drawing and finding the probe and drawing

                    bb  = new BoundingBox(m_probePosition - halfSize, m_probePosition + halfSize);
                    bbp = (BoundingBoxD)bb;

                    m_voxels.Clear();
                    MyGamePruningStructure.GetAllVoxelMapsInBox(ref bbp, m_voxels);

                    MyVoxelBase map      = null;
                    double      distance = double.PositiveInfinity;

                    foreach (var vox in m_voxels)
                    {
                        var d = Vector3D.Distance(vox.WorldMatrix.Translation, m_probePosition);
                        if (d < distance)
                        {
                            distance = d;
                            map      = vox;
                        }
                    }

                    ContainmentType cont = ContainmentType.Disjoint;

                    if (map != null)
                    {
                        map = map.RootVoxel;

                        Vector3 localPos = Vector3.Transform(m_probePosition, map.PositionComp.WorldMatrixInvScaled);
                        localPos += map.SizeInMetresHalf;

                        // Create similar bounding box in storage space
                        bb = new BoundingBox(localPos - halfSize, localPos + halfSize);

                        m_probedVoxel = map;

                        Section("Probing {1}: {0}", map.StorageName, map.GetType().Name);
                        Text("Probe mode: {0}", m_mode);

                        if (m_mode == ProbeMode.Intersect)
                        {
                            Text("Local Pos: {0}", localPos);
                            Text("Probe Size: {0}", m_probeSize);
                            cont = map.Storage.Intersect(ref bb, false);
                            Text("Result: {0}", cont.ToString());
                            bbp = (BoundingBoxD)bb;
                        }
                        else
                        {
                            Vector3I min = Vector3I.Floor(bb.Min / lodSize + .5f);
                            Vector3I max = min + ((int)m_probeSize >> m_probeLod) - 1;

                            bbp = new BoundingBoxD(min << m_probeLod, (max + 1) << m_probeLod);
                            bbp.Translate(new Vector3D(-.5));

                            Text("Probe Size: {0}({1})", (max - min).X + 1, m_probeSize);
                            Text("Probe LOD: {0}", m_probeLod);

                            var requestData           = (MyStorageDataTypeEnum)(int)m_mode;
                            MyVoxelRequestFlags flags = MyVoxelRequestFlags.ContentChecked;

                            m_target.Resize(max - min + 1);
                            m_target.Clear(MyStorageDataTypeEnum.Content, 0);
                            m_target.Clear(MyStorageDataTypeEnum.Material, 0);
                            map.Storage.ReadRange(m_target, (MyStorageDataTypeFlags)(1 << (int)requestData), m_probeLod, ref min, ref max, ref flags);

                            if (requestData == MyStorageDataTypeEnum.Content)
                            {
                                if (flags.HasFlag(MyVoxelRequestFlags.EmptyContent))
                                {
                                    cont = ContainmentType.Disjoint;
                                }
                                else if (flags.HasFlag(MyVoxelRequestFlags.FullContent))
                                {
                                    cont = ContainmentType.Contains;
                                }
                                else
                                {
                                    int val = m_target.ValueWhenAllEqual(requestData);
                                    if (val == -1)
                                    {
                                        cont = ContainmentType.Intersects;
                                    }
                                    else if (val >= MyVoxelConstants.VOXEL_ISO_LEVEL)
                                    {
                                        cont = ContainmentType.Contains;
                                    }
                                    else
                                    {
                                        cont = ContainmentType.Disjoint;
                                    }
                                }

                                DrawContentsInfo(m_target);
                            }
                            else
                            {
                                cont = ContainmentType.Disjoint;
                                DrawMaterialsInfo(m_target);
                            }

                            Text(Color.Yellow, 1.5f, "Voxel Editing:");
                            Text("Value to set (Ctrl+Mousewheel): {0}", m_valueToSet);
                            if (m_probeLod != 0)
                            {
                                Text(Color.Red, "Writing to storage is only possible when probe is set to LOD 0");
                            }
                            else
                            {
                                Text("Use primary mouse button to set.");
                                Text("Position/Extents: {0}/{1}", bbp.Min, bbp.Extents);

                                if (MyInput.Static.IsLeftMousePressed())
                                {
                                    if (requestData == MyStorageDataTypeEnum.Content)
                                    {
                                        m_target.BlockFillContent(Vector3I.Zero, m_target.Size3D - Vector3I.One, m_valueToSet);
                                    }
                                    else
                                    {
                                        m_target.BlockFillMaterial(Vector3I.Zero, m_target.Size3D - Vector3I.One, m_valueToSet);
                                    }

                                    map.Storage.WriteRange(m_target, (MyStorageDataTypeFlags)(1 << (int)requestData), ref min, ref max);
                                }
                            }
                        }
                    }
                    else
                    {
                        Section("No Voxel Found");
                        Text("Probe mode: {0}", m_mode);
                        Text("Probe Size: {0}", m_probeSize);
                    }

                    Color c = ColorForContainment(cont);
                    if (map != null)
                    {
                        bbp = bbp.Translate(-map.SizeInMetresHalf);
                        MyOrientedBoundingBoxD oobb = new MyOrientedBoundingBoxD(bbp, map.WorldMatrix);
                        MyRenderProxy.DebugDrawOBB(oobb, c, 0.5f, true, false);
                    }
                    else
                    {
                        MyRenderProxy.DebugDrawAABB(bbp, c, 0.5f, 1.0f, true);
                    }
                }
            }
Exemplo n.º 17
0
        public void Update()
        {
            ProfilerShort.Begin("MyVoxelPathfinding.Update");

            if (++m_updateCtr >= UPDATE_PERIOD)
            {
                m_tmpUpdatePositions.Clear();
                m_updateCtr = 0;

                var players = Sync.Players.GetOnlinePlayers();
                foreach (var player in players)
                {
                    var controlledEntity = player.Controller.ControlledEntity;
                    if (controlledEntity == null)
                    {
                        continue;
                    }

                    m_tmpUpdatePositions.Add(controlledEntity.Entity.PositionComp.GetPosition());
                }

                m_tmpNavmeshes.Clear();

                ProfilerShort.Begin("Cell marking");
                Vector3D offset = new Vector3D(20.0f);
                foreach (var pos in m_tmpUpdatePositions)
                {
                    BoundingBoxD box = new BoundingBoxD(pos - offset, pos + offset);

                    ProfilerShort.Begin("GetVoxelMaps");
                    m_tmpVoxelMaps.Clear();
                    MyGamePruningStructure.GetAllVoxelMapsInBox(ref box, m_tmpVoxelMaps);
                    ProfilerShort.End();

                    foreach (var map in m_tmpVoxelMaps)
                    {
                        MyVoxelNavigationMesh mesh = null;
                        m_navigationMeshes.TryGetValue(map, out mesh);
                        Debug.Assert(mesh != null, "Navigation mesh for a voxel map is not generated!");
                        if (mesh == null)
                        {
                            continue;
                        }

                        mesh.MarkBoxForAddition(box);

                        if (!m_tmpNavmeshes.Contains(mesh))
                        {
                            m_tmpNavmeshes.Add(mesh);
                        }
                    }
                }
                m_tmpVoxelMaps.Clear();
                ProfilerShort.End();

                m_tmpNavmeshes.Clear();

                ProfilerShort.Begin("Cell additions");
                foreach (var mesh in m_navigationMeshes)
                {
                    m_tmpNavmeshes.Add(mesh.Value);
                }
                m_tmpNavmeshes.ShuffleList();

                foreach (var mesh in m_tmpNavmeshes)
                {
                    if (mesh.AddOneMarkedCell())
                    {
                        // Break after the first added cell
                        break;
                    }
                }
                ProfilerShort.End();

                ProfilerShort.Begin("Cell removals");
                foreach (var mesh in m_tmpNavmeshes)
                {
                    if (mesh.RemoveOneUnusedCell(m_tmpUpdatePositions))
                    {
                        // Break after the first removed cell
                        break;
                    }
                }
                ProfilerShort.End();

                m_tmpNavmeshes.Clear();
                m_tmpUpdatePositions.Clear();
            }

            ProfilerShort.End();
        }
Exemplo n.º 18
0
        public override void UpdateAfterSimulation10()
        {
            base.UpdateAfterSimulation10();

            if (!Sync.IsServer || !IsWorking)
            {
                return;
            }

            if (!ResourceSink.IsPowered)
            {
                if (ResourceSink.IsPowerAvailable(MyResourceDistributorComponent.ElectricityId, BlockDefinition.RequiredPowerInput))
                {
                    float origInput = ResourceSink.RequiredInput;
                    ResourceSink.SetRequiredInputByType(MyResourceDistributorComponent.ElectricityId, 0);
                    ResourceSink.SetRequiredInputByType(MyResourceDistributorComponent.ElectricityId, origInput);
                }
                else
                {
                    return;
                }
            }

            var rotation1 = Quaternion.CreateFromForwardUp(WorldMatrix.Forward, WorldMatrix.Up);
            var position1 = PositionComp.GetPosition() + Vector3D.Transform(PositionComp.LocalVolume.Center + (m_fieldMax.Value + m_fieldMin.Value) * 0.5f, rotation1);

            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Recreate Field");
            if (m_recreateField)
            {
                m_recreateField = false;
                m_fieldShape.RemoveReference();
                m_fieldShape = GetHkShape();
                ResourceSink.Update();
            }
            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();

            var boundingBox = new BoundingBoxD(m_fieldMin.Value, m_fieldMax.Value).Translate(PositionComp.LocalVolume.Center).TransformFast(WorldMatrix.GetOrientation()).Translate(PositionComp.GetPosition());

            m_potentialPenetrations.Clear();
            MyGamePruningStructure.GetTopMostEntitiesInBox(ref boundingBox, m_potentialPenetrations);

            m_potentialVoxelPenetrations.Clear();
            MyGamePruningStructure.GetAllVoxelMapsInBox(ref boundingBox, m_potentialVoxelPenetrations);//disabled until heightmap queries are finished

            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Sensor Physics");
            LastDetectedEntity = null;
            bool empty = true;

            foreach (var entity in m_potentialPenetrations)
            {
                if (entity is MyVoxelBase)
                {
                    //voxels are handled in different loop (becaose of planets)
                    continue;
                }
                if (ShouldDetect(entity))
                {
                    Quaternion rotation2;
                    Vector3    posDiff;
                    HkShape?   shape2;
                    if (GetPropertiesFromEntity(entity, ref position1, out rotation2, out posDiff, out shape2))
                    {
                        if (entity.GetPhysicsBody().HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2))
                        {
                            LastDetectedEntity = entity;
                            empty = false;
                            break;
                        }
                    }
                }
            }

            if (DetectAsteroids)
            {
                foreach (var entity in m_potentialVoxelPenetrations)
                {
                    var voxel = entity as MyVoxelPhysics;
                    if (voxel != null)
                    {
                        Vector3D localPositionMin, localPositionMax;

                        MyVoxelCoordSystems.WorldPositionToLocalPosition(boundingBox.Min, voxel.PositionComp.WorldMatrix, voxel.PositionComp.WorldMatrixInvScaled, voxel.SizeInMetresHalf, out localPositionMin);
                        MyVoxelCoordSystems.WorldPositionToLocalPosition(boundingBox.Max, voxel.PositionComp.WorldMatrix, voxel.PositionComp.WorldMatrixInvScaled, voxel.SizeInMetresHalf, out localPositionMax);
                        var aabb = new BoundingBox(localPositionMin, localPositionMax);
                        aabb.Translate(voxel.StorageMin);
                        if (voxel.Storage.Intersect(ref aabb) != ContainmentType.Disjoint)
                        {
                            LastDetectedEntity = voxel;
                            empty = false;
                            break;
                        }
                    }
                    else
                    {
                        Quaternion rotation2;
                        Vector3    posDiff;
                        HkShape?   shape2;
                        if (GetPropertiesFromEntity(entity, ref position1, out rotation2, out posDiff, out shape2))
                        {
                            if (entity.GetPhysicsBody().HavokWorld.IsPenetratingShapeShape(m_fieldShape, ref Vector3.Zero, ref rotation1, shape2.Value, ref posDiff, ref rotation2))
                            {
                                LastDetectedEntity = entity;
                                empty = false;
                                break;
                            }
                        }
                    }
                }
            }
            IsActive = !empty;
            m_potentialPenetrations.Clear();
            m_potentialVoxelPenetrations.Clear();
            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
        }
        public override void GenerateObjects(List <MyObjectSeed> objectsList)
        {
            ProfilerShort.Begin("GenerateObjects");
            foreach (var objectSeed in objectsList)
            {
                if (objectSeed.Generated)
                {
                    continue;
                }

                objectSeed.Generated = true;

                using (MyRandom.Instance.PushSeed(GetObjectIdSeed(objectSeed)))
                {
                    switch (objectSeed.Type)
                    {
                    case MyObjectSeedType.Asteroid:
                        ProfilerShort.Begin("Asteroid");

                        var bbox = objectSeed.BoundingVolume;
                        MyGamePruningStructure.GetAllVoxelMapsInBox(ref bbox, m_tmpVoxelMapsList);

                        String storageName = string.Format("Asteroid_{0}_{1}_{2}_{3}_{4}", objectSeed.CellId.X, objectSeed.CellId.Y, objectSeed.CellId.Z, objectSeed.Index, objectSeed.Seed);

                        bool exists = false;
                        foreach (var voxelMap in m_tmpVoxelMapsList)
                        {
                            if (voxelMap.StorageName == storageName)
                            {
                                exists = true;
                                break;
                            }
                        }

                        if (!exists)
                        {
                            var           provider = MyCompositeShapeProvider.CreateAsteroidShape(objectSeed.Seed, objectSeed.Size, MySession.Static.Settings.VoxelGeneratorVersion);
                            MyStorageBase storage  = new MyOctreeStorage(provider, GetAsteroidVoxelSize(objectSeed.Size));
                            var           voxelMap = MyWorldGenerator.AddVoxelMap(storageName, storage, objectSeed.BoundingVolume.Center - VRageMath.MathHelper.GetNearestBiggerPowerOfTwo(objectSeed.Size) / 2, GetAsteroidEntityId(objectSeed));

                            if (voxelMap != null)
                            {
                                voxelMap.Save = false;
                                RangeChangedDelegate OnStorageRangeChanged = null;
                                OnStorageRangeChanged = delegate(Vector3I minVoxelChanged, Vector3I maxVoxelChanged, MyStorageDataTypeFlags changedData)
                                {
                                    voxelMap.Save         = true;
                                    storage.RangeChanged -= OnStorageRangeChanged;
                                };
                                storage.RangeChanged += OnStorageRangeChanged;
                            }
                        }
                        m_tmpVoxelMapsList.Clear();
                        ProfilerShort.End();
                        break;

                    case MyObjectSeedType.EncounterAlone:
                    case MyObjectSeedType.EncounterSingle:
                    case MyObjectSeedType.EncounterMulti:
                        ProfilerShort.Begin("Encounter");
                        MyEncounterGenerator.PlaceEncounterToWorld(objectSeed.BoundingVolume, objectSeed.Seed, objectSeed.Type);
                        ProfilerShort.End();
                        break;

                    default:
                        throw new InvalidBranchException();
                        break;
                    }
                }
            }
            ProfilerShort.End();
        }
        public override void GenerateLoadedCellObjects()
        {
            List <MyObjectSeed> seeds = new List <MyObjectSeed>();

            foreach (var cell in m_loadedCells.Values)
            {
                cell.GetAll(seeds, false);
            }

            List <MyVoxelBase> tmp_voxelMaps = new List <MyVoxelBase>();

            foreach (var seed in seeds)
            {
                if (seed.Params.Generated)
                {
                    continue;
                }
                if (seed.Params.Type != VRage.Game.MyObjectSeedType.Asteroid)
                {
                    continue;
                }

                seed.Params.Generated = true;

                using (MyRandom.Instance.PushSeed(GetObjectIdSeed(seed)))
                {
                    tmp_voxelMaps.Clear();

                    var bounds = seed.BoundingVolume;
                    MyGamePruningStructure.GetAllVoxelMapsInBox(ref bounds, tmp_voxelMaps);

                    string storageName = string.Format("Asteroid_{0}_{1}_{2}_{3}_{4}", seed.CellId.X, seed.CellId.Y, seed.CellId.Z, seed.Params.Index, seed.Params.Seed);

                    bool exists = false;
                    foreach (var tmp in tmp_voxelMaps)
                    {
                        if (tmp.StorageName == storageName)
                        {
                            if (!m_existingObjectSeeds.Contains(seed))
                            {
                                m_existingObjectSeeds.Add(seed);
                            }
                            exists = true;

                            if (tmp_voxelMaps.Contains(tmp))
                            {
                                tmp.Save = true;
                            }
                            break;
                        }
                    }

                    if (exists)
                    {
                        continue;
                    }

                    var      storage = CreateAsteroidStorage(GetAsteroidVoxelSize(seed.Size), seed.Params.Seed, seed.Size, m_definition.UseGeneratorSeed ? seed.Params.GeneratorSeed : 0);
                    Vector3D pos     = seed.BoundingVolume.Center - MathHelper.GetNearestBiggerPowerOfTwo(seed.Size) / 2;

                    MyVoxelMap voxelMap;

                    voxelMap = MyWorldGenerator.AddVoxelMap(storageName, storage, pos, GetAsteroidEntityId(storageName));
                    if (voxelMap == null)
                    {
                        continue;
                    }

                    MyVoxelBase.StorageChanged del = null;
                    del = delegate(MyVoxelBase voxel, Vector3I minVoxelChanged, Vector3I maxVoxelChanged, MyStorageDataTypeFlags changedData)
                    {
                        voxel.Save = true;
                        m_tmpAsteroids.Remove(voxel);
                        voxel.RangeChanged -= del;
                    };
                    voxelMap.RangeChanged += del;

                    voxelMap.IsSeedOpen = true;

                    seed.UserData = voxelMap;
                    m_tmpAsteroids.Add(voxelMap);
                }
            }
        }
        public override void CloseObject(MyObjectSeed seed)
        {
            m_existingObjectSeeds.Remove(seed);
            MyVoxelBase voxelMap;

            if (seed.UserData != null)
            {
                if (seed.UserData is MyVoxelBase)
                {
                    voxelMap = seed.UserData as MyVoxelBase;

                    if (!m_tmpAsteroids.Contains(voxelMap))
                    {
                        return;
                    }

                    if (!m_tmpAsteroids.Remove(voxelMap))
                    {
                        for (int i = 0; i < m_tmpAsteroids.Count; i++)
                        {
                            if (m_tmpAsteroids[i].StorageName.Equals(voxelMap.StorageName))
                            {
                                m_tmpAsteroids.RemoveAt(i);
                                voxelMap.Save = false;
                                break;
                            }
                        }
                    }
                    else
                    {
                        voxelMap.Save = false;
                    }

                    voxelMap.IsSeedOpen = false;
                    seed.UserData       = null;

                    voxelMap.Close();
                }
            }
            else
            {
                List <MyVoxelBase> voxelMaps = new List <MyVoxelBase>();
                var bounds = seed.BoundingVolume;

                MyGamePruningStructure.GetAllVoxelMapsInBox(ref bounds, voxelMaps);

                string storageName = string.Format("Asteroid_{0}_{1}_{2}_{3}_{4}", seed.CellId.X, seed.CellId.Y, seed.CellId.Z, seed.Params.Index, seed.Params.Seed);

                foreach (MyVoxelBase map in voxelMaps)
                {
                    if (map.StorageName == storageName)
                    {
                        if (m_tmpAsteroids.Contains(map))
                        {
                            map.Save = false;

                            m_tmpAsteroids.Remove(map);
                            map.IsSeedOpen = false;
                            map.Close();
                            break;
                        }
                    }
                }

                voxelMaps.Clear();
            }
        }
Exemplo n.º 22
0
        private void ProcessDirtyCells()
        {
            foreach (var cell in m_dirtyCellsToAdd)
            {
                m_dirtyCells.Add(cell);
            }
            m_dirtyCellsToAdd.Clear();

            if (m_dirtyCells.Count == 0)
            {
                return;
            }
            ProfilerShort.Begin("Find false possitive dirty cells");
            foreach (var cell in m_dirtyCells)
            {
                foreach (var tracker in m_trackedEntities.Values)
                {
                    if (tracker.BoundingVolume.Contains(cell.BoundingVolume) != ContainmentType.Disjoint)
                    {
                        m_dirtyCellsToRemove.Add(cell);
                        break;
                    }
                }
            }

            ProfilerShort.BeginNextBlock("Remove false possitive dirty cells");
            foreach (var cell in m_dirtyCellsToRemove)
            {
                m_dirtyCells.Remove(cell);
            }
            m_dirtyCellsToRemove.Clear();

            ProfilerShort.BeginNextBlock("Remove stuff");
            foreach (var cell in m_dirtyCells)
            {
                cell.GetAll(m_tempObjectSeedList);

                foreach (var objectSeed in m_tempObjectSeedList)
                {
                    switch (objectSeed.Type)
                    {
                    case MyObjectSeedType.Asteroid:
                    case MyObjectSeedType.AsteroidCluster:
                        var bbox = objectSeed.BoundingVolume;
                        MyGamePruningStructure.GetAllVoxelMapsInBox(ref bbox, m_tmpVoxelMapsList);

                        String storageName = string.Format("Asteroid_{0}_{1}_{2}_{3}_{4}", cell.CellId.X, cell.CellId.Y, cell.CellId.Z, objectSeed.Index, objectSeed.Seed);

                        foreach (var voxelMap in m_tmpVoxelMapsList)
                        {
                            if (voxelMap.StorageName == storageName)
                            {
                                if (!voxelMap.Save)     // for now
                                {
                                    m_asteroidCount--;
                                    voxelMap.Close();
                                }
                                break;
                            }
                        }
                        m_asteroidSeedCount--;
                        m_tmpVoxelMapsList.Clear();
                        break;

                    case MyObjectSeedType.EncounterAlone:
                    case MyObjectSeedType.EncounterSingle:
                    case MyObjectSeedType.EncounterMulti:
                        if (MyEncounterGenerator.RemoveEncounter(objectSeed.BoundingVolume, objectSeed.Seed))
                        {
                            m_encounterCount--;
                        }
                        m_encounterSeedCount--;
                        break;

                    default:
                        throw new InvalidBranchException();
                        break;
                    }
                }
            }
            m_tempObjectSeedList.Clear();

            ProfilerShort.BeginNextBlock("Remove dirty cells");
            foreach (var cell in m_dirtyCells)
            {
                m_cells.Remove(cell.CellId);
                m_cellsTree.RemoveProxy(cell.proxyId);
            }
            m_dirtyCells.Clear();
            ProfilerShort.End();
        }