Skip to content

Commit f69d285

Browse files
committed
Console state refactor.
1 parent 91b2fa0 commit f69d285

File tree

197 files changed

+1121
-825
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+1121
-825
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,7 @@ file(GLOB MAIN_SOURCES
969969
Source/NintendoSwitch/Inference/NintendoSwitch_UpdatePopupDetector.h
970970
Source/NintendoSwitch/NintendoSwitch_ConsoleHandle.cpp
971971
Source/NintendoSwitch/NintendoSwitch_ConsoleHandle.h
972+
Source/NintendoSwitch/NintendoSwitch_ConsoleState.h
972973
Source/NintendoSwitch/NintendoSwitch_MultiSwitchProgram.cpp
973974
Source/NintendoSwitch/NintendoSwitch_MultiSwitchProgram.h
974975
Source/NintendoSwitch/NintendoSwitch_Panels.cpp

SerialPrograms/Source/CommonTools/VisualDetector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class StaticScreenDetector{
1919
public:
2020
virtual ~StaticScreenDetector() = default;
2121
virtual void make_overlays(VideoOverlaySet& items) const = 0;
22-
virtual bool detect(const ImageViewRGB32& screen) const = 0;
22+
virtual bool detect(const ImageViewRGB32& screen) = 0;
2323
};
2424

2525

SerialPrograms/Source/CommonTools/VisualDetectors/BlackBorderDetector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void BlackBorderDetector::make_overlays(VideoOverlaySet& items) const{
3131
items.add(COLOR_RED, m_right);
3232
// items.add(COLOR_RED, m_body);
3333
}
34-
bool BlackBorderDetector::detect(const ImageViewRGB32& screen) const{
34+
bool BlackBorderDetector::detect(const ImageViewRGB32& screen){
3535
const double MAX_SUM = 50;
3636
const double MAX_STDDEV = 20;
3737

SerialPrograms/Source/CommonTools/VisualDetectors/BlackBorderDetector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class BlackBorderDetector : public StaticScreenDetector{
1818
BlackBorderDetector();
1919

2020
virtual void make_overlays(VideoOverlaySet& items) const override;
21-
virtual bool detect(const ImageViewRGB32& screen) const override;
21+
virtual bool detect(const ImageViewRGB32& screen) override;
2222

2323
private:
2424
ImageFloatBox m_top;

SerialPrograms/Source/CommonTools/VisualDetectors/BlackScreenDetector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ BlackScreenDetector::BlackScreenDetector(
3232
void BlackScreenDetector::make_overlays(VideoOverlaySet& items) const{
3333
items.add(m_color, m_box);
3434
}
35-
bool BlackScreenDetector::detect(const ImageViewRGB32& screen) const{
35+
bool BlackScreenDetector::detect(const ImageViewRGB32& screen){
3636
return is_black(extract_box_reference(screen, m_box), m_max_rgb_sum, m_max_stddev_sum);
3737
}
3838

@@ -51,7 +51,7 @@ WhiteScreenDetector::WhiteScreenDetector(
5151
void WhiteScreenDetector::make_overlays(VideoOverlaySet& items) const{
5252
items.add(m_color, m_box);
5353
}
54-
bool WhiteScreenDetector::detect(const ImageViewRGB32& screen) const{
54+
bool WhiteScreenDetector::detect(const ImageViewRGB32& screen){
5555
return is_white(extract_box_reference(screen, m_box), m_min_rgb_sum, m_max_stddev_sum);
5656
}
5757

SerialPrograms/Source/CommonTools/VisualDetectors/BlackScreenDetector.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class BlackScreenDetector : public StaticScreenDetector{
3030
);
3131

3232
virtual void make_overlays(VideoOverlaySet& items) const override;
33-
virtual bool detect(const ImageViewRGB32& screen) const override;
33+
virtual bool detect(const ImageViewRGB32& screen) override;
3434

3535
private:
3636
Color m_color;
@@ -48,7 +48,7 @@ class WhiteScreenDetector : public StaticScreenDetector{
4848
);
4949

5050
virtual void make_overlays(VideoOverlaySet& items) const override;
51-
virtual bool detect(const ImageViewRGB32& screen) const override;
51+
virtual bool detect(const ImageViewRGB32& screen) override;
5252

5353
private:
5454
Color m_color;

SerialPrograms/Source/CommonTools/VisualDetectors/ImageMatchDetector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ double ImageMatchDetector::rmsd(const ImageViewRGB32& frame) const{
6767
void ImageMatchDetector::make_overlays(VideoOverlaySet& items) const{
6868
items.add(m_color, m_box);
6969
}
70-
bool ImageMatchDetector::detect(const ImageViewRGB32& screen) const{
70+
bool ImageMatchDetector::detect(const ImageViewRGB32& screen){
7171
return rmsd(screen) <= m_max_rmsd;
7272
}
7373

SerialPrograms/Source/CommonTools/VisualDetectors/ImageMatchDetector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ImageMatchDetector : public StaticScreenDetector{
2727
double rmsd(const ImageViewRGB32& frame) const;
2828

2929
virtual void make_overlays(VideoOverlaySet& items) const override;
30-
virtual bool detect(const ImageViewRGB32& screen) const override;
30+
virtual bool detect(const ImageViewRGB32& screen) override;
3131

3232
private:
3333
std::shared_ptr<const ImageRGB32> m_reference_image;

SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Routines.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace PokemonAutomation{
2323
namespace NintendoSwitch{
2424

2525

26-
void close_game(VideoStream& stream, ProControllerContext& context){
26+
void close_game(ConsoleHandle& console, ProControllerContext& context){
2727
// Use mashing to ensure that the X press succeeds. If it fails, the SR
2828
// will fail and can kill a den for the autohosts.
2929

@@ -43,16 +43,16 @@ void close_game(VideoStream& stream, ProControllerContext& context){
4343
// context.wait_for(10s);
4444

4545
// send a second Home button press, if the first one is dropped
46-
bool video_available = (bool)stream.video().snapshot();
46+
bool video_available = (bool)console.video().snapshot();
4747
if (video_available){
4848
HomeMenuWatcher detector;
4949
int ret = wait_until(
50-
stream, context,
50+
console, context,
5151
std::chrono::milliseconds(5000),
5252
{ detector }
5353
);
5454
if (ret == 0){
55-
stream.log("Detected Home screen.");
55+
console.log("Detected Home screen.");
5656
}else{ // if game initially open. | if game initially closed
5757
// initial Home button press was dropped
5858
// - Does nothing. | - goes back to home screen, from opened app
@@ -72,7 +72,7 @@ void close_game(VideoStream& stream, ProControllerContext& context){
7272
pbf_mash_button(context, BUTTON_B, 350);
7373
}
7474

75-
void close_game(VideoStream& stream, JoyconContext& context){
75+
void close_game(ConsoleHandle& console, JoyconContext& context){
7676
// Use mashing to ensure that the X press succeeds. If it fails, the SR
7777
// will fail and can kill a den for the autohosts.
7878

@@ -90,12 +90,12 @@ void close_game(VideoStream& stream, JoyconContext& context){
9090

9191
HomeMenuWatcher detector;
9292
int ret = wait_until(
93-
stream, context,
93+
console, context,
9494
std::chrono::milliseconds(5000),
9595
{ detector }
9696
);
9797
if (ret == 0){
98-
stream.log("Detected Home screen.");
98+
console.log("Detected Home screen.");
9999
}else{ // if game initially open. | if game initially closed
100100
// initial Home button press was dropped
101101
// - Does nothing. | - goes back to home screen, from opened app

SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Routines.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
#include "CommonFramework/Tools/VideoStream.h"
1111
#include "NintendoSwitch/Controllers/NintendoSwitch_ProController.h"
1212
#include "NintendoSwitch/Controllers/NintendoSwitch_Joycon.h"
13+
#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h"
1314

1415
namespace PokemonAutomation{
1516
namespace NintendoSwitch{
1617

1718

18-
void close_game(VideoStream& stream, ProControllerContext& device);
19+
void close_game(ConsoleHandle& console, ProControllerContext& device);
1920

20-
void close_game(VideoStream& stream, JoyconContext& device);
21+
void close_game(ConsoleHandle& console, JoyconContext& device);
2122

2223

2324

0 commit comments

Comments
 (0)