Skip to content

Commit 0de088f

Browse files
committed
Minor refactor to eliminate static globals.
1 parent 59ce0c3 commit 0de088f

2 files changed

Lines changed: 36 additions & 26 deletions

File tree

SerialPrograms/Source/PokemonLZA/Inference/Map/PokemonLZA_MapDetector.cpp

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#include "PokemonLZA_MapDetector.h"
1010
#include "PokemonLZA_MapIconDetector.h"
1111

12+
//#include <iostream>
13+
//using std::cout;
14+
//using std::endl;
15+
1216
namespace PokemonAutomation{
1317
namespace NintendoSwitch{
1418
namespace PokemonLZA{
@@ -39,39 +43,15 @@ class TravelSpotMatcher : public ImageMatch::WaterfillTemplateMatcher{
3943
}
4044
};
4145

42-
const ImageFloatBox TRAVEL_SPOT_BOX(0.040000, 0.235000, 0.030000, 0.068500);
43-
44-
// Progressive cyan filters to handle capture-card color variance.
45-
const std::vector<std::pair<uint32_t, uint32_t>> CYAN_FILTERS = {
46-
// Brighter cyan/teal.
47-
{0xff004898, 0xff70ffff},
48-
{0xff003878, 0xff80ffff},
49-
// Darker/desaturated cyan seen in some captures (e.g. 1080p hyperspace_True).
50-
{0xff002860, 0xff90ffff},
51-
{0xff001c50, 0xffa0ffff},
52-
};
53-
54-
bool detect_travel_spot(const ImageViewRGB32& screen){
55-
double rel = screen.height() / 2160.0;
56-
size_t min_area = size_t(50.0 * rel * rel);
5746

58-
return match_template_by_waterfill(
59-
screen.size(),
60-
extract_box_reference(screen, TRAVEL_SPOT_BOX),
61-
TravelSpotMatcher::instance(),
62-
CYAN_FILTERS,
63-
{min_area, SIZE_MAX},
64-
100.0,
65-
[](Kernels::Waterfill::WaterfillObject&) -> bool{ return true; }
66-
);
67-
}
6847

6948
} // anonymous namespace
7049

7150

7251

7352
MapDetector::MapDetector(Color color, VideoOverlay* overlay)
7453
: m_color(color)
54+
, m_travel_icon(0.040000, 0.235000, 0.030000, 0.068500)
7555
, m_x_button(
7656
color,
7757
ButtonType::ButtonX,
@@ -87,12 +67,13 @@ MapDetector::MapDetector(Color color, VideoOverlay* overlay)
8767
{}
8868

8969
void MapDetector::make_overlays(VideoOverlaySet& items) const{
90-
items.add(m_color, TRAVEL_SPOT_BOX);
70+
items.add(m_color, m_travel_icon);
9171
m_x_button.make_overlays(items);
9272
m_y_button.make_overlays(items);
9373
}
9474

9575
bool MapDetector::detect(const ImageViewRGB32& screen){
76+
// cout << "MapDetector::detect()" << endl;
9677
const bool detected = detect_travel_spot(screen)
9778
&& m_x_button.detect(screen)
9879
&& m_y_button.detect(screen);
@@ -105,6 +86,31 @@ bool MapDetector::detect(const ImageViewRGB32& screen){
10586
return detected;
10687
}
10788

89+
90+
bool MapDetector::detect_travel_spot(const ImageViewRGB32& screen){
91+
// Progressive cyan filters to handle capture-card color variance.
92+
static const std::vector<std::pair<uint32_t, uint32_t>> CYAN_FILTERS{
93+
// Brighter cyan/teal.
94+
{0xff004898, 0xff70ffff},
95+
{0xff003878, 0xff80ffff},
96+
// Darker/desaturated cyan seen in some captures (e.g. 1080p hyperspace_True).
97+
{0xff002860, 0xff90ffff},
98+
{0xff001c50, 0xffa0ffff},
99+
};
100+
101+
double rel = screen.height() / 2160.0;
102+
size_t min_area = size_t(50.0 * rel * rel);
103+
104+
return match_template_by_waterfill(
105+
screen.size(),
106+
extract_box_reference(screen, m_travel_icon),
107+
TravelSpotMatcher::instance(),
108+
CYAN_FILTERS,
109+
{min_area, SIZE_MAX},
110+
100.0,
111+
[](Kernels::Waterfill::WaterfillObject&) -> bool{ return true; }
112+
);
113+
}
108114
std::vector<DetectedBox> MapDetector::detected_map_icons() const{
109115
std::vector<DetectedBox> ret;
110116
for (MapIconDetector* detector : m_map_icon_detectors){

SerialPrograms/Source/PokemonLZA/Inference/Map/PokemonLZA_MapDetector.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ class MapDetector : public StaticScreenDetector{
4040

4141
void reset_state() override;
4242

43+
private:
44+
bool detect_travel_spot(const ImageViewRGB32& screen);
45+
4346
private:
4447
Color m_color;
48+
ImageFloatBox m_travel_icon;
4549
ButtonDetector m_x_button;
4650
ButtonDetector m_y_button;
4751
std::vector<MapIconDetector*> m_map_icon_detectors;

0 commit comments

Comments
 (0)