public void EnsureGenerationStarted()
 {
     TimeRemoved = null;
     using (m_creationQueueSemaphore.AcquireSharedUsing())
         if (m_creationQueued)
         {
             return;
         }
     using (m_creationQueueSemaphore.AcquireExclusiveUsing())
     {
         if (m_creationQueued)
         {
             return;
         }
         m_creationQueued = true;
     }
     if (IsMarkedForRemoval)
     {
         return;
     }
     if (m_construction == null)
     {
         MyAPIGateway.Parallel.StartBackground(ParallelUtilities.WrapAction(() =>
         {
             if (!Stage_Generate())
             {
                 return;
             }
             if (!Stage_Build())
             {
                 return;
             }
             MyAPIGateway.Utilities.InvokeOnGameThread(ParallelUtilities.WrapAction(Stage_SpawnGrid, Module));
         }, Module));
     }
     else if (m_grids == null)
     {
         MyAPIGateway.Parallel.StartBackground(ParallelUtilities.WrapAction(() =>
         {
             if (!Stage_Build())
             {
                 return;
             }
             MyAPIGateway.Utilities.InvokeOnGameThread(ParallelUtilities.WrapAction(Stage_SpawnGrid, Module));
         }, Module));
     }
     else if (m_component == null)
     {
         MyAPIGateway.Utilities.InvokeOnGameThread(ParallelUtilities.WrapAction(Stage_SpawnGrid, Module));
     }
     else
     {
         m_creationQueued = false;
     }
 }
Example #2
0
        public void InitFromPrefab()
        {
            if (Initialized)
            {
                return;
            }

            var cob   = GetObjectBuilder();
            var chash = cob.ComputeHash();

            Initialized = true;
            InitFromGrids(Prefab.CubeGrids[0], Prefab.CubeGrids);
            Logger.Info("Loaded {0} with {1} mount points, {2} reserved spaces, and {3} blocks.  {4} aux grids", Name, MountPoints.Count(), ReservedSpaces.Count(), PrimaryGrid.CubeBlocks.Count, Prefab.CubeGrids.Length - 1);
            foreach (var type in MountPointTypes)
            {
                Logger.Info("    ...of type \"{0}\" there are {1}", type, MountPointsOfType(type).Count());
            }

            var obs   = GetObjectBuilder();
            var nhash = obs.ComputeHash();

            if (nhash == chash)
            {
                return;
            }
            MyAPIGateway.Parallel.StartBackground(ParallelUtilities.WrapAction(() =>
            {
                try
                {
                    Logger.Info("Invalid hash for cached definition of {0}; writing to local storage.  {1} => {2}", Name, chash, nhash);
                    using (var writer = MyAPIGateway.Utilities.WriteFileInLocalStorage(CacheName, typeof(PartFromPrefab)))
                    {
                        var xml = MyAPIGateway.Utilities.SerializeToXML(obs);
                        writer.Write(xml);
                    }
                }
                catch (Exception e)
                {
                    Logger.Error("Write failed.\n{0}", e);
                }
            }, Manager));
        }