Skip to content

Commit 94508b0

Browse files
committed
Refactor controller statics. Make date-spam faster for ESP32.
1 parent 165322f commit 94508b0

25 files changed

+222
-147
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,9 @@ file(GLOB MAIN_SOURCES
629629
Source/Controllers/ControllerSession.h
630630
Source/Controllers/ControllerSelectorWidget.cpp
631631
Source/Controllers/ControllerSelectorWidget.h
632+
Source/Controllers/ControllerTypes.h
633+
Source/Controllers/ControllerTypeStrings.cpp
634+
Source/Controllers/ControllerTypeStrings.h
632635
Source/Controllers/KeyboardInput/GlobalQtKeyMap.cpp
633636
Source/Controllers/KeyboardInput/GlobalQtKeyMap.h
634637
Source/Controllers/KeyboardInput/KeyboardInput.cpp

SerialPrograms/SerialPrograms.pro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ SOURCES += \
316316
Source/Controllers/ControllerSelectorWidget.cpp \
317317
Source/Controllers/ControllerSession.cpp \
318318
Source/Controllers/ControllerDescriptor.cpp \
319+
Source/Controllers/ControllerTypeStrings.cpp \
319320
Source/Controllers/KeyboardInput/GlobalQtKeyMap.cpp \
320321
Source/Controllers/KeyboardInput/KeyboardInput.cpp \
321322
Source/Controllers/KeyboardInput/KeyboardStateTracker.cpp \
@@ -1467,6 +1468,8 @@ HEADERS += \
14671468
Source/Controllers/ControllerSelectorWidget.h \
14681469
Source/Controllers/ControllerSession.h \
14691470
Source/Controllers/ControllerDescriptor.h \
1471+
Source/Controllers/ControllerTypeStrings.h \
1472+
Source/Controllers/ControllerTypes.h \
14701473
Source/Controllers/KeyboardInput/GlobalQtKeyMap.h \
14711474
Source/Controllers/KeyboardInput/KeyboardInput.h \
14721475
Source/Controllers/KeyboardInput/KeyboardStateTracker.h \

SerialPrograms/Source/Controllers/Controller.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,45 @@
99

1010
#include <string>
1111
#include "Common/Compiler.h"
12+
#include "Common/Cpp/Time.h"
1213

1314
class QKeyEvent;
1415

1516
namespace PokemonAutomation{
1617

1718

19+
enum class ControllerType;
20+
21+
1822
class AbstractController{
1923
public:
2024
virtual ~AbstractController() = default;
2125

26+
27+
public:
28+
// Static Information
29+
30+
virtual ControllerType controller_type() const = 0;
31+
32+
// If the controller is polled at a fixed interval, this is that interval.
33+
// Otherwise, returns zero.
34+
virtual Milliseconds ticksize() const = 0;
35+
36+
// Some controllers are imprecise. This returns the variation.
37+
// Zero means "tick precise".
38+
virtual Milliseconds timing_variation() const = 0;
39+
40+
41+
public:
42+
// Status
43+
2244
virtual bool is_ready() const = 0;
2345
virtual std::string error_string() const = 0;
2446

47+
2548
public:
2649
// Keyboard Controls
50+
2751
virtual void keyboard_release_all(){}
2852
virtual void keyboard_press(const QKeyEvent& event){}
2953
virtual void keyboard_release(const QKeyEvent& event){}
@@ -32,5 +56,14 @@ class AbstractController{
3256

3357

3458

59+
inline Milliseconds round_up_to_ticksize(Milliseconds ticksize, Milliseconds duration){
60+
if (ticksize == Milliseconds::zero()){
61+
return duration;
62+
}
63+
return (duration + ticksize - Milliseconds(1)) / ticksize * ticksize;
64+
}
65+
66+
67+
3568
}
3669
#endif

SerialPrograms/Source/Controllers/ControllerCapability.cpp

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,13 @@
44
*
55
*/
66

7+
#include "ControllerTypeStrings.h"
78
#include "ControllerCapability.h"
89

910
namespace PokemonAutomation{
1011

1112

1213

13-
const EnumStringMap<ControllerInterface> CONTROLLER_INTERFACE_STRINGS{
14-
{ControllerInterface::None, "None"},
15-
{ControllerInterface::SerialPABotBase, "Serial: PABotBase"},
16-
{ControllerInterface::TcpSysbotBase, "TCP: sys-botbase"},
17-
{ControllerInterface::UsbSysbotBase, "USB: sys-botbase"},
18-
};
19-
20-
const EnumStringMap<ControllerType> CONTROLLER_TYPE_STRINGS{
21-
{ControllerType::None, "None"},
22-
{ControllerType::NintendoSwitch_WiredProController, "Switch: Wired Pro Controller"},
23-
{ControllerType::NintendoSwitch_WirelessProController, "Switch: Wireless Pro Controller"},
24-
{ControllerType::NintendoSwitch_LeftJoycon, "Switch: Left Joycon"},
25-
{ControllerType::NintendoSwitch_RightJoycon, "Switch: Right Joycon"},
26-
};
27-
28-
const EnumStringMap<ControllerFeature> CONTROLLER_FEATURE_STRINGS{
29-
{ControllerFeature::TickPrecise, "TickPrecise"},
30-
{ControllerFeature::QueryTickSize, "QueryTickSize"},
31-
{ControllerFeature::QueryCommandQueueSize, "QueryCommandQueueSize"},
32-
{ControllerFeature::NintendoSwitch_ProController, "NintendoSwitch_ProController"},
33-
{ControllerFeature::NintendoSwitch_DateSkip, "NintendoSwitch_DateSkip"},
34-
};
35-
36-
37-
38-
3914

4015

4116
ControllerRequirements::ControllerRequirements(std::initializer_list<ControllerFeature> args)

SerialPrograms/Source/Controllers/ControllerCapability.h

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,56 +21,12 @@
2121
#include <initializer_list>
2222
#include <string>
2323
#include <set>
24-
#include "Common/Cpp/EnumStringMap.h"
2524
#include "Common/Cpp/LifetimeSanitizer.h"
26-
27-
//#include <iostream>
28-
//using std::cout;
29-
//using std::endl;
25+
#include "ControllerTypes.h"
3026

3127
namespace PokemonAutomation{
3228

3329

34-
enum class FasterIfTickPrecise{
35-
NOT_FASTER,
36-
FASTER,
37-
MUCH_FASTER,
38-
};
39-
40-
41-
42-
enum class ControllerInterface{
43-
None,
44-
SerialPABotBase,
45-
TcpSysbotBase,
46-
UsbSysbotBase,
47-
};
48-
extern const EnumStringMap<ControllerInterface> CONTROLLER_INTERFACE_STRINGS;
49-
50-
51-
enum class ControllerType{
52-
None,
53-
NintendoSwitch_WiredProController,
54-
NintendoSwitch_WirelessProController,
55-
NintendoSwitch_LeftJoycon,
56-
NintendoSwitch_RightJoycon,
57-
};
58-
extern const EnumStringMap<ControllerType> CONTROLLER_TYPE_STRINGS;
59-
60-
61-
enum class ControllerFeature{
62-
TickPrecise,
63-
QueryTickSize,
64-
QueryCommandQueueSize,
65-
NintendoSwitch_ProController,
66-
NintendoSwitch_DateSkip,
67-
};
68-
extern const EnumStringMap<ControllerFeature> CONTROLLER_FEATURE_STRINGS;
69-
70-
71-
72-
73-
7430

7531
class ControllerRequirements{
7632
public:

SerialPrograms/Source/Controllers/ControllerDescriptor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "Common/Cpp/Exceptions.h"
88
#include "Common/Cpp/Json/JsonValue.h"
99
#include "Common/Cpp/Json/JsonObject.h"
10-
#include "ControllerCapability.h"
10+
#include "ControllerTypeStrings.h"
1111
#include "ControllerDescriptor.h"
1212
#include "NullController.h"
1313

SerialPrograms/Source/Controllers/ControllerDescriptor.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <string>
1111
#include <memory>
12+
#include <map>
1213
#include "Common/Cpp/AbstractLogger.h"
1314
//#include "Common/Cpp/Json/JsonObject.h"
1415
#include "ControllerCapability.h"
@@ -113,10 +114,6 @@ class ControllerDescriptor{
113114

114115

115116

116-
#if 0
117-
std::vector<std::shared_ptr<const ControllerDescriptor>>
118-
get_compatible_descriptors(const ControllerRequirements& requirements);
119-
#endif
120117

121118

122119

SerialPrograms/Source/Controllers/ControllerSelectorWidget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "CommonFramework/Globals.h"
1010
#include "CommonFramework/GlobalSettingsPanel.h"
1111
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
12+
#include "Controllers/ControllerTypeStrings.h"
1213
#include "ControllerSelectorWidget.h"
1314

1415
#include "SerialPABotBase/SerialPABotBase_SelectorWidget.h"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* Controller Type Strings
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#include "ControllerTypeStrings.h"
8+
9+
namespace PokemonAutomation{
10+
11+
12+
13+
const EnumStringMap<ControllerInterface> CONTROLLER_INTERFACE_STRINGS{
14+
{ControllerInterface::None, "None"},
15+
{ControllerInterface::SerialPABotBase, "Serial: PABotBase"},
16+
{ControllerInterface::TcpSysbotBase, "TCP: sys-botbase"},
17+
{ControllerInterface::UsbSysbotBase, "USB: sys-botbase"},
18+
};
19+
20+
const EnumStringMap<ControllerType> CONTROLLER_TYPE_STRINGS{
21+
{ControllerType::None, "None"},
22+
{ControllerType::NintendoSwitch_WiredProController, "Switch: Wired Pro Controller"},
23+
{ControllerType::NintendoSwitch_WirelessProController, "Switch: Wireless Pro Controller"},
24+
{ControllerType::NintendoSwitch_LeftJoycon, "Switch: Left Joycon"},
25+
{ControllerType::NintendoSwitch_RightJoycon, "Switch: Right Joycon"},
26+
};
27+
28+
const EnumStringMap<ControllerFeature> CONTROLLER_FEATURE_STRINGS{
29+
{ControllerFeature::TickPrecise, "TickPrecise"},
30+
{ControllerFeature::QueryTickSize, "QueryTickSize"},
31+
{ControllerFeature::QueryCommandQueueSize, "QueryCommandQueueSize"},
32+
{ControllerFeature::NintendoSwitch_ProController, "NintendoSwitch_ProController"},
33+
{ControllerFeature::NintendoSwitch_DateSkip, "NintendoSwitch_DateSkip"},
34+
};
35+
36+
37+
38+
39+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* Controller Type Strings
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_Controllers_ControllerTypeStrings_H
8+
#define PokemonAutomation_Controllers_ControllerTypeStrings_H
9+
10+
#include "Common/Cpp/EnumStringMap.h"
11+
#include "ControllerTypes.h"
12+
13+
namespace PokemonAutomation{
14+
15+
16+
17+
extern const EnumStringMap<ControllerInterface> CONTROLLER_INTERFACE_STRINGS;
18+
extern const EnumStringMap<ControllerType> CONTROLLER_TYPE_STRINGS;
19+
extern const EnumStringMap<ControllerFeature> CONTROLLER_FEATURE_STRINGS;
20+
21+
22+
23+
}
24+
#endif

0 commit comments

Comments
 (0)