diff --git a/src/scripted_input/scripted_buttons.cpp b/src/scripted_input/scripted_buttons.cpp index 742bba3a4..4c7dfef2a 100644 --- a/src/scripted_input/scripted_buttons.cpp +++ b/src/scripted_input/scripted_buttons.cpp @@ -33,6 +33,8 @@ int IndexOfButton(const std::string& button) { return -1; //home } +int frame = 0; + namespace ScriptedInput { class ScriptedButton final : public Input::ButtonDevice { @@ -61,8 +63,24 @@ std::unique_ptr ScriptedButtons::Create(const Common::Param int index = IndexOfButton(button_str); if (index >= 0) { scripted_button_list.get()->buttons[index] = button.get(); + is_in_use = true; } return std::move(button); } + +bool ScriptedButtons::IsInUse() { + return is_in_use; +} + +void ScriptedButtons::NotifyFrameFinished() { + frame++; + if (frame >= 10) { + printf("TOGGLING\r\n"); + frame = 0; + + auto button = scripted_button_list.get()->buttons[0]; + button->status.store(!button->GetStatus()); + } +} } \ No newline at end of file diff --git a/src/scripted_input/scripted_buttons.h b/src/scripted_input/scripted_buttons.h index aae734198..e3cdc02ed 100644 --- a/src/scripted_input/scripted_buttons.h +++ b/src/scripted_input/scripted_buttons.h @@ -25,8 +25,15 @@ public: */ std::unique_ptr Create(const Common::ParamPackage& params) override; + /** + * True if any button is being controlled + */ + bool IsInUse(); + + void NotifyFrameFinished(); private: std::shared_ptr scripted_button_list; + bool is_in_use {false}; }; } // namespace InputCommon diff --git a/src/scripted_input/scripted_input.cpp b/src/scripted_input/scripted_input.cpp index b51fc1a5a..23417f974 100644 --- a/src/scripted_input/scripted_input.cpp +++ b/src/scripted_input/scripted_input.cpp @@ -21,8 +21,12 @@ void Shutdown() { Input::UnregisterFactory("scripted"); } -ScriptedButtons* GetScriptedButtons() { - return scripted_buttons.get(); +bool IsInUse() { + return scripted_buttons.get()->IsInUse(); +} + +void NotifyFrameFinished() { + scripted_buttons.get()->NotifyFrameFinished(); } } // namespace ScriptedInput diff --git a/src/scripted_input/scripted_input.h b/src/scripted_input/scripted_input.h index 43c8c0ff8..f6a5417e5 100644 --- a/src/scripted_input/scripted_input.h +++ b/src/scripted_input/scripted_input.h @@ -16,6 +16,8 @@ void Shutdown(); class ScriptedButtons; -ScriptedButtons* GetScriptedButtons(); +bool IsInUse(); + +void NotifyFrameFinished(); } // namespace InputCommon diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index cffa4c952..155b0309b 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt @@ -81,7 +81,7 @@ endif() create_directory_groups(${SRCS} ${HEADERS}) add_library(video_core STATIC ${SRCS} ${HEADERS}) -target_link_libraries(video_core PUBLIC common core) +target_link_libraries(video_core PUBLIC common core scripted_input) target_link_libraries(video_core PRIVATE glad nihstro-headers) if (ARCHITECTURE_x86_64) diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index 65c18aecc..8a915515f 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -19,6 +19,7 @@ #include "core/memory.h" #include "core/settings.h" #include "core/tracer/recorder.h" +#include "scripted_input/scripted_input.h" #include "video_core/debug_utils/debug_utils.h" #include "video_core/rasterizer_interface.h" #include "video_core/renderer_opengl/renderer_opengl.h" @@ -151,6 +152,10 @@ void RendererOpenGL::SwapBuffers() { prev_state.Apply(); RefreshRasterizerSetting(); + if (ScriptedInput::IsInUse()) { + ScriptedInput::NotifyFrameFinished(); + } + if (Pica::g_debug_context && Pica::g_debug_context->recorder) { Pica::g_debug_context->recorder->FrameFinished(); }