Skip to content

Commit d50af7c

Browse files
committed
More controller feature check to run-time.
1 parent 3c17a6a commit d50af7c

File tree

53 files changed

+190
-234
lines changed

Some content is hidden

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

53 files changed

+190
-234
lines changed

SerialPrograms/Source/CommonFramework/Panels/UI/PanelElements.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,19 @@ CollapsibleGroupBox* make_panel_header(
100100
const std::string& display_name,
101101
const std::string& doc_link,
102102
const std::string& description,
103-
const ControllerRequirements& requirements,
103+
const ControllerFeatures& required_features,
104104
FasterIfTickPrecise faster_if_tick_precise
105105
){
106106
CollapsibleGroupBox* header = make_panel_header(parent, display_name, doc_link, description);
107107
QLayout* layout = header->widget()->layout();
108108

109109
std::string text;
110110
do{
111-
if (requirements.contains(ControllerFeature::NintendoSwitch_DateSkip)){
111+
if (required_features.contains(ControllerFeature::NintendoSwitch_DateSkip)){
112112
text = html_color_text("(This program requires advanced RPCs. It requires Serial PABotBase.)", COLOR_RED);
113113
break;
114114
}
115-
if (requirements.contains(ControllerFeature::TickPrecise)){
115+
if (required_features.contains(ControllerFeature::TickPrecise)){
116116
text = html_color_text("(This program requires a tick-precise controller.)", COLOR_PURPLE);
117117
break;
118118
}

SerialPrograms/Source/CommonFramework/Panels/UI/PanelElements.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ CollapsibleGroupBox* make_panel_header(
4040
const std::string& display_name,
4141
const std::string& doc_link,
4242
const std::string& description,
43-
const ControllerRequirements& requirements,
43+
const ControllerFeatures& required_features,
4444
FasterIfTickPrecise faster_if_tick_precise
4545
);
4646

SerialPrograms/Source/CommonTools/StartupChecks/StartProgramChecks.cpp

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
1111
#include "CommonFramework/Tools/VideoStream.h"
1212
#include "CommonTools/VisualDetectors/BlackBorderDetector.h"
13+
#include "Controllers/ControllerCapability.h"
1314
#include "StartProgramChecks.h"
1415

1516
namespace PokemonAutomation{
@@ -21,26 +22,50 @@ void check_feedback(VideoStream& stream, FeedbackType feedback){
2122
return;
2223
}
2324
VideoSnapshot screen = stream.video().snapshot();
24-
if (!screen){
25-
if (feedback == FeedbackType::REQUIRED || feedback == FeedbackType::VIDEO_AUDIO){
26-
throw UserSetupError(stream.logger(), "This program requires video feedback. Please make sure the video is working.");
27-
}
25+
if (screen){
2826
return;
2927
}
28+
if (feedback == FeedbackType::REQUIRED || feedback == FeedbackType::VIDEO_AUDIO){
29+
throw UserSetupError(
30+
stream.logger(),
31+
"This program requires video feedback. Please make sure the video is working."
32+
);
33+
}
3034
}
3135

3236
void check_border(VideoStream& stream){
3337
BlackBorderDetector detector;
3438
VideoOverlaySet set(stream.overlay());
3539
detector.make_overlays(set);
3640
VideoSnapshot screen = stream.video().snapshot();
37-
if (detector.detect(screen)){
38-
throw UserSetupError(stream.logger(), "Black border detected! Please set your screen size to 100% in the TV Settings on your Nintendo Switch.");
41+
if (!detector.detect(screen)){
42+
return;
3943
}
44+
throw UserSetupError(
45+
stream.logger(),
46+
"Black border detected! Please set your screen size to 100% in the TV Settings on your Nintendo Switch."
47+
);
48+
}
49+
4050

51+
52+
void check_controller_features(
53+
Logger& logger,
54+
const ControllerFeatures& capabilities,
55+
const ControllerFeatures& required_features
56+
){
57+
std::string missing_feature = capabilities.contains_all(required_features);
58+
if (missing_feature.empty()){
59+
return;
60+
}
61+
throw UserSetupError(
62+
logger,
63+
"Cannot start program. The controller is missing the feature: " + missing_feature
64+
);
4165
}
4266

4367

4468

69+
4570
}
4671
}

SerialPrograms/Source/CommonTools/StartupChecks/StartProgramChecks.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,26 @@
77
#ifndef PokemonAutomation_CommonTools_StartProgramChecks_H
88
#define PokemonAutomation_CommonTools_StartProgramChecks_H
99

10+
#include <set>
1011
#include "CommonFramework/Globals.h"
1112

1213
namespace PokemonAutomation{
14+
class Logger;
1315
class VideoStream;
16+
class ControllerFeatures;
1417
namespace StartProgramChecks{
1518

1619

1720

1821
void check_feedback(VideoStream& stream, FeedbackType feedback);
1922
void check_border(VideoStream& stream);
2023

24+
void check_controller_features(
25+
Logger& logger,
26+
const ControllerFeatures& capabilities,
27+
const ControllerFeatures& required_features
28+
);
29+
2130

2231

2332
}

SerialPrograms/Source/Controllers/Controller.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class QKeyEvent;
1818
namespace PokemonAutomation{
1919

2020
enum class ControllerType;
21+
class ControllerFeatures;
2122

2223

2324

@@ -42,6 +43,7 @@ class AbstractController{
4243
// Static Information
4344

4445
virtual ControllerType controller_type() const = 0;
46+
virtual const ControllerFeatures& controller_features() const = 0;
4547

4648
// If the controller is polled at a fixed interval, this is that interval.
4749
// Otherwise, returns zero.
@@ -56,7 +58,6 @@ class AbstractController{
5658
// Status
5759

5860
virtual bool is_ready() const = 0;
59-
virtual std::string error_string() const = 0;
6061

6162

6263
public:

SerialPrograms/Source/Controllers/ControllerCapability.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,10 @@ namespace PokemonAutomation{
1111

1212

1313

14-
15-
16-
ControllerRequirements::ControllerRequirements(std::initializer_list<ControllerFeature> args)
17-
: m_features(std::move(args))
18-
, m_sanitizer("ControllerRequirements")
19-
{}
20-
21-
std::string ControllerRequirements::check_compatibility(const std::set<ControllerFeature>& features) const{
14+
std::string ControllerFeatures::contains_all(const ControllerFeatures& features) const{
2215
auto scope_check = m_sanitizer.check_scope();
23-
24-
for (ControllerFeature feature : m_features){
25-
if (features.find(feature) == features.end()){
16+
for (ControllerFeature feature : features.m_features){
17+
if (!contains(feature)){
2618
return CONTROLLER_FEATURE_STRINGS.get_string(feature);
2719
}
2820
}
@@ -32,4 +24,5 @@ std::string ControllerRequirements::check_compatibility(const std::set<Controlle
3224

3325

3426

27+
3528
}

SerialPrograms/Source/Controllers/ControllerCapability.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,23 @@
2727
namespace PokemonAutomation{
2828

2929

30-
31-
class ControllerRequirements{
30+
class ControllerFeatures{
3231
public:
33-
ControllerRequirements(std::initializer_list<ControllerFeature> args);
32+
ControllerFeatures()
33+
: m_sanitizer("ControllerFeatures")
34+
{}
35+
ControllerFeatures(std::initializer_list<ControllerFeature> list)
36+
: m_features(std::move(list))
37+
, m_sanitizer("ControllerFeatures")
38+
{}
3439

3540
bool contains(ControllerFeature feature) const{
3641
return m_features.contains(feature);
3742
}
3843

39-
// Check compatibility. If compatible, returns empty string.
40-
// Otherwise returns one of the missing features.
41-
std::string check_compatibility(const std::set<ControllerFeature>& features) const;
42-
44+
// Returns empty string if this class contains everything in "features".
45+
// Otherwise, returns the name of one of the missing features.
46+
std::string contains_all(const ControllerFeatures& features) const;
4347

4448
private:
4549
std::set<ControllerFeature> m_features;
@@ -49,6 +53,5 @@ class ControllerRequirements{
4953

5054

5155

52-
5356
}
5457
#endif

SerialPrograms/Source/Controllers/ControllerConnection.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#ifndef PokemonAutomation_Controllers_ControllerConnection_H
88
#define PokemonAutomation_Controllers_ControllerConnection_H
99

10-
#include <set>
1110
#include "Common/Cpp/ListenerSet.h"
1211
#include "Common/Cpp/Concurrency/SpinLock.h"
1312
#include "ControllerDescriptor.h"
@@ -18,7 +17,7 @@ namespace PokemonAutomation{
1817

1918
struct ControllerModeStatus{
2019
ControllerType current_controller = ControllerType::None;
21-
std::map<ControllerType, std::set<ControllerFeature>> supported_controllers;
20+
std::map<ControllerType, ControllerFeatures> supported_controllers;
2221
};
2322

2423

SerialPrograms/Source/Controllers/ControllerDescriptor.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ class ControllerDescriptor{
107107
virtual std::unique_ptr<AbstractController> make_controller(
108108
Logger& logger,
109109
ControllerConnection& connection,
110-
ControllerType controller_type,
111-
const ControllerRequirements& requirements
110+
ControllerType controller_type
112111
) const{
113112
return nullptr;
114113
}

SerialPrograms/Source/Controllers/ControllerSession.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ ControllerSession::~ControllerSession(){
4343
ControllerSession::ControllerSession(
4444
Logger& logger,
4545
ControllerOption& option,
46-
const ControllerRequirements& requirements
46+
const ControllerFeatures& required_features
4747
)
4848
: m_logger(logger)
49-
, m_requirements(requirements)
49+
, m_required_features(required_features)
5050
, m_option(option)
5151
, m_controller_type(ControllerType::None)
5252
, m_options_locked(false)
@@ -109,12 +109,6 @@ std::string ControllerSession::status_text() const{
109109
if (!m_connection){
110110
return "<font color=\"red\">No controller selected.</font>";
111111
}
112-
if (m_controller){
113-
std::string error_string = m_controller->error_string();
114-
if (!error_string.empty()){
115-
return error_string;
116-
}
117-
}
118112
return m_connection->status_text();
119113
}
120114
ControllerConnection& ControllerSession::connection() const{
@@ -310,7 +304,7 @@ void ControllerSession::post_connection_ready(
310304
ControllerConnection& connection,
311305
const ControllerModeStatus& mode_status
312306
){
313-
const std::map<ControllerType, std::set<ControllerFeature>>& supported_controllers = mode_status.supported_controllers;
307+
const std::map<ControllerType, ControllerFeatures>& supported_controllers = mode_status.supported_controllers;
314308
if (supported_controllers.empty()){
315309
return;
316310
}
@@ -370,20 +364,14 @@ void ControllerSession::post_connection_ready(
370364
m_controller = m_descriptor->make_controller(
371365
m_logger,
372366
*m_connection,
373-
current_controller,
374-
m_requirements
367+
current_controller
375368
);
376369
}
377370

378371
// Commit all changes.
379372
// cout << "current_controller = " << CONTROLLER_TYPE_STRINGS.get_string(current_controller) << endl;
380373
m_controller_type = current_controller;
381374
ready = m_controller && m_controller->is_ready();
382-
383-
WriteSpinLock lg1(m_message_lock);
384-
if (m_controller){
385-
m_controller_error = m_controller->error_string();
386-
}
387375
}
388376

389377
signal_controller_changed(current_controller, available_controllers);

0 commit comments

Comments
 (0)