private String GetPath(EmulationContext context, IDirectoryManager directoryManager) { var path = directoryManager.GetPath(context, ReplayPathKey); if (String.IsNullOrEmpty(path)) { path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Wren\\Replays"); directoryManager.AddPath(context, ReplayPathKey, path); System.IO.Directory.CreateDirectory(path); } return path; }
public IInputSource BuildInputSource(EmulationContext context) { IInputSource inputSource = new CompositeInputSource(); ; foreach (var source in _inputSourceFactories) { var newSource = source.Invoke(context); if (newSource != null) { ((CompositeInputSource)inputSource).AddInputSource(source.Invoke(context)); } } foreach (var configuration in _inputSourceConfigurations) { inputSource = configuration.Invoke(context, inputSource); } return inputSource; }
public void Save() { UpdateBindingsFromStrings(); var keyboardSettings = new KeyboardBindingSettings() { Bindings = _newKeyboardBindings.ToArray() }; var gamepadSettings = new GamepadBindingSettings() { Gamepad1Bindings = _newGamepad1BindingSettings.ToArray(), Gamepad2Bindings = _newGamepad2BindingSettings.ToArray() }; var context = new EmulationContext(new Game(String.Empty, String.Empty), new EmulatedSystem("SMS")); _settingsManager.ApplySettings(keyboardSettings, context, SettingsScope.EmulatedSystem); }
public void Start(EmulationContext context, IEventAggregator eventAggregator, EmulationMode mode) { _emulator = _emulatorRegistry.GetEmulator(context.EmulatedSystem, _handle); IRomSource loader = null; if (context.Game.RomPath.ToLower().EndsWith(".zip")) { loader = new ZipRomSource(context.Game.RomPath); } else { loader = new FileRomSource(context.Game.RomPath); } using (var romData = loader.GetRomData()) { if (!_emulator.IsRomValid(romData)) return; romData.Seek(0, System.IO.SeekOrigin.Begin); _emulator.LoadRom(romData, null); } eventAggregator.Publish(new EmulatorStartingEvent(InstanceId, this, context.Game, mode)); while (_bus.HasMessages) { _bus.GetCommand().Execute(_emulator); } _emulator.Initialize(eventAggregator); int pixelWidth, pixelHeight; Wren.Core.PixelFormats requestedPixelFormat; Int32 framePerSecond; // assemble rendering pipeline _emulator.GetSpecifications(out pixelWidth, out pixelHeight, out framePerSecond, out requestedPixelFormat); var rSource = _renderingSourceFactory.Create(pixelWidth, pixelHeight, requestedPixelFormat); eventAggregator.Publish(new RenderingSurfaceCreatedEvent(this.InstanceId, rSource.MemorySection, rSource.RenderingSurface, rSource.SurfaceInformation)); _emulator.SetRenderingSurface(rSource.RenderingSurface); var input = _inputPipeline.BuildInputSource(context); eventAggregator.Publish(new EmulatorStartedEvent(this.InstanceId)); FrameRateTimer fp = _frameRateTimerFactory.GetFrameRateTimer(framePerSecond); fp.ScheduleAction(() => { while (_bus.HasMessages) { _bus.GetCommand().Execute(_emulator); } _emulator.SetInput(input.GetCurrentInputState()); Boolean isRunning; try { isRunning = _emulator.Run(); } catch { isRunning = false; } eventAggregator.Publish(new FrameRenderedEvent(this.InstanceId)); if (!isRunning) { eventAggregator.Publish(new EmulatorQuitEvent(this.InstanceId)); input.Close(); } return isRunning; }); if (!fp.IsRunning) { fp.Start(); } }
private void RunEmulator() { GameInfo gi = gamesList.SelectedItem as GameInfo; if (_runner != null) _runner.SendCommand(new QuitCommand()); _runner = _serviceLocator.GetInstance<IEmulationRunner>(); var eContext = new EmulationContext(gi.Game, new EmulatedSystem((String)gi.GetValue("System"))); var eventAggregator = _serviceLocator.GetInstance<IEventAggregator>(); if (_isInGameMode) { /*var statisticsManager = _serviceLocator.GetInstance<IStatisticsManager>(); statisticsManager.UpdateStatisticDefinitions(eContext.Game); statisticsManager.InitializeStatistics(eContext.Game, new GameEventAggregator(eventAggregator, _runner));*/ } _runner.Start(eContext, eventAggregator, _isInGameMode ? EmulationMode.Playing : EmulationMode.Preview); _fullScreenEmulationRunner = _runner.InstanceId; }