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); } }
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); } }
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; } }
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); } }
protected virtual IEnumerable <KeyValuePair <string, string> > GetNamesToRegister(ChaFile chaFile) { var handled = HashSetPool <string> .Get(); var controller = chaFile.GetTranslationHelperController(); try { foreach (var nameEntry in chaFile.EnumerateNames()) { var name = nameEntry.Value; if (handled.Contains(name)) { continue; } handled.Add(name); yield return(new KeyValuePair <string, string>(name, name)); if (controller == null) { continue; } var origName = controller.OriginalNames[nameEntry.Key]; if (origName.IsNullOrEmpty() || origName == name || handled.Contains(origName)) { continue; } handled.Add(origName); yield return(new KeyValuePair <string, string>(origName, origName)); } var fullname = chaFile.GetFullName(); foreach (var name in new[] { fullname, chaFile.GetOriginalFullName(), chaFile.GetFormattedOriginalName() }) { if (handled.Contains(name)) { continue; } handled.Add(name); yield return(new KeyValuePair <string, string>(name, name)); } } finally { HashSetPool <string> .Release(handled); } }
private void HandleAttributeOpenAndShut(Dictionary <Block, int> impactBlocks, Vector2Int scanDisplacement, Stack <Command> tickCommands) { var toDestroyBlocks = HashSetPool <Block> .Get(); foreach (var impactBlockPair in impactBlocks) { var block = impactBlockPair.Key; var impact = impactBlockPair.Value; var isOpen = HasAttribute(block, AttributeCategory.Open); var isShut = HasAttribute(block, AttributeCategory.Shut); if (!isOpen && !isShut) { continue; } var preMovePosition = impact == 1 ? block.position + scanDisplacement : block.position - scanDisplacement; var preMovePositionBlocks = m_logicGameManager.Map[preMovePosition.x, preMovePosition.y]; foreach (var preMovePositionBlock in preMovePositionBlocks) { if (toDestroyBlocks.Contains(preMovePositionBlock)) { continue; } if ((isOpen && HasAttribute(preMovePositionBlock, AttributeCategory.Shut)) || (isShut && HasAttribute(preMovePositionBlock, AttributeCategory.Open))) { toDestroyBlocks.Add(block); toDestroyBlocks.Add(preMovePositionBlock); break; } } } foreach (var block in toDestroyBlocks) { if (impactBlocks.ContainsKey(block)) { impactBlocks.Remove(block); } PerformDestroyBlockCommand(block, tickCommands); } HashSetPool <Block> .Release(toDestroyBlocks); }
public void Dispose() { if (_assetBundleInfoDict != null) { DictionaryPool <IgnoreCaseString, AssetBundleInfo> .Release(_assetBundleInfoDict); _assetBundleInfoDict = null; } if (_assetbundleDictionary != null) { DictionaryPool <IgnoreCaseString, GameAssetBundle> .Release(_assetbundleDictionary); _assetbundleDictionary = null; } if (_assetbundleincludes != null) { foreach (var item in _assetbundleincludes) { ListPool <string> .Release(item.Value); } DictionaryPool <string, List <string> > .Release(_assetbundleincludes); _assetbundleincludes = null; } if (_exceptionHashSet != null) { HashSetPool <IgnoreCaseString> .Release(_exceptionHashSet); _exceptionHashSet = null; } _remoteinfo = null; }
public List <Grid.NodeItem> FindingPath(Vector3 s, Vector3 e) { Grid.NodeItem item = this.grid.getItem(s); Grid.NodeItem endNode = this.grid.getItem(e); List <Grid.NodeItem> toRelease = ListPool <Grid.NodeItem> .Get(); HashSet <Grid.NodeItem> set = HashSetPool <Grid.NodeItem> .Get(); toRelease.Add(item); List <Grid.NodeItem> list2 = new List <Grid.NodeItem>(); while (toRelease.Count > 0) { Grid.NodeItem item3 = toRelease[0]; int num = 0; int count = toRelease.Count; while (num < count) { if ((toRelease[num].fCost <= item3.fCost) && (toRelease[num].hCost < item3.hCost)) { item3 = toRelease[num]; } num++; } toRelease.Remove(item3); set.Add(item3); if (item3 == endNode) { list2 = this.generatePath(item, endNode); break; } List <Grid.NodeItem> list3 = this.grid.getNeibourhood(item3); for (int i = 0; i < list3.Count; i++) { Grid.NodeItem item4 = list3[i]; if (!item4.isWall && !set.Contains(item4)) { int num4 = item3.gCost + this.getDistanceNodes(item3, item4); if ((num4 < item4.gCost) || !toRelease.Contains(item4)) { item4.gCost = num4; item4.hCost = this.getDistanceNodes(item4, endNode); item4.parent = item3; if (!toRelease.Contains(item4)) { toRelease.Add(item4); } } } } } if (list2.Count == 0) { list2 = this.generatePath(item, null); } ListPool <Grid.NodeItem> .Release(toRelease); HashSetPool <Grid.NodeItem> .Release(set); return(list2); }
SpriteTrackData BuildGoData(AssetTreeModel <SpriteTrackData> dataModel, Dictionary <Sprite, HashSet <Object> > allUsed, Dictionary <Sprite, SimpleSpriteInfo> sprCache, string assetpath) { GameObject gameObject = AssetDatabase.LoadAssetAtPath <GameObject>(assetpath); if (gameObject) { HashSet <string> allHashSet = HashSetPool <string> .Get(); SpriteTrackData data = new SpriteTrackData(); data.ShowMode = SpriteShowMode.Prefabs; data.Id = AssetTreeManager.mIns.GetUniqueId(); data.IconName = AssetTreeManager.mIns.GetIconName(AssetBundleResType.GameObject); data.DisplayName = Path.GetFileNameWithoutExtension(assetpath); data.GameObjectData.GoData = GetGoData(gameObject); string bundleName = ""; AssetImporter importer = AssetImporter.GetAtPath(assetpath); if (importer) { bundleName = importer.assetBundleName; } data.GameObjectData.SprData.BundleName = bundleName; data.GameObjectData.SprData.AssetPath = assetpath; var allScripts = gameObject.GetComponentsInChildren <MonoBehaviour>(true); Dictionary <Sprite, HashSet <Object> > allRecords = new Dictionary <Sprite, HashSet <Object> >(); foreach (MonoBehaviour script in allScripts) { CollectSprite(script, allRecords); } foreach (var pair in allRecords) { HashSet <Object> hashset; if (allUsed.TryGetValue(pair.Key, out hashset)) { foreach (var subdata in pair.Value) { hashset.Add(subdata); } } else { allUsed[pair.Key] = pair.Value;//new HashSet<Object>(pair.Value); } } HashSet <string> atlasHashset = HashSetPool <string> .Get(); Dictionary <Object, List <Sprite> > sprRefDictionary = Convert(allRecords); foreach (var pair in sprRefDictionary) { atlasHashset.Clear(); SpriteTrackData sprData = new SpriteTrackData(); sprData.ShowMode = SpriteShowMode.Prefabs; sprData.Id = AssetTreeManager.mIns.GetUniqueId(); sprData.DisplayName = MonoScript.FromMonoBehaviour(pair.Key as MonoBehaviour).name; sprData.IconName = AssetTreeManager.mIns.GetIconName(AssetBundleResType.Cs); sprData.GameObjectData.GoData = GetGoData(pair.Key); sprData.GameObjectData.SprData.BundleName = bundleName; sprData.GameObjectData.SprData.AssetPath = AssetDatabase.GetAssetPath(pair.Key); dataModel.Add(ref sprData); foreach (var refsprite in pair.Value) { SpriteTrackData refData = BuildData(refsprite, pair.Key, SpriteShowMode.Prefabs, sprCache); refData.UsedRefCount = 1; dataModel.Add(ref refData); dataModel.AddChild(ref sprData, ref refData); atlasHashset.Add(refData.GameObjectData.SprData.PackingTag); allHashSet.Add(refData.GameObjectData.SprData.PackingTag); } sprData.UsedRefCount = atlasHashset.Count; //refresh dataModel.Add(ref sprData); // dataModel.AddChild(ref data, ref sprData); } data.UsedRefCount = allHashSet.Count; //refresh dataModel.Add(ref data); HashSetPool <string> .Release(atlasHashset); HashSetPool <string> .Release(allHashSet); return(data); } else { SpriteTrackData data = new SpriteTrackData(); data.ShowMode = SpriteShowMode.Prefabs; data.Id = AssetTreeManager.mIns.GetUniqueId(); data.IconName = AssetTreeManager.mIns.GetIconName(AssetBundleResType.Prefab); data.DisplayName = "Load Failed"; return(data); } }
IEnumerator CollectSceneInfo(AssetTreeModel <SpriteTrackData> dataModel, Dictionary <Sprite, HashSet <Object> > allUsed, Dictionary <Sprite, SimpleSpriteInfo> sprCache) { var displayRoot = CreateDisplayRoot("Scene"); displayRoot.ShowMode = SpriteShowMode.Scene; dataModel.Add(ref displayRoot); dataModel.AddChild(dataModel.Root.Id, displayRoot.Id); var allScripts = GameObject.FindObjectsOfType <MonoBehaviour>(); Dictionary <Sprite, HashSet <Object> > allRecords = new Dictionary <Sprite, HashSet <Object> >(); int i = 0; foreach (MonoBehaviour script in allScripts) { CollectSprite(script, allRecords); yield return(DisplayProgressBar("Parse Scene", "Parsing script " + script.name, (float)i / allScripts.Length)); i++; } foreach (var pair in allRecords) { allUsed[pair.Key] = pair.Value;//new HashSet<Object>(pair.Value); } i = 0; Dictionary <Object, List <Sprite> > sprRefDictionary = Convert(allRecords); foreach (var pair in sprRefDictionary) { SpriteTrackData sprData = new SpriteTrackData(); sprData.ShowMode = SpriteShowMode.Scene; sprData.Id = AssetTreeManager.mIns.GetUniqueId(); sprData.DisplayName = pair.Key.name; sprData.IconName = AssetTreeManager.mIns.GetIconName(AssetBundleResType.Cs); sprData.SceneData.CsReferences = pair.Key as MonoBehaviour; sprData.SceneData.InstanceId = pair.Key.GetInstanceID(); sprData.SceneData.MemSize = AssetBundleEditorHelper.ConvertSize(Profiler.GetRuntimeMemorySizeLong(pair.Key)); if (sprData.SceneData.CsReferences) { sprData.SceneData.Path = GetPath(sprData.SceneData.CsReferences.gameObject); } dataModel.Add(ref sprData); HashSet <string> hashset = HashSetPool <string> .Get(); foreach (var refsprite in pair.Value) { SpriteTrackData refData = BuildData(refsprite, pair.Key, SpriteShowMode.Scene, sprCache); refData.UsedRefCount = 1; dataModel.Add(ref refData); dataModel.AddChild(ref sprData, ref refData); hashset.Add(refData.SceneData.SprData.PackingTag); } sprData.UsedRefCount = hashset.Count; //refresh dataModel.Add(ref sprData); HashSetPool <string> .Release(hashset); dataModel.AddChild(ref displayRoot, ref sprData); yield return(DisplayProgressBar("Parse Scene", "Parsing Sprite", (float)i / sprRefDictionary.Count)); i++; } }
void DetectPassengers(Vector2 movement, List <Passenger> result) { HashSet <Transform> added = HashSetPool <Transform> .Get(); float dirX = Mathf.Sign(movement.x); float dirY = Mathf.Sign(movement.y); //竖直方向移动 if (movement.y != 0) { float rayLength = Mathf.Abs(movement.y) + c_skinWidth; void action(RaycastHit2D hit) { if (added.Add(hit.transform)) { float pushX = (dirY == Defines.c_top ? movement.x : 0); float pushY = movement.y - (hit.distance - c_skinWidth) * dirY; Vector2 m = new Vector2(pushX, pushY); bool isMovingUp = dirY == Defines.c_top; Passenger p = new Passenger(hit.transform, m, isMovingUp, true); result.Add(p); } } CheckRaycast(true, rayLength, dirY, action); } //水平方向移动 if (movement.x != 0) { float rayLength = Mathf.Abs(movement.x) + c_skinWidth; void action(RaycastHit2D hit) { if (added.Add(hit.transform)) { float pushX = movement.x - (hit.distance - c_skinWidth) * dirX; float pushY = -c_skinWidth; Vector2 m = new Vector2(pushX, pushY); Passenger p = new Passenger(hit.transform, m, false, true); result.Add(p); } } CheckRaycast(false, rayLength, dirX, action); } //乘客在水平移动或向下移动的平台上 if (dirY == Defines.c_bottom || (movement.y == 0 && movement.x != 0)) { float rayLength = c_skinWidth * 2; void action(RaycastHit2D hit) { if (added.Add(hit.transform)) { Passenger p = new Passenger(hit.transform, movement, true, false); result.Add(p); } } CheckRaycast(true, rayLength, 1, action); } HashSetPool <Transform> .Release(ref added); }
/// <summary> /// This will iterate over the current UI Builder hierarchy and extract the supported animatable properties. /// This will allow to display the options to users in the same order that they are in the builder. /// </summary> void GenerateTransitionPropertiesContent() { var content = new CategoryDropdownContent(); content.AppendValue(new CategoryDropdownContent.ValueItem { value = "all", displayName = "all" }); foreach (var kvp in m_StyleCategories) { var groupName = kvp.Key.text; if (string.IsNullOrWhiteSpace(groupName) || groupName == "Transition Animations") { continue; } content.AppendCategory(new CategoryDropdownContent.Category { name = groupName }); foreach (var element in kvp.Value) { var styleName = element.GetProperty(BuilderConstants.InspectorStylePropertyNameVEPropertyName) as string; if (!string.IsNullOrWhiteSpace(styleName)) { var styleId = StyleDebug.GetStylePropertyIdFromName(styleName); if (!StylePropertyUtil.IsAnimatable(styleId)) { continue; } if (!string.IsNullOrWhiteSpace(styleId.ToString())) { content.AppendValue( new CategoryDropdownContent.ValueItem { categoryName = groupName, value = styleName, displayName = ObjectNames.NicifyVariableName(styleId.ToString()) }); } } if (!(element is FoldoutField foldoutField)) { continue; } var hashSet = HashSetPool <StylePropertyId> .Get(); try { foreach (var bindingPath in foldoutField.bindingPathArray) { var shortHandId = StyleDebug.GetStylePropertyIdFromName(bindingPath).GetShorthandProperty(); if (shortHandId == StylePropertyId.Unknown || !hashSet.Add(shortHandId)) { continue; } if (!StylePropertyUtil.IsAnimatable(shortHandId)) { continue; } if (!string.IsNullOrWhiteSpace(shortHandId.ToString())) { content.AppendValue( new CategoryDropdownContent.ValueItem { categoryName = groupName, value = BuilderNameUtilities.ConvertStyleCSharpNameToUssName( shortHandId.ToString()), displayName = ObjectNames.NicifyVariableName(shortHandId.ToString()) }); } } } finally { HashSetPool <StylePropertyId> .Release(hashSet); } } } content.AppendSeparator(); content.AppendValue(new CategoryDropdownContent.ValueItem { value = "none", displayName = "none" }); content.AppendValue(new CategoryDropdownContent.ValueItem { value = "initial", displayName = "initial" }); content.AppendValue(new CategoryDropdownContent.ValueItem { value = "ignored", displayName = "ignored" }); TransitionPropertyDropdownContent.Content = content; }
public void Dispose() { HashSetPool.Release(Set); }
protected override IEnumerator StartJobs() { var jobs = ListPool <Coroutine> .Get(); var fullName = _chaFile.GetFullName(); var handled = HashSetPool <int> .Get(); if (TranslationHelper.Instance.NamePresetManager.TryTranslateCardNames(_chaFile, out var result)) { foreach (var entry in result) { FullNameHandled = FullNameHandled || entry.Key == "fullname"; var i = GeBoAPI.Instance.ChaFileNameToIndex(entry.Key); if (i < 0 || string.IsNullOrEmpty(entry.Value) || _chaFile.GetName(i) == entry.Value) { continue; } _chaFile.SetTranslatedName(i, entry.Value); handled.Add(i); } } var sex = _chaFile.GetSex(); foreach (var name in _chaFile.EnumerateNames()) { if (handled.Contains(name.Key)) { continue; } FullNameHandled = FullNameHandled || name.Value == fullName; var i = name.Key; var chaFile = _chaFile; var nameScope = new NameScope(sex, _chaFile.GetNameType(i)); if (TryGetRecentTranslation(nameScope, name.Value, out var cachedName)) { // if true, but name unchanged then name in NoTranslate if (name.Value != cachedName) { chaFile.SetTranslatedName(i, cachedName); } continue; } if (!StringUtils.ContainsJapaneseChar(name.Value)) { NoTranslate[nameScope].Add(name.Value); continue; } JobStarted(); var job = StartCoroutine(Instance.TranslateCardName(name.Value, nameScope, Handlers.UpdateCardName(chaFile, i), Handlers.AddNameToAutoTranslationCache(name.Value, true), JobCompleteHandler)); jobs.Add(job); } HashSetPool <int> .Release(handled); foreach (var job in jobs) { yield return(job); } ListPool <Coroutine> .Release(jobs); }
public void Cleanup(bool deepClean = false) { if (!_inUse) { return; } var orig = _nameToIDMap.Count; int current; var namesToRemove = HashSetPool <string> .Get(); try { lock (_lock) { if (deepClean) { var deadEntries = _regIDtoCardMap .Where(e => !e.Value.IsAlive || (e.Value.Target as ChaFile).GetRegistrationID() != e.Key) .Select(e => e.Key).ToList(); foreach (var deadEntry in deadEntries) { Logger.DebugLogDebug($"Cleanup: dead entry: {deadEntry}"); _regIDtoCardMap.Remove(deadEntry); } foreach (var entry in _nameToIDMap) { var removed = entry.Value.RemoveWhere(e => deadEntries.Contains(e)); if (removed > 0) { Logger.DebugLogDebug($"Cleanup: removed {removed} entries for {entry.Key}"); } } } foreach (var name in _nameToIDMap.Keys.AsEnumerable().Where(key => _nameToIDMap[key].Count == 0) .ToList()) { namesToRemove.Add(name); _nameToIDMap.Remove(name); } current = _nameToIDMap.Count; _inUse = current > 0; } CheckNamesForCleanup(namesToRemove.ToArray()); } finally { HashSetPool <string> .Release(namesToRemove); } if (orig <= current) { return; } Logger.DebugLogDebug( $"{nameof(TranslatorReplacementsManager)}.{nameof(Cleanup)}: removed {orig - current} entries ({current} remain)"); }
private IEnumerator DoCleanupCheck() { var workNames = HashSetPool <string> .Get(); try { int UpdateWorkNames() { if (workNames.Count > 0) { return(workNames.Count); } lock (_lock) { if (_namesPendingCleanupCheck.Count == 0) { return(0); } foreach (var name in _namesPendingCleanupCheck.ToList()) { _namesPendingCleanupCheck.Remove(name); workNames.Add(name); } } return(workNames.Count); } var replacements = GetReplacements(); while (UpdateWorkNames() > 0) { var idleTimeEnd = _lastBusyTime + CleanupIdleTime; while (Time.unscaledTime <= idleTimeEnd) { yield return(_cleanupIdleDelay); } var name = workNames.FirstOrDefault(); workNames.Remove(name); if (string.IsNullOrEmpty(name)) { continue; } yield return(null); lock (_lock) { if (!_currentlyRegisteredReplacements.Contains(name) || CounterCount(name) != 0) { continue; } if (replacements?.Remove(name) ?? false) { Logger.DebugLogDebug($"Unregistering as translation replacement: {name}"); } _currentlyRegisteredReplacements.Remove(name); } } } finally { HashSetPool <string> .Release(workNames); } }