public void TestTrim() { FasterList <int> list = new FasterList <int>(); for (int i = 0; i < 10; i++) { list.Add(i); } list.UnorderedRemoveAt(3); list.UnorderedRemoveAt(0); list.UnorderedRemoveAt(7); list.Trim(); Assert.That(list.capacity, Is.EqualTo(7)); Assert.That(list.count, Is.EqualTo(7)); }
static void Log(string txt, LogType type, Exception e = null, Dictionary <string, string> extraData = null) { for (int i = 0; i < _loggers.Count; i++) { if (_loggers[i].IsValid == true) { _loggers[i].Target.Log(txt, type, e, extraData); } else { _loggers.UnorderedRemoveAt(i); i--; } } }
static void ExecuteRoutines(FasterList <IEnumerator> list) { var count = list.Count; var routines = list.ToArrayFast(); for (int i = 0; i < count; i++) { var ret = routines[i].MoveNext(); if (ret == false) { list.UnorderedRemoveAt(i); count--; i--; } } }
public QueryGroups Except(ExclusiveGroupStruct[] groupsToIgnore) { var groupsCount = groups.count; for (int i = 0; i < groupsToIgnore.Length; i++) { for (int j = 0; j < groupsCount; j++) { if (groupsToIgnore[i] == groups[j]) { groups.UnorderedRemoveAt(j); j--; groupsCount--; } } } return(this); }
/// <summary> /// Remember that this operation os O(N*M*P) where N,M,P are the number of groups where each component /// is found. /// </summary> /// <typeparam name="T1"></typeparam> /// <typeparam name="T2"></typeparam> /// <typeparam name="T3"></typeparam> /// <returns></returns> public LocalFasterReadOnlyList <ExclusiveGroupStruct> FindGroups <T1, T2, T3>() where T1 : IEntityComponent where T2 : IEntityComponent where T3 : IEntityComponent { FindGroups <T1, T2>(); FasterList <ExclusiveGroupStruct> result = groups.Value; if (result.count == 0) { return(result); } if (_groupsPerEntity.TryGetValue(TypeRefWrapper <T3> .wrapper , out FasterDictionary <uint, ITypeSafeDictionary> result3) == false) { return(result); } var result3Count = result3.count; var fasterDictionaryNodes3 = result3.unsafeKeys; for (int j = 0; j < result3Count; j++) { for (int i = (int)0; i < result.count; i++) { if (fasterDictionaryNodes3[j].key == result[i]) { break; } result.UnorderedRemoveAt(i); i--; } } return(result); }
public bool MoveNext() { if (false == _flushingOperation.stopped) //don't start anything while flushing { _flushTaskDel(_newTaskRoutines, _coroutines, _flushingOperation); } else if (_runnerBehaviourForUnityCoroutine != null) { _runnerBehaviourForUnityCoroutine.StopAllCoroutines(); } UnityEngine.Profiling.Profiler.BeginSample(_info.runnerName); for (int i = 0; _info.MoveNext(i, _coroutines.Count); i++) { var pausableTask = _coroutines[i]; //let's spend few words on this. //yielded YieldInstruction and AsyncOperation can //only be processed internally by Unity. //The simplest way to handle them is to hand them to Unity itself. //However while the Unity routine is processed, the rest of the //coroutine is waiting for it. This would defeat the purpose //of the parallel procedures. For this reason, a Parallel //task will mark the enumerator returned as ParallelYield which //will change the way the routine is processed. //in this case the MonoRunner won't wait for the Unity routine //to continue processing the next tasks. //Note that it is much better to return wrap AsyncOperation around //custom IEnumerator classes then returning them directly as //most of the time they don't need to be handled by Unity as //YieldInstructions do /// /// Handle special Unity instructions /// you should avoid them or wrap them /// around custom IEnumerator to avoid /// the cost of two allocations per instruction /// if (_runnerBehaviourForUnityCoroutine != null && _flushingOperation.stopped == false) { var current = pausableTask.Current; if (current is YieldInstruction) { var handItToUnity = new HandItToUnity (current, pausableTask, _resumeOperation, _flushingOperation); //remove the special instruction. it will //be added back once Unity completes. _coroutines.UnorderedRemoveAt(i--); var coroutine = _runnerBehaviourForUnityCoroutine.StartCoroutine (handItToUnity.GetEnumerator()); (pausableTask as PausableTask).onExplicitlyStopped = () => { _runnerBehaviourForUnityCoroutine.StopCoroutine(coroutine); handItToUnity.ForceStop(); }; continue; } var parallelTask = (current as ParallelTaskCollection.ParallelTask); if (parallelTask != null && parallelTask.current is YieldInstruction) { var handItToUnity = new HandItToUnity(parallelTask.current); parallelTask.Add(handItToUnity.WaitUntilIsDone()); var coroutine = _runnerBehaviourForUnityCoroutine.StartCoroutine (handItToUnity.GetEnumerator()); (pausableTask as PausableTask).onExplicitlyStopped = () => { _runnerBehaviourForUnityCoroutine.StopCoroutine(coroutine); handItToUnity.ForceStop(); }; } } bool result; #if TASKS_PROFILER_ENABLED result = Svelto.Tasks.Profiler.TaskProfiler.MonitorUpdateDuration(pausableTask, _info.runnerName); #else #if PROFILER UnityEngine.Profiling.Profiler.BeginSample(_info.runnerName.FastConcat("+", pausableTask.ToString())); #endif result = pausableTask.MoveNext(); #if PROFILER UnityEngine.Profiling.Profiler.EndSample(); #endif #endif if (result == false) { var disposable = pausableTask as IDisposable; if (disposable != null) { disposable.Dispose(); } _coroutines.UnorderedRemoveAt(i--); } } UnityEngine.Profiling.Profiler.EndSample(); if (_flushingOperation.stopped == true && _coroutines.Count == 0) { //once all the coroutines are flushed //the loop can return accepting new tasks _flushingOperation.stopped = false; } return(true); }
internal static IEnumerator Process( ThreadSafeQueue <IPausableTask> newTaskRoutines, FasterList <IPausableTask> coroutines, FlushingOperation flushingOperation, RunningTasksInfo info, FlushTasksDel flushTaskDel, RunnerBehaviour runnerBehaviourForUnityCoroutine, Action <IPausableTask> resumeOperation) { while (true) { if (false == flushingOperation.stopped) //don't start anything while flushing { flushTaskDel(newTaskRoutines, coroutines, flushingOperation); } else if (runnerBehaviourForUnityCoroutine != null) { runnerBehaviourForUnityCoroutine.StopAllCoroutines(); } info.count = coroutines.Count; for (var i = 0; i < info.count; i++) { var pausableTask = coroutines[i]; //let's spend few words on this. //yielded YieldInstruction and AsyncOperation can //only be processed internally by Unity. //The simplest way to handle them is to hand them to Unity itself. //However while the Unity routine is processed, the rest of the //coroutine is waiting for it. This would defeat the purpose //of the parallel procedures. For this reason, a Parallel //task will mark the enumerator returned as ParallelYield which //will change the way the routine is processed. //in this case the MonoRunner won't wait for the Unity routine //to continue processing the next tasks. //Note that it is much better to return wrap AsyncOperation around //custom IEnumerator classes then returning them directly as //most of the time they don't need to be handled by Unity as //YieldInstructions do /// /// Handle special Unity instructions /// you should avoid them or wrap them /// around custom IEnumerator to avoid /// the cost of two allocations per instruction /// if (runnerBehaviourForUnityCoroutine != null && flushingOperation.stopped == false) { var current = pausableTask.Current; if (current is YieldInstruction) { var handItToUnity = new HandItToUnity (current, pausableTask, resumeOperation, flushingOperation); //remove the special instruction. it will //be added back once Unity completes. coroutines.UnorderedRemoveAt(i--); info.count = coroutines.Count; var coroutine = runnerBehaviourForUnityCoroutine.StartCoroutine (handItToUnity.GetEnumerator()); (pausableTask as PausableTask).onExplicitlyStopped = () => { runnerBehaviourForUnityCoroutine.StopCoroutine(coroutine); handItToUnity.ForceStop(); }; continue; } var parallelTask = (current as ParallelTaskCollection.ParallelTask); if (parallelTask != null && parallelTask.current is YieldInstruction) { var handItToUnity = new HandItToUnity(parallelTask.current); parallelTask.Add(handItToUnity.WaitUntilIsDone()); var coroutine = runnerBehaviourForUnityCoroutine.StartCoroutine (handItToUnity.GetEnumerator()); (pausableTask as PausableTask).onExplicitlyStopped = () => { runnerBehaviourForUnityCoroutine.StopCoroutine(coroutine); handItToUnity.ForceStop(); }; } } bool result; #if TASKS_PROFILER_ENABLED && UNITY_EDITOR result = TASK_PROFILER.MonitorUpdateDuration(pausableTask, info.runnerName); #else result = pausableTask.MoveNext(); #endif if (result == false) { var disposable = pausableTask as IDisposable; if (disposable != null) { disposable.Dispose(); } coroutines.UnorderedRemoveAt(i--); } info.count = coroutines.Count; } if (flushingOperation.stopped == true && coroutines.Count == 0) { //once all the coroutines are flushed //the loop can return accepting new tasks flushingOperation.stopped = false; } yield return(null); } }