Skip to content

Commit 90ad667

Browse files
committed
Allow programs that don't require a controller to run without a controller.
1 parent 9003470 commit 90ad667

27 files changed

Lines changed: 100 additions & 102 deletions

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestDudunsparceFormDetector.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ TestDudunsparceFormDetector_Descriptor::TestDudunsparceFormDetector_Descriptor()
147147
TestDudunsparceFormDetector::TestDudunsparceFormDetector(){}
148148

149149

150-
void TestDudunsparceFormDetector::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
150+
void TestDudunsparceFormDetector::program(SingleSwitchProgramEnvironment& env, CancellableScope& scope){
151151

152152
DudunsparceFormDetector detector(env.console.overlay());
153153

@@ -162,15 +162,16 @@ void TestDudunsparceFormDetector::program(SingleSwitchProgramEnvironment& env, P
162162
// context.wait_until_cancel();
163163

164164
std::string last_label = "";
165-
run_until<ProControllerContext>(
166-
env.console, context, [&](ProControllerContext& context){
165+
run_until(
166+
env.console, scope,
167+
[&](CancellableScope& scope){
167168
while (true){
168169
std::string cur_label = detector.get_label();
169170
if (cur_label != last_label){
170171
last_label = cur_label;
171172
env.console.overlay().add_log("Detected " + last_label);
172173
}
173-
context.wait_for(std::chrono::milliseconds(100));
174+
scope.wait_for(std::chrono::milliseconds(100));
174175
}
175176
},
176177
{detector},

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestDudunsparceFormDetector.h

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,34 @@
44
*
55
*/
66

7-
#ifndef PokemonAutomation_NintendoSwitch_TestDudunsparceFormDetector_H
8-
#define PokemonAutomation_NintendoSwitch_TestDudunsparceFormDetector_H
9-
10-
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
11-
12-
namespace PokemonAutomation{
13-
namespace NintendoSwitch{
14-
15-
16-
class TestDudunsparceFormDetector_Descriptor : public SingleSwitchProgramDescriptor{
17-
public:
18-
TestDudunsparceFormDetector_Descriptor();
19-
};
20-
21-
22-
class TestDudunsparceFormDetector : public SingleSwitchProgramInstance{
23-
public:
24-
TestDudunsparceFormDetector();
25-
26-
virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override;
27-
28-
private:
29-
};
30-
7+
#ifndef PokemonAutomation_NintendoSwitch_TestDudunsparceFormDetector_H
8+
#define PokemonAutomation_NintendoSwitch_TestDudunsparceFormDetector_H
9+
10+
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
11+
12+
namespace PokemonAutomation{
13+
namespace NintendoSwitch{
14+
15+
16+
class TestDudunsparceFormDetector_Descriptor : public SingleSwitchProgramDescriptor{
17+
public:
18+
TestDudunsparceFormDetector_Descriptor();
19+
};
20+
21+
22+
class TestDudunsparceFormDetector : public SingleSwitchProgramInstance{
23+
public:
24+
TestDudunsparceFormDetector();
25+
26+
virtual void start_program_controller_check(ControllerSession& session) override{}
27+
virtual void program(SingleSwitchProgramEnvironment& env, CancellableScope& scope) override;
28+
29+
private:
30+
};
31+
3132

3233

3334
}
3435
}
3536
#endif // TESTPATHMAKER_H
36-
37+

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ class TestProgram : public MultiSwitchProgramInstance, public ButtonListener{
5353
// std::unique_ptr<StatsTracker> make_stats() const override{
5454
// return std::unique_ptr<StatsTracker>(new StatsTracker());
5555
// }
56+
virtual void start_program_controller_check(
57+
ControllerSession& session, size_t console_index
58+
) override{}
5659
virtual void program(MultiSwitchProgramEnvironment& env, CancellableScope& scope) override;
5760

5861
virtual void on_press() override;

SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_SnapshotDumper.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,22 +137,22 @@ void SnapshotKeyTrigger::on_key_release(QKeyEvent* event){
137137
}
138138

139139

140-
void SnapshotDumper::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
140+
void SnapshotDumper::program(SingleSwitchProgramEnvironment& env, CancellableScope& scope){
141141
std::string folder_path = USER_FILE_PATH() + "ScreenshotDumper/";
142142
QDir().mkpath(folder_path.c_str());
143143

144144
if (SNAPSHOT_MODE == SnapshotMode::KEYPRESS){
145145
SnapshotKeyTrigger key_trigger(env.console, env.console.overlay(), FORMAT);
146-
context.wait_until_cancel();
146+
scope.wait_until_cancel();
147147
}else if (SNAPSHOT_MODE == SnapshotMode::MOUSE_CLICK){
148148
SnapshotClickTrigger click_trigger(env.console, env.console.overlay(), FORMAT);
149-
context.wait_until_cancel();
149+
scope.wait_until_cancel();
150150
}else if (SNAPSHOT_MODE == SnapshotMode::PERIODIC){
151151
while (true){
152152
VideoSnapshot last = env.console.video().snapshot();
153153
std::string filename = folder_path + now_to_filestring();
154154
last->save(filename + to_format_string(FORMAT));
155-
context.wait_until(last.timestamp + std::chrono::milliseconds(PERIOD_MILLISECONDS));
155+
scope.wait_until(last.timestamp + std::chrono::milliseconds(PERIOD_MILLISECONDS));
156156
}
157157
}else{
158158
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Unexpected SNAPSHOT_MODE enum.");

SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_SnapshotDumper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class SnapshotDumper : public SingleSwitchProgramInstance, public ConfigOption::
3434
~SnapshotDumper();
3535
SnapshotDumper();
3636

37-
virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override;
37+
virtual void start_program_controller_check(ControllerSession& session) override{}
38+
virtual void program(SingleSwitchProgramEnvironment& env, CancellableScope& scope) override;
3839

3940
private:
4041
virtual void on_config_value_changed(void* object) override;

SerialPrograms/Source/PokemonBDSP/Programs/TestPrograms/PokemonBDSP_ShinyEncounterTester.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ ShinyEncounterTester::ShinyEncounterTester()
5555
}
5656

5757

58-
void ShinyEncounterTester::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
58+
void ShinyEncounterTester::program(SingleSwitchProgramEnvironment& env, CancellableScope& scope){
5959
DoublesShinyDetection result_wild;
6060
ShinyDetectionResult result_own;
6161
detect_shiny_battle(
62-
env, env.console, context,
62+
env, env.console, scope,
6363
result_wild, result_own,
6464
NOTIFICATION_ERROR_RECOVERABLE,
6565
ENCOUNTER_TYPE == BattleType::STARTER ? YOUR_POKEMON : WILD_POKEMON,

SerialPrograms/Source/PokemonBDSP/Programs/TestPrograms/PokemonBDSP_ShinyEncounterTester.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class ShinyEncounterTester : public SingleSwitchProgramInstance{
2727
public:
2828
ShinyEncounterTester();
2929

30-
virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override;
30+
virtual void start_program_controller_check(ControllerSession& session) override{}
31+
virtual void program(SingleSwitchProgramEnvironment& env, CancellableScope& scope) override;
3132

3233
private:
3334
EnumDropdownOption<BattleType> ENCOUNTER_TYPE;

SerialPrograms/Source/PokemonBDSP/Programs/TestPrograms/PokemonBDSP_SoundListener.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ SoundListener::SoundListener()
6363

6464
// void search_alpha_roar_from_audio_dump();
6565

66-
void SoundListener::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
66+
void SoundListener::program(SingleSwitchProgramEnvironment& env, CancellableScope& scope){
6767
// search_alpha_roar_from_audio_dump();
6868
// return;
6969

@@ -90,10 +90,10 @@ void SoundListener::program(SingleSwitchProgramEnvironment& env, ProControllerCo
9090
}
9191

9292
InferenceSession session(
93-
context, env.console,
93+
scope, env.console,
9494
{{*detector, std::chrono::milliseconds(20)}}
9595
);
96-
context.wait_until_cancel();
96+
scope.wait_until_cancel();
9797

9898
std::cout << "Audio test program Sound listener finished." << std::endl;
9999
}

SerialPrograms/Source/PokemonBDSP/Programs/TestPrograms/PokemonBDSP_SoundListener.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ class SoundListener : public SingleSwitchProgramInstance{
2828
public:
2929
SoundListener();
3030

31-
virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override;
31+
virtual void start_program_controller_check(ControllerSession& session) override{}
32+
virtual void program(SingleSwitchProgramEnvironment& env, CancellableScope& scope) override;
3233

3334
private:
3435
enum class SoundType{

SerialPrograms/Source/PokemonFRLG/Programs/TestPrograms/PokemonFRLG_ReadBattleLevelUp.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ ReadBattleLevelUp::ReadBattleLevelUp()
4747

4848
void ReadBattleLevelUp::program(
4949
SingleSwitchProgramEnvironment &env,
50-
ProControllerContext &context
50+
CancellableScope& scope
5151
){
5252
env.log(
5353
"Starting Read Battle Level Up program..."
@@ -94,8 +94,7 @@ void ReadBattleLevelUp::program(
9494

9595
env.log("Finished Reading Stats. Verification boxes are on overlay.",
9696
COLOR_BLUE);
97-
pbf_wait(context, 10s);
98-
context.wait_for_all_requests();
97+
scope.wait_for(10s);
9998
}
10099

101100
} // namespace PokemonFRLG

0 commit comments

Comments
 (0)