Fixing formatting

This commit is contained in:
danzel 2017-08-13 10:33:23 +12:00
parent c96d031b90
commit 63ca1acd2b
6 changed files with 80 additions and 60 deletions

View File

@ -16,8 +16,8 @@
#include "core/settings.h" #include "core/settings.h"
#include "input_common/keyboard.h" #include "input_common/keyboard.h"
#include "input_common/main.h" #include "input_common/main.h"
#include "scripted_input/scripted_input.h"
#include "network/network.h" #include "network/network.h"
#include "scripted_input/scripted_input.h"
void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) { void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) {
TouchMoved((unsigned)std::max(x, 0), (unsigned)std::max(y, 0)); TouchMoved((unsigned)std::max(x, 0), (unsigned)std::max(y, 0));

View File

@ -45,25 +45,22 @@ void ScriptRunner::LoadScript(std::string script_name) {
// The first token is a number or "screenshot" // The first token is a number or "screenshot"
if (strcmp("screenshot", pch) == 0) { if (strcmp("screenshot", pch) == 0) {
item.type = ScriptItemType::Screenshot; item.type = ScriptItemType::Screenshot;
} } else {
else {
int res = sscanf(pch, "%d", &item.frames); int res = sscanf(pch, "%d", &item.frames);
if (res == 1 && item.frames > 0) { if (res == 1 && item.frames > 0) {
item.type = ScriptItemType::Run; item.type = ScriptItemType::Run;
} } else {
else {
LOG_ERROR(ScriptedInput, "Unable to parse line %i of script file", lineno); LOG_ERROR(ScriptedInput, "Unable to parse line %i of script file", lineno);
} }
} }
} } else {
else {
// The following should be buttons // The following should be buttons
int index = IndexOfButton(pch); int index = IndexOfButton(pch);
if (index != -1) { if (index != -1) {
item.buttons_active.push_back(index); item.buttons_active.push_back(index);
} } else {
else { LOG_ERROR(ScriptedInput, "Unable to parse line %i, button %s is unknown",
LOG_ERROR(ScriptedInput, "Unable to parse line %i, button %s is unknown", lineno, pch); lineno, pch);
} }
} }
pch = strtok(NULL, " ,.-"); pch = strtok(NULL, " ,.-");
@ -96,7 +93,8 @@ void ScriptRunner::NotifyFrameFinished() {
script_index++; script_index++;
// take screenshots if we hit a screenshot item // take screenshots if we hit a screenshot item
while (script_index < script.size() && script[script_index].type == ScriptItemType::Screenshot) { while (script_index < script.size() &&
script[script_index].type == ScriptItemType::Screenshot) {
SaveScreenshot(); SaveScreenshot();
script_index++; script_index++;
} }
@ -112,18 +110,57 @@ void ScriptRunner::SaveScreenshot() {
char buf[12]; char buf[12];
sprintf(buf, "%i.bmp", frame_number); sprintf(buf, "%i.bmp", frame_number);
const int w = 400; // render_window->GetActiveConfig().min_client_area_size.first; 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 h = 480; // render_window->GetActiveConfig().min_client_area_size.second;
unsigned char* pixels = new unsigned char[w * h * 3]; unsigned char* pixels = new unsigned char[w * h * 3];
glReadPixels(0, 0, w, h, GL_BGR, GL_UNSIGNED_BYTE, pixels); glReadPixels(0, 0, w, h, GL_BGR, GL_UNSIGNED_BYTE, pixels);
// BMP // BMP
//ref https://web.archive.org/web/20080912171714/http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html // https://web.archive.org/web/20080912171714/http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html
int image_bytes = (w * h * 3); int image_bytes = (w * h * 3);
int size = 14 + 40 + image_bytes; 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 file_header[14] = {'B', 'M', size, size >> 8, size >> 16, size >> 24, 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 }; 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(file_header, sizeof(file_header), 1, fp);
@ -131,7 +168,6 @@ void ScriptRunner::SaveScreenshot() {
fwrite(pixels, w * h * 3, 1, fp); fwrite(pixels, w * h * 3, 1, fp);
fclose(fp); fclose(fp);
delete[] pixels; delete[] pixels;
} }
} }

View File

@ -9,11 +9,7 @@
namespace ScriptedInput { namespace ScriptedInput {
enum class ScriptItemType { enum class ScriptItemType { Undefined, Run, Screenshot };
Undefined,
Run,
Screenshot
};
class ScriptItem { class ScriptItem {
public: public:
@ -34,6 +30,7 @@ public:
bool HasScript() const; bool HasScript() const;
void NotifyFrameFinished(); void NotifyFrameFinished();
private: private:
std::vector<ScriptItem> script; std::vector<ScriptItem> script;
int frame_number{0}; int frame_number{0};

View File

@ -7,23 +7,8 @@
const int button_count = 15; const int button_count = 15;
std::string button_name_to_index[] = { std::string button_name_to_index[] = {"a", "b", "x", "y", "up", "down", "left", "right",
"a", "l", "r", "start", "select", "zl", "zr", "home"};
"b",
"x",
"y",
"up",
"down",
"left",
"right",
"l",
"r",
"start",
"select",
"zl",
"zr",
"home"
};
namespace ScriptedInput { namespace ScriptedInput {
@ -44,6 +29,7 @@ class ScriptedButton final : public Input::ButtonDevice {
} }
friend class ScriptedButtons; friend class ScriptedButtons;
private: private:
std::atomic<bool> status{false}; std::atomic<bool> status{false};
}; };
@ -53,7 +39,6 @@ public:
ScriptedButton* buttons[button_count]; ScriptedButton* buttons[button_count];
}; };
ScriptedButtons::ScriptedButtons() : scripted_button_list{std::make_shared<ScriptedButtonList>()} {} ScriptedButtons::ScriptedButtons() : scripted_button_list{std::make_shared<ScriptedButtonList>()} {}
std::unique_ptr<Input::ButtonDevice> ScriptedButtons::Create(const Common::ParamPackage& params) { std::unique_ptr<Input::ButtonDevice> ScriptedButtons::Create(const Common::ParamPackage& params) {
@ -81,9 +66,11 @@ void ScriptedButtons::SetActiveButtons(const std::vector<int>& buttons_active) {
auto button = scripted_button_list.get()->buttons[buttons_active[i]]; auto button = scripted_button_list.get()->buttons[buttons_active[i]];
if (button) { if (button) {
button->status.store(true); button->status.store(true);
} } else {
else { LOG_ERROR(
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]); 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]);
} }
} }
} }

View File

@ -27,6 +27,7 @@ public:
std::unique_ptr<Input::ButtonDevice> Create(const Common::ParamPackage& params) override; std::unique_ptr<Input::ButtonDevice> Create(const Common::ParamPackage& params) override;
void SetActiveButtons(const std::vector<int>& buttons_active); void SetActiveButtons(const std::vector<int>& buttons_active);
private: private:
std::shared_ptr<ScriptedButtonList> scripted_button_list; std::shared_ptr<ScriptedButtonList> scripted_button_list;
}; };

View File

@ -7,7 +7,6 @@
#include "scripted_input/scripted_buttons.h" #include "scripted_input/scripted_buttons.h"
#include "scripted_input/scripted_input.h" #include "scripted_input/scripted_input.h"
namespace ScriptedInput { namespace ScriptedInput {
static std::shared_ptr<ScriptedButtons> scripted_buttons; static std::shared_ptr<ScriptedButtons> scripted_buttons;