mirror of
https://github.com/citra-emu/citra.git
synced 2024-11-30 02:30:05 +00:00
Fixing formatting
This commit is contained in:
parent
c96d031b90
commit
63ca1acd2b
@ -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));
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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<int> buttons_active;
|
||||
};
|
||||
|
||||
@ -34,11 +30,12 @@ public:
|
||||
bool HasScript() const;
|
||||
|
||||
void NotifyFrameFinished();
|
||||
|
||||
private:
|
||||
std::vector<ScriptItem> 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<ScriptedButtons> scripted_buttons;
|
||||
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -7,11 +7,10 @@
|
||||
#include "scripted_input/scripted_buttons.h"
|
||||
#include "scripted_input/scripted_input.h"
|
||||
|
||||
|
||||
namespace ScriptedInput {
|
||||
|
||||
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;
|
||||
|
||||
void Init() {
|
||||
|
Loading…
Reference in New Issue
Block a user