Skip to content

Commit 62f0328

Browse files
committed
Parallelize the SwSh sparkle detector.
1 parent aac2ec4 commit 62f0328

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

SerialPrograms/Source/PokemonSwSh/Inference/ShinyDetection/PokemonSwSh_ShinySparkleSet.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
*/
66

77
#include <sstream>
8+
#include "Common/Cpp/Concurrency/SpinLock.h"
89
#include "Kernels/Waterfill/Kernels_Waterfill_Session.h"
10+
#include "CommonFramework/Tools/GlobalThreadPools.h"
911
#include "CommonTools/Images/BinaryImage_FilterRgb32.h"
1012
#include "PokemonSwSh/PokemonSwSh_Settings.h"
1113
#include "PokemonSwSh_SparkleDetectorRadial.h"
@@ -124,6 +126,27 @@ void ShinySparkleSetSwSh::read_from_image(size_t screen_area, const ImageViewRGB
124126
{0xffd0d000, 0xffffffff},
125127
}
126128
);
129+
130+
SpinLock lock;
131+
double best_alpha = 0;
132+
GlobalThreadPools::realtime_inference().run_in_parallel(
133+
[&](size_t index){
134+
auto session = make_WaterfillSession();
135+
session->set_source(matrices[index]);
136+
ShinySparkleSetSwSh sparkles = find_sparkles(screen_area, *session);
137+
sparkles.update_alphas();
138+
double alpha = sparkles.alpha_overall();
139+
140+
WriteSpinLock lg(lock);
141+
if (best_alpha < alpha){
142+
best_alpha = alpha;
143+
*this = std::move(sparkles);
144+
}
145+
},
146+
0, matrices.size(), 1
147+
);
148+
149+
#if 0
127150
auto session = make_WaterfillSession();
128151

129152
double best_alpha = 0;
@@ -137,6 +160,7 @@ void ShinySparkleSetSwSh::read_from_image(size_t screen_area, const ImageViewRGB
137160
*this = std::move(sparkles);
138161
}
139162
}
163+
#endif
140164
}
141165

142166

0 commit comments

Comments
 (0)