Host/VMManager: Remove save state cache invalidation and just populate lists every time

Fixes issues where inexistant save states are listed in dropdowns
This commit is contained in:
Silent 2023-01-24 22:13:29 +01:00 committed by refractionpcsx2
parent d2bdb85dc8
commit f73b497b67
6 changed files with 15 additions and 43 deletions

View File

@ -351,10 +351,6 @@ void Host::OnSaveStateSaved(const std::string_view& filename)
{
}
void Host::InvalidateSaveStateCache()
{
}
void Host::RunOnCPUThread(std::function<void()> function, bool block /* = false */)
{
pxFailRel("Not implemented");

View File

@ -157,7 +157,7 @@ void MainWindow::initialize()
restoreStateFromConfig();
switchToGameListView();
updateWindowTitle();
updateSaveStateMenus(QString(), QString(), 0);
updateSaveStateMenusEnableState(false);
#ifdef _WIN32
registerForDeviceNotifications();
@ -1259,11 +1259,6 @@ void MainWindow::cancelGameListRefresh()
m_game_list_widget->cancelRefresh();
}
void MainWindow::invalidateSaveStateCache()
{
m_save_states_invalidated = true;
}
void MainWindow::reportError(const QString& title, const QString& message)
{
QMessageBox::critical(this, title, message);
@ -1374,11 +1369,6 @@ std::optional<WindowInfo> MainWindow::getWindowInfo()
return std::nullopt;
}
void Host::InvalidateSaveStateCache()
{
QMetaObject::invokeMethod(g_main_window, &MainWindow::invalidateSaveStateCache, Qt::QueuedConnection);
}
void MainWindow::onGameListRefreshProgress(const QString& status, int current, int total)
{
m_ui.statusBar->showMessage(status);
@ -1581,14 +1571,14 @@ void MainWindow::onChangeDiscMenuAboutToHide()
void MainWindow::onLoadStateMenuAboutToShow()
{
if (m_save_states_invalidated)
updateSaveStateMenus(m_current_disc_path, m_current_game_serial, m_current_game_crc);
updateSaveStateMenusEnableState(!m_current_game_serial.isEmpty());
populateLoadStateMenu(m_ui.menuLoadState, m_current_disc_path, m_current_game_serial, m_current_game_crc);
}
void MainWindow::onSaveStateMenuAboutToShow()
{
if (m_save_states_invalidated)
updateSaveStateMenus(m_current_disc_path, m_current_game_serial, m_current_game_crc);
updateSaveStateMenusEnableState(!m_current_game_serial.isEmpty());
populateSaveStateMenu(m_ui.menuSaveState, m_current_game_serial, m_current_game_crc);
}
void MainWindow::onViewToolbarActionToggled(bool checked)
@ -1889,7 +1879,7 @@ void MainWindow::onVMStarting()
updateWindowTitle();
// prevent loading state until we're fully initialized
updateSaveStateMenus(QString(), QString(), 0);
updateSaveStateMenusEnableState(false);
}
void MainWindow::onVMStarted()
@ -1969,7 +1959,7 @@ void MainWindow::onGameChanged(const QString& path, const QString& elf_override,
m_current_game_name = name;
m_current_game_crc = crc;
updateWindowTitle();
updateSaveStateMenus(path, serial, crc);
updateSaveStateMenusEnableState(!serial.isEmpty());
}
void MainWindow::showEvent(QShowEvent* event)
@ -2722,6 +2712,8 @@ static QString formatTimestampForSaveStateMenu(time_t timestamp)
void MainWindow::populateLoadStateMenu(QMenu* menu, const QString& filename, const QString& serial, quint32 crc)
{
menu->clear();
if (serial.isEmpty())
return;
@ -2796,6 +2788,8 @@ void MainWindow::populateLoadStateMenu(QMenu* menu, const QString& filename, con
void MainWindow::populateSaveStateMenu(QMenu* menu, const QString& serial, quint32 crc)
{
menu->clear();
if (serial.isEmpty())
return;
@ -2825,21 +2819,14 @@ void MainWindow::populateSaveStateMenu(QMenu* menu, const QString& serial, quint
}
}
void MainWindow::updateSaveStateMenus(const QString& filename, const QString& serial, quint32 crc)
void MainWindow::updateSaveStateMenusEnableState(bool enable)
{
const bool load_enabled = !serial.isEmpty();
const bool save_enabled = !serial.isEmpty() && s_vm_valid;
m_ui.menuLoadState->clear();
const bool load_enabled = enable;
const bool save_enabled = enable && s_vm_valid;
m_ui.menuLoadState->setEnabled(load_enabled);
m_ui.actionLoadState->setEnabled(load_enabled);
m_ui.menuSaveState->clear();
m_ui.menuSaveState->setEnabled(save_enabled);
m_ui.actionSaveState->setEnabled(save_enabled);
m_save_states_invalidated = false;
if (load_enabled)
populateLoadStateMenu(m_ui.menuLoadState, filename, serial, crc);
if (save_enabled)
populateSaveStateMenu(m_ui.menuSaveState, serial, crc);
}
void MainWindow::doStartFile(std::optional<CDVD_SourceType> source, const QString& path)

View File

@ -114,7 +114,6 @@ public Q_SLOTS:
void checkForUpdates(bool display_message, bool force_check);
void refreshGameList(bool invalidate_cache);
void cancelGameListRefresh();
void invalidateSaveStateCache();
void reportError(const QString& title, const QString& message);
bool confirmMessage(const QString& title, const QString& message);
void runOnUIThread(const std::function<void()>& func);
@ -260,7 +259,7 @@ private:
void loadSaveStateFile(const QString& filename, const QString& state_filename);
void populateLoadStateMenu(QMenu* menu, const QString& filename, const QString& serial, quint32 crc);
void populateSaveStateMenu(QMenu* menu, const QString& serial, quint32 crc);
void updateSaveStateMenus(const QString& filename, const QString& serial, quint32 crc);
void updateSaveStateMenusEnableState(bool enable);
void doStartFile(std::optional<CDVD_SourceType> source, const QString& path);
void doDiscChange(CDVD_SourceType source, const QString& path);
@ -292,7 +291,6 @@ private:
bool m_display_created = false;
bool m_relative_mouse_mode = false;
bool m_save_states_invalidated = false;
bool m_was_paused_on_surface_loss = false;
bool m_was_disc_change_request = false;
bool m_is_closing = false;

View File

@ -1339,8 +1339,6 @@ void VMManager::ZipSaveState(std::unique_ptr<ArchiveEntryList> elist,
}
DevCon.WriteLn("Zipping save state to '%s' took %.2f ms", filename, timer.GetTimeMilliseconds());
Host::InvalidateSaveStateCache();
}
void VMManager::ZipSaveStateOnThread(std::unique_ptr<ArchiveEntryList> elist, std::unique_ptr<SaveStateScreenshotData> screenshot,

View File

@ -258,7 +258,4 @@ namespace Host
/// Provided by the host; called once per frame at guest vsync.
void CPUThreadVSync();
/// Provided by the host; called when a state is saved, and the frontend should invalidate its save state cache.
void InvalidateSaveStateCache();
} // namespace Host

View File

@ -176,10 +176,6 @@ void Host::OnSaveStateSaved(const std::string_view& filename)
{
}
void Host::InvalidateSaveStateCache()
{
}
void Host::RunOnCPUThread(std::function<void()> function, bool block /* = false */)
{
}