|
7 | 7 | #include "Common/Qt/TimeQt.h" |
8 | 8 | #include "PokemonSV_ItemPrinterRNGTable.h" |
9 | 9 |
|
| 10 | +//#include <iostream> |
| 11 | +//using std::cout; |
| 12 | +//using std::endl; |
| 13 | + |
10 | 14 | namespace PokemonAutomation{ |
11 | 15 | namespace NintendoSwitch{ |
12 | 16 | namespace PokemonSV{ |
@@ -79,29 +83,52 @@ std::unique_ptr<EditableTableRow> ItemPrinterRngRow::clone() const{ |
79 | 83 | // - also, hide the date if chain enabled. |
80 | 84 | // - trigger the listener for the parent table. |
81 | 85 | void ItemPrinterRngRow::value_changed(void* object){ |
| 86 | + { |
| 87 | + WriteSpinLock lg1(m_pending_lock); |
| 88 | + m_pending.emplace_back(object); |
| 89 | + } |
82 | 90 |
|
83 | | - ItemPrinterRngTable& table = static_cast<ItemPrinterRngTable&>(parent()); |
| 91 | + bool keep_going; |
| 92 | + do{ |
| 93 | + std::unique_lock<std::mutex> lg(m_update_lock, std::try_to_lock_t()); |
| 94 | + if (!lg.owns_lock()){ |
| 95 | + return; |
| 96 | + } |
84 | 97 |
|
85 | | - if (object == &desired_item){ |
86 | | - ItemPrinter::PrebuiltOptions option = desired_item; |
87 | | - if (option != ItemPrinter::PrebuiltOptions::NONE){ |
88 | | - const ItemPrinter::ItemPrinterEnumOption& option_data = option_lookup_by_enum(option); |
89 | | - chain = false; |
90 | | - date.set(from_seconds_since_epoch(option_data.seed)); |
91 | | - jobs.set(option_data.jobs); |
| 98 | + { |
| 99 | + WriteSpinLock lg1(m_pending_lock); |
| 100 | + object = m_pending.front(); |
| 101 | + m_pending.pop_front(); |
92 | 102 | } |
93 | | - }else if (object == &date || object == &jobs || object == &chain){ |
94 | | - date.set_visibility(chain ? ConfigOptionState::HIDDEN : ConfigOptionState::ENABLED); |
95 | | - const ItemPrinter::ItemPrinterEnumOption* option_data = ItemPrinter::option_lookup_by_seed(to_seconds_since_epoch(date)); |
96 | | - // seed found in the PrebuiltOptions table, and jobs number matches and chain disabled |
97 | | - if (option_data != nullptr && option_data->jobs == jobs && !chain){ |
98 | | - desired_item.set(option_data->enum_value); |
99 | | - }else{ |
100 | | - desired_item.set(ItemPrinter::PrebuiltOptions::NONE); |
| 103 | + |
| 104 | + ItemPrinterRngTable& table = static_cast<ItemPrinterRngTable&>(parent()); |
| 105 | + |
| 106 | + if (object == &desired_item){ |
| 107 | + ItemPrinter::PrebuiltOptions option = desired_item; |
| 108 | + if (option != ItemPrinter::PrebuiltOptions::NONE){ |
| 109 | + const ItemPrinter::ItemPrinterEnumOption& option_data = option_lookup_by_enum(option); |
| 110 | + chain = false; |
| 111 | + jobs.set(option_data.jobs); |
| 112 | + date.set(from_seconds_since_epoch(option_data.seed)); |
| 113 | + } |
| 114 | + }else if (object == &date || object == &jobs || object == &chain){ |
| 115 | + date.set_visibility(chain ? ConfigOptionState::HIDDEN : ConfigOptionState::ENABLED); |
| 116 | + const ItemPrinter::ItemPrinterEnumOption* option_data = ItemPrinter::option_lookup_by_seed(to_seconds_since_epoch(date)); |
| 117 | +// cout << "option_data = " << option_data << endl; |
| 118 | + // seed found in the PrebuiltOptions table, and jobs number matches and chain disabled |
| 119 | + if (option_data != nullptr && option_data->jobs == jobs && !chain){ |
| 120 | + desired_item.set(option_data->enum_value); |
| 121 | + }else{ |
| 122 | +// cout << "option_data->jobs = " << (size_t)option_data->jobs << ", jobs = " << jobs.current_value() << ", chain = " << chain << endl; |
| 123 | + desired_item.set(ItemPrinter::PrebuiltOptions::NONE); |
| 124 | + } |
101 | 125 | } |
102 | | - } |
103 | 126 |
|
104 | | - table.report_value_changed(object); |
| 127 | + table.report_value_changed(object); |
| 128 | + |
| 129 | + WriteSpinLock lg1(m_pending_lock); |
| 130 | + keep_going = !m_pending.empty(); |
| 131 | + }while (keep_going); |
105 | 132 | } |
106 | 133 |
|
107 | 134 | ItemPrinterRngTable::ItemPrinterRngTable(std::string label) |
|
0 commit comments