Skip to content

Commit a5f2e4f

Browse files
committed
Disable keyboard command logging for sbb2 and sbb3. Enable keyboard FCE parallelism.
1 parent 9ad3b2b commit a5f2e4f

11 files changed

+93
-44
lines changed

SerialPrograms/Source/Controllers/StandardHid/StandardHid_Keyboard.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ class Keyboard::KeyboardManager final : public PokemonAutomation::KeyboardInputC
134134
if (m_controller == nullptr){
135135
return;
136136
}
137-
m_controller->issue_keys(nullptr, 2000ms, 2000ms, 0ms, local_state.keys);
137+
m_controller->issue_keys(
138+
nullptr,
139+
2000ms, 2000ms, 0ms,
140+
std::vector<KeyboardKey>(local_state.keys.begin(), local_state.keys.end())
141+
);
138142
}
139143

140144

SerialPrograms/Source/Controllers/StandardHid/StandardHid_Keyboard.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef PokemonAutomation_StandardHid_Keyboard_H
1010
#define PokemonAutomation_StandardHid_Keyboard_H
1111

12-
#include <set>
12+
#include <vector>
1313
#include "Common/Cpp/Containers/Pimpl.h"
1414
#include "Controllers/Controller.h"
1515
#include "StandardHid_Keyboard_ControllerButtons.h"
@@ -59,7 +59,7 @@ class Keyboard : public AbstractController{
5959
virtual void issue_keys(
6060
const Cancellable* cancellable,
6161
Milliseconds delay, Milliseconds hold, Milliseconds cooldown,
62-
const std::set<KeyboardKey>& keys
62+
const std::vector<KeyboardKey>& keys
6363
) = 0;
6464

6565

SerialPrograms/Source/Controllers/StandardHid/StandardHid_KeyboardWithScheduler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void KeyboardControllerWithScheduler::issue_key(
2323
cancellable->throw_if_cancelled();
2424
}
2525
m_scheduler.issue_to_resource(
26-
schedule, std::make_unique<KeyboardCommand>(key),
26+
schedule, std::make_unique<KeyboardCommand>(key, m_seqnum++),
2727
delay, hold, cooldown
2828
);
2929
}
@@ -41,7 +41,7 @@ void KeyboardControllerWithScheduler::issue_key(
4141
void KeyboardControllerWithScheduler::issue_keys(
4242
const Cancellable* cancellable,
4343
Milliseconds delay, Milliseconds hold, Milliseconds cooldown,
44-
const std::set<KeyboardKey>& keys
44+
const std::vector<KeyboardKey>& keys
4545
){
4646
SuperscalarScheduler::Schedule schedule;
4747
std::lock_guard<std::mutex> lg0(m_issue_lock);
@@ -54,7 +54,7 @@ void KeyboardControllerWithScheduler::issue_keys(
5454
}
5555
for (KeyboardKey key : keys){
5656
m_scheduler.issue_to_resource(
57-
schedule, std::make_unique<KeyboardCommand>(key),
57+
schedule, std::make_unique<KeyboardCommand>(key, m_seqnum++),
5858
WallDuration::zero(), hold, cooldown
5959
);
6060
}

SerialPrograms/Source/Controllers/StandardHid/StandardHid_KeyboardWithScheduler.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,19 @@ struct KeyboardControllerState{
2626

2727
class KeyboardCommand : public SchedulerResource{
2828
public:
29-
KeyboardCommand(KeyboardKey key)
29+
KeyboardCommand(KeyboardKey key, uint64_t seqnum)
3030
: SchedulerResource((size_t)key)
31+
, m_seqnum(seqnum)
3132
{}
3233
KeyboardKey key() const{
3334
return (KeyboardKey)id;
3435
}
36+
uint64_t seqnum() const{
37+
return m_seqnum;
38+
}
39+
40+
private:
41+
uint64_t m_seqnum;
3542
};
3643

3744

@@ -52,8 +59,11 @@ class KeyboardControllerWithScheduler : public PokemonAutomation::ControllerWith
5259
void issue_keys(
5360
const Cancellable* cancellable,
5461
Milliseconds delay, Milliseconds hold, Milliseconds cooldown,
55-
const std::set<KeyboardKey>& keys
62+
const std::vector<KeyboardKey>& keys
5663
);
64+
65+
private:
66+
uint64_t m_seqnum = 0;
5767
};
5868

5969

SerialPrograms/Source/Controllers/StandardHid/StandardHid_Keyboard_SerialPABotBase.cpp

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -109,38 +109,15 @@ void SerialPABotBase_Keyboard::execute_state(
109109
const Cancellable* cancellable,
110110
const SuperscalarScheduler::ScheduleEntry& entry
111111
){
112-
std::set<KeyboardKey> state;
112+
std::map<KeyboardKey, uint64_t> state;
113113
for (const auto& item : entry.state){
114-
KeyboardKey key = static_cast<const KeyboardCommand&>(*item).key();
114+
const KeyboardCommand& key = static_cast<const KeyboardCommand&>(*item);
115115
// cout << (int)key << endl;
116-
state.insert(key);
116+
state.emplace(key.key(), key.seqnum());
117117
}
118118

119119
// cout << "last = " << m_last_state.size() << ", now = " << state.size() << endl;
120120

121-
// Last State: Remove keys that are no longer pressed.
122-
// Current State: Remove keys that were already pressed.
123-
for (auto iterL = m_last_state.begin(); iterL != m_last_state.end();){
124-
auto iterS = state.find(iterL->second);
125-
if (iterS == state.end()){
126-
iterL = m_last_state.erase(iterL);
127-
}else{
128-
state.erase(iterS);
129-
++iterL;
130-
}
131-
}
132-
133-
// Add the new keys to the state.
134-
for (KeyboardKey key : state){
135-
m_last_state.emplace(current_time(), key);
136-
}
137-
138-
// Get a searchable set of all currently pressed keys.
139-
state.clear();
140-
for (const auto& item : m_last_state){
141-
state.insert(item.second);
142-
}
143-
144121
// Add the modifier keys.
145122
pabb_HID_Keyboard_State report = {};
146123
if (state.contains(KeyboardKey::KEY_LEFT_CTRL)){
@@ -176,18 +153,46 @@ void SerialPABotBase_Keyboard::execute_state(
176153
report.modifiers |= 1 << 7;
177154
}
178155

156+
// Last State: Remove keys that are no longer pressed.
157+
// Current State: Remove keys that were already pressed.
158+
for (auto iterL = m_last_state.begin(); iterL != m_last_state.end();){
159+
auto iterS = state.find(iterL->second);
160+
if (iterS == state.end()){
161+
iterL = m_last_state.erase(iterL);
162+
}else{
163+
state.erase(iterS);
164+
++iterL;
165+
}
166+
}
167+
168+
// Add the new keys to the state.
169+
for (const auto& key : state){
170+
m_last_state.emplace(key.second, key.first);
171+
}
172+
173+
// Get a searchable set of all currently pressed keys.
174+
state.clear();
175+
for (const auto& item : m_last_state){
176+
state.emplace(item.second, item.first);
177+
}
178+
179179
// cout << "modifiers = " << (int)report.modifiers << endl;
180180

181181
// Add the remaining keys.
182-
auto iter = state.begin();
182+
auto iter = m_last_state.begin();
183183
for (size_t c = 0; c < 6; c++){
184-
if (iter == state.end()){
184+
if (iter == m_last_state.end()){
185185
break;
186186
}
187-
report.key[c] = *iter;
187+
report.key[c] = iter->second;
188188
++iter;
189189
}
190190

191+
// cout << m_last_state.size() << endl;
192+
if (m_last_state.size() > 6){
193+
m_logger.log("Unable to send more than 6 simultaneous keyboard presses due to HID limitation.", COLOR_RED);
194+
}
195+
191196
// Divide the controller state into smaller chunks that fit into the report
192197
// duration.
193198
Milliseconds time_left = std::chrono::duration_cast<Milliseconds>(entry.duration);

SerialPrograms/Source/Controllers/StandardHid/StandardHid_Keyboard_SerialPABotBase.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class SerialPABotBase_Keyboard final :
9090
virtual void issue_keys(
9191
const Cancellable* cancellable,
9292
Milliseconds delay, Milliseconds hold, Milliseconds cooldown,
93-
const std::set<KeyboardKey>& keys
93+
const std::vector<KeyboardKey>& keys
9494
) override{
9595
KeyboardControllerWithScheduler::issue_keys(cancellable, delay, hold, cooldown, keys);
9696
}
@@ -131,7 +131,7 @@ class SerialPABotBase_Keyboard final :
131131
mutable SpinLock m_error_lock;
132132
std::string m_error_string;
133133

134-
std::multimap<WallClock, KeyboardKey> m_last_state;
134+
std::map<uint64_t, KeyboardKey> m_last_state;
135135

136136
std::unique_ptr<SerialPABotBase::ControllerStatusThread> m_status_thread;
137137
};

SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase3_ProController.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,13 @@ void ProController_SysbotBase3::execute_state(
286286

287287
m_connection.write_data(message);
288288

289+
// Do not log the contents of the command due to privacy concerns.
290+
// (people entering passwords)
291+
#if 0
289292
if (GlobalSettings::instance().LOG_EVERYTHING){
290293
m_logger.log("sys-botbase3: " + message);
291294
}
295+
#endif
292296
}
293297

294298

SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_ProController.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,13 @@ void ProController_SysbotBase::send_diff(
264264
// cout << message << endl;
265265
m_connection.write_data(message);
266266

267+
// Do not log the contents of the command due to privacy concerns.
268+
// (people entering passwords)
269+
#if 0
267270
if (GlobalSettings::instance().LOG_EVERYTHING){
268271
m_logger.log("sys-botbase: " + message);
269272
}
273+
#endif
270274
}
271275

272276

SerialPrograms/Source/NintendoSwitch/Options/NintendoSwitch_CodeEntrySettingsOption.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ DigitEntryTimingsOption::DigitEntryTimingsOption(bool switch2)
7575
"48 ms"
7676
)
7777
, COOLDOWN(
78-
"<b>Hold:</b><br>Do not reuse a button until this long after it is reused.<br>"
78+
"<b>Cooldown:</b><br>Do not reuse a button until this long after it is reused.<br>"
7979
"<font color=\"red\">Controller timing variation will be added to this number.</font>",
8080
LockMode::UNLOCK_WHILE_RUNNING,
8181
"24 ms"
@@ -117,7 +117,7 @@ KeyboardEntryTimingsOption::KeyboardEntryTimingsOption(bool switch2)
117117
"48 ms"
118118
)
119119
, COOLDOWN(
120-
"<b>Hold:</b><br>Do not reuse a button until this long after it is reused.<br>"
120+
"<b>Cooldown:</b><br>Do not reuse a button until this long after it is reused.<br>"
121121
"<font color=\"red\">Controller timing variation will be added to this number.</font>",
122122
LockMode::UNLOCK_WHILE_RUNNING,
123123
"24 ms"
@@ -137,6 +137,11 @@ KeyboardControllerTimingsOption::KeyboardControllerTimingsOption()
137137
LockMode::UNLOCK_WHILE_RUNNING,
138138
GroupOption::EnableMode::ALWAYS_ENABLED, true
139139
)
140+
, PARLLELIZE(
141+
"<b>Parallel Entry:</b><br>Allow characters to be entered in parallel if possible.",
142+
LockMode::UNLOCK_WHILE_RUNNING,
143+
PreloadSettings::instance().DEVELOPER_MODE
144+
)
140145
, TIME_UNIT(
141146
"<b>Time Unit:</b><br>Timesteps should increment in multiples of this unit.",
142147
LockMode::UNLOCK_WHILE_RUNNING,
@@ -145,14 +150,15 @@ KeyboardControllerTimingsOption::KeyboardControllerTimingsOption()
145150
, HOLD(
146151
"<b>Hold:</b><br>Duration to hold each key press down.",
147152
LockMode::UNLOCK_WHILE_RUNNING,
148-
"48 ms"
153+
"40 ms"
149154
)
150155
, COOLDOWN(
151-
"<b>Hold:</b><br>Do not reuse a key until this long after it is reused.",
156+
"<b>Cooldown:</b><br>Do not reuse a key until this long after it is reused.",
152157
LockMode::UNLOCK_WHILE_RUNNING,
153158
"24 ms"
154159
)
155160
{
161+
PA_ADD_OPTION(PARLLELIZE);
156162
PA_ADD_OPTION(TIME_UNIT);
157163
PA_ADD_OPTION(HOLD);
158164
PA_ADD_OPTION(COOLDOWN);

SerialPrograms/Source/NintendoSwitch/Options/NintendoSwitch_CodeEntrySettingsOption.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class KeyboardControllerTimingsOption : public GroupOption{
6060
KeyboardControllerTimingsOption();
6161

6262
public:
63+
BooleanCheckBoxOption PARLLELIZE;
6364
MillisecondsOption TIME_UNIT;
6465
MillisecondsOption HOLD;
6566
MillisecondsOption COOLDOWN;

0 commit comments

Comments
 (0)