From a47dacfdd0106acd87fe48ef53cfa002ae7c1770 Mon Sep 17 00:00:00 2001 From: danzel Date: Sun, 13 Aug 2017 10:17:21 +1200 Subject: [PATCH] Do logging correctly --- src/common/logging/log.h | 1 + src/scripted_input/script_runner.cpp | 12 ++++-------- src/scripted_input/scripted_buttons.cpp | 7 +++---- src/scripted_input/scripted_input.cpp | 1 - 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/common/logging/log.h b/src/common/logging/log.h index fe4dfed69..b3525c99c 100644 --- a/src/common/logging/log.h +++ b/src/common/logging/log.h @@ -91,6 +91,7 @@ enum class Class : ClassType { Loader, ///< ROM loader Input, ///< Input emulation Network, ///< Network emulation + ScriptedInput, ///< Scripted Input WebService, ///< Interface to Citra Web Services Count ///< Total number of logging classes }; diff --git a/src/scripted_input/script_runner.cpp b/src/scripted_input/script_runner.cpp index 8a734801f..8cd880022 100644 --- a/src/scripted_input/script_runner.cpp +++ b/src/scripted_input/script_runner.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include "common/logging/log.h" #include "scripted_input/script_runner.h" #include "scripted_input/scripted_buttons.h" @@ -15,10 +16,9 @@ void ScriptRunner::SetButtons(std::shared_ptr buttons) { } void ScriptRunner::LoadScript(std::string script_name) { - //TODO: Load from a file specified in config FILE* file = fopen(script_name.c_str(), "r"); if (!file) { - //TODO: Log error + LOG_ERROR(ScriptedInput, "script_file %s does not exist", script_name.c_str()); return; } @@ -52,7 +52,7 @@ void ScriptRunner::LoadScript(std::string script_name) { item.type = ScriptItemType::Run; } else { - //TODO: Parse error + LOG_ERROR(ScriptedInput, "Unable to parse line %i of script file", lineno); } } } @@ -63,7 +63,7 @@ void ScriptRunner::LoadScript(std::string script_name) { item.buttons_active.push_back(index); } else { - //TODO: Parse error + LOG_ERROR(ScriptedInput, "Unable to parse line %i, button %s is unknown", lineno, pch); } } pch = strtok(NULL, " ,.-"); @@ -82,27 +82,23 @@ void ScriptRunner::NotifyFrameFinished() { //Script already finished if (script_index >= script.size()) { - //printf("already done\n"); return; } //If we're done with the current item, move to the next script_frame++; if (script_frame == script[script_index].frames) { - printf("At frame %i, progressing to index %i\n", frame_number, script_index + 1); script_frame = 0; script_index++; //take screenshots if we hit a screenshot item while (script_index < script.size() && script[script_index].type == ScriptItemType::Screenshot) { - //TODO: Screenshot SaveScreenshot(); script_index++; } //Now we'll be at the next run item, so set the buttons up if (script_index < script.size()) { - printf("changing button\n"); scripted_buttons.get()->SetActiveButtons(script[script_index].buttons_active); } } diff --git a/src/scripted_input/scripted_buttons.cpp b/src/scripted_input/scripted_buttons.cpp index 1934a84e6..4e4965277 100644 --- a/src/scripted_input/scripted_buttons.cpp +++ b/src/scripted_input/scripted_buttons.cpp @@ -34,8 +34,8 @@ int IndexOfButton(const std::string& button) { } } - //TODO: Log an error - return -1; //home + LOG_ERROR(ScriptedInput, "Don't know about a button named %s", button.c_str()); + return -1; } class ScriptedButton final : public Input::ButtonDevice { @@ -49,7 +49,6 @@ private: }; class ScriptedButtonList { - //TODO: Do i need to memset(0) buttons? public: ScriptedButton* buttons[button_count]; }; @@ -89,7 +88,7 @@ void ScriptedButtons::SetActiveButtons(const std::vector& buttons_active) { button->status.store(true); } else { - //TODO: Warning that button isn't mapped to scripting + LOG_ERROR(ScriptedInput, "Button %s isn't mapped but is scripted, it should have engine:scripted,button:%s", button_name_to_index[i], button_name_to_index[i]); } } } diff --git a/src/scripted_input/scripted_input.cpp b/src/scripted_input/scripted_input.cpp index 4eef1542a..9029eedc1 100644 --- a/src/scripted_input/scripted_input.cpp +++ b/src/scripted_input/scripted_input.cpp @@ -37,7 +37,6 @@ bool IsInUse() { void NotifyFrameFinished() { script_runner.NotifyFrameFinished(); - //TODO? scripted_buttons.get()->NotifyFrameFinished(); } } // namespace ScriptedInput