Merge pull request #6716 from container1234/qt-cheats-manager

Qt/CheatsManager: Fix updating search result takes a long time
This commit is contained in:
Léo Lam 2018-05-05 10:42:09 +02:00 committed by GitHub
commit d848c7e027
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 124 additions and 135 deletions

View File

@ -426,17 +426,14 @@ void CheatsManager::NewSearch()
return; return;
} }
const auto prev_state = Core::GetState(); Core::RunAsCPUThread([&] {
Core::SetState(Core::State::Paused);
for (u32 i = 0; i < Memory::REALRAM_SIZE - GetTypeSize(); i++) for (u32 i = 0; i < Memory::REALRAM_SIZE - GetTypeSize(); i++)
{ {
if (PowerPC::HostIsRAMAddress(base_address + i) && MatchesSearch(base_address + i)) if (PowerPC::HostIsRAMAddress(base_address + i) && MatchesSearch(base_address + i))
m_results.push_back( m_results.push_back(
{base_address + i, static_cast<DataType>(m_match_length->currentIndex())}); {base_address + i, static_cast<DataType>(m_match_length->currentIndex())});
} }
});
Core::SetState(prev_state);
m_match_next->setEnabled(true); m_match_next->setEnabled(true);
@ -451,17 +448,14 @@ void CheatsManager::NextSearch()
return; return;
} }
const auto prev_state = Core::GetState(); Core::RunAsCPUThread([this] {
Core::SetState(Core::State::Paused);
m_results.erase(std::remove_if(m_results.begin(), m_results.end(), m_results.erase(std::remove_if(m_results.begin(), m_results.end(),
[this](Result r) { [this](Result r) {
return !PowerPC::HostIsRAMAddress(r.address) || return !PowerPC::HostIsRAMAddress(r.address) ||
!MatchesSearch(r.address); !MatchesSearch(r.address);
}), }),
m_results.end()); m_results.end());
});
Core::SetState(prev_state);
Update(); Update();
} }
@ -482,11 +476,15 @@ void CheatsManager::Update()
return; return;
} }
m_updating = true;
m_result_label->setText(tr("%1 Match(es)").arg(m_results.size())); m_result_label->setText(tr("%1 Match(es)").arg(m_results.size()));
m_match_table->setRowCount(static_cast<int>(m_results.size())); m_match_table->setRowCount(static_cast<int>(m_results.size()));
if (m_results.empty())
return;
m_updating = true;
Core::RunAsCPUThread([this] {
for (size_t i = 0; i < m_results.size(); i++) for (size_t i = 0; i < m_results.size(); i++)
{ {
auto* address_item = new QTableWidgetItem( auto* address_item = new QTableWidgetItem(
@ -498,22 +496,19 @@ void CheatsManager::Update()
if (PowerPC::HostIsRAMAddress(m_results[i].address)) if (PowerPC::HostIsRAMAddress(m_results[i].address))
{ {
const auto prev_state = Core::GetState();
Core::SetState(Core::State::Paused);
switch (m_results[i].type) switch (m_results[i].type)
{ {
case DataType::Byte: case DataType::Byte:
value_item->setText(QStringLiteral("%1").arg(PowerPC::HostRead_U8(m_results[i].address), 2, value_item->setText(QStringLiteral("%1").arg(PowerPC::HostRead_U8(m_results[i].address),
16, QLatin1Char('0'))); 2, 16, QLatin1Char('0')));
break; break;
case DataType::Short: case DataType::Short:
value_item->setText(QStringLiteral("%1").arg(PowerPC::HostRead_U16(m_results[i].address), 4, value_item->setText(QStringLiteral("%1").arg(PowerPC::HostRead_U16(m_results[i].address),
16, QLatin1Char('0'))); 4, 16, QLatin1Char('0')));
break; break;
case DataType::Int: case DataType::Int:
value_item->setText(QStringLiteral("%1").arg(PowerPC::HostRead_U32(m_results[i].address), 8, value_item->setText(QStringLiteral("%1").arg(PowerPC::HostRead_U32(m_results[i].address),
16, QLatin1Char('0'))); 8, 16, QLatin1Char('0')));
break; break;
case DataType::Float: case DataType::Float:
value_item->setText(QString::number(PowerPC::HostRead_F32(m_results[i].address))); value_item->setText(QString::number(PowerPC::HostRead_F32(m_results[i].address)));
@ -525,8 +520,6 @@ void CheatsManager::Update()
value_item->setText(tr("String Match")); value_item->setText(tr("String Match"));
break; break;
} }
Core::SetState(prev_state);
} }
else else
{ {
@ -545,16 +538,13 @@ void CheatsManager::Update()
for (size_t i = 0; i < m_watch.size(); i++) for (size_t i = 0; i < m_watch.size(); i++)
{ {
auto* name_item = new QTableWidgetItem(m_watch[i].name); auto* name_item = new QTableWidgetItem(m_watch[i].name);
auto* address_item = auto* address_item = new QTableWidgetItem(
new QTableWidgetItem(QStringLiteral("%1").arg(m_watch[i].address, 8, 16, QLatin1Char('0'))); QStringLiteral("%1").arg(m_watch[i].address, 8, 16, QLatin1Char('0')));
auto* lock_item = new QTableWidgetItem; auto* lock_item = new QTableWidgetItem;
auto* value_item = new QTableWidgetItem; auto* value_item = new QTableWidgetItem;
if (PowerPC::HostIsRAMAddress(m_watch[i].address)) if (PowerPC::HostIsRAMAddress(m_watch[i].address))
{ {
const auto prev_state = Core::GetState();
Core::SetState(Core::State::Paused);
if (m_watch[i].locked) if (m_watch[i].locked)
{ {
PowerPC::debug_interface.Patch(m_watch[i].address, m_watch[i].locked_value); PowerPC::debug_interface.Patch(m_watch[i].address, m_watch[i].locked_value);
@ -584,8 +574,6 @@ void CheatsManager::Update()
value_item->setText(tr("String Match")); value_item->setText(tr("String Match"));
break; break;
} }
Core::SetState(prev_state);
} }
else else
{ {
@ -615,6 +603,7 @@ void CheatsManager::Update()
m_watch_table->setItem(static_cast<int>(i), 2, lock_item); m_watch_table->setItem(static_cast<int>(i), 2, lock_item);
m_watch_table->setItem(static_cast<int>(i), 3, value_item); m_watch_table->setItem(static_cast<int>(i), 3, value_item);
} }
});
m_updating = false; m_updating = false;
} }