Skip to content

Commit 63f28aa

Browse files
committed
Delay replace command and merge with command because TCP is shit.
1 parent 6a58549 commit 63f28aa

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ProController_SysbotBase3::ProController_SysbotBase3(
2828
, ControllerWithScheduler(logger)
2929
, m_connection(connection)
3030
, m_stopping(false)
31+
, m_pending_replace(false)
3132
, m_next_seqnum(1)
3233
, m_next_expected_seqnum_ack(1)
3334
{
@@ -76,10 +77,14 @@ void ProController_SysbotBase3::replace_on_next_command(){
7677
uint64_t queued = m_next_seqnum - m_next_expected_seqnum_ack;
7778
m_next_expected_seqnum_ack = m_next_seqnum;
7879

80+
m_pending_replace = true;
81+
82+
#if 0
7983
m_connection.write_data("cqReplaceOnNext\r\n");
8084
if (GlobalSettings::instance().LOG_EVERYTHING){
8185
m_logger.log("sys-botbase3: cqReplaceOnNext");
8286
}
87+
#endif
8388

8489
this->clear_on_next();
8590
m_cv.notify_all();
@@ -229,6 +234,12 @@ void ProController_SysbotBase3::push_state(const Cancellable* cancellable, WallD
229234
right_y = JoystickTools::linear_float_to_s16(fy);
230235
}
231236

237+
std::string message;
238+
if (m_pending_replace){
239+
m_pending_replace = false;
240+
message += "cqReplaceOnNext\r\n";
241+
}
242+
232243
std::unique_lock<std::mutex> lg(m_state_lock, std::adopt_lock_t());
233244

234245
// Wait until there is space.
@@ -254,10 +265,12 @@ void ProController_SysbotBase3::push_state(const Cancellable* cancellable, WallD
254265
command.state.right_joystick_x = right_x;
255266
command.state.right_joystick_y = right_y;
256267

257-
std::string message;
258-
message.resize(64);
259-
command.write_to_hex(message.data());
260-
message = "cqControllerState " + message + "\r\n";
268+
{
269+
std::string command_message;
270+
command_message.resize(64);
271+
command.write_to_hex(command_message.data());
272+
message += "cqControllerState " + command_message + "\r\n";
273+
}
261274

262275
m_connection.write_data(message);
263276

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ class ProController_SysbotBase3 final :
227227
SysbotBase::TcpSysbotBase_Connection& m_connection;
228228

229229
bool m_stopping;
230+
bool m_pending_replace;
230231
uint64_t m_next_seqnum;
231232
uint64_t m_next_expected_seqnum_ack;
232233

0 commit comments

Comments
 (0)