示例#1
0
        public override void Run()
        {
            MarkProfile("Reading story");

            var bytes = File.ReadAllBytes(StoryFilePath);

            CompiledZMachine machine    = null;
            Action           doneAction = () => { throw new ZMachineInterruptedException(); };

            var mockScreen = new MockScreen(ScriptFilePath, doneAction);

            machine = new CompiledZMachine(Story.FromBytes(bytes), profiler: profile ? this : null);
            machine.RegisterScreen(mockScreen);
            machine.SetRandomSeed(42);

            MarkProfile("Running...");

            watch = Stopwatch.StartNew();

            try
            {
                machine.Run();
            }
            catch (ZMachineQuitException)
            {
                // done
            }
            catch (ZMachineInterruptedException)
            {
                // done
            }
            catch (Exception ex)
            {
                MarkProfile(string.Format("{0}: {1}", ex.GetType().FullName, ex.Message));
            }

            watch.Stop();

            MarkProfile("Done");

            if (profile)
            {
                Console.WriteLine();
                Console.WriteLine("{0:#,#} instructions", instructionCount);
                Console.WriteLine("{0:#,#} calls", callCount);
            }
            Console.WriteLine();
            Console.WriteLine("{0:#,0.##########} seconds", (double)watch.ElapsedTicks / (double)Stopwatch.Frequency);
            if (profile)
            {
                Console.WriteLine("{0:#,0.##########} seconds per instruction", ((double)watch.ElapsedTicks / (double)Stopwatch.Frequency) / (double)instructionCount);
            }
        }
示例#2
0
        private void Run()
        {
            profilerService.Start();
            try
            {
                zmachine.Run();
            }
            catch (ZMachineQuitException)
            {
                // done
                updateTimer.Stop();
                UpdateProfilerStatistics();
            }
            catch (ZMachineInterruptedException)
            {
                // done
                updateTimer.Stop();
                UpdateProfilerStatistics();
            }
            catch (ThreadAbortException)
            {
                // done
                updateTimer.Stop();
            }
            catch (Exception ex)
            {
                updateTimer.Stop();
                screen.Print("\n");
                screen.Print(ex.GetType().FullName);
                screen.Print("\n");
                screen.Print(ex.Message);
                screen.Print("\n");
                screen.Print(ex.StackTrace);
                UpdateProfilerStatistics();
            }

            updateTimer.Stop();
            profilerService.Stop();
        }
示例#3
0
        private string RunGame(string storyName, string scriptName = null)
        {
            var story = Story.FromStream(Resources.LoadStream(storyName));

            story.RegisterInterpreter(new MockInterpreter());

            var scriptCommands = scriptName != null
                ? Resources.LoadLines(scriptName)
                : null;

            var mockScreen = new MockScreen(
                scriptCommands,
                doneAction: () =>
            {
                throw new ZMachineInterruptedException();
            });

            var machine = new CompiledZMachine(story);

            machine.RegisterScreen(mockScreen);
            machine.SetRandomSeed(42);

            try
            {
                machine.Run();
            }
            catch (ZMachineQuitException)
            {
                // done
            }
            catch (ZMachineInterruptedException)
            {
                // done
            }

            return(mockScreen.Output);
        }