示例#1
0
        static void RemoveInsertTestSub(bool trackFree)
        {
            var d = new DArray <object>(trackFree);

            for (var i = 0; i < 10; i++)
            {
                d[i] = new object();
            }

            d.RemoveAt(0);
            d.RemoveAt(5);
            d.RemoveAt(6);
            d.RemoveAt(9);

            var usedIndices = new List <int>();

            for (var i = 0; i < 7; i++)
            {
                usedIndices.Add(d.Insert(new object()));
            }

            var expected = new int[] { 0, 5, 6, 9, 10, 11, 12 };

            Assert.AreEqual(usedIndices.Count(), expected.Length);

            foreach (var i in usedIndices)
            {
                Assert.IsTrue(expected.Contains(i), "TrackFree = " + trackFree);
            }
        }
示例#2
0
        static void CountTestSub(bool trackFree)
        {
            var expectedCount = 0;

            var d = new DArray <object>(trackFree);

            for (var i = 0; i < 1000; i++)
            {
                if ((i % 3) == 0)
                {
                    d[i] = new object();
                    expectedCount++;
                    Assert.AreEqual(expectedCount, d.Count, "TrackFree = " + trackFree);
                }
            }

            for (var i = 0; i < d.Length; i++)
            {
                if ((i % 2) == 0 && d[i] != null)
                {
                    Assert.IsNotNull(d[i]);
                    d.RemoveAt(i);
                    expectedCount--;
                    Assert.IsNull(d[i]);
                    Assert.AreEqual(expectedCount, d.Count, "TrackFree = " + trackFree);
                }
            }

            for (var i = 0; i < 50; i++)
            {
                d.Add(new object());
                expectedCount++;
                Assert.AreEqual(expectedCount, d.Count, "TrackFree = " + trackFree);
            }
        }
示例#3
0
        /// <summary>
        /// Removes all the walls for a <see cref="GrhData"/>.
        /// </summary>
        /// <param name="grhData">The <see cref="GrhData"/> to remove the walls for.</param>
        public void RemoveWalls(GrhData grhData)
        {
            var index = (int)grhData.GrhIndex;

            if (!_walls.CanGet(index))
            {
                return;
            }

            _walls.RemoveAt(index);
        }
示例#4
0
        static void EnumerateVersionTestSub(bool trackFree)
        {
            var d = new DArray <object>(50, trackFree)
            {
                new object(), new object()
            };

            try
            {
                foreach (var obj in d)
                {
                    d[10] = new object();
                }
                Assert.Fail("Failed to generate InvalidOperationException.");
            }
            catch (InvalidOperationException)
            {
            }

            try
            {
                foreach (var obj in d)
                {
                    d.RemoveAt(0);
                }
                Assert.Fail("Failed to generate InvalidOperationException.");
            }
            catch (InvalidOperationException)
            {
            }

            try
            {
                foreach (var obj in d)
                {
                    d[0] = new object();
                }
                Assert.Fail("Failed to generate InvalidOperationException.");
            }
            catch (InvalidOperationException)
            {
            }
        }
示例#5
0
文件: GrhInfo.cs 项目: wtfcolt/game
        /// <summary>
        /// Deletes a <see cref="GrhData"/>.
        /// </summary>
        /// <param name="grhData"><see cref="GrhData"/> to delete.</param>
        /// <exception cref="ArgumentNullException"><paramref name="grhData" /> is <c>null</c>.</exception>
        public static void Delete(GrhData grhData)
        {
            if (grhData == null)
            {
                throw new ArgumentNullException("grhData");
            }

            var grhIndex = grhData.GrhIndex;

            if (grhIndex.IsInvalid)
            {
                return;
            }

            // Insure the index is valid
            if (!_grhDatas.CanGet((int)grhIndex))
            {
                const string errmsg = "Attempted to delete GrhData `{0}`, but GrhIndex `{1}` could not be acquired.";
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, grhData, grhIndex);
                }
                Debug.Fail(string.Format(errmsg, grhData, grhIndex));
                return;
            }

            // Make sure we are deleting the correct GrhData
            var i = (int)grhIndex;

            if (_grhDatas[i] != grhData)
            {
                const string errmsg =
                    "Attempted to delete GrhData `{0}`, but GrhIndex `{1}` is already in use by" +
                    " a different GrhData `{2}`. Most likely, the GrhData we tried to delete is already deleted, and" +
                    " the GrhIndex has been recycled to a new GrhData. Stop trying to delete dead stuff, will ya!?";
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, grhData, grhIndex, _grhDatas[i]);
                }
                Debug.Fail(string.Format(errmsg, grhData, grhIndex, _grhDatas[i]));
                return;
            }

            // Remove the GrhData from the collection
            _grhDatas.RemoveAt((int)grhIndex);

            // If a stationary GrhData and auto-size is set, delete the texture, too
            try
            {
                var sgd = grhData as StationaryGrhData;
                if (sgd != null && sgd.AutomaticSize)
                {
                    // Make sure no other GrhData is using the texture
                    var origTexture = sgd.GetOriginalTexture();
                    if (GrhDatas.OfType <StationaryGrhData>().All(x => origTexture != x.GetOriginalTexture()))
                    {
                        // Dispose of the texture then recycle the file
                        origTexture.Dispose();
                        try
                        {
                            sgd.TextureName.RecycleFile();
                        }
                        catch
                        {
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                const string errmsg = "Failed to recycle texture file for GrhData `{0}`. Exception: {1}";
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, grhData, ex);
                }
                Debug.Fail(string.Format(errmsg, grhData, ex));
            }
        }
示例#6
0
 /// <summary>
 /// Removes the item at the given <paramref name="id"/>.
 /// </summary>
 /// <param name="id">The ID of the item to remove.</param>
 public void RemoveAt(ActionDisplayID id)
 {
     _items.RemoveAt((int)id);
 }
示例#7
0
        static void CountTestSub(bool trackFree)
        {
            var expectedCount = 0;

            var d = new DArray<object>(trackFree);

            for (var i = 0; i < 1000; i++)
            {
                if ((i % 3) == 0)
                {
                    d[i] = new object();
                    expectedCount++;
                    Assert.AreEqual(expectedCount, d.Count, "TrackFree = " + trackFree);
                }
            }

            for (var i = 0; i < d.Length; i++)
            {
                if ((i % 2) == 0 && d[i] != null)
                {
                    Assert.IsNotNull(d[i]);
                    d.RemoveAt(i);
                    expectedCount--;
                    Assert.IsNull(d[i]);
                    Assert.AreEqual(expectedCount, d.Count, "TrackFree = " + trackFree);
                }
            }

            for (var i = 0; i < 50; i++)
            {
                d.Add(new object());
                expectedCount++;
                Assert.AreEqual(expectedCount, d.Count, "TrackFree = " + trackFree);
            }
        }
示例#8
0
        static void RemoveInsertTestSub(bool trackFree)
        {
            var d = new DArray<object>(trackFree);

            for (var i = 0; i < 10; i++)
            {
                d[i] = new object();
            }

            d.RemoveAt(0);
            d.RemoveAt(5);
            d.RemoveAt(6);
            d.RemoveAt(9);

            var usedIndices = new List<int>();
            for (var i = 0; i < 7; i++)
            {
                usedIndices.Add(d.Insert(new object()));
            }

            var expected = new int[] { 0, 5, 6, 9, 10, 11, 12 };

            Assert.AreEqual(usedIndices.Count(), expected.Length);

            foreach (var i in usedIndices)
            {
                Assert.IsTrue(expected.Contains(i), "TrackFree = " + trackFree);
            }
        }
示例#9
0
        static void EnumerateVersionTestSub(bool trackFree)
        {
            var d = new DArray<object>(50, trackFree) { new object(), new object() };

            try
            {
                foreach (var obj in d)
                {
                    d[10] = new object();
                }
                Assert.Fail("Failed to generate InvalidOperationException.");
            }
            catch (InvalidOperationException)
            {
            }

            try
            {
                foreach (var obj in d)
                {
                    d.RemoveAt(0);
                }
                Assert.Fail("Failed to generate InvalidOperationException.");
            }
            catch (InvalidOperationException)
            {
            }

            try
            {
                foreach (var obj in d)
                {
                    d[0] = new object();
                }
                Assert.Fail("Failed to generate InvalidOperationException.");
            }
            catch (InvalidOperationException)
            {
            }
        }