private bool Stage_Build()
 {
     Module.Debug("Build stage for {0}/{1}", m_cell, Seed.Seed);
     m_grids = GridCreator.RemapAndBuild(m_construction);
     if (m_grids != null)
     {
         Module.Debug("Build stage success for {0}/{1}", m_cell, Seed.Seed);
         if (!IsMarkedForRemoval)
         {
             return(true);
         }
     }
     else
     {
         Module.Warning("Build stage failed for {0}/{1}", m_cell, Seed.Seed);
     }
     m_component = null;
     return(false);
 }
 private void Stage_SpawnGrid()
 {
     Module.Debug("Spawn stage for {0}/{1}", m_cell, Seed.Seed);
     if (m_grids.IsRegionEmpty())
     {
         m_component = m_grids.SpawnAsync();
         if (m_component == null)
         {
             Module.Warning("Spawn stage failed for {0}/{1}", m_cell, Seed.Seed);
         }
         else
         {
             Module.Debug("Spawn stage success for {0}/{1}", m_cell, Seed.Seed);
         }
     }
     else
     {
         Module.Debug("Spawn stage ignored for {0}/{1}; entities in box", m_cell, Seed.Seed);
     }
     using (m_creationQueueSemaphore.AcquireExclusiveUsing())
         m_creationQueued = false;
 }
            private bool Stage_Generate()
            {
                Module.Debug("Generation stage for {0}/{1}", m_cell, Seed.Seed);
                m_construction = null;

                var success = Module.Generator.GenerateFromSeed(Seed, ref m_construction);

                if (success)
                {
                    Module.Debug("Generation stage success for {0}/{1}", m_cell, Seed.Seed);
                    if (!IsMarkedForRemoval)
                    {
                        return(true);
                    }
                }
                else
                {
                    Module.Error("Generation stage failed for {0}/{1}", m_cell, Seed.Seed);
                }
                m_grids     = null;
                m_component = null;
                return(false);
            }
            public LoadingConstruction(ProceduralStationModule module, Vector4I cell, ProceduralConstructionSeed seed) : base(module)
            {
                m_cell        = cell;
                m_boundingBox = module.StationNoise.GetNodeAABB(cell);
                RaiseMoved();
                Seed = seed;

                m_creationQueued         = false;
                m_creationQueueSemaphore = new FastResourceLock();

                m_construction  = null;
                m_grids         = null;
                m_component     = null;
                base.OnRemoved += (x) =>
                {
                    var station = x as LoadingConstruction;
                    if (station == null)
                    {
                        return;
                    }
                    station.TimeRemoved = DateTime.UtcNow;
                    Module.Debug("Marking station entity for removal!");
                };
            }
            internal bool TickRemoval(ref int hiddenEntities, ref int removedEntities, ref int removedOB, ref int removedRecipe)
            {
                if (!TimeRemoved.HasValue)
                {
                    return(false);
                }
                using (m_creationQueueSemaphore.AcquireSharedUsing())
                    if (m_creationQueued)
                    {
                        return(false);
                    }
                var dt = DateTime.UtcNow - TimeRemoved;

                if (dt > Module.ConfigReference.StationEntityPersistence && m_component != null)
                {
                    removedEntities++;
                    var grids = new List <IMyCubeGrid>(m_component.GridsInGroup);
                    foreach (var grid in grids)
                    {
                        grid.Close();
                    }
                    m_component = null;
                }
                if (dt > Module.ConfigReference.StationObjectBuilderPersistence && m_grids != null)
                {
                    removedOB++;
                    m_grids = null;
                }
                // ReSharper disable once InvertIf
                if (dt > Module.ConfigReference.StationRecipePersistence && m_construction != null)
                {
                    removedRecipe++;
                    m_construction = null;
                }
                return(dt > Module.ConfigReference.StationRecipePersistence);
            }