Add a setting for ScriptedInput 'close_at_end', closes the emulator when the script finishes running.
This commit is contained in:
		| @@ -154,6 +154,7 @@ void Config::ReadValues() { | |||||||
|  |  | ||||||
|     // Scripted Input |     // Scripted Input | ||||||
|     Settings::values.script_name = sdl2_config->Get("ScriptedInput", "script_name", ""); |     Settings::values.script_name = sdl2_config->Get("ScriptedInput", "script_name", ""); | ||||||
|  |     Settings::values.close_at_end = sdl2_config->GetBoolean("ScriptedInput", "close_at_end", false); | ||||||
|  |  | ||||||
|     // Web Service |     // Web Service | ||||||
|     Settings::values.telemetry_endpoint_url = sdl2_config->Get( |     Settings::values.telemetry_endpoint_url = sdl2_config->Get( | ||||||
|   | |||||||
| @@ -172,6 +172,9 @@ gdbstub_port=24689 | |||||||
| [ScriptedInput] | [ScriptedInput] | ||||||
| # Script file to load for simulated input | # Script file to load for simulated input | ||||||
| script_name= | script_name= | ||||||
|  | # Whether to close the emulator when the script has finished | ||||||
|  | # 0 (default): Don't Close, 1: Close | ||||||
|  | close_at_end= | ||||||
|  |  | ||||||
| [WebService] | [WebService] | ||||||
| # Endpoint URL for submitting telemetry data | # Endpoint URL for submitting telemetry data | ||||||
|   | |||||||
| @@ -36,7 +36,7 @@ void Apply() { | |||||||
|     Service::HID::ReloadInputDevices(); |     Service::HID::ReloadInputDevices(); | ||||||
|     Service::IR::ReloadInputDevices(); |     Service::IR::ReloadInputDevices(); | ||||||
|  |  | ||||||
|     ScriptedInput::LoadScript(values.script_name); |     ScriptedInput::LoadScript(values.script_name, values.close_at_end); | ||||||
| } | } | ||||||
|  |  | ||||||
| } // namespace | } // namespace | ||||||
|   | |||||||
| @@ -129,6 +129,7 @@ struct Values { | |||||||
|  |  | ||||||
|     // ScriptedInput |     // ScriptedInput | ||||||
|     std::string script_name; |     std::string script_name; | ||||||
|  |     bool close_at_end; | ||||||
|  |  | ||||||
|     // WebService |     // WebService | ||||||
|     std::string telemetry_endpoint_url; |     std::string telemetry_endpoint_url; | ||||||
|   | |||||||
| @@ -14,4 +14,4 @@ create_directory_groups(${SRCS} ${HEADERS}) | |||||||
|  |  | ||||||
| add_library(scripted_input STATIC ${SRCS} ${HEADERS}) | add_library(scripted_input STATIC ${SRCS} ${HEADERS}) | ||||||
| target_link_libraries(scripted_input PUBLIC common core) | target_link_libraries(scripted_input PUBLIC common core) | ||||||
| target_link_libraries(scripted_input PRIVATE glad) | target_link_libraries(scripted_input PRIVATE glad SDL2) | ||||||
| @@ -2,6 +2,7 @@ | |||||||
| // Licensed under GPLv2 or any later version | // Licensed under GPLv2 or any later version | ||||||
| // Refer to the license.txt file included. | // Refer to the license.txt file included. | ||||||
|  |  | ||||||
|  | #include <SDL.h> | ||||||
| #include <glad/glad.h> | #include <glad/glad.h> | ||||||
| #include <string.h> | #include <string.h> | ||||||
| #include "common/logging/log.h" | #include "common/logging/log.h" | ||||||
| @@ -16,7 +17,9 @@ void ScriptRunner::SetButtons(std::shared_ptr<ScriptedButtons> buttons) { | |||||||
|     scripted_buttons = buttons; |     scripted_buttons = buttons; | ||||||
| } | } | ||||||
|  |  | ||||||
| void ScriptRunner::LoadScript(std::string script_name) { | void ScriptRunner::LoadScript(std::string script_name, bool close) { | ||||||
|  |     close_at_end = close; | ||||||
|  |  | ||||||
|     FILE* file = fopen(script_name.c_str(), "r"); |     FILE* file = fopen(script_name.c_str(), "r"); | ||||||
|     if (!file) { |     if (!file) { | ||||||
|         LOG_ERROR(ScriptedInput, "script_file %s does not exist", script_name.c_str()); |         LOG_ERROR(ScriptedInput, "script_file %s does not exist", script_name.c_str()); | ||||||
| @@ -108,6 +111,11 @@ void ScriptRunner::NotifyFrameFinished() { | |||||||
|  |  | ||||||
|     if (script_index >= script.size()) { |     if (script_index >= script.size()) { | ||||||
|         LOG_INFO(ScriptedInput, "Scripted Input finished at frame %i", frame_number); |         LOG_INFO(ScriptedInput, "Scripted Input finished at frame %i", frame_number); | ||||||
|  |         if (close_at_end) { | ||||||
|  |             SDL_Event sdlevent; | ||||||
|  |             sdlevent.type = SDL_QUIT; | ||||||
|  |             SDL_PushEvent(&sdlevent); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -27,7 +27,7 @@ public: | |||||||
| class ScriptRunner final { | class ScriptRunner final { | ||||||
| public: | public: | ||||||
|     void SetButtons(std::shared_ptr<ScriptedButtons> buttons); |     void SetButtons(std::shared_ptr<ScriptedButtons> buttons); | ||||||
|     void LoadScript(std::string script_name); |     void LoadScript(std::string script_name, bool close_at_end); | ||||||
|     bool HasScript() const; |     bool HasScript() const; | ||||||
|  |  | ||||||
|     void NotifyFrameFinished(); |     void NotifyFrameFinished(); | ||||||
| @@ -39,6 +39,7 @@ private: | |||||||
|     int script_frame{0}; |     int script_frame{0}; | ||||||
|  |  | ||||||
|     std::shared_ptr<ScriptedButtons> scripted_buttons; |     std::shared_ptr<ScriptedButtons> scripted_buttons; | ||||||
|  |     bool close_at_end; | ||||||
|  |  | ||||||
|     void SaveScreenshot(); |     void SaveScreenshot(); | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -19,9 +19,9 @@ void Init() { | |||||||
|     script_runner.SetButtons(scripted_buttons); |     script_runner.SetButtons(scripted_buttons); | ||||||
| } | } | ||||||
|  |  | ||||||
| void LoadScript(std::string script_name) { | void LoadScript(std::string script_name, bool close_at_end) { | ||||||
|     if (script_name.length() > 0) { |     if (script_name.length() > 0) { | ||||||
|         script_runner.LoadScript(script_name); |         script_runner.LoadScript(script_name, close_at_end); | ||||||
|  |  | ||||||
|         ScriptedButtons::OverrideControlsSettings(); |         ScriptedButtons::OverrideControlsSettings(); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -11,7 +11,7 @@ namespace ScriptedInput { | |||||||
| /// Initializes and registers the input device factories. | /// Initializes and registers the input device factories. | ||||||
| void Init(); | void Init(); | ||||||
|  |  | ||||||
| void LoadScript(std::string script_name); | void LoadScript(std::string script_name, bool close_at_end); | ||||||
|  |  | ||||||
| /// Deregisters the input device factories and shuts them down. | /// Deregisters the input device factories and shuts them down. | ||||||
| void Shutdown(); | void Shutdown(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 danzel
					danzel