dolphin icon indicating copy to clipboard operation
dolphin copied to clipboard

TAS input window breaks when running scripts and vice versa

Open Felk opened this issue 1 year ago • 0 comments

The way input overrides via scripting are handled right now causes the TAS input window to not register any inputs anymore. Also, if a script is executed before the TAS input window is opened, opening it makes the TAS input window work, but Scripting controller inputs not work anymore.

This is due to a limitation on how the new input override system was implemented, namely that it is not designed for multiple "hijackers" to exist simultaneously. More technically, I use SetInputOverrideFunction, which replaces the TAS input window's override function, and vice versa.

This needs to be fixed eventually. There's a TODO in the code: https://github.com/Felk/dolphin/blob/master/Source/Core/Core/API/Controller.cpp#L31

BaseManip::BaseManip(API::EventHub& event_hub,
          const std::vector<ControllerEmu::EmulatedController*> controllers)
    : m_event_hub(event_hub), m_controllers(controllers)
{
  m_frame_advanced_listener = m_event_hub.ListenEvent<API::Events::FrameAdvance>(
      [&](const API::Events::FrameAdvance&) { NotifyFrameAdvanced(); });
  for (auto i = 0; i < m_controllers.size(); i++)
  {
    // TODO felk: find a more robust way to set the input override functions.
    //   This way scripting breaks once the TAS input window is opened,
    //   and vice versa, the TAS window breaks once scripting starts.
    m_controllers[i]->SetInputOverrideFunction([=](const std::string_view group_name,
                                                   const std::string_view control_name,
                                                   ControlState orig_state) {
      const InputKey input_key = {group_name, control_name};
      std::optional<ControlState> manip = this->PerformInputManip(i, input_key, orig_state);
      m_last_seen_input[{i, input_key}] = manip.value_or(orig_state);
      return manip;
    });
  }
}

I considered this not a priority right now, as I think people are likely not TASing and Scripting at the same time. But yeah, needs to be fixed eventually...

Felk avatar Sep 24 '23 10:09 Felk