Exemplo n.º 1
0
        public static void TestRepeatForever()
        {
            CommandQueue queue            = new CommandQueue();
            const int    MAX_REPEAT_COUNT = 100;
            int          repeatCount      = 0;

            queue.Enqueue(
                Cmd.RepeatForever(
                    Cmd.Do(() => {
                if (repeatCount < MAX_REPEAT_COUNT)
                {
                    repeatCount++;
                }
                else
                {
                    // Well there is one way to stop execution
                    throw new Exception();
                }
            })
                    )
                );

            bool threwException = false;

            try {
                while (!queue.Update(DELTA_TIME_RATE))
                {
                }
            } catch (Exception) {
                threwException = true;
            }

            Assert.IsTrue(threwException);
            Assert.AreEqual(repeatCount, MAX_REPEAT_COUNT);
        }
Exemplo n.º 2
0
        public static void TestRequire()
        {
            CommandQueue queue = new CommandQueue();

            bool shouldStop = false;
            bool didFinish  = false;
            int  callCount  = 0;

            queue.Enqueue(
                Cmd.RepeatForever(
                    Cmd.Require(() => !shouldStop,
                                () => Cmd.RepeatForever(
                                    Cmd.Sequence(
                                        Cmd.Do(() => callCount++),
                                        Cmd.WaitForFrames(1)
                                        )
                                    )
                                ),
                    Cmd.Do(() => didFinish = true),
                    Cmd.WaitForFrames(1)
                    )
                );

            Assert.AreEqual(callCount, 0);
            queue.Update(1.0f);
            Assert.AreEqual(callCount, 1);
            queue.Update(1.0f);
            Assert.AreEqual(callCount, 2);
            queue.Update(1.0f);
            Assert.AreEqual(callCount, 3);

            // Require should only re-evaluate on next update.
            shouldStop = true;
            Assert.AreEqual(didFinish, false);
            queue.Update(1.0f);
            Assert.AreEqual(callCount, 3);
            Assert.AreEqual(didFinish, true);

            queue.Update(1.0f);
            Assert.AreEqual(callCount, 3);
            Assert.AreEqual(didFinish, true);
            shouldStop = false;

            queue.Update(1.0f);
            Assert.AreEqual(callCount, 4);
            Assert.AreEqual(didFinish, true);
        }