mirror of
https://github.com/citra-emu/citra.git
synced 2024-11-30 04:40:05 +00:00
Fixing formatting
This commit is contained in:
parent
c96d031b90
commit
63ca1acd2b
@ -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));
|
||||||
|
@ -28,7 +28,7 @@ void ScriptRunner::LoadScript(std::string script_name) {
|
|||||||
while (fgets(line, SCRIPT_MAX_LINE, file) != NULL) {
|
while (fgets(line, SCRIPT_MAX_LINE, file) != NULL) {
|
||||||
lineno++;
|
lineno++;
|
||||||
|
|
||||||
//Remove end of line bytes and comments
|
// Remove end of line bytes and comments
|
||||||
char terminal_chars[] = "\r\n#";
|
char terminal_chars[] = "\r\n#";
|
||||||
for (int i = 0; i < strlen(terminal_chars); i++) {
|
for (int i = 0; i < strlen(terminal_chars); i++) {
|
||||||
char* index = strchr(line, 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, " ");
|
char* pch = strtok(line, " ");
|
||||||
while (pch != NULL) {
|
while (pch != NULL) {
|
||||||
if (item.type == ScriptItemType::Undefined) {
|
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) {
|
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, " ,.-");
|
||||||
@ -84,24 +81,25 @@ bool ScriptRunner::HasScript() const {
|
|||||||
void ScriptRunner::NotifyFrameFinished() {
|
void ScriptRunner::NotifyFrameFinished() {
|
||||||
frame_number++;
|
frame_number++;
|
||||||
|
|
||||||
//Script already finished
|
// Script already finished
|
||||||
if (script_index >= script.size()) {
|
if (script_index >= script.size()) {
|
||||||
return;
|
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++;
|
script_frame++;
|
||||||
if (script_frame == script[script_index].frames) {
|
if (script_frame == script[script_index].frames) {
|
||||||
script_frame = 0;
|
script_frame = 0;
|
||||||
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++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//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()) {
|
if (script_index < script.size()) {
|
||||||
scripted_buttons.get()->SetActiveButtons(script[script_index].buttons_active);
|
scripted_buttons.get()->SetActiveButtons(script[script_index].buttons_active);
|
||||||
}
|
}
|
||||||
@ -112,26 +110,64 @@ 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);
|
||||||
fwrite(info_header, sizeof(info_header), 1, fp);
|
fwrite(info_header, sizeof(info_header), 1, fp);
|
||||||
fwrite(pixels, w * h * 3, 1, fp);
|
fwrite(pixels, w * h * 3, 1, fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
|
|
||||||
delete[] pixels;
|
delete[] pixels;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,18 +9,14 @@
|
|||||||
|
|
||||||
namespace ScriptedInput {
|
namespace ScriptedInput {
|
||||||
|
|
||||||
enum class ScriptItemType {
|
enum class ScriptItemType { Undefined, Run, Screenshot };
|
||||||
Undefined,
|
|
||||||
Run,
|
|
||||||
Screenshot
|
|
||||||
};
|
|
||||||
|
|
||||||
class ScriptItem {
|
class ScriptItem {
|
||||||
public:
|
public:
|
||||||
static ScriptItem Screenshot;
|
static ScriptItem Screenshot;
|
||||||
|
|
||||||
ScriptItemType type{ ScriptItemType::Undefined };
|
ScriptItemType type{ScriptItemType::Undefined};
|
||||||
int frames {0};
|
int frames{0};
|
||||||
std::vector<int> buttons_active;
|
std::vector<int> buttons_active;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -34,11 +30,12 @@ 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};
|
||||||
int script_index {0};
|
int script_index{0};
|
||||||
int script_frame {0};
|
int script_frame{0};
|
||||||
|
|
||||||
std::shared_ptr<ScriptedButtons> scripted_buttons;
|
std::shared_ptr<ScriptedButtons> scripted_buttons;
|
||||||
|
|
||||||
|
@ -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]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
};
|
};
|
||||||
|
@ -7,11 +7,10 @@
|
|||||||
#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;
|
||||||
//TODO: static std::shared_ptr<ScriptedAnalog> scripted_analog;
|
// TODO: static std::shared_ptr<ScriptedAnalog> scripted_analog;
|
||||||
static ScriptRunner script_runner;
|
static ScriptRunner script_runner;
|
||||||
|
|
||||||
void Init() {
|
void Init() {
|
||||||
|
Loading…
Reference in New Issue
Block a user