Beispiel #1
0
        public void Test1()
        {
            var parser         = new FiltersParser();
            var fastCollection = new FastCollection <TestClassA>();
            var parsed         = parser.ParsePredicate((TestClassA x) => x.F1 > 3, OperationTargetBuilder.BuildForRoot(fastCollection));

            Assert.IsAssignableFrom <ComparisonFilter>(parsed);
            Assert.AreEqual(ComparisonFilterType.Greater, ((ComparisonFilter)parsed).ComparisonFilterType);
            Assert.AreEqual(3, ((ComparisonFilter)parsed).Value);
            Assert.AreSame(fastCollection, ((ComparisonFilter)parsed).OperationTarget.RootFastCollection);
        }
Beispiel #2
0
        internal static void UpdateTransformations(FastCollection <TransformComponent> transformationComponents)
        {
            Dispatcher.ForEach(transformationComponents, transformation =>
            {
                UpdateTransformation(transformation);

                // Recurse
                if (transformation.Children.Count > 0)
                {
                    UpdateTransformationsRecursive(transformation.Children);
                }
            });
        }
Beispiel #3
0
        private static void UpdateTransformationsRecursive(FastCollection <TransformComponent> transformationComponents)
        {
            foreach (var transformation in transformationComponents)
            {
                UpdateTransformation(transformation);

                // Recurse
                if (transformation.Children.Count > 0)
                {
                    UpdateTransformationsRecursive(transformation.Children);
                }
            }
        }
 public void RemoveAllWorks()
 {
     var c = new FastCollection<int> { 1, 2, 3, 4, 5 };
     c.RemoveAll(x => x % 2 == 0);
     AssertEquals(c, new[] { 1, 3, 5 });
     c.RemoveAll(x => false);
     AssertEquals(c, new[] { 1, 3, 5 });
     c.RemoveAll(x => true);
     Assert.Equal(0, c.Count);
     Assert.False(c.Any());
     c.RemoveAll(x => true);
     Assert.Equal(0, c.Count);
     Assert.False(c.Any());
 }
Beispiel #5
0
        public void Remove()
        {
            IList b = new List <int>();

            var fc = new FastCollection <IList>();

            fc.Add(b, 2);

            Assert.AreEqual(1, b.Count);

            fc.Remove(b, 2);

            Assert.AreEqual(0, b.Count);
        }
        private static void UpdateTransformationsRecursive(FastCollection <TransformComponent> transformationComponents)
        {
            for (int i = 0; i < transformationComponents.Count; i++)
            {
                TransformComponent transformation = transformationComponents[i];

                UpdateTransformation(transformation);

                // Recurse
                if (transformation.Children.Count > 0)
                {
                    UpdateTransformationsRecursive(transformation.Children);
                }
            }
        }
Beispiel #7
0
        internal void UpdateTransformations(FastCollection <TransformComponent> transformationComponents)
        {
            Dispatcher.ForEach(transformationComponents, UpdateTransformationAndChildren);

            // Re-update model node links to avoid one frame delay compared reference model (ideally entity should be sorted to avoid this in future).
            if (ModelNodeLinkProcessor != null)
            {
                modelNodeLinkComponents.Clear();
                foreach (var modelNodeLink in ModelNodeLinkProcessor.ModelNodeLinkComponents)
                {
                    modelNodeLinkComponents.Add(modelNodeLink.Entity.Transform);
                }
                Dispatcher.ForEach(modelNodeLinkComponents, UpdateTransformationAndChildren);
            }
        }
        public static FastList <Vector3> GetPoints(SplineMeshComponent component, FastCollection <TransformComponent> children)
        {
            // Setup the points
            var points = new FastList <Vector3>();

            foreach (var child in children)
            {
                points.Add(child.WorldMatrix.TranslationVector);
            }

            var output = new FastList <Vector3>();

            GetPoints(points, component.SegmentLength, output);

            return(output);
        }
Beispiel #9
0
        private static void UpdateTransformationsRecursive(FastCollection <TransformComponent> transformationComponents)
        {
            for (int i = 0; i < transformationComponents.Count; i++)
            {
                TransformComponent transformation = transformationComponents[i];

                transformation.UpdateLocalMatrix();
                transformation.UpdateWorldMatrixInternal(false);

                // Recurse
                if (transformation.Children.Count > 0)
                {
                    UpdateTransformationsRecursive(transformation.Children);
                }
            }
        }
 public void AddRangeEnumerableWorks()
 {
     var c = new FastCollection<int>();
     const int count = 10;
     var array = (IEnumerable<int>)Enumerable.Range(0, count).ToArray();
     c.AddRange(array, 10);
     AssertEquals(c, array);
     c.AddRange(array, 0);
     AssertEquals(c, array);
     c.Clear();
     Assert.Equal(0, c.Count);
     c.AddRange(array, 0);
     Assert.Equal(0, c.Count);
     c.AddRange(array, 2);
     AssertEquals(c, array.Take(2));
 }
 public void AddRangeArrayWorks()
 {
     var c = new FastCollection<int>();
     var array = Enumerable.Range(0, 10).ToArray();
     c.AddRange(array, 0, 10);
     AssertEquals(c, array);
     c.AddRange(array, 5, 0);
     AssertEquals(c, array);
     c.Clear();
     Assert.Equal(0, c.Count);
     c.AddRange(array, 0);
     Assert.Equal(0, c.Count);
     c.AddRange(array, 0, 2);
     AssertEquals(c, array.Take(2));
     c.AddRange(array, 2, 3);
     AssertEquals(c, array.Take(5));
 }
Beispiel #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EntityManager"/> class.
        /// </summary>
        /// <param name="registry">The registry.</param>
        /// <exception cref="System.ArgumentNullException">registry</exception>
        protected EntityManager(IServiceRegistry registry)
        {
            if (registry == null)
            {
                throw new ArgumentNullException("registry");
            }
            Services = registry;

            entities        = new TrackingDictionary <Entity, List <EntityProcessor> >();
            enabledEntities = new TrackingHashSet <Entity>();

            processors    = new FastCollection <EntityProcessor>();
            newProcessors = new List <EntityProcessor>();

            componentTypes = new HashSet <Type>();
            processorTypes = new HashSet <Type>();
        }
Beispiel #13
0
        internal static void UpdateTransformations(FastCollection <TransformationComponent> transformationComponents, bool skipSpecialRoots)
        {
            // To avoid GC pressure (due to lambda), parallelize only if required
            if (transformationComponents.Count >= 1024)
            {
                TaskList.Dispatch(
                    transformationComponents,
                    8,
                    1024,
                    (i, transformation) =>
                {
                    if (skipSpecialRoots && transformation.isSpecialRoot)
                    {
                        return;
                    }

                    UpdateTransformation(transformation);

                    // Recurse
                    if (transformation.Children.Count > 0)
                    {
                        UpdateTransformations(transformation.Children, true);
                    }
                }
                    );
            }
            else
            {
                foreach (var transformation in transformationComponents)
                {
                    if (skipSpecialRoots && transformation.isSpecialRoot)
                    {
                        continue;
                    }

                    UpdateTransformation(transformation);

                    // Recurse
                    if (transformation.Children.Count > 0)
                    {
                        UpdateTransformations(transformation.Children, true);
                    }
                }
            }
        }
        public void Test1()
        {
            var fastCollection = new FastCollection <int>();
            var filter1        = new ComparisonFilter(OperationTargetBuilder.BuildForRoot(fastCollection), ComparisonFilterType.Less, 3);
            var filter2        = new ComparisonFilter(OperationTargetBuilder.BuildForRoot(fastCollection), ComparisonFilterType.Greater, 6);

            var filter3 = new CompoundFilter(
                CompoundFilter.CompoundFilterType.And,
                filter1,
                filter2);

            var executionGroups = FiltersExecutionPipeline.Build(filter3).GetExecutionGroups();

            Assert.AreEqual(0, executionGroups.ElementAt(0).Level);
            CollectionAssert.AreEquivalent(new [] { filter1, filter2 }, executionGroups.ElementAt(0).Filters);
            Assert.AreEqual(1, executionGroups.ElementAt(1).Level);
            CollectionAssert.AreEquivalent(new [] { filter3 }, executionGroups.ElementAt(1).Filters);
        }
Beispiel #15
0
        public void AndCompoundTest()
        {
            var parser         = new FiltersParser();
            var fastCollection = new FastCollection <TestClassA>();
            var parsed         = parser.ParsePredicate((TestClassA x) => (x.F1 > 3) && (x.F1 <= 10), OperationTargetBuilder.BuildForRoot(fastCollection));

            Assert.IsAssignableFrom <CompoundFilter>(parsed);
            Assert.AreEqual(CompoundFilter.CompoundFilterType.And, ((CompoundFilter)parsed).OperationType);

            var filter1 = (ComparisonFilter)((CompoundFilter)parsed).Operands.ElementAt(0);

            Assert.AreEqual(ComparisonFilterType.Greater, filter1.ComparisonFilterType);
            Assert.AreEqual(3, filter1.Value);

            var filter2 = (ComparisonFilter)((CompoundFilter)parsed).Operands.ElementAt(1);

            Assert.AreEqual(ComparisonFilterType.LessOrEqual, filter2.ComparisonFilterType);
            Assert.AreEqual(10, filter2.Value);
        }
 public void DoesntHoldReferencesRemoveAll()
 {
     var wr1 = new WeakReference(new object());
     var wr2 = new WeakReference(new object());
     var c = new FastCollection<object> { wr1.Target, wr2.Target };
     GCEx.CollectAndWait();
     Assert.Equal(2, c.Count);
     Assert.True(wr1.IsAlive);
     Assert.True(wr2.IsAlive);
     c.RemoveAll(x => x == wr1.Target);
     GCEx.CollectAndWait();
     Assert.Equal(1, c.Count);
     Assert.False(wr1.IsAlive);
     Assert.True(wr2.IsAlive);
     c.RemoveAll(x => x == wr2.Target);
     GCEx.CollectAndWait();
     Assert.Equal(0, c.Count);
     Assert.False(wr1.IsAlive);
     Assert.False(wr2.IsAlive);
 }
 public void IndexOfWorks()
 {
     var c = new FastCollection<int> { 1, 2, 3 };
     Assert.Equal(1, c[c.IndexOf(1)]);
     Assert.Equal(2, c[c.IndexOf(2)]);
     Assert.Equal(3, c[c.IndexOf(3)]);
     Assert.Equal(-1, c.IndexOf(4));
     c.Remove(1);
     Assert.Equal(2, c[c.IndexOf(2)]);
     Assert.Equal(3, c[c.IndexOf(3)]);
     Assert.Equal(-1, c.IndexOf(1));
     c.Clear();
     Assert.Equal(-1, c.IndexOf(1));
     Assert.Equal(-1, c.IndexOf(2));
     Assert.Equal(-1, c.IndexOf(3));
     c.Add(3);
     Assert.Equal(-1, c.IndexOf(1));
     Assert.Equal(-1, c.IndexOf(2));
     Assert.Equal(0, c.IndexOf(3));
     Assert.Equal(3, c[0]);
 }
 public void ContainsWorks()
 {
     var c = new FastCollection<int> { 1, 2, 3 };
     Assert.True(c.Contains(1));
     Assert.True(c.Contains(2));
     Assert.True(c.Contains(3));
     Assert.False(c.Contains(4));
     c.Remove(1);
     Assert.False(c.Contains(1));
     Assert.True(c.Contains(2));
     Assert.True(c.Contains(3));
     Assert.False(c.Contains(4));
     c.Clear();
     Assert.False(c.Contains(1));
     Assert.False(c.Contains(2));
     Assert.False(c.Contains(3));
     c.Add(3);
     Assert.False(c.Contains(1));
     Assert.False(c.Contains(2));
     Assert.True(c.Contains(3));
 }
        private bool RecurseCheckChildren(FastCollection <TransformComponent> children, TransformComponent targetTransform)
        {
            foreach (var transformComponentChild in children)
            {
                if (transformComponentChild.Parent == null)
                {
                    continue;                                         // skip this case, the parent has not updated it's list yet
                }
                if (!RecurseCheckChildren(transformComponentChild.Children, targetTransform))
                {
                    return(false);
                }

                if (targetTransform.Entity.Id != transformComponentChild.Entity.Id)
                {
                    continue;
                }

                return(false);
            }
            return(true);
        }
 public void DoesntHoldReferences()
 {
     var wr1 = new WeakReference(new object());
     var wr2 = new WeakReference(new object());
     var c = new FastCollection<object> { wr1.Target, wr2.Target };
     GC.Collect();
     //GC.WaitForFullGCComplete();
     Assert.Equal(2, c.Count);
     Assert.True(wr1.IsAlive);
     Assert.True(wr2.IsAlive);
     c.Remove(wr1.Target);
     GC.Collect();
     //GC.WaitForFullGCComplete();
     Assert.Equal(1, c.Count);
     Assert.False(wr1.IsAlive);
     Assert.True(wr2.IsAlive);
     c.Clear();
     GC.Collect();
     //GC.WaitForFullGCComplete();
     Assert.Equal(0, c.Count);
     Assert.False(wr1.IsAlive);
     Assert.False(wr2.IsAlive);
 }
Beispiel #21
0
 public static void ForEach <T>([NotNull] FastCollection <T> collection, [Pooled] Action <T> action)
 {
     For(0, collection.Count, i => action(collection[i]));
 }
Beispiel #22
0
 public TransformationComponentData()
 {
     UseTRS   = true;
     Scaling  = Vector3.One;
     Children = new FastCollection <EntityComponentReference <TransformationComponent> >();
 }
 public ArrayTupleStorage(int capacity)
 {
     _storage = new FastCollection <T>(capacity);
 }
 internal FastCollectionBuilderFlow([NotNull] FastCollection <TRaw> fastCollection)
 {
     _fastCollection = fastCollection;
 }
Beispiel #25
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="AppSettings"/> class with a settings collection.
 /// </summary>
 /// <param name="settings">The settings collection.</param>
 public AppSettings(IEnumerable <object> settings)
 {
     Settings = new FastCollection <object>(settings);
 }
 private static void AssertEquals<T>(FastCollection<T> collection, IEnumerable<T> enumerable)
 {
     var array = enumerable as T[] ?? enumerable.ToArray();
     Assert.Equal(array.Length, collection.Count);
     Assert.True(collection.All(e => array.Contains(e)));
 }