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); } }
void StoryService_StoryOpened(object sender, StoryOpenedEventArgs e) { //profilerService.Create(); PropertyChanged("Profiling"); e.Story.RegisterInterpreter(new Interpreter()); zmachine = new CompiledZMachine(e.Story, profiler: profilerService.Profiler); zmachine.SetRandomSeed(42); zmachine.RegisterScreen(screen); zmachine.RegisterSoundEngine(this); zmachineThread = new Thread(new ThreadStart(Run)); zmachineThread.Start(); PropertyChanged("Title"); }
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); }