示例#1
0
        [Test] public void Basics()
        {
            RawList <int> intList = new RawList <int>();

            intList.Add(10);
            intList.AddRange(new int[] { 17, 42, 94 });

            Assert.AreEqual(4, intList.Count);
            Assert.IsTrue(intList.Contains(42));
            Assert.AreEqual(2, intList.IndexOf(42));
            CollectionAssert.AreEqual(new int[] { 10, 17, 42, 94 }, intList);
            CollectionAssert.AreEqual(new int[] { 10, 17, 42, 94 }, intList.Data.Take(4));

            intList.ShrinkToFit();
            Assert.AreEqual(intList.Count, intList.Capacity);

            intList.Remove(42);
            Assert.AreEqual(3, intList.Count);
            Assert.IsTrue(!intList.Contains(42));
            Assert.AreEqual(-1, intList.IndexOf(42));
            CollectionAssert.AreEqual(new int[] { 10, 17, 94 }, intList);
            CollectionAssert.AreEqual(new int[] { 10, 17, 94 }, intList.Data.Take(3));

            intList.Insert(1, 100);
            CollectionAssert.AreEqual(new int[] { 10, 100, 17, 94 }, intList);
            CollectionAssert.AreEqual(new int[] { 10, 100, 17, 94 }, intList.Data.Take(4));

            intList.InsertRange(2, new int[] { 150, 200, 250, 300 });
            CollectionAssert.AreEqual(new int[] { 10, 100, 150, 200, 250, 300, 17, 94 }, intList);
            CollectionAssert.AreEqual(new int[] { 10, 100, 150, 200, 250, 300, 17, 94 }, intList.Data.Take(8));

            intList.Clear();
            Assert.AreEqual(0, intList.Count);
            Assert.IsTrue(!intList.Contains(94));
        }
示例#2
0
		[Test] public void Basics()
		{
			RawList<int> intList = new RawList<int>();
			intList.Add(10);
			intList.AddRange(new int[] { 17, 42, 94 });

			Assert.AreEqual(4, intList.Count);
			Assert.IsTrue(intList.Contains(42));
			Assert.AreEqual(2, intList.IndexOf(42));
			CollectionAssert.AreEqual(new int[] { 10, 17, 42, 94 }, intList);
			CollectionAssert.AreEqual(new int[] { 10, 17, 42, 94 }, intList.Data.Take(4));

			intList.ShrinkToFit();
			Assert.AreEqual(intList.Count, intList.Capacity);

			intList.Remove(42);
			Assert.AreEqual(3, intList.Count);
			Assert.IsTrue(!intList.Contains(42));
			Assert.AreEqual(-1, intList.IndexOf(42));
			CollectionAssert.AreEqual(new int[] { 10, 17, 94 }, intList);
			CollectionAssert.AreEqual(new int[] { 10, 17, 94 }, intList.Data.Take(3));

			intList.Insert(1, 100);
			CollectionAssert.AreEqual(new int[] { 10, 100, 17, 94 }, intList);
			CollectionAssert.AreEqual(new int[] { 10, 100, 17, 94 }, intList.Data.Take(4));

			intList.InsertRange(2, new int[] { 150, 200, 250, 300 });
			CollectionAssert.AreEqual(new int[] { 10, 100, 150, 200, 250, 300, 17, 94 }, intList);
			CollectionAssert.AreEqual(new int[] { 10, 100, 150, 200, 250, 300, 17, 94 }, intList.Data.Take(8));

			intList.Clear();
			Assert.AreEqual(0, intList.Count);
			Assert.IsTrue(!intList.Contains(94));
		}
        ///<summary>
        /// Removes an entity from the manager.
        ///</summary>
        ///<param name="e">Entity to remove.</param>
        ///<exception cref="InvalidOperationException">Thrown if the entity does not belong to this manager.</exception>
        public void Remove(Entity e)
        {
            lock (InterpolatedStates.FlipLocker)
            {
                lock (ReadBuffers.FlipLocker)
                {
                    if (e.BufferedStates.BufferedStatesManager == this)
                    {
                        int index = entities.IndexOf(e);

                        int endIndex = entities.Count - 1;
                        entities[index] = entities[endIndex];
                        entities.RemoveAt(endIndex);
                        if (index < entities.Count)
                        {
                            entities[index].BufferedStates.motionStateIndex = index;
                        }
                        if (ReadBuffers.Enabled)
                        {
                            ReadBuffers.Remove(index, endIndex);
                        }
                        if (InterpolatedStates.Enabled)
                        {
                            InterpolatedStates.Remove(index, endIndex);
                        }

                        e.BufferedStates.BufferedStatesManager = null;
                    }
                    else
                    {
                        throw new InvalidOperationException("Entity does not belong to this BufferedStatesManager; cannot remove.");
                    }
                }
            }
        }