Пример #1
0
        public static void Main(string[] args)
        {
            var player = new Replayer();

            player.UseGraphQl(typeof(Config));
            if (args.Length != 1)
            {
                Console.WriteLine("ZES.Replayer log.json");
            }

            var logFile = args[0];
            var task    = Task.Run(() => player.Replay(logFile));

            var result = task.Result;

            Console.WriteLine($"{result.Result}, replay took {result.Elapsed} ms");

            if (!result.Result)
            {
                Console.WriteLine($"Mismatch in output : {result.Difference}");
            }

            var name = logFile.Split('.')[0];

            using (var sw = new StreamWriter($"{name}_output.json"))
            {
                sw.WriteLine(result.Output);
            }
        }
Пример #2
0
        public void EndToEndTest()
        {
            // Arrange.
            var device       = new Device();
            var logger       = new TracefileBuilder(device);
            var expectedData = RenderScene(device);

            var stringWriter = new StringWriter();

            logger.WriteTo(stringWriter);

            var loggedJson = stringWriter.ToString();
            var logReader  = new StringReader(loggedJson);
            var tracefile  = Tracefile.FromTextReader(logReader);

            // Act.
            var swapChainPresenter = new RawSwapChainPresenter();
            var replayer           = new Replayer(
                tracefile.Frames[0], tracefile.Frames[0].Events.Last(),
                swapChainPresenter);

            replayer.Replay();
            var actualData = swapChainPresenter.Data;

            // Assert.
            Assert.That(actualData, Is.EqualTo(expectedData));
        }
Пример #3
0
        private void OnSelectedEventChanged(object sender, TracefileEventChangedEventArgs e)
        {
            if (_selectionService.SelectedEvent == null)
            {
                return;
            }

            var dispatcher         = Dispatcher.CurrentDispatcher;
            var swapChainPresenter = new WpfSwapChainPresenter(dispatcher);
            var replayer           = new Replayer(
                _frame, _selectionService.SelectedEvent.Model,
                swapChainPresenter);

            Task.Factory.StartNew(() =>
            {
                replayer.Replay();

                DepthStencilView depthStencilView; RenderTargetView[] renderTargetViews;
                replayer.Device.ImmediateContext.OutputMerger.GetTargets(
                    out depthStencilView, out renderTargetViews);

                var activeRenderTargetView = renderTargetViews[0];
                _activeRenderTarget        = (Texture2D)activeRenderTargetView.Resource;

                ActiveRenderTargetViewIdentifier = activeRenderTargetView.ID;
                NotifyOfPropertyChange(() => ActiveRenderTargetArraySlices);
                ActiveRenderTargetArraySlice = 0;
            });
        }
Пример #4
0
        private void OnSelectedPixelChanged(object sender, PixelChangedEventArgs e)
        {
            FrameNumber   = _selectionService.SelectedFrame.Number;
            PixelLocation = e.SelectedPixel;

            HasSelectedPixel = true;
            _pixelEvents.Clear();

            var swapChainPresenter = new WpfSwapChainPresenter(Dispatcher.CurrentDispatcher);
            var replayer           = new Replayer(
                _selectionService.SelectedFrame.Model, _selectionService.SelectedEvent.Model,
                swapChainPresenter,
                _selectionService.SelectedFrame.ActiveRenderTargetViewIdentifier,
                _selectionService.SelectedFrame.ActiveRenderTargetArraySlice,
                e.SelectedPixel.X, e.SelectedPixel.Y);

            Task.Factory.StartNew(() =>
            {
                replayer.Replay();

                var events = replayer.Logger.GetPixelHistoryEvents(_selectionService.SelectedFrame.Number);
                _pixelEvents.AddRange(events.Select(x => new PixelHistoryEventViewModel(x)));

                FinalFrameBufferColor = ((ColorResultViewModel)_pixelEvents.Last(x => x.Result is ColorResultViewModel).Result).Result;
            });
        }
Пример #5
0
        protected async Task <ReplayResult> Replay(string logFile)
        {
            var player = new Replayer();

            lock (_lock)
                player.UseGraphQl(Configs, _logger);

            var result = await player.Replay(logFile);

            return(result);
        }
        private void OnSelectedEventChanged(object sender, TracefileEventChangedEventArgs e)
        {
            NotifyOfPropertyChange(() => SelectedEvent);

            _objects.Clear();

            if (_selectionService.SelectedEvent == null)
            {
                return;
            }

            var swapChainPresenter = new WpfSwapChainPresenter(Dispatcher.CurrentDispatcher);
            var replayer           = new Replayer(
                _selectionService.SelectedFrame.Model, _selectionService.SelectedEvent.Model,
                swapChainPresenter);

            Task.Factory.StartNew(() =>
            {
                replayer.Replay();

                _objects.AddRange(replayer.Device.DeviceChildren
                                  .Select(x => new GraphicsObjectViewModel(x)));
            });
        }
Пример #7
0
        public static void Main(string[] args)
        {
            var hello = Hello.Deserialize(new Reader(new byte[] {
                // Numbers: 1, 2, 1337
                2, 7, 0, 2, 8, 4, 16, 242, 20,
                // Others: -1, -2, 1337
                10, 4, 1, 3, 242, 20,
            }));

            Console.WriteLine("Numbers: {0}", String.Join(", ", hello.Numbers));
            Console.WriteLine("Others: {0}", String.Join(", ", hello.Others));

            Outer.OnUpdateFoo((newValue, oldValue, container) => {
                Console.WriteLine("Outer / Foo: {0} => {1}", oldValue, newValue);
            });

            Outer.OnUpdateBar((newValue, oldValue, container) => {
                Console.WriteLine("Outer / Bar: {0} => {1}", oldValue, newValue);
            });

            Outer.OnUpdateInner((newValue, oldValue, container) => {
                Console.WriteLine("Outer / Inner: {0} => {1}", InnerToString(oldValue), InnerToString(newValue));
            });

            Inner.OnUpdateFoo((newValue, oldValue, container) => {
                Console.WriteLine("Outer / Inner / Foo: {0} => {1}", oldValue, newValue);
            });

            Inner.OnUpdateBar((newValue, oldValue, container) => {
                Console.WriteLine("Outer / Inner / Bar: {0} => {1}", oldValue, newValue);
            });

            var outer = new Outer();

            Replayer.Replay(ref outer, new Reader(new byte[] {
                8, 0, 2, 1, 0, 10, 2, 254, 1,
                7, 0, 2, 1, 1, 10, 1, 1,
                10, 0, 2, 1, 2, 10, 4, 0, 44, 8, 1,
                9, 0, 2, 2, 2, 0, 10, 2, 192, 2,
                4, 0, 2, 1, 2,
                1, 0,
            }));

            Console.WriteLine("{0} {1} {2}", outer.Foo, outer.Bar, InnerToString(outer.Inner));

            Multicase.OnUpdate((newValue, newVariant, oldValue, oldVariant, container) => {
                Console.WriteLine("Multicase: variant {0} ({1}) => variant {2} ({3}", oldVariant, oldValue, newVariant, newValue);
            });

            Multicase.FirstCase.OnUpdateFoo((newValue, oldValue, container) => {
                Console.WriteLine("Multicase / FirstCase / Foo: {0} => {1}", oldValue, newValue);
            });

            Multicase.FirstCase.OnUpdateBar((newValue, oldValue, container) => {
                Console.WriteLine("Multicase / FirstCase / Bar: {0} => {1}", oldValue, newValue);
            });

            Multicase.SecondCase.OnUpdateFoo((newValue, oldValue, container) => {
                Console.WriteLine("Multicase / SecondCase / Foo: {0} => {1}", oldValue, newValue);
            });

            Multicase.SecondCase.OnUpdateBar((newValue, oldValue, container) => {
                Console.WriteLine("Multicase / SecondCase / Bar: {0} => {1}", oldValue, newValue);
            });

            var multicase = new Multicase();

            Replayer.Replay(ref multicase, new Reader(new byte[] {
                4, 0, 10, 1, 1,
                9, 0, 2, 2, 1, 0, 10, 2, 136, 1,
            }));

            var list1 = new StateList <Inner>();

            list1.OnUpdate((newItem, oldItem, tag, container) => {
                Console.WriteLine("List<Inner>, update #{0}: {1} => {2}", tag, InnerToString(oldItem), InnerToString(newItem));
            });

            list1.OnAdd((item, tag, container) => {
                Console.WriteLine("List<Inner>, add #{0}: {1}", tag, InnerToString(item));
            });

            list1.OnRemove((item, tag, container) => {
                Console.WriteLine("List<Inner>, remove #{0}: {1}", tag, InnerToString(item));
            });

            Replayer.Replay(ref list1, new Reader(new byte[] {
                5, 1, 10, 2, 0, 12,
                8, 1, 10, 5, 0, 154, 1, 8, 1,
                1, 1,
                9, 0, 2, 2, 1, 0, 10, 2, 136, 1,
                4, 2, 2, 1, 0,
                4, 2, 2, 1, 1,
            }));

            var list2 = new StateList <SByte>();

            list2.OnUpdate((newItem, oldItem, tag, container) => {
                Console.WriteLine("List<SByte>, update #{0}: {1} => {2}", tag, oldItem, newItem);
            });

            list2.OnAdd((item, tag, container) => {
                Console.WriteLine("List<SByte>, add #{0}: {1}", tag, item);
            });

            list2.OnRemove((item, tag, container) => {
                Console.WriteLine("List<SByte>, remove #{0}: {1}", tag, item);
            });

            Replayer.Replay(ref list2, new Reader(new byte[] {
                4, 1, 10, 1, 20,
                4, 1, 10, 1, 22,
                4, 1, 10, 1, 0,
                4, 2, 2, 1, 1,
            }));

            var map1 = new StateDictionary <Inner>();

            map1.OnUpdate((newItem, oldItem, tag, container) => {
                Console.WriteLine("Dictionary<Inner>, update #{0}: {1} => {2}", tag, InnerToString(oldItem), InnerToString(newItem));
            });

            map1.OnRemove((item, tag, container) => {
                Console.WriteLine("Dictionary<Inner>, remove #{0}: {1}", tag, InnerToString(item));
            });

            Replayer.Replay(ref map1, new Reader(new byte[] {
                8, 0, 2, 1, 5, 10, 2, 0, 12,
                11, 0, 2, 1, 1, 10, 5, 0, 154, 1, 8, 1,
                4, 0, 2, 1, 0,
                9, 0, 2, 2, 1, 0, 10, 2, 136, 1,
                4, 2, 2, 1, 0,
            }));

            var map2 = new StateDictionary <SByte>();

            map2.OnUpdate((newItem, oldItem, tag, container) => {
                Console.WriteLine("Dictionary<SByte>, update #{0}: {1} => {2}", tag, oldItem, newItem);
            });

            map2.OnRemove((item, tag, container) => {
                Console.WriteLine("Dictionary<SByte>, remove #{0}: {1}", tag, item);
            });

            Replayer.Replay(ref map2, new Reader(new byte[] {
                7, 0, 2, 1, 1, 10, 1, 20,
                7, 0, 2, 1, 3, 10, 1, 22,
                7, 0, 2, 1, 7, 10, 1, 0,
                4, 2, 2, 1, 1,
            }));

            Action.OnUpdate((newValue, newVariant, oldValue, oldVariant, container) => {
                Console.WriteLine("Action: variant {0} ({1}) => variant {2} ({3}", oldVariant, oldValue, newVariant, newValue);
            });

            Action.Attack.OnUpdateAttacker((newValue, oldValue, container) => {
                Console.WriteLine("Action / Attack / Attacker: {0} => {1}", oldValue, newValue);
            });

            Action.Attack.OnUpdateDefender((newValue, oldValue, container) => {
                Console.WriteLine("Action / Attack / Defender: {0} => {1}", oldValue, newValue);
            });

            Action.Attack.OnUpdateHits((newValue, oldValue, container) => {
                Console.WriteLine("Action / Attack / Hits:");

                if (oldValue.Count > 0)
                {
                    Console.WriteLine("Old Hits:");
                    foreach (var hit in oldValue)
                    {
                        Console.WriteLine(HitToString(hit));
                    }
                }
                else
                {
                    Console.WriteLine("Old Hits:\n<empty>");
                }

                if (newValue.Count > 0)
                {
                    Console.WriteLine("New Hits:");
                    foreach (var hit in newValue)
                    {
                        Console.WriteLine(HitToString(hit));
                    }
                }
                else
                {
                    Console.WriteLine("New Hits:\n<empty>");
                }
            });

            var action = new Action();

            Replayer.Replay(ref action, new Reader(new byte[] {
                // Set variant from to `Action::Attack`
                4, 0, 10, 1, 1,
                // Set attacker to 1
                8, 0, 2, 2, 1, 0, 10, 1, 1,
                // Set defender to 2
                8, 0, 2, 2, 1, 1, 10, 1, 2,
                // Add 4 hits with dummy values from 6 to 9, inclusive
                83, 0, 2, 2, 1, 2, 10, 76,
                2, 17, 2, 1, 0, 10, 1, 0, 18, 1, 0, 26, 1, 0, 34, 1, 0, 40, 12,
                10, 17, 2, 1, 0, 10, 1, 0, 18, 1, 0, 26, 1, 0, 34, 1, 0, 40, 14,
                18, 17, 2, 1, 0, 10, 1, 0, 18, 1, 0, 26, 1, 0, 34, 1, 0, 40, 16,
                26, 17, 2, 1, 0, 10, 1, 0, 18, 1, 0, 26, 1, 0, 34, 1, 0, 40, 18,
            }));
        }