Пример #1
0
		protected override void OnDragTool(int cell, int distFromOrigin) {
			var gameObject = Grid.Objects[cell, (int)ObjectLayer.Pickupables];
			if (gameObject != null && TypeSelect != null) {
				// Linked list of debris in layer 3
				var objectListNode = gameObject.GetComponent<Pickupable>().objectLayerListItem;
				var priority = ToolMenu.Instance.PriorityScreen.GetLastSelectedPriority();
				if (cachedTypes == null) {
					// Build the list
					cachedTypes = HashSetPool<Tag, FilteredClearTool>.Allocate();
					TypeSelect.AddTypesToSweep(cachedTypes);
				}
				var types = cachedTypes;
				while (objectListNode != null) {
					var content = objectListNode.gameObject;
					objectListNode = objectListNode.nextItem;
					// Ignore Duplicants
					if (content != null && content.GetComponent<MinionIdentity>() == null) {
						var cc = content.GetComponent<Clearable>();
						if (cc != null && cc.isClearable && types.Contains(content.PrefabID()))
						{
							// Parameter is whether to force, not remove sweep errand!
							cc.MarkForClear(false);
							var pr = content.GetComponent<Prioritizable>();
							if (pr != null)
								pr.SetMasterPriority(priority);
						}
					}
				}
			}
		}
Пример #2
0
        public void ReleaseRef()
        {
            if (null != _assets)
            {
                foreach (var asset in _assets)
                {
                    Logger.LogVerbose("BundlerMessenger::ReleaseRef: {0}, loader: {1}", this, asset.Loader);
                    asset.Release();
                    Logger.LogVerbose("BundlerMessenger::ReleaseRef: {0}, loader: {1}, finished!", this, asset.Loader);
                }

                HashSetPool <AssetBase> .Return(_assets);
            }

            if (null != _typedAssets)
            {
                foreach (var kv in _typedAssets)
                {
                    Logger.LogVerbose("BundlerMessenger::ReleaseRef: {0}, loader: {1}", this, kv.Value.Loader);
                    kv.Value.Release();
                    Logger.LogVerbose("BundlerMessenger::ReleaseRef: {0}, loader: {1}, finished!", this, kv.Value.Loader);
                }

                DictionaryPool <Type, AssetBase> .Return(_typedAssets);
            }

            Messengers.Remove(this);
        }
Пример #3
0
        public HashSet <KeyValuePair <IgnoreCaseString, GameAssetBundle> > Record(ref AssetBundleContext data, ref bool force, Dictionary <IgnoreCaseString, GameAssetBundle> targets)
        {
            HashSet <KeyValuePair <IgnoreCaseString, GameAssetBundle> > result = null;

            foreach (var pair in targets)
            {
                var  gameAssetBundle = pair.Value;
                bool inmemory        = gameAssetBundle.AssetStatus.HasEnum(AssetBundleStatus.InMemory);
                bool canUnload       = gameAssetBundle.CanUnLoad;
                bool nointask        = !InTask(ref data, ref gameAssetBundle);
                bool noinscene       = !InScene(ref data, ref gameAssetBundle);
                bool hasactivescene  = HasShowScene();

                if (force ||
                    (inmemory && canUnload && nointask && noinscene && hasactivescene))
                {
                    if (result == null)
                    {
                        result = HashSetPool <KeyValuePair <IgnoreCaseString, GameAssetBundle> > .Get();
                    }

                    KeyValuePair <IgnoreCaseString, GameAssetBundle> tuple = new KeyValuePair <IgnoreCaseString, GameAssetBundle>(pair.Key, gameAssetBundle);

                    result.Add(tuple);
                }
            }
            return(result);
        }
Пример #4
0
        public bool HaveNamesChanged(ChaFile chaFile)
        {
            //return trackedRegistrationIDs.Contains(chaFile.GetRegistrationID());
            var current = HashSetPool <string> .Get();

            try
            {
                foreach (var name in GetNamesToRegister(chaFile))
                {
                    current.Add(name.Key);
                }

                lock (_lock)
                {
                    if (!_regIDtoNamesMap.TryGetValue(chaFile.GetRegistrationID(), out var registered))
                    {
                        registered = new HashSet <string>();
                    }

                    return(!registered.SetEquals(current));
                }
            }
            finally
            {
                HashSetPool <string> .Release(current);
            }
        }
Пример #5
0
        public override void Update()
        {
            int x1, x2, y1, y2;
            var intersecting = HashSetPool <Uprootable, PipPlantOverlay> .Allocate();

            base.Update();
            // SimDebugView is updated on a background thread, so since plant checking
            // must be done on the FG thread, it is updated here
            Grid.GetVisibleExtents(out Vector2I min, out Vector2I max);
            x1 = min.x; x2 = max.x;
            y1 = min.y; y2 = max.y;
            // Refresh plant list with plants on the screen
            RemoveOffscreenTargets(layerTargets, min, max, null);
            partition.GetAllIntersecting(new Vector2(x1, y1), new Vector2(x2, y2),
                                         intersecting);
            foreach (var uprootable in intersecting)
            {
                AddTargetIfVisible(uprootable, min, max, layerTargets, targetLayer);
            }
            for (int y = y1; y <= y2; y++)
            {
                for (int x = x1; x <= x2; x++)
                {
                    int cell = Grid.XYToCell(x, y);
                    if (Grid.IsValidCell(cell))
                    {
                        cells[cell] = PipPlantOverlayTests.CheckCell(cell);
                    }
                }
            }
            UpdateHighlightTypeOverlay(min, max, layerTargets, plants, conditions,
                                       OverlayModes.BringToFrontLayerSetting.Constant, targetLayer);
            intersecting.Recycle();
        }
Пример #6
0
    public override void Execute()
    {
        // Find targets
        HashSet <ShipSystem> targets = HashSetPool <ShipSystem> .Get();

        var systems = Ship.instance.systems;

        while (targets.Count < this.asteroidsToFire)
        {
            targets.Add(systems[Random.Range(0, systems.Count)]);
        }

        // Fire asteroids
        float t = 0;

        foreach (var target in targets)
        {
            var asteroidGo = Instantiate(this.prefab.gameObject);
            var asteroid   = asteroidGo.GetComponent <Asteroid>();
            asteroid.Initialize(target.gameObject, t);
            t += this.interval;
        }

        HashSetPool <ShipSystem> .Return(targets);
    }
Пример #7
0
        /// <summary>
        /// Scrubs the config of mods that Steam got around to actually updating.
        /// </summary>
        private static void DoScrubConfig()
        {
            var settings = ModUpdateInfo.Settings;
            var existing = settings?.ModUpdates;
            var manager  = Global.Instance.modManager;

            if (existing != null && manager != null)
            {
                // Anything that is up to date gets purged
                var remove = HashSetPool <ModUpdateData, ModUpdateHandler> .Allocate();

                foreach (var info in existing)
                {
                    ulong id = info.ID;
                    if (CheckMod(manager, id))
                    {
                        remove.Add(info);
                    }
                    if (info.Status == ModUpdateStatus.PendingUpdate)
                    {
                        // Purge the temporary zip
                        ExtensionMethods.RemoveOldDownload(ModUpdateHandler.GetDownloadPath(id));
                        info.Status = ModUpdateStatus.UpdatedByThisMod;
                    }
                }
                // Remove the obsolete entries
                foreach (var info in remove)
                {
                    existing.Remove(info);
                }
                remove.Recycle();
                POptions.WriteSettingsForAssembly(settings);
            }
        }
Пример #8
0
        /// <summary>
        /// Destroys debris in the cell.
        /// </summary>
        /// <param name="cell">The cell to destroy.</param>
        private void DestroyItems(int cell)
        {
            var destroy = HashSetPool <GameObject, FilteredDestroyTool> .Allocate();

            var gameObject = Grid.Objects[cell, (int)ObjectLayer.Pickupables];

            if (gameObject != null)
            {
                // Linked list of debris in layer 3
                var objectListNode = gameObject.GetComponent <Pickupable>().objectLayerListItem;
                while (objectListNode != null)
                {
                    var content = objectListNode.gameObject;
                    objectListNode = objectListNode.nextItem;
                    // Ignore Duplicants
                    if (content != null && content.GetComponent <MinionIdentity>() == null)
                    {
                        var cc = content.GetComponent <Clearable>();
                        if (cc != null && cc.isClearable)
                        {
                            destroy.Add(content);
                        }
                    }
                }
            }
            DestroyAndRecycle(destroy);
        }
Пример #9
0
        protected override void OnDragTool(int cell, int distFromOrigin)
        {
            var gameObject = Grid.Objects[cell, (int)ObjectLayer.Pickupables];

            if (gameObject != null && TypeSelect != null)
            {
                // Linked list of debris in layer 3
                var objectListNode = gameObject.GetComponent <Pickupable>().objectLayerListItem;
                var priority       = ToolMenu.Instance.PriorityScreen.GetLastSelectedPriority();
                if (cachedTypes == null)
                {
                    // Build the list
                    cachedTypes = HashSetPool <Tag, FilteredClearTool> .Allocate();

                    TypeSelect.AddTypesToSweep(cachedTypes);
                }
                while (objectListNode != null)
                {
                    var content = objectListNode.gameObject;
                    objectListNode = objectListNode.nextItem;
                    // Ignore Duplicants
                    if (content != null && content.GetComponent <MinionIdentity>() == null)
                    {
                        MarkForClear(content, priority);
                    }
                }
            }
        }
Пример #10
0
            /// <summary>
            /// Applied after UpdateAchievementData runs.
            /// </summary>
            internal static void Postfix(Dictionary <string, GameObject> ___achievementEntries,
                                         string[] newlyAchieved)
            {
                var newly = HashSetPool <string, AchievementStateComponent> .Allocate();

                // Achievements just obtained should always be shown
                if (newlyAchieved != null)
                {
                    foreach (string achieved in newlyAchieved)
                    {
                        newly.Add(achieved);
                    }
                }
                foreach (var pair in ___achievementEntries)
                {
                    var         obj = pair.Value;
                    string      id  = pair.Key;
                    MultiToggle toggle;
                    var         info = MoreAchievementsAPI.TranslateAchievement(id);
                    if (obj != null && (toggle = obj.GetComponent <MultiToggle>()) != null &&
                        info.Hidden)
                    {
                        // Inactivate achievements that have never been achieved
                        obj.SetActive(toggle.CurrentState != 2 || newly.Contains(id));
                    }
                }
                newly.Recycle();
            }
Пример #11
0
        /// <summary>
        /// Retrieves a list of KSelectable objects currently under the mouse cursor.
        /// </summary>
        /// <param name="cell">The cell that the cursor occupies.</param>
        /// <param name="coords">The raw mouse coordinates.</param>
        /// <param name="previousItems">The previously selected items.</param>
        /// <param name="hits">The location where the hits will be stored.</param>
        /// <returns>true to reset the cycle count, or false to leave it as is.</returns>
        private static bool GetAllSelectables(int cell, Vector3 coords,
                                              HashSet <Component> previousItems, List <KSelectable> hits)
        {
            var compareSet = HashSetPool <Component, InterfaceTool> .Allocate();

            bool reset = false;

            if (Grid.IsVisible(cell))
            {
                FindSelectables(cell, coords, hits, compareSet);
            }
            if (compareSet.Count < 1)
            {
                previousItems.Clear();
            }
            else if (!previousItems.SetEquals(compareSet))
            {
                reset = true;
                previousItems.Clear();
                // Copy for next time
                previousItems.UnionWith(compareSet);
            }
            compareSet.Recycle();
            return(reset);
        }
        public void FloodCollect(int _x, int _y, ref List <GridObject> ret, Func <GridObject, bool> comparator)
        {
            void InnerFunc(int x, int y, ref List <GridObject> found, HashSet <pair <int, int> > searched)
            {
                var current = new pair <int, int>(x, y);

                if (searched.Contains(current))
                {
                    return;
                }
                searched.Add(current);

                var obj = ObjectAt(x, y);

                if (obj == null)
                {
                    return;
                }

                if (comparator == null || comparator.Invoke(obj))
                {
                    found.Add(obj);

                    InnerFunc(x + 1, y, ref found, searched);
                    InnerFunc(x - 1, y, ref found, searched);
                    InnerFunc(x, y + 1, ref found, searched);
                    InnerFunc(x, y - 1, ref found, searched);
                }
            }

            var search = HashSetPool <pair <int, int> > .New();

            InnerFunc(_x, _y, ref ret, search);
            search.Free();
        }
Пример #13
0
			/// <summary>
			/// Applied before RefreshRows runs.
			/// </summary>
			internal static bool Prefix(TableScreen __instance) {
				var identities = HashSetPool<IAssignableIdentity, TableScreen>.Allocate();
				var living = Components.LiveMinionIdentities.Items;
				StoredMinionIdentity smi;
				// Living Duplicants
				for (int i = 0; i < living.Count; i++) {
					var dupe = living[i];
					if (dupe != null)
						identities.Add(dupe);
				}
				// Duplicants in vanilla rockets and similar
				foreach (var minionStorage in Components.MinionStorages.Items)
					foreach (var info in minionStorage.GetStoredMinionInfo()) {
						var dupe = info.serializedMinion;
						if (dupe != null && (smi = dupe.Get<StoredMinionIdentity>()) != null)
							__instance.AddRow(smi);
					}
				ClearAndAddRows(__instance, identities);
				// Add the missing rows
				foreach (var missingMinion in identities)
					__instance.AddRow(missingMinion);
				identities.Recycle();
				if (DlcManager.FeatureClusterSpaceEnabled())
					AddDividers(__instance);
				SortRows(__instance);
				__instance.rows_dirty = false;
				return false;
			}
Пример #14
0
        private void Do(int C, int P, int M, bool noisy, bool useRAII, Func <HashSet <int>, int> test)
        {
            var pool = HashSetPool <int> .Create(C);

            void testCore(HashSet <int> set)
            {
                var len = set.Count;

                Assert.AreEqual(0, len);

                var L = test(set);

                len = set.Count;
                Assert.AreEqual(L, len);
            }

            if (useRAII)
            {
                Run(() => pool.New(), o => o.HashSet, o => o.Dispose(), testCore, P, M, noisy);
            }
            else
            {
                Run(() => pool.Allocate(), o => o, o => pool.Free(o), testCore, P, M, noisy);
            }
        }
Пример #15
0
        /// <summary>
        /// Removes all invalid (dead, deleted) Duplicants from the access list if it is not
        /// set to Public.
        /// </summary>
        public void CleanupAccess()
        {
            if (allowIDs != null)
            {
                var preserve = HashSetPool <int, WorkshopProfile> .Allocate();

                var intersection = ListPool <int, WorkshopProfile> .Allocate();

                KPrefabID minionID;
                // Add all living Duplicants
                foreach (var id in Components.LiveMinionIdentities.Items)
                {
                    if (id != null && (minionID = id.GetComponent <KPrefabID>()) != null)
                    {
                        preserve.Add(minionID.InstanceID);
                    }
                }
                // Remove all dead ones
                foreach (int id in allowIDs)
                {
                    if (preserve.Contains(id))
                    {
                        intersection.Add(id);
                    }
                }
                allowIDs.Clear();
                // Copy back since removing from active enumeration is an error
                foreach (var id in intersection)
                {
                    allowIDs.Add(id);
                }
                intersection.Recycle();
                preserve.Recycle();
            }
        }
Пример #16
0
        /// <summary>
        /// Looks up a particular item tag to see what foods it can be used to produce.
        /// </summary>
        /// <param name="tag">The item tag to look up.</param>
        /// <returns>The foods for which it can be used, or an empty array if it cannot be used
        /// for any foods.</returns>
        public FoodResult[] Lookup(Tag tag)
        {
            if (tag == null)
            {
                throw new ArgumentNullException("tag");
            }
            // Check for existing list
            if (!cache.TryGetValue(tag, out IList <FoodResult> items))
            {
                var seen = HashSetPool <Tag, FoodRecipeCache> .Allocate();

                try {
                    items = new List <FoodResult>();
                    SearchForRecipe(tag, items, seen, 1.0f);
                    cache.Add(tag, items);
                } finally {
                    seen.Recycle();
                }
            }
            // Create a copy of the results
            int n      = items.Count;
            var result = new FoodResult[n];

            if (n > 0)
            {
                items.CopyTo(result, 0);
            }
            return(result);
        }
Пример #17
0
        public static void Trigger <TArgs>(EventHook hook, TArgs args)
        {
            HashSet <Action <TArgs> > handlers = null;

            if (events.TryGetValue(hook, out var potentialHandlers))
            {
                foreach (var potentialHandler in potentialHandlers)
                {
                    if (potentialHandler is Action <TArgs> handler)
                    {
                        if (handlers == null)
                        {
                            handlers = HashSetPool <Action <TArgs> > .New();
                        }

                        handlers.Add(handler);
                    }
                }
            }

            if (handlers != null)
            {
                foreach (var handler in handlers)
                {
                    if (!potentialHandlers.Contains(handler))
                    {
                        continue;
                    }

                    handler.Invoke(args);
                }

                handlers.Free();
            }
        }
Пример #18
0
 /// <summary>
 /// Destroys the cached list after a drag completes.
 /// </summary>
 private void DoneDrag()
 {
     if (cachedTypes != null)
     {
         cachedTypes.Recycle();
         cachedTypes = null;
     }
 }
Пример #19
0
        /// <summary>
        /// Refreshes one set of required conditions.
        /// </summary>
        /// <param name="conditionType">The condition type to refresh.</param>
        /// <param name="nh">The number of header rows allocated.</param>
        /// <param name="nr">The number of content rows allocated.</param>
        private void RefreshProcessConditions(ProcessConditionType conditionType, ref int nh,
                                              ref int nr)
        {
            var conditions = lastSelection.conditions.GetConditionSet(conditionType);
            int n          = conditions.Count;

            if (n > 0)
            {
                int    nHeaders = nh, nRows = nr;
                var    pr            = processRows;
                var    ph            = processHeaders;
                string conditionName = StringFormatter.ToUpper(conditionType.ToString());
                var    seen          = HashSetPool <ProcessCondition, SimpleInfoScreen> .Allocate();

                ProcessConditionRow row;
                // Grab a cached header if possible
                if (nHeaders >= ph.Count)
                {
                    ph.Add(row = new ProcessConditionRow(Util.KInstantiateUI(sis.
                                                                             processConditionHeader.gameObject, conditionParent, true), true));
                }
                else
                {
                    row = ph[nHeaders];
                    row.SetActive(true);
                }
                row.SetTitle(Strings.Get("STRINGS.UI.DETAILTABS.PROCESS_CONDITIONS." +
                                         conditionName), Strings.Get("STRINGS.UI.DETAILTABS.PROCESS_CONDITIONS." +
                                                                     conditionName + "_TOOLTIP"));
                processVisible.Add(row);
                nh = nHeaders + 1;
                for (int i = 0; i < n; i++)
                {
                    var condition = conditions[i];
                    if (condition.ShowInUI() && (condition is RequireAttachedComponent || seen.
                                                 Add(condition)))
                    {
                        if (nRows >= pr.Count)
                        {
                            row = new ProcessConditionRow(Util.KInstantiateUI(sis.
                                                                              processConditionRow, conditionParent, true), false);
                            pr.Add(row);
                        }
                        else
                        {
                            row = pr[nRows];
                            row.SetActive(true);
                        }
                        processVisible.Add(row);
                        row.SetCondition(condition);
                        nRows++;
                    }
                }
                nr = nRows;
                seen.Recycle();
            }
        }
Пример #20
0
 /// <summary>
 /// Destroys the items in the set and recycles the list.
 /// </summary>
 /// <param name="destroy">The objects to destroy.</param>
 private static void DestroyAndRecycle(HashSetPool <GameObject, FilteredDestroyTool> .
                                       PooledHashSet destroy)
 {
     foreach (var gameObject in destroy)
     {
         Util.KDestroyGameObject(gameObject);
     }
     destroy.Recycle();
 }
    protected override void OnPaintCell(int cell, int distFromOrigin)
    {
        base.OnPaintCell(cell, distFromOrigin);
        recentlyAffectedCells.Add(cell);
        Game.CallbackInfo item = new Game.CallbackInfo(delegate
        {
            recentlyAffectedCells.Remove(cell);
        }, false);
        int              index       = Game.Instance.callbackManager.Add(item).index;
        int              gameCell    = cell;
        SimHashes        new_element = SimHashes.Vacuum;
        CellElementEvent sandBoxTool = CellEventLogger.Instance.SandBoxTool;
        float            mass        = 0f;
        float            temperature = 0f;
        int              callbackIdx = index;

        SimMessages.ReplaceElement(gameCell, new_element, sandBoxTool, mass, temperature, Db.Get().Diseases.GetIndex(settings.Disease.IdHash), 0, callbackIdx);
        HashSetPool <GameObject, SandboxDestroyerTool> .PooledHashSet pooledHashSet = HashSetPool <GameObject, SandboxDestroyerTool> .Allocate();

        foreach (Pickupable item2 in Components.Pickupables.Items)
        {
            if (Grid.PosToCell(item2) == cell)
            {
                pooledHashSet.Add(item2.gameObject);
            }
        }
        foreach (BuildingComplete item3 in Components.BuildingCompletes.Items)
        {
            if (Grid.PosToCell(item3) == cell)
            {
                pooledHashSet.Add(item3.gameObject);
            }
        }
        if ((Object)Grid.Objects[cell, 1] != (Object)null)
        {
            pooledHashSet.Add(Grid.Objects[cell, 1]);
        }
        foreach (Crop item4 in Components.Crops.Items)
        {
            if (Grid.PosToCell(item4) == cell)
            {
                pooledHashSet.Add(item4.gameObject);
            }
        }
        foreach (Health item5 in Components.Health.Items)
        {
            if (Grid.PosToCell(item5) == cell)
            {
                pooledHashSet.Add(item5.gameObject);
            }
        }
        foreach (GameObject item6 in pooledHashSet)
        {
            Util.KDestroyGameObject(item6);
        }
        pooledHashSet.Recycle();
    }
        public static void FindMatches(StyleMatchingContext context, List <SelectorMatchRecord> matchedSelectors, int parentSheetIndex)
        {
            Debug.Assert(matchedSelectors.Count == 0);

            Debug.Assert(context.currentElement != null, "context.currentElement != null");

            var toggleRoot           = false;
            var processedStyleSheets = HashSetPool <StyleSheet> .Get();

            try
            {
                var element = context.currentElement;
                for (var i = context.styleSheetCount - 1; i >= 0; --i)
                {
                    var styleSheet = context.GetStyleSheetAt(i);
                    if (!processedStyleSheets.Add(styleSheet))
                    {
                        continue;
                    }

                    // If the sheet is added on the element consider it as :root
                    if (i > parentSheetIndex)
                    {
                        element.pseudoStates |= PseudoStates.Root;
                        toggleRoot            = true;
                    }
                    else
                    {
                        element.pseudoStates &= ~PseudoStates.Root;
                    }

                    var record = new SelectorMatchRecord(styleSheet, i);

                    FastLookup(styleSheet.orderedTypeSelectors, matchedSelectors, context, element.typeName, ref record);
                    FastLookup(styleSheet.orderedTypeSelectors, matchedSelectors, context, "*", ref record);

                    if (!string.IsNullOrEmpty(element.name))
                    {
                        FastLookup(styleSheet.orderedNameSelectors, matchedSelectors, context, element.name, ref record);
                    }

                    foreach (string @class in element.GetClassesForIteration())
                    {
                        FastLookup(styleSheet.orderedClassSelectors, matchedSelectors, context, @class, ref record);
                    }
                }

                if (toggleRoot)
                {
                    element.pseudoStates &= ~PseudoStates.Root;
                }
            }
            finally
            {
                HashSetPool <StyleSheet> .Release(processedStyleSheets);
            }
        }
Пример #23
0
        public void PooledHashSet_GottenTooBig()
        {
            var bigPool = HashSetPool <int> .Create(1, EqualityComparer <int> .Default, 2048);

            var smallPool = HashSetPool <int> .Create(1, EqualityComparer <int> .Default, 16);

            TooBig(() => PooledHashSet <int> .New(), h => h.HashSet, (h, n) => h.UnionWith(Enumerable.Range(0, n)), 1024);
            TooBig(() => bigPool.New(), h => h.HashSet, (h, n) => h.UnionWith(Enumerable.Range(0, n)), 2048);
            TooBig(() => smallPool.New(), h => h.HashSet, (h, n) => h.UnionWith(Enumerable.Range(0, n)), 16);
        }
Пример #24
0
        public static void RefreshSelectionToolbar()
        {
            var sceneViews         = SceneView.sceneViews.OfType <SceneView>().ToListPooled();
            var sceneViewsToRemove = HashSetPool <SceneView> .New();

            try
            {
                // Don't pick prefabs
                selectionToolbarTargets = Selection.transforms.Select(t => t.gameObject).ToArray();

                if (selectionToolbarTargets.Length > 0)
                {
                    // Update controls for each open scene view
                    foreach (var sceneView in sceneViews)
                    {
                        var toolbar = ObjectToolbarProvider.GetToolbar(selectionToolbarTargets);

                        var toolbarControl = toolbarControlProvider.GetControl(toolbar, sceneView);

                        selectionToolbarControls[sceneView] = toolbarControl;

                        if (sceneView == SceneView.lastActiveSceneView)
                        {
                            ShortcutsIntegration.primaryToolbar = toolbarControl;
                        }
                    }
                }
                else
                {
                    selectionToolbarControls.Clear();
                    ShortcutsIntegration.primaryToolbar = null;
                }

                // Remove toolbars for closed scene views
                foreach (var selectionToolbarControl in selectionToolbarControls)
                {
                    if (!sceneViews.Contains(selectionToolbarControl.Key))
                    {
                        sceneViewsToRemove.Add(selectionToolbarControl.Key);
                    }
                }

                foreach (var sceneViewToRemove in sceneViewsToRemove)
                {
                    selectionToolbarControls.Remove(sceneViewToRemove);
                }

                SceneView.RepaintAll();
            }
            finally
            {
                sceneViews.Free();
                sceneViewsToRemove.Free();
            }
        }
Пример #25
0
        public void UnLoad(HashSet <KeyValuePair <IgnoreCaseString, GameAssetBundle> > removeList, ref AssetBundleContext context)
        {
            foreach (var pair in removeList)
            {
                GameAssetBundle assetBundle = pair.Value;
                var             key         = pair.Key;
                if (assetBundle.AssetBundle != null)
                {
                    Debug.LogFormat("UnLoad {0}", assetBundle.AssetBundle);
                    //UnLoadAsset
                    var allassets = assetBundle.GetAllAssets();
                    if (allassets != null)
                    {
                        foreach (var kvAllasset in allassets)
                        {
                            var asset = kvAllasset.Value;
                            if (asset != null)
                            {
                                UnityEngine.Object.DestroyImmediate(asset, true);
                            }
                        }
                    }
                    //Unload Reference
                    if (assetBundle.References != null)
                    {
                        for (int i = 0; i < assetBundle.References.Count; i++)
                        {
                            var target = assetBundle.References[i];
                            if (target != null && target.IsAlive && target.Target != null && target.Target is UnityEngine.Object)
                            {
                                UnityEngine.Object.Destroy(target.Target as UnityEngine.Object);
                            }
                        }
                    }

                    assetBundle.AssetBundle.Unload(true);
                    assetBundle.Dispose();
                }

                context.Cache.RemoveAssetBundle(key);
            }


            if (removeList != null && removeList.Count > 0)
            {
                HashSetPool <KeyValuePair <IgnoreCaseString, GameAssetBundle> > .Release(removeList);

#if UNITY_EDITOR
                Debug.LogFormat("<color=#ff0a22ff>left AssetBundle Count:{0} at :{1}</color>", context.Cache.AssetBundleCount(), Time.frameCount);
#else
                Debug.LogFormat("left AssetBundle Count:{0} at :{1}", context.Cache.AssetBundleCount(), Time.frameCount);
#endif
                context.IsDestroying = false;
            }
        }
Пример #26
0
        public void Untrack(ChaFile chaFile)
        {
            UpdateLastBusyTime();

            var regID = chaFile.GetRegistrationID();
            //Logger.LogDebug($"Attempting to unregister translation replacements: {regID} {chaFile.GetFullName()}");
            var toClean = HashSetPool <string> .Get();

            try
            {
                lock (_lock)
                {
                    // make a copy of current entries in _regIDtoNamesMap
                    var namesToCheck = ListPool <string> .Get();

                    try
                    {
                        if (_regIDtoNamesMap.TryGetValue(regID, out var tmp))
                        {
                            namesToCheck.AddRange(tmp);
                        }
                        foreach (var name in namesToCheck)
                        {
                            if (string.IsNullOrEmpty(name))
                            {
                                continue;
                            }
                            CounterRemove(name, regID);

                            if (CounterCount(name) != 0 || !_currentlyRegisteredReplacements.Contains(name))
                            {
                                continue;
                            }
                            toClean.Add(name);
                        }
                    }
                    finally
                    {
                        ListPool <string> .Release(namesToCheck);
                    }

                    _regIDtoCardMap.Remove(regID);
                }

                foreach (var name in toClean)
                {
                    CheckNamesForCleanup(name);
                }
            }
            finally
            {
                HashSetPool <string> .Release(toClean);
            }
        }
Пример #27
0
    public static HashSet <T> ToHashSetPooled <T>(this IEnumerable <T> source)
    {
        var hashSet = HashSetPool <T> .New();

        foreach (var item in source)
        {
            hashSet.Add(item);
        }

        return(hashSet);
    }
Пример #28
0
 HashSet <T> InitCollection <T>(HashSet <T> container)
 {
     if (container == null)
     {
         container = HashSetPool <T> .Get();
     }
     else
     {
         container.Clear();
     }
     return(container);
 }
Пример #29
0
        public AssetBundleCache(int capacity)
        {
            _assetBundleInfoDict = DictionaryPool <IgnoreCaseString, AssetBundleInfo> .Get();

            _assetbundleDictionary = DictionaryPool <IgnoreCaseString, GameAssetBundle> .Get();

            _exceptionHashSet = HashSetPool <IgnoreCaseString> .Get();

            _assetbundleincludes = DictionaryPool <string, List <string> > .Get();

            _remoteinfo = null;
        }
Пример #30
0
        /// <summary>
        /// Destroys plants in the cell.
        /// </summary>
        /// <param name="cell">The cell to destroy.</param>
        private void DestroyPlants(int cell)
        {
            var destroy = HashSetPool <GameObject, FilteredDestroyTool> .Allocate();

            foreach (var crop in Components.Uprootables.Items)
            {
                if (Grid.PosToCell(crop) == cell)
                {
                    destroy.Add(crop.gameObject);
                }
            }
            DestroyAndRecycle(destroy);
        }