コード例 #1
0
        public void StateBeforeFrame()
        {
            var ss = new StateSource {
                PaddingData = new byte[1000]
            };
            var zw = new ZwinderStateManager(new ZwinderStateManagerSettings
            {
                CurrentBufferSize        = 1,
                CurrentTargetFrameLength = 10000,

                RecentBufferSize        = 1,
                RecentTargetFrameLength = 100000,

                AncientStateInterval = 50000
            }, f => false);

            {
                var ms = new MemoryStream();
                ss.SaveStateBinary(new BinaryWriter(ms));
                zw.Engage(ms.ToArray());
            }
            for (int frame = 0; frame <= 10440; frame++)
            {
                ss.Frame = frame;
                zw.Capture(frame, ss);
            }
            var kvp    = zw.GetStateClosestToFrame(10440);
            var actual = StateSource.GetFrameNumberInState(kvp.Value);

            Assert.AreEqual(kvp.Key, actual);
            Assert.IsTrue(actual <= 10440);
        }
コード例 #2
0
        public void StateCache()
        {
            var ss = CreateStateSource();
            var zw = new ZwinderStateManager(new ZwinderStateManagerSettings
            {
                CurrentBufferSize        = 2,
                CurrentTargetFrameLength = 1000,
                RecentBufferSize         = 2,
                RecentTargetFrameLength  = 1000,
                AncientStateInterval     = 100
            }, f => false);

            for (int i = 0; i < 1000; i += 200)
            {
                zw.CaptureReserved(i, ss);
            }

            for (int i = 400; i < 1000; i += 400)
            {
                zw.EvictReserved(i);
            }

            for (int i = 0; i < 10000; i++)
            {
                zw.Capture(i, ss);
            }

            zw.Capture(101, ss);

            var allStates = zw.AllStates()
                            .Select(s => s.Frame)
                            .ToList();

            for (int i = 0; i < 10000; i++)
            {
                var actual   = zw.HasState(i);
                var expected = allStates.Contains(i);
                Assert.AreEqual(expected, actual);
            }
        }