Skip to content

Commit bb00e31

Browse files
committed
Throw error if user console type selection conflicts with the detected value.
1 parent d7852fd commit bb00e31

27 files changed

+272
-96
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
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.cpp
972973
Source/NintendoSwitch/NintendoSwitch_ConsoleState.h
973974
Source/NintendoSwitch/NintendoSwitch_MultiSwitchProgram.cpp
974975
Source/NintendoSwitch/NintendoSwitch_MultiSwitchProgram.h
@@ -2449,7 +2450,7 @@ if (MSVC)
24492450
PA_DPP
24502451
)
24512452

2452-
target_compile_options(SerialPrograms PRIVATE /FAs /FaAssembly/ /MP /W4 /WX /utf-8)
2453+
target_compile_options(SerialPrograms PRIVATE /FAs /FaAssembly/ /MP /W4 /WX /external:anglebrackets /external:W0 /utf-8)
24532454
target_compile_options(SerialPrograms PRIVATE /wd5054) # Deprecated enum arithemtic
24542455
target_compile_options(SerialPrograms PRIVATE /wd4505) # unreferenced local function has been removed
24552456

SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_MultiSwitchProgramSession.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ void MultiSwitchProgramSession::internal_run_program(){
174174
session.audio(),
175175
session.stream_history()
176176
);
177-
handles.back().state().set_console_type(session.console_type());
177+
handles.back().state().set_console_type_user(session.console_type());
178178
}
179179

180180

SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SingleSwitchProgramSession.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ void SingleSwitchProgramSession::internal_run_program(){
143143
m_system.audio(),
144144
m_system.stream_history()
145145
);
146-
env.console.state().set_console_type(m_system.console_type());
146+
env.console.state().set_console_type_user(m_system.console_type());
147147

148148
try{
149149
logger().log("<b>Starting Program: " + identifier() + "</b>");

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_ConsoleTypeDetector.cpp

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,66 +16,62 @@ namespace PokemonAutomation{
1616
namespace NintendoSwitch{
1717

1818

19-
ConsoleTypeDetector_Home::ConsoleTypeDetector_Home(ConsoleState& state, Color color)
20-
: m_state(state)
19+
ConsoleTypeDetector_Home::ConsoleTypeDetector_Home(ConsoleHandle& console, Color color)
20+
: m_console(console)
2121
, m_color(color)
2222
, m_bottom_line(0.10, 0.88, 0.80, 0.03)
2323
{}
2424
void ConsoleTypeDetector_Home::make_overlays(VideoOverlaySet& items) const{
25-
ConsoleType known_state = m_state.console_type();
25+
ConsoleType known_state = m_console.state().console_type();
2626
if (known_state != ConsoleType::Unknown){
2727
return;
2828
}
2929
items.add(m_color, m_bottom_line);
3030
}
3131
ConsoleType ConsoleTypeDetector_Home::detect(const ImageViewRGB32& screen){
32-
ConsoleType known_state = m_state.console_type();
33-
if (known_state != ConsoleType::Unknown){
34-
return known_state;
32+
if (m_console.state().console_type_confirmed()){
33+
return m_console.state().console_type();
3534
}
3635

3736
ImageStats stats = image_stats(extract_box_reference(screen, m_bottom_line));
3837
// cout << "ConsoleTypeDetector: " << stats.stddev.sum() << endl;
38+
ConsoleType state;
3939
if (stats.stddev.sum() < 10){
40-
known_state = ConsoleType::Switch2_Unknown;
40+
state = ConsoleType::Switch2_Unknown;
4141
}else{
42-
known_state = ConsoleType::Switch1;
42+
state = ConsoleType::Switch1;
4343
}
4444

45-
m_state.set_console_type(known_state);
46-
return known_state;
45+
m_console.state().set_console_type(m_console, state);
46+
return state;
4747
}
4848

4949

5050

51-
ConsoleTypeDetector_StartGameUserSelect::ConsoleTypeDetector_StartGameUserSelect(ConsoleState& state, Color color)
52-
: m_state(state)
51+
ConsoleTypeDetector_StartGameUserSelect::ConsoleTypeDetector_StartGameUserSelect(ConsoleHandle& console, Color color)
52+
: m_console(console)
5353
, m_color(color)
5454
, m_bottom_line(0.02, 0.53, 0.96, 0.03)
5555
{}
5656
void ConsoleTypeDetector_StartGameUserSelect::make_overlays(VideoOverlaySet& items) const{
57-
ConsoleType known_state = m_state.console_type();
58-
if (known_state != ConsoleType::Unknown){
59-
return;
60-
}
6157
items.add(m_color, m_bottom_line);
6258
}
6359
ConsoleType ConsoleTypeDetector_StartGameUserSelect::detect(const ImageViewRGB32& screen){
64-
ConsoleType known_state = m_state.console_type();
65-
if (known_state != ConsoleType::Unknown){
66-
return known_state;
60+
if (m_console.state().console_type_confirmed()){
61+
return m_console.state().console_type();
6762
}
6863

6964
ImageStats stats = image_stats(extract_box_reference(screen, m_bottom_line));
7065
// cout << "ConsoleTypeDetector: " << stats.stddev.sum() << endl;
66+
ConsoleType state;
7167
if (stats.stddev.sum() < 10){
72-
known_state = ConsoleType::Switch2_Unknown;
68+
state = ConsoleType::Switch2_Unknown;
7369
}else{
74-
known_state = ConsoleType::Switch1;
70+
state = ConsoleType::Switch1;
7571
}
7672

77-
m_state.set_console_type(known_state);
78-
return known_state;
73+
m_console.state().set_console_type(m_console, state);
74+
return state;
7975
}
8076

8177

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_ConsoleTypeDetector.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "CommonFramework/ImageTools/ImageBoxes.h"
1212
#include "CommonTools/InferenceCallbacks/VisualInferenceCallback.h"
1313
#include "CommonTools/VisualDetector.h"
14-
#include "NintendoSwitch/NintendoSwitch_ConsoleState.h"
14+
#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h"
1515

1616
namespace PokemonAutomation{
1717
namespace NintendoSwitch{
@@ -21,26 +21,26 @@ namespace NintendoSwitch{
2121

2222
class ConsoleTypeDetector_Home{
2323
public:
24-
ConsoleTypeDetector_Home(ConsoleState& state, Color color = COLOR_RED);
24+
ConsoleTypeDetector_Home(ConsoleHandle& console, Color color = COLOR_RED);
2525

2626
void make_overlays(VideoOverlaySet& items) const;
2727
ConsoleType detect(const ImageViewRGB32& screen);
2828

2929
private:
30-
ConsoleState& m_state;
30+
ConsoleHandle& m_console;
3131
Color m_color;
3232
ImageFloatBox m_bottom_line;
3333
};
3434

3535
class ConsoleTypeDetector_StartGameUserSelect{
3636
public:
37-
ConsoleTypeDetector_StartGameUserSelect(ConsoleState& state, Color color = COLOR_RED);
37+
ConsoleTypeDetector_StartGameUserSelect(ConsoleHandle& console, Color color = COLOR_RED);
3838

3939
void make_overlays(VideoOverlaySet& items) const;
4040
ConsoleType detect(const ImageViewRGB32& screen);
4141

4242
private:
43-
ConsoleState& m_state;
43+
ConsoleHandle& m_console;
4444
Color m_color;
4545
ImageFloatBox m_bottom_line;
4646
};

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_HomeMenuDetector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ namespace NintendoSwitch{
1414

1515

1616

17-
HomeMenuDetector::HomeMenuDetector(ConsoleState& state, Color color)
17+
HomeMenuDetector::HomeMenuDetector(ConsoleHandle& console, Color color)
1818
: m_color(color)
19-
, m_console_type(state, color)
19+
, m_console_type(console, color)
2020
, m_bottom_row(0.10, 0.92, 0.10, 0.05)
2121
, m_bottom_icons(0.70, 0.92, 0.28, 0.05)
2222
, m_bottom_left(0.02, 0.70, 0.15, 0.15)

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_HomeMenuDetector.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace NintendoSwitch{
2121

2222
class HomeMenuDetector : public StaticScreenDetector{
2323
public:
24-
HomeMenuDetector(ConsoleState& state, Color color = COLOR_RED);
24+
HomeMenuDetector(ConsoleHandle& console, Color color = COLOR_RED);
2525

2626
virtual void make_overlays(VideoOverlaySet& items) const override;
2727
virtual bool detect(const ImageViewRGB32& screen) override;
@@ -39,10 +39,10 @@ class HomeMenuDetector : public StaticScreenDetector{
3939
class HomeMenuWatcher : public DetectorToFinder<HomeMenuDetector>{
4040
public:
4141
HomeMenuWatcher(
42-
ConsoleState& state,
42+
ConsoleHandle& console,
4343
std::chrono::milliseconds hold_duration = std::chrono::milliseconds(250)
4444
)
45-
: DetectorToFinder("HomeMenuWatcher", hold_duration, state)
45+
: DetectorToFinder("HomeMenuWatcher", hold_duration, console)
4646
{}
4747
};
4848

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_StartGameUserSelectDetector.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ namespace NintendoSwitch{
1919

2020

2121

22-
StartGameUserSelectDetector::StartGameUserSelectDetector(ConsoleState& state, Color color)
23-
: m_type_detector(state, color)
22+
StartGameUserSelectDetector::StartGameUserSelectDetector(ConsoleHandle& console, Color color)
23+
: m_type_detector(console, color)
2424
, m_switch1(color)
2525
, m_switch2(color)
2626
{}
@@ -36,7 +36,7 @@ bool StartGameUserSelectDetector::detect(const ImageViewRGB32& screen){
3636
if (type == ConsoleType::Unknown){
3737
return false;
3838
}
39-
if (type == ConsoleType::Switch1){
39+
if (is_switch1(type)){
4040
return m_switch1.detect(screen);
4141
}
4242
if (is_switch2(type)){

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_StartGameUserSelectDetector.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class StartGameUserSelectDetector_Switch2 : public StaticScreenDetector{
5656

5757
class StartGameUserSelectDetector : public StaticScreenDetector{
5858
public:
59-
StartGameUserSelectDetector(ConsoleState& state, Color color = COLOR_RED);
59+
StartGameUserSelectDetector(ConsoleHandle& console, Color color = COLOR_RED);
6060

6161
virtual void make_overlays(VideoOverlaySet& items) const override;
6262
virtual bool detect(const ImageViewRGB32& screen) override;
@@ -68,8 +68,8 @@ class StartGameUserSelectDetector : public StaticScreenDetector{
6868
};
6969
class StartGameUserSelectWatcher : public DetectorToFinder<StartGameUserSelectDetector>{
7070
public:
71-
StartGameUserSelectWatcher(ConsoleState& state, Color color = COLOR_RED)
72-
: DetectorToFinder("StartGameUserSelectWatcher", std::chrono::milliseconds(250), state, color)
71+
StartGameUserSelectWatcher(ConsoleHandle& console, Color color = COLOR_RED)
72+
: DetectorToFinder("StartGameUserSelectWatcher", std::chrono::milliseconds(250), console, color)
7373
{}
7474
};
7575

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_UpdatePopupDetector.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ namespace NintendoSwitch{
1818

1919

2020

21-
UpdatePopupDetector::UpdatePopupDetector(ConsoleState& state, Color color)
22-
: m_type_detector(state, color)
21+
UpdatePopupDetector::UpdatePopupDetector(ConsoleHandle& console, Color color)
22+
: m_type_detector(console, color)
2323
, m_switch1(color)
2424
, m_switch2(color)
2525
{}
@@ -34,7 +34,7 @@ bool UpdatePopupDetector::detect(const ImageViewRGB32& screen){
3434
if (type == ConsoleType::Unknown){
3535
return false;
3636
}
37-
if (type == ConsoleType::Switch1){
37+
if (is_switch1(type)){
3838
return m_switch1.detect(screen);
3939
}
4040
if (is_switch2(type)){

0 commit comments

Comments
 (0)