Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Command File Runner

Check warning on line 1 in SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileRunner.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=532 (advisory above 500, limit 1000)

Check warning on line 1 in SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileRunner.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=532 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand All @@ -13,6 +13,7 @@
#include "Common/Cpp/Filesystem/Filesystem.h"
#include "Common/Cpp/Filesystem/FileIO.h"
#include "CommonFramework/GlobalAutoPaths.h"
#include "CommonFramework/ImageTools/ImageDiff.h"
#include "CommonFramework/ImageTypes/ImageRGB32.h"
#include "CommonFramework/Exceptions/OperationFailedException.h"
#include "CommonFramework/VideoPipeline/VideoFeed.h"
Expand Down Expand Up @@ -42,6 +43,13 @@
constexpr Milliseconds SHOTS_INTERVAL = 500ms;
constexpr Milliseconds WAIT_FOR_TIMEOUT = 5000ms;

// "walk": the stick is held in slices this long, and the frames between
// slices are compared (RMSD at 192x108). Two slices in a row under the
// threshold count as standing still against something.
constexpr Milliseconds WALK_SLICE = 200ms;
constexpr Milliseconds WALK_LIMIT = 5000ms;
constexpr double WALK_STILL_RMSD = 10;

// How often "wait_for" and "expect" check a new frame.
constexpr Milliseconds DETECTOR_POLL_INTERVAL = 100ms;

Expand Down Expand Up @@ -160,6 +168,7 @@
{"dpad", {"dpad UP|DOWN|LEFT|RIGHT [hold_ms] [release_ms]", &LineRunner::dpad}},
{"stick", {"stick L|R x y [hold_ms] [release_ms] (x, y from -1 to 1)", &LineRunner::stick}},
{"wait", {"wait ms", &LineRunner::wait}},
{"walk", {"walk x y [max_ms] [still_rmsd] (left stick until the screen holds still)", &LineRunner::walk}},
{"shot", {"shot label", &LineRunner::shot}},
{"shots", {"shots label count [interval_ms]", &LineRunner::shots}},
{"detect", {"detect detector [image] (image: a path, or a file in the outbox)", &LineRunner::detect}},
Expand Down Expand Up @@ -218,6 +227,45 @@
void wait(const std::vector<std::string>& words){
pbf_wait(context(), optional_duration(words, 1, 0ms));
}
// Holds the left stick until the screen stops changing (a wall, a
// sign, someone in the way) or max_ms passes, and reports how long it
// moved. Measuring a map with walks that stop on their own: a timed
// hold moves a different number of tiles from one try to the next.
void walk(const std::vector<std::string>& words){

Check warning on line 234 in SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileRunner.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::LineRunner::walk( const std :: vector<std::string> & words): function_lines=35 (advisory above 25, limit 50)

Check warning on line 234 in SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileRunner.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::LineRunner::walk( const std :: vector<std::string> & words): function_lines=35 (advisory above 25, limit 50)
const JoystickPosition position{optional_number(words, 1, 0), optional_number(words, 2, 0)};
const Milliseconds limit = optional_duration(words, 3, WALK_LIMIT);
const double still = optional_number(words, 4, WALK_STILL_RMSD);
VideoSnapshot before = current_frame();
if (!before){
throw OperationFailedException(ErrorReportMode::NO_ERROR_REPORT, "walk: no video frame");
}
Milliseconds walked = 0ms;
Milliseconds moving = 0ms;
int quiet = 0;
std::ostringstream changes;
while (walked < limit && quiet < 2){
pbf_move_left_joystick(context(), position, WALK_SLICE, 0ms);
VideoSnapshot after = current_frame();
if (!after){
break;
}
const double change = ImageMatch::pixel_RMSD(
before.frame->scale_to(192, 108), after.frame->scale_to(192, 108)
);
walked += WALK_SLICE;
changes << " " << (int)change;
if (change < still){
quiet++;
}else{
quiet = 0;
moving = walked;
}
before = std::move(after);
}
pbf_wait(context(), STICK_RELEASE);
out() << "walk " << (quiet >= 2 ? "still" : "limit") << " after " << walked.count()
<< "ms, moving " << moving.count() << "ms; changes" << changes.str() << "\n";
}
void shot(const std::vector<std::string>& words){
out() << "shot " << save_screenshot(required_arg(words, 1)) << "\n";
}
Expand Down Expand Up @@ -329,7 +377,7 @@
};

// Runs one line and adds its "ok" or "error" result to `session.out`.
LineResult run_line(LineRunner& runner, CommandFileSession& session, const std::string& text, size_t number, WallClock file_start){

Check warning on line 380 in SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileRunner.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::run_line( LineRunner & runner , CommandFileSession & session , const std :: string & text , size_t number , WallClock file_start): function_lines=30 (advisory above 25, limit 50)
const std::vector<std::string> words = split_command_line(text);
if (words.empty()){
return LineResult::NEXT_LINE;
Expand Down Expand Up @@ -361,7 +409,7 @@
}

// Runs a file from the inbox and moves it to "done". Returns false if it ran "stop".
bool run_command_file(

Check warning on line 412 in SerialPrograms/Source/NintendoSwitch/Programs/CommandFileRunner/NintendoSwitch_CommandFileRunner.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::run_command_file( SingleSwitchProgramEnvironment & env , ProControllerContext & context , const std :: string & folder , const Filesystem :: Path & file): function_lines=36 (advisory above 25, limit 50)
SingleSwitchProgramEnvironment& env, ProControllerContext& context,
const std::string& folder, const Filesystem::Path& file
){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Any other line comes from a command, such as `detect home yes` or the path of a
| `dpad UP\|DOWN\|LEFT\|RIGHT [hold] [release]` | Presses the D-pad. | hold 100, release 200 |
| `stick L\|R x y [hold] [release]` | Moves the left or right stick. `x` and `y` run from -1 to 1; `y` is +1 for up. | hold 160, release 160 |
| `wait ms` | Waits. | |
| `walk x y [max] [still]` | Holds the left stick in 200 ms slices until two slices in a row change the screen less than `still` (RMSD at 192x108): a wall or someone in the way. Prints `walk still\|limit after N ms, moving M ms` and each slice's change. For measuring maps: a timed `stick` hold moves a different number of tiles from try to try. | max 5000, still 10 |

### Screen

Expand Down
Loading