public static void ResolveAllWantedCrossReferences(FailMode failReportMode)
 {
     DeepProfiler.Start("ResolveAllWantedCrossReferences");
     try
     {
         HashSet <WantedRef> resolvedRefs = new HashSet <WantedRef>();
         object resolvedRefsLock          = new object();
         DeepProfiler.enabled = false;
         GenThreading.ParallelForEach(wantedRefs, delegate(WantedRef wantedRef)
         {
             if (wantedRef.TryResolve(failReportMode))
             {
                 lock (resolvedRefsLock)
                 {
                     resolvedRefs.Add(wantedRef);
                 }
             }
         });
         foreach (WantedRef item in resolvedRefs)
         {
             item.Apply();
         }
         wantedRefs.RemoveAll((WantedRef x) => resolvedRefs.Contains(x));
         DeepProfiler.enabled = true;
     }
     finally
     {
         DeepProfiler.End();
     }
 }
Exemplo n.º 2
0
 public static void ResolveAllReferences(bool onlyExactlyMyType = true, bool parallel = false)
 {
     DeepProfiler.Start("SetIndices");
     try
     {
         SetIndices();
     }
     finally
     {
         DeepProfiler.End();
     }
     DeepProfiler.Start("ResolveAllReferences " + typeof(T).FullName);
     try
     {
         Action <T> action = delegate(T def)
         {
             if (!onlyExactlyMyType || !(def.GetType() != typeof(T)))
             {
                 DeepProfiler.Start("Resolver call");
                 try
                 {
                     def.ResolveReferences();
                 }
                 catch (Exception ex)
                 {
                     Log.Error("Error while resolving references for def " + def + ": " + ex);
                 }
                 finally
                 {
                     DeepProfiler.End();
                 }
             }
         };
         if (parallel)
         {
             GenThreading.ParallelForEach(defsList, action);
         }
         else
         {
             for (int i = 0; i < defsList.Count; i++)
             {
                 action(defsList[i]);
             }
         }
     }
     finally
     {
         DeepProfiler.End();
     }
     DeepProfiler.Start("SetIndices");
     try
     {
         SetIndices();
     }
     finally
     {
         DeepProfiler.End();
     }
 }
Exemplo n.º 3
0
        public void RecalculateDisplayRootCategory()
        {
            if (ThingCategoryNodeDatabase.allThingCategoryNodes == null)
            {
                DisplayRootCategory = ThingCategoryNodeDatabase.RootNode;
                return;
            }
            int    lastFoundCategory = -1;
            object lockObject        = new object();

            GenThreading.ParallelFor(0, ThingCategoryNodeDatabase.allThingCategoryNodes.Count, delegate(int index)
            {
                TreeNode_ThingCategory treeNode_ThingCategory = ThingCategoryNodeDatabase.allThingCategoryNodes[index];
                bool flag  = false;
                bool flag2 = false;
                foreach (ThingDef allowedDef in allowedDefs)
                {
                    if (treeNode_ThingCategory.catDef.ContainedInThisOrDescendant(allowedDef))
                    {
                        flag2 = true;
                    }
                    else
                    {
                        flag = true;
                    }
                }
                if (!flag && flag2)
                {
                    lock (lockObject)
                    {
                        if (index > lastFoundCategory)
                        {
                            lastFoundCategory = index;
                        }
                    }
                }
            });
            if (lastFoundCategory == -1)
            {
                DisplayRootCategory = ThingCategoryNodeDatabase.RootNode;
            }
            else
            {
                DisplayRootCategory = ThingCategoryNodeDatabase.allThingCategoryNodes[lastFoundCategory];
            }
        }
Exemplo n.º 4
0
        public static LoadableXmlAsset[] XmlAssetsInModFolder(ModContentPack mod, string folderPath, List <string> foldersToLoadDebug = null)
        {
            List <string> list = foldersToLoadDebug ?? mod.foldersToLoadDescendingOrder;
            Dictionary <string, FileInfo> dictionary = new Dictionary <string, FileInfo>();

            for (int j = 0; j < list.Count; j++)
            {
                string        text          = list[j];
                DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(text, folderPath));
                if (!directoryInfo.Exists)
                {
                    continue;
                }
                FileInfo[] files = directoryInfo.GetFiles("*.xml", SearchOption.AllDirectories);
                foreach (FileInfo fileInfo in files)
                {
                    string key = fileInfo.FullName.Substring(text.Length + 1);
                    if (!dictionary.ContainsKey(key))
                    {
                        dictionary.Add(key, fileInfo);
                    }
                }
            }
            if (dictionary.Count == 0)
            {
                return(emptyXmlAssetsArray);
            }
            List <FileInfo> fileList = dictionary.Values.ToList();

            LoadableXmlAsset[] assets = new LoadableXmlAsset[fileList.Count];
            GenThreading.ParallelFor(0, fileList.Count, delegate(int i)
            {
                FileInfo fileInfo2 = fileList[i];
                LoadableXmlAsset loadableXmlAsset = new LoadableXmlAsset(fileInfo2.Name, fileInfo2.Directory.FullName, File.ReadAllText(fileInfo2.FullName))
                {
                    mod = mod
                };
                assets[i] = loadableXmlAsset;
            });
            return(assets);
        }