Пример #1
0
        /// <summary>
        /// This function adjust the current first element index, the current offsets and the current visual children collection to have a valid stack display.
        /// </summary>
        private void AdjustOffsetsAndVisualChildren(float desiredNewScrollPosition)
        {
            offset = Vector3.Zero;
            var axis = (int)Orientation;

            if (ItemVirtualizationEnabled)
            {
                UpdateScrollPosition(desiredNewScrollPosition);
                UpdateAndArrangeVisibleChildren();
            }
            else // no item virtualization
            {
                if (elementBounds.Count < 2) // no children
                {
                    scrollPosition = 0;
                    offset         = Vector3.Zero;
                }
                else
                {
                    var viewportSize    = Viewport[axis];
                    var inferiorBound   = elementBounds[indexElementMaxScrolling];
                    var superiorBound   = elementBounds[indexElementMaxScrolling + 1];
                    var boundDifference = superiorBound - inferiorBound;

                    // calculate the maximum scroll position
                    float maxScrollPosition = indexElementMaxScrolling;
                    if (boundDifference > MathUtil.ZeroTolerance)
                    {
                        maxScrollPosition += Math.Min(1 - MathUtil.ZeroTolerance, (extent[axis] - viewportSize - inferiorBound) / boundDifference);
                    }

                    // set a valid scroll position
                    scrollPosition = Math.Max(0, Math.Min(maxScrollPosition, desiredNewScrollPosition));

                    // add the first element start bound as initial scroll offset
                    var firstElementIndex = (int)Math.Floor(scrollPosition);
                    offset[axis] = -elementBounds[firstElementIndex];

                    // update the visible element list for hit tests
                    visibleChildren.Clear();
                    for (var i = firstElementIndex; i < Children.Count; i++)
                    {
                        visibleChildren.Add(Children[i]);
                        if (elementBounds[i + 1] - elementBounds[firstElementIndex + 1] > viewportSize)
                        {
                            break;
                        }
                    }
                }
            }

            // adjust the offset of the children
            var scrollPositionIndex     = (int)Math.Floor(scrollPosition);
            var scrollPositionRemainder = scrollPosition - scrollPositionIndex;

            offset[axis] -= scrollPositionRemainder * GetSafeChildSize(scrollPositionIndex, axis);

            // force the scroll owner to update the scroll info
            ScrollOwner?.InvalidateScrollInfo();
        }
Пример #2
0
 public void CopyToWorks()
 {
     var arr = Enumerable.Range(0, 10).ToArray();
     var c = new FastCollection<int>();
     c.CopyTo(arr, 0);
     Assert.True(arr.SequenceEqual(Enumerable.Range(0, 10)));
     c.Add(5);
     c.CopyTo(arr, 0);
     Assert.Equal(5, arr[0]);
     Assert.True(arr.Skip(1).SequenceEqual(Enumerable.Range(1, 9)));
     c.CopyTo(arr, 1);
     Assert.Equal(5, arr[0]);
     Assert.Equal(5, arr[1]);
     Assert.True(arr.Skip(2).SequenceEqual(Enumerable.Range(2, 8)));
     c.Add(6);
     c.CopyTo(arr, 0);
     Assert.Equal(5, arr[0]);
     Assert.Equal(6, arr[1]);
     Assert.True(arr.Skip(2).SequenceEqual(Enumerable.Range(2, 8)));
     c.CopyTo(arr, 1);
     Assert.Equal(5, arr[0]);
     Assert.Equal(5, arr[1]);
     Assert.Equal(6, arr[2]);
     Assert.True(arr.Skip(3).SequenceEqual(Enumerable.Range(3, 7)));
 }
Пример #3
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);
        }
Пример #4
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);
 }
Пример #5
0
 public void SetterWorks()
 {
     var c = new FastCollection<int> { 1 };
     Assert.Equal(1, c[0]);
     Assert.True(c.Contains(1));
     Assert.False(c.Contains(2));
     c[0] = 2;
     Assert.Equal(2, c[0]);
     Assert.False(c.Contains(1));
     Assert.True(c.Contains(2));
     c.Add(3);
     Assert.False(c.Contains(1));
     Assert.True(c.Contains(2));
     Assert.True(c.Contains(3));
     Assert.False(c.Contains(4));
     c[c.IndexOf(3)] = 4;
     Assert.False(c.Contains(1));
     Assert.True(c.Contains(2));
     Assert.False(c.Contains(3));
     Assert.True(c.Contains(4));
     c[c.IndexOf(4)] = 2;
     Assert.False(c.Contains(1));
     Assert.True(c.Contains(2));
     Assert.False(c.Contains(3));
     Assert.False(c.Contains(4));
     Assert.Equal(2, c.Count);
 }
Пример #6
0
 public void AddTaken(LocalTable <T> borrower, T tuple)
 {
     /*if (_takenCount == _taken.Length)
      * {
      *  Array.Resize(ref _taken, _takenCount * 2);
      * }
      * _taken[_takenCount++] = new TakenTuple<T>(borrower, tuple);*/
     _taken.Add(new TakenTuple <T>(borrower, tuple));
 }
Пример #7
0
 /// <summary>
 /// Append <paramref name="gameEvent"/> to the log.
 /// </summary>
 /// <param name="gameEvent">New event</param>
 public void Log(GameEvent gameEvent)
 {
     lock (eventLog)
     {
         gameEvent.TimeStamp = Game.UpdateTime.Total;
         eventLog.Add(gameEvent);
         this.LogDebug("Logged new event: {eventType}.", gameEvent.GetType().Name);
     }
 }
Пример #8
0
        public void Add()
        {
            IList b = new List <int>();

            var fc = new FastCollection <IList>();

            fc.Add(b, 2);

            Assert.AreEqual(1, b.Count);
        }
Пример #9
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);
        }
Пример #10
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);
        }
Пример #11
0
        public void Generic_Remove()
        {
            IList <int> b = new List <int>();

            var fc = new FastCollection <IList <int>, int>();

            fc.Add(b, 2);

            Assert.AreEqual(1, b.Count);

            fc.Remove(b, 2);

            Assert.AreEqual(0, b.Count);
        }
Пример #12
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);
            }
        }
Пример #13
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));
 }
Пример #14
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]);
 }
Пример #15
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();
                }
            }
        }
Пример #16
0
 public void Add(T tuple)
 {
     _storage.Add(tuple);
 }