From e3c40ea2ef32912cb5f05a00481aa0686d4a8d86 Mon Sep 17 00:00:00 2001 From: adelikat Date: Mon, 7 Sep 2015 10:29:40 -0400 Subject: [PATCH] Basic Bot - make the UpdateValues call much much faster --- BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs b/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs index 633a1fbb79..f4a114be87 100644 --- a/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs +++ b/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs @@ -54,6 +54,9 @@ namespace BizHawk.Client.EmuHawk private bool _bigEndian; private int _dataSize; + private Dictionary _cachedControlProbabilities; + private ILogEntryGenerator _logGenerator; + #region Services and Settings [RequiredService] @@ -867,16 +870,14 @@ namespace BizHawk.Client.EmuHawk foreach (var button in Emulator.ControllerDefinition.BoolButtons) { - double probability = ControlProbabilities[button]; + double probability = _cachedControlProbabilities[button]; bool pressed = !(rand.Next(100) < probability); buttonLog.Add(button, pressed); Global.ClickyVirtualPadController.SetBool(button, pressed); } - var lg = Global.MovieSession.LogGeneratorInstance(); - lg.SetSource(Global.ClickyVirtualPadController); - _currentBotAttempt.Log.Add(lg.GenerateLogEntry()); + _currentBotAttempt.Log.Add(_logGenerator.GenerateLogEntry()); } private void StartBot() @@ -915,7 +916,10 @@ namespace BizHawk.Client.EmuHawk UpdateBotStatusIcon(); MessageLabel.Text = "Running..."; - } + _cachedControlProbabilities = ControlProbabilities; + _logGenerator = Global.MovieSession.LogGeneratorInstance(); + _logGenerator.SetSource(Global.ClickyVirtualPadController); + } private bool CanStart() {