From 60e1c4d9acf3c97f86e1689a6a2bf2619b0e313d Mon Sep 17 00:00:00 2001 From: jw098 Date: Tue, 9 Jul 2024 12:40:53 -0700 Subject: [PATCH] parallelize detection of material value --- .../PokemonSV_ItemPrinterMaterialDetector.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/SerialPrograms/Source/PokemonSV/Inference/ItemPrinter/PokemonSV_ItemPrinterMaterialDetector.cpp b/SerialPrograms/Source/PokemonSV/Inference/ItemPrinter/PokemonSV_ItemPrinterMaterialDetector.cpp index d47c43986..7f009be2d 100644 --- a/SerialPrograms/Source/PokemonSV/Inference/ItemPrinter/PokemonSV_ItemPrinterMaterialDetector.cpp +++ b/SerialPrograms/Source/PokemonSV/Inference/ItemPrinter/PokemonSV_ItemPrinterMaterialDetector.cpp @@ -192,11 +192,16 @@ std::vector ItemPrinterMaterialDetector::find_material_value_row_index( VideoSnapshot snapshot = console.video().snapshot(); int8_t total_rows = 10; std::vector row_indexes; + SpinLock lock; + std::vector> tasks(total_rows); for (int8_t row_index = 0; row_index < total_rows; row_index++){ - int16_t value = read_number(console, dispatcher, snapshot, m_box_mat_value[row_index]); - if (value == material_value){ - row_indexes.push_back(row_index); - } + tasks[row_index] = dispatcher.dispatch([&, row_index]{ + int16_t value = read_number(console, dispatcher, snapshot, m_box_mat_value[row_index]); + if (value == material_value){ + WriteSpinLock lg(lock); + row_indexes.push_back(row_index); + } + }); } return row_indexes;