Skip to content

Commit e92d6f3

Browse files
committed
Clean up BotBase. Move keyboard controls into the controller itself.
1 parent 5b6fd8a commit e92d6f3

30 files changed

+345
-475
lines changed

ClientSource/Connection/BotBase.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,46 +15,4 @@ namespace PokemonAutomation{
1515

1616

1717

18-
void BotBaseControllerContext::wait_for_all_requests() const{
19-
m_lifetime_sanitizer.check_usage();
20-
m_controller.wait_for_all_requests(this);
21-
}
22-
void BotBaseControllerContext::cancel_now(){
23-
m_lifetime_sanitizer.check_usage();
24-
CancellableScope::cancel(nullptr);
25-
m_controller.stop_all_commands();
26-
}
27-
void BotBaseControllerContext::cancel_lazy(){
28-
m_lifetime_sanitizer.check_usage();
29-
CancellableScope::cancel(nullptr);
30-
m_controller.next_command_interrupt();
31-
}
32-
33-
bool BotBaseControllerContext::cancel(std::exception_ptr exception) noexcept{
34-
m_lifetime_sanitizer.check_usage();
35-
if (CancellableScope::cancel(std::move(exception))){
36-
return true;
37-
}
38-
try{
39-
m_controller.stop_all_commands();
40-
}catch (...){}
41-
return false;
42-
}
43-
44-
bool BotBaseControllerContext::try_issue_request(const BotBaseRequest& request) const{
45-
m_lifetime_sanitizer.check_usage();
46-
return m_controller.try_issue_request(request, this);
47-
}
48-
void BotBaseControllerContext::issue_request(const BotBaseRequest& request) const{
49-
m_lifetime_sanitizer.check_usage();
50-
m_controller.issue_request(request, this);
51-
}
52-
53-
BotBaseMessage BotBaseControllerContext::issue_request_and_wait(const BotBaseRequest& request) const{
54-
m_lifetime_sanitizer.check_usage();
55-
return m_controller.issue_request_and_wait(request, this);
56-
}
57-
58-
59-
6018
}

ClientSource/Connection/BotBase.h

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#define PokemonAutomation_AbstractBotBase_H
99

1010
#include "Common/Cpp/CancellableScope.h"
11-
#include "Common/Cpp/LifetimeSanitizer.h"
1211

1312
namespace PokemonAutomation{
1413

@@ -73,66 +72,6 @@ class BotBaseController{
7372

7473

7574

76-
class ControllerContext0 : public CancellableScope{
77-
public:
78-
virtual void wait_for_all_requests() const = 0;
79-
virtual void cancel_now() = 0;
80-
virtual void cancel_lazy() = 0;
81-
};
82-
83-
84-
// A wrapper for BotBase that allows for asynchronous cancelling.
85-
class BotBaseControllerContext final : public ControllerContext0{
86-
public:
87-
using ControllerType = BotBaseController;
88-
89-
public:
90-
BotBaseControllerContext(BotBaseController& botbase)
91-
: m_controller(botbase)
92-
{}
93-
BotBaseControllerContext(CancellableScope& parent, BotBaseController& botbase)
94-
: m_controller(botbase)
95-
{
96-
attach(parent);
97-
}
98-
virtual ~BotBaseControllerContext(){
99-
detach();
100-
}
101-
102-
103-
virtual void wait_for_all_requests() const override;
104-
105-
operator BotBaseController&() const{ return m_controller; }
106-
BotBaseController& controller() const{ return m_controller; }
107-
108-
// Stop all commands in this context now.
109-
virtual void cancel_now() override;
110-
111-
// Stop the commands in this context, but do it lazily.
112-
// Still will stop new commands from being issued to the device,
113-
// and will tell the device that the next command that is issued
114-
// should replace the command queue.
115-
// This cancel is used when you need continuity from an ongoing
116-
// sequence.
117-
virtual void cancel_lazy() override;
118-
119-
120-
virtual bool cancel(std::exception_ptr exception) noexcept override;
121-
122-
123-
public:
124-
bool try_issue_request(const BotBaseRequest& request) const;
125-
void issue_request(const BotBaseRequest& request) const;
126-
BotBaseMessage issue_request_and_wait(const BotBaseRequest& request) const;
127-
128-
129-
private:
130-
BotBaseController& m_controller;
131-
LifetimeSanitizer m_lifetime_sanitizer;
132-
};
133-
134-
135-
13675

13776

13877
}

ClientSource/Connection/PABotBase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class PABotBase : public BotBaseController, private PABotBaseConnection{
155155
const BotBaseRequest& request, bool silent_remove
156156
);
157157

158+
public:
158159
virtual bool try_issue_request(
159160
const BotBaseRequest& request,
160161
const Cancellable* cancelled
@@ -168,6 +169,7 @@ class PABotBase : public BotBaseController, private PABotBaseConnection{
168169
const Cancellable* cancelled
169170
) override;
170171

172+
private:
171173
BotBaseMessage wait_for_request(uint64_t seqnum);
172174

173175
private:

ClientSource/Libraries/MessageConverter.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -349,15 +349,6 @@ std::string message_to_string(const BotBaseMessage& message){
349349
}
350350

351351

352-
std::string program_name(uint8_t id){
353-
switch (id){
354-
case PABB_PID_UNSPECIFIED: return "Microcontroller Program";
355-
case PABB_PID_PABOTBASE_12KB: return "PABotBase-12KB";
356-
case PABB_PID_PABOTBASE_31KB: return "PABotBase-31KB";
357-
default: return "Unknown ID";
358-
}
359-
}
360-
361352

362353

363354

ClientSource/Libraries/MessageConverter.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ void register_message_converter(uint8_t type, MessageConverter converter);
1616
std::string message_to_string(const BotBaseMessage& message);
1717

1818

19-
std::string program_name(uint8_t id);
20-
2119

2220
}
2321

SerialPrograms/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ file(GLOB MAIN_SOURCES
609609
Source/ComputerPrograms/Framework/ComputerProgramSession.h
610610
Source/ComputerPrograms/Framework/ComputerProgramWidget.cpp
611611
Source/ComputerPrograms/Framework/ComputerProgramWidget.h
612+
Source/Controllers/Controller.h
612613
Source/Controllers/ControllerCapability.h
613614
Source/Controllers/ControllerDescriptor.cpp
614615
Source/Controllers/ControllerDescriptor.h
@@ -622,6 +623,7 @@ file(GLOB MAIN_SOURCES
622623
Source/Controllers/KeyboardInput/GlobalQtKeyMap.h
623624
Source/Controllers/KeyboardInput/KeyboardInput.cpp
624625
Source/Controllers/KeyboardInput/KeyboardInput.h
626+
Source/Controllers/KeyboardInput/KeyboardStateTracker.cpp
625627
Source/Controllers/KeyboardInput/KeyboardStateTracker.h
626628
Source/Controllers/NullController.cpp
627629
Source/Controllers/NullController.h
@@ -802,8 +804,6 @@ file(GLOB MAIN_SOURCES
802804
Source/Kernels/Waterfill/Kernels_Waterfill_Session.h
803805
Source/Kernels/Waterfill/Kernels_Waterfill_Session.tpp
804806
Source/Kernels/Waterfill/Kernels_Waterfill_Types.h
805-
Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Device.cpp
806-
Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Device.h
807807
Source/NintendoSwitch/Commands/NintendoSwitch_Commands_DigitEntry.cpp
808808
Source/NintendoSwitch/Commands/NintendoSwitch_Commands_DigitEntry.h
809809
Source/NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.cpp
@@ -819,8 +819,6 @@ file(GLOB MAIN_SOURCES
819819
Source/NintendoSwitch/Controllers/NintendoSwitch_Controller.h
820820
Source/NintendoSwitch/Controllers/NintendoSwitch_ControllerWithScheduler.cpp
821821
Source/NintendoSwitch/Controllers/NintendoSwitch_ControllerWithScheduler.h
822-
Source/NintendoSwitch/Controllers/NintendoSwitch_KeyboardInput.cpp
823-
Source/NintendoSwitch/Controllers/NintendoSwitch_KeyboardInput.h
824822
Source/NintendoSwitch/Controllers/NintendoSwitch_KeyboardMapping.cpp
825823
Source/NintendoSwitch/Controllers/NintendoSwitch_KeyboardMapping.h
826824
Source/NintendoSwitch/Controllers/NintendoSwitch_SerialPABotBase.cpp

SerialPrograms/SerialPrograms.pro

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ SOURCES += \
316316
Source/Controllers/ControllerDescriptor.cpp \
317317
Source/Controllers/KeyboardInput/GlobalQtKeyMap.cpp \
318318
Source/Controllers/KeyboardInput/KeyboardInput.cpp \
319+
Source/Controllers/KeyboardInput/KeyboardStateTracker.cpp \
319320
Source/Controllers/NullController.cpp \
320321
Source/Controllers/SerialPABotBase/SerialPABotBase.cpp \
321322
Source/Controllers/SerialPABotBase/SerialPABotBase_Handle.cpp \
@@ -399,14 +400,12 @@ SOURCES += \
399400
Source/Kernels/Waterfill/Kernels_Waterfill_Core_64x8_x64_SSE42.cpp \
400401
Source/Kernels/Waterfill/Kernels_Waterfill_Core_64xH_Default.cpp \
401402
Source/Kernels/Waterfill/Kernels_Waterfill_Session.cpp \
402-
Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Device.cpp \
403403
Source/NintendoSwitch/Commands/NintendoSwitch_Commands_DigitEntry.cpp \
404404
Source/NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.cpp \
405405
Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Routines.cpp \
406406
Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.cpp \
407407
Source/NintendoSwitch/Controllers/NintendoSwitch_Controller.cpp \
408408
Source/NintendoSwitch/Controllers/NintendoSwitch_ControllerWithScheduler.cpp \
409-
Source/NintendoSwitch/Controllers/NintendoSwitch_KeyboardInput.cpp \
410409
Source/NintendoSwitch/Controllers/NintendoSwitch_KeyboardMapping.cpp \
411410
Source/NintendoSwitch/Controllers/NintendoSwitch_SerialPABotBase.cpp \
412411
Source/NintendoSwitch/Controllers/NintendoSwitch_VirtualControllerState.cpp \
@@ -1443,6 +1442,7 @@ HEADERS += \
14431442
Source/ComputerPrograms/Framework/ComputerProgramOption.h \
14441443
Source/ComputerPrograms/Framework/ComputerProgramSession.h \
14451444
Source/ComputerPrograms/Framework/ComputerProgramWidget.h \
1445+
Source/Controllers/Controller.h \
14461446
Source/Controllers/ControllerCapability.h \
14471447
Source/Controllers/ControllerConnection.h \
14481448
Source/Controllers/ControllerSelectorWidget.h \
@@ -1546,7 +1546,6 @@ HEADERS += \
15461546
Source/Kernels/Waterfill/Kernels_Waterfill_Session.h \
15471547
Source/Kernels/Waterfill/Kernels_Waterfill_Session.tpp \
15481548
Source/Kernels/Waterfill/Kernels_Waterfill_Types.h \
1549-
Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Device.h \
15501549
Source/NintendoSwitch/Commands/NintendoSwitch_Commands_DigitEntry.h \
15511550
Source/NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h \
15521551
Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Routines.h \
@@ -1556,7 +1555,6 @@ HEADERS += \
15561555
Source/NintendoSwitch/Commands/NintendoSwitch_Messages_Superscalar.h \
15571556
Source/NintendoSwitch/Controllers/NintendoSwitch_Controller.h \
15581557
Source/NintendoSwitch/Controllers/NintendoSwitch_ControllerWithScheduler.h \
1559-
Source/NintendoSwitch/Controllers/NintendoSwitch_KeyboardInput.h \
15601558
Source/NintendoSwitch/Controllers/NintendoSwitch_KeyboardMapping.h \
15611559
Source/NintendoSwitch/Controllers/NintendoSwitch_SerialPABotBase.h \
15621560
Source/NintendoSwitch/Controllers/NintendoSwitch_VirtualControllerState.h \
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* Controller
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_Controllers_Controller_H
8+
#define PokemonAutomation_Controllers_Controller_H
9+
10+
#include "Common/Compiler.h"
11+
12+
class QKeyEvent;
13+
14+
namespace PokemonAutomation{
15+
16+
17+
class Controller{
18+
public:
19+
virtual void keyboard_release_all(){}
20+
virtual void keyboard_press(const QKeyEvent& event){}
21+
virtual void keyboard_release(const QKeyEvent& event){}
22+
};
23+
24+
25+
26+
27+
}
28+
#endif

SerialPrograms/Source/Controllers/ControllerDescriptor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*
55
*/
66

7-
#ifndef PokemonAutomation_Controllers_Controller_H
8-
#define PokemonAutomation_Controllers_Controller_H
7+
#ifndef PokemonAutomation_Controllers_ControllerDescriptor_H
8+
#define PokemonAutomation_Controllers_ControllerDescriptor_H
99

1010
#include <string>
1111
#include <memory>

SerialPrograms/Source/Controllers/ControllerSession.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ std::string ControllerSession::status_text() const{
8383
}
8484
return m_connection->status_text();
8585
}
86+
Controller* ControllerSession::controller() const{
87+
return dynamic_cast<Controller*>(m_connection.get());
88+
}
8689
ControllerConnection& ControllerSession::connection() const{
8790
if (m_connection){
8891
return *m_connection;

0 commit comments

Comments
 (0)