From 63ca1acd2bbd046cc930541ef56ed67578ca444c Mon Sep 17 00:00:00 2001 From: danzel Date: Sun, 13 Aug 2017 10:33:23 +1200 Subject: [PATCH] Fixing formatting --- src/citra/emu_window/emu_window_sdl2.cpp | 2 +- src/scripted_input/script_runner.cpp | 88 +++++++++++++++++------- src/scripted_input/script_runner.h | 17 ++--- src/scripted_input/scripted_buttons.cpp | 29 +++----- src/scripted_input/scripted_buttons.h | 1 + src/scripted_input/scripted_input.cpp | 3 +- 6 files changed, 80 insertions(+), 60 deletions(-) diff --git a/src/citra/emu_window/emu_window_sdl2.cpp b/src/citra/emu_window/emu_window_sdl2.cpp index 91150de12..43266acff 100644 --- a/src/citra/emu_window/emu_window_sdl2.cpp +++ b/src/citra/emu_window/emu_window_sdl2.cpp @@ -16,8 +16,8 @@ #include "core/settings.h" #include "input_common/keyboard.h" #include "input_common/main.h" -#include "scripted_input/scripted_input.h" #include "network/network.h" +#include "scripted_input/scripted_input.h" void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) { TouchMoved((unsigned)std::max(x, 0), (unsigned)std::max(y, 0)); diff --git a/src/scripted_input/script_runner.cpp b/src/scripted_input/script_runner.cpp index 363e8ec22..6c977e397 100644 --- a/src/scripted_input/script_runner.cpp +++ b/src/scripted_input/script_runner.cpp @@ -28,7 +28,7 @@ void ScriptRunner::LoadScript(std::string script_name) { while (fgets(line, SCRIPT_MAX_LINE, file) != NULL) { lineno++; - //Remove end of line bytes and comments + // Remove end of line bytes and comments char terminal_chars[] = "\r\n#"; for (int i = 0; i < strlen(terminal_chars); i++) { char* index = strchr(line, terminal_chars[i]); @@ -42,28 +42,25 @@ void ScriptRunner::LoadScript(std::string script_name) { char* pch = strtok(line, " "); while (pch != NULL) { if (item.type == ScriptItemType::Undefined) { - //The first token is a number or "screenshot" + // The first token is a number or "screenshot" if (strcmp("screenshot", pch) == 0) { item.type = ScriptItemType::Screenshot; - } - else { + } else { int res = sscanf(pch, "%d", &item.frames); if (res == 1 && item.frames > 0) { item.type = ScriptItemType::Run; - } - else { + } else { LOG_ERROR(ScriptedInput, "Unable to parse line %i of script file", lineno); } } - } - else { - //The following should be buttons + } else { + // The following should be buttons int index = IndexOfButton(pch); if (index != -1) { item.buttons_active.push_back(index); - } - else { - LOG_ERROR(ScriptedInput, "Unable to parse line %i, button %s is unknown", lineno, pch); + } else { + LOG_ERROR(ScriptedInput, "Unable to parse line %i, button %s is unknown", + lineno, pch); } } pch = strtok(NULL, " ,.-"); @@ -84,24 +81,25 @@ bool ScriptRunner::HasScript() const { void ScriptRunner::NotifyFrameFinished() { frame_number++; - //Script already finished + // Script already finished if (script_index >= script.size()) { return; } - //If we're done with the current item, move to the next + // If we're done with the current item, move to the next script_frame++; if (script_frame == script[script_index].frames) { script_frame = 0; script_index++; - //take screenshots if we hit a screenshot item - while (script_index < script.size() && script[script_index].type == ScriptItemType::Screenshot) { + // take screenshots if we hit a screenshot item + while (script_index < script.size() && + script[script_index].type == ScriptItemType::Screenshot) { SaveScreenshot(); script_index++; } - //Now we'll be at the next run item, so set the buttons up + // Now we'll be at the next run item, so set the buttons up if (script_index < script.size()) { scripted_buttons.get()->SetActiveButtons(script[script_index].buttons_active); } @@ -112,26 +110,64 @@ void ScriptRunner::SaveScreenshot() { char buf[12]; sprintf(buf, "%i.bmp", frame_number); - - const int w = 400;//render_window->GetActiveConfig().min_client_area_size.first; - const int h = 480;//render_window->GetActiveConfig().min_client_area_size.second; + const int w = 400; // render_window->GetActiveConfig().min_client_area_size.first; + const int h = 480; // render_window->GetActiveConfig().min_client_area_size.second; unsigned char* pixels = new unsigned char[w * h * 3]; glReadPixels(0, 0, w, h, GL_BGR, GL_UNSIGNED_BYTE, pixels); - //BMP - //ref https://web.archive.org/web/20080912171714/http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html + // BMP + // https://web.archive.org/web/20080912171714/http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html int image_bytes = (w * h * 3); int size = 14 + 40 + image_bytes; - unsigned char file_header[14] = { 'B', 'M', size, size >> 8, size >> 16, size >> 24, 0, 0, 0, 0, 14 + 40, 0, 0, 0 }; - unsigned char info_header[40] = { 40, 0, 0, 0, w, w >> 8, w >> 16, w >> 24, h, h >> 8, h >> 16, h >> 24, 1, 0, 24, 0, 0, 0, 0, 0, image_bytes, image_bytes >> 8, image_bytes >> 16, image_bytes >> 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + unsigned char file_header[14] = {'B', 'M', size, size >> 8, size >> 16, size >> 24, 0, + 0, 0, 0, 14 + 40, 0, 0, 0}; + unsigned char info_header[40] = {40, + 0, + 0, + 0, + w, + w >> 8, + w >> 16, + w >> 24, + h, + h >> 8, + h >> 16, + h >> 24, + 1, + 0, + 24, + 0, + 0, + 0, + 0, + 0, + image_bytes, + image_bytes >> 8, + image_bytes >> 16, + image_bytes >> 24, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0}; - FILE *fp = fopen(buf, "wb"); + FILE* fp = fopen(buf, "wb"); fwrite(file_header, sizeof(file_header), 1, fp); fwrite(info_header, sizeof(info_header), 1, fp); fwrite(pixels, w * h * 3, 1, fp); fclose(fp); - delete[] pixels; } } \ No newline at end of file diff --git a/src/scripted_input/script_runner.h b/src/scripted_input/script_runner.h index 75b0af1e4..b20f5e4c8 100644 --- a/src/scripted_input/script_runner.h +++ b/src/scripted_input/script_runner.h @@ -9,18 +9,14 @@ namespace ScriptedInput { -enum class ScriptItemType { - Undefined, - Run, - Screenshot -}; +enum class ScriptItemType { Undefined, Run, Screenshot }; class ScriptItem { public: static ScriptItem Screenshot; - ScriptItemType type{ ScriptItemType::Undefined }; - int frames {0}; + ScriptItemType type{ScriptItemType::Undefined}; + int frames{0}; std::vector buttons_active; }; @@ -34,11 +30,12 @@ public: bool HasScript() const; void NotifyFrameFinished(); + private: std::vector script; - int frame_number {0}; - int script_index {0}; - int script_frame {0}; + int frame_number{0}; + int script_index{0}; + int script_frame{0}; std::shared_ptr scripted_buttons; diff --git a/src/scripted_input/scripted_buttons.cpp b/src/scripted_input/scripted_buttons.cpp index e4e9dd8dd..59f3d5718 100644 --- a/src/scripted_input/scripted_buttons.cpp +++ b/src/scripted_input/scripted_buttons.cpp @@ -7,23 +7,8 @@ const int button_count = 15; -std::string button_name_to_index[] = { - "a", - "b", - "x", - "y", - "up", - "down", - "left", - "right", - "l", - "r", - "start", - "select", - "zl", - "zr", - "home" -}; +std::string button_name_to_index[] = {"a", "b", "x", "y", "up", "down", "left", "right", + "l", "r", "start", "select", "zl", "zr", "home"}; namespace ScriptedInput { @@ -44,6 +29,7 @@ class ScriptedButton final : public Input::ButtonDevice { } friend class ScriptedButtons; + private: std::atomic status{false}; }; @@ -53,7 +39,6 @@ public: ScriptedButton* buttons[button_count]; }; - ScriptedButtons::ScriptedButtons() : scripted_button_list{std::make_shared()} {} std::unique_ptr ScriptedButtons::Create(const Common::ParamPackage& params) { @@ -81,9 +66,11 @@ void ScriptedButtons::SetActiveButtons(const std::vector& buttons_active) { auto button = scripted_button_list.get()->buttons[buttons_active[i]]; if (button) { button->status.store(true); - } - else { - 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]); + } else { + 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_buttons.h b/src/scripted_input/scripted_buttons.h index 1cf327a56..dd5291860 100644 --- a/src/scripted_input/scripted_buttons.h +++ b/src/scripted_input/scripted_buttons.h @@ -27,6 +27,7 @@ public: std::unique_ptr Create(const Common::ParamPackage& params) override; void SetActiveButtons(const std::vector& buttons_active); + private: std::shared_ptr scripted_button_list; }; diff --git a/src/scripted_input/scripted_input.cpp b/src/scripted_input/scripted_input.cpp index 5662ca5df..f0d9d416c 100644 --- a/src/scripted_input/scripted_input.cpp +++ b/src/scripted_input/scripted_input.cpp @@ -7,11 +7,10 @@ #include "scripted_input/scripted_buttons.h" #include "scripted_input/scripted_input.h" - namespace ScriptedInput { static std::shared_ptr scripted_buttons; -//TODO: static std::shared_ptr scripted_analog; +// TODO: static std::shared_ptr scripted_analog; static ScriptRunner script_runner; void Init() {