Skip to content

Commit 84ba78f

Browse files
committed
Simplify the capabilities.
1 parent d385c17 commit 84ba78f

21 files changed

+93
-130
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,8 @@ file(GLOB MAIN_SOURCES
632632
Source/Controllers/SuperscalarScheduler.h
633633
Source/Controllers/SerialPABotBase/SerialPABotBase.cpp
634634
Source/Controllers/SerialPABotBase/SerialPABotBase.h
635-
Source/Controllers/SerialPABotBase/SerialPABotBase_Handle.cpp
636-
Source/Controllers/SerialPABotBase/SerialPABotBase_Handle.cpp
637-
Source/Controllers/SerialPABotBase/SerialPABotBase_Handle.h
635+
Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.cpp
636+
Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.h
638637
Source/Integrations/DiscordIntegrationSettings.cpp
639638
Source/Integrations/DiscordIntegrationSettings.h
640639
Source/Integrations/DiscordIntegrationTable.cpp

SerialPrograms/SerialPrograms.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ SOURCES += \
320320
Source/Controllers/KeyboardInput/KeyboardStateTracker.cpp \
321321
Source/Controllers/NullController.cpp \
322322
Source/Controllers/SerialPABotBase/SerialPABotBase.cpp \
323-
Source/Controllers/SerialPABotBase/SerialPABotBase_Handle.cpp \
323+
Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.cpp \
324324
Source/Controllers/SuperscalarScheduler.cpp \
325325
Source/Integrations/DiscordIntegrationSettings.cpp \
326326
Source/Integrations/DiscordIntegrationTable.cpp \
@@ -1454,7 +1454,7 @@ HEADERS += \
14541454
Source/Controllers/KeyboardInput/KeyboardStateTracker.h \
14551455
Source/Controllers/NullController.h \
14561456
Source/Controllers/SerialPABotBase/SerialPABotBase.h \
1457-
Source/Controllers/SerialPABotBase/SerialPABotBase_Handle.h \
1457+
Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.h \
14581458
Source/Controllers/SuperscalarScheduler.h \
14591459
Source/Integrations/DiscordIntegrationSettings.h \
14601460
Source/Integrations/DiscordIntegrationTable.h \

SerialPrograms/Source/Controllers/ControllerCapability.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ namespace PokemonAutomation{
1111

1212
const char* to_string(ControllerType type){
1313
switch (type){
14+
case ControllerType::None:
15+
return "None";
1416
case ControllerType::NintendoSwitch_WiredProController:
1517
return "NintendoSwitch_WiredProController";
1618
case ControllerType::NintendoSwitch_WirelessProController:
@@ -45,4 +47,24 @@ const char* to_string(ControllerFeature feature){
4547

4648

4749

50+
51+
ControllerRequirements::ControllerRequirements(std::initializer_list<ControllerFeature> args)
52+
: m_features(std::move(args))
53+
, m_sanitizer("ControllerRequirements")
54+
{}
55+
56+
std::string ControllerRequirements::check_compatibility(const std::set<ControllerFeature>& features) const{
57+
auto scope_check = m_sanitizer.check_scope();
58+
59+
for (ControllerFeature feature : m_features){
60+
if (features.find(feature) == features.end()){
61+
return to_string(feature);
62+
}
63+
}
64+
return "";
65+
}
66+
67+
68+
69+
4870
}

SerialPrograms/Source/Controllers/ControllerCapability.h

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
#ifndef PokemonAutomation_Controllers_ControllerCapabilities_H
1919
#define PokemonAutomation_Controllers_ControllerCapabilities_H
2020

21+
#include <initializer_list>
2122
#include <string>
2223
#include <set>
23-
#include <map>
2424
#include "Common/Cpp/LifetimeSanitizer.h"
2525

2626
//#include <iostream>
@@ -58,57 +58,17 @@ const char* to_string(ControllerFeature feature);
5858

5959

6060

61-
//
62-
// This class is a double map.
63-
// The first level is keyed on a string representing the interface type. (serial, bluetooth, etc...)
64-
// The second level is a set of features for that interface type.
65-
//
66-
// Programs will specify which interfaces they support and which features are
67-
// required for each interface.
68-
//
69-
// The list of interfaces will filter which connections are shown in the UI
70-
// dropdown. The feature set will be enforced after connecting since you won't
71-
// know the feature set until after talking to the controller.
72-
//
7361
class ControllerRequirements{
7462
public:
75-
ControllerRequirements(std::initializer_list<std::map<std::string, std::set<ControllerFeature>>::value_type> args)
76-
: m_map(std::move(args))
77-
, m_sanitizer("ControllerRequirements")
78-
{}
79-
80-
const std::map<std::string, std::set<ControllerFeature>>& map() const{
81-
auto scope_check = m_sanitizer.check_scope();
82-
return m_map;
83-
}
84-
85-
bool contains_device(const std::string& device) const{
86-
auto scope_check = m_sanitizer.check_scope();
87-
return m_map.find(device) != m_map.end();
88-
}
63+
ControllerRequirements(std::initializer_list<ControllerFeature> args);
8964

9065
// Check compatibility. If compatible, returns empty string.
9166
// Otherwise returns one of the missing features.
92-
std::string check_compatibility(const std::string& device, const std::set<ControllerFeature>& features) const{
93-
auto scope_check = m_sanitizer.check_scope();
94-
95-
auto iter0 = m_map.find(device);
96-
if (iter0 == m_map.end()){
97-
return device;
98-
}
99-
100-
const std::set<ControllerFeature>& required = iter0->second;
101-
for (ControllerFeature feature : required){
102-
if (features.find(feature) == features.end()){
103-
return to_string(feature);
104-
}
105-
}
106-
return "";
107-
}
67+
std::string check_compatibility(const std::set<ControllerFeature>& features) const;
10868

10969

11070
private:
111-
std::map<std::string, std::set<ControllerFeature>> m_map;
71+
std::set<ControllerFeature> m_features;
11272

11373
LifetimeSanitizer m_sanitizer;
11474
};

SerialPrograms/Source/Controllers/ControllerDescriptor.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ std::vector<std::shared_ptr<const ControllerDescriptor>>
4141
get_compatible_descriptors(const ControllerRequirements& requirements){
4242
std::vector<std::shared_ptr<const ControllerDescriptor>> ret;
4343

44+
for (const auto& controller_interface : CONTROLLER_TYPES){
45+
std::vector<std::shared_ptr<const ControllerDescriptor>> list = controller_interface.second->list();
46+
std::move(list.begin(), list.end(), std::back_inserter(ret));
47+
}
48+
49+
#if 0
4450
// Find all the devices in common between the supported list and the
4551
// required list. For each of those, enumerate all the descriptors and
4652
// combine them into a single list.
@@ -51,6 +57,7 @@ get_compatible_descriptors(const ControllerRequirements& requirements){
5157
std::move(list.begin(), list.end(), std::back_inserter(ret));
5258
}
5359
}
60+
#endif
5461

5562
return ret;
5663
}

SerialPrograms/Source/Controllers/ControllerDescriptor.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
namespace PokemonAutomation{
1717

1818
class JsonValue;
19-
class ControllerRequirements;
2019
class AbstractControllerType;
2120
class ControllerDescriptor;
2221
class ControllerConnection;

SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@ const char NintendoSwitch_Basic[] = "NintendoSwitch-SerialPABotBase";
1616

1717

1818
// Defaults
19-
const std::pair<std::string, std::set<ControllerFeature>> OLD_NINTENDO_SWITCH_DEFAULT_REQUIREMENTS{
20-
NintendoSwitch_Basic,
21-
{
22-
ControllerFeature::TickPrecise,
23-
ControllerFeature::NintendoSwitch_ProController,
24-
}
19+
const ControllerRequirements OLD_NINTENDO_SWITCH_DEFAULT_REQUIREMENTS{
20+
ControllerFeature::TickPrecise,
21+
ControllerFeature::NintendoSwitch_ProController,
2522
};
2623

2724

SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extern const char NintendoSwitch_Basic[];
2323

2424

2525
// Defaults
26-
extern const std::pair<std::string, std::set<ControllerFeature>> OLD_NINTENDO_SWITCH_DEFAULT_REQUIREMENTS;
26+
extern const ControllerRequirements OLD_NINTENDO_SWITCH_DEFAULT_REQUIREMENTS;
2727

2828

2929

SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Handle.cpp renamed to SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,20 @@
2222
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
2323
#include "NintendoSwitch/Commands/NintendoSwitch_Messages_Device.h"
2424
#include "SerialPABotBase.h"
25-
#include "SerialPABotBase_Handle.h"
25+
#include "SerialPABotBase_Connection.h"
2626

2727
//#include <iostream>
2828
//using std::cout;
2929
//using std::endl;
3030

3131
namespace PokemonAutomation{
32+
namespace SerialPABotBase{
3233

33-
using namespace SerialPABotBase;
3434

3535

3636

3737

38-
39-
BotBaseHandle::BotBaseHandle(Logger& logger, const QSerialPortInfo* port)
38+
SerialPABotBaseConnection::SerialPABotBaseConnection(Logger& logger, const QSerialPortInfo* port)
4039
: m_logger(logger, GlobalSettings::instance().LOG_EVERYTHING)
4140
, m_port(port)
4241
{
@@ -82,9 +81,9 @@ BotBaseHandle::BotBaseHandle(Logger& logger, const QSerialPortInfo* port)
8281
return;
8382
}
8483

85-
m_status_thread = std::thread(run_with_catch, "BotBaseHandle::thread_body()", [this]{ thread_body(); });
84+
m_status_thread = std::thread(run_with_catch, "SerialPABotBaseConnection::thread_body()", [this]{ thread_body(); });
8685
}
87-
BotBaseHandle::~BotBaseHandle(){
86+
SerialPABotBaseConnection::~SerialPABotBaseConnection(){
8887
m_ready.store(false, std::memory_order_release);
8988
signal_pre_not_ready();
9089
if (m_botbase == nullptr){
@@ -102,7 +101,7 @@ BotBaseHandle::~BotBaseHandle(){
102101
}
103102

104103

105-
void BotBaseHandle::update_with_capabilities(const std::set<ControllerFeature>& capabilities){
104+
void SerialPABotBaseConnection::update_with_capabilities(const std::set<ControllerFeature>& capabilities){
106105
Logger& logger = m_logger;
107106

108107
do{
@@ -132,16 +131,16 @@ void BotBaseHandle::update_with_capabilities(const std::set<ControllerFeature>&
132131

133132

134133

135-
BotBaseController* BotBaseHandle::botbase(){
134+
BotBaseController* SerialPABotBaseConnection::botbase(){
136135
BotBaseController* ret = m_botbase.get();
137136
if (ret == nullptr){
138-
m_logger.log("BotBaseHandle::botbase() called with null botbase...", COLOR_RED);
137+
m_logger.log("SerialPABotBaseConnection::botbase() called with null botbase...", COLOR_RED);
139138
}
140139
return ret;
141140
}
142141

143142

144-
void BotBaseHandle::set_label_text(const std::string& text, Color color){
143+
void SerialPABotBaseConnection::set_label_text(const std::string& text, Color color){
145144
m_label = html_color_text(text, color);
146145

147146
std::string status = m_label;
@@ -153,7 +152,7 @@ void BotBaseHandle::set_label_text(const std::string& text, Color color){
153152
}
154153
set_status(status);
155154
}
156-
void BotBaseHandle::set_uptime_text(const std::string& text, Color color){
155+
void SerialPABotBaseConnection::set_uptime_text(const std::string& text, Color color){
157156
m_uptime = html_color_text(text, color);
158157

159158
std::string status = m_label;
@@ -170,13 +169,13 @@ void BotBaseHandle::set_uptime_text(const std::string& text, Color color){
170169

171170

172171

173-
std::map<ControllerType, std::set<ControllerFeature>> BotBaseHandle::supported_controllers() const{
172+
std::map<ControllerType, std::set<ControllerFeature>> SerialPABotBaseConnection::supported_controllers() const{
174173
std::lock_guard<std::mutex> lg(m_lock);
175174
return m_controllers;
176175
}
177176

178177

179-
std::map<ControllerType, std::set<ControllerFeature>> BotBaseHandle::read_device_specs(){
178+
std::map<ControllerType, std::set<ControllerFeature>> SerialPABotBaseConnection::read_device_specs(){
180179
Logger& logger = m_logger;
181180

182181

@@ -225,7 +224,7 @@ std::map<ControllerType, std::set<ControllerFeature>> BotBaseHandle::read_device
225224

226225

227226

228-
void BotBaseHandle::thread_body(){
227+
void SerialPABotBaseConnection::thread_body(){
229228
using namespace PokemonAutomation;
230229

231230
m_botbase->set_sniffer(&m_logger);
@@ -358,4 +357,5 @@ void BotBaseHandle::thread_body(){
358357

359358

360359

360+
}
361361
}

SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Handle.h renamed to SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
class QSerialPortInfo;
2222

2323
namespace PokemonAutomation{
24+
class PABotBase;
25+
namespace SerialPABotBase{
2426

25-
class PABotBase;
2627

27-
28-
class BotBaseHandle : public ControllerConnection{
28+
class SerialPABotBaseConnection : public ControllerConnection{
2929
public:
30-
BotBaseHandle(Logger& logger, const QSerialPortInfo* port);
31-
~BotBaseHandle();
30+
SerialPABotBaseConnection(Logger& logger, const QSerialPortInfo* port);
31+
~SerialPABotBaseConnection();
3232

3333
void update_with_capabilities(const std::set<ControllerFeature>& capabilities);
3434

@@ -69,5 +69,6 @@ class BotBaseHandle : public ControllerConnection{
6969

7070

7171

72+
}
7273
}
7374
#endif

0 commit comments

Comments
 (0)