Skip to content

Commit 0c66895

Browse files
committed
Fix Game -> Home delay.
1 parent 0f53d58 commit 0c66895

24 files changed

+85
-79
lines changed

SerialPrograms/Source/CommonFramework/Globals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace PokemonAutomation{
2525
const bool IS_BETA_VERSION = true;
2626
const int PROGRAM_VERSION_MAJOR = 0;
2727
const int PROGRAM_VERSION_MINOR = 51;
28-
const int PROGRAM_VERSION_PATCH = 7;
28+
const int PROGRAM_VERSION_PATCH = 8;
2929

3030
const std::string PROGRAM_VERSION_BASE =
3131
"v" + std::to_string(PROGRAM_VERSION_MAJOR) +

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_ProController.h

Lines changed: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -90,54 +90,56 @@ class ProController : public AbstractController{
9090
public:
9191
//
9292
// Cancellation
93-
// These are thread-safe with everything.
93+
//
94+
// These functions will return immediately and are thread-safe with
95+
// everything. The intended use-case is for an inference thread to cancel
96+
// a running sequence of commands on a program thread.
9497
//
9598

9699
// Cancel all commands. This returns the controller to the neutral button
97100
// state and clears the command queue.
101+
// This does not wait for the commands to finish cancelling. This is an
102+
// asynchronous function that merely initiates the cancellation process.
98103
virtual void cancel_all_commands() = 0;
99104

100-
// Declare that the next command will replace the current command stream
101-
// with no gaps.
105+
// Same as "cancel_all_commands()", but instead of cancelling the stream,
106+
// it lets it keep running. Then on the next command issued after this
107+
// cancel, it will atomically replace the stream without gapping.
108+
// This lets you do stuff like suddenly change joystick movement in
109+
// response to inference while simultaneously holding a button without
110+
// ever releasing it during the transition.
102111
virtual void replace_on_next_command() = 0;
103112

104113

105114
public:
106115
//
107-
// Basic Commands
116+
// Commands
117+
//
118+
// Commands are actions like button presses or joystick movements that are
119+
// eventually sent to the console.
120+
//
121+
// All commands are prefixed with "issue_".
122+
// Commands are not thread-safe with other commands.
123+
// Commands are thread-safe with the cancellation functions above.
108124
//
109-
// Commands not thread-safe with other commands. But they are thread-safe
110-
// with the cancellation functions above.
125+
// Commands are asynchronous. When you call a command function on this,
126+
// class it gets enqueued into a FIFO and immediately returns. It will only
127+
// block if the FIFO is full.
111128
//
112-
// As of this writing, all implementations are thread-safe enough that
113-
// they will neither crash nor enter an invalid state with concurrent
114-
// commands. But the implied queuing semantics means that parallelizing
115-
// commands will not do what you want it to do.
129+
// If a command is called with a cancelled "cancellable" parameter, it will
130+
// throw an OperationCancelledException.
131+
// If a cancellation happens while you are inside a command function, it
132+
// will immediately stop and throw an OperationCancelledException.
116133
//
117134

118135
// Wait for all unfinished commands to finish. This will also wait out
119136
// hanging commands including their cooldown periods.
137+
// This is not a true command function as it waits for the entire queue to
138+
// empty out rather than entering itself into the queue.
139+
// If a cancellation happens inside this function, it will immediately
140+
// throw an OperationCancelledException.
120141
virtual void wait_for_all(const Cancellable* cancellable) = 0;
121142

122-
//
123-
// All commands are enqueued into a FIFO that the controller will execute
124-
// in order preserving the timing semantics as closely as possible
125-
// irrespective of the latencies between the host and the device.
126-
//
127-
// For wired controller emulation, the timings will be preserved exactly as
128-
// long as the FIFO never completely empties out.
129-
//
130-
// For wireless controllers (Joy Con), while we do not have an
131-
// implementation of this at this time, we do not expect it to be able to
132-
// preserve timing.
133-
//
134-
// Whether a controller supports exact timings is controlled by the feature
135-
// flag "TickPrecise".
136-
//
137-
138-
// The following functions are asynchronous. They will return immediately
139-
// if the command can be enqueued into the FIFO. Otherwise, they will block
140-
// until there is space in the FIFO.
141143

142144
// Temporary for refactor: Send custom requests for PABotBase's advanced
143145
// RPCs.
@@ -167,7 +169,7 @@ class ProController : public AbstractController{
167169
// exposes.
168170
//
169171
// If the button is busy (due to still being held down or is waiting out
170-
// the cooldown), the command will block until the button is ready.
172+
// the cooldown), the command will wait until the button is ready.
171173
//
172174
// By setting (delay < hold), the command will "return" early and move onto
173175
// the next command while the button is still being held down.
@@ -183,6 +185,14 @@ class ProController : public AbstractController{
183185
// Users are responsible for understanding the controller state and
184186
// managing the timeline/scheduling.
185187
//
188+
// It is important to remember that the "timeline" here is the timeline
189+
// being fed to the Switch. Thus the timing parameters written in the C++
190+
// code here is what you will get on the console (or as close as possible).
191+
//
192+
// The actual calls to the methods in the class will return or block in an
193+
// unspecified manner as they merely enqueue into a FIFO which is then
194+
// "replayed" to the Switch in an implementation-dependent manner.
195+
//
186196

187197
// Tell the scheduler to wait for all pending commands to finish
188198
// (including cooldowns) before executing further instructions.
@@ -229,13 +239,12 @@ class ProController : public AbstractController{
229239
//
230240
// This command will wait until the controller is fully idle (including
231241
// cooldowns) before it starts. This ensures that everything is issued
232-
// simultaneously.
242+
// simultaneously. In other words, there is an implied call to
243+
// "issue_barrier()" before executing the state.
233244
//
234245
// The sole purpose of this function is for keyboard commands.
235-
// While it's technically possible to implement any button overlapping
236-
// sequence with this, doing so this way can lead to very inefficient
237-
// serial bandwidth usage if buttons are being rapidly pressed and released
238-
// in an arbitrary manner that leads to constant state changes.
246+
// For programs, it is easier to use the individual button/joystick
247+
// functions above.
239248
//
240249
// If we need to support new Switch controller functionality
241250
// (such as Joycon gyro or new stuff in Switch 2), we can simply add
@@ -255,14 +264,13 @@ class ProController : public AbstractController{
255264
//
256265
// High speed Macros
257266
//
258-
// It is currently unclear if these can be properly executed over wireless.
259-
// If they can't, then it remains to be decided if we should gate these
260-
// behind a feature flag or if the controller should slow them down to make
261-
// them work properly.
267+
// Be mindful when calling these mashing functions on a tick imprecise
268+
// controller. You can guarantee that some (most) of them will be dropped.
262269
//
263-
// It is not advised to call these if you are micromanaging with tick-level
264-
// precision since the exact timing characteristics and button selection
265-
// is not specified and context-dependent.
270+
// Even if you are on a tick-precise controller, it is not advised to call
271+
// these if you are micromanaging with tick-level granularity. The exact
272+
// timing characteristics and button selection is not specified and may be
273+
// context and implementation-dependent.
266274
//
267275

268276
// Mash a button as quickly as possible.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,6 @@ void ProController_SysbotBase::thread_body(){
353353

354354
// Waking up from idle.
355355
if (!m_is_active){
356-
// Waking up from idle.
357356
m_is_active = true;
358357
m_queue_start_time = now;
359358

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class ProController_SysbotBase : public ProControllerWithScheduler{
2424
using ContextType = ProControllerContext;
2525

2626
static constexpr size_t QUEUE_SIZE = 4;
27-
static constexpr std::chrono::microseconds EARLY_WAKE_SPIN = std::chrono::microseconds(2000);
2827

2928

3029
public:

SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Navigation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void home_to_date_time(ProControllerContext& context, bool to_date_change, bool
6767
}else{
6868
// Slow version for tick-imprecise controllers.
6969

70-
ssf_do_nothing(context, 1500ms);
70+
// ssf_do_nothing(context, 1500ms);
7171

7272
ssf_issue_scroll_ptv(context, SSF_SCROLL_RIGHT);
7373
ssf_issue_scroll_ptv(context, SSF_SCROLL_RIGHT);

SerialPrograms/Source/PokemonSV/PokemonSV_Settings.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ GameSettings& GameSettings::instance(){
2424
GameSettings::GameSettings()
2525
: BatchOption(LockMode::LOCK_WHILE_RUNNING)
2626
, m_menu_navigation("<font size=4><b>Menu Navigation Timings:</b></font>")
27-
, GAME_TO_HOME_DELAY0(
27+
, GAME_TO_HOME_DELAY1(
2828
"<b>Game to Home Delay:</b><br>Delay from pressing home to entering the the Switch home menu.",
2929
LockMode::LOCK_WHILE_RUNNING,
30-
"100 ms"
30+
"1000 ms"
3131
)
3232
, m_start_game_timings("<font size=4><b>Start Game Timings:</b></font>")
3333
, START_GAME_MASH0(
@@ -79,7 +79,7 @@ GameSettings::GameSettings()
7979
1000, 0, 48000
8080
)
8181
{
82-
PA_ADD_OPTION(GAME_TO_HOME_DELAY0);
82+
PA_ADD_OPTION(GAME_TO_HOME_DELAY1);
8383
PA_ADD_STATIC(m_start_game_timings);
8484
PA_ADD_OPTION(START_GAME_MASH0);
8585
PA_ADD_OPTION(START_GAME_WAIT0);

SerialPrograms/Source/PokemonSV/PokemonSV_Settings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class GameSettings : public BatchOption{
2323
static GameSettings& instance();
2424

2525
SectionDividerOption m_menu_navigation;
26-
MillisecondsOption GAME_TO_HOME_DELAY0;
26+
MillisecondsOption GAME_TO_HOME_DELAY1;
2727

2828
SectionDividerOption m_start_game_timings;
2929
MillisecondsOption START_GAME_MASH0;

SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_11.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ void checkpoint_26(
237237
context.wait_for_all_requests();
238238

239239
// change the time of day: close game, change time to 5:45 am.
240-
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
240+
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY1);
241241
change_date(env, context, {2025, 1, 1, 5, 45, 0});
242242
reset_game_from_home(env.program_info(), env.console, context);
243243

@@ -566,7 +566,7 @@ void checkpoint_26(
566566
mash_button_till_overworld(env.console, context, BUTTON_A, 360);
567567

568568
// fix the time
569-
pbf_press_button(context, BUTTON_HOME, 80ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
569+
pbf_press_button(context, BUTTON_HOME, 80ms, GameSettings::instance().GAME_TO_HOME_DELAY1);
570570
home_to_date_time(context, false, false);
571571
pbf_press_button(context, BUTTON_A, 20, 105);
572572
pbf_press_button(context, BUTTON_A, 20, 105);

SerialPrograms/Source/PokemonSV/Programs/Farming/PokemonSV_AuctionFarmer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,17 @@ void AuctionFarmer::reset_auctions(SingleSwitchProgramEnvironment& env, ProContr
178178
try{
179179
if (do_full_reset){
180180
if (year == MAX_YEAR){
181-
pbf_press_button(context, BUTTON_HOME, 80ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
181+
pbf_press_button(context, BUTTON_HOME, 80ms, GameSettings::instance().GAME_TO_HOME_DELAY1);
182182
PokemonSwSh::home_roll_date_enter_game_autorollback(env.console, context, year);
183183
}
184184
save_game_from_overworld(env.program_info(), env.console, context);
185185

186-
pbf_press_button(context, BUTTON_HOME, 80ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
186+
pbf_press_button(context, BUTTON_HOME, 80ms, GameSettings::instance().GAME_TO_HOME_DELAY1);
187187
PokemonSwSh::home_roll_date_enter_game_autorollback(env.console, context, year);
188188
}
189189
pbf_wait(context, 1 * TICKS_PER_SECOND);
190190

191-
pbf_press_button(context, BUTTON_HOME, 80ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
191+
pbf_press_button(context, BUTTON_HOME, 80ms, GameSettings::instance().GAME_TO_HOME_DELAY1);
192192
context.wait_for_all_requests();
193193
reset_game_from_home(env.program_info(), env.console, context, TICKS_PER_SECOND);
194194
}catch (OperationFailedException& e){

SerialPrograms/Source/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void BBQSoloFarmer::program(SingleSwitchProgramEnvironment& env, ProControllerCo
144144
env.update_stats();
145145

146146
if (BBQ_OPTIONS.FIX_TIME_WHEN_DONE){
147-
pbf_press_button(context, BUTTON_HOME, 80ms, GameSettings::instance().GAME_TO_HOME_DELAY0);
147+
pbf_press_button(context, BUTTON_HOME, 80ms, GameSettings::instance().GAME_TO_HOME_DELAY1);
148148
home_to_date_time(context, false, false);
149149
pbf_press_button(context, BUTTON_A, 20, 105);
150150
pbf_press_button(context, BUTTON_A, 20, 105);

0 commit comments

Comments
 (0)