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 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);
            }
 public bool GenerateFromSeedAndRemap(ProceduralConstructionSeed seed, ref ProceduralConstruction construction, out ConstructionCopy grids, int?roomCount = null)
 {
     grids = null;
     try
     {
         if (!GenerateFromSeed(seed, ref construction, roomCount))
         {
             Log(MyLogSeverity.Debug, "Failed to generate from seed");
             return(false);
         }
         var watch = new Stopwatch();
         watch.Restart();
         grids = GridCreator.RemapAndBuild(construction);
         Log(MyLogSeverity.Debug, "Added {0} rooms in {1}", construction.Rooms.Count(), watch.Elapsed);
         return(true);
     }
     catch (Exception e)
     {
         Log(MyLogSeverity.Error, "Failed to generate station.\n{0}", e.ToString());
         return(false);
     }
 }