Skip to content

Commit 9e7e470

Browse files
committed
refactor Autostory so that Stats is a parameter that is passed into the inner functions, rather than cast from env.current_stats.
1 parent b3793aa commit 9e7e470

File tree

54 files changed

+547
-406
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+547
-406
lines changed

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

Lines changed: 59 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -567,66 +567,67 @@ void AutoStory::test_checkpoints(
567567
int start, int end,
568568
int loop, int start_loop, int end_loop
569569
){
570+
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
570571
EventNotificationOption& notif_status_update = NOTIFICATION_STATUS_UPDATE;
571572
Language language = LANGUAGE;
572573
StarterChoice starter_choice = STARTERCHOICE;
573574
std::vector<std::function<void()>> checkpoint_list;
574575
checkpoint_list.push_back([&](){checkpoint_00(env, context);});
575-
checkpoint_list.push_back([&](){checkpoint_01(env, context, notif_status_update, language);});
576-
checkpoint_list.push_back([&](){checkpoint_02(env, context, notif_status_update);});
577-
checkpoint_list.push_back([&](){checkpoint_03(env, context, notif_status_update, language, starter_choice);});
578-
checkpoint_list.push_back([&](){checkpoint_04(env, context, notif_status_update);});
579-
checkpoint_list.push_back([&](){checkpoint_05(env, context, notif_status_update);});
580-
checkpoint_list.push_back([&](){checkpoint_06(env, context, notif_status_update);});
581-
checkpoint_list.push_back([&](){checkpoint_07(env, context, notif_status_update);});
582-
checkpoint_list.push_back([&](){checkpoint_08(env, context, notif_status_update);});
583-
checkpoint_list.push_back([&](){checkpoint_09(env, context, notif_status_update);});
584-
checkpoint_list.push_back([&](){checkpoint_10(env, context, notif_status_update);});
585-
checkpoint_list.push_back([&](){checkpoint_11(env, context, notif_status_update);});
586-
checkpoint_list.push_back([&](){checkpoint_12(env, context, notif_status_update);});
587-
checkpoint_list.push_back([&](){checkpoint_13(env, context, notif_status_update);});
588-
checkpoint_list.push_back([&](){checkpoint_14(env, context, notif_status_update);});
589-
checkpoint_list.push_back([&](){checkpoint_15(env, context, notif_status_update);});
590-
checkpoint_list.push_back([&](){checkpoint_16(env, context, notif_status_update);});
591-
checkpoint_list.push_back([&](){checkpoint_17(env, context, notif_status_update);});
592-
checkpoint_list.push_back([&](){checkpoint_18(env, context, notif_status_update);});
593-
checkpoint_list.push_back([&](){checkpoint_19(env, context, notif_status_update);});
594-
checkpoint_list.push_back([&](){checkpoint_20(env, context, notif_status_update);});
595-
checkpoint_list.push_back([&](){checkpoint_21(env, context, notif_status_update);});
596-
checkpoint_list.push_back([&](){checkpoint_22(env, context, notif_status_update);});
597-
checkpoint_list.push_back([&](){checkpoint_23(env, context, notif_status_update);});
598-
checkpoint_list.push_back([&](){checkpoint_24(env, context, notif_status_update);});
599-
checkpoint_list.push_back([&](){checkpoint_25(env, context, notif_status_update);});
600-
checkpoint_list.push_back([&](){checkpoint_26(env, context, notif_status_update);});
601-
checkpoint_list.push_back([&](){checkpoint_27(env, context, notif_status_update);});
602-
checkpoint_list.push_back([&](){checkpoint_28(env, context, notif_status_update);});
603-
checkpoint_list.push_back([&](){checkpoint_29(env, context, notif_status_update);});
604-
checkpoint_list.push_back([&](){checkpoint_30(env, context, notif_status_update);});
605-
checkpoint_list.push_back([&](){checkpoint_31(env, context, notif_status_update);});
606-
checkpoint_list.push_back([&](){checkpoint_32(env, context, notif_status_update);});
607-
checkpoint_list.push_back([&](){checkpoint_33(env, context, notif_status_update);});
608-
checkpoint_list.push_back([&](){checkpoint_34(env, context, notif_status_update);});
609-
checkpoint_list.push_back([&](){checkpoint_35(env, context, notif_status_update);});
610-
checkpoint_list.push_back([&](){checkpoint_36(env, context, notif_status_update);});
611-
checkpoint_list.push_back([&](){checkpoint_37(env, context, notif_status_update);});
612-
checkpoint_list.push_back([&](){checkpoint_38(env, context, notif_status_update);});
613-
checkpoint_list.push_back([&](){checkpoint_39(env, context, notif_status_update);});
614-
checkpoint_list.push_back([&](){checkpoint_40(env, context, notif_status_update);});
615-
checkpoint_list.push_back([&](){checkpoint_41(env, context, notif_status_update);});
616-
checkpoint_list.push_back([&](){checkpoint_42(env, context, notif_status_update);});
617-
checkpoint_list.push_back([&](){checkpoint_43(env, context, notif_status_update);});
618-
checkpoint_list.push_back([&](){checkpoint_44(env, context, notif_status_update);});
619-
checkpoint_list.push_back([&](){checkpoint_45(env, context, notif_status_update);});
620-
checkpoint_list.push_back([&](){checkpoint_46(env, context, notif_status_update);});
621-
checkpoint_list.push_back([&](){checkpoint_47(env, context, notif_status_update);});
622-
checkpoint_list.push_back([&](){checkpoint_48(env, context, notif_status_update);});
623-
checkpoint_list.push_back([&](){checkpoint_49(env, context, notif_status_update);});
624-
checkpoint_list.push_back([&](){checkpoint_50(env, context, notif_status_update);});
625-
checkpoint_list.push_back([&](){checkpoint_51(env, context, notif_status_update);});
626-
checkpoint_list.push_back([&](){checkpoint_52(env, context, notif_status_update);});
627-
checkpoint_list.push_back([&](){checkpoint_53(env, context, notif_status_update);});
628-
checkpoint_list.push_back([&](){checkpoint_54(env, context, notif_status_update);});
629-
checkpoint_list.push_back([&](){checkpoint_55(env, context, notif_status_update);});
576+
checkpoint_list.push_back([&](){checkpoint_01(env, context, notif_status_update, stats, language);});
577+
checkpoint_list.push_back([&](){checkpoint_02(env, context, notif_status_update, stats);});
578+
checkpoint_list.push_back([&](){checkpoint_03(env, context, notif_status_update, stats, language, starter_choice);});
579+
checkpoint_list.push_back([&](){checkpoint_04(env, context, notif_status_update, stats);});
580+
checkpoint_list.push_back([&](){checkpoint_05(env, context, notif_status_update, stats);});
581+
checkpoint_list.push_back([&](){checkpoint_06(env, context, notif_status_update, stats);});
582+
checkpoint_list.push_back([&](){checkpoint_07(env, context, notif_status_update, stats);});
583+
checkpoint_list.push_back([&](){checkpoint_08(env, context, notif_status_update, stats);});
584+
checkpoint_list.push_back([&](){checkpoint_09(env, context, notif_status_update, stats);});
585+
checkpoint_list.push_back([&](){checkpoint_10(env, context, notif_status_update, stats);});
586+
checkpoint_list.push_back([&](){checkpoint_11(env, context, notif_status_update, stats);});
587+
checkpoint_list.push_back([&](){checkpoint_12(env, context, notif_status_update, stats);});
588+
checkpoint_list.push_back([&](){checkpoint_13(env, context, notif_status_update, stats);});
589+
checkpoint_list.push_back([&](){checkpoint_14(env, context, notif_status_update, stats);});
590+
checkpoint_list.push_back([&](){checkpoint_15(env, context, notif_status_update, stats);});
591+
checkpoint_list.push_back([&](){checkpoint_16(env, context, notif_status_update, stats);});
592+
checkpoint_list.push_back([&](){checkpoint_17(env, context, notif_status_update, stats);});
593+
checkpoint_list.push_back([&](){checkpoint_18(env, context, notif_status_update, stats);});
594+
checkpoint_list.push_back([&](){checkpoint_19(env, context, notif_status_update, stats);});
595+
checkpoint_list.push_back([&](){checkpoint_20(env, context, notif_status_update, stats);});
596+
checkpoint_list.push_back([&](){checkpoint_21(env, context, notif_status_update, stats);});
597+
checkpoint_list.push_back([&](){checkpoint_22(env, context, notif_status_update, stats);});
598+
checkpoint_list.push_back([&](){checkpoint_23(env, context, notif_status_update, stats);});
599+
checkpoint_list.push_back([&](){checkpoint_24(env, context, notif_status_update, stats);});
600+
checkpoint_list.push_back([&](){checkpoint_25(env, context, notif_status_update, stats);});
601+
checkpoint_list.push_back([&](){checkpoint_26(env, context, notif_status_update, stats);});
602+
checkpoint_list.push_back([&](){checkpoint_27(env, context, notif_status_update, stats);});
603+
checkpoint_list.push_back([&](){checkpoint_28(env, context, notif_status_update, stats);});
604+
checkpoint_list.push_back([&](){checkpoint_29(env, context, notif_status_update, stats);});
605+
checkpoint_list.push_back([&](){checkpoint_30(env, context, notif_status_update, stats);});
606+
checkpoint_list.push_back([&](){checkpoint_31(env, context, notif_status_update, stats);});
607+
checkpoint_list.push_back([&](){checkpoint_32(env, context, notif_status_update, stats);});
608+
checkpoint_list.push_back([&](){checkpoint_33(env, context, notif_status_update, stats);});
609+
checkpoint_list.push_back([&](){checkpoint_34(env, context, notif_status_update, stats);});
610+
checkpoint_list.push_back([&](){checkpoint_35(env, context, notif_status_update, stats);});
611+
checkpoint_list.push_back([&](){checkpoint_36(env, context, notif_status_update, stats);});
612+
checkpoint_list.push_back([&](){checkpoint_37(env, context, notif_status_update, stats);});
613+
checkpoint_list.push_back([&](){checkpoint_38(env, context, notif_status_update, stats);});
614+
checkpoint_list.push_back([&](){checkpoint_39(env, context, notif_status_update, stats);});
615+
checkpoint_list.push_back([&](){checkpoint_40(env, context, notif_status_update, stats);});
616+
checkpoint_list.push_back([&](){checkpoint_41(env, context, notif_status_update, stats);});
617+
checkpoint_list.push_back([&](){checkpoint_42(env, context, notif_status_update, stats);});
618+
checkpoint_list.push_back([&](){checkpoint_43(env, context, notif_status_update, stats);});
619+
checkpoint_list.push_back([&](){checkpoint_44(env, context, notif_status_update, stats);});
620+
checkpoint_list.push_back([&](){checkpoint_45(env, context, notif_status_update, stats);});
621+
checkpoint_list.push_back([&](){checkpoint_46(env, context, notif_status_update, stats);});
622+
checkpoint_list.push_back([&](){checkpoint_47(env, context, notif_status_update, stats);});
623+
checkpoint_list.push_back([&](){checkpoint_48(env, context, notif_status_update, stats);});
624+
checkpoint_list.push_back([&](){checkpoint_49(env, context, notif_status_update, stats);});
625+
checkpoint_list.push_back([&](){checkpoint_50(env, context, notif_status_update, stats);});
626+
checkpoint_list.push_back([&](){checkpoint_51(env, context, notif_status_update, stats);});
627+
checkpoint_list.push_back([&](){checkpoint_52(env, context, notif_status_update, stats);});
628+
checkpoint_list.push_back([&](){checkpoint_53(env, context, notif_status_update, stats);});
629+
checkpoint_list.push_back([&](){checkpoint_54(env, context, notif_status_update, stats);});
630+
checkpoint_list.push_back([&](){checkpoint_55(env, context, notif_status_update, stats);});
630631

631632

632633
for (int checkpoint = start; checkpoint <= end; checkpoint++){
@@ -728,12 +729,13 @@ void AutoStory::run_autostory(SingleSwitchProgramEnvironment& env, ProController
728729
NOTIFICATION_STATUS_UPDATE
729730
};
730731

732+
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
731733
if (get_start_segment_index() > get_end_segment_index()){
732734
throw UserSetupError(env.logger(), "The start segment cannot be later than the end segment.");
733735
}
734-
736+
735737
for (size_t segment_index = get_start_segment_index(); segment_index <= get_end_segment_index(); segment_index++){
736-
ALL_AUTO_STORY_SEGMENT_LIST()[segment_index]->run_segment(env, context, options);
738+
ALL_AUTO_STORY_SEGMENT_LIST()[segment_index]->run_segment(env, context, options, stats);
737739
}
738740
}
739741

@@ -797,7 +799,6 @@ void AutoStory::test_code(SingleSwitchProgramEnvironment& env, ProControllerCont
797799

798800
void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
799801
assert_16_9_720p_min(env.logger(), env.console);
800-
// AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
801802

802803

803804
// test code

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,8 +1009,7 @@ void get_on_or_off_ride(const ProgramInfo& info, VideoStream& stream, ProControl
10091009
}
10101010
}
10111011

1012-
void checkpoint_save(SingleSwitchProgramEnvironment& env, ProControllerContext& context, EventNotificationOption& notif_status_update){
1013-
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
1012+
void checkpoint_save(SingleSwitchProgramEnvironment& env, ProControllerContext& context, EventNotificationOption& notif_status_update, AutoStoryStats& stats){
10141013
save_game_from_overworld(env.program_info(), env.console, context);
10151014
stats.m_checkpoint++;
10161015
env.update_stats();

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ class AutoStory_Segment {
115115
virtual void run_segment(
116116
SingleSwitchProgramEnvironment& env,
117117
ProControllerContext& context,
118-
AutoStoryOptions options) const = 0;
118+
AutoStoryOptions options,
119+
AutoStoryStats& stats) const = 0;
119120
};
120121

121122
// spam A button to choose the first move for trainer battles
@@ -289,7 +290,7 @@ void change_settings_prior_to_autostory(
289290
void change_settings(SingleSwitchProgramEnvironment& env, ProControllerContext& context, Language language, bool use_inference = true);
290291

291292

292-
void checkpoint_save(SingleSwitchProgramEnvironment& env, ProControllerContext& context, EventNotificationOption& notif_status_update);
293+
void checkpoint_save(SingleSwitchProgramEnvironment& env, ProControllerContext& context, EventNotificationOption& notif_status_update, AutoStoryStats& stats);
293294

294295
enum class ZoomChange{
295296
ZOOM_IN,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ std::string AutoStory_Segment_00::end_text() const{
3737
void AutoStory_Segment_00::run_segment(
3838
SingleSwitchProgramEnvironment& env,
3939
ProControllerContext& context,
40-
AutoStoryOptions options
40+
AutoStoryOptions options,
41+
AutoStoryStats& stats
4142
) const{
42-
// AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
4343

4444
context.wait_for_all_requests();
4545
env.console.log("Start Segment 00: Intro Cutscene", COLOR_ORANGE);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class AutoStory_Segment_00 : public AutoStory_Segment{
2121
virtual void run_segment(
2222
SingleSwitchProgramEnvironment& env,
2323
ProControllerContext& context,
24-
AutoStoryOptions options
24+
AutoStoryOptions options,
25+
AutoStoryStats& stats
2526
) const override;
2627
};
2728

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@ std::string AutoStory_Segment_01::end_text() const{
4949
void AutoStory_Segment_01::run_segment(
5050
SingleSwitchProgramEnvironment& env,
5151
ProControllerContext& context,
52-
AutoStoryOptions options
52+
AutoStoryOptions options,
53+
AutoStoryStats& stats
5354
) const{
54-
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
5555

5656
stats.m_segment++;
5757
env.update_stats();
5858
context.wait_for_all_requests();
5959
env.console.log("Start Segment 01: Pick Starter", COLOR_ORANGE);
6060

61-
checkpoint_01(env, context, options.notif_status_update, options.language);
62-
checkpoint_02(env, context, options.notif_status_update);
63-
checkpoint_03(env, context, options.notif_status_update, options.language, options.starter_choice);
61+
checkpoint_01(env, context, options.notif_status_update, stats, options.language);
62+
checkpoint_02(env, context, options.notif_status_update, stats);
63+
checkpoint_03(env, context, options.notif_status_update, stats, options.language, options.starter_choice);
6464

6565
context.wait_for_all_requests();
6666
env.console.log("End Segment 01: Pick Starter", COLOR_GREEN);
@@ -71,10 +71,10 @@ void AutoStory_Segment_01::run_segment(
7171
void checkpoint_01(
7272
SingleSwitchProgramEnvironment& env,
7373
ProControllerContext& context,
74-
EventNotificationOption& notif_status_update,
74+
EventNotificationOption& notif_status_update,
75+
AutoStoryStats& stats,
7576
Language language
7677
){
77-
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
7878
bool first_attempt = true;
7979
while (true){
8080
try{
@@ -108,9 +108,9 @@ AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
108108
void checkpoint_02(
109109
SingleSwitchProgramEnvironment& env,
110110
ProControllerContext& context,
111-
EventNotificationOption& notif_status_update
111+
EventNotificationOption& notif_status_update,
112+
AutoStoryStats& stats
112113
){
113-
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
114114
bool first_attempt = true;
115115
while (true){
116116
try{
@@ -199,15 +199,15 @@ void checkpoint_03(
199199
SingleSwitchProgramEnvironment& env,
200200
ProControllerContext& context,
201201
EventNotificationOption& notif_status_update,
202+
AutoStoryStats& stats,
202203
Language language,
203204
StarterChoice starter_choice
204205
){
205-
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
206206
bool first_attempt = true;
207207
while (true){
208208
try{
209209
if (first_attempt){
210-
checkpoint_save(env, context, notif_status_update);
210+
checkpoint_save(env, context, notif_status_update, stats);
211211
first_attempt = false;
212212
}
213213

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class AutoStory_Segment_01 : public AutoStory_Segment{
2121
virtual void run_segment(
2222
SingleSwitchProgramEnvironment& env,
2323
ProControllerContext& context,
24-
AutoStoryOptions options
24+
AutoStoryOptions options,
25+
AutoStoryStats& stats
2526
) const override;
2627
};
2728

@@ -31,6 +32,7 @@ void checkpoint_01(
3132
SingleSwitchProgramEnvironment& env,
3233
ProControllerContext& context,
3334
EventNotificationOption& notif_status_update,
35+
AutoStoryStats& stats,
3436
Language language
3537
);
3638

@@ -39,7 +41,8 @@ void checkpoint_01(
3941
void checkpoint_02(
4042
SingleSwitchProgramEnvironment& env,
4143
ProControllerContext& context,
42-
EventNotificationOption& notif_status_update
44+
EventNotificationOption& notif_status_update,
45+
AutoStoryStats& stats
4346
);
4447

4548
// start: standing in front of power of science NPC. Cleared map tutorial.
@@ -48,6 +51,7 @@ void checkpoint_03(
4851
SingleSwitchProgramEnvironment& env,
4952
ProControllerContext& context,
5053
EventNotificationOption& notif_status_update,
54+
AutoStoryStats& stats,
5155
Language language,
5256
StarterChoice starter_choice
5357
);

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,15 @@ std::string AutoStory_Segment_02::end_text() const{
4545
void AutoStory_Segment_02::run_segment(
4646
SingleSwitchProgramEnvironment& env,
4747
ProControllerContext& context,
48-
AutoStoryOptions options
48+
AutoStoryOptions options,
49+
AutoStoryStats& stats
4950
) const{
50-
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
51-
5251
stats.m_segment++;
5352
env.update_stats();
5453
context.wait_for_all_requests();
5554
env.console.log("Start Segment 02: First Nemona Battle", COLOR_ORANGE);
5655

57-
checkpoint_04(env, context, options.notif_status_update);
56+
checkpoint_04(env, context, options.notif_status_update, stats);
5857

5958
context.wait_for_all_requests();
6059
env.console.log("End Segment 02: First Nemona Battle", COLOR_GREEN);
@@ -65,14 +64,14 @@ void AutoStory_Segment_02::run_segment(
6564
void checkpoint_04(
6665
SingleSwitchProgramEnvironment& env,
6766
ProControllerContext& context,
68-
EventNotificationOption& notif_status_update
67+
EventNotificationOption& notif_status_update,
68+
AutoStoryStats& stats
6969
){
70-
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
7170
bool first_attempt = true;
7271
while (true){
7372
try{
7473
if (first_attempt){
75-
checkpoint_save(env, context, notif_status_update);
74+
checkpoint_save(env, context, notif_status_update, stats);
7675
first_attempt = false;
7776
}
7877
context.wait_for_all_requests();

0 commit comments

Comments
 (0)