예제 #1
0
        public void OnUpdateTest()
        {
            var target = new TweenOps();
            TweenSharkCallback onUpdate = tweenShark => { };
            var expected = target;
            var actual   = target.OnUpdate(onUpdate);

            // test chaining
            Assert.AreEqual(expected, actual);
            // test if onUpdate is set
            Assert.AreEqual(onUpdate, target.OnUpdateCallback);
        }
예제 #2
0
        public void OnStartTest()
        {
            var target = new TweenOps();
            TweenSharkCallback onStart = tweenShark => { };
            var expected = target;
            var actual   = target.OnStart(onStart);

            // test chaining
            Assert.AreEqual(expected, actual);
            // test if OnStart is set
            Assert.AreEqual(onStart, target.OnStartCallback);
        }
예제 #3
0
        public RunningTweenShark(TweenShark tweenShark)
        {
            _tweenShark = tweenShark;
            _tweenOps   = tweenShark.TweenOps;

            StartTicks    = DateTime.Now.Ticks;
            DurationTicks = (uint)(1000 * 10000 * tweenShark.Duration);
            _deltaTicks   = 0;

            _onStart    = _tweenOps.OnStartCallback;
            _onUpdate   = _tweenOps.OnUpdateCallback;
            _onComplete = _tweenOps.OnCompleteCallback;
        }
예제 #4
0
 public TweenOps OnStart(TweenSharkCallback onStart)
 {
     OnStartCallback = onStart;
     return(this);
 }
예제 #5
0
 public TweenOps OnComplete(TweenSharkCallback onComplete)
 {
     OnCompleteCallback = onComplete;
     return(this);
 }
예제 #6
0
 public TweenOps OnUpdate(TweenSharkCallback onUpdate)
 {
     OnUpdateCallback = onUpdate;
     return(this);
 }
예제 #7
0
        /// <summary>
        /// We are testing three tweens, that endure 1, 3 and 5 seconds. Ever Tween has onStart, onComplete, onUpdate callbacks set.
        /// To ensure that ticks is working the way it should we count how oftern the callbacks are called for each Tweens.
        /// In the end we check if the the values where tweened correctly.
        /// </summary>
        private void TestSimpleTickScenario()
        {
            var obj = new TweeningTestObject();
            var registeredPropertyTweens = new Dictionary <string, Type>();

            // register tweener for ints
            registeredPropertyTweens.Add(typeof(SByte).FullName, typeof(SignedByteTweener));
            registeredPropertyTweens.Add(typeof(Int16).FullName, typeof(SignedInt16Tweener));
            registeredPropertyTweens.Add(typeof(Int32).FullName, typeof(SignedInt32Tweener));
            registeredPropertyTweens.Add(typeof(Int64).FullName, typeof(SignedInt64Tweener));
            // register tweener for unsigned ints
            registeredPropertyTweens.Add(typeof(Byte).FullName, typeof(UnsignedByteTweener));
            registeredPropertyTweens.Add(typeof(UInt16).FullName, typeof(UnsignedInt16Tweener));
            registeredPropertyTweens.Add(typeof(UInt32).FullName, typeof(UnsignedInt32Tweener));
            registeredPropertyTweens.Add(typeof(UInt64).FullName, typeof(UnsignedInt64Tweener));
            // register tweener for floats
            registeredPropertyTweens.Add(typeof(Single).FullName, typeof(FloatTweener));
            // register tweener for doubles
            registeredPropertyTweens.Add(typeof(Double).FullName, typeof(DoubleTweener));

            var target = new TweenedObject(obj, registeredPropertyTweens); // TODO: Passenden Wert initialisieren

            var onStartTweens          = new Dictionary <TweenShark, int>();
            TweenSharkCallback onStart = tween => onStartTweens[tween]++;

            var onUpdateTweens          = new Dictionary <TweenShark, int>();
            TweenSharkCallback onUpdate = tween => onUpdateTweens[tween]++;

            var onCompleteTweens          = new Dictionary <TweenShark, int>();
            TweenSharkCallback onComplete = tween => onCompleteTweens[tween]++;

            // first tween takes ONE second
            var tween1 = new TweenShark(obj, 1, new TweenOps()
                                        .PropTo("DoubleValue", 100).PropTo("FloatValue", 200)
                                        .OnStart(onStart).OnUpdate(onUpdate).OnComplete(onComplete));

            onStartTweens[tween1]    = 0;
            onUpdateTweens[tween1]   = 0;
            onCompleteTweens[tween1] = 0;
            target.AddTweenShark(tween1);

            // second tween takes THREE seconds
            var tween2 = new TweenShark(obj, 3, new TweenOps()
                                        .PropTo("IntValue", 300).PropTo("UintValue", 400)
                                        .OnStart(onStart).OnUpdate(onUpdate).OnComplete(onComplete));

            onStartTweens[tween2]    = 0;
            onUpdateTweens[tween2]   = 0;
            onCompleteTweens[tween2] = 0;
            target.AddTweenShark(tween2);

            // third tween takes FIVE seconds
            var tween3 = new TweenShark(obj, 5, new TweenOps()
                                        .PropTo("LongValue", 500).PropTo("UlongValue", 600)
                                        .OnStart(onStart).OnUpdate(onUpdate).OnComplete(onComplete));

            onStartTweens[tween3]    = 0;
            onUpdateTweens[tween3]   = 0;
            onCompleteTweens[tween3] = 0;
            target.AddTweenShark(tween3);

            //////////////////////////////////////////////////////////////////////////////////////////
            // do one tick now
            long currentTicks = DateTime.Now.Ticks;
            bool actual       = target.Tick(currentTicks);

            Assert.AreEqual(true, actual);

            // oStart must be called 3 times now, each one time
            Assert.AreEqual(3, onStartTweens.Values.Sum());
            Assert.AreEqual(1, onStartTweens[tween1]);
            Assert.AreEqual(1, onStartTweens[tween2]);
            Assert.AreEqual(1, onStartTweens[tween3]);
            // onUpdate must also be called that often
            Assert.AreEqual(3, onUpdateTweens.Values.Sum());
            Assert.AreEqual(1, onUpdateTweens[tween1]);
            Assert.AreEqual(1, onUpdateTweens[tween2]);
            Assert.AreEqual(1, onUpdateTweens[tween3]);
            // onComplete must not have been called yet
            Assert.AreEqual(0, onCompleteTweens.Values.Sum());
            Assert.AreEqual(0, onCompleteTweens[tween1]);
            Assert.AreEqual(0, onCompleteTweens[tween2]);
            Assert.AreEqual(0, onCompleteTweens[tween3]);

            //////////////////////////////////////////////////////////////////////////////////////////
            System.Threading.Thread.Sleep(200);
            //////////////////////////////////////////////////////////////////////////////////////////

            //////////////////////////////////////////////////////////////////////////////////////////
            // do one tick now
            currentTicks = DateTime.Now.Ticks;
            actual       = target.Tick(currentTicks);
            Assert.AreEqual(true, actual);

            // oStart must not be changed
            Assert.AreEqual(3, onStartTweens.Values.Sum());
            Assert.AreEqual(1, onStartTweens[tween1]);
            Assert.AreEqual(1, onStartTweens[tween2]);
            Assert.AreEqual(1, onStartTweens[tween3]);
            // onUpdate must be called again for every tween
            Assert.AreEqual(3 + 3, onUpdateTweens.Values.Sum());
            Assert.AreEqual(1 + 1, onUpdateTweens[tween1]);
            Assert.AreEqual(1 + 1, onUpdateTweens[tween2]);
            Assert.AreEqual(1 + 1, onUpdateTweens[tween3]);
            // onComplete must not have been called yet
            Assert.AreEqual(0, onCompleteTweens.Values.Sum());
            Assert.AreEqual(0, onCompleteTweens[tween1]);
            Assert.AreEqual(0, onCompleteTweens[tween2]);
            Assert.AreEqual(0, onCompleteTweens[tween3]);

            //////////////////////////////////////////////////////////////////////////////////////////
            System.Threading.Thread.Sleep(1000);
            //////////////////////////////////////////////////////////////////////////////////////////

            //////////////////////////////////////////////////////////////////////////////////////////
            // do one tick now
            currentTicks = DateTime.Now.Ticks;
            actual       = target.Tick(currentTicks);
            Assert.AreEqual(true, actual);

            // oStart must not be changed
            Assert.AreEqual(3, onStartTweens.Values.Sum());
            Assert.AreEqual(1, onStartTweens[tween1]);
            Assert.AreEqual(1, onStartTweens[tween2]);
            Assert.AreEqual(1, onStartTweens[tween3]);
            // onUpdate must be called again for every tween
            Assert.AreEqual(3 + 3 + 3, onUpdateTweens.Values.Sum());
            Assert.AreEqual(1 + 1 + 1, onUpdateTweens[tween1]);
            Assert.AreEqual(1 + 1 + 1, onUpdateTweens[tween2]);
            Assert.AreEqual(1 + 1 + 1, onUpdateTweens[tween3]);
            // onComplete be called for the first and second tween
            Assert.AreEqual(1, onCompleteTweens.Values.Sum());
            Assert.AreEqual(1, onCompleteTweens[tween1]);
            Assert.AreEqual(0, onCompleteTweens[tween2]);
            Assert.AreEqual(0, onCompleteTweens[tween3]);

            //////////////////////////////////////////////////////////////////////////////////////////
            System.Threading.Thread.Sleep(2000);
            //////////////////////////////////////////////////////////////////////////////////////////

            //////////////////////////////////////////////////////////////////////////////////////////
            // do one tick now
            currentTicks = DateTime.Now.Ticks;
            actual       = target.Tick(currentTicks);
            Assert.AreEqual(true, actual);

            // oStart must not be changed
            Assert.AreEqual(3, onStartTweens.Values.Sum());
            Assert.AreEqual(1, onStartTweens[tween1]);
            Assert.AreEqual(1, onStartTweens[tween2]);
            Assert.AreEqual(1, onStartTweens[tween3]);
            // onUpdate must be called again for every tween, but the first one
            Assert.AreEqual(3 + 3 + 3 + 2, onUpdateTweens.Values.Sum());
            Assert.AreEqual(1 + 1 + 1, onUpdateTweens[tween1]);
            Assert.AreEqual(1 + 1 + 1 + 1, onUpdateTweens[tween2]);
            Assert.AreEqual(1 + 1 + 1 + 1, onUpdateTweens[tween3]);
            // onComplete be called for all tweens
            Assert.AreEqual(2, onCompleteTweens.Values.Sum());
            Assert.AreEqual(1, onCompleteTweens[tween1]);
            Assert.AreEqual(1, onCompleteTweens[tween2]);
            Assert.AreEqual(0, onCompleteTweens[tween3]);

            //////////////////////////////////////////////////////////////////////////////////////////
            System.Threading.Thread.Sleep(2000);
            //////////////////////////////////////////////////////////////////////////////////////////

            //////////////////////////////////////////////////////////////////////////////////////////
            // do one tick now
            currentTicks = DateTime.Now.Ticks;
            actual       = target.Tick(currentTicks);
            // there is no pending tween left, so we expect false as return value of Tick()
            Assert.AreEqual(false, actual);

            // oStart must not be changed
            Assert.AreEqual(3, onStartTweens.Values.Sum());
            Assert.AreEqual(1, onStartTweens[tween1]);
            Assert.AreEqual(1, onStartTweens[tween2]);
            Assert.AreEqual(1, onStartTweens[tween3]);
            // onUpdate must be called again for every tween, but the first and second one
            Assert.AreEqual(3 + 3 + 3 + 2 + 1, onUpdateTweens.Values.Sum());
            Assert.AreEqual(1 + 1 + 1, onUpdateTweens[tween1]);
            Assert.AreEqual(1 + 1 + 1 + 1, onUpdateTweens[tween2]);
            Assert.AreEqual(1 + 1 + 1 + 1 + 1, onUpdateTweens[tween3]);
            // onComplete be called for all tweens
            Assert.AreEqual(3, onCompleteTweens.Values.Sum());
            Assert.AreEqual(1, onCompleteTweens[tween1]);
            Assert.AreEqual(1, onCompleteTweens[tween2]);
            Assert.AreEqual(1, onCompleteTweens[tween3]);

            //////////////////////////////////////////////////////////////////////////////////////////
            // test the results
            Assert.AreEqual(obj.DoubleValue, 100);
            Assert.AreEqual(obj.FloatValue, 200);
            Assert.AreEqual(obj.IntValue, 300);
            Assert.AreEqual(obj.UintValue, 400U);
            Assert.AreEqual(obj.LongValue, 500L);
            Assert.AreEqual(obj.UlongValue, 600UL);

            //////////////////////////////////////////////////////////////////////////////////////////
            System.Threading.Thread.Sleep(1000);
            //////////////////////////////////////////////////////////////////////////////////////////

            //////////////////////////////////////////////////////////////////////////////////////////
            // the last tick... nothing can change, since there is no tween left
            currentTicks = DateTime.Now.Ticks;
            actual       = target.Tick(currentTicks);
            // there is no pending tween left, so we expect false as return value of Tick()
            Assert.AreEqual(false, actual);

            // oStart must not be changed
            Assert.AreEqual(3, onStartTweens.Values.Sum());
            Assert.AreEqual(1, onStartTweens[tween1]);
            Assert.AreEqual(1, onStartTweens[tween2]);
            Assert.AreEqual(1, onStartTweens[tween3]);
            // onUpdate must not be changed
            Assert.AreEqual(3 + 3 + 3 + 2 + 1, onUpdateTweens.Values.Sum());
            Assert.AreEqual(1 + 1 + 1, onUpdateTweens[tween1]);
            Assert.AreEqual(1 + 1 + 1 + 1, onUpdateTweens[tween2]);
            Assert.AreEqual(1 + 1 + 1 + 1 + 1, onUpdateTweens[tween3]);
            // onUpdate must not be changed
            Assert.AreEqual(3, onCompleteTweens.Values.Sum());
            Assert.AreEqual(1, onCompleteTweens[tween1]);
            Assert.AreEqual(1, onCompleteTweens[tween2]);
            Assert.AreEqual(1, onCompleteTweens[tween3]);
        }