Exemple #1
0
        public void Tick()
        {
            Assert.That(_isAsync);

            if (!_asyncQueue.IsEmpty())
            {
                // Cache the callback list to allow handlers to be added from within callbacks
                using (var block = DisposeBlock.Spawn())
                {
                    var subscriptions = block.SpawnList <SignalSubscription>();
                    subscriptions.AddRange(_subscriptions);

                    // Cache the signals so that if the signal is fired again inside the handler that it
                    // is not executed until next frame
                    var signals = block.SpawnList <object>();
                    signals.AddRange(_asyncQueue);

                    _asyncQueue.Clear();

                    for (int i = 0; i < signals.Count; i++)
                    {
                        FireInternal(subscriptions, signals[i]);
                    }
                }
            }
        }
Exemple #2
0
        public void Fire(object signal)
        {
            Assert.That(signal.GetType().DerivesFromOrEqual(_bindingId.Type));

            if (_isAsync)
            {
                _asyncQueue.Add(signal);
            }
            else
            {
                // Cache the callback list to allow handlers to be added from within callbacks
                using (var block = DisposeBlock.Spawn())
                {
                    var subscriptions = block.SpawnList <SignalSubscription>();
                    subscriptions.AddRange(_subscriptions);
                    FireInternal(subscriptions, signal);
                }
            }
        }
Exemple #3
0
        public void TestExceptions()
        {
            var qux1 = new Qux();
            var qux2 = new Qux();

            try
            {
                using (var block = DisposeBlock.Spawn())
                {
                    block.Add(qux1);
                    block.Add(qux2);
                    throw new Exception();
                }
            }
            catch
            {
            }

            Assert.That(qux1.WasDisposed);
            Assert.That(qux2.WasDisposed);
        }
Exemple #4
0
        public void TestWithStaticMemoryPool()
        {
            var pool = Foo.Pool;

            pool.Clear();

            Assert.IsEqual(pool.NumTotal, 0);
            Assert.IsEqual(pool.NumActive, 0);
            Assert.IsEqual(pool.NumInactive, 0);

            using (var block = DisposeBlock.Spawn())
            {
                block.Spawn(pool, "asdf");

                Assert.IsEqual(pool.NumTotal, 1);
                Assert.IsEqual(pool.NumActive, 1);
                Assert.IsEqual(pool.NumInactive, 0);
            }

            Assert.IsEqual(pool.NumTotal, 1);
            Assert.IsEqual(pool.NumActive, 0);
            Assert.IsEqual(pool.NumInactive, 1);
        }
Exemple #5
0
        public void TestWithNormalMemoryPool()
        {
            Container.BindMemoryPool <Bar, Bar.Pool>();

            var pool = Container.Resolve <Bar.Pool>();

            Assert.IsEqual(pool.NumTotal, 0);
            Assert.IsEqual(pool.NumActive, 0);
            Assert.IsEqual(pool.NumInactive, 0);

            using (var block = DisposeBlock.Spawn())
            {
                block.Spawn(pool);

                Assert.IsEqual(pool.NumTotal, 1);
                Assert.IsEqual(pool.NumActive, 1);
                Assert.IsEqual(pool.NumInactive, 0);
            }

            Assert.IsEqual(pool.NumTotal, 1);
            Assert.IsEqual(pool.NumActive, 0);
            Assert.IsEqual(pool.NumInactive, 1);
        }
        public void TestPoolWrapper()
        {
            var pool = Foo.Pool;

            pool.Clear();
            pool.ClearActiveCount();

            Assert.IsEqual(pool.NumActive, 0);
            Assert.IsEqual(pool.NumInactive, 0);
            Assert.IsEqual(pool.NumTotal, 0);

            using (var block = DisposeBlock.Spawn())
            {
                block.Spawn(pool, "asdf");

                Assert.IsEqual(pool.NumActive, 1);
                Assert.IsEqual(pool.NumInactive, 0);
                Assert.IsEqual(pool.NumTotal, 1);
            }

            Assert.IsEqual(pool.NumActive, 0);
            Assert.IsEqual(pool.NumInactive, 1);
            Assert.IsEqual(pool.NumTotal, 1);
        }
    /// <summary>
    /// Takes in an array of points and returns
    /// the characteristic points of the point set.
    /// </summary>
    /// <param name="_p">The point list</param>
    /// <param name="_featureP">The returned characteristic points</param>
    public static void IdentifyFeaturePoints(ref Vector3 [] _p, out Vector3 [] _featureP)
    {
        // check for null
        if (_p == null || _p.Length < 1)
        {
            Debug.LogWarning("The Points were null or empty, therefore no FeaturePoints were detected.");
            _featureP = new Vector3 [0];
            return;
        }

        using (var block = DisposeBlock.Spawn())
        {
            var result = block.Spawn(ListPool <Vector3> .Instance);

            Vector3 lastCharPoint = _p [0];
            result.Add(lastCharPoint);

            /* Step 1: Find the characteristic points */

            for (int i = 1; i < _p.Length - 1; ++i)
            {
                // Pass the minimal distance test?
                float distance = Vector3.Distance(_p [i], lastCharPoint);
                if (distance < Configuration.DistanceThreshold)
                {
                    continue;
                }

                // Pass the angle test?
                Vector3 segment1 = _p [i] - lastCharPoint;
                Vector3 segment2 = _p [i + 1] - _p [i];
                float   angle    = Vector3.Angle(segment1.normalized, segment2.normalized);
                if (angle < Configuration.AngleThreshold)
                {
                    continue;
                }

                lastCharPoint = _p [i];
                result.Add(lastCharPoint);
            }

            // fix the last point
            Vector3 lastPoint = _p [_p.Length - 1];

            // is it already the last point? you're good! Else...
            if (lastCharPoint != lastPoint)
            {
                // is the last added point too close? remove the lastCharPoint and replace by last point
                float dist = Vector3.Distance(lastCharPoint, lastPoint);
                if (dist < Configuration.DistanceThreshold)
                {
                    result [result.Count - 1] = lastPoint;
                }
                else
                {
                    result.Add(lastPoint);
                }
            }

            // Last Step: Assign the result
            _featureP = result.ToArray();
        }
    }