예제 #1
0
        /// <summary>
        /// Updates all the <see cref="TransformComponent.WorldMatrix"/>.
        /// </summary>
        /// <param name="context">The render context.</param>
        public override void Draw(RenderContext context)
        {
            notSpecialRootComponents.Clear();

            lock (TransformationRoots)
            {
                foreach (var t in TransformationRoots)
                {
                    if (t.UpdateImmobilePosition || t.Immobile != IMMOBILITY.EverythingImmobile)
                    {
                        notSpecialRootComponents.Add(t);
                    }
                }
            }

            // Update scene transforms
            // TODO: Entity processors should not be aware of scenes
            var sceneInstance = EntityManager as SceneInstance;

            if (sceneInstance?.RootScene != null)
            {
                UpdateTransfromationsRecursive(sceneInstance.RootScene);
            }

            // Special roots are already filtered out
            UpdateTransformations(notSpecialRootComponents);
        }
예제 #2
0
 public void AddRemoveWorks()
 {
     var c = new FastCollection<int> { 1, 2, 3, 4, 5 };
     Assert.True(c.SequenceEqual(new[] { 1, 2, 3, 4, 5 }));
     Assert.Equal(5, c.Count);
     var originalCapacity = c.Capacity;
     Assert.InRange(originalCapacity, 5, int.MaxValue);
     Assert.True(c.Remove(5));
     AssertEquals(c, new[] { 1, 2, 3, 4 });
     Assert.InRange(c.Capacity, 4, originalCapacity);
     c.RemoveAt(3);
     AssertEquals(c, new[] { 1, 2, 3 });
     Assert.InRange(c.Capacity, 3, originalCapacity);
     Assert.True(c.Remove(1));
     AssertEquals(c, new[] { 2, 3 });
     Assert.InRange(c.Capacity, 2, originalCapacity);
     Assert.False(c.Remove(1));
     var oneEl = c[1];
     c.RemoveAt(0);
     Assert.Equal(oneEl, c[0]);
     Assert.Equal(1, c.Count);
     c.Add(4);
     AssertEquals(c, new[] { oneEl, 4 });
     c.Clear();
     Assert.True(c.SequenceEqual(new int[0]));
     Assert.Equal(0, c.Count);
 }
예제 #3
0
        /// <summary>
        /// Updates all the <see cref="TransformComponent.WorldMatrix"/>.
        /// </summary>
        /// <param name="context"></param>
        public override void Draw(RenderContext context)
        {
            notSpecialRootComponents.Clear();
            foreach (var t in TransformationRoots)
            {
                notSpecialRootComponents.Add(t);
            }

            // Special roots are already filtered out
            UpdateTransformations(notSpecialRootComponents);
        }
예제 #4
0
 private void Cleanup()
 {
     //_parent = null;
     _written.Clear();
     // TODO: do we need to clear the array
     //if (_takenCount != 0)
     //{
     //    Array.Clear(_taken, 0, _takenCount);
     //    _takenCount = 0;
     //}
     _taken.Clear();
     _cache.Push(this);
 }
예제 #5
0
        /// <summary>
        /// Updates all the <see cref="TransformationComponent.WorldMatrix"/>.
        /// </summary>
        /// <param name="time"></param>
        public override void Draw(GameTime time)
        {
            notSpecialRootComponents.Clear();
            foreach (var t in transformationRoots)
            {
                if (!t.isSpecialRoot)
                {
                    notSpecialRootComponents.Add(t);
                }
            }

            // Special roots are already filtered out
            UpdateTransformations(notSpecialRootComponents, false);
        }
예제 #6
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);
            }
        }
예제 #7
0
 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));
 }
예제 #8
0
 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));
 }
예제 #9
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));
 }
예제 #10
0
 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]);
 }
예제 #11
0
 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);
 }
예제 #12
0
        private void UpdateAndArrangeVisibleChildren()
        {
            var axis = (int)Orientation;

            // cache the initial list of children
            cachedVisibleChildren.Clear();
            foreach (var child in visibleChildren)
            {
                cachedVisibleChildren.Add(child);
            }

            // reset the list
            visibleChildren.Clear();

            // remove all the current visual children
            while (VisualChildrenCollection.Count > 0)
            {
                SetVisualParent(VisualChildrenCollection[0], null);
            }

            // determine first element index and size
            var elementIndex   = (int)Math.Floor(scrollPosition);
            var firstChildSize = GetSafeChildSize(elementIndex, axis);

            // create the next visual children collection to display
            var currentSize = -(scrollPosition - elementIndex) * firstChildSize;

            while (elementIndex < Children.Count && currentSize <= Viewport[axis])
            {
                currentSize += GetSafeChildSize(elementIndex, axis);

                visibleChildren.Add(Children[elementIndex]);
                SetVisualParent(Children[elementIndex], this);
                ++elementIndex;
            }

            // reorder visual children by z-Order
            VisualChildrenCollection.Sort(PanelChildrenSorter);

            // re-arrange the children if they changed
            if (visibleChildren.Count > 0)
            {
                var shouldRearrangeChildren = cachedVisibleChildren.Count == 0 || cachedVisibleChildren.Count != visibleChildren.Count;

                // determine if the two list are equals
                if (!shouldRearrangeChildren)
                {
                    for (int i = 0; i < visibleChildren.Count; i++)
                    {
                        if (cachedVisibleChildren[i] != visibleChildren[i])
                        {
                            shouldRearrangeChildren = true;
                            break;
                        }
                    }
                }
                if (shouldRearrangeChildren)
                {
                    ArrangeChildren();
                }
            }
        }
예제 #13
0
        protected override Vector3 ArrangeOverride(Vector3 finalSizeWithoutMargins)
        {
            visibleChildren.Clear(); // children's children may have changed we need to force the rearrangement.

            Viewport = finalSizeWithoutMargins;

            // determine the stack panel axis
            var stackAxis = (int)Orientation;

            // re-arrange all children and update item position cache data when virtualization is off
            if (!ItemVirtualizationEnabled)
            {
                ArrangeChildren();

                // determine the index of the last element that we can scroll to
                indexElementMaxScrolling = elementBounds.Count - 2;
                while (indexElementMaxScrolling > 0 && elementBounds[indexElementMaxScrolling] > elementBounds[elementBounds.Count - 1] - Viewport[stackAxis])
                {
                    --indexElementMaxScrolling;
                }
            }

            // update the extent (extent need to be valid before updating scrolling)
            extent = finalSizeWithoutMargins;
            if (ItemVirtualizationEnabled)
            {
                extent[stackAxis] = EstimateExtentLength();
            }
            else
            {
                extent[stackAxis] = elementBounds[elementBounds.Count - 1];
            }

            // Update the scrolling
            if (scrollingRequets.Count > 0) // perform scroll requests
            {
                foreach (var request in scrollingRequets)
                {
                    switch (request.Type)
                    {
                    case ScrollRequestType.AbsolutePosition:
                        ScrolllToElement(request.ScrollValue);
                        break;

                    case ScrollRequestType.RelativeElement:
                        ScrolllToNeigbourElement(Orientation, request.ScrollValue);
                        break;

                    case ScrollRequestType.RelativePosition:
                        ScrollOf(request.ScrollValue);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }
            else // update children and scrolling info (mainly offsets)
            {
                AdjustOffsetsAndVisualChildren(scrollPosition);
            }
            scrollingRequets.Clear();

            // invalidate anchor info
            if (ScrollOwner != null)
            {
                ScrollOwner.InvalidateAnchorInfo();
            }

            return(finalSizeWithoutMargins);
        }
예제 #14
0
 public void Clear()
 {
     _storage.Clear();
 }