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 "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));

View File

@ -45,25 +45,22 @@ void ScriptRunner::LoadScript(std::string script_name) {
// 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 {
} 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, " ,.-");
@ -96,7 +93,8 @@ void ScriptRunner::NotifyFrameFinished() {
script_index++;
// 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();
script_index++;
}
@ -112,18 +110,57 @@ 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;
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
// 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");
fwrite(file_header, sizeof(file_header), 1, fp);
@ -131,7 +168,6 @@ void ScriptRunner::SaveScreenshot() {
fwrite(pixels, w * h * 3, 1, fp);
fclose(fp);
delete[] pixels;
}
}

View File

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

View File

@ -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<bool> status{false};
};
@ -53,7 +39,6 @@ public:
ScriptedButton* buttons[button_count];
};
ScriptedButtons::ScriptedButtons() : scripted_button_list{std::make_shared<ScriptedButtonList>()} {}
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]];
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]);
}
}
}

View File

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

View File

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