Skip to content

Commit e34fdfa

Browse files
authored
remove version of pbf_move_left_joystick_old that uses ticks. Remove TICKS_PER_SECOND (#951)
* rename pbf_move_left_joystick_old to pbf_move_left_joystick_old1, for functions that use ticks. * pbf_move_left_joystick_old: convert ticks to ms * remove version of pbf_move_left_joystick_old that uses ticks. * Remove TICKS_PER_SECOND
1 parent fd534a4 commit e34fdfa

File tree

15 files changed

+75
-80
lines changed

15 files changed

+75
-80
lines changed

SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,6 @@ void pbf_press_dpad_old(ProControllerContext& context, DpadPosition position, ui
2525
void pbf_press_dpad(ProControllerContext& context, DpadPosition position, Milliseconds hold, Milliseconds release){
2626
ssf_press_dpad(context, position, hold + release, hold, 0ms);
2727
}
28-
void pbf_move_left_joystick_old(ProControllerContext& context, uint8_t x, uint8_t y, uint16_t hold_ticks, uint16_t release_ticks){
29-
uint32_t delay = (uint32_t)hold_ticks + release_ticks;
30-
if ((uint16_t)delay == delay){
31-
ssf_press_left_joystick_old(context, x, y, (uint16_t)delay, hold_ticks, 0);
32-
}else{
33-
ssf_press_left_joystick_old(context, x, y, hold_ticks, hold_ticks, 0);
34-
ssf_do_nothing(context, release_ticks * 8ms);
35-
}
36-
}
3728
void pbf_move_left_joystick_old(ProControllerContext& context, uint8_t x, uint8_t y, Milliseconds hold, Milliseconds release){
3829
ssf_press_left_joystick_old(context, x, y, hold + release, hold, 0ms);
3930
}

SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ void pbf_press_dpad (ProControllerContext& context, DpadPosition position, M
5151
// y = 255 : down
5252
// Example: move the joystick fully left: (x, y) = (0, 128)
5353
// move the joystick upper-right: (x, y) = (255, 0)
54-
void pbf_move_left_joystick_old (ProControllerContext& context, uint8_t x, uint8_t y, uint16_t hold_ticks, uint16_t release_ticks);
5554
void pbf_move_left_joystick_old (ProControllerContext& context, uint8_t x, uint8_t y, Milliseconds hold, Milliseconds release);
5655
void pbf_move_left_joystick (ProControllerContext& context, const JoystickPosition& position, Milliseconds hold, Milliseconds release);
5756

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_ControllerButtons.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ namespace PokemonAutomation{
1414
namespace NintendoSwitch{
1515

1616

17-
// Legacy tick type. This comes from the refresh rate of the wired controller.
18-
// One second = 125 ticks. Thus each tick is 8 milliseconds.
19-
constexpr uint16_t TICKS_PER_SECOND = 125;
2017

2118

2219
// Buttons

SerialPrograms/Source/PokemonLA/Programs/General/PokemonLA_MMORoutines.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ std::set<std::string> enter_region_and_read_MMO(
6464
// MMO question marks. So we have to move the map cursor away after we land in the region.
6565
uint8_t map_cursor_move_x = 0;
6666
uint8_t map_cursor_move_y = 0;
67-
const int map_cursor_move_duration = 50;
67+
const Milliseconds map_cursor_move_duration = 400ms;
6868

6969
for(size_t i = 0; i < 5; i++){
7070
if (mmo_name == MMO_NAMES()[i]){
@@ -141,7 +141,7 @@ std::set<std::string> enter_region_and_read_MMO(
141141
}
142142

143143
// Move cursor away so that it does not show a text box that occludes MMO sprites.
144-
pbf_move_left_joystick_old(context, map_cursor_move_x, map_cursor_move_y, map_cursor_move_duration, 30);
144+
pbf_move_left_joystick_old(context, map_cursor_move_x, map_cursor_move_y, map_cursor_move_duration, 240ms);
145145
context.wait_for_all_requests();
146146

147147
// Fix Missions & Requests tab:
@@ -242,7 +242,7 @@ std::set<std::string> enter_region_and_read_MMO(
242242
}
243243

244244
// Move cursor away so that it does not show a text box that occludes MMO sprites.
245-
pbf_move_left_joystick_old(context, map_cursor_move_x, map_cursor_move_y, map_cursor_move_duration, 30);
245+
pbf_move_left_joystick_old(context, map_cursor_move_x, map_cursor_move_y, map_cursor_move_duration, 240ms);
246246
context.wait_for_all_requests();
247247

248248
std::set<std::string> found;

SerialPrograms/Source/PokemonSV/Inference/Overworld/PokemonSV_OliveDetector.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,17 +193,19 @@ ImageFloatBox OliveDetector::align_to_olive(
193193
// }
194194

195195

196-
uint16_t push_duration = std::max(uint16_t((std::abs(diff_from_center) + 0.02) * scale_factor / (olive_y)), uint16_t(15));
196+
uint16_t push_duration_ticks = std::max(uint16_t((std::abs(diff_from_center) + 0.02) * scale_factor / (olive_y)), uint16_t(15));
197+
Milliseconds push_duration = push_duration_ticks * 8ms;
197198
double push_magnitude = 128; // std::max(double(128 / (i + 1)), double(20)); // push less with each iteration/attempt
198199
uint8_t push_x = uint8_t(std::max(std::min(int(128 + (push_direction * push_magnitude)), 255), 0));
199200
stream.log("scale_factor: " + std::to_string(scale_factor));
200-
stream.log("push x: " + std::to_string(push_x) + ", push duration: " + std::to_string(push_duration));
201+
stream.log("push x: " + std::to_string(push_x) + ", push duration: " + std::to_string(push_duration.count()) + "ms");
201202
// pbf_wait(context, 800ms);
202203
uint16_t wait_ticks = 50;
203204
if (std::abs(diff_from_center) < 0.05){
204205
wait_ticks = 100;
205206
}
206-
pbf_move_left_joystick_old(context, push_x, 128, push_duration, wait_ticks);
207+
Milliseconds wait_duration = wait_ticks * 8ms;
208+
pbf_move_left_joystick_old(context, push_x, 128, push_duration, wait_duration);
207209
prev_push_direction = push_direction;
208210

209211

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,12 +1262,12 @@ void AutoStory::test_code(SingleSwitchProgramEnvironment& env, ProControllerCont
12621262
}
12631263

12641264
if (TEST_PBF_LEFT_JOYSTICK){
1265-
pbf_move_left_joystick_old(context, X_MOVE, Y_MOVE, HOLD_TICKS, RELEASE_TICKS);
1265+
pbf_move_left_joystick_old(context, X_MOVE, Y_MOVE, HOLD_TICKS * 8ms, RELEASE_TICKS * 8ms);
12661266
return;
12671267
}
12681268

12691269
if (TEST_PBF_JOYSTICK2){
1270-
pbf_move_left_joystick_old(context, X_MOVE2, Y_MOVE2, HOLD_TICKS2, RELEASE_TICKS2);
1270+
pbf_move_left_joystick_old(context, X_MOVE2, Y_MOVE2, HOLD_TICKS2 * 8ms, RELEASE_TICKS2 * 8ms);
12711271
return;
12721272
}
12731273

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,9 @@ bool confirm_marker_present(
274274

275275
void realign_player(const ProgramInfo& info, VideoStream& stream, ProControllerContext& context,
276276
PlayerRealignMode realign_mode,
277-
uint8_t move_x, uint8_t move_y, uint16_t move_duration
277+
uint8_t move_x, uint8_t move_y, uint16_t move_duration_ticks
278278
){
279+
Milliseconds move_duration = move_duration_ticks * 8ms;
279280
stream.log("Realigning player direction...");
280281
switch (realign_mode){
281282
case PlayerRealignMode::REALIGN_NEW_MARKER:
@@ -287,7 +288,7 @@ void realign_player(const ProgramInfo& info, VideoStream& stream, ProControllerC
287288
});
288289

289290
pbf_press_button(context, BUTTON_ZR, 160ms, 840ms);
290-
pbf_move_left_joystick_old(context, move_x, move_y, move_duration, 1 * TICKS_PER_SECOND);
291+
pbf_move_left_joystick_old(context, move_x, move_y, move_duration, 1000ms);
291292
pbf_press_button(context, BUTTON_A, 160ms, 840ms);
292293
pbf_press_button(context, BUTTON_A, 160ms, 840ms);
293294

@@ -310,7 +311,7 @@ void realign_player(const ProgramInfo& info, VideoStream& stream, ProControllerC
310311
pbf_press_button(context, BUTTON_L, 160ms, 840ms);
311312
return;
312313
case PlayerRealignMode::REALIGN_NO_MARKER:
313-
pbf_move_left_joystick_old(context, move_x, move_y, move_duration, 1 * TICKS_PER_SECOND);
314+
pbf_move_left_joystick_old(context, move_x, move_y, move_duration, 1000ms);
314315
pbf_press_button(context, BUTTON_L, 160ms, 840ms);
315316
return;
316317
}
@@ -334,7 +335,7 @@ void overworld_navigation(
334335
seconds_realign = seconds_timeout;
335336
should_realign = false;
336337
}
337-
uint16_t forward_ticks = seconds_realign * TICKS_PER_SECOND;
338+
Milliseconds forward_duration = seconds_realign * 1000ms;
338339
// WallClock start = current_time();
339340

340341
if (stop_condition == NavigationStopCondition::STOP_MARKER){
@@ -352,8 +353,6 @@ void overworld_navigation(
352353
if (stop_condition == NavigationStopCondition::STOP_MARKER){
353354
callbacks.emplace_back(marker);
354355
}
355-
// uint16_t ticks_passed = std::chrono::duration_cast<std::chrono::milliseconds>(current_time() - start).count() * TICKS_PER_SECOND / 1000;
356-
// forward_ticks = seconds_realign * TICKS_PER_SECOND - ticks_passed;
357356

358357
int ret = run_until<ProControllerContext>(
359358
stream, context,
@@ -365,7 +364,7 @@ void overworld_navigation(
365364
stream, context,
366365
[&](ProControllerContext& context){
367366
if (movement_mode == NavigationMovementMode::CLEAR_WITH_LETS_GO){
368-
walk_forward_while_clear_front_path(info, stream, context, forward_ticks*8ms, y);
367+
walk_forward_while_clear_front_path(info, stream, context, forward_duration, y);
369368
}else{
370369
ssf_press_left_joystick_old(context, x, y, 0ms, Seconds(seconds_realign));
371370
if (movement_mode == NavigationMovementMode::DIRECTIONAL_ONLY){
@@ -1561,10 +1560,10 @@ void move_forward_until_yolo_object_above_min_size(
15611560
const std::string& target_label,
15621561
double min_width, double min_height,
15631562
std::function<void()>&& recovery_action,
1564-
uint16_t forward_ticks,
1563+
Milliseconds forward_duration,
15651564
uint8_t y,
1566-
uint16_t delay_after_forward_move,
1567-
uint16_t delay_after_lets_go
1565+
Milliseconds delay_after_forward_move,
1566+
Milliseconds delay_after_lets_go
15681567
){
15691568
context.wait_for_all_requests();
15701569
pbf_move_left_joystick(context, {0, +1}, 80ms, 400ms); // move forward to align with camera
@@ -1603,7 +1602,7 @@ void move_forward_until_yolo_object_above_min_size(
16031602
return; // stop when the target is above a certain size. i.e. we are close enough to the target.
16041603
}
16051604

1606-
pbf_move_left_joystick_old(context, 128, y, forward_ticks, 0);
1605+
pbf_move_left_joystick_old(context, 128, y, forward_duration, 0ms);
16071606
// pbf_press_button(context, BUTTON_R, 20, delay_after_lets_go);
16081607
// pbf_move_left_joystick(context, 128, y, forward_ticks, delay_after_forward_move);
16091608
});
@@ -1641,11 +1640,11 @@ void move_player_until_yolo_object_detected(
16411640
const std::string& target_label,
16421641
std::function<void()>&& recovery_action,
16431642
uint16_t max_rounds,
1644-
uint16_t forward_ticks,
1643+
Milliseconds forward_duration,
16451644
uint8_t x,
16461645
uint8_t y,
1647-
uint16_t delay_after_forward_move,
1648-
uint16_t delay_after_lets_go
1646+
Milliseconds delay_after_forward_move,
1647+
Milliseconds delay_after_lets_go
16491648
){
16501649
context.wait_for_all_requests();
16511650
pbf_move_left_joystick(context, {0, +1}, 80ms, 400ms); // move forward to align with camera
@@ -1666,7 +1665,7 @@ void move_player_until_yolo_object_detected(
16661665

16671666

16681667

1669-
pbf_move_left_joystick_old(context, x, y, forward_ticks, 0);
1668+
pbf_move_left_joystick_old(context, x, y, forward_duration, 0ms);
16701669
// pbf_press_button(context, BUTTON_R, 20, delay_after_lets_go);
16711670
// pbf_move_left_joystick(context, 128, y, forward_ticks, delay_after_forward_move);
16721671
});
@@ -1697,10 +1696,10 @@ void move_forward_until_yolo_object_not_detected(
16971696
const std::string& target_label,
16981697
size_t times_not_seen_threshold,
16991698
std::function<void()>&& recovery_action,
1700-
uint16_t forward_ticks,
1699+
Milliseconds forward_duration,
17011700
uint8_t y,
1702-
uint16_t delay_after_forward_move,
1703-
uint16_t delay_after_lets_go
1701+
Milliseconds delay_after_forward_move,
1702+
Milliseconds delay_after_lets_go
17041703
){
17051704
VideoOverlaySet overlays(env.console.overlay());
17061705
bool target_visible = true;
@@ -1721,7 +1720,7 @@ void move_forward_until_yolo_object_not_detected(
17211720
}
17221721
}
17231722

1724-
pbf_move_left_joystick_old(context, 128, y, forward_ticks, 0);
1723+
pbf_move_left_joystick_old(context, 128, y, forward_duration, 0ms);
17251724
// pbf_press_button(context, BUTTON_R, 20, delay_after_lets_go);
17261725
// pbf_move_left_joystick(context, 128, y, forward_ticks, delay_after_forward_move);
17271726
});
@@ -1925,20 +1924,21 @@ bool move_player_to_realign_via_yolo(
19251924
// }
19261925
double push_magnitude_scale_factor = 60 / std::sqrt(std::abs(diff));
19271926

1928-
uint16_t push_duration = std::max(uint16_t(std::abs(diff * duration_scale_factor)), uint16_t(8));
1927+
uint16_t push_duration_ticks = std::max(uint16_t(std::abs(diff * duration_scale_factor)), uint16_t(8));
1928+
Milliseconds push_duration = push_duration_ticks * 8ms;
19291929
int16_t push_direction = (diff > 0) ? -1 : 1;
19301930
double push_magnitude = std::max(double(std::abs(diff * push_magnitude_scale_factor)), double(15));
19311931
uint8_t x_push = uint8_t(std::max(std::min(int(128 + (push_direction * push_magnitude)), 255), 0));
19321932

19331933
// env.console.log("object_x: {" + std::to_string(target_box.x) + ", " + std::to_string(target_box.y) + ", " + std::to_string(target_box.width) + ", " + std::to_string(target_box.height) + "}");
19341934
// env.console.log("object_x_pos: " + std::to_string(object_x_pos));
1935-
env.console.log("x push: " + std::to_string(x_push) + ", push duration: " + std::to_string(push_duration));
1935+
env.console.log("x push: " + std::to_string(x_push) + ", push duration: " + std::to_string(push_duration.count()) + "ms");
19361936
if (i == 0){
19371937
pbf_move_left_joystick_old(context, x_push, 128, 80ms, 400ms);
19381938
pbf_press_button(context, BUTTON_R, 160ms, 840ms);
19391939
}
19401940

1941-
pbf_move_left_joystick_old(context, x_push, 128, push_duration, 0);
1941+
pbf_move_left_joystick_old(context, x_push, 128, push_duration, 0ms);
19421942

19431943
});
19441944

SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,10 @@ void move_forward_until_yolo_object_above_min_size(
425425
const std::string& target_label,
426426
double min_width, double min_height,
427427
std::function<void()>&& recovery_action,
428-
uint16_t forward_ticks = 100,
428+
Milliseconds forward_duration = Milliseconds(800),
429429
uint8_t y = 0,
430-
uint16_t delay_after_forward_move = 50,
431-
uint16_t delay_after_lets_go = 105
430+
Milliseconds delay_after_forward_move = Milliseconds(400),
431+
Milliseconds delay_after_lets_go = Milliseconds(840)
432432
);
433433

434434
// walk forward forward_ticks each time
@@ -442,11 +442,11 @@ void move_player_until_yolo_object_detected(
442442
const std::string& target_label,
443443
std::function<void()>&& recovery_action,
444444
uint16_t max_rounds,
445-
uint16_t forward_ticks = 100,
445+
Milliseconds forward_duration = Milliseconds(800),
446446
uint8_t x = 128,
447447
uint8_t y = 0,
448-
uint16_t delay_after_forward_move = 50,
449-
uint16_t delay_after_lets_go = 105
448+
Milliseconds delay_after_forward_move = Milliseconds(400),
449+
Milliseconds delay_after_lets_go = Milliseconds(840)
450450
);
451451

452452
// walk forward forward_ticks each time
@@ -460,10 +460,10 @@ void move_forward_until_yolo_object_not_detected(
460460
const std::string& target_label,
461461
size_t times_not_seen_threshold,
462462
std::function<void()>&& recovery_action,
463-
uint16_t forward_ticks = 100,
463+
Milliseconds forward_duration = Milliseconds(800),
464464
uint8_t y = 0,
465-
uint16_t delay_after_forward_move = 50,
466-
uint16_t delay_after_lets_go = 105
465+
Milliseconds delay_after_forward_move = Milliseconds(400),
466+
Milliseconds delay_after_lets_go = Milliseconds(840)
467467
);
468468

469469
enum class CameraAxis{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ void checkpoint_101(SingleSwitchProgramEnvironment& env, ProControllerContext& c
282282
run_wild_battle_press_A(env.console, context, BattleStopCondition::STOP_OVERWORLD);
283283
},
284284
5,
285-
100,
285+
800ms,
286286
0, 128
287287
);
288288

@@ -435,7 +435,7 @@ void checkpoint_101(SingleSwitchProgramEnvironment& env, ProControllerContext& c
435435
run_wild_battle_press_A(env.console, context, BattleStopCondition::STOP_OVERWORLD);
436436
},
437437
5,
438-
100,
438+
800ms,
439439
0, 128
440440
);
441441

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,8 +672,9 @@ void fly_from_paldea_to_blueberry_entrance(const ProgramInfo& info, VideoStream&
672672

673673
// move cursor to Blueberry academy fast travel point (up-left)
674674
// try different magnitudes of cursor push with each failure.
675-
int push_magnitude = 105 + adjustment_table[numAttempts];
676-
pbf_move_left_joystick_old(context, 64, 64, (uint16_t)push_magnitude, 50);
675+
int push_magnitude_ticks = 105 + adjustment_table[numAttempts];
676+
Milliseconds push_magnitude = push_magnitude_ticks * 8ms;
677+
pbf_move_left_joystick_old(context, 64, 64, push_magnitude, 400ms);
677678

678679
// press A to fly to Blueberry academy
679680
isFlySuccessful = fly_to_overworld_from_map(info, stream, context, true);
@@ -854,8 +855,9 @@ void fly_from_blueberry_to_north_province_3(const ProgramInfo& info, VideoStream
854855

855856
// move cursor up-left
856857
// try different magnitudes of cursor push with each failure.
857-
int push_magnitude = 168 + adjustment_table[numAttempts];
858-
pbf_move_left_joystick_old(context, 112, 0, (uint16_t)push_magnitude, 50);
858+
int push_magnitude_ticks = 168 + adjustment_table[numAttempts];
859+
Milliseconds push_magnitude = push_magnitude_ticks * 8ms;
860+
pbf_move_left_joystick_old(context, 112, 0, push_magnitude, 400ms);
859861

860862
// press A to fly to North province area 3
861863
isFlySuccessful = fly_to_overworld_from_map(info, stream, context, true);

0 commit comments

Comments
 (0)