Skip to content

Commit 4d59f8f

Browse files
committed
Make Button an enum. Replace some uses of pbf_controller_state with ssf.
1 parent 3936a49 commit 4d59f8f

File tree

10 files changed

+36
-44
lines changed

10 files changed

+36
-44
lines changed

SerialPrograms/Source/Integrations/IntegrationsAPI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void pai_stop_program(DllSafeString& error, uint64_t program_id){
106106
}
107107

108108
void pai_nsw_press_button(DllSafeString& error, uint64_t console_id, uint16_t button, uint16_t ticks){
109-
error = ProgramTracker::instance().nsw_press_button(console_id, button, ticks);
109+
error = ProgramTracker::instance().nsw_press_button(console_id, (NintendoSwitch::Button)button, ticks);
110110
}
111111
void pai_nsw_press_dpad(DllSafeString& error, uint64_t console_id, uint8_t position, uint16_t ticks){
112112
error = ProgramTracker::instance().nsw_press_dpad(console_id, (NintendoSwitch::DpadPosition)position, ticks);

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_KeyboardMapping.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ std::unique_ptr<EditableTableRow> KeyMapTableRow::clone() const{
7575
}
7676
ControllerDeltas KeyMapTableRow::snapshot() const{
7777
return {
78-
.buttons = buttons,
78+
.buttons = (Button)buttons.current_value(),
7979
.dpad_x = dpad_x,
8080
.dpad_y = dpad_y,
8181
.left_x = left_stick_x,

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_SerialPABotBase.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,11 @@ SwitchController_SerialPABotBase::SwitchController_SerialPABotBase(
180180
}
181181

182182
void SwitchController_SerialPABotBase::push_state(const Cancellable* cancellable, WallDuration duration){
183-
uint16_t buttons = 0;
183+
Button buttons = BUTTON_NONE;
184184
for (size_t c = 0; c < 14; c++){
185-
buttons |= m_buttons[c].is_busy() ? ((uint16_t)1 << c) : 0;
185+
buttons |= m_buttons[c].is_busy()
186+
? (Button)((uint16_t)1 << c)
187+
: BUTTON_NONE;
186188
}
187189

188190
uint8_t left_x = 128;

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_VirtualControllerState.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ using namespace std::chrono_literals;
2222

2323

2424
void SwitchControllerState::clear(){
25-
buttons = 0;
25+
buttons = BUTTON_NONE;
2626
dpad = DPAD_NONE;
2727
left_x = 128;
2828
left_y = 128;

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_VirtualControllerState.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class SwitchControllerState : public ControllerState{
2525
virtual bool send_to_controller(ControllerSession& controller) const override;
2626

2727
public:
28-
Button buttons = 0;
28+
Button buttons = BUTTON_NONE;
2929
DpadPosition dpad = DPAD_NONE;
3030
uint8_t left_x = 128;
3131
uint8_t left_y = 128;
@@ -35,7 +35,7 @@ class SwitchControllerState : public ControllerState{
3535

3636

3737
struct ControllerDeltas{
38-
Button buttons = 0;
38+
Button buttons = BUTTON_NONE;
3939
int dpad_x = 0;
4040
int dpad_y = 0;
4141
int left_x = 0;

SerialPrograms/Source/PokemonBDSP/Programs/Eggs/PokemonBDSP_EggRoutines.cpp

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
8+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
89
#include "PokemonBDSP/PokemonBDSP_Settings.h"
910
#include "PokemonBDSP/Programs/PokemonBDSP_GameNavigation.h"
1011
#include "PokemonBDSP_EggRoutines.h"
@@ -16,7 +17,6 @@ namespace PokemonBDSP{
1617

1718
void egg_spin(SwitchControllerContext& context, uint16_t duration){
1819
for (uint16_t c = 0; c < duration; c += 42){
19-
#if 1
2020
pbf_move_left_joystick(context, 0, 0, 5, 0);
2121
pbf_move_left_joystick(context, 128, 0, 5, 0);
2222
pbf_move_left_joystick(context, 255, 0, 5, 0);
@@ -25,28 +25,19 @@ void egg_spin(SwitchControllerContext& context, uint16_t duration){
2525
pbf_move_left_joystick(context, 128, 255, 5, 0);
2626
pbf_move_left_joystick(context, 0, 255, 6, 0);
2727
pbf_move_left_joystick(context, 0, 128, 6, 0);
28-
#else
29-
pbf_controller_state(context, 0, DPAD_NONE, 0, 0, 128, 128, 5);
30-
pbf_controller_state(context, 0, DPAD_NONE, 128, 0, 128, 128, 5);
31-
pbf_controller_state(context, 0, DPAD_NONE, 255, 0, 128, 128, 5);
32-
pbf_controller_state(context, 0, DPAD_NONE, 255, 128, 128, 128, 5);
33-
pbf_controller_state(context, 0, DPAD_NONE, 255, 255, 128, 128, 5);
34-
pbf_controller_state(context, 0, DPAD_NONE, 128, 255, 128, 128, 5);
35-
pbf_controller_state(context, 0, DPAD_NONE, 0, 255, 128, 128, 6);
36-
pbf_controller_state(context, 0, DPAD_NONE, 0, 128, 128, 128, 6);
37-
#endif
3828
}
3929
}
4030
void egg_spin_with_A(SwitchControllerContext& context, uint16_t duration){
4131
for (uint16_t c = 0; c < duration; c += 42){
42-
pbf_controller_state(context, BUTTON_ZL, DPAD_NONE, 0, 0, 128, 128, 5);
43-
pbf_controller_state(context, 0, DPAD_NONE, 128, 0, 128, 128, 5);
44-
pbf_controller_state(context, 0, DPAD_NONE, 255, 0, 128, 128, 5);
45-
pbf_controller_state(context, 0, DPAD_NONE, 255, 128, 128, 128, 5);
46-
pbf_controller_state(context, 0, DPAD_NONE, 255, 255, 128, 128, 5);
47-
pbf_controller_state(context, 0, DPAD_NONE, 128, 255, 128, 128, 5);
48-
pbf_controller_state(context, 0, DPAD_NONE, 0, 255, 128, 128, 6);
49-
pbf_controller_state(context, 0, DPAD_NONE, 0, 128, 128, 128, 6);
32+
ssf_press_button(context, BUTTON_ZL, 0, 10);
33+
pbf_move_left_joystick(context, 0, 0, 5, 0);
34+
pbf_move_left_joystick(context, 128, 0, 5, 0);
35+
pbf_move_left_joystick(context, 255, 0, 5, 0);
36+
pbf_move_left_joystick(context, 255, 128, 5, 0);
37+
pbf_move_left_joystick(context, 255, 255, 5, 0);
38+
pbf_move_left_joystick(context, 128, 255, 5, 0);
39+
pbf_move_left_joystick(context, 0, 255, 6, 0);
40+
pbf_move_left_joystick(context, 0, 128, 6, 0);
5041
}
5142
}
5243

SerialPrograms/Source/PokemonSV/Programs/Eggs/PokemonSV_EggRoutines.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,9 @@ void do_egg_cycle_motion(
127127
// hatch circle:
128128
// Left joystick forward, right joystick right
129129
// click left joystick
130-
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE,
131-
128, 0, 255, 128, 20);
132-
pbf_controller_state(context, 0, DPAD_NONE, 128, 0, 255, 128, 20);
133-
for(int j = 0; j < 600; j++){
134-
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE,
135-
128, 0, 255, 128, TICKS_PER_SECOND);
136-
}
130+
ssf_press_left_joystick(context, 128, 0, 0ms, std::chrono::minutes(10));
131+
ssf_press_right_joystick(context, 255, 128, 0ms, std::chrono::minutes(10));
132+
pbf_press_button(context, BUTTON_LCLICK, std::chrono::minutes(10), 0ms);
137133
},
138134
{dialog}
139135
);
@@ -410,7 +406,7 @@ void check_basket_to_collect_eggs(
410406
){
411407
bool checked = false;
412408
size_t consecutive_nothing = 0;
413-
Button last_prompt = 0;
409+
Button last_prompt = BUTTON_NONE;
414410
bool pending_refuse = false;
415411

416412
WallClock start = current_time();
@@ -446,7 +442,7 @@ void check_basket_to_collect_eggs(
446442
case 0:
447443
stream.log("Detected no dialog.");
448444
consecutive_nothing++;
449-
last_prompt = 0;
445+
last_prompt = BUTTON_NONE;
450446
if (consecutive_nothing >= 10){
451447
dump_image_and_throw_recoverable_exception(
452448
info, stream, "BasketNotFound",
@@ -463,7 +459,7 @@ void check_basket_to_collect_eggs(
463459

464460
case 1:
465461
stream.log("Detected advanced dialog.");
466-
last_prompt = 0;
462+
last_prompt = BUTTON_NONE;
467463
pbf_press_button(context, BUTTON_B, 20, 30);
468464
checked = true;
469465
continue;

SerialPrograms/Source/PokemonSV/Programs/PokemonSV_Navigation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -895,8 +895,8 @@ void walk_forward_while_clear_front_path(
895895

896896
void mash_button_till_overworld(
897897
VideoStream& stream,
898-
SwitchControllerContext& context,
899-
uint16_t button, uint16_t seconds_run
898+
SwitchControllerContext& context,
899+
Button button, uint16_t seconds_run
900900
){
901901
OverworldWatcher overworld(stream.logger(), COLOR_CYAN);
902902
context.wait_for_all_requests();
@@ -1043,7 +1043,7 @@ void press_button_until_gradient_arrow(
10431043
VideoStream& stream,
10441044
SwitchControllerContext& context,
10451045
ImageFloatBox box_area_to_check,
1046-
uint16_t button,
1046+
Button button,
10471047
GradientArrowType arrow_type
10481048
){
10491049
GradientArrowWatcher arrow(COLOR_RED, arrow_type, box_area_to_check);

SerialPrograms/Source/PokemonSV/Programs/PokemonSV_Navigation.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,9 @@ void walk_forward_while_clear_front_path(
145145
// mashes A button by default
146146
void mash_button_till_overworld(
147147
VideoStream& stream,
148-
SwitchControllerContext& context,
149-
uint16_t button = BUTTON_A, uint16_t seconds_run = 360
148+
SwitchControllerContext& context,
149+
Button button = BUTTON_A,
150+
uint16_t seconds_run = 360
150151
);
151152

152153
// fly to the pokecenter that overlaps with the player on the map, and return true.
@@ -178,7 +179,7 @@ void press_button_until_gradient_arrow(
178179
VideoStream& stream,
179180
SwitchControllerContext& context,
180181
ImageFloatBox box_area_to_check,
181-
uint16_t button = BUTTON_A,
182+
Button button = BUTTON_A,
182183
GradientArrowType arrow_type = GradientArrowType::RIGHT
183184
);
184185

SerialPrograms/Source/PokemonSV/Programs/Sandwiches/PokemonSV_SandwichRoutines.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ void repeat_press_until(
575575
void repeat_button_press_until(
576576
const ProgramInfo& info,
577577
VideoStream& stream, SwitchControllerContext& context,
578-
uint16_t button, uint16_t hold_ticks, uint16_t release_ticks,
578+
Button button, uint16_t hold_ticks, uint16_t release_ticks,
579579
const std::vector<PeriodicInferenceCallback>& callbacks,
580580
const std::string &error_name, const std::string &error_message,
581581
std::chrono::milliseconds iteration_length = std::chrono::seconds(5),
@@ -586,7 +586,9 @@ void repeat_button_press_until(
586586
const std::chrono::milliseconds button_time = std::chrono::milliseconds((hold_ticks + release_ticks) * (1000 / TICKS_PER_SECOND));
587587
repeat_press_until(
588588
info, stream, context,
589-
[&](){ pbf_press_button(context, button, hold_ticks, release_ticks); },
589+
[&](){
590+
pbf_press_button(context, button, hold_ticks, release_ticks);
591+
},
590592
callbacks, error_name, error_message, iteration_length - button_time, max_presses,
591593
default_video_period, default_audio_period
592594
);

0 commit comments

Comments
 (0)