Skip to content

Commit b67a8c8

Browse files
committed
gba black borders
1 parent 4bf5931 commit b67a8c8

File tree

9 files changed

+147
-14
lines changed

9 files changed

+147
-14
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ file(GLOB MAIN_SOURCES
387387
Source/CommonFramework/Inference/AudioTemplateCache.h
388388
Source/CommonFramework/Inference/BlackBorderDetector.cpp
389389
Source/CommonFramework/Inference/BlackBorderDetector.h
390+
Source/CommonFramework/Inference/BlackBorderGBADetector.cpp
391+
Source/CommonFramework/Inference/BlackBorderGBADetector.h
390392
Source/CommonFramework/Inference/BlackScreenDetector.cpp
391393
Source/CommonFramework/Inference/BlackScreenDetector.h
392394
Source/CommonFramework/Inference/DetectionDebouncer.h
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/* Black Border Detector
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#include "CommonFramework/ImageTools/ImageStats.h"
8+
#include "CommonFramework/ImageTools/SolidColorTest.h"
9+
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
10+
#include "BlackBorderGBADetector.h"
11+
12+
#include <iostream>
13+
using std::cout;
14+
using std::endl;
15+
16+
namespace PokemonAutomation{
17+
18+
19+
BlackBorderGBADetector::BlackBorderGBADetector()
20+
: m_top(0.126, 0.055, 0.748, 0.006)
21+
, m_bottom(0.124, 0.940, 0.751, 0.004)
22+
, m_left(0.126, 0.055, 0.002, 0.888)
23+
, m_right(0.871, 0.055, 0.003, 0.888)
24+
// , m_body(0.100, 0.100, 0.800, 0.800)
25+
{}
26+
27+
void BlackBorderGBADetector::make_overlays(VideoOverlaySet& items) const{
28+
items.add(COLOR_RED, m_top);
29+
items.add(COLOR_RED, m_bottom);
30+
items.add(COLOR_RED, m_left);
31+
items.add(COLOR_RED, m_right);
32+
// items.add(COLOR_RED, m_body);
33+
}
34+
bool BlackBorderGBADetector::detect(const ImageViewRGB32& screen) const{
35+
const double MAX_SUM = 50;
36+
const double MAX_STDDEV = 20;
37+
38+
ImageStats top = image_stats(extract_box_reference(screen, m_top));
39+
// cout << "top = " << top.average << top.stddev << endl;
40+
// extract_box(screen, m_top).save("top.png");
41+
if (!is_black(top, MAX_SUM, MAX_STDDEV)){
42+
return false;
43+
}
44+
ImageStats bottom = image_stats(extract_box_reference(screen, m_bottom));
45+
// cout << "bottom = " << bottom.average << bottom.stddev << endl;
46+
if (!is_black(bottom, MAX_SUM, MAX_STDDEV)){
47+
return false;
48+
}
49+
ImageStats left = image_stats(extract_box_reference(screen, m_left));
50+
// cout << "left = " << left.average << left.stddev << endl;
51+
if (!is_black(left, MAX_SUM, MAX_STDDEV)){
52+
return false;
53+
}
54+
ImageStats right = image_stats(extract_box_reference(screen, m_right));
55+
// cout << "right = " << right.average << right.stddev << endl;
56+
if (!is_black(right, MAX_SUM, MAX_STDDEV)){
57+
return false;
58+
}
59+
// ImageStats body = image_stats(extract_box_reference(screen, m_body));
60+
// cout << "body = " << body.average << body.stddev << endl;
61+
// if (is_black(right, 30, 30)){
62+
// return false;
63+
// }
64+
65+
66+
// for (int c = 0; c < screen.width(); c++){
67+
// QRgb pixel = screen.pixel(c, 0);
68+
// cout << "(" << qRed(pixel) << "," << qGreen(pixel) << "," << qBlue(pixel) << ")";
69+
// }
70+
71+
return true;
72+
}
73+
74+
75+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* Black Screen Detector
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_CommonFramework_BlackBorderGBADetector_H
8+
#define PokemonAutomation_CommonFramework_BlackBorderGBADetector_H
9+
10+
#include "CommonFramework/ImageTools/ImageBoxes.h"
11+
#include "CommonFramework/Inference/VisualDetector.h"
12+
13+
namespace PokemonAutomation{
14+
15+
16+
class BlackBorderGBADetector : public StaticScreenDetector{
17+
public:
18+
BlackBorderGBADetector();
19+
20+
virtual void make_overlays(VideoOverlaySet& items) const override;
21+
virtual bool detect(const ImageViewRGB32& screen) const override;
22+
23+
private:
24+
ImageFloatBox m_top;
25+
ImageFloatBox m_bottom;
26+
ImageFloatBox m_left;
27+
ImageFloatBox m_right;
28+
// ImageFloatBox m_body;
29+
};
30+
31+
32+
33+
}
34+
#endif

SerialPrograms/Source/CommonFramework/Tools/BlackBorderCheck.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
1111
#include "CommonFramework/Tools/ConsoleHandle.h"
1212
#include "CommonFramework/Inference/BlackBorderDetector.h"
13+
#include "CommonFramework/Inference/BlackBorderGBADetector.h"
1314
#include "BlackBorderCheck.h"
1415

1516
namespace PokemonAutomation{
@@ -23,18 +24,29 @@ void start_program_video_check(ConsoleHandle& console, FeedbackType feedback){
2324
VideoSnapshot screen = console.video().snapshot();
2425

2526
if (!screen){
26-
if (feedback == FeedbackType::REQUIRED || feedback == FeedbackType::VIDEO_AUDIO){
27+
if (feedback == FeedbackType::REQUIRED || feedback == FeedbackType::VIDEO_AUDIO || feedback == FeedbackType::VIDEO_AUDIO_GBA){
2728
throw UserSetupError(console, "This program requires video feedback. Please make sure the video is working.");
2829
}
2930
return;
3031
}
3132

32-
BlackBorderDetector detector;
33-
VideoOverlaySet set(console);
34-
detector.make_overlays(set);
33+
if (feedback != FeedbackType::VIDEO_AUDIO_GBA) { //GB, GBC in fullscreen will reach the top and bottom of the screen
34+
BlackBorderDetector detector;
35+
VideoOverlaySet set(console);
36+
detector.make_overlays(set);
3537

36-
if (detector.detect(screen)){
37-
throw UserSetupError(console, "Black border detected! Please set your screen size to 100% in the TV Settings on your Nintendo Switch.");
38+
if (detector.detect(screen)) {
39+
throw UserSetupError(console, "Black border detected! Please set your screen size to 100% in the TV Settings on your Nintendo Switch.");
40+
}
41+
}
42+
else {
43+
BlackBorderGBADetector detector;
44+
VideoOverlaySet set(console);
45+
detector.make_overlays(set);
46+
47+
if (detector.detect(screen)) {
48+
throw UserSetupError(console, "Black border detected! Please set your screen size to 100% in the TV Settings on your Nintendo Switch.");
49+
}
3850
}
3951
}
4052
void start_program_video_check(FixedLimitVector<ConsoleHandle>& consoles, FeedbackType feedback){

SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SwitchSystemOption.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ Color pick_color(FeedbackType feedback, PABotBaseLevel size){
2222
case PABotBaseLevel::PABOTBASE_12KB:
2323
if (feedback == FeedbackType::REQUIRED){
2424
return COLOR_DARKGREEN;
25-
}else if (feedback == FeedbackType::VIDEO_AUDIO){
25+
}else if (feedback == FeedbackType::VIDEO_AUDIO || feedback == FeedbackType::VIDEO_AUDIO_GBA){
2626
return COLOR_GREEN2;
2727
}else{
2828
return COLOR_BLUE;
2929
}
3030
case PABotBaseLevel::PABOTBASE_31KB:
31-
return (feedback == FeedbackType::REQUIRED || feedback == FeedbackType::VIDEO_AUDIO) ? COLOR_PURPLE : COLOR_RED;
31+
return (feedback == FeedbackType::REQUIRED || feedback == FeedbackType::VIDEO_AUDIO || feedback == FeedbackType::VIDEO_AUDIO_GBA) ? COLOR_PURPLE : COLOR_RED;
3232
}
3333
return Color();
3434
}

SerialPrograms/Source/PokemonRSE/PokemonRSE_Navigation.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "CommonFramework/Exceptions/OperationFailedException.h"
1010
#include "CommonFramework/Exceptions/UnexpectedBattleException.h"
1111
#include "CommonFramework/InferenceInfra/InferenceRoutines.h"
12+
#include "CommonFramework/Inference/BlackScreenDetector.h"
1213
#include "NintendoSwitch/NintendoSwitch_Settings.h"
1314
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
1415
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
@@ -30,7 +31,17 @@ void soft_reset(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext&
3031
pbf_press_button(context, BUTTON_A, 20, 40);
3132

3233
//Wait for game to load in
33-
pbf_wait(context, GameSettings::instance().ENTER_GAME_WAIT);
34+
BlackScreenOverWatcher detector(COLOR_RED, {0.282, 0.064, 0.448, 0.871});
35+
int ret = wait_until(
36+
console, context,
37+
std::chrono::milliseconds(GameSettings::instance().ENTER_GAME_WAIT * (1000 / TICKS_PER_SECOND)),
38+
{{detector}}
39+
);
40+
if (ret == 0){
41+
console.log("Entered game!");
42+
}else{
43+
console.log("Timed out waiting to enter game.", COLOR_RED);
44+
}
3445
context.wait_for_all_requests();
3546
}
3647

SerialPrograms/Source/PokemonRSE/PokemonRSE_Navigation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace NintendoSwitch{
1919
namespace PokemonRSE{
2020

2121
// Press A+B+Select+Start at the same time to soft reset, then re-enters the game.
22-
// This assumes no dry battery. Adding detection for that is a TODO.
22+
// This assumes no dry battery.
2323
void soft_reset(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context);
2424

2525

SerialPrograms/Source/PokemonRSE/PokemonRSE_Settings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ GameSettings::GameSettings()
3333
"<b>1. Start Button Mash:</b><br>Mash Start for this long after a soft reset to get to the main menu.",
3434
LockMode::LOCK_WHILE_RUNNING,
3535
TICKS_PER_SECOND,
36-
"4 * TICKS_PER_SECOND"
36+
"5 * TICKS_PER_SECOND"
3737
)
3838
, ENTER_GAME_WAIT(
3939
"<b>2. Enter Game Wait:</b><br>Wait this long for the game to load.",

SerialPrograms/Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_AudioStarterReset.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ AudioStarterReset::AudioStarterReset()
8686
}
8787

8888
void AudioStarterReset::program(SingleSwitchProgramEnvironment& env, BotBaseContext& context){
89-
//assert_16_9_720p_min(env.logger(), env.console);
89+
assert_16_9_720p_min(env.logger(), env.console);
9090
AudioStarterReset_Descriptor::Stats& stats = env.current_stats<AudioStarterReset_Descriptor::Stats>();
9191

9292
/*
@@ -96,7 +96,6 @@ void AudioStarterReset::program(SingleSwitchProgramEnvironment& env, BotBaseCont
9696
*
9797
* Setup: Stand in front of the Professor's bag and save the game.
9898
*
99-
*
10099
* Required to fight, so have to do the SR method instead of run away
101100
* Soft reset programs are only for Ruby/Sapphire, as Emerald has the 0 seed issue.
102101
*
@@ -207,9 +206,9 @@ void AudioStarterReset::program(SingleSwitchProgramEnvironment& env, BotBaseCont
207206
env, NOTIFICATION_STATUS_UPDATE,
208207
"Soft resetting."
209208
);
210-
soft_reset(env.program_info(), env.console, context);
211209
stats.resets++;
212210
env.update_stats();
211+
soft_reset(env.program_info(), env.console, context);
213212
}
214213
}
215214

0 commit comments

Comments
 (0)