Add a setting for ScriptedInput 'close_at_end', closes the emulator when the script finishes running.

This commit is contained in:
danzel 2017-08-13 18:26:30 +12:00
parent 196a09fefa
commit deb35f4fb4
9 changed files with 21 additions and 7 deletions

View File

@ -154,6 +154,7 @@ void Config::ReadValues() {
// Scripted Input
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
Settings::values.telemetry_endpoint_url = sdl2_config->Get(

View File

@ -172,6 +172,9 @@ gdbstub_port=24689
[ScriptedInput]
# Script file to load for simulated input
script_name=
# Whether to close the emulator when the script has finished
# 0 (default): Don't Close, 1: Close
close_at_end=
[WebService]
# Endpoint URL for submitting telemetry data

View File

@ -36,7 +36,7 @@ void Apply() {
Service::HID::ReloadInputDevices();
Service::IR::ReloadInputDevices();
ScriptedInput::LoadScript(values.script_name);
ScriptedInput::LoadScript(values.script_name, values.close_at_end);
}
} // namespace

View File

@ -129,6 +129,7 @@ struct Values {
// ScriptedInput
std::string script_name;
bool close_at_end;
// WebService
std::string telemetry_endpoint_url;

View File

@ -14,4 +14,4 @@ create_directory_groups(${SRCS} ${HEADERS})
add_library(scripted_input STATIC ${SRCS} ${HEADERS})
target_link_libraries(scripted_input PUBLIC common core)
target_link_libraries(scripted_input PRIVATE glad)
target_link_libraries(scripted_input PRIVATE glad SDL2)

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <SDL.h>
#include <glad/glad.h>
#include <string.h>
#include "common/logging/log.h"
@ -16,7 +17,9 @@ void ScriptRunner::SetButtons(std::shared_ptr<ScriptedButtons> 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");
if (!file) {
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()) {
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);
}
}
}

View File

@ -27,7 +27,7 @@ public:
class ScriptRunner final {
public:
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;
void NotifyFrameFinished();
@ -39,6 +39,7 @@ private:
int script_frame{0};
std::shared_ptr<ScriptedButtons> scripted_buttons;
bool close_at_end;
void SaveScreenshot();
};

View File

@ -19,9 +19,9 @@ void Init() {
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) {
script_runner.LoadScript(script_name);
script_runner.LoadScript(script_name, close_at_end);
ScriptedButtons::OverrideControlsSettings();
}

View File

@ -11,7 +11,7 @@ namespace ScriptedInput {
/// Initializes and registers the input device factories.
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.
void Shutdown();